OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <title>Service Worker: Client.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?client-id'; | |
8 var t = async_test('Test Client.id'); | |
9 var frame1, frame2; | |
10 t.step(function() { | |
11 service_worker_unregister_and_register( | |
12 t, 'resources/client-id-worker.js', scope) | |
13 .then(function(registration) { | |
14 return wait_for_state(t, registration.installing, 'activated'); | |
15 }) | |
16 .then(function() { return with_iframe(scope + '#1'); }) | |
17 .then(function(f) { | |
18 frame1 = f; | |
19 f.focus(); | |
20 return with_iframe(scope + '#2'); | |
21 }) | |
22 .then(function(f) { | |
23 frame2 = f; | |
24 var channel = new MessageChannel(); | |
25 channel.port1.onmessage = t.step_func(onMessage); | |
26 f.contentWindow.navigator.serviceWorker.controller.postMessage( | |
27 {port:channel.port2}, [channel.port2]); | |
28 }) | |
29 .catch(unreached_rejection(t)); | |
30 }); | |
31 | |
32 // A regex object for UUID validation | |
kinuko
2015/06/25 02:23:04
nit: end comments with period. Also it might be ni
| |
33 var pattern = new RegExp (['^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0', | |
lgombos
2015/06/25 01:04:21
Not sure if this regexp is general enough. Does th
lgombos
2015/06/25 01:10:34
Sorry I missed the 'i' at the end, but why [1-5] i
jungkees
2015/06/25 01:51:36
According to RFC4122, that byte can hold the value
| |
34 '-9a-f]{3}-[0-9a-f]{12}$'].join(''), 'i'); | |
35 function validateUUID(id) { | |
36 return id.match(pattern) ? true : false; | |
37 } | |
38 | |
39 function onMessage(e) { | |
40 // The result of two sequential clients.matchAll() calls in the SW. | |
41 // 1st matchAll() results in e.data[0], e.data[1]. | |
42 // 2nd matchAll() results in e.data[2], e.data[3]. | |
43 assert_equals(e.data.length, 4); | |
44 // All should be valid UUIDs. | |
45 assert_true(validateUUID(e.data[0])); | |
46 assert_true(validateUUID(e.data[1])); | |
47 assert_true(validateUUID(e.data[2])); | |
48 assert_true(validateUUID(e.data[3])); | |
49 // Different clients should have different ids. | |
50 assert_not_equals(e.data[0], e.data[1]); | |
51 assert_not_equals(e.data[2], e.data[3]); | |
52 // Same clients should have an identical id. | |
53 assert_equals(e.data[0], e.data[2]); | |
54 assert_equals(e.data[1], e.data[3]); | |
55 frame1.remove(); | |
56 frame2.remove(); | |
57 service_worker_unregister_and_done(t, scope); | |
58 } | |
59 </script> | |
OLD | NEW |