Bug 806733 - Port test_sts_preloadlist.js to the new per-window PB APIs; r=ehsan
authorAndres Hernandez <andres@appcoast.com>
Thu, 13 Dec 2012 12:15:10 -0600
changeset 125079 d0dca968428b85bee110c86e2a2c980ad7fe19f9
parent 125078 d40e4d1abffd9192c1edf0a61913eb7a23a80284
child 125080 2d2e54c90ae0902892c1b5f5c4868414471e94d3
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs806733
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 806733 - Port test_sts_preloadlist.js to the new per-window PB APIs; r=ehsan
security/manager/ssl/tests/unit/test_sts_preloadlist_perwindowpb.js
security/manager/ssl/tests/unit/xpcshell.ini
copy from security/manager/ssl/tests/unit/test_sts_preloadlist.js
copy to security/manager/ssl/tests/unit/test_sts_preloadlist_perwindowpb.js
--- a/security/manager/ssl/tests/unit/test_sts_preloadlist.js
+++ b/security/manager/ssl/tests/unit/test_sts_preloadlist_perwindowpb.js
@@ -1,70 +1,49 @@
 var Cc = Components.classes;
 var Ci = Components.interfaces;
 
 Components.utils.import("resource://gre/modules/Services.jsm");
 
-var _pbsvc;
-
-// lazy getter, added for bug 785860 to avoid testing private browsing when the
-// private browsing service doesn't exist
-function getPBSvc() {
-  if (_pbsvc)
-    return _pbsvc;
-
-  try {
-    _pbsvc = Cc["@mozilla.org/privatebrowsing;1"]
-               .getService(Ci.nsIPrivateBrowsingService);
-    return _pbsvc;
-  } catch (e) {}
-
-  return null;
-}
-
 var gSTSService = Cc["@mozilla.org/stsservice;1"]
                   .getService(Ci.nsIStrictTransportSecurityService);
 
 function Observer() {}
 Observer.prototype = {
   observe: function(subject, topic, data) {
-    run_next_test();
+    if (topic == "last-pb-context-exited")
+      run_next_test();
   }
 };
 
 var gObserver = new Observer();
 
 // This is a list of every host we call processStsHeader with
 // (we have to remove any state added to the sts service so as to not muck
 // with other tests).
 var hosts = ["http://keyerror.com", "http://subdomain.intercom.io",
              "http://subdomain.pixi.me", "http://crypto.cat",
              "http://logentries.com"];
 
 function cleanup() {
-  Services.obs.removeObserver(gObserver, "private-browsing-transition-complete");
-  if (getPBSvc())
-    getPBSvc().privateBrowsingEnabled = false;
+  Services.obs.removeObserver(gObserver, "last-pb-context-exited");
 
   for (var host of hosts) {
     var uri = Services.io.newURI(host, null, null);
     gSTSService.removeStsState(uri, 0);
   }
 }
 
 function run_test() {
   do_register_cleanup(cleanup);
-  Services.obs.addObserver(gObserver, "private-browsing-transition-complete", false);
-  Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
+  Services.obs.addObserver(gObserver, "last-pb-context-exited", false);
 
   add_test(test_part1);
-  if (getPBSvc()) {
-    add_test(test_private_browsing1);
-    add_test(test_private_browsing2);
-  }
+  add_test(test_private_browsing1);
+  add_test(test_private_browsing2);
 
   run_next_test();
 }
 
 function test_part1() {
   // check that a host not in the list is not identified as an sts host
   do_check_false(gSTSService.isStsHost("nonexistent.mozilla.com", 0));
 
@@ -143,25 +122,18 @@ function test_part1() {
   // |-- pixi.me (in preload list, includes subdomains)      IS sts host
   //     |-- subdomain.pixi.me (include subdomains is false) IS sts host
   //     |   `-- another.subdomain.pixi.me                   IS NOT sts host
   //     `-- sibling.pixi.me                                 IS sts host
   do_check_true(gSTSService.isStsHost("subdomain.pixi.me", 0));
   do_check_true(gSTSService.isStsHost("sibling.pixi.me", 0));
   do_check_false(gSTSService.isStsHost("another.subdomain.pixi.me", 0));
 
-  // Test private browsing correctly interacts with removing preloaded sites.
-  // If we don't have the private browsing service, don't run those tests
-  // (which means we have to manually call run_next_test() instead of relying
-  // on our observer to call it).
-  if (getPBSvc()) {
-    getPBSvc().privateBrowsingEnabled = true;
-  } else {
-    run_next_test();
-  }
+  // Simulate leaving private browsing mode
+  Services.obs.notifyObservers(null, "last-pb-context-exited", null);
 }
 
 const IS_PRIVATE = Ci.nsISocketProvider.NO_PERMANENT_STORAGE;
 
 function test_private_browsing1() {
   // sanity - crypto.cat is preloaded, includeSubdomains set
   do_check_true(gSTSService.isStsHost("crypto.cat", IS_PRIVATE));
   do_check_true(gSTSService.isStsHost("a.b.c.subdomain.crypto.cat", IS_PRIVATE));
@@ -193,18 +165,18 @@ function test_private_browsing1() {
   // (sanity check first - this should be in the preload list)
   do_check_true(gSTSService.isStsHost("logentries.com", IS_PRIVATE));
   var uri = Services.io.newURI("http://logentries.com", null, null);
   // according to the rfc, max-age can't be negative, but this is a great
   // way to test an expired entry
   gSTSService.processStsHeader(uri, "max-age=-1000", IS_PRIVATE);
   do_check_false(gSTSService.isStsHost("logentries.com", IS_PRIVATE));
 
-  // if this test gets this far, it means there's a private browsing service
-  getPBSvc().privateBrowsingEnabled = false;
+  // Simulate leaving private browsing mode
+  Services.obs.notifyObservers(null, "last-pb-context-exited", null);
 }
 
 function test_private_browsing2() {
   // if this test gets this far, it means there's a private browsing service
   do_check_true(gSTSService.isStsHost("crypto.cat", 0));
   // the crypto.cat entry has includeSubdomains set
   do_check_true(gSTSService.isStsHost("subdomain.crypto.cat", 0));
 
--- a/security/manager/ssl/tests/unit/xpcshell.ini
+++ b/security/manager/ssl/tests/unit/xpcshell.ini
@@ -11,9 +11,11 @@ skip-if = os == "android"
 skip-if = os == "android"
 [test_hmac.js]
 # Bug 676972: test hangs consistently on Android
 skip-if = os == "android"
 [test_bug627234.js]
 skip-if = perwindowprivatebrowsing
 [test_sts_preloadlist.js]
 skip-if = perwindowprivatebrowsing
+[test_sts_preloadlist_perwindowpb.js]
+skip-if = !perwindowprivatebrowsing
 [test_sts_preloadlist_selfdestruct.js]