summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/page-visibility/resources/pagevistestharness.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/page-visibility/resources/pagevistestharness.js
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/page-visibility/resources/pagevistestharness.js')
-rw-r--r--testing/web-platform/tests/page-visibility/resources/pagevistestharness.js112
1 files changed, 112 insertions, 0 deletions
diff --git a/testing/web-platform/tests/page-visibility/resources/pagevistestharness.js b/testing/web-platform/tests/page-visibility/resources/pagevistestharness.js
new file mode 100644
index 0000000000..d164d4603b
--- /dev/null
+++ b/testing/web-platform/tests/page-visibility/resources/pagevistestharness.js
@@ -0,0 +1,112 @@
+//
+// Helper functions for Page Visibility tests
+//
+
+var VISIBILITY_STATES =
+{
+ HIDDEN: "hidden",
+ VISIBLE: "visible"
+};
+
+var feature_check = false;
+
+//
+// All test() functions in the WebPerf PageVis test suite should use pv_test() instead.
+//
+// pv_test() validates the document.hidden and document.visibilityState attributes
+// exist prior to running tests and immediately shows a failure if they do not.
+//
+
+function pv_test(func, msg, doc)
+{
+ if (!doc)
+ {
+ doc = document;
+ }
+
+ // only run the feature check once, unless func == null, in which case,
+ // this call is intended as a feature check
+ if (!feature_check)
+ {
+ feature_check = true;
+
+ var hiddenVal = doc.hidden;
+ var visStateVal = doc.visibilityState;
+
+ // show a single error that the Page Visibility feature is undefined
+ test(function()
+ {
+ assert_true(hiddenVal !== undefined && hiddenVal != null,
+ "document.hidden is defined and not null.");},
+ "document.hidden is defined and not null.");
+
+ test(function()
+ {
+ assert_true(visStateVal !== undefined && hiddenVal != null,
+ "document.visibilityState is defined and not null.");},
+ "document.visibilityState is defined and not null.");
+
+ }
+
+ if (func)
+ {
+ test(func, msg);
+ }
+}
+
+
+function test_feature_exists(doc, msg)
+{
+ if (!msg)
+ {
+ msg = "";
+ }
+ var hiddenMsg = "document.hidden is defined" + msg + ".";
+ var stateMsg = "document.visibilityState is defined" + msg + ".";
+ pv_test(function(){assert_not_equals(document.hidden, undefined, hiddenMsg);}, hiddenMsg, doc);
+ pv_test(function(){assert_not_equals(document.visibilityState, undefined, stateMsg);}, stateMsg, doc);
+}
+
+//
+// Common helper functions
+//
+
+function test_true(value, msg)
+{
+ pv_test(function() { assert_true(value, msg); }, msg);
+}
+
+function test_equals(value, equals, msg)
+{
+ pv_test(function() { assert_equals(value, equals, msg); }, msg);
+}
+
+//
+// asynchronous test helper functions
+//
+
+function add_async_result(test_obj, pass_state)
+{
+ // add assertion to manual test for the pass state
+ test_obj.step(function() { assert_true(pass_state) });
+
+ // end manual test
+ test_obj.done();
+}
+
+function add_async_result_assert(test_obj, func)
+{
+ // add assertion to manual test for the pass state
+ test_obj.step(func);
+
+ // end manual test
+ test_obj.done();
+}
+
+var open_link;
+function TabSwitch()
+{
+ //var open_link = window.open("http://www.bing.com");
+ open_link = window.open('', '_blank');
+ step_timeout(function() { open_link.close(); }, 2000);
+}