-
Notifications
You must be signed in to change notification settings - Fork 54
/
common.sub.js
61 lines (58 loc) · 1.75 KB
/
common.sub.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Test should set these:
// const expectSuccess = {'iframe': bool, 'frame': bool, 'object': bool, 'embed': bool};
// const setAllowPaymentRequest = bool;
// const testCrossOrigin = bool;
const tests = {};
window.onmessage = e => {
const result = e.data;
const tagName = result.urlQuery;
const t = tests[tagName];
t.step(() => {
if (expectSuccess[tagName]) {
assert_equals(result.message, "Success");
if (result.message === "Exception") {
const [, code, name, stack] = result.details;
assert_unreached(`Unexpected exception "${name}" (${code}) ${stack}`);
}
} else {
assert_equals(result.message, "Exception");
const detailsArray = result.details.slice(0,3);
assert_array_equals(detailsArray, [
true /*ex instanceof DOMException*/,
DOMException.SECURITY_ERR /*ex.code*/,
"SecurityError" /*ex.name*/,
]);
}
t.done();
});
};
["iframe", "frame", "object", "embed"].forEach((tagName, i) => {
tests[tagName] = async_test(t => {
const elm = document.createElement(tagName);
if (setAllowPaymentRequest) {
elm.setAttribute("allowpaymentrequest", "");
}
const path = location.pathname.substring(
0,
location.pathname.lastIndexOf("/") + 1
);
const url =
(testCrossOrigin ? "https://{{domains[www1]}}:{{ports[https][0]}}" : "") +
path +
"echo-PaymentRequest.html?" +
tagName;
if (tagName === "object") {
elm.data = url;
} else {
elm.src = url;
}
elm.onload = t.step_func(() => {
window[i].postMessage(
"What is the result of new PaymentRequest(...)?",
"*"
);
});
elm.onerror = t.unreached_func("elm.onerror");
document.body.appendChild(elm);
}, tagName);
});