summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/user-activation/resources
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/html/user-activation/resources')
-rw-r--r--testing/web-platform/tests/html/user-activation/resources/child-message-event-api.html24
-rw-r--r--testing/web-platform/tests/html/user-activation/resources/child-one.html29
-rw-r--r--testing/web-platform/tests/html/user-activation/resources/child-two.html29
-rw-r--r--testing/web-platform/tests/html/user-activation/resources/consumption-crossorigin-child.sub.html29
-rw-r--r--testing/web-platform/tests/html/user-activation/resources/consumption-sameorigin-child.html29
-rw-r--r--testing/web-platform/tests/html/user-activation/resources/propagation-crossorigin-child.sub.html27
-rw-r--r--testing/web-platform/tests/html/user-activation/resources/propagation-sameorigin-child.html27
-rw-r--r--testing/web-platform/tests/html/user-activation/resources/utils.js48
8 files changed, 242 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/user-activation/resources/child-message-event-api.html b/testing/web-platform/tests/html/user-activation/resources/child-message-event-api.html
new file mode 100644
index 0000000000..a0001633c2
--- /dev/null
+++ b/testing/web-platform/tests/html/user-activation/resources/child-message-event-api.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<body style="background: red;">
+ <script>
+ window.parent.postMessage("child-loaded",
+ {targetOrigin: "*", includeUserActivation: true});
+ window.addEventListener("click", event => {
+ window.parent.postMessage("child-clicked",
+ {targetOrigin: "*", includeUserActivation: true});
+ var win = window.open('404.html');
+ win.close();
+ });
+
+ window.addEventListener("message", event => {
+ if (event.data == "report") {
+ window.parent.postMessage("child-report",
+ {targetOrigin: "*", includeUserActivation: true});
+ }
+ if (event.data == "report-no-activation") {
+ window.parent.postMessage("child-report-no-activation",
+ {targetOrigin: "*", includeUserActivation: false});
+ }
+ });
+ </script>
+</body>
diff --git a/testing/web-platform/tests/html/user-activation/resources/child-one.html b/testing/web-platform/tests/html/user-activation/resources/child-one.html
new file mode 100644
index 0000000000..9668372620
--- /dev/null
+++ b/testing/web-platform/tests/html/user-activation/resources/child-one.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<body style="background: yellow;">
+ <script>
+ window.top.postMessage(JSON.stringify({
+ "type": "child-one-loaded",
+ "isActive": navigator.userActivation.isActive,
+ "hasBeenActive": navigator.userActivation.hasBeenActive
+ }), "*");
+
+ window.addEventListener("click", event => {
+ window.top.postMessage(JSON.stringify({
+ "type": "child-one-clicked",
+ "isActive": navigator.userActivation.isActive,
+ "hasBeenActive": navigator.userActivation.hasBeenActive
+ }), "*");
+ });
+
+ window.addEventListener("message", event => {
+ var msg = JSON.parse(event.data);
+ if (msg.type == "report") {
+ window.top.postMessage(JSON.stringify({
+ "type": "child-one-report",
+ "isActive": navigator.userActivation.isActive,
+ "hasBeenActive": navigator.userActivation.hasBeenActive
+ }), "*");
+ }
+ });
+ </script>
+</body>
diff --git a/testing/web-platform/tests/html/user-activation/resources/child-two.html b/testing/web-platform/tests/html/user-activation/resources/child-two.html
new file mode 100644
index 0000000000..9fb68dbd51
--- /dev/null
+++ b/testing/web-platform/tests/html/user-activation/resources/child-two.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<body style="background: lightgrey;">
+ <script>
+ window.top.postMessage(JSON.stringify({
+ "type": "child-two-loaded",
+ "isActive": navigator.userActivation.isActive,
+ "hasBeenActive": navigator.userActivation.hasBeenActive
+ }), "*");
+
+ window.addEventListener("click", event => {
+ window.top.postMessage(JSON.stringify({
+ "type": "child-two-clicked",
+ "isActive": navigator.userActivation.isActive,
+ "hasBeenActive": navigator.userActivation.hasBeenActive
+ }), "*");
+ });
+
+ window.addEventListener("message", event => {
+ var msg = JSON.parse(event.data);
+ if (msg.type == "report") {
+ window.top.postMessage(JSON.stringify({
+ "type": "child-two-report",
+ "isActive": navigator.userActivation.isActive,
+ "hasBeenActive": navigator.userActivation.hasBeenActive
+ }), "*");
+ }
+ });
+ </script>
+</body>
diff --git a/testing/web-platform/tests/html/user-activation/resources/consumption-crossorigin-child.sub.html b/testing/web-platform/tests/html/user-activation/resources/consumption-crossorigin-child.sub.html
new file mode 100644
index 0000000000..518e000d0b
--- /dev/null
+++ b/testing/web-platform/tests/html/user-activation/resources/consumption-crossorigin-child.sub.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script>
+ window.top.postMessage(JSON.stringify({
+ "type": "child-crossorigin-loaded",
+ "isActive": navigator.userActivation.isActive,
+ "hasBeenActive": navigator.userActivation.hasBeenActive
+ }), "*");
+
+ window.addEventListener("click", event => {
+ window.open().close();
+
+ window.top.postMessage(JSON.stringify({
+ "type": "child-crossorigin-report",
+ "isActive": navigator.userActivation.isActive,
+ "hasBeenActive": navigator.userActivation.hasBeenActive
+ }), "*");
+ });
+ </script>
+</head>
+<body style="background: lightgreen;">
+ <!-- The midpoint of this frame should be outside the grandchild frame. -->
+ <div style="height: 75px;">Cross-origin child frame</div>
+ <iframe id="child2" width="270px" height="30px"
+ src="http://{{hosts[][]}}:{{ports[http][1]}}/html/user-activation/resources/child-two.html">
+ </iframe>
+</body>
+</html>
diff --git a/testing/web-platform/tests/html/user-activation/resources/consumption-sameorigin-child.html b/testing/web-platform/tests/html/user-activation/resources/consumption-sameorigin-child.html
new file mode 100644
index 0000000000..9e421fc0f1
--- /dev/null
+++ b/testing/web-platform/tests/html/user-activation/resources/consumption-sameorigin-child.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script>
+ window.top.postMessage(JSON.stringify({
+ "type": "child-sameorigin-loaded",
+ "isActive": navigator.userActivation.isActive,
+ "hasBeenActive": navigator.userActivation.hasBeenActive
+ }), "*");
+
+ window.addEventListener("click", event => {
+ window.open().close();
+
+ window.top.postMessage(JSON.stringify({
+ "type": "child-sameorigin-report",
+ "isActive": navigator.userActivation.isActive,
+ "hasBeenActive": navigator.userActivation.hasBeenActive
+ }), "*");
+ });
+ </script>
+</head>
+<body style="background: lightgreen;">
+ <!-- The midpoint of this frame should be outside the grandchild frame. -->
+ <div style="height: 75px;">Same-origin child frame</div>
+ <iframe id="child2" width="270px" height="30px"
+ src="child-two.html">
+ </iframe>
+</body>
+</html>
diff --git a/testing/web-platform/tests/html/user-activation/resources/propagation-crossorigin-child.sub.html b/testing/web-platform/tests/html/user-activation/resources/propagation-crossorigin-child.sub.html
new file mode 100644
index 0000000000..e920566a21
--- /dev/null
+++ b/testing/web-platform/tests/html/user-activation/resources/propagation-crossorigin-child.sub.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script>
+ window.top.postMessage(JSON.stringify({
+ "type": "child-crossorigin-loaded",
+ "isActive": navigator.userActivation.isActive,
+ "hasBeenActive": navigator.userActivation.hasBeenActive
+ }), "*");
+
+ window.addEventListener("click", event => {
+ window.top.postMessage(JSON.stringify({
+ "type": "child-crossorigin-report",
+ "isActive": navigator.userActivation.isActive,
+ "hasBeenActive": navigator.userActivation.hasBeenActive
+ }), "*");
+ });
+ </script>
+</head>
+<body style="background: lightgreen;">
+ <!-- The midpoint of this frame should be outside the grandchild frame. -->
+ <div style="height: 75px;">Cross-origin child frame</div>
+ <iframe id="child2" width="270px" height="30px"
+ src="http://{{hosts[][]}}:{{ports[http][1]}}/html/user-activation/resources/child-two.html">
+ </iframe>
+</body>
+</html>
diff --git a/testing/web-platform/tests/html/user-activation/resources/propagation-sameorigin-child.html b/testing/web-platform/tests/html/user-activation/resources/propagation-sameorigin-child.html
new file mode 100644
index 0000000000..69ad50cb71
--- /dev/null
+++ b/testing/web-platform/tests/html/user-activation/resources/propagation-sameorigin-child.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script>
+ window.top.postMessage(JSON.stringify({
+ "type": "child-sameorigin-loaded",
+ "isActive": navigator.userActivation.isActive,
+ "hasBeenActive": navigator.userActivation.hasBeenActive
+ }), "*");
+
+ window.addEventListener("click", event => {
+ window.top.postMessage(JSON.stringify({
+ "type": "child-sameorigin-report",
+ "isActive": navigator.userActivation.isActive,
+ "hasBeenActive": navigator.userActivation.hasBeenActive
+ }), "*");
+ });
+ </script>
+</head>
+<body style="background: lightgreen;">
+ <!-- The midpoint of this frame should be outside the grandchild frame. -->
+ <div style="height: 75px;">Same-origin child frame</div>
+ <iframe id="child2" width="270px" height="30px"
+ src="child-two.html">
+ </iframe>
+</body>
+</html>
diff --git a/testing/web-platform/tests/html/user-activation/resources/utils.js b/testing/web-platform/tests/html/user-activation/resources/utils.js
new file mode 100644
index 0000000000..5d3302583f
--- /dev/null
+++ b/testing/web-platform/tests/html/user-activation/resources/utils.js
@@ -0,0 +1,48 @@
+function delayByFrames(f, num_frames) {
+ function recurse(depth) {
+ if (depth == 0)
+ f();
+ else
+ requestAnimationFrame(() => recurse(depth-1));
+ }
+ recurse(num_frames);
+}
+
+// Returns a Promise which is resolved with the event object when the event is
+// fired.
+function getEvent(eventType) {
+ return new Promise(resolve => {
+ document.body.addEventListener(eventType, e => resolve(e), {once: true});
+ });
+}
+
+
+// Returns a Promise which is resolved with a "true" iff transient activation
+// was available and successfully consumed.
+//
+// This function relies on Fullscreen API to check/consume user activation
+// state.
+async function consumeTransientActivation() {
+ try {
+ await document.body.requestFullscreen();
+ await document.exitFullscreen();
+ return true;
+ } catch(e) {
+ return false;
+ }
+}
+
+function receiveMessage(type) {
+ return new Promise((resolve) => {
+ window.addEventListener("message", function listener(event) {
+ if (typeof event.data !== "string") {
+ return;
+ }
+ const data = JSON.parse(event.data);
+ if (data.type === type) {
+ window.removeEventListener("message", listener);
+ resolve(data);
+ }
+ });
+ });
+}