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
|
const TEST_PAGE =
"http://example.org/browser/browser/base/content/test/general/dummy_page.html";
const TEST_REFERRER = "http://mochi.test:8888/";
const ReferrerInfo = Components.Constructor(
"@mozilla.org/referrer-info;1",
"nsIReferrerInfo",
"init"
);
let referrerInfo = new ReferrerInfo(
Ci.nsIReferrerInfo.ORIGIN,
true,
Services.io.newURI(TEST_REFERRER)
);
let deReferrerInfo = E10SUtils.serializeReferrerInfo(referrerInfo);
var checkResult = async function(isRemote, browserKey, uri) {
is(
gBrowser.selectedBrowser.isRemoteBrowser,
isRemote,
"isRemoteBrowser should be correct"
);
is(
gBrowser.selectedBrowser.permanentKey,
browserKey,
"browser.permanentKey should be correct"
);
if (SpecialPowers.Services.appinfo.sessionHistoryInParent) {
let sessionHistory =
gBrowser.selectedBrowser.browsingContext.sessionHistory;
let entry = sessionHistory.getEntryAtIndex(sessionHistory.count - 1);
let args = { uri, referrerInfo: deReferrerInfo, isRemote };
Assert.equal(entry.URI.spec, args.uri, "Uri should be correct");
// Main process like about:mozilla does not trigger the real network request.
// So we don't store referrerInfo in sessionHistory in that case.
// Besides, the referrerInfo stored in sessionHistory was computed, we only
// check pre-computed things.
if (args.isRemote) {
let resultReferrerInfo = entry.referrerInfo;
let expectedReferrerInfo = E10SUtils.deserializeReferrerInfo(
args.referrerInfo
);
Assert.equal(
resultReferrerInfo.originalReferrer.spec,
expectedReferrerInfo.originalReferrer.spec,
"originalReferrer should be correct"
);
Assert.equal(
resultReferrerInfo.sendReferrer,
expectedReferrerInfo.sendReferrer,
"sendReferrer should be correct"
);
Assert.equal(
resultReferrerInfo.referrerPolicy,
expectedReferrerInfo.referrerPolicy,
"referrerPolicy should be correct"
);
} else {
Assert.equal(entry.referrerInfo, null, "ReferrerInfo should be correct");
}
return;
}
await SpecialPowers.spawn(
gBrowser.selectedBrowser,
[{ uri, referrerInfo: deReferrerInfo, isRemote }],
async function(args) {
let webNav = content.docShell.QueryInterface(Ci.nsIWebNavigation);
let sessionHistory = webNav.sessionHistory;
let entry = sessionHistory.legacySHistory.getEntryAtIndex(
sessionHistory.count - 1
);
var { E10SUtils } = SpecialPowers.Cu.import(
"resource://gre/modules/E10SUtils.jsm"
);
Assert.equal(entry.URI.spec, args.uri, "Uri should be correct");
// Main process like about:mozilla does not trigger the real network request.
// So we don't store referrerInfo in sessionHistory in that case.
// Besides, the referrerInfo stored in sessionHistory was computed, we only
// check pre-computed things.
if (args.isRemote) {
let resultReferrerInfo = entry.referrerInfo;
let expectedReferrerInfo = E10SUtils.deserializeReferrerInfo(
args.referrerInfo
);
Assert.equal(
resultReferrerInfo.originalReferrer.spec,
expectedReferrerInfo.originalReferrer.spec,
"originalReferrer should be correct"
);
Assert.equal(
resultReferrerInfo.sendReferrer,
expectedReferrerInfo.sendReferrer,
"sendReferrer should be correct"
);
Assert.equal(
resultReferrerInfo.referrerPolicy,
expectedReferrerInfo.referrerPolicy,
"referrerPolicy should be correct"
);
} else {
Assert.equal(
entry.referrerInfo,
null,
"ReferrerInfo should be correct"
);
}
}
);
};
var waitForLoad = async function(uri) {
info("waitForLoad " + uri);
let loadURIOptions = {
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
referrerInfo,
};
gBrowser.selectedBrowser.webNavigation.loadURI(uri, loadURIOptions);
await BrowserTestUtils.browserStopped(gBrowser, uri);
};
// Tests referrerInfo when navigating from a page in the remote process to main
// process and vice versa.
add_task(async function test_navigation() {
// Navigate from non remote to remote
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:blank");
let testURI = TEST_PAGE;
let { permanentKey } = gBrowser.selectedBrowser;
await waitForLoad(testURI);
await checkResult(true, permanentKey, testURI);
gBrowser.removeCurrentTab();
// Navigate from remote to non-remote
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, TEST_PAGE);
testURI = "about:mozilla";
permanentKey = gBrowser.selectedBrowser.permanentKey;
await waitForLoad(testURI);
await checkResult(false, permanentKey, testURI);
gBrowser.removeCurrentTab();
});
|