tor-browser

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

test_fragment.html (2480B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4 <title>Bug 1694932: Https-only mode reloads the page in certain cases when there should be just a fragment navigation </title>
      5 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7 </head>
      8 <body>
      9 
     10 <script class="testbody" type="text/javascript">
     11 "use strict";
     12 /*
     13 * Description of the test:
     14 * Perform a test where a button click leads to scroll the page. Test if https-only detects
     15 * that the redirection address of the button is on the same page. Instead of a reload https-only
     16 * should only scroll.
     17 *
     18 * Test:
     19 * Enable https-only and load the url
     20 * Load: http://mozilla.pettay.fi/moztests/fragment.html
     21 * Click "Click me"
     22 * The page should be  scrolled down to 'foo' without a reload
     23 * It shouldn't receive a message 'before unload' because the on before unload
     24 *  function in file_fragment.html should not be called
     25 */
     26 
     27 SimpleTest.waitForExplicitFinish();
     28 
     29 const REQUEST_URL = "http://example.com/tests/dom/security/test/https-only/file_fragment.html";
     30 const EXPECT_URL = REQUEST_URL.replace("http://", "https://");
     31 let winTest = null;
     32 let checkButtonClicked = false;
     33 
     34 async function receiveMessage(event) {
     35  let data = event.data;
     36  // checks if click was successful
     37  if (!checkButtonClicked){
     38    // expected window location ( expected URL)
     39    ok(data.result == EXPECT_URL, "location is correct");
     40    ok(data.button, "button is clicked");
     41    // checks if loading was successful
     42    ok(data.info == "onload", "Onloading worked");
     43    // button was clicked
     44    checkButtonClicked = true;
     45    return;
     46  }
     47  // if Button was clicked once -> test finished
     48  // check if hash exist and if hash of location is correct
     49  ok(data.button, "button is clicked");
     50  ok(data.result == EXPECT_URL + "#foo", "location (hash) is correct");
     51  // check that page is scrolled not reloaded
     52  ok(data.info == "scrolled-to-foo","Scrolled successfully without reloading!");
     53  is(data.documentURI, EXPECT_URL + "#foo", "Document URI is correct");
     54  // complete test and close window
     55  window.removeEventListener("message",receiveMessage);
     56  winTest.close();
     57  SimpleTest.finish();
     58 }
     59 
     60 async function runTest() {
     61  //Test: With https-only mode activated
     62  await SpecialPowers.pushPrefEnv({ set: [
     63    ["dom.security.https_only_mode", true],
     64  ]});
     65  winTest = window.open(REQUEST_URL);
     66 }
     67 window.addEventListener("message", receiveMessage);
     68 runTest();
     69 
     70 </script>
     71 </body>
     72 </html>