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

Unified Diff: LayoutTests/http/tests/serviceworker/getregistration.html

Issue 540823003: ServiceWorker: Implement navigator.serviceWorker.getRegistration [3/3] (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | Source/modules/serviceworkers/ServiceWorkerContainer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/http/tests/serviceworker/getregistration.html
diff --git a/LayoutTests/http/tests/serviceworker/getregistration.html b/LayoutTests/http/tests/serviceworker/getregistration.html
new file mode 100644
index 0000000000000000000000000000000000000000..64a26ffc93a0b103f044420aa613d6689e9f9790
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/getregistration.html
@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.js"></script>
+<script>
+async_test(function(t) {
+ var documentURL = 'no-such-worker';
+ navigator.serviceWorker.getRegistration(documentURL)
+ .then(function(value) {
+ assert_equals(value, undefined,
+ 'getRegistration should resolve with undefined');
+ t.done();
+ })
+ .catch(unreached_rejection(t));
+ }, 'getRegistration');
+
+async_test(function(t) {
+ var scope = 'scope/worker/';
+ var registration;
+ navigator.serviceWorker.register('resources/empty-worker.js',
nhiroki 2014/09/11 11:30:34 Can you use service_worker_unregister_and_register
Kunihiko Sakamoto 2014/09/12 01:32:13 Done.
+ {scope: scope})
+ .then(function(r) {
+ registration = r;
+ return navigator.serviceWorker.getRegistration(scope);
+ })
+ .then(function(value) {
+ assert_equals(value, registration,
+ 'getRegistration should resolve with registration');
+ t.done();
nhiroki 2014/09/11 11:30:34 To unregister the registration before finishing th
Kunihiko Sakamoto 2014/09/12 01:32:13 Done.
+ })
+ .catch(unreached_rejection(t));
+ }, 'Register then getRegistration');
+
+async_test(function(t) {
+ var documentURL = 'http://example.com/';
+ navigator.serviceWorker.getRegistration(documentURL)
+ .then(function() {
+ assert_unreached('getRegistration with an out of origin URL should fail');
nhiroki 2014/09/11 11:30:34 nit: +2-space indents nit: please wrap this at 80-
Kunihiko Sakamoto 2014/09/12 01:32:13 Done.
+ }, function(reason) {
+ assert_equals(reason.name, 'SecurityError',
+ 'getRegistration with an out of origin URL should fail');
+ t.done();
+ })
+ .catch(unreached_rejection(t));
+ }, 'getRegistration with a cross origin URL');
+
+async_test(function(t) {
+ var registration;
+ navigator.serviceWorker.register('resources/empty-worker.js',
+ {scope: location.href})
nhiroki 2014/09/11 11:30:34 Why do you use |location.href|? We'd prefer to av
Kunihiko Sakamoto 2014/09/12 01:32:13 Wanted to test that getRegistration() gets a regis
nhiroki 2014/09/12 02:23:26 I see. Probably you can make an iframe for |scope|
+ .then(function(r) {
+ registration = r;
+ return navigator.serviceWorker.getRegistration();
+ })
+ .then(function(value) {
+ assert_equals(value, registration,
+ 'getRegistration should resolve with registration');
+ t.done();
nhiroki 2014/09/11 11:30:34 ditto (service_worker_unregister_and_done)
+ })
+ .catch(unreached_rejection(t));
+ }, 'getRegistration without argument');
+
+async_test(function(t) {
+ var scope = 'scope/worker/';
+ navigator.serviceWorker.register('resources/empty-worker.js',
+ {scope: scope})
+ .then(function(registration) {
+ return registration.unregister();
+ })
+ .then(function() {
+ return navigator.serviceWorker.getRegistration(scope);
+ })
+ .then(function(value) {
+ assert_equals(value, undefined,
+ 'getRegistration should resolve with undefined');
+ t.done();
+ })
+ .catch(unreached_rejection(t));
+ }, 'Register then Unregister then getRegistration');
+
+</script>
« no previous file with comments | « no previous file | Source/modules/serviceworkers/ServiceWorkerContainer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698