testing/mochitest/b2g_start_script.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 let outOfProcess = __marionetteParams[0]
michael@0 6 let mochitestUrl = __marionetteParams[1]
michael@0 7 let onDevice = __marionetteParams[2]
michael@0 8 let wifiSettings = __marionetteParams[3]
michael@0 9 let prefs = Components.classes["@mozilla.org/preferences-service;1"].
michael@0 10 getService(Components.interfaces.nsIPrefBranch)
michael@0 11 let settings = window.navigator.mozSettings;
michael@0 12
michael@0 13 if (wifiSettings)
michael@0 14 wifiSettings = JSON.parse(wifiSettings);
michael@0 15
michael@0 16 const CHILD_SCRIPT = "chrome://specialpowers/content/specialpowers.js";
michael@0 17 const CHILD_SCRIPT_API = "chrome://specialpowers/content/specialpowersAPI.js";
michael@0 18 const CHILD_LOGGER_SCRIPT = "chrome://specialpowers/content/MozillaLogger.js";
michael@0 19
michael@0 20 let homescreen = document.getElementById('systemapp');
michael@0 21 let container = homescreen.contentWindow.document.getElementById('test-container');
michael@0 22
michael@0 23 function openWindow(aEvent) {
michael@0 24 var popupIframe = aEvent.detail.frameElement;
michael@0 25 popupIframe.setAttribute('style', 'position: absolute; left: 0; top: 0px; background: white;');
michael@0 26
michael@0 27 // This is to size the iframe to what is requested in the window.open call,
michael@0 28 // e.g. window.open("", "", "width=600,height=600");
michael@0 29 if (aEvent.detail.features.indexOf('width') != -1) {
michael@0 30 let width = aEvent.detail.features.substr(aEvent.detail.features.indexOf('width')+6);
michael@0 31 width = width.substr(0,width.indexOf(',') == -1 ? width.length : width.indexOf(','));
michael@0 32 popupIframe.style.width = width + 'px';
michael@0 33 }
michael@0 34 if (aEvent.detail.features.indexOf('height') != -1) {
michael@0 35 let height = aEvent.detail.features.substr(aEvent.detail.features.indexOf('height')+7);
michael@0 36 height = height.substr(0, height.indexOf(',') == -1 ? height.length : height.indexOf(','));
michael@0 37 popupIframe.style.height = height + 'px';
michael@0 38 }
michael@0 39
michael@0 40 popupIframe.addEventListener('mozbrowserclose', function(e) {
michael@0 41 container.parentNode.removeChild(popupIframe);
michael@0 42 container.focus();
michael@0 43 });
michael@0 44
michael@0 45 // yes, the popup can call window.open too!
michael@0 46 popupIframe.addEventListener('mozbrowseropenwindow', openWindow);
michael@0 47
michael@0 48 popupIframe.addEventListener('mozbrowserloadstart', function(e) {
michael@0 49 popupIframe.focus();
michael@0 50 let mm = popupIframe.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager;
michael@0 51 mm.loadFrameScript(CHILD_LOGGER_SCRIPT, true);
michael@0 52 mm.loadFrameScript(CHILD_SCRIPT_API, true);
michael@0 53 mm.loadFrameScript(CHILD_SCRIPT, true);
michael@0 54 mm.loadFrameScript('data:,attachSpecialPowersToWindow%28content%29%3B', true);
michael@0 55 });
michael@0 56
michael@0 57 container.parentNode.appendChild(popupIframe);
michael@0 58 }
michael@0 59 container.addEventListener('mozbrowseropenwindow', openWindow);
michael@0 60
michael@0 61 if (outOfProcess) {
michael@0 62 let specialpowers = {};
michael@0 63 let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
michael@0 64 loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserver.js", specialpowers);
michael@0 65 let specialPowersObserver = new specialpowers.SpecialPowersObserver();
michael@0 66
michael@0 67 let mm = container.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager;
michael@0 68 specialPowersObserver.init(mm);
michael@0 69
michael@0 70 mm.addMessageListener("SPPrefService", specialPowersObserver);
michael@0 71 mm.addMessageListener("SPProcessCrashService", specialPowersObserver);
michael@0 72 mm.addMessageListener("SPPingService", specialPowersObserver);
michael@0 73 mm.addMessageListener("SpecialPowers.Quit", specialPowersObserver);
michael@0 74 mm.addMessageListener("SpecialPowers.Focus", specialPowersObserver);
michael@0 75 mm.addMessageListener("SPPermissionManager", specialPowersObserver);
michael@0 76 mm.addMessageListener("SPLoadChromeScript", specialPowersObserver);
michael@0 77 mm.addMessageListener("SPChromeScriptMessage", specialPowersObserver);
michael@0 78
michael@0 79 mm.loadFrameScript(CHILD_LOGGER_SCRIPT, true);
michael@0 80 mm.loadFrameScript(CHILD_SCRIPT_API, true);
michael@0 81 mm.loadFrameScript(CHILD_SCRIPT, true);
michael@0 82 //Workaround for bug 848411, once that bug is fixed, the following line can be removed
michael@0 83 mm.loadFrameScript('data:,addEventListener%28%22DOMWindowCreated%22%2C%20function%28e%29%20%7B%0A%20%20removeEventListener%28%22DOMWindowCreated%22%2C%20arguments.callee%2C%20false%29%3B%0A%20%20var%20window%20%3D%20e.target.defaultView%3B%0A%20%20window.wrappedJSObject.SpecialPowers.addPermission%28%22allowXULXBL%22%2C%20true%2C%20window.document%29%3B%0A%7D%0A%29%3B', true);
michael@0 84
michael@0 85 specialPowersObserver._isFrameScriptLoaded = true;
michael@0 86 }
michael@0 87
michael@0 88
michael@0 89 if (onDevice) {
michael@0 90 var cpuLock = Cc["@mozilla.org/power/powermanagerservice;1"]
michael@0 91 .getService(Ci.nsIPowerManagerService)
michael@0 92 .newWakeLock("cpu");
michael@0 93
michael@0 94 let manager = navigator.mozWifiManager;
michael@0 95 let con = manager.connection;
michael@0 96 manager.setPowerSavingMode(false);
michael@0 97
michael@0 98 manager.onenabled = function () {
michael@0 99 if(wifiSettings) {
michael@0 100 var req = manager.getKnownNetworks();
michael@0 101 req.onsuccess = function () {
michael@0 102 var networks = req.result;
michael@0 103 for (var i = 0; i < networks.length; ++i){
michael@0 104 var network = networks[i];
michael@0 105 if(network.ssid == wifiSettings.ssid) {
michael@0 106 manager.forget(network);
michael@0 107 }
michael@0 108 }
michael@0 109 manager.associate(wifiSettings);
michael@0 110 };
michael@0 111 }
michael@0 112 };
michael@0 113
michael@0 114 manager.onstatuschange = function (event) {
michael@0 115 prefs.setIntPref("network.proxy.type", 2);
michael@0 116 if (event.status == 'connected') {
michael@0 117 container.src = mochitestUrl;
michael@0 118 }
michael@0 119 };
michael@0 120
michael@0 121 if(wifiSettings) {
michael@0 122 var req = settings.createLock().set({
michael@0 123 'wifi.enabled': false,
michael@0 124 'wifi.suspended': false
michael@0 125 });
michael@0 126
michael@0 127 req.onsuccess = function () {
michael@0 128 dump("----------------------enabling wifi------------------\n");
michael@0 129 var req1 = settings.createLock().set({
michael@0 130 'wifi.enabled': true,
michael@0 131 'wifi.suspended': false});
michael@0 132 };
michael@0 133 }
michael@0 134 } else {
michael@0 135 container.src = mochitestUrl;
michael@0 136 }

mercurial