mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 02:25:34 +00:00
Bug 1236933 - Return null from FetchEvent.clientId for non-subresource network requests; r=bkelly
This commit is contained in:
parent
5188962c9a
commit
cddea9ec89
@ -3601,7 +3601,8 @@ ServiceWorkerManager::DispatchFetchEvent(const PrincipalOriginAttributes& aOrigi
|
||||
|
||||
internalChannel->GetLoadGroup(getter_AddRefs(loadGroup));
|
||||
|
||||
documentId = aDocumentIdForTopLevelNavigation;
|
||||
// TODO: Use aDocumentIdForTopLevelNavigation for potentialClientId, pending
|
||||
// the spec change.
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
aRv = aChannel->GetSecureUpgradedChannelURI(getter_AddRefs(uri));
|
||||
|
@ -1243,7 +1243,9 @@ private:
|
||||
init.mRequest.Value() = request;
|
||||
init.mBubbles = false;
|
||||
init.mCancelable = true;
|
||||
init.mClientId = mClientId;
|
||||
if (!mClientId.IsEmpty()) {
|
||||
init.mClientId = mClientId;
|
||||
}
|
||||
init.mIsReload = mIsReload;
|
||||
RefPtr<FetchEvent> event =
|
||||
FetchEvent::Constructor(globalObj, NS_LITERAL_STRING("fetch"), init, result);
|
||||
|
@ -7,9 +7,10 @@
|
||||
<script>
|
||||
var host_info = get_host_info();
|
||||
|
||||
var scope = 'resources/blank.html?clients-get';
|
||||
var scope = 'resources/clients-get-frame.html';
|
||||
var t = async_test('Test Clients.get()');
|
||||
var clientIds = [];
|
||||
var frame;
|
||||
t.step(function() {
|
||||
service_worker_unregister_and_register(
|
||||
t, 'resources/clients-get-worker.js', scope)
|
||||
@ -20,21 +21,38 @@ t.step(function() {
|
||||
return with_iframe(scope + '#1');
|
||||
})
|
||||
.then(function(frame1) {
|
||||
clientIds.push(frame1.contentDocument.body.textContent);
|
||||
frame1.focus();
|
||||
return wait_for_clientId();
|
||||
})
|
||||
.then(function(clientId) {
|
||||
clientIds.push(clientId);
|
||||
return with_iframe(scope + '#2');
|
||||
})
|
||||
.then(function(frame2) {
|
||||
clientIds.push(frame2.contentDocument.body.textContent);
|
||||
frame = frame2;
|
||||
return wait_for_clientId();
|
||||
})
|
||||
.then(function(clientId) {
|
||||
clientIds.push(clientId);
|
||||
var channel = new MessageChannel();
|
||||
channel.port1.onmessage = t.step_func(on_message);
|
||||
frame2.contentWindow.navigator.serviceWorker.controller.postMessage(
|
||||
frame.contentWindow.navigator.serviceWorker.controller.postMessage(
|
||||
{port:channel.port2, clientIds:clientIds,
|
||||
message: 'get_client_ids'}, [channel.port2]);
|
||||
})
|
||||
.catch(unreached_rejection(t));
|
||||
});
|
||||
|
||||
function wait_for_clientId() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
function get_client_id(e) {
|
||||
window.removeEventListener("message", get_client_id);
|
||||
resolve(e.data.clientId);
|
||||
}
|
||||
window.addEventListener("message", get_client_id, false);
|
||||
});
|
||||
}
|
||||
|
||||
var expected = [
|
||||
/* visibilityState, focused, url, frameType */
|
||||
['visible', true, new URL(scope + '#1', location).toString(), 'nested'],
|
||||
|
@ -71,7 +71,6 @@ async_test(function(t) {
|
||||
async_test(function(t) {
|
||||
var scope = 'resources/simple.html?clientId';
|
||||
var frame;
|
||||
var initial_client_id;
|
||||
service_worker_unregister_and_register(t, worker, scope)
|
||||
.then(function(reg) {
|
||||
return wait_for_state(t, reg.installing, 'activated');
|
||||
@ -80,10 +79,9 @@ async_test(function(t) {
|
||||
.then(function(f) {
|
||||
frame = f;
|
||||
assert_equals(
|
||||
frame.contentDocument.body.textContent.substr(0, 15),
|
||||
'Client ID Found',
|
||||
frame.contentDocument.body.textContent,
|
||||
'Client ID Not Found',
|
||||
'Service Worker should respond to fetch with a client id');
|
||||
initial_client_id = frame.contentDocument.body.textContent.substr(17);
|
||||
return frame.contentWindow.fetch('resources/other.html?clientId');
|
||||
})
|
||||
.then(function(response) { return response.text(); })
|
||||
@ -93,10 +91,6 @@ async_test(function(t) {
|
||||
response_text.substr(0, 15),
|
||||
'Client ID Found',
|
||||
'Service Worker should respond to fetch with an existing client id');
|
||||
assert_equals(
|
||||
initial_client_id,
|
||||
new_client_id,
|
||||
'Service Worker should observe the correct client ID for a controlled document');
|
||||
frame.remove();
|
||||
return service_worker_unregister_and_done(t, scope);
|
||||
})
|
||||
|
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<script>
|
||||
|
||||
fetch("clientId")
|
||||
.then(function(response) {
|
||||
return response.text();
|
||||
})
|
||||
.then(function(text) {
|
||||
parent.postMessage({clientId: text}, "*");
|
||||
});
|
||||
|
||||
</script>
|
@ -1,4 +1,12 @@
|
||||
self.onfetch = function(e) {
|
||||
if (e.request.url.indexOf("clients-get-frame.html") >= 0) {
|
||||
if (e.clientId === null) {
|
||||
e.respondWith(fetch(e.request));
|
||||
} else {
|
||||
e.respondWith(Response.error());
|
||||
}
|
||||
return;
|
||||
}
|
||||
e.respondWith(new Response(e.clientId));
|
||||
};
|
||||
|
||||
|
@ -13,7 +13,7 @@ function handleReferrer(event) {
|
||||
|
||||
function handleClientId(event) {
|
||||
var body;
|
||||
if (event.clientId !== '') {
|
||||
if (event.clientId !== null) {
|
||||
body = 'Client ID Found: ' + event.clientId;
|
||||
} else {
|
||||
body = 'Client ID Not Found';
|
||||
|
Loading…
Reference in New Issue
Block a user