summaryrefslogtreecommitdiffstats
path: root/dom/u2f/tests/frame_utils.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /dom/u2f/tests/frame_utils.js
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/u2f/tests/frame_utils.js')
-rw-r--r--dom/u2f/tests/frame_utils.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/dom/u2f/tests/frame_utils.js b/dom/u2f/tests/frame_utils.js
new file mode 100644
index 0000000000..b033b84094
--- /dev/null
+++ b/dom/u2f/tests/frame_utils.js
@@ -0,0 +1,54 @@
+// Utilities to help talk between the frame_ iframe documents and the parent
+// tests.
+
+var _parentOrigin = "https://example.com/";
+
+function local_setParentOrigin(aOrigin) {
+ _parentOrigin = aOrigin;
+}
+
+function handleEventMessage(event) {
+ if ("test" in event.data) {
+ let summary = event.data.test + ": " + event.data.msg;
+ ok(event.data.status, summary);
+ } else if ("done" in event.data) {
+ SimpleTest.finish();
+ } else {
+ ok(false, "Unexpected message in the test harness: " + event.data);
+ }
+}
+
+function local_is(value, expected, message) {
+ if (value === expected) {
+ local_ok(true, message);
+ } else {
+ local_ok(false, message + " unexpectedly: " + value + " !== " + expected);
+ }
+}
+
+function local_isnot(value, expected, message) {
+ if (value !== expected) {
+ local_ok(true, message);
+ } else {
+ local_ok(false, message + " unexpectedly: " + value + " === " + expected);
+ }
+}
+
+function local_ok(expression, message) {
+ let body = { test: this.location.pathname, status: expression, msg: message };
+ parent.postMessage(body, _parentOrigin);
+}
+
+function local_doesThrow(fn, name) {
+ let gotException = false;
+ try {
+ fn();
+ } catch (ex) {
+ gotException = true;
+ }
+ local_ok(gotException, name);
+}
+
+function local_finished() {
+ parent.postMessage({ done: true }, _parentOrigin);
+}