2013-07-26 11:40:04 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
let outOfProcess = __marionetteParams[0]
|
|
|
|
let mochitestUrl = __marionetteParams[1]
|
2014-01-31 10:22:51 -08:00
|
|
|
let onDevice = __marionetteParams[2]
|
|
|
|
let wifiSettings = __marionetteParams[3]
|
|
|
|
let prefs = Components.classes["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Components.interfaces.nsIPrefBranch)
|
2014-03-12 05:29:23 -07:00
|
|
|
let settings = window.navigator.mozSettings;
|
2014-06-30 20:59:00 -07:00
|
|
|
let cm = Components.classes["@mozilla.org/categorymanager;1"].
|
|
|
|
getService(Components.interfaces.nsICategoryManager);
|
2014-01-31 10:22:51 -08:00
|
|
|
|
|
|
|
if (wifiSettings)
|
|
|
|
wifiSettings = JSON.parse(wifiSettings);
|
2013-07-26 11:40:04 -07:00
|
|
|
|
|
|
|
const CHILD_SCRIPT = "chrome://specialpowers/content/specialpowers.js";
|
|
|
|
const CHILD_SCRIPT_API = "chrome://specialpowers/content/specialpowersAPI.js";
|
|
|
|
const CHILD_LOGGER_SCRIPT = "chrome://specialpowers/content/MozillaLogger.js";
|
|
|
|
|
2013-08-28 14:35:34 -07:00
|
|
|
let homescreen = document.getElementById('systemapp');
|
2013-07-26 11:40:04 -07:00
|
|
|
let container = homescreen.contentWindow.document.getElementById('test-container');
|
|
|
|
|
2014-06-30 20:59:00 -07:00
|
|
|
// Disable udpate timers which cause failure in b2g permisson prompt tests.
|
|
|
|
if (cm) {
|
|
|
|
cm.deleteCategoryEntry("update-timer", "WebappsUpdateTimer", false);
|
|
|
|
cm.deleteCategoryEntry("update-timer", "nsUpdateService", false);
|
|
|
|
}
|
|
|
|
|
2013-07-26 11:40:04 -07:00
|
|
|
function openWindow(aEvent) {
|
|
|
|
var popupIframe = aEvent.detail.frameElement;
|
2014-05-12 12:02:14 -07:00
|
|
|
popupIframe.style = 'position: absolute; left: 0; top: 0px; background: white;';
|
2013-09-25 10:09:30 -07:00
|
|
|
|
|
|
|
// This is to size the iframe to what is requested in the window.open call,
|
|
|
|
// e.g. window.open("", "", "width=600,height=600");
|
|
|
|
if (aEvent.detail.features.indexOf('width') != -1) {
|
|
|
|
let width = aEvent.detail.features.substr(aEvent.detail.features.indexOf('width')+6);
|
|
|
|
width = width.substr(0,width.indexOf(',') == -1 ? width.length : width.indexOf(','));
|
|
|
|
popupIframe.style.width = width + 'px';
|
|
|
|
}
|
|
|
|
if (aEvent.detail.features.indexOf('height') != -1) {
|
|
|
|
let height = aEvent.detail.features.substr(aEvent.detail.features.indexOf('height')+7);
|
|
|
|
height = height.substr(0, height.indexOf(',') == -1 ? height.length : height.indexOf(','));
|
|
|
|
popupIframe.style.height = height + 'px';
|
|
|
|
}
|
2013-07-26 11:40:04 -07:00
|
|
|
|
|
|
|
popupIframe.addEventListener('mozbrowserclose', function(e) {
|
|
|
|
container.parentNode.removeChild(popupIframe);
|
|
|
|
container.focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
// yes, the popup can call window.open too!
|
|
|
|
popupIframe.addEventListener('mozbrowseropenwindow', openWindow);
|
|
|
|
|
|
|
|
popupIframe.addEventListener('mozbrowserloadstart', function(e) {
|
|
|
|
popupIframe.focus();
|
2013-09-25 10:09:30 -07:00
|
|
|
let mm = popupIframe.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager;
|
|
|
|
mm.loadFrameScript(CHILD_LOGGER_SCRIPT, true);
|
|
|
|
mm.loadFrameScript(CHILD_SCRIPT_API, true);
|
|
|
|
mm.loadFrameScript(CHILD_SCRIPT, true);
|
2014-06-13 10:56:38 -07:00
|
|
|
mm.loadFrameScript('data:,attachSpecialPowersToWindow(content);', true);
|
2013-07-26 11:40:04 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
container.parentNode.appendChild(popupIframe);
|
|
|
|
}
|
|
|
|
container.addEventListener('mozbrowseropenwindow', openWindow);
|
|
|
|
|
2013-08-14 10:57:43 -07:00
|
|
|
if (outOfProcess) {
|
|
|
|
let specialpowers = {};
|
|
|
|
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
|
|
|
|
loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserver.js", specialpowers);
|
|
|
|
let specialPowersObserver = new specialpowers.SpecialPowersObserver();
|
|
|
|
|
|
|
|
let mm = container.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager;
|
2013-12-19 17:04:20 -08:00
|
|
|
specialPowersObserver.init(mm);
|
|
|
|
|
2013-08-20 15:41:18 -07:00
|
|
|
//Workaround for bug 848411, once that bug is fixed, the following line can be removed
|
2014-06-13 10:56:38 -07:00
|
|
|
function contentScript() {
|
|
|
|
addEventListener("DOMWindowCreated", function listener(e) {
|
|
|
|
removeEventListener("DOMWindowCreated", listener, false);
|
|
|
|
var window = e.target.defaultView;
|
|
|
|
window.wrappedJSObject.SpecialPowers.addPermission("allowXULXBL", true, window.document);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
mm.loadFrameScript("data:,(" + encodeURI(contentScript.toSource()) + ")();", true);
|
2013-08-14 10:57:43 -07:00
|
|
|
}
|
2013-07-26 11:40:04 -07:00
|
|
|
|
2014-01-31 10:22:51 -08:00
|
|
|
|
|
|
|
if (onDevice) {
|
2014-04-07 11:39:16 -07:00
|
|
|
var cpuLock = Cc["@mozilla.org/power/powermanagerservice;1"]
|
|
|
|
.getService(Ci.nsIPowerManagerService)
|
|
|
|
.newWakeLock("cpu");
|
|
|
|
|
2014-01-31 10:22:51 -08:00
|
|
|
let manager = navigator.mozWifiManager;
|
|
|
|
let con = manager.connection;
|
2014-03-12 05:29:23 -07:00
|
|
|
manager.setPowerSavingMode(false);
|
|
|
|
|
|
|
|
manager.onenabled = function () {
|
|
|
|
if(wifiSettings) {
|
|
|
|
var req = manager.getKnownNetworks();
|
|
|
|
req.onsuccess = function () {
|
|
|
|
var networks = req.result;
|
|
|
|
for (var i = 0; i < networks.length; ++i){
|
|
|
|
var network = networks[i];
|
|
|
|
if(network.ssid == wifiSettings.ssid) {
|
|
|
|
manager.forget(network);
|
|
|
|
}
|
|
|
|
}
|
2014-06-19 20:23:00 -07:00
|
|
|
manager.associate(new window.MozWifiNetwork(wifiSettings));
|
2014-01-31 10:22:51 -08:00
|
|
|
};
|
|
|
|
}
|
2014-03-12 05:29:23 -07:00
|
|
|
};
|
2014-01-31 10:22:51 -08:00
|
|
|
|
|
|
|
manager.onstatuschange = function (event) {
|
2014-03-12 05:29:23 -07:00
|
|
|
prefs.setIntPref("network.proxy.type", 2);
|
2014-01-31 10:22:51 -08:00
|
|
|
if (event.status == 'connected') {
|
|
|
|
container.src = mochitestUrl;
|
|
|
|
}
|
2014-03-12 05:29:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
if(wifiSettings) {
|
|
|
|
var req = settings.createLock().set({
|
|
|
|
'wifi.enabled': false,
|
|
|
|
'wifi.suspended': false
|
|
|
|
});
|
|
|
|
|
|
|
|
req.onsuccess = function () {
|
|
|
|
dump("----------------------enabling wifi------------------\n");
|
|
|
|
var req1 = settings.createLock().set({
|
|
|
|
'wifi.enabled': true,
|
|
|
|
'wifi.suspended': false});
|
|
|
|
};
|
2014-01-31 10:22:51 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
container.src = mochitestUrl;
|
|
|
|
}
|