summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/popupNotifications/browser_displayURI.js
blob: c9e677cd4530e832f9bac71d006beb129436e4cb (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
 * Make sure that the correct origin is shown for permission prompts.
 */

async function check(contentTask, options = {}) {
  await BrowserTestUtils.withNewTab(
    "https://test1.example.com/",
    async function (browser) {
      let popupShownPromise = waitForNotificationPanel();
      await SpecialPowers.spawn(browser, [], contentTask);
      let panel = await popupShownPromise;
      let notification = panel.children[0];
      let body = notification.querySelector(".popup-notification-body");
      ok(
        body.innerHTML.includes("example.com"),
        "Check that at least the eTLD+1 is present in the markup"
      );
    }
  );

  let channel = NetUtil.newChannel({
    uri: getRootDirectory(gTestPath),
    loadUsingSystemPrincipal: true,
  });
  channel = channel.QueryInterface(Ci.nsIFileChannel);

  await BrowserTestUtils.withNewTab(
    channel.file.path,
    async function (browser) {
      let popupShownPromise = waitForNotificationPanel();
      await SpecialPowers.spawn(browser, [], contentTask);
      let panel = await popupShownPromise;
      let notification = panel.children[0];
      let body = notification.querySelector(".popup-notification-body");
      if (
        notification.id == "geolocation-notification" ||
        notification.id == "xr-notification"
      ) {
        ok(
          body.innerHTML.includes("local file"),
          `file:// URIs should be displayed as local file.`
        );
      } else {
        ok(
          body.innerHTML.includes("Unknown origin"),
          "file:// URIs should be displayed as unknown origin."
        );
      }
    }
  );

  if (!options.skipOnExtension) {
    // Test the scenario also on the extension page if not explicitly unsupported
    // (e.g. an extension page can't be navigated on a blob URL).
    let extension = ExtensionTestUtils.loadExtension({
      manifest: {
        name: "Test Extension Name",
      },
      background() {
        let { browser } = this;
        browser.test.sendMessage(
          "extension-tab-url",
          browser.runtime.getURL("extension-tab-page.html")
        );
      },
      files: {
        "extension-tab-page.html": `<!DOCTYPE html><html><body></body></html>`,
      },
    });

    await extension.startup();
    let extensionURI = await extension.awaitMessage("extension-tab-url");

    await BrowserTestUtils.withNewTab(extensionURI, async function (browser) {
      let popupShownPromise = waitForNotificationPanel();
      await SpecialPowers.spawn(browser, [], contentTask);
      let panel = await popupShownPromise;
      let notification = panel.children[0];
      let body = notification.querySelector(".popup-notification-body");
      ok(
        body.innerHTML.includes("Test Extension Name"),
        "Check the the extension name is present in the markup"
      );
    });

    await extension.unload();
  }
}

add_setup(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["media.navigator.permission.fake", true],
      ["media.navigator.permission.force", true],
      ["dom.vr.always_support_vr", true],
    ],
  });
});

add_task(async function test_displayURI_geo() {
  await check(async function () {
    content.navigator.geolocation.getCurrentPosition(() => {});
  });
});

const kVREnabled = SpecialPowers.getBoolPref("dom.vr.enabled");
if (kVREnabled) {
  add_task(async function test_displayURI_xr() {
    await check(async function () {
      content.navigator.getVRDisplays();
    });
  });
}

add_task(async function test_displayURI_camera() {
  await check(async function () {
    content.navigator.mediaDevices.getUserMedia({ video: true, fake: true });
  });
});

add_task(async function test_displayURI_geo_blob() {
  await check(
    async function () {
      let text =
        "<script>navigator.geolocation.getCurrentPosition(() => {})</script>";
      let blob = new Blob([text], { type: "text/html" });
      let url = content.URL.createObjectURL(blob);
      content.location.href = url;
    },
    { skipOnExtension: true }
  );
});

if (kVREnabled) {
  add_task(async function test_displayURI_xr_blob() {
    await check(
      async function () {
        let text = "<script>navigator.getVRDisplays()</script>";
        let blob = new Blob([text], { type: "text/html" });
        let url = content.URL.createObjectURL(blob);
        content.location.href = url;
      },
      { skipOnExtension: true }
    );
  });
}

add_task(async function test_displayURI_camera_blob() {
  await check(
    async function () {
      let text =
        "<script>navigator.mediaDevices.getUserMedia({video: true, fake: true})</script>";
      let blob = new Blob([text], { type: "text/html" });
      let url = content.URL.createObjectURL(blob);
      content.location.href = url;
    },
    { skipOnExtension: true }
  );
});