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
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const USER_CONTEXTS = ["default", "personal", "work"];
const BASE_URI =
"http://mochi.test:8888/browser/browser/components/" +
"contextualidentity/test/browser/empty_file.html";
add_setup(async function () {
// make sure userContext is enabled.
await SpecialPowers.pushPrefEnv({
set: [
["privacy.userContext.enabled", true],
["browser.link.open_newwindow", 3],
],
});
});
add_task(async function test() {
info("Creating first tab...");
let tab1 = BrowserTestUtils.addTab(gBrowser, BASE_URI + "?old", {
userContextId: 1,
});
let browser1 = gBrowser.getBrowserForTab(tab1);
await BrowserTestUtils.browserLoaded(browser1);
await SpecialPowers.spawn(browser1, [], function (opts) {
content.window.name = "tab-1";
});
info("Creating second tab...");
let tab2 = BrowserTestUtils.addTab(gBrowser, BASE_URI + "?old", {
userContextId: 2,
});
let browser2 = gBrowser.getBrowserForTab(tab2);
await BrowserTestUtils.browserLoaded(browser2);
await SpecialPowers.spawn(browser2, [], function (opts) {
content.window.name = "tab-2";
});
// Let's try to open a window from tab1 with a name 'tab-2'.
info("Opening a window from the first tab...");
await SpecialPowers.spawn(
browser1,
[{ url: BASE_URI + "?new" }],
async function (opts) {
await new content.window.wrappedJSObject.Promise(resolve => {
let w = content.window.wrappedJSObject.open(opts.url, "tab-2");
w.onload = function () {
resolve();
};
});
}
);
is(browser1.contentTitle, "?old", "Tab1 title must be 'old'");
is(browser1.contentPrincipal.userContextId, 1, "Tab1 UCI must be 1");
is(browser2.contentTitle, "?old", "Tab2 title must be 'old'");
is(browser2.contentPrincipal.userContextId, 2, "Tab2 UCI must be 2");
let found = false;
for (let i = 0; i < gBrowser.tabs.length; ++i) {
let tab = gBrowser.tabs[i];
let browser = gBrowser.getBrowserForTab(tab);
if (browser.contentTitle == "?new") {
is(browser.contentPrincipal.userContextId, 1, "Tab3 UCI must be 1");
isnot(browser, browser1, "Tab3 is not browser 1");
isnot(browser, browser2, "Tab3 is not browser 2");
gBrowser.removeTab(tab);
found = true;
break;
}
}
ok(found, "We have tab3");
gBrowser.removeTab(tab1);
gBrowser.removeTab(tab2);
});
|