summaryrefslogtreecommitdiffstats
path: root/browser/components/contextualidentity/test/browser/browser_relatedTab.js
blob: 56c72d599edff363667f18165a9c1d7f6c9a7aae (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
"use strict";

/*
 * Bug 1325014 - Adding tab related to current tab inherits current tab's container usercontextid unless otherwise specified
 */

add_task(async function() {
  let tab = BrowserTestUtils.addTab(gBrowser, "about:blank", {
    userContextId: 1,
  });
  let ReferrerInfo = Components.Constructor(
    "@mozilla.org/referrer-info;1",
    "nsIReferrerInfo",
    "init"
  );

  gBrowser.selectedTab = tab;
  let relatedTab = BrowserTestUtils.addTab(gBrowser, "about:blank", {
    relatedToCurrent: true,
  });
  is(
    relatedTab.getAttribute("usercontextid"),
    "1",
    "Related tab (relatedToCurrent) inherits current tab's usercontextid"
  );
  is(
    relatedTab.linkedBrowser.contentPrincipal.userContextId,
    1,
    "Related tab's browser actually inherits the current tab's usercontextid"
  );
  BrowserTestUtils.removeTab(relatedTab);

  gBrowser.selectedTab = tab;
  relatedTab = BrowserTestUtils.addTab(gBrowser, "about:blank", {
    relatedToCurrent: true,
    userContextId: 2,
  });
  is(
    relatedTab.getAttribute("usercontextid"),
    "2",
    "Related tab (relatedToCurrent) with overridden usercontextid"
  );
  is(
    relatedTab.linkedBrowser.contentPrincipal.userContextId,
    2,
    "Related tab's browser actually gets overridden usercontextid"
  );
  BrowserTestUtils.removeTab(relatedTab);

  gBrowser.selectedTab = tab;
  let referrerInfo = new ReferrerInfo(
    Ci.nsIReferrerInfo.EMPTY,
    true,
    gBrowser.currentURI
  );
  relatedTab = BrowserTestUtils.addTab(gBrowser, "about:blank", {
    referrerInfo,
  });
  is(
    relatedTab.getAttribute("usercontextid"),
    "1",
    "Related tab (referrer) inherits current tab's usercontextid"
  );
  is(
    relatedTab.linkedBrowser.contentPrincipal.userContextId,
    1,
    "Related tab's browser (referrer) actually inherits the current tab's usercontextid"
  );
  BrowserTestUtils.removeTab(relatedTab);

  gBrowser.selectedTab = tab;
  referrerInfo = new ReferrerInfo(
    Ci.nsIReferrerInfo.EMPTY,
    true,
    gBrowser.currentURI
  );
  relatedTab = BrowserTestUtils.addTab(gBrowser, "about:blank", {
    referrerInfo,
    userContextId: 2,
  });
  is(
    relatedTab.getAttribute("usercontextid"),
    "2",
    "Related tab (referrer) with overridden usercontextid"
  );
  is(
    relatedTab.linkedBrowser.contentPrincipal.userContextId,
    2,
    "Related tab's browser (referrer) actually gets overridden usercontextid"
  );
  BrowserTestUtils.removeTab(relatedTab);

  BrowserTestUtils.removeTab(tab);
});