tor-browser

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

browser_test_view_image_data_navigation.js (2400B)


      1 "use strict";
      2 
      3 add_task(async function test_principal_right_click_open_link_in_new_tab() {
      4  await SpecialPowers.pushPrefEnv({
      5    set: [
      6      ["test.wait300msAfterTabSwitch", true],
      7      ["security.data_uri.block_toplevel_data_uri_navigations", true],
      8    ],
      9  });
     10 
     11  const TEST_PAGE =
     12    getRootDirectory(gTestPath) + "file_view_image_data_navigation.html";
     13 
     14  await BrowserTestUtils.withNewTab(TEST_PAGE, async function () {
     15    let loadPromise = BrowserTestUtils.waitForNewTab(gBrowser, null, true);
     16 
     17    // simulate right-click->view-image
     18    BrowserTestUtils.waitForEvent(document, "popupshown", false, event => {
     19      // These are operations that must be executed synchronously with the event.
     20      document.getElementById("context-viewimage").doCommand();
     21      event.target.hidePopup();
     22      return true;
     23    });
     24    BrowserTestUtils.synthesizeMouseAtCenter(
     25      "#testimage",
     26      { type: "contextmenu", button: 2 },
     27      gBrowser.selectedBrowser
     28    );
     29    let tab = await loadPromise;
     30 
     31    let spec = tab.linkedBrowser.currentURI.spec;
     32    ok(
     33      spec.startsWith("data:image/svg+xml;"),
     34      "data:image/svg navigation allowed through right-click view-image"
     35    );
     36 
     37    gBrowser.removeTab(tab);
     38  });
     39 });
     40 
     41 add_task(async function test_right_click_open_bg_image() {
     42  await SpecialPowers.pushPrefEnv({
     43    set: [["security.data_uri.block_toplevel_data_uri_navigations", true]],
     44  });
     45 
     46  const TEST_PAGE =
     47    getRootDirectory(gTestPath) + "file_view_bg_image_data_navigation.html";
     48 
     49  await BrowserTestUtils.withNewTab(TEST_PAGE, async function () {
     50    let loadPromise = BrowserTestUtils.waitForNewTab(gBrowser, null, true);
     51 
     52    // simulate right-click->view-image
     53    BrowserTestUtils.waitForEvent(document, "popupshown", false, event => {
     54      // These are operations that must be executed synchronously with the event.
     55      document.getElementById("context-viewimage").doCommand();
     56      event.target.hidePopup();
     57      return true;
     58    });
     59    BrowserTestUtils.synthesizeMouseAtCenter(
     60      "#testbody",
     61      { type: "contextmenu", button: 2 },
     62      gBrowser.selectedBrowser
     63    );
     64    let tab = await loadPromise;
     65 
     66    let spec = tab.linkedBrowser.currentURI.spec;
     67    ok(
     68      spec.startsWith("data:image/svg+xml;"),
     69      "data:image/svg navigation allowed through right-click view-image with background image"
     70    );
     71 
     72    gBrowser.removeTab(tab);
     73  });
     74 });