diff options
Diffstat (limited to 'testing/web-platform/tests/browsing-topics/resources/permissions-policy-util.sub.js')
-rw-r--r-- | testing/web-platform/tests/browsing-topics/resources/permissions-policy-util.sub.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/testing/web-platform/tests/browsing-topics/resources/permissions-policy-util.sub.js b/testing/web-platform/tests/browsing-topics/resources/permissions-policy-util.sub.js new file mode 100644 index 0000000000..e8bf45049c --- /dev/null +++ b/testing/web-platform/tests/browsing-topics/resources/permissions-policy-util.sub.js @@ -0,0 +1,30 @@ +const TOPICS_PERMISSIONS_POLICY_ERROR_MESSAGE = 'The \"browsing-topics\" Permissions Policy denied the use of document.browsingTopics().'; + +function test_topics_feature_availability_in_subframe(test, is_same_origin, expect_feature_available_func) { + const same_origin_src = '/browsing-topics/resources/document-api-notify-parent.tentative.https.html'; + const cross_origin_src = 'https://{{domains[www]}}:{{ports[https][0]}}' + + same_origin_src; + + let frame = document.createElement('iframe'); + frame.src = is_same_origin ? same_origin_src : cross_origin_src; + + window.addEventListener('message', test.step_func(function handler(evt) { + if (evt.source === frame.contentWindow) { + expect_feature_available_func(evt.data); + + document.body.removeChild(frame); + window.removeEventListener('message', handler); + test.done(); + } + })); + + document.body.appendChild(frame); +} + +function expect_topics_feature_unavailable(data) { + assert_equals(data.error, TOPICS_PERMISSIONS_POLICY_ERROR_MESSAGE); +} + +function expect_topics_feature_available(data) { + assert_equals(data.error, 'No error'); +} |