OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Service Worker: ServiceWorker.id</title> |
| 3 <script src="../resources/testharness.js"></script> |
| 4 <script src="../resources/testharnessreport.js"></script> |
| 5 <script src="resources/test-helpers.js"></script> |
| 6 <script> |
| 7 var scope = 'resources/blank.html?serviceworker-id'; |
| 8 var worker_url = 'resources/update-worker.php'; |
| 9 var registration; |
| 10 var uuid1, uuid2; |
| 11 |
| 12 // A regex object for UUID(http://tools.ietf.org/html/rfc4122) validation. |
| 13 var pattern = new RegExp(['^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-', |
| 14 '9a-f]{3}-[0-9a-f]{12}$'].join(''), 'i'); |
| 15 |
| 16 function validate_uuid(id) { |
| 17 return !!id.match(pattern); |
| 18 } |
| 19 |
| 20 promise_test(function(t) { |
| 21 return service_worker_unregister_and_register(t, worker_url, scope) |
| 22 .then(function(r) { |
| 23 registration = r; |
| 24 uuid1 = r.installing.id; |
| 25 assert_true(validate_uuid(uuid1)); |
| 26 return wait_for_state(t, r.installing, 'activated'); |
| 27 }) |
| 28 .then(function() { |
| 29 assert_equals( |
| 30 registration.active.id, |
| 31 uuid1, |
| 32 'installing should still have the same UUID when activated.'); |
| 33 |
| 34 // A new worker should be found. |
| 35 registration.update(); |
| 36 return wait_for_update(t, registration); |
| 37 }) |
| 38 .then(function(new_installing) { |
| 39 uuid2 = new_installing.id; |
| 40 assert_true(validate_uuid(uuid2)); |
| 41 return wait_for_state(t, new_installing, 'activated'); |
| 42 }) |
| 43 .then(function() { |
| 44 assert_equals( |
| 45 registration.active.id, |
| 46 uuid2, |
| 47 'new installing should still have the same UUID when activated.'); |
| 48 assert_not_equals( |
| 49 uuid1, |
| 50 uuid2, |
| 51 'A service worker should obtain a new UUID after update.'); |
| 52 return service_worker_unregister_and_done(t, scope); |
| 53 }); |
| 54 }, 'ServiceWorker.id returns the service worker\'s UUID.'); |
| 55 </script> |
OLD | NEW |