tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

select-url-saved-query.tentative.https.sub.html (2587B)


      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 promise_test(async () => {
     14  const ancestorKey = token();
     15 
     16  // Note that we have set the site page bit limit to 3 and the overall page
     17  // bit limit to 6. A single saved query with 8 URLs (i.e. log2(8) = 3 bits)
     18  // will be permitted by the site's page budget, plus re-uses of the saved
     19  // query.
     20  const numUrls = 8;
     21  const urls = generateUrls(numUrls, "/shared-storage/resources/frame",
     22                            [ancestorKey]);
     23 
     24  await sharedStorage.worklet.addModule(
     25      "/shared-storage/resources/simple-module.js");
     26 
     27  function processSavedQuery(optionalData = {}) {
     28    return sharedStorage.selectURL(
     29        "test-url-selection-operation", urls,
     30        {data: optionalData, keepAlive: true, resolveToConfig: true,
     31         savedQuery: "query"});
     32  }
     33 
     34  let config0 = await processSavedQuery({'mockResult': 1});
     35  assert_true(config0 instanceof FencedFrameConfig);
     36  attachFencedFrame(config0, 'opaque-ads');
     37  const result0 = await nextValueFromServer(ancestorKey);
     38  assert_equals(result0, "frame1_loaded",
     39                 `when budget should remain;`);
     40 
     41  // The per-site per-pageload bit limit for `selectURL()` has been
     42  // reached, but a saved query should not trigger a page-budget charge.
     43  // Moreover, index 1 should be retrieved even though we omit providing
     44  // `data: {'mockResult': 1}` here.
     45  let config1 = await processSavedQuery();;
     46  assert_true(config1 instanceof FencedFrameConfig);
     47  attachFencedFrame(config1, 'opaque-ads');
     48  const result1 = await nextValueFromServer(ancestorKey);
     49  assert_equals(result1, "frame1_loaded", 'when budget should not be charged;');
     50 
     51  // The per-site per-pageload bit limit for `selectURL()` has been
     52  // reached. The next call should return the default URL.
     53  let config2 = await sharedStorage.selectURL(
     54      "test-url-selection-operation", urls,
     55      {data: {'mockResult': 1}, resolveToConfig: true});
     56  assert_true(config2 instanceof FencedFrameConfig);
     57  attachFencedFrame(config2, 'opaque-ads');
     58  const result2 = await nextValueFromServer(ancestorKey);
     59  assert_equals(result2, "frame0_loaded", 'when budget should be exhausted;');
     60 }, 'selectURL() saved query does not deduct budget on re-use');
     61 </script>
     62 </body>