Skip to content

Commit

Permalink
service worker WPT tests: split very big registration tests into mult…
Browse files Browse the repository at this point in the history
…iple files

registration.https.html and link-element-register.https.html do about 70
register calls, most of which result in a service worker starting up. These
test files always came close to the test harness timeout, and with the new
snapshotting change r496290 which does a lot of work in Debug, started timing
out on Debug. The snapshotting change is supposed to be fixed soon, but split
them up into smaller files anyway.

I verified that no tests were lost by generating the new files then
`cat registration-*expected* | sort | uniq` and comparing to
the existing test output (and similar for link-element-register*).

Bug: 758481
Change-Id: I7e522e3c4e87df11fcb5197da59005e2d9e25f92
Reviewed-on: https://chromium-review.googlesource.com/635065
Commit-Queue: Matt Falkenhagen <[email protected]>
Reviewed-by: Hiroki Nakagawa <[email protected]>
Cr-Commit-Position: refs/heads/master@{#497717}
  • Loading branch information
mfalken authored and foolip committed Aug 31, 2017
1 parent 8c6e6f2 commit 4e7404d
Show file tree
Hide file tree
Showing 21 changed files with 612 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<title>Service Worker: Register via link element (basic)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script src="resources/registration-tests-basic.js"></script>
<body>
<script>
registration_tests_basic(register_using_link, false);
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<title>Service Worker: Register via link element (MIME types)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script src="resources/registration-tests-mime-types.js"></script>
<body>
<script>
registration_tests_mime_types(register_using_link, false);
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<title>Service Worker: Register via link element (scope)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script src="resources/registration-tests-scope.js"></script>
<body>
<script>
registration_tests_scope(register_using_link, false);
</script>
</body>

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<title>Service Worker: Register via link element (scriptURL)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script src="resources/registration-tests-script-url.js"></script>
<body>
<script>
registration_tests_script_url(register_using_link, false);
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<title>Service Worker: Register via link element (script)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script src="resources/registration-tests-script.js"></script>
<body>
<script>
registration_tests_script(register_using_link, false);
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<title>Service Worker: Register via link element (SecurityError)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script src="resources/registration-tests-security-error.js"></script>
<body>
<script>
registration_tests_security_error(register_using_link, false);
</script>
</body>
25 changes: 0 additions & 25 deletions service-workers/service-worker/register-link-element.https.html

This file was deleted.

9 changes: 9 additions & 0 deletions service-workers/service-worker/registration-basic.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<title>Service Worker: Registration (basic)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script src="resources/registration-tests-basic.js"></script>
<script>
registration_tests_basic((script, options) => navigator.serviceWorker.register(script, options), true);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<title>Service Worker: Registration (MIME types)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script src="resources/registration-tests-mime-types.js"></script>
<script>
registration_tests_mime_types((script, options) => navigator.serviceWorker.register(script, options), true);
</script>
9 changes: 9 additions & 0 deletions service-workers/service-worker/registration-scope.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<title>Service Worker: Registration (scope)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script src="resources/registration-tests-scope.js"></script>
<script>
registration_tests_scope((script, options) => navigator.serviceWorker.register(script, options), true);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<title>Service Worker: Registration (scriptURL)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script src="resources/registration-tests-script-url.js"></script>
<script>
registration_tests_script_url((script, options) => navigator.serviceWorker.register(script, options), true);
</script>
9 changes: 9 additions & 0 deletions service-workers/service-worker/registration-script.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<title>Service Worker: Registration (script)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script src="resources/registration-tests-script.js"></script>
<script>
registration_tests_script((script, options) => navigator.serviceWorker.register(script, options), true);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<title>Service Worker: Registration (SecurityError)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script src="resources/registration-tests-security-error.js"></script>
<script>
registration_tests_security_error((script, options) => navigator.serviceWorker.register(script, options), true);
</script>
9 changes: 0 additions & 9 deletions service-workers/service-worker/registration.https.html

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Basic registration tests that succeed. We don't want too many successful
// registration tests in the same file since starting a service worker can be
// slow.
function registration_tests_basic(register_method, check_error_types) {
promise_test(function(t) {
var script = 'resources/registration-worker.js';
var scope = 'resources/registration/normal';
return register_method(script, {scope: scope})
.then(function(registration) {
assert_true(
registration instanceof ServiceWorkerRegistration,
'Successfully registered.');
return registration.unregister();
});
}, 'Registering normal scope');

promise_test(function(t) {
var script = 'resources/registration-worker.js';
var scope = 'resources/registration/scope-with-fragment#ref';
return register_method(script, {scope: scope})
.then(function(registration) {
assert_true(
registration instanceof ServiceWorkerRegistration,
'Successfully registered.');
assert_equals(
registration.scope,
normalizeURL('resources/registration/scope-with-fragment'),
'A fragment should be removed from scope')
return registration.unregister();
});
}, 'Registering scope with fragment');

promise_test(function(t) {
var script = 'resources/registration-worker.js';
var scope = 'resources/';
return register_method(script, {scope: scope})
.then(function(registration) {
assert_true(
registration instanceof ServiceWorkerRegistration,
'Successfully registered.');
return registration.unregister();
});
}, 'Registering same scope as the script directory');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Registration tests that mostly verify the MIME type.
//
// This file tests every MIME type so it necessarily starts many service
// workers, so it may be slow.
function registration_tests_mime_types(register_method, check_error_types) {
promise_test(function(t) {
var script = 'resources/mime-type-worker.py';
var scope = 'resources/scope/no-mime-type-worker/';
return promise_rejects(t,
check_error_types ? 'SecurityError' : null,
register_method(script, {scope: scope}),
'Registration of no MIME type script should fail.');
}, 'Registering script with no MIME type');

promise_test(function(t) {
var script = 'resources/mime-type-worker.py?mime=text/plain';
var scope = 'resources/scope/bad-mime-type-worker/';
return promise_rejects(t,
check_error_types ? 'SecurityError' : null,
register_method(script, {scope: scope}),
'Registration of plain text script should fail.');
}, 'Registering script with bad MIME type');

promise_test(function(t) {
var script = 'resources/import-mime-type-worker.py';
var scope = 'resources/scope/no-mime-type-worker/';
return promise_rejects(t,
check_error_types ? 'SecurityError' : null,
register_method(script, {scope: scope}),
'Registration of no MIME type imported script should fail.');
}, 'Registering script that imports script with no MIME type');

promise_test(function(t) {
var script = 'resources/import-mime-type-worker.py?mime=text/plain';
var scope = 'resources/scope/bad-mime-type-worker/';
return promise_rejects(t,
check_error_types ? 'SecurityError' : null,
register_method(script, {scope: scope}),
'Registration of plain text imported script should fail.');
}, 'Registering script that imports script with bad MIME type');

const validMimeTypes = [
'application/ecmascript',
'application/javascript',
'application/x-ecmascript',
'application/x-javascript',
'text/ecmascript',
'text/javascript',
'text/javascript1.0',
'text/javascript1.1',
'text/javascript1.2',
'text/javascript1.3',
'text/javascript1.4',
'text/javascript1.5',
'text/jscript',
'text/livescript',
'text/x-ecmascript',
'text/x-javascript'
];

for (const validMimeType of validMimeTypes) {
promise_test(() => {
var script = `resources/mime-type-worker.py?mime=${validMimeType}`;
var scope = 'resources/scope/good-mime-type-worker/';

return register_method(script, {scope}).then(registration => {
assert_true(
registration instanceof ServiceWorkerRegistration,
'Successfully registered.');
return registration.unregister();
});
}, `Registering script with good MIME type ${validMimeType}`);

promise_test(() => {
var script = `resources/import-mime-type-worker.py?mime=${validMimeType}`;
var scope = 'resources/scope/good-mime-type-worker/';

return register_method(script, { scope }).then(registration => {
assert_true(
registration instanceof ServiceWorkerRegistration,
'Successfully registered.');
return registration.unregister();
});
}, `Registering script that imports script with good MIME type ${validMimeType}`);
}
}
Loading

0 comments on commit 4e7404d

Please sign in to comment.