tor-browser

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

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


      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() {
     28    return sharedStorage.selectURL(
     29        "test-slow-url-selection-operation", urls,
     30        {data: {'mockResult': 1}, keepAlive: true, resolveToConfig: true,
     31         savedQuery: "query"});
     32  }
     33 
     34  // Start initial query.
     35  const savedQueryPromise = processSavedQuery();
     36 
     37  // This query will be received before the initial query finishes processing.
     38  let config0 = await processSavedQuery();
     39  assert_true(config0 instanceof FencedFrameConfig);
     40  attachFencedFrame(config0, 'opaque-ads');
     41  const result0 = await nextValueFromServer(ancestorKey);
     42  assert_equals(result0, "frame1_loaded", 'when budget should remain;');
     43 
     44  // Wait for the initial query to finish processing.
     45  let config1 = await savedQueryPromise;
     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 that doesn't reuse a query should return the
     53  // default URL.
     54  let config2 = await sharedStorage.selectURL(
     55      "test-url-selection-operation", urls,
     56      {data: {'mockResult': 1}, keepAlive: true, resolveToConfig: true});
     57  assert_true(config2 instanceof FencedFrameConfig);
     58  attachFencedFrame(config2, 'opaque-ads');
     59  const result2 = await nextValueFromServer(ancestorKey);
     60    assert_equals(result2, "frame0_loaded", 'when budget should be exhausted;');
     61 
     62  // Reuse the saved query after processing is finished.
     63  let config3 = await processSavedQuery();;
     64  assert_true(config3 instanceof FencedFrameConfig);
     65  attachFencedFrame(config3, 'opaque-ads');
     66  const result3 = await nextValueFromServer(ancestorKey);
     67  assert_equals(result3, "frame1_loaded",
     68                'when budget still should not be charged;');
     69 }, 'selectURL() saved query does not deduct budget on re-use, even if the '
     70    + 'initial query has not yet resolved.');
     71 </script>
     72 </body>