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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
|
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<!-- Pull in executor_path needed by newPopup / newIframe -->
<script src="/html/cross-origin-embedder-policy/credentialless/resources/common.js"></script>
<!-- Pull in importScript / newPopup / newIframe -->
<script src="/html/anonymous-iframe/resources/common.js"></script>
<body>
<script>
const cache_exists_js = (cache_name, response_queue_name) => `
try {
const exists = await self.caches.has("${cache_name}");
if (exists) {
await send("${response_queue_name}", "true");
} else {
await send("${response_queue_name}", "false");
}
} catch {
await send("${response_queue_name}", "exception");
}
`;
const add_iframe_js = (iframe_origin, response_queue_uuid) => `
const importScript = ${importScript};
await importScript("/html/cross-origin-embedder-policy/credentialless" +
"/resources/common.js");
await importScript("/html/anonymous-iframe/resources/common.js");
await importScript("/common/utils.js");
await send("${response_queue_uuid}", newIframe("${iframe_origin}"));
`;
const same_site_origin = get_host_info().HTTPS_ORIGIN;
const cross_site_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;
async function create_test_iframes(t, response_queue_uuid) {
// Create a same-origin iframe in a cross-site popup.
const not_same_site_popup_uuid = newPopup(t, cross_site_origin);
await send(not_same_site_popup_uuid,
add_iframe_js(same_site_origin, response_queue_uuid));
const iframe_1_uuid = await receive(response_queue_uuid);
// Create a same-origin iframe in a same-site popup.
const same_origin_popup_uuid = newPopup(t, same_site_origin);
await send(same_origin_popup_uuid,
add_iframe_js(same_site_origin, response_queue_uuid));
const iframe_2_uuid = await receive(response_queue_uuid);
return [iframe_1_uuid, iframe_2_uuid];
}
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const response_queue_uuid = token();
const [iframe_1_uuid, iframe_2_uuid] =
await create_test_iframes(t, response_queue_uuid);
const cache_name = token();
await self.caches.open(cache_name);
t.add_cleanup(() => self.caches.delete(cache_name));
await send(iframe_2_uuid,
cache_exists_js(cache_name, response_queue_uuid));
if (await receive(response_queue_uuid) !== "true") {
reject("Cache not visible in same-top-level-site iframe");
}
await send(iframe_1_uuid,
cache_exists_js(cache_name, response_queue_uuid));
if (await receive(response_queue_uuid) !== "false") {
reject("Cache visible in not-same-top-level-site iframe");
}
resolve();
} catch (e) {
reject(e);
}
});
}, "CacheStorage caches shouldn't be shared with a cross-partition iframe");
const newWorker = (origin) => {
const worker_token = token();
const worker_url = origin + executor_worker_path + `&uuid=${worker_token}`;
const worker = new Worker(worker_url);
return worker_token;
}
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const response_queue_uuid = token();
const create_worker_js = (origin) => `
const importScript = ${importScript};
await importScript("/html/cross-origin-embedder-policy/credentialless" +
"/resources/common.js");
await importScript("/html/anonymous-iframe/resources/common.js");
await importScript("/common/utils.js");
const newWorker = ${newWorker};
await send("${response_queue_uuid}", newWorker("${origin}"));
`;
const [iframe_1_uuid, iframe_2_uuid] =
await create_test_iframes(t, response_queue_uuid);
// Create a dedicated worker in the cross-top-level-site iframe.
await send(iframe_1_uuid, create_worker_js(same_site_origin));
const worker_1_uuid = await receive(response_queue_uuid);
// Create a dedicated worker in the same-top-level-site iframe.
await send(iframe_2_uuid, create_worker_js(same_site_origin));
const worker_2_uuid = await receive(response_queue_uuid);
const cache_name = token();
await self.caches.open(cache_name);
t.add_cleanup(() => self.caches.delete(cache_name));
await send(worker_2_uuid,
cache_exists_js(cache_name, response_queue_uuid));
if (await receive(response_queue_uuid) !== "true") {
reject("Cache not visible in same-top-level-site worker");
}
await send(worker_1_uuid,
cache_exists_js(cache_name, response_queue_uuid));
if (await receive(response_queue_uuid) !== "false") {
reject("Cache visible in not-same-top-level-site worker");
}
resolve();
} catch (e) {
reject(e);
}
});
}, "CacheStorage caches shouldn't be shared with a cross-partition dedicated worker");
const newSharedWorker = (origin) => {
const worker_token = token();
const worker_url = origin + executor_worker_path + `&uuid=${worker_token}`;
const worker = new SharedWorker(worker_url, worker_token);
return worker_token;
}
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const response_queue_uuid = token();
const create_worker_js = (origin) => `
const importScript = ${importScript};
await importScript("/html/cross-origin-embedder-policy/credentialless" +
"/resources/common.js");
await importScript("/html/anonymous-iframe/resources/common.js");
await importScript("/common/utils.js");
const newSharedWorker = ${newSharedWorker};
await send("${response_queue_uuid}", newSharedWorker("${origin}"));
`;
const [iframe_1_uuid, iframe_2_uuid] =
await create_test_iframes(t, response_queue_uuid);
// Create a shared worker in the cross-top-level-site iframe.
await send(iframe_1_uuid, create_worker_js(same_site_origin));
const worker_1_uuid = await receive(response_queue_uuid);
// Create a shared worker in the same-top-level-site iframe.
await send(iframe_2_uuid, create_worker_js(same_site_origin));
const worker_2_uuid = await receive(response_queue_uuid);
const cache_name = token();
await self.caches.open(cache_name);
t.add_cleanup(() => self.caches.delete(cache_name));
await send(worker_2_uuid,
cache_exists_js(cache_name, response_queue_uuid));
if (await receive(response_queue_uuid) !== "true") {
reject("Cache not visible in same-top-level-site worker");
}
await send(worker_1_uuid,
cache_exists_js(cache_name, response_queue_uuid));
if (await receive(response_queue_uuid) !== "false") {
reject("Cache visible in not-same-top-level-site worker");
}
resolve();
} catch (e) {
reject(e);
}
});
}, "CacheStorage caches shouldn't be shared with a cross-partition shared worker");
const newServiceWorker = async (origin) => {
const worker_token = token();
const worker_url = origin + executor_service_worker_path +
`&uuid=${worker_token}`;
const worker_url_path = executor_service_worker_path.substring(0,
executor_service_worker_path.lastIndexOf('/'));
const scope = worker_url_path + "/not-used/";
const reg = await navigator.serviceWorker.register(worker_url,
{'scope': scope});
return worker_token;
}
promise_test(t => {
return new Promise(async (resolve, reject) => {
try {
const response_queue_uuid = token();
const create_worker_js = (origin) => `
const importScript = ${importScript};
await importScript("/html/cross-origin-embedder-policy/credentialless" +
"/resources/common.js");
await importScript("/html/anonymous-iframe/resources/common.js");
await importScript("/common/utils.js");
const newServiceWorker = ${newServiceWorker};
await send("${response_queue_uuid}", await newServiceWorker("${origin}"));
`;
const [iframe_1_uuid, iframe_2_uuid] =
await create_test_iframes(t, response_queue_uuid);
// Create a service worker in the same-top-level-site iframe.
await send(iframe_2_uuid, create_worker_js(same_site_origin));
const worker_2_uuid = await receive(response_queue_uuid);
t.add_cleanup(() =>
send(worker_2_uuid, "self.registration.unregister();"));
const cache_name = token();
await self.caches.open(cache_name);
t.add_cleanup(() => self.caches.delete(cache_name));
await send(worker_2_uuid,
cache_exists_js(cache_name, response_queue_uuid));
if (await receive(response_queue_uuid) !== "true") {
reject("Cache not visible in same-top-level-site worker");
}
// Create a service worker in the cross-top-level-site iframe. Note that
// if service workers are unpartitioned then this new service worker would
// replace the one created above. This is why we wait to create the second
// service worker until after we are done with the first one.
await send(iframe_1_uuid, create_worker_js(same_site_origin));
const worker_1_uuid = await receive(response_queue_uuid);
t.add_cleanup(() =>
send(worker_1_uuid, "self.registration.unregister();"));
await send(worker_1_uuid,
cache_exists_js(cache_name, response_queue_uuid));
if (await receive(response_queue_uuid) !== "false") {
reject("Cache visible in not-same-top-level-site worker");
}
resolve();
} catch (e) {
reject(e);
}
});
}, "CacheStorage caches shouldn't be shared with a cross-partition service worker");
</script>
</body>
|