Bug 796911 - Attempt #2 to fix Intermittent test_clear_browser_data.html. r=bz
authorMounir Lamouri <mounir.lamouri@gmail.com>
Mon, 15 Oct 2012 16:28:23 +0100
changeset 110424 49b130f753d3837eb460d296be14499c9966a603
parent 110423 7703f0ec6770271ae06a9bd2034f898439da4168
child 110425 1a3fae956dd782839400125555a0fafc5fb4d77f
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersbz
bugs796911
milestone19.0a1
Bug 796911 - Attempt #2 to fix Intermittent test_clear_browser_data.html. r=bz This patch also removes the debug statements.
dom/tests/mochitest/localstorage/frame_clear_browser_data.html
dom/tests/mochitest/localstorage/test_clear_browser_data.html
--- a/dom/tests/mochitest/localstorage/frame_clear_browser_data.html
+++ b/dom/tests/mochitest/localstorage/frame_clear_browser_data.html
@@ -1,14 +1,15 @@
 <!DOCTYPE html>
 <html>
+  <body>
+  </body>
   <script>
-    dump("\n frame created \n\n");
     addEventListener('message', function(e) {
       if (e.data == 'clear') {
         navigator.mozApps.getSelf().onsuccess = function() {
-          dump("\n clearing browser data \n\n");
           this.result.clearBrowserData();
+          document.body.innerHTML = "<done></done>";
         };
       }
     });
   </script>
 </html>
--- a/dom/tests/mochitest/localstorage/test_clear_browser_data.html
+++ b/dom/tests/mochitest/localstorage/test_clear_browser_data.html
@@ -186,45 +186,53 @@ function browserLoadEvent() {
   gBrowserStorage.localStorage = window.frames[1].frames[0].localStorage;
   gBrowserStorage.sessionStorage = window.frames[1].frames[0].sessionStorage;
 
   setupStorage(gAppStorage.localStorage);
   setupStorage(gAppStorage.sessionStorage);
   setupStorage(gBrowserStorage.localStorage);
   setupStorage(gBrowserStorage.sessionStorage);
 
-  dump("\n send message to iframe \n\n");
   frames[1].postMessage("clear", "http://www.example.com");
 
-  SimpleTest.executeSoon(function() {
-    dump("\n call getAll() \n\n");
-    navigator.mozApps.mgmt.getAll().onsuccess = function() {
-      dump("\n get getAll() results \n\n");
-      for (i in this.result) {
-        var app = this.result[i];
-        if (app.manifestURL == gManifestURL) {
-          is(gBrowserStorage.localStorage.getItem("foo"), null, "localstorage data have been deleted");
-          is(gBrowserStorage.sessionStorage.getItem("foo"), "bar", "sessionstorage data have not been deleted");
-
-          is(gAppStorage.localStorage.getItem("foo"), "bar", "data are still there");
-          is(gAppStorage.sessionStorage.getItem("foo"), "bar", "data are still there");
+  waitForClearBrowserData();
+};
 
-          is(gWitnessStorage.localStorage.getItem("foo"), "bar", "data are still there");
-          is(gWitnessStorage.sessionStorage.getItem("foo"), "bar", "data are still there");
-
-          Webapps.DOMApplicationRegistry.allAppsLaunchable = gPreviousLaunchableValue;
+function waitForClearBrowserData() {
+  SimpleTest.executeSoon(function() {
+    if (frames[1].document.getElementsByTagName('done').length == 0) {
+      waitForClearBrowserData();
+    } else {
+      checks();
+    }
+  });
+}
+function checks() {
+  navigator.mozApps.mgmt.getAll().onsuccess = function() {
+    for (i in this.result) {
+      var app = this.result[i];
+      if (app.manifestURL == gManifestURL) {
+        is(gBrowserStorage.localStorage.getItem("foo"), null, "localstorage data have been deleted");
+        is(gBrowserStorage.sessionStorage.getItem("foo"), "bar", "sessionstorage data have not been deleted");
 
-          // Now we uninstall the app and make sure everything is clean.
-          app.uninstall().onsuccess = function() {
-            finish();
-          };
-        }
+        is(gAppStorage.localStorage.getItem("foo"), "bar", "data are still there");
+        is(gAppStorage.sessionStorage.getItem("foo"), "bar", "data are still there");
+
+        is(gWitnessStorage.localStorage.getItem("foo"), "bar", "data are still there");
+        is(gWitnessStorage.sessionStorage.getItem("foo"), "bar", "data are still there");
+
+        Webapps.DOMApplicationRegistry.allAppsLaunchable = gPreviousLaunchableValue;
+
+        // Now we uninstall the app and make sure everything is clean.
+        app.uninstall().onsuccess = function() {
+          finish();
+        };
       }
-    };
-  });
+    }
+  };
 }
 
 /**
  * This method will be called when the test will be done. It is going to clear
  * all storage data, permissions, etc.
  */
 function finish() {
   gWitnessStorage.localStorage.clear();