Skip to content

Commit

Permalink
Bug 1122161 - Redirected channels should respect skip service worker …
Browse files Browse the repository at this point in the history
…flag. r=nsm

--HG--
extra : rebase_source : 959228846310fa8b44a74e8378f24c14a4f278c0
  • Loading branch information
jaoo committed Jun 3, 2015
1 parent fc69cd9 commit 49e0208
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dom/tests/mochitest/fetch/mochitest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ skip-if = buildapp == 'b2g' # Bug 1137683
skip-if = buildapp == 'b2g' # Bug 1137683
[test_fetch_basic_http.html]
[test_fetch_basic_http_sw_reroute.html]
skip-if = true # Bug 1122161, need proper support for redirects
skip-if = true # Bug 1170937, need fully support for redirects
#skip-if = buildapp == 'b2g' # Bug 1137683
[test_fetch_cors.html]
[test_fetch_cors_sw_reroute.html]
skip-if = true # Bug 1122161, need proper support for redirects
skip-if = true # Bug 1170937, need fully support for redirects
#skip-if = buildapp == 'b2g' # Bug 1137683
[test_formdataparsing.html]
[test_formdataparsing_sw_reroute.html]
Expand Down
19 changes: 19 additions & 0 deletions dom/workers/test/serviceworkers/fetch/fetch_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ fetchXHR('http://example.com/tests/dom/base/test/file_CrossSiteXHR_server.sjs?st
finish();
});

// Test that when the page fetches a url the controlling SW forces a redirect to
// another location. This other location fetch should also be intercepted by
// the SW.
fetchXHR('something.txt', function(xhr) {
my_ok(xhr.status == 200, "load should be successful");
my_ok(xhr.responseText == "something else response body", "load should have something else");
finish();
});

// Test fetch will internally get it's SkipServiceWorker flag set. The request is
// made from the SW through fetch(). fetch() fetches a server-side JavaScript
// file that force a redirect. The redirect location fetch does not go through
// the SW.
fetchXHR('redirect_serviceworker.sjs', function(xhr) {
my_ok(xhr.status == 200, "load should be successful");
my_ok(xhr.responseText == "// empty worker, always succeed!\n", "load should have redirection content");
finish();
});

expectAsyncResult();
fetch('http://example.com/tests/dom/base/test/file_CrossSiteXHR_server.sjs?status=200&allowOrigin=*')
.then(function(res) {
Expand Down
18 changes: 17 additions & 1 deletion dom/workers/test/serviceworkers/fetch_event_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,20 @@ onfetch = function(ev) {
return new Response(body + body);
}));
}
}

else if (ev.request.url.includes('something.txt')) {
ev.respondWith(Response.redirect('fetch/somethingelse.txt'));
}

else if (ev.request.url.includes('somethingelse.txt')) {
ev.respondWith(new Response('something else response body', {}));
}

else if (ev.request.url.includes('redirect_serviceworker.sjs')) {
// The redirect_serviceworker.sjs server-side JavaScript file redirects to
// 'http://mochi.test:8888/tests/dom/workers/test/serviceworkers/worker.js'
// The redirected fetch should not go through the SW since the original
// fetch was initiated from a SW.
ev.respondWith(fetch('redirect_serviceworker.sjs'));
}
};

0 comments on commit 49e0208

Please sign in to comment.