зеркало из https://github.com/mozilla/pjs.git
Bug 651534 - Use click events in test rather than a timeout. r=mfinkle
This commit is contained in:
Родитель
eb19cf63b3
Коммит
5113ad85f8
|
@ -2,7 +2,6 @@ let testURL_click = chromeRoot + "browser_click_content.html";
|
||||||
|
|
||||||
let currentTab;
|
let currentTab;
|
||||||
let element;
|
let element;
|
||||||
let isClickFired = false;
|
|
||||||
let clickPosition = { x: null, y: null};
|
let clickPosition = { x: null, y: null};
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
@ -24,7 +23,6 @@ function test() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function clickFired(aEvent) {
|
function clickFired(aEvent) {
|
||||||
isClickFired = true;
|
|
||||||
let [x, y] = browserViewToClient(aEvent.clientX, aEvent.clientY);
|
let [x, y] = browserViewToClient(aEvent.clientX, aEvent.clientY);
|
||||||
clickPosition.x = x;
|
clickPosition.x = x;
|
||||||
clickPosition.y = y;
|
clickPosition.y = y;
|
||||||
|
@ -37,29 +35,30 @@ function testClickAndPosition() {
|
||||||
|
|
||||||
// Check click
|
// Check click
|
||||||
element = currentTab.browser.contentDocument.getElementById("iframe-1");
|
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);
|
EventUtils.synthesizeMouseForContent(element, 1, 1, {}, window);
|
||||||
waitFor(checkClick, function() { return isClickFired });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkClick() {
|
function checkClick() {
|
||||||
ok(isClickFired, "Click handler fired");
|
|
||||||
element.removeEventListener("click", clickFired, true);
|
|
||||||
|
|
||||||
// Check position
|
// Check position
|
||||||
isClickFired = false;
|
|
||||||
element = currentTab.browser.contentDocument.documentElement;
|
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);
|
let rect = getBoundingContentRect(element);
|
||||||
EventUtils.synthesizeMouse(element, 1, rect.height + 10, {}, window);
|
EventUtils.synthesizeMouse(element, 1, rect.height + 10, {}, window);
|
||||||
waitFor(checkPosition, function() { return isClickFired });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkPosition() {
|
function checkPosition() {
|
||||||
element.removeEventListener("click", clickFired, true);
|
|
||||||
|
|
||||||
let rect = getBoundingContentRect(element);
|
let rect = getBoundingContentRect(element);
|
||||||
is(clickPosition.x, 1, "X position is correct");
|
is(clickPosition.x, 1, "X position is correct");
|
||||||
is(clickPosition.y, rect.height + 10, "Y position is correct");
|
is(clickPosition.y, rect.height + 10, "Y position is correct");
|
||||||
|
|
Загрузка…
Ссылка в новой задаче