Index: LayoutTests/http/tests/serviceworker/serviceworkerobject-id.html |
diff --git a/LayoutTests/http/tests/serviceworker/serviceworkerobject-id.html b/LayoutTests/http/tests/serviceworker/serviceworkerobject-id.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f3acdfe95aa6fdcc8d3388bac47662f8990f8741 |
--- /dev/null |
+++ b/LayoutTests/http/tests/serviceworker/serviceworkerobject-id.html |
@@ -0,0 +1,55 @@ |
+<!DOCTYPE html> |
+<title>Service Worker: ServiceWorker.id</title> |
+<script src="../resources/testharness.js"></script> |
+<script src="../resources/testharnessreport.js"></script> |
+<script src="resources/test-helpers.js"></script> |
+<script> |
+var scope = 'resources/blank.html?serviceworker-id'; |
+var worker_url = 'resources/update-worker.php'; |
+var registration; |
+var uuid1, uuid2; |
+ |
+// A regex object for UUID(http://tools.ietf.org/html/rfc4122) validation. |
+var pattern = new RegExp(['^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-', |
+ '9a-f]{3}-[0-9a-f]{12}$'].join(''), 'i'); |
+ |
+function validate_uuid(id) { |
+ return !!id.match(pattern); |
+} |
+ |
+promise_test(function(t) { |
+ return service_worker_unregister_and_register(t, worker_url, scope) |
+ .then(function(r) { |
+ registration = r; |
+ uuid1 = r.installing.id; |
+ assert_true(validate_uuid(uuid1)); |
+ return wait_for_state(t, r.installing, 'activated'); |
+ }) |
+ .then(function() { |
+ assert_equals( |
+ registration.active.id, |
+ uuid1, |
+ 'installing should still have the same UUID when activated.'); |
+ |
+ // A new worker should be found. |
+ registration.update(); |
+ return wait_for_update(t, registration); |
+ }) |
+ .then(function(new_installing) { |
+ uuid2 = new_installing.id; |
+ assert_true(validate_uuid(uuid2)); |
+ return wait_for_state(t, new_installing, 'activated'); |
+ }) |
+ .then(function() { |
+ assert_equals( |
+ registration.active.id, |
+ uuid2, |
+ 'new installing should still have the same UUID when activated.'); |
+ assert_not_equals( |
+ uuid1, |
+ uuid2, |
+ 'A service worker should obtain a new UUID after update.'); |
+ return service_worker_unregister_and_done(t, scope); |
+ }); |
+ }, 'ServiceWorker.id returns the service worker\'s UUID.'); |
+</script> |