Bug 651534 - Use click events in test rather than a timeout. r=mfinkle
authorWes Johnston <wjohnston@mozilla.com>
Fri, 22 Apr 2011 16:06:07 -0700
changeset 68570 83b7d7837e6b6b2f66e592ff7a5f3c75c8be70fc
parent 68569 9b17b766116db33212b72853482bd2e6c691e594
child 68571 6edb7954577c50be56898bbed69f195e98e0ded5
push id99
push usereakhgari@mozilla.com
push dateTue, 24 May 2011 18:03:59 +0000
treeherdermozilla-aurora@26d6981b3d6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs651534
milestone6.0a1
Bug 651534 - Use click events in test rather than a timeout. r=mfinkle
mobile/chrome/tests/browser_click_content.js
--- a/mobile/chrome/tests/browser_click_content.js
+++ b/mobile/chrome/tests/browser_click_content.js
@@ -1,13 +1,12 @@
 let testURL_click = chromeRoot + "browser_click_content.html";
 
 let currentTab;
 let element;
-let isClickFired = false;
 let clickPosition = { x: null, y: null};
 
 //------------------------------------------------------------------------------
 // Entry point (must be named "test")
 function test() {
   // This test is async
   waitForExplicitFinish();
 
@@ -19,52 +18,52 @@ function test() {
   messageManager.addMessageListener("pageshow", function() {
   if (currentTab.browser.currentURI.spec == testURL_click) {
     messageManager.removeMessageListener("pageshow", arguments.callee);
     testClickAndPosition();
   }});
 }
 
 function clickFired(aEvent) {
-  isClickFired = true;
   let [x, y] = browserViewToClient(aEvent.clientX, aEvent.clientY);
   clickPosition.x = x;
   clickPosition.y = y;
 }
 
 function testClickAndPosition() {
   // Do sanity tests
   let uri = currentTab.browser.currentURI.spec;
   is(uri, testURL_click, "URL Matches newly created Tab");
 
   // Check click
   element = currentTab.browser.contentDocument.getElementById("iframe-1");
-  element.addEventListener("click", clickFired, true);
+  element.addEventListener("click", function(aEvent) {
+    element.removeEventListener("click", arguments.callee, true);
+    clickFired(aEvent);
+    is(aEvent.type, "click", "Click fired");
+    checkClick();
+  }, true);
 
   EventUtils.synthesizeMouseForContent(element, 1, 1, {}, window);
-  waitFor(checkClick, function() { return isClickFired });
 }
 
 function checkClick() {
-  ok(isClickFired, "Click handler fired");
-  element.removeEventListener("click", clickFired, true);
-
   // Check position
-  isClickFired = false;
   element = currentTab.browser.contentDocument.documentElement;
-  element.addEventListener("click", clickFired, true);
+  element.addEventListener("click", function(aEvent) {
+    element.removeEventListener("click", arguments.callee, true);
+    clickFired(aEvent);
+    checkPosition();
+  }, true);
 
   let rect = getBoundingContentRect(element);
   EventUtils.synthesizeMouse(element, 1, rect.height + 10, {}, window);
-  waitFor(checkPosition, function() { return isClickFired });
 }
 
 function checkPosition() {
-  element.removeEventListener("click", clickFired, true);
-
   let rect = getBoundingContentRect(element);
   is(clickPosition.x, 1, "X position is correct");
   is(clickPosition.y, rect.height + 10, "Y position is correct");
 
   checkThickBorder();
 }
 
 function checkThickBorder() {