tor-browser

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

protocol-handler-validation.https.html (2463B)


      1 <!DOCTYPE html>
      2 <title>prerendered page calls to registerProtocolHandler should validate input synchronously</title>
      3 <meta name="timeout" content="long">
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/common/utils.js"></script>
      7 <script src="/common/dispatcher/dispatcher.js"></script>
      8 <script src="../resources/utils.js"></script>
      9 <script src="resources/utils.js"></script>
     10 
     11 <script>
     12 // Create a prerender page that attempts to use either registerProtocolHandler
     13 // or unregisterProtocolHandler with either an invalid scheme or an invalid
     14 // URL template. Validation of invalid parameters for both should happen
     15 // synchronously in prerendered pages.
     16 async function registerProtocolHandlerTestHelper(
     17    t, fn_name, scheme, url_template, expected_result) {
     18  const {exec} = await create_prerendered_page(t);
     19 
     20  const result = await exec((fn_name, scheme, url_template) => {
     21    try {
     22      navigator[fn_name](scheme, url_template);
     23    } catch (registerProtocolHandlerException) {
     24      return `failed with '${registerProtocolHandlerException.name}'`;
     25    }
     26    return 'success';
     27  }, [fn_name, scheme, url_template]);
     28 
     29  assert_equals(result, expected_result);
     30 }
     31 
     32 setup(() => assertSpeculationRulesIsSupported());
     33 
     34 promise_test(async t => {
     35  await registerProtocolHandlerTestHelper(
     36      t, 'registerProtocolHandler', 'notallowed', 'https://example.com/?%s',
     37      'failed with \'SecurityError\'');
     38 }, 'prerendering page registerProtocolHandler calls with invalid URI scheme should fail synchronously.');
     39 
     40 promise_test(async t => {
     41  await registerProtocolHandlerTestHelper(
     42      t, 'registerProtocolHandler', 'news', 'https://example.com/?',
     43      'failed with \'SyntaxError\'');
     44 }, 'prerendering page registerProtocolHandler calls with invalid URI template should fail synchronously.');
     45 
     46 promise_test(async t => {
     47  await registerProtocolHandlerTestHelper(
     48      t, 'unregisterProtocolHandler', 'notallowed', 'https://example.com/?%s',
     49      'failed with \'SecurityError\'');
     50 }, 'prerendering page unregisterProtocolHandler calls with invalid URI scheme should fail synchronously.');
     51 
     52 promise_test(async t => {
     53  await registerProtocolHandlerTestHelper(
     54      t, 'unregisterProtocolHandler', 'news', 'https://example.com/?',
     55      'failed with \'SyntaxError\'');
     56 }, 'prerendering page unregisterProtocolHandler calls with invalid URI template should fail synchronously.');
     57 </script>