From 02b38533baf6625358f89f21294ca68de8975215 Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Fri, 28 May 2010 12:28:31 -0400 Subject: [PATCH] Bug 567098 - Remove setTimeout's in autofocus tests; r=ehsan --- content/html/content/test/file_bug546995.html | 5 ++-- .../html/content/test/test_bug546995-2.html | 13 +++++----- .../html/content/test/test_bug546995-3.html | 7 +----- .../html/content/test/test_bug546995-5.html | 18 +++++-------- .../browser/browser_autofocus_background.js | 25 ++++++------------- 5 files changed, 25 insertions(+), 43 deletions(-) diff --git a/content/html/content/test/file_bug546995.html b/content/html/content/test/file_bug546995.html index bd30c643f1f..c67b55e74ac 100644 --- a/content/html/content/test/file_bug546995.html +++ b/content/html/content/test/file_bug546995.html @@ -23,8 +23,9 @@ diff --git a/content/html/content/test/test_bug546995-2.html b/content/html/content/test/test_bug546995-2.html index 772cd66e341..2b4b5f9a3c0 100644 --- a/content/html/content/test/test_bug546995-2.html +++ b/content/html/content/test/test_bug546995-2.html @@ -56,12 +56,13 @@ function runTests() document.getElementById('content').appendChild(e); } - // The element should still be focused. Waiting a second to be sure. - setTimeout(function() { - ok(document.activeElement, document.body, - "After loading, elements can't be autofocused"); - SimpleTest.finish(); - }, 1000); + // When the function will be executed, the focus event from autofocus should + // have been processed. + SimpleTest.executeSoon(function() { + ok(document.activeElement, document.body, + "After loading, elements can't be autofocused"); + SimpleTest.finish(); + }); yield; } diff --git a/content/html/content/test/test_bug546995-3.html b/content/html/content/test/test_bug546995-3.html index 695b48d01dd..1fa240d223a 100644 --- a/content/html/content/test/test_bug546995-3.html +++ b/content/html/content/test/test_bug546995-3.html @@ -9,12 +9,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=546995 - - + - - + Mozilla Bug 546995

@@ -32,13 +27,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=546995 SimpleTest.waitForExplicitFinish(); -function runTests() -{ - is(document.activeElement, document.getElementById('i'), - "The input element should be focused"); +document.getElementById('i').addEventListener("focus", function(aEvent) { + aEvent.target.removeEventListener("focus", arguments.callee, false); + ok(true, "The input element has been focused"); SimpleTest.finish(); -} + }, false); diff --git a/dom/tests/browser/browser_autofocus_background.js b/dom/tests/browser/browser_autofocus_background.js index a81a8ffdae8..50b67afb1b2 100644 --- a/dom/tests/browser/browser_autofocus_background.js +++ b/dom/tests/browser/browser_autofocus_background.js @@ -4,15 +4,13 @@ function test() { let fm = Components.classes["@mozilla.org/focus-manager;1"] .getService(Components.interfaces.nsIFocusManager); - let tabs = [ gBrowser.selectedTab, gBrowser.addTab(), gBrowser.addTab() ]; + let tabs = [ gBrowser.selectedTab, gBrowser.addTab() ]; // The first tab has an autofocused element. // The second tab is exactly like the first one without the autofocus. let testingList = [ { uri: "data:text/html,", tagName: "INPUT"}, - { uri: "data:text/html,", - tagName: "BODY"} ]; function runTest() { @@ -20,23 +18,17 @@ function test() { tabs[0].linkedBrowser.focus(); // Load the first tab on background. - tabs[1].linkedBrowser.addEventListener("load", onLoadBackgroundFirstTab, true); + tabs[1].linkedBrowser.addEventListener("load", onLoadBackgroundTab, true); tabs[1].linkedBrowser.loadURI(testingList[0].uri); } - function onLoadBackgroundFirstTab() { - tabs[1].linkedBrowser.removeEventListener("load", onLoadBackgroundFirstTab, true); + function onLoadBackgroundTab() { + tabs[1].linkedBrowser.removeEventListener("load", onLoadBackgroundTab, true); - // Now load the second tab on background. - tabs[2].linkedBrowser.addEventListener("load", onLoadBackgroundSecondTab, true); - tabs[2].linkedBrowser.loadURI(testingList[1].uri); - } - - function onLoadBackgroundSecondTab() { - tabs[2].linkedBrowser.removeEventListener("load", onLoadBackgroundSecondTab, true); - - // Wait a second to be sure all focus events are done before launching tests. - setTimeout(doTest, 1000); + // The focus event (from autofocus) has been sent, + // let's test with executeSoon so we are sure the test is done + // after the focus event is processed. + executeSoon(doTest); } function doTest() { @@ -53,7 +45,6 @@ function test() { } // Cleaning up. - gBrowser.addTab(); for (let i = 0; i < tabs.length; i++) { gBrowser.removeTab(tabs[i]); }