michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // This is a template to help porting global private browsing tests michael@0: // to per-window private browsing tests michael@0: function test() { michael@0: // initialization michael@0: waitForExplicitFinish(); michael@0: let windowsToClose = []; michael@0: let testURI = "about:blank"; michael@0: let uri; michael@0: let gSSService = Cc["@mozilla.org/ssservice;1"]. michael@0: getService(Ci.nsISiteSecurityService); michael@0: michael@0: function privacyFlags(aIsPrivateMode) { michael@0: return aIsPrivateMode ? Ci.nsISocketProvider.NO_PERMANENT_STORAGE : 0; michael@0: } michael@0: michael@0: function doTest(aIsPrivateMode, aWindow, aCallback) { michael@0: aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { michael@0: aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); michael@0: michael@0: uri = aWindow.Services.io.newURI("https://localhost/img.png", null, null); michael@0: gSSService.processHeader(Ci.nsISiteSecurityService.HEADER_HSTS, uri, michael@0: "max-age=1000", privacyFlags(aIsPrivateMode)); michael@0: ok(gSSService.isSecureHost(Ci.nsISiteSecurityService.HEADER_HSTS, "localhost", privacyFlags(aIsPrivateMode)), "checking sts host"); michael@0: michael@0: aCallback(); michael@0: }, true); michael@0: michael@0: aWindow.gBrowser.selectedBrowser.loadURI(testURI); michael@0: } michael@0: michael@0: function testOnWindow(aOptions, aCallback) { michael@0: whenNewWindowLoaded(aOptions, function(aWin) { michael@0: windowsToClose.push(aWin); michael@0: // execute should only be called when need, like when you are opening michael@0: // web pages on the test. If calling executeSoon() is not necesary, then michael@0: // call whenNewWindowLoaded() instead of testOnWindow() on your test. michael@0: executeSoon(function() aCallback(aWin)); michael@0: }); michael@0: }; michael@0: michael@0: // this function is called after calling finish() on the test. michael@0: registerCleanupFunction(function() { michael@0: windowsToClose.forEach(function(aWin) { michael@0: aWin.close(); michael@0: }); michael@0: uri = Services.io.newURI("http://localhost", null, null); michael@0: gSSService.removeState(Ci.nsISiteSecurityService.HEADER_HSTS, uri, 0); michael@0: }); michael@0: michael@0: // test first when on private mode michael@0: testOnWindow({private: true}, function(aWin) { michael@0: doTest(true, aWin, function() { michael@0: //test when not on private mode michael@0: testOnWindow({}, function(aWin) { michael@0: doTest(false, aWin, function() { michael@0: //test again when on private mode michael@0: testOnWindow({private: true}, function(aWin) { michael@0: doTest(true, aWin, function () { michael@0: finish(); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: }