select-url-saved-query-multi-frame-inner.https.sub.html (3701B)
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 async function init() { 14 const url = new URL(location.href); 15 const queryName = url.searchParams.get("query") ? 16 url.searchParams.get("query") : ""; 17 const mockResult = url.searchParams.get("mockresult") ? 18 parseInt(url.searchParams.get("mockresult")) : 1; 19 const innerKey = token(); 20 let parentOrOpener = window.opener || window.parent; 21 22 // Note that we have set the site page bit limit to 3 and the overall page 23 // bit limit to 6. A single saved query with 8 URLs (i.e. log2(8) = 3 bits) 24 // will be permitted by a site's page budget, plus re-uses of the saved 25 // query. Two saved queries with 8 URLs (and their re-uses) will be 26 // permitted by the overall page budget. 27 const numUrls = 8; 28 const urls = generateUrls(numUrls, "/shared-storage/resources/frame", 29 [innerKey]); 30 31 await sharedStorage.worklet.addModule( 32 "/shared-storage/resources/simple-module.js"); 33 34 function processSavedQuery(optionalData = {}) { 35 return sharedStorage.selectURL( 36 "test-url-selection-operation", urls, 37 {data: optionalData, keepAlive: true, resolveToConfig: true, 38 savedQuery: queryName}); 39 } 40 41 const expected_result = `frame${mockResult}_loaded`; 42 const message = {selectURLStatus: `success`, origin: `${location.origin}`, 43 query: queryName, mockResultIndex: mockResult}; 44 45 let config0 = await processSavedQuery({'mockResult': mockResult}); 46 assert_true(config0 instanceof FencedFrameConfig); 47 attachFencedFrame(config0, 'opaque-ads'); 48 try { 49 const result0 = await nextValueFromServer(innerKey); 50 assert_equals(result0, expected_result, 51 `for origin ${location.origin} when budget should remain;`); 52 } catch (error) { 53 message.selectURLStatus = `${error}`; 54 parentOrOpener.postMessage(message, "*"); 55 return; 56 } 57 58 // Either the per-site per-pageload bit limit or the overall per-pageload 59 // bit limit for `selectURL()` has been reached. The next non-saved-query 60 // call should return the default URL. 61 let config1 = await sharedStorage.selectURL( 62 "test-url-selection-operation", urls, 63 {data: {'mockResult': mockResult}, keepAlive: true, 64 resolveToConfig: true}); 65 assert_true(config1 instanceof FencedFrameConfig); 66 attachFencedFrame(config1, 'opaque-ads'); 67 try { 68 const result1 = await nextValueFromServer(innerKey); 69 assert_equals(result1, "frame0_loaded", 70 `for origin ${location.origin} when budget should be exhausted;`); 71 } catch (error) { 72 message.selectURLStatus = `${error}`; 73 parentOrOpener.postMessage(message, "*"); 74 return; 75 } 76 77 // Query should be saved and not cost any budget. 78 let config2 = await processSavedQuery(); 79 assert_true(config2 instanceof FencedFrameConfig); 80 attachFencedFrame(config2, 'opaque-ads'); 81 try { 82 const result2 = await nextValueFromServer(innerKey); 83 assert_equals(result2, expected_result, 84 `for origin ${location.origin} when budget should remain` 85 + ` for saved query ${queryName}.`); 86 } catch (error) { 87 message.selectURLStatus = `${error}`; 88 parentOrOpener.postMessage(message, "*"); 89 return; 90 } 91 92 // No errors were caught, so this portion of the test succeeded. 93 parentOrOpener.postMessage(message, "*"); 94 } 95 96 init(); 97 </script> 98 </body>