Bug 487823 - mochitest-browser-chrome hang/timeout (1200 seconds without output) on mozilla-central Linux box, r=adw
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 30 Apr 2009 11:10:38 -0700
changeset 27922 e134b869d01c946b574c21d6bde0bd02db3c39b8
parent 27921 cb8262ea787fb45fcd644057b42dc61364ade14e
child 27924 ee67b87b2c0e4496c9b9a19f578bf246b4811b70
push id6778
push usermak77@bonardo.net
push dateThu, 30 Apr 2009 18:11:22 +0000
treeherdermozilla-central@e134b869d01c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs487823
milestone1.9.2a1pre
Bug 487823 - mochitest-browser-chrome hang/timeout (1200 seconds without output) on mozilla-central Linux box, r=adw
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
@@ -205,33 +205,71 @@ gTests.push({
     tree.selectItems([this._itemId]);
     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;
-    tagsField.popup.addEventListener("popupshown", function (aEvent) {
-        tagsField.popup.removeEventListener("popupshown", arguments.callee, true);
-        tagsField.popup.focus();
-        EventUtils.synthesizeKey("VK_RETURN", {}, self.window);
-      }, true);
-    tagsField.popup.addEventListener("popuphidden", function (aEvent) {
-        tagsField.popup.removeEventListener("popuphidden", arguments.callee, true);
-        self.finish();
-      }, true);
+
+    var windowObserver = {
+      observe: function(aSubject, aTopic, aData) {
+        if (aTopic === "domwindowclosed") {
+          ww.unregisterNotification(this);
+          tagsField.popup.removeEventListener("popuphidden", popupListener, true);
+          ok(false, "Dialog window should not be closed by pressing Enter on the autocomplete popup");
+          self.finish();
+        }
+      }
+    };
+
+    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.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);
+            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");
+            dump("About to focus the autocomplete results tree\n");
+            tree.focus();
+            EventUtils.synthesizeKey("VK_RETURN", {}, self.window);
+            break;
+          default:
+            ok(false, "unknown event: " + aEvent.type);
+            return;
+        }
+      }
+    };
+    tagsField.popup.addEventListener("popupshown", popupListener, true);
+    tagsField.popup.addEventListener("popuphidden", popupListener, true);
+
+    // Open tags autocomplete popup.
+    dump("About to focus the tagsField\n");
     tagsField.focus();
     tagsField.value = "";
     EventUtils.synthesizeKey("t", {}, this.window);
   },
 
   finish: function() {
-    isnot(this.window, null, "Window is still open");
-    this.window.document.documentElement.cancelDialog();
     toggleSidebar("viewBookmarksSidebar", false);
     runNextTest();
   },
 
   cleanup: function() {
     // Check tags have not changed.
     var tags = PlacesUtils.tagging.getTagsForURI(PlacesUtils._uri(TEST_URL), {});
     is(tags[0], "testTag", "Tag on node has not changed");
@@ -263,26 +301,28 @@ gTests.push({
     tree.selectItems([itemId]);
     this.selectedNode = tree.selectedNode;
   },
 
   run: function() {
     this._itemId = this.window.gEditItemOverlay._itemId;
     // Change folder name
     var namePicker = this.window.document.getElementById("editBMPanel_namePicker");
-    namePicker.value = "";
+    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);
+    namePicker.value = "n";
+    userEnteredName.label = "n";
+    dump("About to focus the namePicker field\n");
     namePicker.focus();
-    EventUtils.synthesizeKey("n", {}, this.window);
     EventUtils.synthesizeKey("VK_RETURN", {}, this.window);
   },
 
   finish: function() {
     // Window is already closed.
     toggleSidebar("viewBookmarksSidebar", false);
     runNextTest();
   },
@@ -323,33 +363,71 @@ gTests.push({
     tree.selectItems([this._itemId]);
     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;
-    tagsField.popup.addEventListener("popupshown", function (aEvent) {
-        tagsField.popup.removeEventListener("popupshown", arguments.callee, true);
-        tagsField.popup.focus();
-        EventUtils.synthesizeKey("VK_ESCAPE", {}, self.window);
-      }, true);
-    tagsField.popup.addEventListener("popuphidden", function (aEvent) {
-        tagsField.popup.removeEventListener("popuphidden", arguments.callee, true);
-        self.finish();
-      }, true);
+
+    var windowObserver = {
+      observe: function(aSubject, aTopic, aData) {
+        if (aTopic === "domwindowclosed") {
+          ww.unregisterNotification(this);
+          tagsField.popup.removeEventListener("popuphidden", popupListener, true);
+          ok(false, "Dialog window should not be closed by pressing Escape on the autocomplete popup");
+          self.finish();
+        }
+      }
+    };
+
+    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.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);
+            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");
+            dump("About to focus the autocomplete results tree\n");
+            tree.focus();
+            EventUtils.synthesizeKey("VK_ESCAPE", {}, self.window);
+            break;
+          default:
+            ok(false, "unknown event: " + aEvent.type);
+            return;
+        }
+      }
+    };
+    tagsField.popup.addEventListener("popupshown", popupListener, true);
+    tagsField.popup.addEventListener("popuphidden", popupListener, true);
+
+    // Open tags autocomplete popup.
+    dump("About to focus the tagsField\n");
     tagsField.focus();
     tagsField.value = "";
     EventUtils.synthesizeKey("t", {}, this.window);
   },
 
   finish: function() {
-    isnot(this.window, null, "Window is still open");
-    this.window.document.documentElement.cancelDialog();
     toggleSidebar("viewBookmarksSidebar", false);
     runNextTest();
   },
 
   cleanup: function() {
     // Check tags have not changed.
     var tags = PlacesUtils.tagging.getTagsForURI(PlacesUtils._uri(TEST_URL), {});
     is(tags[0], "testTag", "Tag on node has not changed");
@@ -359,16 +437,17 @@ gTests.push({
                                  ["testTag"]);
     PlacesUtils.bookmarks.removeItem(this._itemId);
   }
 });
 
 //------------------------------------------------------------------------------
 
 function test() {
+  dump("Starting test browser_bookmarksProperties.js\n");
   waitForExplicitFinish();
   // Sanity checks.
   ok(PlacesUtils, "PlacesUtils in context");
   ok(PlacesUIUtils, "PlacesUIUtils in context");
 
   // kick off tests
   runNextTest();
 }
@@ -379,16 +458,17 @@ function runNextTest() {
     gCurrentTest.cleanup();
     ok(true, "*** FINISHED TEST ***");
   }
 
   if (gTests.length > 0) {
     // Goto next tests.
     gCurrentTest = gTests.shift();
     ok(true, "*** TEST: " + gCurrentTest.desc);
+    dump("*** TEST: " + gCurrentTest.desc + "\n");
     gCurrentTest.setup();
     execute_test_in_sidebar();
   }
   else {
     // Finished all tests.
     finish();
   }
 }
@@ -396,17 +476,16 @@ function runNextTest() {
 /**
  * Global functions to run a test in Properties dialog context.
  */
 
 function execute_test_in_sidebar() {
     var sidebar = document.getElementById("sidebar");
     sidebar.addEventListener("load", function() {
       sidebar.removeEventListener("load", arguments.callee, true);
-      sidebar.focus();
       // Need to executeSoon since the tree is initialized on sidebar load.
       executeSoon(open_properties_dialog);
     }, true);
     toggleSidebar("viewBookmarksSidebar", true);
 }
 
 function open_properties_dialog() {
     var sidebar = document.getElementById("sidebar");