-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathbrowser_modifiedclick_inherit_principal.js
42 lines (40 loc) · 1.78 KB
/
browser_modifiedclick_inherit_principal.js
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
"use strict";
const kURL =
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
"http://example.com/browser/browser/base/content/test/general/dummy_page.html";
("data:text/html,<a href=''>Middle-click me</a>");
/*
* Check that when manually opening content JS links in new tabs/windows,
* we use the correct principal, and we don't clear the URL bar.
*/
add_task(async function () {
await BrowserTestUtils.withNewTab(kURL, async function (browser) {
let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser);
await SpecialPowers.spawn(browser, [], async function () {
let a = content.document.createElement("a");
// newTabPromise won't resolve until it has a URL that's not "about:blank".
// But doing document.open() from inside that same document does not change
// the URL of the docshell. So we need to do some URL change to cause
// newTabPromise to resolve, since the document is at about:blank the whole
// time, URL-wise. Navigating to '#' should do the trick without changing
// anything else about the document involved.
a.href =
"javascript:document.write('spoof'); location.href='#'; void(0);";
a.textContent = "Some link";
content.document.body.appendChild(a);
});
info("Added element");
await BrowserTestUtils.synthesizeMouseAtCenter("a", { button: 1 }, browser);
let newTab = await newTabPromise;
is(
newTab.linkedBrowser.contentPrincipal.origin,
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
"http://example.com",
"Principal should be for example.com"
);
await BrowserTestUtils.switchTab(gBrowser, newTab);
info(gURLBar.value);
isnot(gURLBar.value, "", "URL bar should not be empty.");
BrowserTestUtils.removeTab(newTab);
});
});