Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
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 | function test() { |
michael@0 | 6 | // initialization |
michael@0 | 7 | waitForExplicitFinish(); |
michael@0 | 8 | let windowsToClose = []; |
michael@0 | 9 | let testURI = "https://www.mozilla.org/en-US/"; |
michael@0 | 10 | let initialURL = |
michael@0 | 11 | "http://example.com/tests/toolkit/components/places/tests/browser/begin.html"; |
michael@0 | 12 | let finalURL = |
michael@0 | 13 | "http://example.com/tests/toolkit/components/places/tests/browser/final.html"; |
michael@0 | 14 | let observer = null; |
michael@0 | 15 | let enumerator = null; |
michael@0 | 16 | let currentObserver = null; |
michael@0 | 17 | let uri = null; |
michael@0 | 18 | |
michael@0 | 19 | function doTest(aIsPrivateMode, aWindow, aTestURI, aCallback) { |
michael@0 | 20 | aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { |
michael@0 | 21 | if (aWindow.gBrowser.selectedBrowser.contentWindow.location != aTestURI) { |
michael@0 | 22 | aWindow.gBrowser.selectedBrowser.contentWindow.location = aTestURI; |
michael@0 | 23 | return; |
michael@0 | 24 | } |
michael@0 | 25 | aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); |
michael@0 | 26 | |
michael@0 | 27 | if (aCallback) { |
michael@0 | 28 | aCallback(); |
michael@0 | 29 | } |
michael@0 | 30 | }, true); |
michael@0 | 31 | |
michael@0 | 32 | observer = { |
michael@0 | 33 | observe: function(aSubject, aTopic, aData) { |
michael@0 | 34 | // The uri-visit-saved topic should only work when on normal mode. |
michael@0 | 35 | if (aTopic == "uri-visit-saved") { |
michael@0 | 36 | // Remove the observers set on per window private mode and normal |
michael@0 | 37 | // mode. |
michael@0 | 38 | enumerator = aWindow.Services.obs.enumerateObservers("uri-visit-saved"); |
michael@0 | 39 | while (enumerator.hasMoreElements()) { |
michael@0 | 40 | currentObserver = enumerator.getNext(); |
michael@0 | 41 | aWindow.Services.obs.removeObserver(currentObserver, "uri-visit-saved"); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | // The expected visit should be the finalURL because private mode |
michael@0 | 45 | // should not register a visit with the initialURL. |
michael@0 | 46 | uri = aSubject.QueryInterface(Ci.nsIURI); |
michael@0 | 47 | is(uri.spec, finalURL, "Check received expected visit"); |
michael@0 | 48 | } |
michael@0 | 49 | } |
michael@0 | 50 | }; |
michael@0 | 51 | |
michael@0 | 52 | aWindow.Services.obs.addObserver(observer, "uri-visit-saved", false); |
michael@0 | 53 | aWindow.gBrowser.selectedBrowser.loadURI(aTestURI); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function testOnWindow(aOptions, aCallback) { |
michael@0 | 57 | whenNewWindowLoaded(aOptions, function(aWin) { |
michael@0 | 58 | windowsToClose.push(aWin); |
michael@0 | 59 | // execute should only be called when need, like when you are opening |
michael@0 | 60 | // web pages on the test. If calling executeSoon() is not necesary, then |
michael@0 | 61 | // call whenNewWindowLoaded() instead of testOnWindow() on your test. |
michael@0 | 62 | executeSoon(function() aCallback(aWin)); |
michael@0 | 63 | }); |
michael@0 | 64 | }; |
michael@0 | 65 | |
michael@0 | 66 | // This function is called after calling finish() on the test. |
michael@0 | 67 | registerCleanupFunction(function() { |
michael@0 | 68 | windowsToClose.forEach(function(aWin) { |
michael@0 | 69 | aWin.close(); |
michael@0 | 70 | }); |
michael@0 | 71 | }); |
michael@0 | 72 | |
michael@0 | 73 | // test first when on private mode |
michael@0 | 74 | testOnWindow({private: true}, function(aWin) { |
michael@0 | 75 | doTest(true, aWin, initialURL, function() { |
michael@0 | 76 | // then test when not on private mode |
michael@0 | 77 | testOnWindow({}, function(aWin) { |
michael@0 | 78 | doTest(false, aWin, finalURL, function () { |
michael@0 | 79 | promiseClearHistory().then(finish); |
michael@0 | 80 | }); |
michael@0 | 81 | }); |
michael@0 | 82 | }); |
michael@0 | 83 | }); |
michael@0 | 84 | } |