security/manager/ssl/tests/mochitest/browser/browser_bug627234_perwindowpb.js

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

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

mercurial