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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
<!DOCTYPE html>
<title>Test Content Index API</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="resources/utils.js"></script>
<body>
<script>
const id = 'fenced-frame-id';
promise_test(async () => {
const frame = attachFencedFrameContext();
try {
await frame.execute(async (id) => {
navigator.serviceWorker.register(
"empty-worker.js", { scope: location.href });
const registration = await navigator.serviceWorker.ready;
return registration.index.add({
id,
title: 'same title',
description: 'same description',
url: 'resources/'
});
}, [id]);
assert_unreached('index.add executed without error; want error');
} catch(e) {
assert_equals(e.message, "Failed to execute 'add' on 'ContentIndex': " +
"ContentIndex is not allowed in fenced frames.")
}
}, 'index.add should fail inside a fenced frame');
promise_test(async () => {
const frame = attachFencedFrameContext();
try {
await frame.execute(async (id) => {
navigator.serviceWorker.register(
"empty-worker.js", { scope: location.href });
const registration = await navigator.serviceWorker.ready;
return registration.index.delete(id);
}, [id]);
assert_unreached('index.delete executed without error; want error');
} catch(e) {
assert_equals(e.message, "Failed to execute 'delete' on 'ContentIndex': " + "ContentIndex is not allowed in fenced frames.");
}
}, 'index.delete should fail inside a fenced frame');
promise_test(async () => {
const frame = attachFencedFrameContext();
try {
await frame.execute(async () => {
navigator.serviceWorker.register(
"empty-worker.js", { scope: location.href });
const registration = await navigator.serviceWorker.ready;
return registration.index.getAll();
});
assert_unreached('index.getAll executed without error; want error');
} catch(e) {
assert_equals(e.message, "Failed to execute 'getAll' on 'ContentIndex': " + "ContentIndex is not allowed in fenced frames.");
}
}, 'index.getAll should fail inside a fenced frame');
promise_test(async () => {
const frame = attachFencedFrameContext();
const message = await frame.execute(async () => {
const getController = () => {
if (navigator.serviceWorker.controller) {
return navigator.serviceWorker.controller;
}
return new Promise(resolve => {
navigator.serviceWorker.addEventListener('controllerchange', () => {
resolve(navigator.serviceWorker.controller);
});
});
};
navigator.serviceWorker.register(
"content-index-sw.js", { scope: location.href });
return new Promise(async resolve => {
const ctrl = await getController();
ctrl.postMessage('add');
navigator.serviceWorker.onmessage = e => {
resolve(e.data);
}
});
});
assert_equals(message, "Failed to execute 'add' on 'ContentIndex': " +
"ContentIndex is not allowed in fenced frames.");
}, 'index.add should fail from the service worker inside a fenced frame');
promise_test(async () => {
const frame = attachFencedFrameContext();
const message = await frame.execute(async () => {
const getController = () => {
if (navigator.serviceWorker.controller) {
return navigator.serviceWorker.controller;
}
return new Promise(resolve => {
navigator.serviceWorker.addEventListener('controllerchange', () => {
resolve(navigator.serviceWorker.controller);
});
});
};
navigator.serviceWorker.register(
"content-index-sw.js", { scope: location.href });
return new Promise(async resolve => {
const ctrl = await getController();
ctrl.postMessage('delete');
navigator.serviceWorker.onmessage = e => {
resolve(e.data);
}
});
});
assert_equals(message, "Failed to execute 'delete' on 'ContentIndex': " +
"ContentIndex is not allowed in fenced frames.");
}, 'index.delete should fail from the service worker inside a fenced frame');
promise_test(async () => {
const frame = attachFencedFrameContext();
const message = await frame.execute(async () => {
const getController = () => {
if (navigator.serviceWorker.controller) {
return navigator.serviceWorker.controller;
}
return new Promise(resolve => {
navigator.serviceWorker.addEventListener('controllerchange', () => {
resolve(navigator.serviceWorker.controller);
});
});
};
navigator.serviceWorker.register(
"content-index-sw.js", { scope: location.href });
return new Promise(async resolve => {
const ctrl = await getController();
ctrl.postMessage('getAll');
navigator.serviceWorker.onmessage = e => {
resolve(e.data);
}
});
});
assert_equals(message, "Failed to execute 'getAll' on 'ContentIndex': " +
"ContentIndex is not allowed in fenced frames.");
}, 'index.getAll should fail from the service worker inside a fenced frame');
</script>
</body>
|