tor-browser

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

browser_refresh_after_document_write.js (1483B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /*
      5 Test that after using document.write(...), refreshing the document and calling write again,
      6 resulting document.URL is identical to the original URL.
      7 
      8 This testcase is aimed at preventing bug 619092
      9 */
     10 var testURL =
     11  "http://mochi.test:8888/browser/dom/html/test/file_refresh_after_document_write.html";
     12 let aTab, aBrowser;
     13 
     14 function test() {
     15  waitForExplicitFinish();
     16 
     17  aTab = BrowserTestUtils.addTab(gBrowser, testURL);
     18  aBrowser = gBrowser.getBrowserForTab(aTab);
     19  BrowserTestUtils.browserLoaded(aBrowser)
     20    .then(() => {
     21      is(
     22        aBrowser.currentURI.spec,
     23        testURL,
     24        "Make sure we start at the correct URL"
     25      );
     26 
     27      SpecialPowers.spawn(aBrowser, [], () => {
     28        // test_btn calls document.write() then reloads the document
     29        let test_btn = content.document.getElementById("test_btn");
     30 
     31        docShell.chromeEventHandler.addEventListener(
     32          "load",
     33          () => {
     34            test_btn.click();
     35          },
     36          { once: true, capture: true }
     37        );
     38 
     39        test_btn.click();
     40      });
     41 
     42      return BrowserTestUtils.browserLoaded(aBrowser);
     43    })
     44    .then(() => {
     45      return SpecialPowers.spawn(aBrowser, [], () => content.document.URL);
     46    })
     47    .then(url => {
     48      is(url, testURL, "Document URL should be identical after reload");
     49      gBrowser.removeTab(aTab);
     50      finish();
     51    });
     52 }