Bug 551538 - intermittend timeout in browser_bookmarksProperties.js
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 03 Mar 2011 13:51:03 +0100
changeset 63316 779f2ca8eb0c
parent 63315 61d11ecb169b
child 63317 195a7aceb72b
push idunknown
push userunknown
push dateunknown
bugs551538
milestone2.0b13pre
Bug 551538 - intermittend timeout in browser_bookmarksProperties.js r=sdwilsh a=tests-only
browser/components/places/tests/browser/browser_bookmarksProperties.js
--- a/browser/components/places/tests/browser/browser_bookmarksProperties.js
+++ b/browser/components/places/tests/browser/browser_bookmarksProperties.js
@@ -195,16 +195,17 @@ gTests.push({
 
 gTests.push({
   desc: "Bug 462662 - Pressing Enter to select tag from autocomplete closes bookmarks properties dialog",
   sidebar: SIDEBAR_BOOKMARKS_ID,
   action: ACTION_EDIT,
   itemType: null,
   window: null,
   _itemId: null,
+  _cleanShutdown: false,
 
   setup: function() {
     // Add a bookmark in unsorted bookmarks folder.
     this._itemId = add_bookmark(PlacesUtils._uri(TEST_URL));
     ok(this._itemId > 0, "Correctly added a bookmark");
     // Add a tag to this bookmark.
     PlacesUtils.tagging.tagURI(PlacesUtils._uri(TEST_URL),
                                ["testTag"]);
@@ -217,41 +218,37 @@ gTests.push({
     is(tree.selectedNode.itemId, this._itemId, "Bookmark has been selected");
   },
 
   run: function() {
     // open tags autocomplete and press enter
     var tagsField = this.window.document.getElementById("editBMPanel_tagsField");
     var self = this;
 
-    function windowObserver(aSubject, aTopic, aData) {
-      if (aTopic == "domwindowclosed" &&
-          aSubject.QueryInterface(Ci.nsIDOMWindow).location == DIALOG_URL) {
-        ww.unregisterNotification(windowObserver);
-        tagsField.popup.removeEventListener("popuphidden", popupListener, true);
-        ok(false, "Dialog window should not be closed by pressing Enter on the autocomplete popup");
+    this.window.addEventListener("unload", function(event) {
+      self.window.removeEventListener("unload", arguments.callee, true);
+      tagsField.popup.removeEventListener("popuphidden", popupListener, true);
+      ok(self._cleanShutdown, "Dialog window should not be closed by pressing Enter on the autocomplete popup");
+      executeSoon(function () {
         self.finish();
-      }
-    }
+      });
+    }, true);
 
     var popupListener = {
       handleEvent: function(aEvent) {
         switch (aEvent.type) {
           case "popuphidden":
             // Everything worked fine, we can stop observing the window.
-            ww.unregisterNotification(windowObserver);
-            tagsField.popup.removeEventListener("popuphidden", this, true);
+            self._cleanShutdown = true;
             self.window.document.documentElement.cancelDialog();
-            self.finish();
             break;
           case "popupshown":
             tagsField.popup.removeEventListener("popupshown", this, true);
-            // In case this test fails the window will close, we should mark the
-            // failure and continue, to avoid timing out.
-            ww.registerNotification(windowObserver);
+            // In case this test fails the window will close, the test will fail
+            // since we didn't set _cleanShutdown.
             var tree = tagsField.popup.tree;
             // Focus and select first result.
             isnot(tree, null, "Autocomplete results tree exists");
             is(tree.view.rowCount, 1, "We have 1 autocomplete result");
             tagsField.popup.selectedIndex = 0;
             is(tree.view.selection.count, 1,
                "We have selected a tag from the autocomplete popup");
             info("About to focus the autocomplete results tree");
@@ -313,22 +310,24 @@ gTests.push({
   },
 
   run: function() {
     this._itemId = this.window.gEditItemOverlay._itemId;
     // Change folder name
     var namePicker = this.window.document.getElementById("editBMPanel_namePicker");
     var userEnteredName = this.window.document.getElementById("editBMPanel_userEnteredName");
     var self = this;
+
     this.window.addEventListener("unload", function(event) {
-        this.window.removeEventListener("unload", arguments.callee, false);
-        executeSoon(function() {
-          self.finish();
-        });
-      }, false);
+      self.window.removeEventListener("unload", arguments.callee, false);
+      executeSoon(function () {
+        self.finish();
+      });
+    }, false);
+
     namePicker.value = "n";
     userEnteredName.label = "n";
     info("About to focus the namePicker field");
     namePicker.focus();
     EventUtils.synthesizeKey("VK_RETURN", {}, this.window);
   },
 
   finish: function() {
@@ -352,16 +351,17 @@ gTests.push({
 
 gTests.push({
   desc: "Bug 476020 - Pressing Esc while having the tag autocomplete open closes the bookmarks panel",
   sidebar: SIDEBAR_BOOKMARKS_ID,
   action: ACTION_EDIT,
   itemType: null,
   window: null,
   _itemId: null,
+  _cleanShutdown: false,
 
   setup: function() {
     // Add a bookmark in unsorted bookmarks folder.
     this._itemId = add_bookmark(PlacesUtils._uri(TEST_URL));
     ok(this._itemId > 0, "Correctly added a bookmark");
     // Add a tag to this bookmark.
     PlacesUtils.tagging.tagURI(PlacesUtils._uri(TEST_URL),
                                ["testTag"]);
@@ -374,41 +374,37 @@ gTests.push({
     is(tree.selectedNode.itemId, this._itemId, "Bookmark has been selected");
   },
 
   run: function() {
     // open tags autocomplete and press enter
     var tagsField = this.window.document.getElementById("editBMPanel_tagsField");
     var self = this;
 
-    function windowObserver(aSubject, aTopic, aData) {
-      if (aTopic == "domwindowclosed" &&
-          aSubject.QueryInterface(Ci.nsIDOMWindow).location == DIALOG_URL) {
-        ww.unregisterNotification(windowObserver);
-        tagsField.popup.removeEventListener("popuphidden", popupListener, true);
-        ok(false, "Dialog window should not be closed by pressing Escape on the autocomplete popup");
+    this.window.addEventListener("unload", function(event) {
+      self.window.removeEventListener("unload", arguments.callee, true);
+      tagsField.popup.removeEventListener("popuphidden", popupListener, true);
+      ok(self._cleanShutdown, "Dialog window should not be closed by pressing Escape on the autocomplete popup");
+      executeSoon(function () {
         self.finish();
-      }
-    }
+      });
+    }, true);
 
     var popupListener = {
       handleEvent: function(aEvent) {
         switch (aEvent.type) {
           case "popuphidden":
-            // Everything worked fine, we can stop observing the window.
-            ww.unregisterNotification(windowObserver);
-            tagsField.popup.removeEventListener("popuphidden", this, true);
+            // Everything worked fine.
+            self._cleanShutdown = true;
             self.window.document.documentElement.cancelDialog();
-            self.finish();
             break;
           case "popupshown":
             tagsField.popup.removeEventListener("popupshown", this, true);
-            // In case this test fails the window will close, we should mark the
-            // failure and continue, to avoid timing out.
-            ww.registerNotification(windowObserver);
+            // In case this test fails the window will close, the test will fail
+            // since we didn't set _cleanShutdown.
             var tree = tagsField.popup.tree;
             // Focus and select first result.
             isnot(tree, null, "Autocomplete results tree exists");
             is(tree.view.rowCount, 1, "We have 1 autocomplete result");
             tagsField.popup.selectedIndex = 0;
             is(tree.view.selection.count, 1,
                "We have selected a tag from the autocomplete popup");
             info("About to focus the autocomplete results tree");
@@ -474,26 +470,23 @@ gTests.push({
   },
 
   run: function() {
     // Open folder selector.
     var foldersExpander = this.window.document.getElementById("editBMPanel_foldersExpander");
     var folderTree = this.window.document.getElementById("editBMPanel_folderTree");
     var self = this;
 
-    function windowObserver(aSubject, aTopic, aData) {
-      if (aTopic == "domwindowclosed" &&
-          aSubject.QueryInterface(Ci.nsIDOMWindow).location == DIALOG_URL_MINIMAL_UI) {
-        ww.unregisterNotification(windowObserver);
-        ok(self._cleanShutdown,
-           "Dialog window should not be closed by pressing ESC in folder name textbox");
+    this.window.addEventListener("unload", function(event) {
+      self.window.removeEventListener("unload", arguments.callee, true);
+      ok(self._cleanShutdown, "Dialog window should not be closed by pressing ESC in folder name textbox");
+      executeSoon(function () {
         self.finish();
-      }
-    }
-    ww.registerNotification(windowObserver);
+      });
+    }, true);
 
     folderTree.addEventListener("DOMAttrModified", function onDOMAttrModified(event) {
       if (event.attrName != "place")
         return;
       folderTree.removeEventListener("DOMAttrModified", arguments.callee, false);
       executeSoon(function () {
         // Create a new folder.
         var newFolderButton = self.window.document.getElementById("editBMPanel_newFolderButton");