summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/browsing-topics/resources
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/browsing-topics/resources')
-rw-r--r--testing/web-platform/tests/browsing-topics/resources/check-topics-request-header-notify-parent.py18
-rw-r--r--testing/web-platform/tests/browsing-topics/resources/check-topics-request-header.py4
-rw-r--r--testing/web-platform/tests/browsing-topics/resources/document-api-notify-parent.tentative.https.html11
-rw-r--r--testing/web-platform/tests/browsing-topics/resources/empty.html1
-rw-r--r--testing/web-platform/tests/browsing-topics/resources/fetch-topics-header-not-visible-in-service-worker-helper.tentative.https.html21
-rw-r--r--testing/web-platform/tests/browsing-topics/resources/fetch-topics.js14
-rw-r--r--testing/web-platform/tests/browsing-topics/resources/intercept-request.js12
-rw-r--r--testing/web-platform/tests/browsing-topics/resources/navigation-header-util.sub.js36
-rw-r--r--testing/web-platform/tests/browsing-topics/resources/permissions-policy-util.sub.js30
-rw-r--r--testing/web-platform/tests/browsing-topics/resources/topics-not-allowed-for-service-worker-fetch-helper.tentative.https.html19
10 files changed, 166 insertions, 0 deletions
diff --git a/testing/web-platform/tests/browsing-topics/resources/check-topics-request-header-notify-parent.py b/testing/web-platform/tests/browsing-topics/resources/check-topics-request-header-notify-parent.py
new file mode 100644
index 0000000000..98c77c2b0b
--- /dev/null
+++ b/testing/web-platform/tests/browsing-topics/resources/check-topics-request-header-notify-parent.py
@@ -0,0 +1,18 @@
+def main(request, response):
+ """
+ Returns an HTML response that notifies its parent frame the topics header
+ via postMessage
+ """
+
+ topics_header = request.headers.get(b"sec-browsing-topics", b"NO_TOPICS_HEADER")
+
+ headers = [(b"Content-Type", b"text/html"),
+ (b"Access-Control-Allow-Origin", b"*")]
+ content = b'''
+<script>
+ let parentOrOpener = window.opener || window.parent;
+ parentOrOpener.postMessage({ topicsHeader: '%s'}, "*");
+</script>
+''' % (topics_header)
+
+ return 200, headers, content
diff --git a/testing/web-platform/tests/browsing-topics/resources/check-topics-request-header.py b/testing/web-platform/tests/browsing-topics/resources/check-topics-request-header.py
new file mode 100644
index 0000000000..569b754496
--- /dev/null
+++ b/testing/web-platform/tests/browsing-topics/resources/check-topics-request-header.py
@@ -0,0 +1,4 @@
+def main(request, response):
+ topics_header = request.headers.get(b"sec-browsing-topics", b"NO_TOPICS_HEADER")
+ response.headers.append(b"Access-Control-Allow-Origin", b"*")
+ response.content = topics_header
diff --git a/testing/web-platform/tests/browsing-topics/resources/document-api-notify-parent.tentative.https.html b/testing/web-platform/tests/browsing-topics/resources/document-api-notify-parent.tentative.https.html
new file mode 100644
index 0000000000..2fd55ebeb2
--- /dev/null
+++ b/testing/web-platform/tests/browsing-topics/resources/document-api-notify-parent.tentative.https.html
@@ -0,0 +1,11 @@
+<!doctype html>
+<body>
+ <script>
+ document.browsingTopics().then((topics) => {
+ window.parent.postMessage({error: 'No error'}, '*');
+ })
+ .catch((err) => {
+ window.parent.postMessage({error: err.message}, '*');
+ });
+ </script>
+</body>
diff --git a/testing/web-platform/tests/browsing-topics/resources/empty.html b/testing/web-platform/tests/browsing-topics/resources/empty.html
new file mode 100644
index 0000000000..c50eddd41f
--- /dev/null
+++ b/testing/web-platform/tests/browsing-topics/resources/empty.html
@@ -0,0 +1 @@
+<!doctype html>
diff --git a/testing/web-platform/tests/browsing-topics/resources/fetch-topics-header-not-visible-in-service-worker-helper.tentative.https.html b/testing/web-platform/tests/browsing-topics/resources/fetch-topics-header-not-visible-in-service-worker-helper.tentative.https.html
new file mode 100644
index 0000000000..e9cb8144e0
--- /dev/null
+++ b/testing/web-platform/tests/browsing-topics/resources/fetch-topics-header-not-visible-in-service-worker-helper.tentative.https.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<body>
+ <script>
+ var current_url = window.location.href;
+ var fetch_url = current_url.substring(0, current_url.lastIndexOf("/")) + '/empty.html'
+
+ navigator.serviceWorker.addEventListener('message', e => {
+ if (e.data.fetchUrl == fetch_url) {
+ if (e.data.topicsHeader === 'null') {
+ window.opener.postMessage(
+ {testResult: 'Service worker intercepted no topics header'}, '*');
+ } else {
+ window.opener.postMessage(
+ {testResult: 'Service worker intercepted topics header'}, '*');
+ }
+ }
+ });
+
+ fetch(fetch_url, {browsingTopics: true});
+ </script>
+</body>
diff --git a/testing/web-platform/tests/browsing-topics/resources/fetch-topics.js b/testing/web-platform/tests/browsing-topics/resources/fetch-topics.js
new file mode 100644
index 0000000000..71064a90c5
--- /dev/null
+++ b/testing/web-platform/tests/browsing-topics/resources/fetch-topics.js
@@ -0,0 +1,14 @@
+self.addEventListener('message', event => {
+ if (event.data.fetchUrl) {
+ clients.matchAll().then((clients) => {
+ fetch(event.data.fetchUrl, {browsingTopics: true}).then((response) => {
+ response.text().then((topics_header) => {
+ // clients[0] is the most recently focused one
+ clients[0].postMessage({
+ topicsHeader: topics_header
+ });
+ });
+ });
+ });
+ }
+});
diff --git a/testing/web-platform/tests/browsing-topics/resources/intercept-request.js b/testing/web-platform/tests/browsing-topics/resources/intercept-request.js
new file mode 100644
index 0000000000..c19efb5f2f
--- /dev/null
+++ b/testing/web-platform/tests/browsing-topics/resources/intercept-request.js
@@ -0,0 +1,12 @@
+self.addEventListener('fetch', event => {
+ event.waitUntil(async function () {
+ if (!event.clientId) return;
+ const client = await clients.get(event.clientId);
+ if (!client) return;
+
+ client.postMessage({
+ fetchUrl: event.request.url,
+ topicsHeader: String(event.request.headers.get("Sec-Browsing-Topics"))
+ });
+ }());
+});
diff --git a/testing/web-platform/tests/browsing-topics/resources/navigation-header-util.sub.js b/testing/web-platform/tests/browsing-topics/resources/navigation-header-util.sub.js
new file mode 100644
index 0000000000..b3bec79651
--- /dev/null
+++ b/testing/web-platform/tests/browsing-topics/resources/navigation-header-util.sub.js
@@ -0,0 +1,36 @@
+function test_topics_iframe_navigation_header(
+ test, has_browsing_topics_attribute, is_same_origin, expect_topics_header_available_func) {
+ const same_origin_src = '/browsing-topics/resources/check-topics-request-header-notify-parent.py';
+ 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;
+
+ if (has_browsing_topics_attribute) {
+ frame.browsingTopics = true;
+ }
+
+ window.addEventListener('message', test.step_func(function handler(evt) {
+ if (evt.source === frame.contentWindow) {
+ expect_topics_header_available_func(evt.data);
+
+ document.body.removeChild(frame);
+ window.removeEventListener('message', handler);
+ test.done();
+ }
+ }));
+
+ document.body.appendChild(frame);
+}
+
+function expect_topics_header_unavailable(data) {
+ assert_equals(data.topicsHeader, 'NO_TOPICS_HEADER');
+}
+
+function expect_topics_header_available(data) {
+ // An empty result indicates that the request was eligible for topics.
+ // Currently, the web-platform-tests framework does not support actually
+ // handling the topics request.
+ assert_equals(data.topicsHeader, '');
+} \ No newline at end of file
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');
+}
diff --git a/testing/web-platform/tests/browsing-topics/resources/topics-not-allowed-for-service-worker-fetch-helper.tentative.https.html b/testing/web-platform/tests/browsing-topics/resources/topics-not-allowed-for-service-worker-fetch-helper.tentative.https.html
new file mode 100644
index 0000000000..2278d5bc76
--- /dev/null
+++ b/testing/web-platform/tests/browsing-topics/resources/topics-not-allowed-for-service-worker-fetch-helper.tentative.https.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<body>
+ <script>
+ var current_url = window.location.href;
+ var fetch_url = current_url.substring(0, current_url.lastIndexOf("/")) + '/check-topics-request-header.py'
+
+ navigator.serviceWorker.addEventListener('message', e => {
+ if (e.data.topicsHeader === 'NO_TOPICS_HEADER') {
+ window.opener.postMessage({testResult: 'Topics fetch initiated from service worker did not include the topics header'}, '*');
+ } else {
+ window.opener.postMessage({testResult: 'Topics fetch initiated from service worker included the topics header'}, '*');
+ }
+ });
+
+ navigator.serviceWorker.controller.postMessage({
+ fetchUrl: fetch_url
+ });
+ </script>
+</body>