tor-browser

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

browser_printpreview_crash.js (2910B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const TEST_URL =
      7  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      8  "http://example.com/browser/browser/base/content/test/tabcrashed/file_contains_emptyiframe.html";
      9 const DOMAIN = "example.com";
     10 
     11 /**
     12 * This is really a crashtest, but because we need PrintUtils this is written as a browser test.
     13 * Test that when we don't crash when trying to print a document in the following scenario -
     14 * A top level document has an iframe of different origin embedded (here example.com has test1.example.com iframe embedded)
     15 * and they both set their document.domain to be "example.com".
     16 */
     17 add_task(async function test() {
     18  // 1. Open a new tab and wait for it to load the top level doc
     19  let newTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL);
     20  let browser = newTab.linkedBrowser;
     21 
     22  // 2. Navigate the iframe within the doc and wait for the load to complete
     23  await SpecialPowers.spawn(browser, [], async function () {
     24    const iframe = content.document.querySelector("iframe");
     25    const loaded = new Promise(resolve => {
     26      iframe.addEventListener(
     27        "load",
     28        () => {
     29          resolve();
     30        },
     31        { once: true }
     32      );
     33    });
     34    iframe.src =
     35      // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     36      "http://test1.example.com/browser/browser/base/content/test/tabcrashed/file_iframe.html";
     37    await loaded;
     38  });
     39 
     40  // 3. Change the top level document's domain
     41  await SpecialPowers.spawn(browser, [DOMAIN], async function (domain) {
     42    content.document.domain = domain;
     43  });
     44 
     45  // 4. Get the reference to the iframe and change its domain
     46  const iframe = await SpecialPowers.spawn(browser, [], () => {
     47    return content.document.querySelector("iframe").browsingContext;
     48  });
     49 
     50  await SpecialPowers.spawn(iframe, [DOMAIN], domain => {
     51    content.document.domain = domain;
     52  });
     53 
     54  // 5. Try to print things
     55  ok(
     56    !document.querySelector(".printPreviewBrowser"),
     57    "Should NOT be in print preview mode at the start of this test."
     58  );
     59 
     60  // Enter print preview
     61  document.getElementById("cmd_print").doCommand();
     62  await BrowserTestUtils.waitForCondition(() => {
     63    let preview = document.querySelector(".printPreviewBrowser");
     64    return preview && BrowserTestUtils.isVisible(preview);
     65  });
     66 
     67  let ppBrowser = document.querySelector(
     68    ".printPreviewBrowser[previewtype=source]"
     69  );
     70  ok(ppBrowser, "Print preview browser was created");
     71 
     72  ok(true, "We did not crash.");
     73 
     74  // We haven't crashed! Exit the print preview.
     75  gBrowser.getTabDialogBox(gBrowser.selectedBrowser).abortAllDialogs();
     76  await BrowserTestUtils.waitForCondition(
     77    () => !document.querySelector(".printPreviewBrowser")
     78  );
     79 
     80  info("We are not in print preview anymore.");
     81 
     82  BrowserTestUtils.removeTab(newTab);
     83 });