зеркало из https://github.com/mozilla/pjs.git
Bug 567098 - Remove setTimeout's in autofocus tests; r=ehsan
This commit is contained in:
Родитель
5214a6374b
Коммит
02b38533ba
|
@ -23,8 +23,9 @@
|
|||
|
||||
<script>
|
||||
function load() {
|
||||
// Our parent should have a look at us in 1 sec so focus events can be thrown.
|
||||
setTimeout("parent.gGen.next()", 1000);
|
||||
// When the function will be executed, the focus events from autofocus should
|
||||
// have been processed.
|
||||
setTimeout(parent.gGen.next(), 0);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,12 +9,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=546995
|
|||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<!-- When the page is loaded, we wait 2 seconds before launching the tests
|
||||
because the focus events may not be finished when the page is loaded so
|
||||
we have to wait or launch the tests when a focus events is thrown.
|
||||
However, if autofocus is ignored, there will be no focus event so we can't
|
||||
rely on that. -->
|
||||
<body onload="window.setTimeout(runTests, 2000);">
|
||||
<body onload="SimpleTest.executeSoon(runTests);">
|
||||
<script type="application/javascript">
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
|
|
|
@ -9,18 +9,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=546995
|
|||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<!-- When the page is loaded, we wait 2 seconds before launching the tests
|
||||
because the focus events may not be finished when the page is loaded so
|
||||
we have to wait or launch the tests when a focus events is thrown.
|
||||
However, if autofocus is ignored, there will be no focus event so we can't
|
||||
rely on that. -->
|
||||
<body onload="setTimeout(runTests, 2000);">
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=546995">Mozilla Bug 546995</a>
|
||||
<p id="display"></p>
|
||||
<script type="application/javascript">
|
||||
document.body.focus();
|
||||
is(document.activeElement, document.body,
|
||||
"The document body should have te focus");
|
||||
"The document body should have the focus");
|
||||
</script>
|
||||
<div id='content'>
|
||||
<input id='i' autofocus>
|
||||
|
@ -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);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
|
|
|
@ -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,<!DOCTYPE html><html><body><input autofocus id='target'></body></html>",
|
||||
tagName: "INPUT"},
|
||||
{ uri: "data:text/html,<!DOCTYPE html><html><body><input id='target'></body></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]);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче