tor-browser

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

test_allow_opening_data_json.html (1238B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Bug 1403814: Allow toplevel data URI navigation data:application/json</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 <body>
     10 <script class="testbody" type="text/javascript">
     11 
     12 SimpleTest.waitForExplicitFinish();
     13 
     14 function test_toplevel_data_json() {
     15  const DATA_JSON = "data:application/json,{'my_json_key':'my_json_value'}";
     16 
     17  let win = window.open(DATA_JSON);
     18  let wrappedWin = SpecialPowers.wrap(win);
     19 
     20  // Unfortunately we can't detect whether the JSON has loaded or not using some
     21  // event, hence we are constantly polling location.href till we see that
     22  // the data: URI appears. Test times out on failure.
     23  var jsonLoaded = setInterval(function() {
     24    if (wrappedWin.document.location.href.startsWith("data:application/json")) {
     25      clearInterval(jsonLoaded);
     26      ok(true, "navigating to data:application/json allowed");
     27      wrappedWin.close();
     28      SimpleTest.finish();
     29    }
     30  }, 200);
     31 }
     32 
     33 SpecialPowers.pushPrefEnv({
     34  set: [["security.data_uri.block_toplevel_data_uri_navigations", true]]
     35 }, test_toplevel_data_json);
     36 
     37 </script>
     38 </body>
     39 </html>