-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
trusted-types-navigation.html
100 lines (89 loc) · 3.68 KB
/
trusted-types-navigation.html
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
function expectMessage(filter) {
return new Promise(resolve => {
window.addEventListener("message", e => { if (filter(e)) resolve(); });
});
}
function expectViolationAsMessage(sample) {
const filter = e => ((e.data.effectiveDirective == "require-trusted-types-for" ||
e.data.effectiveDirective == "trusted-types") &&
(!sample || e.data.sample.startsWith(sample)));
return new expectMessage(filter);
}
function expectLoadedAsMessage(uri) {
const filter = e => (e.data.type == "DOMContentLoaded" &&
(!uri || e.data.uri.endsWith(uri)));
return new expectMessage(filter);
}
function openWindow(test, uri) {
const win = window.open(uri);
test.add_cleanup(_ => win.close());
}
promise_test(t => {
openWindow(t, "support/navigation-support.html");
return Promise.all([
expectLoadedAsMessage("navigation-support.html"),
expectViolationAsMessage("Location href"),
]);
}, "Navigate a window with javascript:-urls in enforcing mode.");
promise_test(t => {
openWindow(t, "support/navigation-support.html?defaultpolicy=1");
return Promise.all([
expectLoadedAsMessage("navigation-support.html?defaultpolicy=1"),
expectLoadedAsMessage("navigation-support.html?defaultpolicy=1&defaultpolicywashere"),
]);
}, "Navigate a window with javascript:-urls w/ default policy in enforcing mode.");
promise_test(t => {
const page = "navigation-report-only-support.html"
openWindow(t, `support/${page}`);
return Promise.all([
expectLoadedAsMessage(page),
expectLoadedAsMessage("navigation-support.html#continue"),
]);
}, "Navigate a window with javascript:-urls in report-only mode.");
promise_test(t => {
const page = "navigation-report-only-support.html?defaultpolicy=1";
openWindow(t, `support/${page}`);
return Promise.all([
expectLoadedAsMessage(page),
expectLoadedAsMessage("navigation-support.html?defaultpolicy=1#defaultpolicywashere"),
]);
}, "Navigate a window with javascript:-urls w/ default policy in report-only mode.");
promise_test(t => {
openWindow(t, "support/navigation-support.html?frame=1");
return Promise.all([
expectLoadedAsMessage("navigation-support.html?frame=1"),
expectViolationAsMessage("Location href"),
]);
}, "Navigate a frame with javascript:-urls in enforcing mode.");
promise_test(t => {
openWindow(t, "support/navigation-support.html?defaultpolicy=1&frame=1");
return Promise.all([
expectLoadedAsMessage("navigation-support.html?defaultpolicy=1&frame=1"),
expectLoadedAsMessage("navigation-support.html?defaultpolicy=1&frame=1&defaultpolicywashere"),
]);
}, "Navigate a frame with javascript:-urls w/ default policy in enforcing mode.");
promise_test(t => {
const page = "navigation-report-only-support.html?frame=1"
openWindow(t, `support/${page}`);
return Promise.all([
expectLoadedAsMessage(page),
expectLoadedAsMessage("navigation-support.html?frame=1#continue"),
]);
}, "Navigate a frame with javascript:-urls in report-only mode.");
promise_test(t => {
const page = "navigation-report-only-support.html?defaultpolicy=1&frame=1";
openWindow(t, `support/${page}`);
return Promise.all([
expectLoadedAsMessage(page),
expectLoadedAsMessage("navigation-support.html?defaultpolicy=1&frame=1#defaultpolicywashere"),
]);
}, "Navigate a frame with javascript:-urls w/ default policy in report-only mode.");
</script>
</body>