Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | function test() { |
michael@0 | 2 | var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); |
michael@0 | 3 | let baseProvider = "http://mochi.test:8888/browser/dom/tests/browser/network_geolocation.sjs"; |
michael@0 | 4 | prefs.setCharPref("geo.wifi.uri", baseProvider + "?desired_access_token=fff"); |
michael@0 | 5 | |
michael@0 | 6 | prefs.setBoolPref("geo.prompt.testing", true); |
michael@0 | 7 | prefs.setBoolPref("geo.prompt.testing.allow", true); |
michael@0 | 8 | var origScanValue = true; // same default in NetworkGeolocationProvider.js. |
michael@0 | 9 | try { |
michael@0 | 10 | origScanValue = prefs.getBoolPref("geo.wifi.scan"); |
michael@0 | 11 | } catch(ex) {} |
michael@0 | 12 | prefs.setBoolPref("geo.wifi.scan", false); |
michael@0 | 13 | |
michael@0 | 14 | const testPageURL = "http://mochi.test:8888/browser/" + |
michael@0 | 15 | "dom/tests/browser/browser_geolocation_privatebrowsing_page.html"; |
michael@0 | 16 | waitForExplicitFinish(); |
michael@0 | 17 | |
michael@0 | 18 | var windowsToClose = []; |
michael@0 | 19 | function testOnWindow(aIsPrivate, aCallback) { |
michael@0 | 20 | let win = OpenBrowserWindow({private: aIsPrivate}); |
michael@0 | 21 | let gotLoad = false; |
michael@0 | 22 | let gotActivate = |
michael@0 | 23 | (Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager).activeWindow == win); |
michael@0 | 24 | if (!gotActivate) { |
michael@0 | 25 | win.addEventListener("activate", function onActivate() { |
michael@0 | 26 | info("got activate"); |
michael@0 | 27 | win.removeEventListener("activate", onActivate, true); |
michael@0 | 28 | gotActivate = true; |
michael@0 | 29 | if (gotLoad) { |
michael@0 | 30 | windowsToClose.push(win); |
michael@0 | 31 | win.BrowserChromeTest.runWhenReady(function() { aCallback(win) }); |
michael@0 | 32 | } |
michael@0 | 33 | }, true); |
michael@0 | 34 | } else { |
michael@0 | 35 | info("Was activated"); |
michael@0 | 36 | } |
michael@0 | 37 | win.addEventListener("load", function onLoad() { |
michael@0 | 38 | info("Got load"); |
michael@0 | 39 | win.removeEventListener("load", onLoad, true); |
michael@0 | 40 | gotLoad = true; |
michael@0 | 41 | if (gotActivate) { |
michael@0 | 42 | windowsToClose.push(win); |
michael@0 | 43 | setTimeout(function() { aCallback(win) }, 1000); |
michael@0 | 44 | } |
michael@0 | 45 | }, true); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | testOnWindow(false, function(aNormalWindow) { |
michael@0 | 49 | aNormalWindow.gBrowser.selectedBrowser.addEventListener("georesult", function load(ev) { |
michael@0 | 50 | aNormalWindow.gBrowser.selectedBrowser.removeEventListener("georesult", load, false); |
michael@0 | 51 | is(ev.detail, 200, "unexpected access token"); |
michael@0 | 52 | |
michael@0 | 53 | prefs.setCharPref("geo.wifi.uri", baseProvider + "?desired_access_token=ggg"); |
michael@0 | 54 | |
michael@0 | 55 | testOnWindow(true, function(aPrivateWindow) { |
michael@0 | 56 | aPrivateWindow.gBrowser.selectedBrowser.addEventListener("georesult", function load2(ev) { |
michael@0 | 57 | aPrivateWindow.gBrowser.selectedBrowser.removeEventListener("georesult", load2, false); |
michael@0 | 58 | is(ev.detail, 200, "unexpected access token"); |
michael@0 | 59 | |
michael@0 | 60 | prefs.setCharPref("geo.wifi.uri", baseProvider + "?expected_access_token=fff"); |
michael@0 | 61 | |
michael@0 | 62 | testOnWindow(false, function(aAnotherNormalWindow) { |
michael@0 | 63 | aAnotherNormalWindow.gBrowser.selectedBrowser.addEventListener("georesult", function load3(ev) { |
michael@0 | 64 | aAnotherNormalWindow.gBrowser.selectedBrowser.removeEventListener("georesult", load3, false); |
michael@0 | 65 | is(ev.detail, 200, "unexpected access token"); |
michael@0 | 66 | prefs.setBoolPref("geo.prompt.testing", false); |
michael@0 | 67 | prefs.setBoolPref("geo.prompt.testing.allow", false); |
michael@0 | 68 | prefs.setBoolPref("geo.wifi.scan", origScanValue); |
michael@0 | 69 | windowsToClose.forEach(function(win) { |
michael@0 | 70 | win.close(); |
michael@0 | 71 | }); |
michael@0 | 72 | finish(); |
michael@0 | 73 | }, false, true); |
michael@0 | 74 | aAnotherNormalWindow.content.location = testPageURL; |
michael@0 | 75 | }); |
michael@0 | 76 | }, false, true); |
michael@0 | 77 | aPrivateWindow.content.location = testPageURL; |
michael@0 | 78 | }); |
michael@0 | 79 | }, false, true); |
michael@0 | 80 | aNormalWindow.content.location = testPageURL; |
michael@0 | 81 | }); |
michael@0 | 82 | } |