tor-browser

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

detector-iframe.https.html (3379B)


      1 <!DOCTYPE html>
      2 <meta name="timeout" content="long">
      3 <script src="/resources/testdriver.js"></script>
      4 <script src="/resources/testdriver-vendor.js"></script>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="/common/get-host-info.sub.js"></script>
      8 <body></body>
      9 <script>
     10 'use strict';
     11 
     12 const { HTTPS_ORIGIN, HTTPS_NOTSAMESITE_ORIGIN } = get_host_info();
     13 const PATH = location.pathname.substring(0, location.pathname.lastIndexOf('/') + 1);
     14 const IFRAME_PATH = PATH + 'resources/iframe-helper.html';
     15 
     16 const getId = (() => {
     17  let idCount = 0;
     18  return () => idCount++;
     19 })();
     20 
     21 function run_iframe_test(iframe, test_name) {
     22  const id = getId();
     23  iframe.contentWindow.postMessage({id, type: test_name}, '*');
     24  const {promise, resolve, reject} = Promise.withResolvers();
     25 
     26  window.onmessage = message => {
     27    if (message.data.id !== id){
     28      return;
     29    }
     30 
     31    if (message.data.success) {
     32      resolve(message.data.success);
     33    } else {
     34      reject(message.data.err)
     35    }
     36  }
     37 
     38  return promise;
     39 }
     40 
     41 function load_iframe(src, permission_policy) {
     42  let iframe = document.createElement('iframe');
     43  const {promise, resolve} = Promise.withResolvers();
     44 
     45  iframe.onload = () => {
     46    resolve(iframe);
     47  }
     48  iframe.src = src;
     49  iframe.allow = permission_policy;
     50  document.body.appendChild(iframe);
     51 
     52  return promise;
     53 }
     54 
     55 promise_test(async t => {
     56  const src = HTTPS_NOTSAMESITE_ORIGIN + IFRAME_PATH;
     57  const iframe = await load_iframe(src, /*permission_policy=*/"");
     58  await promise_rejects_dom(t, 'NotAllowedError',
     59    run_iframe_test(iframe, "LanguageDetectorCreate"));
     60 }, "Throw a 'NotAllowedError' when creating Language Detector within cross-origin iframe");
     61 
     62 promise_test(async t => {
     63  const src = HTTPS_NOTSAMESITE_ORIGIN + IFRAME_PATH;
     64  const iframe = await load_iframe(src, "language-detector");
     65 
     66  assert_equals(
     67    await run_iframe_test(iframe, "LanguageDetectorCreate"), 'Success');
     68 }, "Language Detector can be created within cross-origin iframe with permission policy");
     69 
     70 promise_test(async t => {
     71  const src = HTTPS_ORIGIN + IFRAME_PATH;
     72  const iframe = await load_iframe(src, /*permission_policy=*/"");
     73 
     74  assert_equals(
     75    await run_iframe_test(iframe, "LanguageDetectorCreate"), 'Success');
     76 }, "Language Detector can be used within same-origin iframe");
     77 
     78 promise_test(async t => {
     79  const src = HTTPS_NOTSAMESITE_ORIGIN + IFRAME_PATH;
     80  const iframe = await load_iframe(src, /*permission_policy=*/"");
     81 
     82  assert_equals(
     83    await run_iframe_test(iframe, "LanguageDetectorAvailability"), 'unavailable');
     84 }, "Language Detector is unavailable within cross-origin iframe");
     85 
     86 promise_test(async t => {
     87  const src = HTTPS_NOTSAMESITE_ORIGIN + IFRAME_PATH;
     88  const iframe = await load_iframe(src, "language-detector");
     89 
     90  assert_in_array(
     91  await run_iframe_test(iframe, "LanguageDetectorAvailability"),
     92    ['downloadable', 'downloading', 'available']);
     93 }, "Language Detector is available within cross-origin iframe with permission policy");
     94 
     95 promise_test(async t => {
     96  const src = HTTPS_ORIGIN + IFRAME_PATH;
     97  const iframe = await load_iframe(src, /*permission_policy=*/"");
     98 
     99  assert_in_array(
    100    await run_iframe_test(iframe, "LanguageDetectorAvailability"),
    101      ['downloadable', 'downloading', 'available']);
    102 }, "LanguageDetector is available within same-origin iframe");
    103 
    104 </script>