1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 Services.prefs.setBoolPref("network.http.debug-observations", true);
7 registerCleanupFunction(function () {
8 Services.prefs.clearUserPref("network.http.debug-observations");
12 // 1. Load file_link_header.sjs
13 // 2.`<link rel="preconnect" href="https://localhost">` is in
14 // file_link_header.sjs, so we will create a speculative connection.
15 // 3. We use "speculative-connect-request" topic to observe whether the
16 // speculative connection is attempted.
17 // 4. Finally, we check if the observed host and partition key are the same and
19 add_task(async function test_link_preconnect() {
20 let requestUrl = `https://example.com/browser/netwerk/test/browser/file_link_header.sjs`;
24 QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
25 observe(aSubject, aTopic, aData) {
26 if (aTopic == "speculative-connect-request") {
27 Services.obs.removeObserver(observer, "speculative-connect-request");
32 Services.obs.addObserver(observer, "speculative-connect-request");
34 await BrowserTestUtils.withNewTab(
43 // The hash key should be like:
44 // ".S........[tlsflags0x00000000]localhost:443^partitionKey=%28https%2Cexample.com%29"
46 // Extracting "localhost:443"
47 let hostPortRegex = /\[.*\](.*?)\^/;
48 let hostPortMatch = hostPortRegex.exec(observed);
49 let hostPort = hostPortMatch ? hostPortMatch[1] : "";
50 // Extracting "%28https%2Cexample.com%29"
51 let partitionKeyRegex = /\^partitionKey=(.*)$/;
52 let partitionKeyMatch = partitionKeyRegex.exec(observed);
53 let partitionKey = partitionKeyMatch ? partitionKeyMatch[1] : "";
55 Assert.equal(hostPort, "localhost:443");
56 Assert.equal(partitionKey, "%28https%2Cexample.com%29");