Bug 613403 - Fix existing tests to work with tab-modal prompt changes. r=ehsan, a=testsonly
authorJustin Dolske <dolske@mozilla.com>
Fri, 19 Nov 2010 15:15:27 -0800
changeset 57928 bbc4273845eb1bd1c7133a5416ec0fb1450e9213
parent 57927 5c6fa4a5c3da3251baa57efe71eb4423b92aeb29
child 57929 9f934ed430c3cc3166ceb8daae9ab9c4ab02959c
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersehsan, testsonly
bugs613403
milestone2.0b8pre
Bug 613403 - Fix existing tests to work with tab-modal prompt changes. r=ehsan, a=testsonly
browser/components/places/tests/browser/browser_sidebarpanels_click.js
editor/libeditor/text/tests/test_bug569988.html
--- a/browser/components/places/tests/browser/browser_sidebarpanels_click.js
+++ b/browser/components/places/tests/browser/browser_sidebarpanels_click.js
@@ -40,18 +40,18 @@
 
 function test() {
   const BOOKMARKS_SIDEBAR_ID = "viewBookmarksSidebar";
   const BOOKMARKS_SIDEBAR_TREE_ID = "bookmarks-view";
   const HISTORY_SIDEBAR_ID = "viewHistorySidebar";
   const HISTORY_SIDEBAR_TREE_ID = "historyTree";
 
   // Initialization.
-  let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-           getService(Ci.nsIWindowWatcher);
+  let os = Cc["@mozilla.org/observer-service;1"].
+           getService(Ci.nsIObserverService);
   let bs = PlacesUtils.bookmarks;
   let hs = PlacesUtils.history;
   let sidebarBox = document.getElementById("sidebar-box");
   let sidebar = document.getElementById("sidebar");
   waitForExplicitFinish();
 
   // If a sidebar is already open, close it.
   if (!sidebarBox.hidden) {
@@ -120,32 +120,30 @@ function test() {
       let tbo = tree.treeBoxObject;
 
       executeSoon(function() {
         currentTest.prepare();
         if (preFunc)
           preFunc();
 
         function observer(aSubject, aTopic, aData) {
-          if (aTopic != "domwindowopened")
-            return;
-          ww.unregisterNotification(observer);
-          let alertDialog = aSubject.QueryInterface(Ci.nsIDOMWindow);
-          alertDialog.addEventListener("load", function () {
-            alertDialog.removeEventListener("load", arguments.callee, false);
-            info("alert dialog observed as expected");
-            executeSoon(function () {
-              alertDialog.close();
+          info("alert dialog observed as expected");
+          os.removeObserver(observer, "common-dialog-loaded");
+          os.removeObserver(observer, "tabmodal-dialog-loaded");
+
+          aSubject.Dialog.ui.button0.click();
+
+          executeSoon(function () {
               toggleSidebar(currentTest.sidebarName);
               currentTest.cleanup();
               postFunc();
             });
-          }, false);
         }
-        ww.registerNotification(observer);
+        os.addObserver(observer, "common-dialog-loaded", false);
+        os.addObserver(observer, "tabmodal-dialog-loaded", false);
 
         // Select the inserted places item.
         currentTest.selectNode(tree);
         is(tbo.view.selection.count, 1,
            "The test node should be successfully selected");
         // Get its row ID.
         let min = {}, max = {};
         tbo.view.selection.getRangeAt(0, min, max);
@@ -155,17 +153,17 @@ function test() {
         // Calculate the click coordinates.
         let x = {}, y = {}, width = {}, height = {};
         tbo.getCoordsForCellItem(rowID, tree.columns[0], "text",
                                  x, y, width, height);
         x = x.value + width.value / 2;
         y = y.value + height.value / 2;
         // Simulate the click.
         EventUtils.synthesizeMouse(tree.body, x, y, {}, doc.defaultView);
-        // Now, wait for the domwindowopened observer to catch the alert dialog.
+        // Now, wait for the observer to catch the alert dialog.
         // If something goes wrong, the test will time out at this stage.
         // Note that for the history sidebar, the URL itself is not opened,
         // and Places will show the load-js-data-url-error prompt as an alert
         // box, which means that the click actually worked, so it's good enough
         // for the purpose of this test.
       });
     }, true);
     toggleSidebar(currentTest.sidebarName);
--- a/editor/libeditor/text/tests/test_bug569988.html
+++ b/editor/libeditor/text/tests/test_bug569988.html
@@ -20,93 +20,69 @@ https://bugzilla.mozilla.org/show_bug.cg
 <script type="application/javascript">
 
 /** Test for Bug 569988 **/
 
 SimpleTest.waitForExplicitFinish();
 SimpleTest.waitForFocus(runTest);
 
 var gPromptInput = null;
-var gPromptWindow = null;
 
 function runTest()
 {
   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 
-  function WindowObserver()
-  {
-    Components.classes["@mozilla.org/observer-service;1"].
-               getService(Components.interfaces.nsIObserverService).
-               addObserver(this, "domwindowopened", false);
-  }
-  WindowObserver.prototype = {
-    QueryInterface: function (iid) {
-      if (iid.equals(Components.interfaces.nsIObserver) ||
-          iid.equals(Components.interfaces.nsISupports)) {
-        return this;
-      }
-      throw Components.results.NS_ERROR_NO_INTERFACE;
-    },
+  var os = Components.classes["@mozilla.org/observer-service;1"].
+             getService(Components.interfaces.nsIObserverService);
 
-    observe: function (subject, topic, data) {
-      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-      if (topic === "domwindowopened") {
-        ok(true, "prompt window is created");
-        gPromptWindow =
-          subject.QueryInterface(Components.interfaces.nsIDOMWindow);
-        gPromptWindow.addEventListener("load", onPromptLoad, false);
-      }
-    }
-  };
+  os.addObserver(onPromptLoad, "common-dialog-loaded", false);
+  os.addObserver(onPromptLoad, "tabmodal-dialog-loaded", false);
 
-  var observer = new WindowObserver();
-
+  ok(true, "opening prompt...");
   prompt("summary", "text");
   ok(true, "prompt is closed");
 
-  Components.classes["@mozilla.org/observer-service;1"].          
-             getService(Components.interfaces.nsIObserverService).
-             removeObserver(observer, "domwindowopened");
-  SimpleTest.finish();
+  os.removeObserver(onPromptLoad, "tabmodal-dialog-loaded");
+  os.removeObserver(onPromptLoad, "common-dialog-loaded");
 }
 
-function onPromptLoad()
+function onPromptLoad(subject, topic, data)
 {
   ok(true, "onPromptLoad is called");
   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-  gPromptWindow.removeEventListener("load", onPromptLoad, false);
-  gPromptInput = gPromptWindow.document.getElementById("loginTextbox");
+  gPromptInput = subject.Dialog.ui.loginTextbox;
   gPromptInput.addEventListener("focus", onPromptFocus, false);
+  // shift focus to ensure it fires.
+  subject.Dialog.ui.button0.focus();
+  gPromptInput.focus();
 }
 
-function onPromptFocus()
-{
+function onPromptFocus() {
   ok(true, "onPromptFocus is called");
   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   gPromptInput.removeEventListener("focus", onPromptFocus, false);
+
   var systemGroup =
     Components.classes["@mozilla.org/eventlistenerservice;1"].
       getService(Components.interfaces.nsIEventListenerService).
       systemEventGroup;
   gPromptInput.QueryInterface(Components.interfaces.nsIDOM3EventTarget);
-  var isPrevented = false;
   var listener = {
     handleEvent: function _hv(aEvent)
     {
-      isPrevented = aEvent.getPreventDefault();
+      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+      var isPrevented = aEvent.getPreventDefault();
+      ok(!isPrevented, "ESC key event is prevented by editor");
+      gPromptInput.removeGroupedEventListener("keypress", listener, false,
+                                              systemGroup);
+      SimpleTest.finish();
     }
   };
   gPromptInput.addGroupedEventListener("keypress", listener, false,
                                        systemGroup);
-  synthesizeKey("VK_ESCAPE", { }, gPromptWindow);
-  gPromptInput.removeGroupedEventListener("keypress", listener, false,
-                                          systemGroup);
-
-  ok(!isPrevented, "ESC key event is prevented by editor");
-  if (isPrevented) {
-    gPromptWindow.close();
-  }
+  ok(true, "sending key");
+  synthesizeKey("VK_ESCAPE", { }, gPromptInput.ownerDocument.defaultView);
 }
 
 </script>
 </pre>
 </body>
 </html>