Skip to content

Commit

Permalink
service workers: Simplified tests with async/await - Part 1
Browse files Browse the repository at this point in the history
- Fix a couple of tests with function t.add_cleanup() as it supports promise, see detail in #8748.
- The usage of unregister() method in some tests is not rigorous.  As [spec]\(https://w3c.github.io/ServiceWorker/#dom-serviceworkerregistration-unregister):
>>   [NewObject] Promise<boolean> unregister();
  unregister() method must run these steps:
>> 1. Let promise be a promise.
...
>> 4. Return promise.
  • Loading branch information
wanghongjuan committed Sep 21, 2018
1 parent e1c38af commit 43fabbf
Show file tree
Hide file tree
Showing 11 changed files with 534 additions and 659 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,48 @@
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/test-helpers.sub.js"></script>
<script>
promise_test(t => {
var script = 'resources/broken-chunked-encoding-worker.js';
var scope = 'resources/broken-chunked-encoding-scope.asis';
return service_worker_unregister_and_register(t, script, scope)
.then(registration => {
add_completion_callback(_ => registration.unregister());
var worker = registration.installing;
return wait_for_state(t, worker, 'activated');
})
.then(_ => with_iframe(scope))
.then(frame => {
assert_equals(
frame.contentDocument.body.textContent,
'PASS: preloadResponse resolved');
});
}, 'FetchEvent#preloadResponse resolves even if the body is sent with broken chunked encoding.');

promise_test(t => {
var script = 'resources/broken-chunked-encoding-worker.js';
var scope = 'resources/chunked-encoding-scope.py?use_broken_body';
return service_worker_unregister_and_register(t, script, scope)
.then(registration => {
add_completion_callback(_ => registration.unregister());
var worker = registration.installing;
return wait_for_state(t, worker, 'activated');
})
.then(_ => with_iframe(scope))
.then(frame => {
assert_equals(
frame.contentDocument.body.textContent,
'PASS: preloadResponse resolved');
});
}, 'FetchEvent#preloadResponse resolves even if the body is sent with broken chunked encoding with some delays');
promise_test(async t => {
const SCRIPT = 'resources/broken-chunked-encoding-worker.js';
const SCOPE = 'resources/broken-chunked-encoding-scope.asis';

const registration =
await service_worker_unregister_and_register(t, SCRIPT, SCOPE);
const worker = registration.installing;
await wait_for_state(t, worker, 'activated');
const frame = await with_iframe(SCOPE);

add_completion_callback(async() => {
if (registration)
await registration.unregister();
if (frame)
frame.remove();
});

assert_equals(frame.contentDocument.body.textContent,
'PASS: preloadResponse resolved');
}, 'FetchEvent#preloadResponse resolves even if the body is sent with ' +
'broken chunked encoding.');

promise_test(async t => {
const SCRIPT = 'resources/broken-chunked-encoding-worker.js';
const SCOPE = 'resources/chunked-encoding-scope.py?use_broken_body';

const registration =
await service_worker_unregister_and_register(t, SCRIPT, SCOPE);
const worker = registration.installing;
await wait_for_state(t, worker, 'activated');
const frame = await with_iframe(SCOPE);

add_completion_callback(async() => {
if (registration)
await registration.unregister();
if (frame)
frame.remove();
});

assert_equals(frame.contentDocument.body.textContent,
'PASS: preloadResponse resolved');
}, 'FetchEvent#preloadResponse resolves even if the body is sent with ' +
'broken chunked encoding with some delays');

</script>
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/test-helpers.sub.js"></script>
<script>
promise_test(t => {
var script = 'resources/chunked-encoding-worker.js';
var scope = 'resources/chunked-encoding-scope.py';
return service_worker_unregister_and_register(t, script, scope)
.then(registration => {
add_completion_callback(_ => registration.unregister());
var worker = registration.installing;
return wait_for_state(t, worker, 'activated');
})
.then(_ => with_iframe(scope))
.then(frame => {
assert_equals(
frame.contentDocument.body.textContent,
'0123456789');
});
}, 'Navigation Preload must work with chunked encoding.');
promise_test(async t => {
const SCRIPT = 'resources/chunked-encoding-worker.js';
const SCOPE = 'resources/chunked-encoding-scope.py';

const registration =
await service_worker_unregister_and_register(t, SCRIPT, SCOPE);
const worker = registration.installing;
await wait_for_state(t, worker, 'activated');
const frame = await with_iframe(SCOPE);

add_completion_callback(async() => {
if (registration)
await registration.unregister();
if (frame)
frame.remove();
})

assert_equals(frame.contentDocument.body.textContent, '0123456789');
}, 'Navigation Preload must work with chunked encoding.');

</script>
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/test-helpers.sub.js"></script>
<script>
promise_test(t => {
var script = 'resources/empty-preload-response-body-worker.js';
var scope = 'resources/empty-preload-response-body-scope.html';
return service_worker_unregister_and_register(t, script, scope)
.then(registration => {
add_completion_callback(_ => registration.unregister());
var worker = registration.installing;
return wait_for_state(t, worker, 'activated');
})
.then(_ => with_iframe(scope))
.then(frame => {
assert_equals(
frame.contentDocument.body.textContent,
'[]');
});
}, 'Navigation Preload empty response body.');
promise_test(async t => {
const SCRIPT = 'resources/empty-preload-response-body-worker.js';
const SCOPE = 'resources/empty-preload-response-body-scope.html';
const registration =
await service_worker_unregister_and_register(t, SCRIPT, SCOPE);
const worker = registration.installing;
await wait_for_state(t, worker, 'activated');
const frame = await with_iframe(SCOPE);

add_completion_callback(async() => {
if (registration)
await registration.unregister();
if (frame)
frame.remove();
})

assert_equals(frame.contentDocument.body.textContent, '[]');
}, 'Navigation Preload empty response body.');

</script>
Loading

0 comments on commit 43fabbf

Please sign in to comment.