summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/document-policy/required-policy
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/document-policy/required-policy')
-rw-r--r--testing/web-platform/tests/document-policy/required-policy/document-policy.html54
-rw-r--r--testing/web-platform/tests/document-policy/required-policy/document-policy.html.headers1
-rw-r--r--testing/web-platform/tests/document-policy/required-policy/no-document-policy.html44
-rw-r--r--testing/web-platform/tests/document-policy/required-policy/required-document-policy-nested.html65
-rw-r--r--testing/web-platform/tests/document-policy/required-policy/required-document-policy.html65
-rw-r--r--testing/web-platform/tests/document-policy/required-policy/required-document-policy.html.headers1
-rw-r--r--testing/web-platform/tests/document-policy/required-policy/separate-document-policies.html64
-rw-r--r--testing/web-platform/tests/document-policy/required-policy/separate-document-policies.html.headers2
8 files changed, 296 insertions, 0 deletions
diff --git a/testing/web-platform/tests/document-policy/required-policy/document-policy.html b/testing/web-platform/tests/document-policy/required-policy/document-policy.html
new file mode 100644
index 0000000000..aaa8d69200
--- /dev/null
+++ b/testing/web-platform/tests/document-policy/required-policy/document-policy.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Test advertised required document policy</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script> </head>
+ <body>
+ <h1>Test advertised required document policy</h1>
+<script>
+// The top-level document has a document policy, but not a required document
+// policy. A request for a document in a frame should not include a
+// `Sec-Required-Document-Policy` header, unless that frame requires it
+// explicitly through the `policy` attribute.
+
+callbacks = {};
+
+window.addEventListener('message', ev => {
+ var id = ev.data.id;
+ if (id && callbacks[id]) {
+ callbacks[id](ev.data.requiredPolicy || null);
+ }
+});
+
+async_test(t => {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/document-policy/echo-policy.py?id=1";
+ callbacks["1"] = t.step_func_done(result => {
+ assert_equals(result, null);
+ });
+ document.body.appendChild(iframe);
+}, "Top-level document's policy should not affect child frame requests");
+
+async_test(t => {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/document-policy/echo-policy.py?id=2";
+ iframe.policy = "font-display-late-swap=?0";
+ callbacks["2"] = t.step_func_done(result => {
+ assert_equals(result, "font-display-late-swap=?0");
+ });
+ document.body.appendChild(iframe);
+}, "Child frame can have a required policy independent of the parent document.");
+
+async_test(t => {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/document-policy/echo-policy.py?id=3";
+ iframe.policy = "lossless-images-max-bpp=4";
+ callbacks["3"] = t.step_func_done(result => {
+ assert_equals(result, "lossless-images-max-bpp=4.0");
+ });
+ document.body.appendChild(iframe);
+}, "Child frame can have a required policy which is less strict than the parent document's policy.");
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/document-policy/required-policy/document-policy.html.headers b/testing/web-platform/tests/document-policy/required-policy/document-policy.html.headers
new file mode 100644
index 0000000000..20629ac15f
--- /dev/null
+++ b/testing/web-platform/tests/document-policy/required-policy/document-policy.html.headers
@@ -0,0 +1 @@
+Document-Policy: lossless-images-max-bpp=1.1
diff --git a/testing/web-platform/tests/document-policy/required-policy/no-document-policy.html b/testing/web-platform/tests/document-policy/required-policy/no-document-policy.html
new file mode 100644
index 0000000000..8a3624440f
--- /dev/null
+++ b/testing/web-platform/tests/document-policy/required-policy/no-document-policy.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Test advertised required document policy</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script> </head>
+ <body>
+ <h1>Test advertised required document policy</h1>
+<script>
+// The top-level document does not have any document-policy-related headers.
+// A request for a document in a frame should not include a
+// `Sec-Required-Document-Policy` header, unless that frame requires it
+// explicitly through the `policy` attribute.
+
+callbacks = {};
+
+window.addEventListener('message', ev => {
+ var id = ev.data.id;
+ if (id && callbacks[id]) {
+ callbacks[id](ev.data.requiredPolicy || null);
+ }
+});
+
+async_test(t => {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/document-policy/echo-policy.py?id=1";
+ callbacks["1"] = t.step_func_done(result => {
+ assert_equals(result, null);
+ });
+ document.body.appendChild(iframe);
+}, "Child frame should have no required policy by default.");
+
+async_test(t => {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/document-policy/echo-policy.py?id=2";
+ iframe.policy = "font-display-late-swap=?0";
+ callbacks["2"] = t.step_func_done(result => {
+ assert_equals(result, "font-display-late-swap=?0");
+ });
+ document.body.appendChild(iframe);
+}, "Child frame can have an explicit required policy.");
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/document-policy/required-policy/required-document-policy-nested.html b/testing/web-platform/tests/document-policy/required-policy/required-document-policy-nested.html
new file mode 100644
index 0000000000..33de2533a2
--- /dev/null
+++ b/testing/web-platform/tests/document-policy/required-policy/required-document-policy-nested.html
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Test advertised required document policy</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script> </head>
+ <body>
+ <h1>Test advertised required document policy</h1>
+<script>
+// The top-level document has no required document policy. Its child frames may,
+// though, and those policies should be set for any subframes.
+
+callbacks = {};
+
+window.addEventListener('message', ev => {
+ var id = ev.data.id;
+ if (id && callbacks[id]) {
+ callbacks[id](ev.data.requiredPolicy || null);
+ }
+});
+
+// Frame tree should be:
+// Top:
+// <iframe>
+// <iframe>
+async_test(t => {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/document-policy/echo-policy-nested.html?id=1";
+ callbacks["1"] = t.step_func_done(result => {
+ assert_equals(result, null);
+ });
+ document.body.appendChild(iframe);
+}, "test nested required document policy");
+
+// Frame tree should be:
+// Top:
+// <iframe policy="lossless-images-max-bpp=1.1">
+// <iframe>
+async_test(t => {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/document-policy/echo-policy-nested.html?id=2";
+ iframe.policy = "lossless-images-max-bpp=1.1";
+ callbacks["2"] = t.step_func_done(result => {
+ assert_equals(result, "lossless-images-max-bpp=1.1");
+ });
+ document.body.appendChild(iframe);
+}, "test nested required document policy when set by nested frame");
+
+// Frame tree should be:
+// Top:
+// <iframe policy="lossless-images-max-bpp=1.1">
+// <iframe>
+// <iframe>
+async_test(t => {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/document-policy/echo-policy-nested.html?id=3&level=1";
+ iframe.policy = "lossless-images-max-bpp=1.1";
+ callbacks["3"] = t.step_func_done(result => {
+ assert_equals(result, "lossless-images-max-bpp=1.1");
+ });
+ document.body.appendChild(iframe);
+}, "test nested required document policy when set by intermediate nested frame");
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/document-policy/required-policy/required-document-policy.html b/testing/web-platform/tests/document-policy/required-policy/required-document-policy.html
new file mode 100644
index 0000000000..1058e3582a
--- /dev/null
+++ b/testing/web-platform/tests/document-policy/required-policy/required-document-policy.html
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Test advertised required document policy</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script> </head>
+ <body>
+ <h1>Test advertised required document policy</h1>
+<script>
+// The top-level document has a required document policy. Any requests for
+// documents in child frames must be sent with a required policy header
+// indicating a required policy at least as strict. (In this case, "at least as
+// strict" means that the 'bpp' parameter must be less than or equal to the
+// parent document's required value.)
+
+callbacks = {};
+
+window.addEventListener('message', ev => {
+ var id = ev.data.id;
+ if (id && callbacks[id]) {
+ callbacks[id](ev.data.requiredPolicy || null);
+ }
+});
+
+async_test(t => {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/document-policy/echo-policy.py?id=1";
+ callbacks["1"] = t.step_func_done(result => {
+ assert_equals(result, "lossless-images-max-bpp=1.1");
+ });
+ document.body.appendChild(iframe);
+}, "Child frame with no explicit policy should have the same required policy as its parent.");
+
+async_test(t => {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/document-policy/echo-policy.py?id=2";
+ iframe.policy = "lossless-images-max-bpp=4";
+ callbacks["2"] = t.step_func_done(result => {
+ assert_equals(result, "lossless-images-max-bpp=1.1");
+ });
+ document.body.appendChild(iframe);
+}, "Child frame with a less strict required policy should have the stricter value from the parent's policy applied.");
+
+async_test(t => {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/document-policy/echo-policy.py?id=3";
+ iframe.policy = "lossless-images-max-bpp=1.0";
+ callbacks["3"] = t.step_func_done(result => {
+ assert_equals(result, "lossless-images-max-bpp=1.0");
+ });
+ document.body.appendChild(iframe);
+}, "Child frame may have a stricter policy than the parent.");
+
+async_test(t => {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/document-policy/echo-policy.py?id=4";
+ iframe.policy = "font-display-late-swap=?0";
+ callbacks["4"] = t.step_func_done(result => {
+ assert_equals(result, "font-display-late-swap=?0, lossless-images-max-bpp=1.1");
+ });
+ document.body.appendChild(iframe);
+}, "Any unrelated policy directives should combine with the parent's required policy.");
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/document-policy/required-policy/required-document-policy.html.headers b/testing/web-platform/tests/document-policy/required-policy/required-document-policy.html.headers
new file mode 100644
index 0000000000..ac1bf268b5
--- /dev/null
+++ b/testing/web-platform/tests/document-policy/required-policy/required-document-policy.html.headers
@@ -0,0 +1 @@
+Require-Document-Policy: lossless-images-max-bpp=1.1
diff --git a/testing/web-platform/tests/document-policy/required-policy/separate-document-policies.html b/testing/web-platform/tests/document-policy/required-policy/separate-document-policies.html
new file mode 100644
index 0000000000..1ed94a81e7
--- /dev/null
+++ b/testing/web-platform/tests/document-policy/required-policy/separate-document-policies.html
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Test advertised required document policy</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script> </head>
+ <body>
+ <h1>Test advertised required document policy</h1>
+<script>
+// The top-level document has a document policy, as well as a required document
+// policy (for subframes) which is stricter. This test should load (the required
+// policy should not block this page,) but the requirements should be applied to
+// nested content.
+
+callbacks = {};
+
+window.addEventListener('message', ev => {
+ var id = ev.data.id;
+ if (id && callbacks[id]) {
+ callbacks[id](ev.data.requiredPolicy || null);
+ }
+});
+
+async_test(t => {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/document-policy/echo-policy.py?id=1";
+ callbacks["1"] = t.step_func_done(result => {
+ assert_equals(result, "lossless-images-max-bpp=1.0");
+ });
+ document.body.appendChild(iframe);
+}, "Child frame with no explicit policy should have the same required policy as its parent.");
+
+async_test(t => {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/document-policy/echo-policy.py?id=2";
+ iframe.policy = "lossless-images-max-bpp=4";
+ callbacks["2"] = t.step_func_done(result => {
+ assert_equals(result, "lossless-images-max-bpp=1.0");
+ });
+ document.body.appendChild(iframe);
+}, "Child frame with a less strict required policy should have the stricter value from the parent's policy applied.");
+
+async_test(t => {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/document-policy/echo-policy.py?id=3";
+ iframe.policy = "lossless-images-max-bpp=0.9";
+ callbacks["3"] = t.step_func_done(result => {
+ assert_equals(result, "lossless-images-max-bpp=0.9");
+ });
+ document.body.appendChild(iframe);
+}, "Child frame may have a stricter policy than the parent.");
+
+async_test(t => {
+ var iframe = document.createElement('iframe');
+ iframe.src = "/document-policy/echo-policy.py?id=4";
+ iframe.policy = "no-font-display-late-swap";
+ callbacks["4"] = t.step_func_done(result => {
+ assert_equals(result, "no-font-display-late-swap, lossless-images-max-bpp=1.0");
+ });
+ document.body.appendChild(iframe);
+}, "Any unrelated policy directives should combine with the parent's required policy.");
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/document-policy/required-policy/separate-document-policies.html.headers b/testing/web-platform/tests/document-policy/required-policy/separate-document-policies.html.headers
new file mode 100644
index 0000000000..3c593a32aa
--- /dev/null
+++ b/testing/web-platform/tests/document-policy/required-policy/separate-document-policies.html.headers
@@ -0,0 +1,2 @@
+Document-Policy: lossless-images-max-bpp=1.1
+Require-Document-Policy: lossless-images-max-bpp=1.0