Skip to content

Commit ef3c90f

Browse files
marcoscaceresvinicius0197
authored andcommitted
user activation must survive postMessage() to call show() (web-platform-tests#10090)
Check that we can call pr.show() in an iframe via postMessage(), which is triggered by user activation.
1 parent 66e0742 commit ef3c90f

File tree

5 files changed

+100
-13
lines changed

5 files changed

+100
-13
lines changed

.travis.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ language: python
44
branches:
55
only:
66
- master
7+
- key2
78
addons:
89
hosts:
910
- web-platform.test
@@ -73,7 +74,9 @@ matrix:
7374
apt:
7475
packages:
7576
- libnss3-tools
76-
env: JOB=wpt_integration TOXENV=py27,py27-flake8 SCRIPT=tools/ci/ci_wpt.sh
77+
env:
78+
- JOB=wpt_integration TOXENV=py27,py27-flake8 SCRIPT=tools/ci/ci_wpt.sh
79+
- RUN_JOB=1
7780
- os: linux
7881
python: "2.7"
7982
env: JOB=wptrunner_infrastructure SCRIPT=tools/ci/ci_wptrunner_infrastructure.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<h1>This iframe calls shows() via postMessage()</h1>
2+
<script>
3+
"use strict";
4+
const defaultMethods = Object.freeze([
5+
{ supportedMethods: "basic-card" },
6+
{ supportedMethods: "https://apple.com/pay" },
7+
]);
8+
9+
const defaultDetails = Object.freeze({
10+
id: "fail",
11+
total: {
12+
label: "Total",
13+
amount: {
14+
currency: "USD",
15+
value: "1.00",
16+
},
17+
},
18+
});
19+
20+
// We are going to use the id to prove that this works
21+
// which we will pass back to the caller
22+
window.onmessage = async event => {
23+
const { source, data: { id, request } } = event;
24+
switch (request) {
25+
case "show-payment-request": {
26+
const request = new PaymentRequest(defaultMethods, {
27+
...defaultDetails,
28+
id,
29+
});
30+
try {
31+
const response = await request.show();
32+
source.postMessage(response.toJSON(), window.location.origin);
33+
await response.complete();
34+
} catch (err) {
35+
source.postMessage({ requestId: "fail" }, window.location.origin);
36+
await request.abort();
37+
}
38+
}
39+
}
40+
};
41+
42+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>Test for PaymentRequest.show() method</title>
4+
<link rel="help" href="https://w3c.github.io/browser-payment-api/#show-method">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script>
8+
"use strict";
9+
setup({
10+
explicit_done: true,
11+
explicit_timeout: true,
12+
});
13+
14+
async function runUserActivation(button) {
15+
button.disabled = true;
16+
const { contentWindow: iframeWindow } = document.getElementById("iframe");
17+
const expectedId = "pass123";
18+
await Promise.resolve(); // next tick
19+
const promiseForResponse = new Promise(resolve => {
20+
window.onmessage = ({ data: { requestId } }) => resolve(requestId);
21+
});
22+
const ops = { id: expectedId, request: "show-payment-request" };
23+
iframeWindow.postMessage(ops, window.location.origin);
24+
promise_test(async () => {
25+
const actualId = await promiseForResponse;
26+
assert_equals(actualId, expectedId, "ids must match");
27+
}, button.textContent.trim());
28+
done();
29+
}
30+
</script>
31+
<h2>Test PaymentRequest.show() triggered by user activation using postMessage()</h2>
32+
<p>
33+
Tests that user activation works over postMessage().
34+
</p>
35+
<p>
36+
Click on bottom below. Hit "Pay".
37+
</p>
38+
<ol>
39+
<li>
40+
<button onclick="runUserActivation(this)">
41+
show() is triggered by user activation passed through postMessage() and a promise
42+
</button>
43+
</li>
44+
</ol>
45+
<iframe width="100%" id="iframe" src="show-method-postmessage-iframe.html" allowpaymentrequest></iframe>
46+
<p>
47+
<small>
48+
If you find a buggy test, please <a href="https://github.com/w3c/web-platform-tests/issues">file a bug</a>
49+
and tag one of the <a href="https://github.com/w3c/web-platform-tests/blob/master/payment-request/OWNERS">owners</a>.
50+
</small>
51+
</p>

tools/ci/before_install.sh

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
#!/bin/bash
2-
set -e
1+
export DISPLAY=:99.0
2+
sh -e /etc/init.d/xvfb start 1>&2
33

4-
if [[ -z ${RUN_JOB+x} && $(./wpt test-jobs --includes $JOB; echo $?) -eq 0 ]] || [[ $RUN_JOB -eq 1 ]]; then
5-
export RUN_JOB=1
6-
git submodule update --init --recursive 1>&2
7-
export DISPLAY=:99.0
8-
sh -e /etc/init.d/xvfb start 1>&2
9-
# For uploading the manifest
10-
export WPT_MANIFEST_FILE=$HOME/meta/MANIFEST-$(git rev-parse HEAD).json
11-
elif [[ -z ${RUN_JOB+x} ]]; then
12-
export RUN_JOB=0
13-
fi

tools/pytest.ini

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[pytest]
22
norecursedirs = .* {arch} *.egg html5lib third_party pywebsocket six wpt wptrunner
33
xfail_strict=true
4+
addopts = -v -s

0 commit comments

Comments
 (0)