tor-browser

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

fedcm-third-party-iframe.sub.html (1752B)


      1 <!doctype html>
      2 <script src="/resources/testdriver.js"></script>
      3 <script src="/resources/testdriver-vendor.js"></script>
      4 <script type="module">
      5 import {request_options_with_mediation_required,
      6        select_manifest,
      7        fedcm_expect_dialog,
      8        fedcm_get_dialog_type_promise} from './fedcm-helper.sub.js';
      9 
     10 // Loading the iframe in the test will make a FedCM call on load, and
     11 // trigger a postMessage upon completion.
     12 //
     13 // message {
     14 //   string result: "Pass" | "Fail"
     15 //   string token: token.token
     16 //   string errorType: error.name
     17 // }
     18 
     19 window.onload = async () => {
     20  window.test_driver.set_test_context(window.top);
     21  try {
     22    let options = request_options_with_mediation_required("manifest_iframe.py");
     23    if (location.search == "?active") {
     24      options.identity.mode = "active";
     25      await test_driver.bless();
     26    }
     27    const credentialPromise = navigator.credentials.get(options);
     28    let type = await fedcm_expect_dialog(
     29      credentialPromise,
     30      fedcm_get_dialog_type_promise(null)
     31    );
     32    if (type != "AccountChooser")
     33      throw "Incorrect dialog type: " + type;
     34    let titleAndSubtitle = await test_driver.get_fedcm_dialog_title();
     35    let iframeOrigin = "{{hosts[alt][]}}";
     36    let found = titleAndSubtitle.title.indexOf(iframeOrigin) != -1 ||
     37        (titleAndSubtitle.subtitle &&
     38         titleAndSubtitle.subtitle.indexOf(iframeOrigin) != -1);
     39    if (!found) {
     40      throw "Did not find iframe origin in title or subtitle: " +
     41          title + ", " + subtitle;
     42    }
     43    window.top.postMessage({result: "Pass"}, '*');
     44  } catch (error) {
     45    window.top.postMessage({result: "Fail: " + (error.name || error)}, '*');
     46  }
     47  try {
     48    await test_driver.fedcm_cancel_dialog();
     49  } catch (ex) {}
     50 };
     51 
     52 </script>