|
|
|
|
| 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. We used to distinguish them by the |
| 26 |
// channel.URI.spec, but it doesn't work fine with internal redirect case. The |
26 |
// channel.URI.spec, but it doesn't work fine with internal redirect case. The |
| 27 |
// reason is that the two different channels will have the same channel.URI |
27 |
// reason is that the two different channels will have the same channel.URI |
| 28 |
// if it's an internal redirect. Therefore, distinguish them by the order. |
28 |
// if it's an internal redirect. Therefore, distinguish them by the order. |
| 29 |
let waitForSecondOnStopRequest = aInput.redirect; |
29 |
let waitForSecondOnStopRequest = aInput.intercepted; |
| 30 |
|
30 |
|
| 31 |
let promiseResolve; |
31 |
let promiseResolve; |
| 32 |
|
32 |
|
| 33 |
function observer(aSubject) { |
33 |
function observer(aSubject) { |
| 34 |
let channel = aSubject.QueryInterface(Ci.nsIChannel); |
34 |
let channel = aSubject.QueryInterface(Ci.nsIChannel); |
| 35 |
// Since we cannot make sure that the network event triggered by the fetch() |
35 |
// 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 |
36 |
// in this testcase is the very next event processed by ObserverService, we |
| 37 |
// have to wait until we catch the one we want. |
37 |
// have to wait until we catch the one we want. |
| 38 |
if (!(aInput.redirect && channel.URI.spec.includes(aInput.redirect)) && |
38 |
if (!channel.URI.spec.includes(aInput.responseURL)) { |
| 39 |
!(!aInput.redirect && channel.URI.spec.includes(aInput.url))) { |
|
|
| 40 |
return; |
39 |
return; |
| 41 |
} |
40 |
} |
| 42 |
|
41 |
|
| 43 |
if (waitForSecondOnStopRequest) { |
42 |
if (waitForSecondOnStopRequest) { |
| 44 |
waitForSecondOnStopRequest = false; |
43 |
waitForSecondOnStopRequest = false; |
| 45 |
return; |
44 |
return; |
| 46 |
} |
45 |
} |
| 47 |
|
46 |
|
|
|
| 192 |
info("Open the tab for observing"); |
191 |
info("Open the tab for observing"); |
| 193 |
let tab_observer = BrowserTestUtils.addTab(gBrowser, emptyDoc); |
192 |
let tab_observer = BrowserTestUtils.addTab(gBrowser, emptyDoc); |
| 194 |
let tabBrowser_observer = gBrowser.getBrowserForTab(tab_observer); |
193 |
let tabBrowser_observer = gBrowser.getBrowserForTab(tab_observer); |
| 195 |
await BrowserTestUtils.browserLoaded(tabBrowser_observer); |
194 |
await BrowserTestUtils.browserLoaded(tabBrowser_observer); |
| 196 |
|
195 |
|
| 197 |
let testcases = [ |
196 |
let testcases = [ |
| 198 |
{ |
197 |
{ |
| 199 |
url: helloDoc, |
198 |
url: helloDoc, |
|
|
199 |
responseURL: helloDoc, |
| 200 |
swPresent: false, |
200 |
swPresent: false, |
| 201 |
intercepted: false, |
201 |
intercepted: false, |
| 202 |
fetch: true |
202 |
fetch: true |
| 203 |
}, |
203 |
}, |
| 204 |
{ |
204 |
{ |
| 205 |
url: fakeDoc, |
205 |
url: fakeDoc, |
|
|
206 |
responseURL: helloDoc, |
| 206 |
swPresent: true, |
207 |
swPresent: true, |
| 207 |
intercepted: true, |
208 |
intercepted: true, |
| 208 |
fetch: false // should use HTTP cache |
209 |
fetch: false // should use HTTP cache |
| 209 |
}, |
210 |
}, |
| 210 |
{ // Bypass http cache |
211 |
{ // Bypass http cache |
| 211 |
url: helloDoc + "?ForBypassingHttpCache=" + Date.now(), |
212 |
url: helloDoc + "?ForBypassingHttpCache=" + Date.now(), |
|
|
213 |
responseURL: helloDoc, |
| 212 |
swPresent: true, |
214 |
swPresent: true, |
| 213 |
intercepted: false, |
215 |
intercepted: false, |
| 214 |
fetch: true |
216 |
fetch: true |
| 215 |
}, |
217 |
}, |
| 216 |
{ // no-cors mode redirect to no-cors mode (trigger internal redirect) |
218 |
{ // no-cors mode redirect to no-cors mode (trigger internal redirect) |
| 217 |
url: crossRedirect + "?url=" + crossHelloDoc + "&mode=no-cors", |
219 |
url: crossRedirect + "?url=" + crossHelloDoc + "&mode=no-cors", |
|
|
220 |
responseURL: crossHelloDoc, |
| 218 |
swPresent: true, |
221 |
swPresent: true, |
| 219 |
redirect: "hello.html", |
222 |
redirect: "hello.html", |
| 220 |
intercepted: true, |
223 |
intercepted: true, |
| 221 |
fetch: true |
224 |
fetch: true |
| 222 |
} |
225 |
} |
| 223 |
]; |
226 |
]; |
| 224 |
|
227 |
|
| 225 |
info("Test 1: Verify simple fetch"); |
228 |
info("Test 1: Verify simple fetch"); |