Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / test / browser_refresh_content.js
blobbd1cf8084ad9f7305c0b10313d1f588959893559
1 /* Any copyright is dedicated to the Public Domain.
2  * http://creativecommons.org/publicdomain/zero/1.0/ */
4 /*
5  * Ensures resources can still be fetched without validation
6  */
8 const CONTENT_URL =
9   "http://www.example.com/browser/dom/base/test/file_browser_refresh_content.html";
11 async function run_test_browser_refresh(forceRevalidate) {
12   let tab = await BrowserTestUtils.openNewForegroundTab({
13     gBrowser,
14     url: CONTENT_URL,
15     waitForLoad: true,
16     /* Ensures each run is started with a fresh state */
17     forceNewProcess: true,
18   });
20   let originalAttributes = await SpecialPowers.spawn(
21     tab.linkedBrowser,
22     [],
23     async () => {
24       let result = content.document.getElementById("result");
25       await ContentTaskUtils.waitForCondition(() => {
26         return (
27           result.getAttribute("imageDataURL") &&
28           result.getAttribute("iframeContent") &&
29           result.getAttribute("expiredResourceCacheControl")
30         );
31       });
32       return {
33         imageDataURL: result.getAttribute("imageDataURL"),
34         iframeContent: result.getAttribute("iframeContent"),
35         expiredResourceCacheControl: result.getAttribute(
36           "expiredResourceCacheControl"
37         ),
38       };
39     }
40   );
42   let imageDataURL = originalAttributes.imageDataURL;
43   let expiredResourceCacheControl =
44     originalAttributes.expiredResourceCacheControl;
46   is(
47     originalAttributes.iframeContent,
48     "first load",
49     "Iframe is loaded with the initial content"
50   );
52   tab.linkedBrowser.reload();
54   await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
56   let attributes = await SpecialPowers.spawn(
57     tab.linkedBrowser,
58     [],
59     async () => {
60       let result = content.document.getElementById("result");
62       await ContentTaskUtils.waitForCondition(() => {
63         return (
64           result.getAttribute("imageDataURL") &&
65           result.getAttribute("expiredResourceCacheControl") &&
66           result.getAttribute("nonCacheableResourceCompleted")
67         );
68       });
70       return {
71         iframeContent: result.getAttribute("iframeContent"),
72         imageDataURL: result.getAttribute("imageDataURL"),
73         expiredResourceCacheControl: result.getAttribute(
74           "expiredResourceCacheControl"
75         ),
76         nonCacheableResourceCompleted: result.getAttribute(
77           "nonCacheableResourceCompleted"
78         ),
79       };
80     }
81   );
83   is(
84     attributes.iframeContent,
85     "second load",
86     "Iframe should always be revalidated"
87   );
89   if (!forceRevalidate) {
90     Assert.strictEqual(
91       attributes.imageDataURL,
92       imageDataURL,
93       "Image should use cache"
94     );
95   } else {
96     Assert.notStrictEqual(
97       attributes.imageDataURL,
98       imageDataURL,
99       "Image should be revalidated"
100     );
101   }
103   if (!forceRevalidate) {
104     Assert.strictEqual(
105       attributes.expiredResourceCacheControl,
106       expiredResourceCacheControl,
107       "max-age shouldn't be changed after reload because it didn't revalidate"
108     );
109   } else {
110     Assert.notStrictEqual(
111       attributes.expiredResourceCacheControl,
112       expiredResourceCacheControl,
113       "max-age should be changed after reload because it got revalidated"
114     );
115   }
117   is(
118     attributes.nonCacheableResourceCompleted,
119     "true",
120     "Non cacheable resource should still be loaded"
121   );
123   await BrowserTestUtils.removeTab(tab);
126 add_task(async function test_browser_refresh() {
127   Services.prefs.setBoolPref(
128     "browser.soft_reload.only_force_validate_top_level_document",
129     true
130   );
131   await run_test_browser_refresh(false);
132   Services.prefs.setBoolPref(
133     "browser.soft_reload.only_force_validate_top_level_document",
134     false
135   );
136   await run_test_browser_refresh(true);