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/. */
6 function whenNewWindowLoaded(aOptions, aCallback) {
7 let win = OpenBrowserWindow(aOptions);
17 // This is a template to help porting global private browsing tests
18 // to per-window private browsing tests
21 waitForExplicitFinish();
22 let windowsToClose = [];
23 let testURI = "about:blank";
25 let gSSService = Cc["@mozilla.org/ssservice;1"].getService(
26 Ci.nsISiteSecurityService
29 function originAttributes(aIsPrivateMode) {
30 return aIsPrivateMode ? { privateBrowsingId: 1 } : {};
33 function doTest(aIsPrivateMode, aWindow, aCallback) {
34 BrowserTestUtils.browserLoaded(aWindow.gBrowser.selectedBrowser).then(
36 uri = aWindow.Services.io.newURI("https://localhost/img.png");
37 gSSService.processHeader(
40 originAttributes(aIsPrivateMode)
43 gSSService.isSecureURI(uri, originAttributes(aIsPrivateMode)),
51 BrowserTestUtils.startLoadingURIString(
52 aWindow.gBrowser.selectedBrowser,
57 function testOnWindow(aOptions, aCallback) {
58 whenNewWindowLoaded(aOptions, function (aWin) {
59 windowsToClose.push(aWin);
60 // execute should only be called when need, like when you are opening
61 // web pages on the test. If calling executeSoon() is not necesary, then
62 // call whenNewWindowLoaded() instead of testOnWindow() on your test.
63 executeSoon(function () {
69 // this function is called after calling finish() on the test.
70 registerCleanupFunction(function () {
71 windowsToClose.forEach(function (aWin) {
74 uri = Services.io.newURI("http://localhost");
75 gSSService.resetState(uri);
78 // test first when on private mode
79 testOnWindow({ private: true }, function (aWin) {
80 doTest(true, aWin, function () {
81 // test when not on private mode
82 testOnWindow({}, function (aWin) {
83 doTest(false, aWin, function () {
84 // test again when on private mode
85 testOnWindow({ private: true }, function (aWin) {
86 doTest(true, aWin, function () {