Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/request-end-to-end.https.html

Issue 2889153004: Upstream service worker "request" tests to WPT (Closed)
Patch Set: Add "use strict" directive Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/request-end-to-end.https.html
diff --git a/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/request-end-to-end.https.html b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/request-end-to-end.https.html
index d061a6d1c476f4a5b8db60d8e9259968e89d09a1..7b594aac57d439f0f5b4918869bf1625436525bf 100644
--- a/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/request-end-to-end.https.html
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/request-end-to-end.https.html
@@ -1,75 +1,40 @@
<!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.sub.js"></script>
<script>
-var t = async_test('Request: end-to-end');
-t.step(function() {
- var url = 'resources/request-end-to-end-worker.js';
- var scope = 'resources/blank.html?request-end-to-end';
-
- 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;
- sw.addEventListener('statechange', t.step_func(function(event) {
- if (event.target.state == 'activated') {
- onActive(sw);
- }
- }));
- }
+'use strict';
- function onActive(sw) {
- var port = sendMessagePort(sw);
- port.addEventListener('message', t.step_func(function(event) {
- onMessage(event);
- }), false);
- port.start();
- }
-
- function onMessage(event) {
- if (event.data === 'received port') {
- onPortReady();
- } else {
- onResult(event);
- }
- }
-
- function onPortReady() {
- // The only purpose of the iframe created here is to generate an HTTP
- // request, so the element may be removed as soon as the frame has
- // completed loading.
- with_iframe(scope).then(function(f) { f.remove(); })
- .catch(unreached_rejection(t));
- }
+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(); });
- function onResult(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.mode, 'navigate',
- 'request.mode 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'], undefined,
- 'Default User-Agent header should not 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.mode, 'navigate', 'request.mode');
+ assert_equals(result.request_construct_error, 'TypeError',
+ 'Constructing a Request with a Request whose mode ' +
+ 'is navigate and non-empty RequestInit must throw a ' +
+ 'TypeError.')
+ assert_equals(result.credentials, 'include', 'request.credentials');
+ assert_equals(result.redirect, 'manual', 'request.redirect');
+ assert_equals(result.headers['user-agent'], undefined,
+ 'Default User-Agent header should not be passed to ' +
+ 'onfetch event.')
+ 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>

Powered by Google App Engine
This is Rietveld 408576698