Bug 651534 - Use click events in test rather than a timeout. r=mfinkle

This commit is contained in:
Wes Johnston 2011-04-22 16:06:07 -07:00
Родитель eb19cf63b3
Коммит 5113ad85f8
1 изменённых файлов: 11 добавлений и 12 удалений

Просмотреть файл

@ -2,7 +2,6 @@ let testURL_click = chromeRoot + "browser_click_content.html";
let currentTab;
let element;
let isClickFired = false;
let clickPosition = { x: null, y: null};
//------------------------------------------------------------------------------
@ -24,7 +23,6 @@ function test() {
}
function clickFired(aEvent) {
isClickFired = true;
let [x, y] = browserViewToClient(aEvent.clientX, aEvent.clientY);
clickPosition.x = x;
clickPosition.y = y;
@ -37,29 +35,30 @@ function testClickAndPosition() {
// 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");