tor-browser

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

select-url-saved-query-inner.https.sub.html (3094B)


      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 numUrls = url.searchParams.get("urlcount") ?
     20        parseInt(url.searchParams.get("urlcount")) : 8;
     21  const moduleName = url.searchParams.get("module") ?
     22        url.searchParams.get("module") : "simple-module";
     23  const operationName = url.searchParams.get("operation") ?
     24        url.searchParams.get("operation") : "test-url-selection-operation";
     25  const expectSaved = url.searchParams.get("expectsaved") ?
     26        (url.searchParams.get("expectsaved") !== "false") : false;
     27  const expectSuccess = url.searchParams.get("expectsuccess") ?
     28        (url.searchParams.get("expectsuccess") !== "false") : true;
     29  const innerKey = token();
     30  let parentOrOpener = window.opener || window.parent;
     31 
     32  // Note that we have set the site page bit limit to 6 and the overall page
     33  // bit limit to 12.
     34  const urls = generateUrls(numUrls, "/shared-storage/resources/frame",
     35                            [innerKey]);
     36 
     37  await sharedStorage.worklet.addModule(
     38      `/shared-storage/resources/${moduleName}.js`);
     39 
     40  function processSavedQuery(optionalData) {
     41    return sharedStorage.selectURL(
     42        operationName, urls,
     43        {data: optionalData, resolveToConfig: true, savedQuery: queryName});
     44  }
     45 
     46  const expected_result = expectSuccess ? `frame${mockResult}_loaded` :
     47      `frame0_loaded`;
     48  let frameMessage = {selectURLStatus: `success`, origin: `${location.origin}`,
     49                      query: queryName, mockResultIndex: mockResult,
     50                      module: moduleName, operation: operationName,
     51                      urlCount: numUrls, savedExpected: expectSaved,
     52                      successExpected: expectSuccess};
     53 
     54  // When we expect the query to be saved, omit specfying the index to return
     55  // in the data passed to `selectURL`, so that we can see that this data is
     56  // not relevant in the saved case.
     57  const queryData = expectSaved ? {} : {'mockResult': mockResult};
     58  let config0 = await processSavedQuery(queryData);
     59  assert_true(config0 instanceof FencedFrameConfig);
     60  attachFencedFrame(config0, 'opaque-ads');
     61  try {
     62    const result0 = await nextValueFromServer(innerKey);
     63    assert_equals(result0, expected_result);
     64  } catch (error) {
     65    frameMessage.selectURLStatus = `${error}`;
     66    parentOrOpener.postMessage(frameMessage, "*");
     67    return;
     68  }
     69 
     70  // No errors were caught, so this portion of the test succeeded.
     71  parentOrOpener.postMessage(frameMessage, "*");
     72 }
     73 
     74 init();
     75 </script>
     76 </body>