From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- ...browser_visituri_privatebrowsing_perwindowpb.js | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 toolkit/components/places/tests/browser/browser_visituri_privatebrowsing_perwindowpb.js (limited to 'toolkit/components/places/tests/browser/browser_visituri_privatebrowsing_perwindowpb.js') diff --git a/toolkit/components/places/tests/browser/browser_visituri_privatebrowsing_perwindowpb.js b/toolkit/components/places/tests/browser/browser_visituri_privatebrowsing_perwindowpb.js new file mode 100644 index 000000000..abde69a7d --- /dev/null +++ b/toolkit/components/places/tests/browser/browser_visituri_privatebrowsing_perwindowpb.js @@ -0,0 +1,73 @@ +/* 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/. */ + +function test() { + // initialization + waitForExplicitFinish(); + let windowsToClose = []; + let initialURL = + "http://example.com/tests/toolkit/components/places/tests/browser/begin.html"; + let finalURL = + "http://example.com/tests/toolkit/components/places/tests/browser/final.html"; + let observer = null; + let enumerator = null; + let currentObserver = null; + let uri = null; + + function doTest(aIsPrivateMode, aWindow, aTestURI, aCallback) { + observer = { + observe: function(aSubject, aTopic, aData) { + // The uri-visit-saved topic should only work when on normal mode. + if (aTopic == "uri-visit-saved") { + // Remove the observers set on per window private mode and normal + // mode. + enumerator = aWindow.Services.obs.enumerateObservers("uri-visit-saved"); + while (enumerator.hasMoreElements()) { + currentObserver = enumerator.getNext(); + aWindow.Services.obs.removeObserver(currentObserver, "uri-visit-saved"); + } + + // The expected visit should be the finalURL because private mode + // should not register a visit with the initialURL. + uri = aSubject.QueryInterface(Ci.nsIURI); + is(uri.spec, finalURL, "Check received expected visit"); + } + } + }; + + aWindow.Services.obs.addObserver(observer, "uri-visit-saved", false); + + BrowserTestUtils.browserLoaded(aWindow.gBrowser.selectedBrowser).then(aCallback); + aWindow.gBrowser.selectedBrowser.loadURI(aTestURI); + } + + function testOnWindow(aOptions, aCallback) { + whenNewWindowLoaded(aOptions, function(aWin) { + windowsToClose.push(aWin); + // execute should only be called when need, like when you are opening + // web pages on the test. If calling executeSoon() is not necesary, then + // call whenNewWindowLoaded() instead of testOnWindow() on your test. + executeSoon(() => aCallback(aWin)); + }); + } + + // This function is called after calling finish() on the test. + registerCleanupFunction(function() { + windowsToClose.forEach(function(aWin) { + aWin.close(); + }); + }); + + // test first when on private mode + testOnWindow({private: true}, function(aWin) { + doTest(true, aWin, initialURL, function() { + // then test when not on private mode + testOnWindow({}, function(aWin2) { + doTest(false, aWin2, finalURL, function () { + PlacesTestUtils.clearHistory().then(finish); + }); + }); + }); + }); +} -- cgit v1.2.3