Bug 804690 - Skip test for bug 627234 if the Private Browsing service is not available. r=dkeeler.
authorMike Conley <mconley@mozilla.com>
Wed, 24 Oct 2012 15:00:36 -0400
changeset 111411 6ddc79908e6412c9cd31a0cc2e1b7fdb54c5fc51
parent 111410 256a32a2b634315673a7266cfcc36f82c43b7f31
child 111412 fe526c7150ebc848e2cebc8067b8f39812bee1b9
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersdkeeler
bugs804690, 627234
milestone19.0a1
Bug 804690 - Skip test for bug 627234 if the Private Browsing service is not available. r=dkeeler.
security/manager/ssl/tests/unit/test_bug627234.js
--- a/security/manager/ssl/tests/unit/test_bug627234.js
+++ b/security/manager/ssl/tests/unit/test_bug627234.js
@@ -1,61 +1,75 @@
 var Cc = Components.classes;
 var Ci = Components.interfaces;
 
 Components.utils.import("resource://gre/modules/Services.jsm");
 
-var gPBService = Cc["@mozilla.org/privatebrowsing;1"]
-                 .getService(Ci.nsIPrivateBrowsingService);
+var _PBSvc = null;
+function get_PBSvc() {
+  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) {
     do_execute_soon(gNextTest);
   }
 };
 
 var gObserver = new Observer();
 var gNextTest = null;
 
 function cleanup() {
   Services.obs.removeObserver(gObserver, "private-browsing-transition-complete");
-  gPBService.privateBrowsingEnabled = false;
+  get_PBSvc().privateBrowsingEnabled = false;
   // (we have to remove any state added to the sts service so as to not muck
   // with other tests).
   var uri = Services.io.newURI("http://localhost", null, null);
   gSTSService.removeStsState(uri);
 }
 
 function run_test() {
-  do_test_pending();
-  do_register_cleanup(cleanup);
+  let pb = get_PBSvc();
+  if (pb) {
+    do_test_pending();
+    do_register_cleanup(cleanup);
 
-  gNextTest = test_part1;
-  Services.obs.addObserver(gObserver, "private-browsing-transition-complete", false);
-  Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
-  gPBService.privateBrowsingEnabled = true;
+    gNextTest = test_part1;
+    Services.obs.addObserver(gObserver, "private-browsing-transition-complete", false);
+    Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
+    pb.privateBrowsingEnabled = true;
+  }
 }
 
 function test_part1() {
   var uri = Services.io.newURI("https://localhost/img.png", null, null);
   gSTSService.processStsHeader(uri, "max-age=1000");
   do_check_true(gSTSService.isStsHost("localhost"));
   gNextTest = test_part2;
-  gPBService.privateBrowsingEnabled = false;
+  get_PBSvc().privateBrowsingEnabled = false;
 }
 
 function test_part2() {
   var uri = Services.io.newURI("https://localhost/img.png", null, null);
   gSTSService.processStsHeader(uri, "max-age=1000");
   do_check_true(gSTSService.isStsHost("localhost"));
   gNextTest = test_part3;
-  gPBService.privateBrowsingEnabled = true;
+  get_PBSvc().privateBrowsingEnabled = true;
 }
 
 function test_part3() {
   var uri = Services.io.newURI("https://localhost/img.png", null, null);
   gSTSService.processStsHeader(uri, "max-age=1000");
   do_check_true(gSTSService.isStsHost("localhost"));
   do_test_finished();
 }