tor-browser

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

test_console_messages.html (1297B)


      1 <!DOCTYPE HTML>
      2 <meta charset="utf-8">
      3 <title>Test for SRI console messages</title>
      4 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      5 <script>
      6 
      7 SimpleTest.waitForExplicitFinish();
      8 
      9 async function testSRIWarnings({ triggerLoad, messages }) {
     10  let waitForConsole = new Promise(resolve => {
     11    SimpleTest.monitorConsole(resolve, messages);
     12  });
     13  await triggerLoad();
     14  info(`ending monitorConsole`);
     15  SimpleTest.endMonitorConsole();
     16  info(`waiting for console`);
     17  await waitForConsole;
     18 }
     19 
     20 const kTests = [
     21  {
     22    triggerLoad() {
     23      let link = document.createElement("link");
     24      link.rel = "stylesheet";
     25      link.href = "style1.css";
     26      link.integrity = "sha384-invalid";
     27 
     28      return new Promise(r => {
     29        link.onerror = r;
     30        document.head.appendChild(link);
     31      });
     32    },
     33    messages: [
     34      {
     35        errorMessage: /The hash contained in the integrity attribute has the wrong length/,
     36      },
     37      {
     38        errorMessage: /None of the “sha384” hashes in the integrity attribute match the content of the subresource/,
     39        sourceName: location.href,
     40      }
     41    ],
     42  }
     43 ];
     44 
     45 (async function() {
     46  let i = 0;
     47  for (const test of kTests) {
     48    info("Starting test: " + ++i);
     49    await testSRIWarnings(test);
     50  }
     51  SimpleTest.finish();
     52 }());
     53 </script>