Bug 739217 - Part 7: Browser sanitize replacements of synchronous isVisited with asynchronous isURIVisited. r=mak
authorAndres Hernandez <andres@appcoast.com>
Mon, 04 Feb 2013 15:08:51 -0600
changeset 130750 d21ebe0febbe03f0da0717de7cef370c5a6d3156
parent 130749 e79d18652d56ffea3e59d96f163faec52c7e7642
child 130751 5490d8c52ff47f0d8729f62675546b6ae575860e
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs739217
milestone21.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 739217 - Part 7: Browser sanitize replacements of synchronous isVisited with asynchronous isURIVisited. r=mak
browser/base/content/test/browser_sanitizeDialog.js
browser/base/content/test/browser_sanitizeDialog_treeView.js
browser/base/content/test/head.js
--- a/browser/base/content/test/browser_sanitizeDialog.js
+++ b/browser/base/content/test/browser_sanitizeDialog.js
@@ -72,20 +72,21 @@ var gAllTests = [
         // Show details
         this.toggleDetails();
         this.checkDetails(true);
 
         // Hide details
         this.toggleDetails();
         this.checkDetails(false);
         this.cancelDialog();
-
-        ensureHistoryClearedState(uris, false);
+      };
+      wh.onunload = function () {
+        yield promiseHistoryClearedState(uris, false);
         blankSlate();
-        ensureHistoryClearedState(uris, true);
+        yield promiseHistoryClearedState(uris, true);
       };
       wh.open();
     });
   },
 
   /**
    * Ensures that the combined history-downloads checkbox clears both history
    * visits and downloads when checked; the dialog respects simple timespan.
@@ -131,28 +132,29 @@ var gAllTests = [
                   "timeSpan pref should be hour after accepting dialog with " +
                   "hour selected");
         boolPrefIs("cpd.history", true,
                    "history pref should be true after accepting dialog with " +
                    "history checkbox checked");
         boolPrefIs("cpd.downloads", true,
                    "downloads pref should be true after accepting dialog with " +
                    "history checkbox checked");
-
+      };
+      wh.onunload = function () {
         // History visits and downloads within one hour should be cleared.
-        ensureHistoryClearedState(uris, true);
+        yield promiseHistoryClearedState(uris, true);
         ensureDownloadsClearedState(downloadIDs, true);
 
         // Visits and downloads > 1 hour should still exist.
-        ensureHistoryClearedState(olderURIs, false);
+        yield promiseHistoryClearedState(olderURIs, false);
         ensureDownloadsClearedState(olderDownloadIDs, false);
 
         // OK, done, cleanup after ourselves.
         blankSlate();
-        ensureHistoryClearedState(olderURIs, true);
+        yield promiseHistoryClearedState(olderURIs, true);
         ensureDownloadsClearedState(olderDownloadIDs, true);
       };
       wh.open();
     });
   },
 
   /**
    * Ensures that the combined history-downloads checkbox removes neither
@@ -195,25 +197,26 @@ var gAllTests = [
                   "timeSpan pref should be hour after accepting dialog with " +
                   "hour selected");
         boolPrefIs("cpd.history", false,
                    "history pref should be false after accepting dialog with " +
                    "history checkbox unchecked");
         boolPrefIs("cpd.downloads", false,
                    "downloads pref should be false after accepting dialog with " +
                    "history checkbox unchecked");
-
+      };
+      wh.onunload = function () {
         // Of the three only form entries should be cleared.
-        ensureHistoryClearedState(uris, false);
+        yield promiseHistoryClearedState(uris, false);
         ensureDownloadsClearedState(downloadIDs, false);
         ensureFormEntriesClearedState(formEntries, true);
 
         // OK, done, cleanup after ourselves.
         blankSlate();
-        ensureHistoryClearedState(uris, true);
+        yield promiseHistoryClearedState(uris, true);
         ensureDownloadsClearedState(downloadIDs, true);
       };
       wh.open();
     });
   },
 
   /**
    * Ensures that the "Everything" duration option works.
@@ -248,17 +251,19 @@ var gAllTests = [
         this.toggleDetails();
         this.checkDetails(true);
 
         this.acceptDialog();
 
         intPrefIs("sanitize.timeSpan", Sanitizer.TIMESPAN_EVERYTHING,
                   "timeSpan pref should be everything after accepting dialog " +
                   "with everything selected");
-        ensureHistoryClearedState(uris, true);
+      };
+      wh.onunload = function () {
+        yield promiseHistoryClearedState(uris, true);
       };
       wh.open();
     });
   },
 
   /**
    * Ensures that the "Everything" warning is visible on dialog open after
    * the previous test.
@@ -283,17 +288,19 @@ var gAllTests = [
            "with clearing everything");
         this.selectDuration(Sanitizer.TIMESPAN_EVERYTHING);
         this.checkPrefCheckbox("history", true);
         this.acceptDialog();
 
         intPrefIs("sanitize.timeSpan", Sanitizer.TIMESPAN_EVERYTHING,
                   "timeSpan pref should be everything after accepting dialog " +
                   "with everything selected");
-        ensureHistoryClearedState(uris, true);
+      };
+      wh.onunload = function () {
+        yield promiseHistoryClearedState(uris, true);
       };
       wh.open();
     });
   },
 
   /**
    * The next three tests checks that when a certain history item cannot be
    * cleared then the checkbox should be both disabled and unchecked.
@@ -316,18 +323,19 @@ var gAllTests = [
 
         var cb = this.win.document.querySelectorAll(
                    "#itemList > [preference='privacy.cpd.history']");
         ok(cb.length == 1 && !cb[0].disabled, "There is history, checkbox to " +
            "clear history should be enabled.");
 
         this.checkAllCheckboxes();
         this.acceptDialog();
-
-        ensureHistoryClearedState(uris, true);
+      };
+      wh.onunload = function () {
+        yield promiseHistoryClearedState(uris, true);
         ensureFormEntriesClearedState(formEntries, true);
       };
       wh.open();
     });
   },
   function () {
     let wh = new WindowHelper();
     wh.onload = function() {
@@ -368,16 +376,18 @@ var gAllTests = [
 
       var cb = this.win.document.querySelectorAll(
                  "#itemList > [preference='privacy.cpd.formdata']");
       ok(cb.length == 1 && !cb[0].disabled && cb[0].checked,
          "There exists formEntries so the checkbox should be in sync with " +
          "the pref.");
 
       this.acceptDialog();
+    };
+    wh.onunload = function () {
       ensureFormEntriesClearedState(formEntries, true);
     };
     wh.open();
   },
 
 
   /**
    * These next six tests together ensure that toggling details persists
@@ -778,19 +788,23 @@ WindowHelper.prototype = {
 
         win.removeEventListener("unload", onunload, false);
         wh.win = win;
 
         executeSoon(function () {
           // Some exceptions that reach here don't reach the test harness, but
           // ok()/is() do...
           try {
-            if (wh.onunload)
-              wh.onunload();
-            waitForAsyncUpdates(doNextTest);
+            if (wh.onunload) {
+              Task.spawn(wh.onunload).then(function() {
+                waitForAsyncUpdates(doNextTest);
+              });
+            } else {
+              waitForAsyncUpdates(doNextTest);
+            }
           }
           catch (exc) {
             win.close();
             ok(false, "Unexpected exception: " + exc + "\n" + exc.stack);
             finish();
           }
         });
       }, false);
@@ -980,32 +994,16 @@ function ensureFormEntriesClearedState(a
   let niceStr = aShouldBeCleared ? "no longer" : "still";
   aFormEntries.forEach(function (entry) {
     is(formhist.nameExists(entry), !aShouldBeCleared,
        "form entry " + entry + " should " + niceStr + " exist");
   });
 }
 
 /**
- * Ensures that the specified URIs are either cleared or not.
- *
- * @param aURIs
- *        Array of page URIs
- * @param aShouldBeCleared
- *        True if each visit to the URI should be cleared, false otherwise
- */
-function ensureHistoryClearedState(aURIs, aShouldBeCleared) {
-  let niceStr = aShouldBeCleared ? "no longer" : "still";
-  aURIs.forEach(function (aURI) {
-    is(PlacesUtils.bhistory.isVisited(aURI), !aShouldBeCleared,
-       "history visit " + aURI.spec + " should " + niceStr + " exist");
-  });
-}
-
-/**
  * Ensures that the given pref is the expected value.
  *
  * @param aPrefName
  *        The pref's sub-branch under the privacy branch
  * @param aExpectedVal
  *        The pref's expected value
  * @param aMsg
  *        Passed to is()
--- a/browser/base/content/test/browser_sanitizeDialog_treeView.js
+++ b/browser/base/content/test/browser_sanitizeDialog_treeView.js
@@ -72,21 +72,21 @@ var gAllTests = [
         wh.checkGrippy("Grippy should remain at last row after trying to move " +
                        "it down",
                        wh.getRowCount() - 1);
 
         // Cancel the dialog, make sure history visits are not cleared.
         wh.checkPrefCheckbox("history", false);
 
         wh.cancelDialog();
-        ensureHistoryClearedState(uris, false);
+        yield promiseHistoryClearedState(uris, false);
 
         // OK, done, cleanup after ourselves.
         blankSlate();
-        ensureHistoryClearedState(uris, true);
+        yield promiseHistoryClearedState(uris, true);
       });
     });
   },
 
   /**
    * Ensures that the combined history-downloads checkbox clears both history
    * visits and downloads when checked; the dialog respects simple timespan.
    */
@@ -128,26 +128,26 @@ var gAllTests = [
         wh.checkGrippy("Grippy should be at proper row after selecting HOUR " +
                        "duration",
                        uris.length);
 
         // Accept the dialog, make sure history visits and downloads within one
         // hour are cleared.
         wh.checkPrefCheckbox("history", true);
         wh.acceptDialog();
-        ensureHistoryClearedState(uris, true);
+        yield promiseHistoryClearedState(uris, true);
         ensureDownloadsClearedState(downloadIDs, true);
 
         // Make sure visits and downloads > 1 hour still exist.
-        ensureHistoryClearedState(olderURIs, false);
+        yield promiseHistoryClearedState(olderURIs, false);
         ensureDownloadsClearedState(olderDownloadIDs, false);
 
         // OK, done, cleanup after ourselves.
         blankSlate();
-        ensureHistoryClearedState(olderURIs, true);
+        yield promiseHistoryClearedState(olderURIs, true);
         ensureDownloadsClearedState(olderDownloadIDs, true);
       });
     });
   },
 
   /**
    * Ensures that the combined history-downloads checkbox removes neither
    * history visits nor downloads when not checked.
@@ -182,23 +182,23 @@ var gAllTests = [
                        wh.getRowCount() - 1);
 
         // Remove only form entries, leave history (including downloads).
         wh.checkPrefCheckbox("history", false);
         wh.checkPrefCheckbox("formdata", true);
         wh.acceptDialog();
 
         // Of the three only form entries should be cleared.
-        ensureHistoryClearedState(uris, false);
+        yield promiseHistoryClearedState(uris, false);
         ensureDownloadsClearedState(downloadIDs, false);
         ensureFormEntriesClearedState(formEntries, true);
 
         // OK, done, cleanup after ourselves.
         blankSlate();
-        ensureHistoryClearedState(uris, true);
+        yield promiseHistoryClearedState(uris, true);
         ensureDownloadsClearedState(downloadIDs, true);
       });
     });
   },
 
   /**
    * Ensures that the "Everything" duration option works.
    */
@@ -217,17 +217,17 @@ var gAllTests = [
     addVisits(places, function() {
 
       // Open the dialog and do our tests.
       openWindow(function (aWin) {
         let wh = new WindowHelper(aWin);
         wh.selectDuration(Sanitizer.TIMESPAN_EVERYTHING);
         wh.checkPrefCheckbox("history", true);
         wh.acceptDialog();
-        ensureHistoryClearedState(uris, true);
+        yield promiseHistoryClearedState(uris, true);
       });
     });
   }
 ];
 
 // Used as the download database ID for a new download.  Incremented for each
 // new download.  See addDownloadWithMinutesAgo().
 var gDownloadId = 5555551;
@@ -567,32 +567,16 @@ function ensureFormEntriesClearedState(a
   let niceStr = aShouldBeCleared ? "no longer" : "still";
   aFormEntries.forEach(function (entry) {
     is(formhist.nameExists(entry), !aShouldBeCleared,
        "form entry " + entry + " should " + niceStr + " exist");
   });
 }
 
 /**
- * Ensures that the specified URIs are either cleared or not.
- *
- * @param aURIs
- *        Array of page URIs
- * @param aShouldBeCleared
- *        True if each visit to the URI should be cleared, false otherwise
- */
-function ensureHistoryClearedState(aURIs, aShouldBeCleared) {
-  let niceStr = aShouldBeCleared ? "no longer" : "still";
-  aURIs.forEach(function (aURI) {
-    is(PlacesUtils.bhistory.isVisited(aURI), !aShouldBeCleared,
-       "history visit " + aURI.spec + " should " + niceStr + " exist");
-  });
-}
-
-/**
  * Opens the sanitize dialog and runs a callback once it's finished loading.
  * 
  * @param aOnloadCallback
  *        A function that will be called once the dialog has loaded
  */
 function openWindow(aOnloadCallback) {
   function windowObserver(aSubject, aTopic, aData) {
     if (aTopic != "domwindowopened")
@@ -601,18 +585,21 @@ function openWindow(aOnloadCallback) {
     Services.ww.unregisterNotification(windowObserver);
     let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
     win.addEventListener("load", function onload(event) {
       win.removeEventListener("load", onload, false);
       executeSoon(function () {
         // Some exceptions that reach here don't reach the test harness, but
         // ok()/is() do...
         try {
-          aOnloadCallback(win);
-          waitForAsyncUpdates(doNextTest);
+          Task.spawn(function() {
+            aOnloadCallback(win);
+          }).then(function() {
+            waitForAsyncUpdates(doNextTest);
+          });
         }
         catch (exc) {
           win.close();
           ok(false, "Unexpected exception: " + exc + "\n" + exc.stack);
           finish();
         }
       });
     }, false);
--- a/browser/base/content/test/head.js
+++ b/browser/base/content/test/head.js
@@ -230,8 +230,35 @@ function addVisits(aPlaceInfo, aCallback
       handleResult: function () {},
       handleCompletion: function UP_handleCompletion() {
         if (aCallback)
           aCallback();
       }
     }
   );
 }
+
+/**
+ * Ensures that the specified URIs are either cleared or not.
+ *
+ * @param aURIs
+ *        Array of page URIs
+ * @param aShouldBeCleared
+ *        True if each visit to the URI should be cleared, false otherwise
+ */
+function promiseHistoryClearedState(aURIs, aShouldBeCleared) {
+  let deferred = Promise.defer();
+  let callbackCount = 0;
+  let niceStr = aShouldBeCleared ? "no longer" : "still";
+  function callbackDone() {
+    if (++callbackCount == aURIs.length)
+      deferred.resolve();
+  }
+  aURIs.forEach(function (aURI) {
+    PlacesUtils.asyncHistory.isURIVisited(aURI, function(aURI, aIsVisited) {
+      is(aIsVisited, !aShouldBeCleared,
+         "history visit " + aURI.spec + " should " + niceStr + " exist");
+      callbackDone();
+    });
+  });
+
+  return deferred.promise;
+}