Index: LayoutTests/http/tests/serviceworker/request-end-to-end.html |
diff --git a/LayoutTests/http/tests/serviceworker/request-end-to-end.html b/LayoutTests/http/tests/serviceworker/request-end-to-end.html |
index 3502ab24f475f308dbefc6524f5aaae562ede266..4ac9fed777ff1ceafc04cb653400cd7e9cb323e7 100644 |
--- a/LayoutTests/http/tests/serviceworker/request-end-to-end.html |
+++ b/LayoutTests/http/tests/serviceworker/request-end-to-end.html |
@@ -1,57 +1,30 @@ |
<!DOCTYPE html> |
-<title>Service Worker: Request end-to-end</title> |
+<title>Service Worker: FetchEvent.request passed to onfetch</title> |
<script src="../resources/testharness.js"></script> |
<script src="../resources/testharnessreport.js"></script> |
<script src="resources/test-helpers.js"></script> |
<script> |
-var t = async_test('Request: end-to-end'); |
-t.step(function() { |
+promise_test(t => { |
var url = 'resources/request-end-to-end-worker.js'; |
var scope = 'resources/blank.html'; |
+ return service_worker_unregister_and_register(t, url, scope) |
+ .then(r => { |
+ add_completion_callback(() => { r.unregister(); }); |
+ return wait_for_state(t, r.installing, 'activated'); |
+ }) |
+ .then(() => { return with_iframe(scope); }) |
+ .then(frame => { |
+ add_completion_callback(() => { frame.remove(); }); |
- service_worker_unregister_and_register(t, url, scope) |
- .then(onRegister) |
- .catch(unreached_rejection(t)); |
- |
- function sendMessagePort(worker) { |
- var messageChannel = new MessageChannel(); |
- worker.postMessage({port:messageChannel.port2}, [messageChannel.port2]); |
- return messageChannel.port1; |
- } |
- |
- function onRegister(registration) { |
- var sw = registration.installing; |
- var port = sendMessagePort(sw); |
- port.addEventListener('message', t.step_func(function(event) { |
- onMessage(event); |
- }), false); |
- port.start(); |
- sw.addEventListener('statechange', t.step_func(function(event) { |
- if (event.target.state == 'activated') |
- onActive(); |
- })); |
- } |
- |
- function onActive() { |
- with_iframe(scope); |
- } |
- |
- function onMessage(event) { |
- assert_equals( |
- event.data.url, |
- location.href.substring(0, location.href.lastIndexOf('/') + 1) + |
- scope, |
- 'request.url should be passed to onfetch event.'); |
- assert_equals(event.data.method, 'GET', |
- 'request.method should be passed to onfetch event.'); |
- assert_equals(event.data.referrer, location.href, |
- 'request.referrer should be passed to onfetch event.'); |
- assert_equals(event.data.headers['user-agent'], navigator.userAgent, |
- 'User-Agent header should be passed to onfetch event.') |
- assert_equals(event.data.errorNameWhileAppendingHeader, 'TypeError', |
- 'Appending a new header to the request must throw a ' + |
- 'TypeError.') |
- service_worker_unregister_and_done(t, scope); |
- } |
-}); |
+ var result = JSON.parse(frame.contentDocument.body.textContent); |
+ assert_equals(result.url, frame.src, 'request.url'); |
+ assert_equals(result.method, 'GET', 'request.method'); |
+ assert_equals(result.referrer, location.href, 'request.referrer'); |
+ assert_equals(result.headers['user-agent'], navigator.userAgent, |
+ 'User-Agent header'); |
+ assert_equals(result.append_header_error, 'TypeError', |
+ 'Appending a new header to the request must throw a ' + |
+ 'TypeError.') |
+ }); |
+ }, 'Test FetchEvent.request passed to onfetch'); |
</script> |