summaryrefslogtreecommitdiffstats
path: root/testing/mochitest/tests/Harness_sanity/test_sanity_waitForCondition.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/mochitest/tests/Harness_sanity/test_sanity_waitForCondition.html
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/mochitest/tests/Harness_sanity/test_sanity_waitForCondition.html')
-rw-r--r--testing/mochitest/tests/Harness_sanity/test_sanity_waitForCondition.html51
1 files changed, 51 insertions, 0 deletions
diff --git a/testing/mochitest/tests/Harness_sanity/test_sanity_waitForCondition.html b/testing/mochitest/tests/Harness_sanity/test_sanity_waitForCondition.html
new file mode 100644
index 0000000000..f059adb88d
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_sanity_waitForCondition.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="UTF-8">
+ <title>SimpleTest.waitForCondition test</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
+</head>
+<body>
+<script>
+
+var captureFailure = false;
+var capturedFailures = [];
+window.ok = function (cond, name) {
+ if (!captureFailure) {
+ SimpleTest.ok(cond, name);
+ } else if (cond) {
+ SimpleTest.ok(false, `Expect a failure with "${name}"`);
+ } else {
+ capturedFailures.push(name);
+ }
+};
+
+SimpleTest.waitForExplicitFinish();
+SimpleTest.requestFlakyTimeout("test behavior SimpleTest.waitForCondition");
+
+addLoadEvent(testNormal);
+
+function testNormal() {
+ var condition = false;
+ SimpleTest.waitForCondition(() => condition, () => {
+ ok(condition, "Should only be called when condition is true");
+ SimpleTest.executeSoon(testTimeout);
+ }, "Shouldn't timeout");
+ setTimeout(() => { condition = true; }, 1000);
+}
+
+function testTimeout() {
+ captureFailure = true;
+ SimpleTest.waitForCondition(() => false, () => {
+ captureFailure = false;
+ is(capturedFailures.length, 1, "Should captured one failure");
+ is(capturedFailures[0], "Should timeout",
+ "Should capture the failure passed in");
+ SimpleTest.executeSoon(() => SimpleTest.finish());
+ }, "Should timeout");
+}
+
+</script>
+</body>
+</html>