diff options
Diffstat (limited to 'testing/web-platform/tests/shared-storage-selecturl-limit')
5 files changed, 247 insertions, 0 deletions
diff --git a/testing/web-platform/tests/shared-storage-selecturl-limit/resources/run-url-selection-operation-limit-inner.https.html b/testing/web-platform/tests/shared-storage-selecturl-limit/resources/run-url-selection-operation-limit-inner.https.html new file mode 100644 index 0000000000..c5d057f3e2 --- /dev/null +++ b/testing/web-platform/tests/shared-storage-selecturl-limit/resources/run-url-selection-operation-limit-inner.https.html @@ -0,0 +1,71 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/utils.js"></script> +<script src="/shared-storage-selecturl-limit/resources/utils.js"></script> +<script src="/shared-storage/resources/util.js"></script> +<script src="/fenced-frame/resources/utils.js"></script> + +<body> +<script> +'use strict'; + +function parseBitLimit() { + const url = new URL(location.href); + return parseInt(url.searchParams.get("bits")); +} + +async function init() { + const [outerKey] = parseKeylist(); + const bitLimit = parseBitLimit(); + const innerKey = token(); + const numUrls = 8; + const urls = generateUrls(numUrls, "/shared-storage/resources/frame", + [innerKey]); + const bitsPerCall = Math.log2(numUrls); + + await sharedStorage.worklet.addModule( + "/shared-storage/resources/simple-module.js"); + + for (let i = 0; i < Math.floor(bitLimit / bitsPerCall); ++i) { + let config = await sharedStorage.selectURL( + "test-url-selection-operation", urls, + {data: {'mockResult': 1}, keepAlive: true, resolveToConfig: true}); + assert_true(config instanceof FencedFrameConfig); + attachFencedFrame(config, 'opaque-ads'); + try { + const result = await nextValueFromServer(innerKey); + assert_equals(result, "frame1_loaded", + `for origin ${location.origin}, index ${i} when budget should remain;`); + } catch (error) { + writeValueToServer(outerKey, + `run_url_selection_limit_inner_failed ${error}`); + return; + } + } + + // Either the per-origin per-pageload bit limit or the overall per-pageload + // bit limit for `selectURL()` has been reached. The next call should return + // the default URL. + let config = await sharedStorage.selectURL( + "test-url-selection-operation", urls, + {data: {'mockResult': 1}, resolveToConfig: true}); + assert_true(config instanceof FencedFrameConfig); + attachFencedFrame(config, 'opaque-ads'); + try { + const result = await nextValueFromServer(innerKey); + assert_equals(result, "frame0_loaded", + `for origin ${location.origin} when budget should be exhausted;`); + } catch (error) { + writeValueToServer(outerKey, + `run_url_selection_limit_inner_failed ${error}`); + return; + } + + // No errors were caught, so this portion of the test succeeded. + writeValueToServer(outerKey, "run_url_selection_limit_inner_succeeded"); +} + +init(); +</script> +</body> diff --git a/testing/web-platform/tests/shared-storage-selecturl-limit/resources/utils.js b/testing/web-platform/tests/shared-storage-selecturl-limit/resources/utils.js new file mode 100644 index 0000000000..a7462147d7 --- /dev/null +++ b/testing/web-platform/tests/shared-storage-selecturl-limit/resources/utils.js @@ -0,0 +1,19 @@ +// META: script=/fenced-frame/resources/utils.js + +// Generate a list of URLs to use as input to sharedStorage.selectURL. +// @param {integer} size - The number of URLs to generate +// @param {string} pathPrefix - Prefix of the relative URL to use +// @param {string list} keylist - The list of key UUIDs to be used. Note that +// order matters when extracting the keys +// @return {SharedStorageUrlWithMetadata list} - A list of +// SharedStorageUrlWithMetadata +// dictionaries whose "url" +// values have `keylist` appended +// to their `searchParams` +function generateUrls(size, pathPrefix, keylist) { + return new Array(size).fill(0).map((e, i) => { + return { + url: generateURL(pathPrefix + i.toString() + '.html', keylist) + } + }); +} diff --git a/testing/web-platform/tests/shared-storage-selecturl-limit/run-url-selection-operation-limit-multiple-sites.tentative.https.sub.html b/testing/web-platform/tests/shared-storage-selecturl-limit/run-url-selection-operation-limit-multiple-sites.tentative.https.sub.html new file mode 100644 index 0000000000..b71c368704 --- /dev/null +++ b/testing/web-platform/tests/shared-storage-selecturl-limit/run-url-selection-operation-limit-multiple-sites.tentative.https.sub.html @@ -0,0 +1,63 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/utils.js"></script> +<script src="/common/get-host-info.sub.js"></script> +<script src="/shared-storage-selecturl-limit/resources/utils.js"></script> +<script src="/shared-storage/resources/util.js"></script> +<script src="/fenced-frame/resources/utils.js"></script> + +<body> +<script> +'use strict'; + +function getCrossSiteURL(url) { + return new URL(url.toString().replace(location.origin, + get_host_info().HTTPS_NOTSAMESITE_ORIGIN)); +} + +promise_test(async () => { + const ancestorKey = token(); + const perOriginBitLimit = 6; + const bitsKey = "bits"; + + let url0 = generateURL( + "/shared-storage-selecturl-limit/" + + "resources/run-url-selection-operation-limit-inner.https.html", + [ancestorKey]); + + // The per site per pageload limit is 6 bits. + url0.searchParams.append(bitsKey, perOriginBitLimit.toString()); + attachIFrame(url0); + const result0 = await nextValueFromServer(ancestorKey); + assert_equals(result0, "run_url_selection_limit_inner_succeeded"); + + let url1 = generateURL( + "/shared-storage-selecturl-limit/" + + "resources/run-url-selection-operation-limit-inner.https.html", + [ancestorKey]); + + // The overall pageload budget should have 3 bits remaining, as we have set + // it to start at 9. + url1.searchParams.append(bitsKey, "3"); + url1 = getCrossSiteURL(url1); + attachIFrame(url1); + const result1 = await nextValueFromServer(ancestorKey); + assert_equals(result1, "run_url_selection_limit_inner_succeeded"); + + let url2 = generateURL( + "/shared-storage-selecturl-limit/" + + "resources/run-url-selection-operation-limit-inner.https.html", + [ancestorKey]); + + // Since the overall per pageload limit is 9 bits here, it should have + // already been reached, even though `url2`'s site should have 3 bits + // remaining in the per-site budget, since it is same-site with `url1`. + url2.searchParams.append(bitsKey, "0"); + url2 = getCrossSiteURL(url2); + attachIFrame(url2); + const result2 = await nextValueFromServer(ancestorKey); + assert_equals(result2, "run_url_selection_limit_inner_succeeded"); +}, 'selectURL() with overall per-pageload limit'); +</script> +</body> diff --git a/testing/web-platform/tests/shared-storage-selecturl-limit/run-url-selection-operation-limit.tentative.https.sub.html b/testing/web-platform/tests/shared-storage-selecturl-limit/run-url-selection-operation-limit.tentative.https.sub.html new file mode 100644 index 0000000000..b8f8d5a4bf --- /dev/null +++ b/testing/web-platform/tests/shared-storage-selecturl-limit/run-url-selection-operation-limit.tentative.https.sub.html @@ -0,0 +1,48 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/utils.js"></script> +<script src="/shared-storage-selecturl-limit/resources/utils.js"></script> +<script src="/shared-storage/resources/util.js"></script> +<script src="/fenced-frame/resources/utils.js"></script> + +<body> +<script> +'use strict'; + +promise_test(async () => { + const ancestorKey = token(); + const perOriginBitLimit = 6; + const numUrls = 8; + const urls = generateUrls(numUrls, "/shared-storage/resources/frame", + [ancestorKey]); + const bitsPerCall = Math.log2(numUrls); + + await sharedStorage.worklet.addModule( + "/shared-storage/resources/simple-module.js"); + + + for (let i = 0; i < Math.floor(perOriginBitLimit / bitsPerCall); ++i) { + let config = await sharedStorage.selectURL( + "test-url-selection-operation", urls, + {data: {'mockResult': 1}, keepAlive: true, resolveToConfig: true}); + assert_true(config instanceof FencedFrameConfig); + attachFencedFrame(config, 'opaque-ads'); + const result = await nextValueFromServer(ancestorKey); + assert_equals(result, "frame1_loaded", + `for index ${i} when budget should remain;`); + } + + // The per-origin per-pageload bit limit for `selectURL()` has been + // reached. The next call should return the default URL. + let config = await sharedStorage.selectURL( + "test-url-selection-operation", urls, + {data: {'mockResult': 1}, resolveToConfig: true}); + assert_true(config instanceof FencedFrameConfig); + attachFencedFrame(config, 'opaque-ads'); + const result = await nextValueFromServer(ancestorKey); + assert_equals(result, "frame0_loaded", 'when budget should be exhausted;'); + +}, 'selectURL() with per-origin per-pageload limit'); +</script> +</body> diff --git a/testing/web-platform/tests/shared-storage-selecturl-limit/select-url-limit-multiple-worklets.tentative.https.sub.html b/testing/web-platform/tests/shared-storage-selecturl-limit/select-url-limit-multiple-worklets.tentative.https.sub.html new file mode 100644 index 0000000000..c0eedc6f5f --- /dev/null +++ b/testing/web-platform/tests/shared-storage-selecturl-limit/select-url-limit-multiple-worklets.tentative.https.sub.html @@ -0,0 +1,46 @@ +<!doctype html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/utils.js"></script> +<script src="/shared-storage-selecturl-limit/resources/utils.js"></script> +<script src="/shared-storage/resources/util.js"></script> +<script src="/fenced-frame/resources/utils.js"></script> + +<body> +<script> +'use strict'; + +promise_test(async () => { + const ancestorKey = token(); + const perOriginBitLimit = 6; + const numUrls = 8; + const urls = generateUrls(numUrls, "/shared-storage/resources/frame", + [ancestorKey]); + const bitsPerCall = Math.log2(numUrls); + + for (let i = 0; i < Math.floor(perOriginBitLimit / bitsPerCall); ++i) { + let worklet = await sharedStorage.createWorklet("/shared-storage/resources/simple-module.js"); + let config = await worklet.selectURL( + "test-url-selection-operation", urls, + {data: {'mockResult': 1}, keepAlive: true, resolveToConfig: true}); + assert_true(config instanceof FencedFrameConfig); + attachFencedFrame(config, 'opaque-ads'); + const result = await nextValueFromServer(ancestorKey); + assert_equals(result, "frame1_loaded", + `for index ${i} when budget should remain;`); + } + + // The per-origin per-pageload bit limit for `selectURL()` has been + // reached. The next call should return the default URL. + let worklet = await sharedStorage.createWorklet("/shared-storage/resources/simple-module.js"); + let config = await worklet.selectURL( + "test-url-selection-operation", urls, + {data: {'mockResult': 1}, resolveToConfig: true}); + assert_true(config instanceof FencedFrameConfig); + attachFencedFrame(config, 'opaque-ads'); + const result = await nextValueFromServer(ancestorKey); + assert_equals(result, "frame0_loaded", 'when budget should be exhausted;'); + +}, 'selectURL() called on multiple worklets, with per-origin per-pageload limit'); +</script> +</body> |