run-url-selection-operation-limit-inner.https.html (2483B)
1 <!doctype html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="/common/utils.js"></script> 5 <script src="/shared-storage-selecturl-limit/resources/utils.js"></script> 6 <script src="/shared-storage/resources/util.js"></script> 7 <script src="/fenced-frame/resources/utils.js"></script> 8 9 <body> 10 <script> 11 'use strict'; 12 13 function parseBitLimit() { 14 const url = new URL(location.href); 15 return parseInt(url.searchParams.get("bits")); 16 } 17 18 async function init() { 19 const [outerKey] = parseKeylist(); 20 const bitLimit = parseBitLimit(); 21 const innerKey = token(); 22 const numUrls = 8; 23 const urls = generateUrls(numUrls, "/shared-storage/resources/frame", 24 [innerKey]); 25 const bitsPerCall = Math.log2(numUrls); 26 27 await sharedStorage.worklet.addModule( 28 "/shared-storage/resources/simple-module.js"); 29 30 for (let i = 0; i < Math.floor(bitLimit / bitsPerCall); ++i) { 31 let config = await sharedStorage.selectURL( 32 "test-url-selection-operation", urls, 33 {data: {'mockResult': 1}, keepAlive: true, resolveToConfig: true}); 34 assert_true(config instanceof FencedFrameConfig); 35 attachFencedFrame(config, 'opaque-ads'); 36 try { 37 const result = await nextValueFromServer(innerKey); 38 assert_equals(result, "frame1_loaded", 39 `for origin ${location.origin}, index ${i} when budget should remain;`); 40 } catch (error) { 41 writeValueToServer(outerKey, 42 `run_url_selection_limit_inner_failed ${error}`); 43 return; 44 } 45 } 46 47 // Either the per-origin per-pageload bit limit or the overall per-pageload 48 // bit limit for `selectURL()` has been reached. The next call should return 49 // the default URL. 50 let config = await sharedStorage.selectURL( 51 "test-url-selection-operation", urls, 52 {data: {'mockResult': 1}, resolveToConfig: true}); 53 assert_true(config instanceof FencedFrameConfig); 54 attachFencedFrame(config, 'opaque-ads'); 55 try { 56 const result = await nextValueFromServer(innerKey); 57 assert_equals(result, "frame0_loaded", 58 `for origin ${location.origin} when budget should be exhausted;`); 59 } catch (error) { 60 writeValueToServer(outerKey, 61 `run_url_selection_limit_inner_failed ${error}`); 62 return; 63 } 64 65 // No errors were caught, so this portion of the test succeeded. 66 writeValueToServer(outerKey, "run_url_selection_limit_inner_succeeded"); 67 } 68 69 init(); 70 </script> 71 </body>