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
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Services.prefs.setBoolPref("network.early-hints.enabled", true);
registerCleanupFunction(function () {
Services.prefs.clearUserPref("network.early-hints.enabled");
});
const { request_count_checking } = ChromeUtils.importESModule(
"resource://testing-common/early_hint_preload_test_helper.sys.mjs"
);
// Test steps:
// 1. Install an extension to observe the tabId.
// 2. Load early_hint_asset_html.sjs?as=image, so we should see a hinted
// request to early_hint_asset.sjs?as=image.
// 3. Check if the hinted request has the same tabId as
// early_hint_asset_html.sys.
add_task(async function test_103_asset_with_extension() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: [
"webRequest",
"webRequestBlocking",
"https://example.com/*",
],
},
background() {
let { browser } = this;
browser.webRequest.onBeforeRequest.addListener(
details => {
browser.test.sendMessage("request", {
url: details.url,
tabId: details.tabId,
});
return undefined;
},
{ urls: ["https://example.com/*"] },
["blocking"]
);
},
});
await extension.startup();
// reset the count
let headers = new Headers();
headers.append("X-Early-Hint-Count-Start", "");
await fetch(
"https://example.com/browser/netwerk/test/browser/early_hint_pixel_count.sjs",
{ headers }
);
let baseUrl = "https://example.com/browser/netwerk/test/browser/";
let requestUrl = `${baseUrl}early_hint_asset_html.sjs?as=image&hinted=1`;
let assetUrl = `${baseUrl}early_hint_asset.sjs?as=image`;
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: requestUrl,
waitForLoad: true,
},
async function () {}
);
const result1 = await extension.awaitMessage("request");
Assert.equal(result1.url, requestUrl);
let tabId = result1.tabId;
const result2 = await extension.awaitMessage("request");
Assert.equal(result2.url, assetUrl);
Assert.equal(result2.tabId, tabId);
await extension.unload();
});
|