|
|
|
|
| 17 |
// XXXtt: We should be able to move this check to chrome process after we move |
17 |
// XXXtt: We should be able to move this check to chrome process after we move |
| 18 |
// the interception logic to chrome process. |
18 |
// the interception logic to chrome process. |
| 19 |
async function checkObserverInContent(aInput) { |
19 |
async function checkObserverInContent(aInput) { |
| 20 |
let interceptedChannel = null; |
20 |
let interceptedChannel = null; |
| 21 |
|
21 |
|
| 22 |
// We always get two channels which receive the "http-on-stop-request" |
22 |
// We always get two channels which receive the "http-on-stop-request" |
| 23 |
// notification if the service worker hijacks the request and respondWith an |
23 |
// notification if the service worker hijacks the request and respondWith an |
| 24 |
// another fetch. One is for the "outer" window request when the other one is |
24 |
// another fetch. One is for the "outer" window request when the other one is |
| 25 |
// for the "inner" service worker request. We used to distinguish them by the |
25 |
// for the "inner" service worker request. Therefore, distinguish them by the |
| 26 |
// channel.URI.spec, but it doesn't work fine with internal redirect case. The |
26 |
// order. |
| 27 |
// reason is that the two different channels will have the same channel.URI |
27 |
let waitForSecondOnStopRequest = aInput.intercepted; |
| 28 |
// if it's an internal redirect. Therefore, distinguish them by the order. |
|
|
| 29 |
let waitForSecondOnStopRequest = aInput.redirect; |
| 30 |
|
28 |
|
| 31 |
let promiseResolve; |
29 |
let promiseResolve; |
| 32 |
|
30 |
|
| 33 |
function observer(aSubject) { |
31 |
function observer(aSubject) { |
| 34 |
let channel = aSubject.QueryInterface(Ci.nsIChannel); |
32 |
let channel = aSubject.QueryInterface(Ci.nsIChannel); |
| 35 |
// Since we cannot make sure that the network event triggered by the fetch() |
33 |
// Since we cannot make sure that the network event triggered by the fetch() |
| 36 |
// in this testcase is the very next event processed by ObserverService, we |
34 |
// in this testcase is the very next event processed by ObserverService, we |
| 37 |
// have to wait until we catch the one we want. |
35 |
// have to wait until we catch the one we want. |
| 38 |
if (!(aInput.redirect && channel.URI.spec.includes(aInput.redirect)) && |
36 |
if (!channel.URI.spec.includes(aInput.expectedURL)) { |
| 39 |
!(!aInput.redirect && channel.URI.spec.includes(aInput.url))) { |
|
|
| 40 |
return; |
37 |
return; |
| 41 |
} |
38 |
} |
| 42 |
|
39 |
|
| 43 |
if (waitForSecondOnStopRequest) { |
40 |
if (waitForSecondOnStopRequest) { |
| 44 |
waitForSecondOnStopRequest = false; |
41 |
waitForSecondOnStopRequest = false; |
| 45 |
return; |
42 |
return; |
| 46 |
} |
43 |
} |
| 47 |
|
44 |
|
|
|
| 192 |
info("Open the tab for observing"); |
189 |
info("Open the tab for observing"); |
| 193 |
let tab_observer = BrowserTestUtils.addTab(gBrowser, emptyDoc); |
190 |
let tab_observer = BrowserTestUtils.addTab(gBrowser, emptyDoc); |
| 194 |
let tabBrowser_observer = gBrowser.getBrowserForTab(tab_observer); |
191 |
let tabBrowser_observer = gBrowser.getBrowserForTab(tab_observer); |
| 195 |
await BrowserTestUtils.browserLoaded(tabBrowser_observer); |
192 |
await BrowserTestUtils.browserLoaded(tabBrowser_observer); |
| 196 |
|
193 |
|
| 197 |
let testcases = [ |
194 |
let testcases = [ |
| 198 |
{ |
195 |
{ |
| 199 |
url: helloDoc, |
196 |
url: helloDoc, |
|
|
197 |
expectedURL: helloDoc, |
| 200 |
swPresent: false, |
198 |
swPresent: false, |
| 201 |
intercepted: false, |
199 |
intercepted: false, |
| 202 |
fetch: true |
200 |
fetch: true |
| 203 |
}, |
201 |
}, |
| 204 |
{ |
202 |
{ |
| 205 |
url: fakeDoc, |
203 |
url: fakeDoc, |
|
|
204 |
expectedURL: helloDoc, |
| 206 |
swPresent: true, |
205 |
swPresent: true, |
| 207 |
intercepted: true, |
206 |
intercepted: true, |
| 208 |
fetch: false // should use HTTP cache |
207 |
fetch: false // should use HTTP cache |
| 209 |
}, |
208 |
}, |
| 210 |
{ // Bypass http cache |
209 |
{ // Bypass http cache |
| 211 |
url: helloDoc + "?ForBypassingHttpCache=" + Date.now(), |
210 |
url: helloDoc + "?ForBypassingHttpCache=" + Date.now(), |
|
|
211 |
expectedURL: helloDoc, |
| 212 |
swPresent: true, |
212 |
swPresent: true, |
| 213 |
intercepted: false, |
213 |
intercepted: false, |
| 214 |
fetch: true |
214 |
fetch: true |
| 215 |
}, |
215 |
}, |
| 216 |
{ // no-cors mode redirect to no-cors mode (trigger internal redirect) |
216 |
{ // no-cors mode redirect to no-cors mode (trigger internal redirect) |
| 217 |
url: crossRedirect + "?url=" + crossHelloDoc + "&mode=no-cors", |
217 |
url: crossRedirect + "?url=" + crossHelloDoc + "&mode=no-cors", |
|
|
218 |
expectedURL: crossHelloDoc, |
| 218 |
swPresent: true, |
219 |
swPresent: true, |
| 219 |
redirect: "hello.html", |
220 |
redirect: "hello.html", |
| 220 |
intercepted: true, |
221 |
intercepted: true, |
| 221 |
fetch: true |
222 |
fetch: true |
| 222 |
} |
223 |
} |
| 223 |
]; |
224 |
]; |
| 224 |
|
225 |
|
| 225 |
info("Test 1: Verify simple fetch"); |
226 |
info("Test 1: Verify simple fetch"); |