mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
bug 866641 - add registerCleanupFunction method to mochitest-plain. r=jmaher
This commit is contained in:
parent
27ebe04988
commit
0eb2e7a465
@ -22,6 +22,8 @@ _TEST_FILES = \
|
||||
test_SpecialPowersExtension2.html \
|
||||
file_SpecialPowersFrame1.html \
|
||||
test_bug816847.html \
|
||||
test_sanity_cleanup.html \
|
||||
test_sanity_cleanup2.html \
|
||||
$(NULL)
|
||||
|
||||
ifneq ($(OS_TARGET),Android)
|
||||
|
@ -225,6 +225,7 @@ SimpleTest.testPluginIsOOP = function () {
|
||||
|
||||
SimpleTest._tests = [];
|
||||
SimpleTest._stopOnLoad = true;
|
||||
SimpleTest._cleanupFunctions = [];
|
||||
|
||||
/**
|
||||
* Something like assert.
|
||||
@ -693,7 +694,11 @@ SimpleTest.executeSoon = function(aFunc) {
|
||||
return SpecialPowers.executeSoon(aFunc, window);
|
||||
}
|
||||
setTimeout(aFunc, 0);
|
||||
}
|
||||
};
|
||||
|
||||
SimpleTest.registerCleanupFunction = function(aFunc) {
|
||||
SimpleTest._cleanupFunctions.push(aFunc);
|
||||
};
|
||||
|
||||
/**
|
||||
* Finishes the tests. This is automatically called, except when
|
||||
@ -706,6 +711,17 @@ SimpleTest.finish = function () {
|
||||
|
||||
SimpleTest._alreadyFinished = true;
|
||||
|
||||
// Execute all of our cleanup functions.
|
||||
var func;
|
||||
while ((func = SimpleTest._cleanupFunctions.pop())) {
|
||||
try {
|
||||
func();
|
||||
}
|
||||
catch (ex) {
|
||||
SimpleTest.ok(false, "Cleanup function threw exception: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (SpecialPowers.DOMWindowUtils.isTestControllingRefreshes) {
|
||||
SimpleTest.ok(false, "test left refresh driver under test control");
|
||||
SpecialPowers.DOMWindowUtils.restoreNormalRefresh();
|
||||
|
30
testing/mochitest/tests/test_sanity_cleanup.html
Normal file
30
testing/mochitest/tests/test_sanity_cleanup.html
Normal file
@ -0,0 +1,30 @@
|
||||
<!-- Any copyright is dedicated to the Public Domain.
|
||||
- http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>SimpleTest.registerCleanupFunction test</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<script class="testbody" type="text/javascript">
|
||||
// Not a great example, since we have the pushPrefEnv API to cover
|
||||
// this use case, but I want to be able to test that the cleanup
|
||||
// function gets run, so setting and clearing a pref seems straightforward.
|
||||
function do_cleanup1() {
|
||||
SpecialPowers.clearUserPref("simpletest.cleanup.1");
|
||||
info("do_cleanup1 run!");
|
||||
}
|
||||
function do_cleanup2() {
|
||||
SpecialPowers.clearUserPref("simpletest.cleanup.2");
|
||||
info("do_cleanup2 run!");
|
||||
}
|
||||
SpecialPowers.setBoolPref("simpletest.cleanup.1", true);
|
||||
SpecialPowers.setBoolPref("simpletest.cleanup.2", true);
|
||||
SimpleTest.registerCleanupFunction(do_cleanup1);
|
||||
SimpleTest.registerCleanupFunction(do_cleanup2);
|
||||
ok(true, "dummy check");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
24
testing/mochitest/tests/test_sanity_cleanup2.html
Normal file
24
testing/mochitest/tests/test_sanity_cleanup2.html
Normal file
@ -0,0 +1,24 @@
|
||||
<!-- Any copyright is dedicated to the Public Domain.
|
||||
- http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>SimpleTest.registerCleanupFunction test</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<script class="testbody" type="text/javascript">
|
||||
for (pref of [1, 2]) {
|
||||
try {
|
||||
SpecialPowers.getBoolPref("simpletest.cleanup." + pref);
|
||||
ok(false, "Cleanup function should have unset pref");
|
||||
}
|
||||
catch(ex) {
|
||||
ok(true, "Pref was not set");
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user