From 0e2faa6cfc4f3dbdf20838533b7c20b1249d9014 Mon Sep 17 00:00:00 2001 From: "Mario Alvarado [:marioalv]" Date: Wed, 12 Dec 2012 15:15:35 -0600 Subject: [PATCH] Bug 806732 - Port test_bug627234.js to the new per-tab PB APIs; r=ehsan DONTBUILD since this is NPOTB for global PB builds --HG-- rename : security/manager/ssl/tests/unit/test_bug627234.js => security/manager/ssl/tests/mochitest/browser/browser_bug627234_perwindowpb.js --- .../manager/ssl/tests/mochitest/Makefile.in | 1 + .../ssl/tests/mochitest/browser/Makefile.in | 24 +++++++ .../browser/browser_bug627234_perwindowpb.js | 69 +++++++++++++++++++ .../ssl/tests/mochitest/browser/head.js | 9 +++ 4 files changed, 103 insertions(+) create mode 100644 security/manager/ssl/tests/mochitest/browser/Makefile.in create mode 100644 security/manager/ssl/tests/mochitest/browser/browser_bug627234_perwindowpb.js create mode 100644 security/manager/ssl/tests/mochitest/browser/head.js diff --git a/security/manager/ssl/tests/mochitest/Makefile.in b/security/manager/ssl/tests/mochitest/Makefile.in index 84fe723932da..bd905b5b2561 100644 --- a/security/manager/ssl/tests/mochitest/Makefile.in +++ b/security/manager/ssl/tests/mochitest/Makefile.in @@ -10,6 +10,7 @@ VPATH = @srcdir@ MODULE = pipnss DIRS = \ + browser \ bugs \ mixedcontent \ stricttransportsecurity \ diff --git a/security/manager/ssl/tests/mochitest/browser/Makefile.in b/security/manager/ssl/tests/mochitest/browser/Makefile.in new file mode 100644 index 000000000000..13e8683e192a --- /dev/null +++ b/security/manager/ssl/tests/mochitest/browser/Makefile.in @@ -0,0 +1,24 @@ +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DEPTH = @DEPTH@ +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ +relativesrcdir = @relativesrcdir@ + +include $(DEPTH)/config/autoconf.mk + +MOCHITEST_BROWSER_FILES = \ + head.js \ + $(NULL) + +ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING +MOCHITEST_BROWSER_FILES += \ + browser_bug627234_perwindowpb.js \ + $(NULL) +endif + +include $(topsrcdir)/config/rules.mk diff --git a/security/manager/ssl/tests/mochitest/browser/browser_bug627234_perwindowpb.js b/security/manager/ssl/tests/mochitest/browser/browser_bug627234_perwindowpb.js new file mode 100644 index 000000000000..617fb9a94ba6 --- /dev/null +++ b/security/manager/ssl/tests/mochitest/browser/browser_bug627234_perwindowpb.js @@ -0,0 +1,69 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This is a template to help porting global private browsing tests +// to per-window private browsing tests +function test() { + // initialization + waitForExplicitFinish(); + let windowsToClose = []; + let testURI = "about:blank"; + let uri; + let gSTSService = Cc["@mozilla.org/stsservice;1"]. + getService(Ci.nsIStrictTransportSecurityService); + + function privacyFlags(aIsPrivateMode) { + return aIsPrivateMode ? Ci.nsISocketProvider.NO_PERMANENT_STORAGE : 0; + } + + function doTest(aIsPrivateMode, aWindow, aCallback) { + aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { + aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); + + uri = aWindow.Services.io.newURI("https://localhost/img.png", null, null); + gSTSService.processStsHeader(uri, "max-age=1000", privacyFlags(aIsPrivateMode)); + ok(gSTSService.isStsHost("localhost", privacyFlags(aIsPrivateMode)), "checking sts host"); + + aCallback(); + }, true); + + aWindow.gBrowser.selectedBrowser.loadURI(testURI); + } + + function testOnWindow(aOptions, aCallback) { + whenNewWindowLoaded(aOptions, function(aWin) { + windowsToClose.push(aWin); + // execute should only be called when need, like when you are opening + // web pages on the test. If calling executeSoon() is not necesary, then + // call whenNewWindowLoaded() instead of testOnWindow() on your test. + executeSoon(function() aCallback(aWin)); + }); + }; + + // this function is called after calling finish() on the test. + registerCleanupFunction(function() { + windowsToClose.forEach(function(aWin) { + aWin.close(); + }); + uri = Services.io.newURI("http://localhost", null, null); + gSTSService.removeStsState(uri, privacyFlags(true)); + }); + + // test first when on private mode + testOnWindow({private: true}, function(aWin) { + doTest(true, aWin, function() { + //test when not on private mode + testOnWindow({}, function(aWin) { + doTest(false, aWin, function() { + //test again when on private mode + testOnWindow({private: true}, function(aWin) { + doTest(true, aWin, function () { + finish(); + }); + }); + }); + }); + }); + }); +} diff --git a/security/manager/ssl/tests/mochitest/browser/head.js b/security/manager/ssl/tests/mochitest/browser/head.js new file mode 100644 index 000000000000..babc1e7acd13 --- /dev/null +++ b/security/manager/ssl/tests/mochitest/browser/head.js @@ -0,0 +1,9 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +function whenNewWindowLoaded(aOptions, aCallback) { + let win = OpenBrowserWindow(aOptions); + win.addEventListener("load", function onLoad() { + win.removeEventListener("load", onLoad, false); + aCallback(win); + }, false); +}