Skip to content

Commit

Permalink
Test snapshotting of allowpaymentrequest attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
zcorpan committed Jan 19, 2017
1 parent 2f8e46c commit 9a00e4a
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
18 changes: 18 additions & 0 deletions payment-request/allowpaymentrequest/echo-PaymentRequest.html
@@ -0,0 +1,18 @@
<!doctype html>
<script>
window.onmessage = (e) => {
const paymentArgs = [[{supportedMethods: ['foo']}], {total: {label: 'label', amount: {currency: 'USD', value: '5.00'}}}];

if (e.data === 'What is the result of new PaymentRequest(...)?') {
try {
new PaymentRequest(...paymentArgs);
e.source.postMessage({message: 'Success'}, '*');
} catch(ex) {
e.source.postMessage({message: 'Exception', details: [ex instanceof DOMException, ex.code, ex.name]}, '*');
}
} else {
e.source.postMessage({message: 'Incorrect message'}, '*');
}
}
</script>
<p>This page echos the result of new PaymentRequest(...).</p>
@@ -0,0 +1,38 @@
<!doctype html>
<title>PaymentRequest removing allowpaymentrequest after load and then navigating</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id="log"></div>
<script>
async_test((t) => {
const iframe = document.createElement('iframe');
iframe.allowPaymentRequest = true;

let i = 0;

const path = location.pathname.substring(0, location.pathname.lastIndexOf('/') + 1);
iframe.src = "https://{{domains[www1]}}:{{ports[https][0]}}" + path + "echo-PaymentRequest.html";
iframe.onload = t.step_func(() => {
if (i === 0) {
iframe.allowPaymentRequest = false;
}
iframe.contentWindow.postMessage('What is the result of new PaymentRequest(...)?', '*');
});

window.onmessage = t.step_func((e) => {
i++;
if (i === 1) {
assert_equals(e.data.message, 'Success', 'before navigation');

// Navigate the iframe. This will fire a second 'load' event on the iframe.
iframe.contentWindow.location.href = iframe.src + '?2';
} else {
assert_equals(e.data.message, 'Exception', 'after navigation');
assert_array_equals(e.data.details, [true /* ex instanceof DOMException*/, 18 /* ex.code */, 'SecurityError' /* ex.name */], 'after navigation');
t.done();
}
});

document.body.appendChild(iframe);
});
</script>
@@ -0,0 +1,31 @@
<!doctype html>
<title>PaymentRequest setting allowpaymentrequest after document creation, before response</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id="log"></div>
<script>
// Set allowpaymentrequest attribute in a timeout after <iframe> has been inserted to the document.
// The iframe's response is delayed so it happens after the attribute is set.

async_test((t) => {
const iframe = document.createElement('iframe');
// no allowpaymentrequest attribute

const path = location.pathname.substring(0, location.pathname.lastIndexOf('/') + 1);
iframe.src = "https://{{domains[www1]}}:{{ports[https][0]}}" + path + "echo-PaymentRequest.html?pipe=trickle(d3)";
iframe.onload = t.step_func(() => {
iframe.contentWindow.postMessage('What is the result of new PaymentRequest(...)?', '*');
});

window.onmessage = t.step_func_done((e) => {
assert_equals(e.data.message, 'Exception');
assert_array_equals(e.data.details, [true /* ex instanceof DOMException*/, 18 /* ex.code */, 'SecurityError' /* ex.name */]);
});

document.body.appendChild(iframe);

setTimeout(() => {
iframe.allowPaymentRequest = true;
}, 10);
});
</script>
@@ -0,0 +1,38 @@
<!doctype html>
<title>PaymentRequest setting allowpaymentrequest after load and then navigating</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id="log"></div>
<script>
async_test((t) => {
const iframe = document.createElement('iframe');
// no allowpaymentrequest attribute

let i = 0;

const path = location.pathname.substring(0, location.pathname.lastIndexOf('/') + 1);
iframe.src = "https://{{domains[www1]}}:{{ports[https][0]}}" + path + "echo-PaymentRequest.html";
iframe.onload = t.step_func(() => {
if (i === 0) {
iframe.allowPaymentRequest = true;
}
iframe.contentWindow.postMessage('What is the result of new PaymentRequest(...)?', '*');
});

window.onmessage = t.step_func((e) => {
i++;
if (i === 1) {
assert_equals(e.data.message, 'Exception', 'before navigation');
assert_array_equals(e.data.details, [true /* ex instanceof DOMException*/, 18 /* ex.code */, 'SecurityError' /* ex.name */], 'before navigation');

// Navigate the iframe. This will fire a second 'load' event on the iframe.
iframe.contentWindow.location.href = iframe.src + '?2';
} else {
assert_equals(e.data.message, 'Success', 'after navigation');
t.done();
}
});

document.body.appendChild(iframe);
});
</script>

0 comments on commit 9a00e4a

Please sign in to comment.