Backed out 2 changesets (bug 1881078, bug 1879806) for causing dt failures @ devtools...
[gecko.git] / netwerk / test / browser / browser_103_preload.js
blob977ae83d68f259c3c4fc4d552b1fe130344b008b
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 "use strict";
7 Services.prefs.setBoolPref("network.early-hints.enabled", true);
8 // Disable mixed-content upgrading as this test is expecting HTTP image loads
9 Services.prefs.setBoolPref(
10   "security.mixed_content.upgrade_display_content",
11   false
14 const { request_count_checking, test_preload_url, test_hint_preload } =
15   ChromeUtils.importESModule(
16     "resource://testing-common/early_hint_preload_test_helper.sys.mjs"
17   );
19 // TODO testing:
20 //  * Abort main document load while early hint is still loading -> early hint should be aborted
22 // Test that with early hint config option disabled, no early hint requests are made
23 add_task(async function test_103_preload_disabled() {
24   Services.prefs.setBoolPref("network.early-hints.enabled", false);
25   await test_hint_preload(
26     "test_103_preload_disabled",
27     "https://example.com",
28     "https://example.com/browser/netwerk/test/browser/early_hint_pixel.sjs",
29     { hinted: 0, normal: 1 }
30   );
31   Services.prefs.setBoolPref("network.early-hints.enabled", true);
32 });
34 add_task(async function test_103_font_disabled() {
35   let url =
36     "https://example.com/browser/netwerk/test/browser/early_hint_asset_html.sjs?hinted=1&as=font";
37   Services.prefs.setBoolPref("gfx.downloadable_fonts.enabled", false);
38   await test_preload_url("font_loading_disabled", url, {
39     hinted: 0,
40     normal: 0,
41   });
42   Services.prefs.setBoolPref("gfx.downloadable_fonts.enabled", true);
43   await test_preload_url("font_loading_enabled", url, {
44     hinted: 1,
45     normal: 0,
46   });
47   Services.prefs.clearUserPref("gfx.downloadable_fonts.enabled");
48 });
50 // Preload with same origin in secure context with mochitest http proxy
51 add_task(async function test_103_preload_https() {
52   await test_hint_preload(
53     "test_103_preload_https",
54     "https://example.org",
55     "/browser/netwerk/test/browser/early_hint_pixel.sjs",
56     { hinted: 1, normal: 0 }
57   );
58 });
60 // Preload with same origin in secure context
61 add_task(async function test_103_preload() {
62   await test_hint_preload(
63     "test_103_preload",
64     "https://example.com",
65     "https://example.com/browser/netwerk/test/browser/early_hint_pixel.sjs",
66     { hinted: 1, normal: 0 }
67   );
68 });
70 // Cross origin preload in secure context
71 add_task(async function test_103_preload_cor() {
72   await test_hint_preload(
73     "test_103_preload_cor",
74     "https://example.com",
75     "https://example.net/browser/netwerk/test/browser/early_hint_pixel.sjs",
76     { hinted: 1, normal: 0 }
77   );
78 });
80 // Cross origin preload in insecure context
81 add_task(async function test_103_preload_insecure_cor() {
82   await test_hint_preload(
83     "test_103_preload_insecure_cor",
84     "https://example.com",
85     "http://mochi.test:8888/browser/netwerk/test/browser/early_hint_pixel.sjs",
86     { hinted: 0, normal: 1 }
87   );
88 });
90 // Same origin request with relative url
91 add_task(async function test_103_relative_preload() {
92   await test_hint_preload(
93     "test_103_relative_preload",
94     "https://example.com",
95     "/browser/netwerk/test/browser/early_hint_pixel.sjs",
96     { hinted: 1, normal: 0 }
97   );
98 });
100 // Early hint from insecure context
101 add_task(async function test_103_insecure_preload() {
102   await test_hint_preload(
103     "test_103_insecure_preload",
104     "http://mochi.test:8888",
105     "/browser/netwerk/test/browser/early_hint_pixel.sjs",
106     { hinted: 0, normal: 1 }
107   );
110 // Cross origin preload from secure context to insecure context on same domain
111 add_task(async function test_103_preload_mixed_content() {
112   await test_hint_preload(
113     "test_103_preload_mixed_content",
114     "https://example.org",
115     "http://example.org/browser/netwerk/test/browser/early_hint_pixel.sjs",
116     { hinted: 0, normal: 1 }
117   );
120 // Same preload from localhost to localhost should preload
121 add_task(async function test_103_preload_localhost_to_localhost() {
122   await test_hint_preload(
123     "test_103_preload_localhost_to_localhost",
124     "http://127.0.0.1:8888",
125     "http://127.0.0.1:8888/browser/netwerk/test/browser/early_hint_pixel.sjs",
126     { hinted: 1, normal: 0 }
127   );
130 // Relative url, correct file for requested uri
131 add_task(async function test_103_preload_only_file() {
132   await test_hint_preload(
133     "test_103_preload_only_file",
134     "https://example.com",
135     "early_hint_pixel.sjs",
136     { hinted: 1, normal: 0 }
137   );