Unit test bustage fix from bug 672681 for apps without private browser and that don't have places enabled by default. r=unit-test only bustage fix
authorMark Banner <bugzilla@standard8.plus.com>
Sat, 21 Jan 2012 11:00:18 +0000
changeset 86263 8c664c7ecb7943de6b05ea6c88b0a4d9cf208b10
parent 86262 e46cca5066131e6a86c3ac2989572d179150d10b
child 86264 bf4edffd939497bafb3ec96a7cd7e983966c0a39
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersunit-test
bugs672681
milestone12.0a1
Unit test bustage fix from bug 672681 for apps without private browser and that don't have places enabled by default. r=unit-test only bustage fix
toolkit/components/places/tests/unit/test_download_history.js
--- a/toolkit/components/places/tests/unit/test_download_history.js
+++ b/toolkit/components/places/tests/unit/test_download_history.js
@@ -119,50 +119,46 @@ add_test(function test_dh_addDownload_re
     uri: REFERRER_URI,
     visits: [{
       transitionType: Ci.nsINavHistoryService.TRANSITION_TYPED,
       visitDate: Date.now() * 1000
     }]
   });
 });
 
-add_test(function test_dh_addDownload_privateBrowsing()
-{
-  if (!("@mozilla.org/privatebrowsing;1" in Cc)) {
-    todo(false, "PB service is not available, bail out");
-    run_next_test();
-    return;
-  }
+if ("@mozilla.org/privatebrowsing;1" in Cc) {
+  add_test(function test_dh_addDownload_privateBrowsing()
+  {
+    waitForOnVisit(function DHAD_onVisit(aURI) {
+      // We should only receive the notification for the non-private URI.  This
+      // test is based on the assumption that visit notifications are received
+      // in the same order of the addDownload calls, which is currently true
+      // because database access is serialized on the same worker thread.
+      do_check_true(aURI.equals(DOWNLOAD_URI));
 
-  waitForOnVisit(function DHAD_onVisit(aURI) {
-    // We should only receive the notification for the non-private URI.  This
-    // test is based on the assumption that visit notifications are received in
-    // the same order of the addDownload calls, which is currently true because
-    // database access is serialized on the same worker thread.
-    do_check_true(aURI.equals(DOWNLOAD_URI));
+      uri_in_db(DOWNLOAD_URI, true);
+      uri_in_db(PRIVATE_URI, false);
 
-    uri_in_db(DOWNLOAD_URI, true);
-    uri_in_db(PRIVATE_URI, false);
-
-    waitForClearHistory(run_next_test);
-  });
+      waitForClearHistory(run_next_test);
+    });
 
-  let pb = Cc["@mozilla.org/privatebrowsing;1"]
-           .getService(Ci.nsIPrivateBrowsingService);
-  Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session",
-                             true);
-  pb.privateBrowsingEnabled = true;
-  gDownloadHistory.addDownload(PRIVATE_URI, REFERRER_URI, Date.now() * 1000);
+    let pb = Cc["@mozilla.org/privatebrowsing;1"]
+             .getService(Ci.nsIPrivateBrowsingService);
+    Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session",
+                               true);
+    pb.privateBrowsingEnabled = true;
+    gDownloadHistory.addDownload(PRIVATE_URI, REFERRER_URI, Date.now() * 1000);
 
-  // The addDownload functions calls CanAddURI synchronously, thus we can exit
-  // Private Browsing Mode immediately.
-  pb.privateBrowsingEnabled = false;
-  Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
-  gDownloadHistory.addDownload(DOWNLOAD_URI, REFERRER_URI, Date.now() * 1000);
-});
+    // The addDownload functions calls CanAddURI synchronously, thus we can
+    // exit Private Browsing Mode immediately.
+    pb.privateBrowsingEnabled = false;
+    Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
+    gDownloadHistory.addDownload(DOWNLOAD_URI, REFERRER_URI, Date.now() * 1000);
+  });
+}
 
 add_test(function test_dh_addDownload_disabledHistory()
 {
   waitForOnVisit(function DHAD_onVisit(aURI) {
     // We should only receive the notification for the non-private URI.  This
     // test is based on the assumption that visit notifications are received in
     // the same order of the addDownload calls, which is currently true because
     // database access is serialized on the same worker thread.
@@ -172,19 +168,20 @@ add_test(function test_dh_addDownload_di
     uri_in_db(PRIVATE_URI, false);
 
     waitForClearHistory(run_next_test);
   });
 
   Services.prefs.setBoolPref("places.history.enabled", false);
   gDownloadHistory.addDownload(PRIVATE_URI, REFERRER_URI, Date.now() * 1000);
 
-  // The addDownload functions calls CanAddURI synchronously, thus we can reset
-  // the preference immediately.
-  Services.prefs.clearUserPref("places.history.enabled");
+  // The addDownload functions calls CanAddURI synchronously, thus we can set
+  // the preference back to true immediately (not all apps enable places by
+  // default).
+  Services.prefs.setBoolPref("places.history.enabled", true);
   gDownloadHistory.addDownload(DOWNLOAD_URI, REFERRER_URI, Date.now() * 1000);
 });
 
 /**
  * Tests that nsIDownloadHistory::AddDownload saves the additional download
  * details if the optional destination URL is specified.
  */
 add_test(function test_dh_details()