tor-browser

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

fedcm-iframe.https.html (3757B)


      1 <!doctype html>
      2 <link rel="help" href="https://wicg.github.io/FedCM">
      3 <meta name="timeout" content="long">
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/resources/testdriver.js"></script>
      7 <script src="/resources/testdriver-vendor.js"></script>
      8 <script src="/common/get-host-info.sub.js"></script>
      9 <div id=log>
     10 <script type="module">
     11 'use strict';
     12 
     13 import {fedcm_test, set_fedcm_cookie} from './support/fedcm-helper.sub.js';
     14 
     15 const host = get_host_info();
     16 // This regex removes the filename from the path so that we just get
     17 // the directory.
     18 const basePath = window.location.pathname.replace(/\/[^\/]*$/, '/');
     19 const remoteBaseURL = host.HTTPS_REMOTE_ORIGIN + basePath;
     20 const localhostBaseURL = "http://localhost:" + host.HTTP_PORT + basePath;
     21 
     22 async function createIframeAndWaitForMessage(test, iframeUrl, setPermissionPolicy, style = "") {
     23    const messageWatcher = new EventWatcher(test, window, "message");
     24    let iframe = document.createElement("iframe");
     25    iframe.src = iframeUrl;
     26    if (setPermissionPolicy) {
     27      iframe.allow = "identity-credentials-get";
     28    }
     29    if (style !== "") {
     30      iframe.style = style;
     31    }
     32    document.body.appendChild(iframe);
     33    let message = null;
     34    // Ignore internal "testdriver-complete" messages.
     35    do {
     36        message = await messageWatcher.wait_for("message");
     37    } while (!("result" in message.data));
     38    return message.data;
     39 }
     40 
     41 fedcm_test(async t => {
     42  const message = await createIframeAndWaitForMessage(
     43      t, remoteBaseURL + "support/fedcm-iframe.html",
     44      /*setPermissionPolicy=*/false);
     45  assert_equals(message.result, "Fail");
     46  assert_equals(message.errorType, "NotAllowedError");
     47 }, "FedCM disabled in cross origin iframe without permissions policy");
     48 
     49 fedcm_test(async t => {
     50  const message = await createIframeAndWaitForMessage(
     51      t, remoteBaseURL + "support/fedcm-iframe-level2.html",
     52      /*setPermissionPolicy=*/true);
     53  assert_equals(message.result, "Pass");
     54  assert_equals(message.token, "token");
     55 }, "FedCM enabled in 2 level deep nested iframe. FedCM should be enabled regardless of iframe nesting depth");
     56 
     57 fedcm_test(async t => {
     58  const message = await createIframeAndWaitForMessage(
     59      t, remoteBaseURL + "support/fedcm-iframe.html",
     60      /*setPermissionPolicy=*/true, /*style=*/"display:none;");
     61  assert_equals(message.result, "Pass");
     62  assert_equals(message.token, "token");
     63 }, "FedCM enabled in invisible iframe. FedCM should be enabled as long as the top frame is visible");
     64 
     65 fedcm_test(async t => {
     66  const message = await createIframeAndWaitForMessage(
     67      t, remoteBaseURL + "support/fedcm-iframe-level2.html",
     68      /*setPermissionPolicy=*/false);
     69  assert_equals(message.result, "Fail");
     70  assert_equals(message.errorType, "NotAllowedError");
     71 }, "FedCM disabled in 2 level deep nested iframe where middle iframe does not have permission policy");
     72 
     73 fedcm_test(async t => {
     74  const message = await createIframeAndWaitForMessage(
     75      t, remoteBaseURL + "support/fedcm-iframe-level2.html?permission=0",
     76      /*setPermissionPolicy=*/true);
     77  assert_equals(message.result, "Fail");
     78  assert_equals(message.errorType, "NotAllowedError");
     79 }, "FedCM disabled in 2 level deep nested iframe where innermost iframe does not have permission policy");
     80 
     81 fedcm_test(async t => {
     82  // This is only an iframe because there's no other way to have this URL
     83  // loaded from localhost.
     84  const message = await createIframeAndWaitForMessage(
     85      t, localhostBaseURL + "support/fedcm-iframe.html",
     86      /*setPermissionPolicy=*/true);
     87  assert_equals(message.result, "Pass");
     88  assert_equals(message.token, "token");
     89 }, "FedCM should work in non-HTTPS URLs on localhost");
     90 
     91 </script>