Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 // This test makes sure that the web pages can't register protocol handlers
6 // inside the private browsing mode.
8 function test() {
9 // initialization
10 waitForExplicitFinish();
11 let windowsToClose = [];
12 let notificationValue = "Protocol Registration: testprotocol";
13 let testURI = "http://example.com/browser/" +
14 "browser/components/privatebrowsing/test/browser/browser_privatebrowsing_protocolhandler_page.html";
16 function doTest(aIsPrivateMode, aWindow, aCallback) {
17 aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
18 aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
20 setTimeout(function() {
21 let notificationBox = aWindow.gBrowser.getNotificationBox();
22 let notification = notificationBox.getNotificationWithValue(notificationValue);
24 if (aIsPrivateMode) {
25 // Make sure the notification is correctly displayed without a remember control
26 ok(!notification, "Notification box should not be displayed inside of private browsing mode");
27 } else {
28 // Make sure the notification is correctly displayed with a remember control
29 ok(notification, "Notification box should be displaying outside of private browsing mode");
30 }
32 aCallback();
33 }, 100); // remember control is added in a setTimeout(0) call
34 }, true);
36 aWindow.gBrowser.selectedBrowser.loadURI(testURI);
37 }
39 function testOnWindow(aOptions, aCallback) {
40 whenNewWindowLoaded(aOptions, function(aWin) {
41 windowsToClose.push(aWin);
42 // execute should only be called when need, like when you are opening
43 // web pages on the test. If calling executeSoon() is not necesary, then
44 // call whenNewWindowLoaded() instead of testOnWindow() on your test.
45 executeSoon(function() aCallback(aWin));
46 });
47 };
49 // this function is called after calling finish() on the test.
50 registerCleanupFunction(function() {
51 windowsToClose.forEach(function(aWin) {
52 aWin.close();
53 });
54 });
56 // test first when not on private mode
57 testOnWindow({}, function(aWin) {
58 doTest(false, aWin, function() {
59 // then test when on private mode
60 testOnWindow({private: true}, function(aWin) {
61 doTest(true, aWin, finish);
62 });
63 });
64 });
65 }