Bug 1446879 [wpt PR 10090] - user activation must survive postMessage() to call show(), a=testonly
authorMarcos Cáceres <marcos@marcosc.com>
Mon, 09 Apr 2018 17:28:09 +0000
changeset 413601 45089e52d2fd8e2c104c12e0d80e5c2b1cebc2f7
parent 413600 8480e65de658780eaab84835d33e2ebf9adab775
child 413602 3612002a040f3bb16e7e4a53ed59cf0b15df9dcc
push id33850
push userapavel@mozilla.com
push dateMon, 16 Apr 2018 09:53:48 +0000
treeherdermozilla-central@6276ec7ebbf3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1446879, 10090
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1446879 [wpt PR 10090] - user activation must survive postMessage() to call show(), a=testonly Automatic update from web-platform-testsuser activation must survive postMessage() to call show() (#10090) Check that we can call pr.show() in an iframe via postMessage(), which is triggered by user activation. wpt-commits: 92885acfbbfa2ad0fe08310857379cb4c84797c0 wpt-pr: 10090 wpt-commits: 92885acfbbfa2ad0fe08310857379cb4c84797c0 wpt-pr: 10090
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/payment-request/show-method-postmessage-iframe.html
testing/web-platform/tests/payment-request/show-method-postmessage-manual.https.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -14942,16 +14942,22 @@
     ]
    ],
    "payment-request/show-method-optional-promise-resolves-manual.https.html": [
     [
      "/payment-request/show-method-optional-promise-resolves-manual.https.html",
      {}
     ]
    ],
+   "payment-request/show-method-postmessage-manual.https.html": [
+    [
+     "/payment-request/show-method-postmessage-manual.https.html",
+     {}
+    ]
+   ],
    "payment-request/updateWith-method-pmi-handling-manual.https.html": [
     [
      "/payment-request/updateWith-method-pmi-handling-manual.https.html",
      {}
     ]
    ],
    "payment-request/user-abort-algorithm-manual.https.html": [
     [
@@ -287402,16 +287408,21 @@
      {}
     ]
    ],
    "payment-request/resources/page2.html": [
     [
      {}
     ]
    ],
+   "payment-request/show-method-postmessage-iframe.html": [
+    [
+     {}
+    ]
+   ],
    "performance-timeline/OWNERS": [
     [
      {}
     ]
    ],
    "performance-timeline/performanceobservers.js": [
     [
      {}
@@ -582509,16 +582520,24 @@
   "payment-request/show-method-optional-promise-rejects-manual.https.html": [
    "62542519059ab38ee0753deff5e7e6e587f8adbf",
    "manual"
   ],
   "payment-request/show-method-optional-promise-resolves-manual.https.html": [
    "a07f98e117bce1f040c5e62ef3acbd2ef7475338",
    "manual"
   ],
+  "payment-request/show-method-postmessage-iframe.html": [
+   "954bf12fcc9cb5875bda3f3121708282628b1ffc",
+   "support"
+  ],
+  "payment-request/show-method-postmessage-manual.https.html": [
+   "d2be1d2872a473a48df7139ecd3804f33187ec8f",
+   "manual"
+  ],
   "payment-request/updateWith-method-pmi-handling-manual.https.html": [
    "b473073ad106e9e0732adb6bfbed5f54d6ec3194",
    "manual"
   ],
   "payment-request/user-abort-algorithm-manual.https.html": [
    "31a6f480d015c6c715df2001b03f487a205a7311",
    "manual"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/payment-request/show-method-postmessage-iframe.html
@@ -0,0 +1,42 @@
+<h1>This iframe calls shows() via postMessage()</h1>
+<script>
+"use strict";
+const defaultMethods = Object.freeze([
+  { supportedMethods: "basic-card" },
+  { supportedMethods: "https://apple.com/pay" },
+]);
+
+const defaultDetails = Object.freeze({
+  id: "fail",
+  total: {
+    label: "Total",
+    amount: {
+      currency: "USD",
+      value: "1.00",
+    },
+  },
+});
+
+// We are going to use the id to prove that this works
+// which we will pass back to the caller
+window.onmessage = async event => {
+  const { source, data: { id, request } } = event;
+  switch (request) {
+    case "show-payment-request": {
+      const request = new PaymentRequest(defaultMethods, {
+        ...defaultDetails,
+        id,
+      });
+      try {
+        const response = await request.show();
+        source.postMessage(response.toJSON(), window.location.origin);
+        await response.complete();
+      } catch (err) {
+        source.postMessage({ requestId: "fail" }, window.location.origin);
+        await request.abort();
+      }
+    }
+  }
+};
+
+</script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/payment-request/show-method-postmessage-manual.https.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Test for PaymentRequest.show() method</title>
+<link rel="help" href="https://w3c.github.io/browser-payment-api/#show-method">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+"use strict";
+setup({
+  explicit_done: true,
+  explicit_timeout: true,
+});
+
+async function runUserActivation(button) {
+  button.disabled = true;
+  const { contentWindow: iframeWindow } = document.getElementById("iframe");
+  const expectedId = "pass123";
+  await Promise.resolve(); // next tick
+  const promiseForResponse = new Promise(resolve => {
+    window.onmessage = ({ data: { requestId } }) => resolve(requestId);
+  });
+  const ops = { id: expectedId, request: "show-payment-request" };
+  iframeWindow.postMessage(ops, window.location.origin);
+  promise_test(async () => {
+    const actualId = await promiseForResponse;
+    assert_equals(actualId, expectedId, "ids must match");
+  }, button.textContent.trim());
+  done();
+}
+</script>
+<h2>Test PaymentRequest.show() triggered by user activation using postMessage()</h2>
+<p>
+  Tests that user activation works over postMessage().
+</p>
+<p>
+  Click on bottom below. Hit "Pay".
+</p>
+<ol>
+  <li>
+    <button onclick="runUserActivation(this)">
+      show() is triggered by user activation passed through postMessage() and a promise
+    </button>
+  </li>
+</ol>
+<iframe width="100%" id="iframe" src="show-method-postmessage-iframe.html" allowpaymentrequest></iframe>
+<p>
+  <small>
+    If you find a buggy test, please <a href="https://github.com/w3c/web-platform-tests/issues">file a bug</a>
+    and tag one of the <a href="https://github.com/w3c/web-platform-tests/blob/master/payment-request/OWNERS">owners</a>.
+  </small>
+</p>