Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
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 | // This is a template to help porting global private browsing tests |
michael@0 | 6 | // to per-window private browsing tests |
michael@0 | 7 | function test() { |
michael@0 | 8 | // initialization |
michael@0 | 9 | waitForExplicitFinish(); |
michael@0 | 10 | let windowsToClose = []; |
michael@0 | 11 | let testURI = "about:blank"; |
michael@0 | 12 | let uri; |
michael@0 | 13 | let gSSService = Cc["@mozilla.org/ssservice;1"]. |
michael@0 | 14 | getService(Ci.nsISiteSecurityService); |
michael@0 | 15 | |
michael@0 | 16 | function privacyFlags(aIsPrivateMode) { |
michael@0 | 17 | return aIsPrivateMode ? Ci.nsISocketProvider.NO_PERMANENT_STORAGE : 0; |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | function doTest(aIsPrivateMode, aWindow, aCallback) { |
michael@0 | 21 | aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { |
michael@0 | 22 | aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); |
michael@0 | 23 | |
michael@0 | 24 | uri = aWindow.Services.io.newURI("https://localhost/img.png", null, null); |
michael@0 | 25 | gSSService.processHeader(Ci.nsISiteSecurityService.HEADER_HSTS, uri, |
michael@0 | 26 | "max-age=1000", privacyFlags(aIsPrivateMode)); |
michael@0 | 27 | ok(gSSService.isSecureHost(Ci.nsISiteSecurityService.HEADER_HSTS, "localhost", privacyFlags(aIsPrivateMode)), "checking sts host"); |
michael@0 | 28 | |
michael@0 | 29 | aCallback(); |
michael@0 | 30 | }, true); |
michael@0 | 31 | |
michael@0 | 32 | aWindow.gBrowser.selectedBrowser.loadURI(testURI); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | function testOnWindow(aOptions, aCallback) { |
michael@0 | 36 | whenNewWindowLoaded(aOptions, function(aWin) { |
michael@0 | 37 | windowsToClose.push(aWin); |
michael@0 | 38 | // execute should only be called when need, like when you are opening |
michael@0 | 39 | // web pages on the test. If calling executeSoon() is not necesary, then |
michael@0 | 40 | // call whenNewWindowLoaded() instead of testOnWindow() on your test. |
michael@0 | 41 | executeSoon(function() aCallback(aWin)); |
michael@0 | 42 | }); |
michael@0 | 43 | }; |
michael@0 | 44 | |
michael@0 | 45 | // this function is called after calling finish() on the test. |
michael@0 | 46 | registerCleanupFunction(function() { |
michael@0 | 47 | windowsToClose.forEach(function(aWin) { |
michael@0 | 48 | aWin.close(); |
michael@0 | 49 | }); |
michael@0 | 50 | uri = Services.io.newURI("http://localhost", null, null); |
michael@0 | 51 | gSSService.removeState(Ci.nsISiteSecurityService.HEADER_HSTS, uri, 0); |
michael@0 | 52 | }); |
michael@0 | 53 | |
michael@0 | 54 | // test first when on private mode |
michael@0 | 55 | testOnWindow({private: true}, function(aWin) { |
michael@0 | 56 | doTest(true, aWin, function() { |
michael@0 | 57 | //test when not on private mode |
michael@0 | 58 | testOnWindow({}, function(aWin) { |
michael@0 | 59 | doTest(false, aWin, function() { |
michael@0 | 60 | //test again when on private mode |
michael@0 | 61 | testOnWindow({private: true}, function(aWin) { |
michael@0 | 62 | doTest(true, aWin, function () { |
michael@0 | 63 | finish(); |
michael@0 | 64 | }); |
michael@0 | 65 | }); |
michael@0 | 66 | }); |
michael@0 | 67 | }); |
michael@0 | 68 | }); |
michael@0 | 69 | }); |
michael@0 | 70 | } |