Bug 513707, add a method to wait for load and focus events before starting some tests, r=sayrer

This commit is contained in:
Neil Deakin 2009-09-03 15:30:06 -04:00
Родитель c4e5b9a60e
Коммит b79a438dd5
17 изменённых файлов: 78 добавлений и 74 удалений

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

@ -213,6 +213,45 @@ SimpleTest.waitForExplicitFinish = function () {
SimpleTest._stopOnLoad = false;
};
SimpleTest.waitForFocus_started = false;
SimpleTest.waitForFocus_loaded = false;
SimpleTest.waitForFocus_focused = false;
/**
* Waits for a focus and load event before calling callback.
* targetWindow should be specified if it is different than 'window'.
*/
SimpleTest.waitForFocus = function (callback, targetWindow) {
SimpleTest.waitForFocus_started = false;
SimpleTest.waitForFocus_loaded = false;
SimpleTest.waitForFocus_focused = false;
if (!targetWindow)
targetWindow = window;
function maybeRunTests(event) {
if (SimpleTest.waitForFocus_loaded &&
SimpleTest.waitForFocus_focused &&
!SimpleTest.waitForFocus_started) {
SimpleTest.waitForFocus_started = true;
callback();
}
}
function waitForEvent(event) {
SimpleTest["waitForFocus_" + event.type + "ed"] = true;
targetWindow.removeEventListener(event.type, waitForEvent, false);
setTimeout(maybeRunTests, 0);
}
targetWindow.addEventListener("load", waitForEvent, false);
targetWindow.addEventListener("focus", waitForEvent, false);
// if this is a child frame, ensure that the frame is focused
if (!(targetWindow instanceof Components.interfaces.nsIDOMChromeWindow))
targetWindow.focus();
};
/**
* Executes a function shortly after the call, but lets the caller continue
* working (or finish).

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

@ -18,8 +18,6 @@
<script class="testbody" type="application/javascript">
<![CDATA[
var gDone = false;
SimpleTest.waitForExplicitFinish();
function keyCaretTest()

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

@ -42,8 +42,6 @@
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Textbox with emptyText test" width="500" height="600"
onload="window.focus();"
onfocus="if (doTest) setTimeout(doTest, 0); doTest = null;"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
@ -93,6 +91,8 @@
SimpleTest.finish();
}
SimpleTest.waitForFocus(doTest);
]]></script>
</window>

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

@ -3,8 +3,7 @@
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Key Tests"
onfocus="setTimeout(runTest, 0);"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
@ -94,6 +93,8 @@ function checkKey(event)
function is(l, r, n) { window.opener.wrappedJSObject.SimpleTest.is(l,r,n); }
function ok(v, n) { window.opener.wrappedJSObject.SimpleTest.ok(v,n); }
SimpleTest.waitForFocus(runTest);
]]>
</script>

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

@ -2,8 +2,7 @@
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window title="Large Menu Tests"
onfocus="setTimeout(runTests, 0);"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
@ -290,6 +289,8 @@ function testPopupMovement()
popup.hidePopup();
}
window.opener.wrappedJSObject.SimpleTest.waitForFocus(runTests, window);
]]>
</script>

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

@ -3,9 +3,7 @@
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Panel Focus Tests"
onfocus="setTimeout(showPanel, 0)"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
@ -121,6 +119,8 @@ function noautofocusPanelHidden()
window.opener.wrappedJSObject.SimpleTest.finish();
}
window.opener.wrappedJSObject.SimpleTest.waitForFocus(showPanel, window);
]]>
</script>

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

@ -2,7 +2,6 @@
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window title="Popup Anchor Tests"
onfocus="setTimeout(runTests, 0)"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script>
@ -10,6 +9,8 @@ function runTests()
{
frames[0].openPopup();
}
window.opener.wrappedJSObject.SimpleTest.waitForFocus(runTests, window);
</script>
<spacer height="13"/>

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

@ -2,8 +2,7 @@
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window title="Popup Prevent Default Tests"
onfocus="if (!gDone) { gDone = true; setTimeout(runTest, 0); }"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Popup Prevent Default Tests</title>
@ -14,7 +13,6 @@
<script>
var gDone = false;
var gBlockShowing = true;
var gBlockHiding = true;
var gShownNotAllowed = true;
@ -100,6 +98,8 @@ function popupHidden()
window.opener.wrappedJSObject.SimpleTest.finish();
window.close();
}
window.opener.wrappedJSObject.SimpleTest.waitForFocus(runTest, window);
</script>
<button id="menu" type="menu" label="Menu">

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

@ -5,8 +5,6 @@
XUL Widget Test for tabindex
-->
<window title="tabindex" width="500" height="600"
onload="window.focus();"
onfocus="if (!gDone) { gDone = true; runTests(); }"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
@ -74,8 +72,6 @@
<script>
<![CDATA[
var gDone = false;
SimpleTest.waitForExplicitFinish();
var gAdjustedTabFocusModel = false;
@ -116,6 +112,8 @@ function runTests()
SimpleTest.finish();
}
SimpleTest.waitForFocus(runTests);
]]>
</script>

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

@ -5,8 +5,6 @@
XUL Widget Test for textbox with emptyText
-->
<window title="Textbox with emptyText test" width="500" height="600"
onload="window.focus();"
onfocus="if (!gDone) { gDone = true; doTests(); }"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
@ -21,8 +19,6 @@
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
var gDone = false;
SimpleTest.waitForExplicitFinish();
function doTests() {
@ -52,6 +48,8 @@ function doTests() {
SimpleTest.finish();
}
SimpleTest.waitForFocus(doTests);
]]></script>
</window>

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

@ -5,8 +5,6 @@
XUL Widget Test for textbox type="number"
-->
<window title="Textbox type='number' test" width="500" height="600"
onload="window.focus();"
onfocus="if (!gDone) { gDone = true; doTests(); }"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
@ -41,8 +39,6 @@ function ise(left, right, name) {
SimpleTest.ok(left === right, name, "got " + left + ", expected " + right);
}
var gDone = false;
SimpleTest.waitForExplicitFinish();
// ---- NOTE: the numbers used in these tests are carefully chosen to avoid
@ -325,6 +321,8 @@ function testIncreaseDecrease(nb, testid, increment, fixedCount, min, max)
synthesizeMouseExpectEvent(sb, 2, sbbottom, { }, nb, "!change", testid + "mouse down at min");
}
SimpleTest.waitForFocus(doTests);
]]></script>
</window>

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

@ -5,8 +5,6 @@
XUL Widget Test for search textbox
-->
<window title="Search textbox test" width="500" height="600"
onload="window.focus();"
onfocus="if (!gDone) { gDone = true; doTests(); }"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="/MochiKit/packed.js"/>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"/>
@ -28,7 +26,6 @@
SimpleTest.waitForExplicitFinish();
var gDone = false;
var gExpectedValue;
var gLastTest;
@ -167,6 +164,8 @@ function doSearch(aValue) {
SimpleTest.finish();
}
SimpleTest.waitForFocus(doTests);
]]></script>
</window>

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

@ -3,8 +3,6 @@
<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
<window title="Tooltip Noautohide Tests"
onload="window.focus();"
onfocus="if (!gDone) { gDone = true; setTimeout(runTests, 0); }"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="/MochiKit/packed.js"></script>
@ -22,11 +20,8 @@
<script class="testbody" type="application/javascript">
<![CDATA[
var gDone = false;
var gChecked = false;
SimpleTest.waitForExplicitFinish();
function runTests()
{
var button = document.getElementById("button");
@ -41,6 +36,8 @@ function tooltipStillShown()
document.getElementById("thetooltip").hidePopup();
}
SimpleTest.waitForFocus(runTests);
]]>
</script>

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

@ -5,8 +5,6 @@
unfocuses and refocuses the window on Windows -->
<window title="Popup Tests"
onload="window.gLoaded = true; setTimeout('maybeRunTests()', 0);"
onfocus="window.gFocused = true; setTimeout('maybeRunTests()', 0);"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
@ -85,19 +83,11 @@
<script class="testbody" type="application/javascript">
<![CDATA[
var gStarted = false;
function maybeRunTests()
{
if ('gLoaded' in window &&
'gFocused' in window &&
!gStarted) {
gStarted = true;
gFilePopup = document.getElementById("filepopup");
document.getElementById("filemenu").focus();
startPopupTests(popupTests);
}
}
window.opener.SimpleTest.waitForFocus(function () {
gFilePopup = document.getElementById("filepopup");
document.getElementById("filemenu").focus();
startPopupTests(popupTests);
}, window);
var popupTests = [
{

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

@ -2,10 +2,7 @@
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window title="Popup Attribute Tests"
onload="window.gLoaded = true; setTimeout('maybeRunTests()', 0);"
onfocus="window.gFocused = true; setTimeout('maybeRunTests()', 0);"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Popup Attribute Tests</title>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
@ -13,19 +10,7 @@
<script type="application/javascript" src="popup_trigger.js"></script>
<script>
<![CDATA[
var gStarted = false;
function maybeRunTests()
{
if ('gLoaded' in window &&
'gFocused' in window &&
!gStarted) {
gStarted = true;
runTests();
}
}
]]>
window.opener.SimpleTest.waitForFocus(runTests, window);
</script>
<hbox style="margin-left: 325px; margin-top: 325px;">

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

@ -2,9 +2,7 @@
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window title="Popup Tests"
onfocus="if (!gDone) { gDone = true; runTests(); }"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Popup Tests</title>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
@ -12,7 +10,7 @@
<script type="application/javascript" src="popup_trigger.js"></script>
<script>
var gDone = false;
window.opener.SimpleTest.waitForFocus(runTests, window);
</script>
<hbox style="margin-left: 325px; margin-top: 325px;">

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

@ -2,9 +2,8 @@
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<window title="Tooltip Tests"
onfocus="runTests()" onpopupshowing="checkCoords(event)"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
onpopupshowing="checkCoords(event)"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<title>Tooltip Tests</title>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
@ -200,6 +199,8 @@ var popupTests = [
];
window.opener.SimpleTest.waitForFocus(runTests, window);
]]>
</script>