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
Reviewed-by: Hiroki Nakagawa <[email protected]>
WPT-Export-Revision: 29d6f88462bf06062f93e5bcaecd36c3861496c7
  • Loading branch information
mfalken authored and chromium-wpt-export-bot committed Aug 28, 2017
1 parent e511e5e commit e8e2734
Show file tree
Hide file tree
Showing 21 changed files with 607 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<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,10 @@
<!DOCTYPE html>
<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,11 @@
<!DOCTYPE html>
<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,10 @@
<!DOCTYPE html>
<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,10 @@
<!DOCTYPE html>
<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 @@
<title>Page Title</title>
<!DOCTYPE html>
<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 (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-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}`);
}
}
102 changes: 102 additions & 0 deletions service-workers/service-worker/resources/registration-tests-scope.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Registration tests that mostly exercise the scope option.
function registration_tests_scope(register_method, check_error_types) {
promise_test(function(t) {
var script = 'resources/empty-worker.js';
var scope = 'resources/scope%2fencoded-slash-in-scope';
return promise_rejects(t,
check_error_types ? new TypeError : null,
register_method(script, {scope: scope}),
'URL-encoded slash in the scope should be rejected.');
}, 'Scope including URL-encoded slash');

promise_test(function(t) {
var script = 'resources/empty-worker.js';
var scope = 'resources/scope%5cencoded-slash-in-scope';
return promise_rejects(t,
check_error_types ? new TypeError : null,
register_method(script, {scope: scope}),
'URL-encoded backslash in the scope should be rejected.');
}, 'Scope including URL-encoded backslash');

promise_test(function(t) {
// URL-encoded full-width 'scope'.
var name = '%ef%bd%93%ef%bd%83%ef%bd%8f%ef%bd%90%ef%bd%85';
var script = 'resources/empty-worker.js';
var scope = 'resources/' + name + '/escaped-multibyte-character-scope';
return register_method(script, {scope: scope})
.then(function(registration) {
assert_equals(
registration.scope,
normalizeURL(scope),
'URL-encoded multibyte characters should be available.');
return registration.unregister();
});
}, 'Scope including URL-encoded multibyte characters');

promise_test(function(t) {
// Non-URL-encoded full-width "scope".
var name = String.fromCodePoint(0xff53, 0xff43, 0xff4f, 0xff50, 0xff45);
var script = 'resources/empty-worker.js';
var scope = 'resources/' + name + '/non-escaped-multibyte-character-scope';
return register_method(script, {scope: scope})
.then(function(registration) {
assert_equals(
registration.scope,
normalizeURL(scope),
'Non-URL-encoded multibyte characters should be available.');
return registration.unregister();
});
}, 'Scope including non-escaped multibyte characters');

promise_test(function(t) {
var script = 'resources/empty-worker.js';
var scope = 'resources/././scope/self-reference-in-scope';
return register_method(script, {scope: scope})
.then(function(registration) {
assert_equals(
registration.scope,
normalizeURL('resources/scope/self-reference-in-scope'),
'Scope including self-reference should be normalized.');
return registration.unregister();
});
}, 'Scope including self-reference');

promise_test(function(t) {
var script = 'resources/empty-worker.js';
var scope = 'resources/../resources/scope/parent-reference-in-scope';
return register_method(script, {scope: scope})
.then(function(registration) {
assert_equals(
registration.scope,
normalizeURL('resources/scope/parent-reference-in-scope'),
'Scope including parent-reference should be normalized.');
return registration.unregister();
});
}, 'Scope including parent-reference');

promise_test(function(t) {
var script = 'resources/empty-worker.js';
var scope = 'resources/scope////consecutive-slashes-in-scope';
return register_method(script, {scope: scope})
.then(function(registration) {
// Although consecutive slashes in the scope are not unified, the
// scope is under the script directory and registration should
// succeed.
assert_equals(
registration.scope,
normalizeURL(scope),
'Should successfully be registered.');
return registration.unregister();
})
}, 'Scope including consecutive slashes');

promise_test(function(t) {
var script = 'resources/empty-worker.js';
var scope = 'filesystem:' + normalizeURL('resources/scope/filesystem-scope-url');
return promise_rejects(t,
check_error_types ? 'SecurityError' : null,
register_method(script, {scope: scope}),
'Registering with the scope that has same-origin filesystem: URL ' +
'should fail with SecurityError.');
}, 'Scope URL is same-origin filesystem: URL');
}
Loading

0 comments on commit e8e2734

Please sign in to comment.