summaryrefslogtreecommitdiffstats
path: root/dom/security/test/general/browser_test_view_image_data_navigation.js
blob: 90aace1e3ec7d05475d0481a09c36869d6d3a7a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"use strict";

add_task(async function test_principal_right_click_open_link_in_new_tab() {
  await SpecialPowers.pushPrefEnv({
    set: [["security.data_uri.block_toplevel_data_uri_navigations", true]],
  });

  const TEST_PAGE =
    getRootDirectory(gTestPath) + "file_view_image_data_navigation.html";

  await BrowserTestUtils.withNewTab(TEST_PAGE, async function (browser) {
    let loadPromise = BrowserTestUtils.waitForNewTab(gBrowser, null, true);

    // simulate right-click->view-image
    BrowserTestUtils.waitForEvent(document, "popupshown", false, event => {
      // These are operations that must be executed synchronously with the event.
      document.getElementById("context-viewimage").doCommand();
      event.target.hidePopup();
      return true;
    });
    BrowserTestUtils.synthesizeMouseAtCenter(
      "#testimage",
      { type: "contextmenu", button: 2 },
      gBrowser.selectedBrowser
    );
    let tab = await loadPromise;

    let spec = tab.linkedBrowser.currentURI.spec;
    ok(
      spec.startsWith("data:image/svg+xml;"),
      "data:image/svg navigation allowed through right-click view-image"
    );

    gBrowser.removeTab(tab);
  });
});

add_task(async function test_right_click_open_bg_image() {
  await SpecialPowers.pushPrefEnv({
    set: [["security.data_uri.block_toplevel_data_uri_navigations", true]],
  });

  const TEST_PAGE =
    getRootDirectory(gTestPath) + "file_view_bg_image_data_navigation.html";

  await BrowserTestUtils.withNewTab(TEST_PAGE, async function (browser) {
    let loadPromise = BrowserTestUtils.waitForNewTab(gBrowser, null, true);

    // simulate right-click->view-image
    BrowserTestUtils.waitForEvent(document, "popupshown", false, event => {
      // These are operations that must be executed synchronously with the event.
      document.getElementById("context-viewimage").doCommand();
      event.target.hidePopup();
      return true;
    });
    BrowserTestUtils.synthesizeMouseAtCenter(
      "#testbody",
      { type: "contextmenu", button: 2 },
      gBrowser.selectedBrowser
    );
    let tab = await loadPromise;

    let spec = tab.linkedBrowser.currentURI.spec;
    ok(
      spec.startsWith("data:image/svg+xml;"),
      "data:image/svg navigation allowed through right-click view-image with background image"
    );

    gBrowser.removeTab(tab);
  });
});