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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/client-id.https.html

Issue 2778903002: Upstream service worker `client` tests to WPT (Closed)
Patch Set: Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <title>Service Worker: Client.id</title> 2 <title>Service Worker: Client.id</title>
3 <script src="../resources/testharness.js"></script> 3 <script src="/resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script> 4 <script src="/resources/testharnessreport.js"></script>
5 <script src="resources/test-helpers.js"></script> 5 <script src="resources/test-helpers.sub.js"></script>
6 <script> 6 <script>
7 var test; 7 var test;
8 var scope = 'resources/blank.html?client-id'; 8 var scope = 'resources/blank.html?client-id';
9 var frame1, frame2; 9 var frame1, frame2;
10 10
11 async_test(function(t) { 11 async_test(function(t) {
12 test = t; 12 test = t;
13 service_worker_unregister_and_register( 13 service_worker_unregister_and_register(
14 t, 'resources/client-id-worker.js', scope) 14 t, 'resources/client-id-worker.js', scope)
15 .then(function(registration) { 15 .then(function(registration) {
16 return wait_for_state(t, registration.installing, 'activated'); 16 return wait_for_state(t, registration.installing, 'activated');
17 }) 17 })
18 .then(function() { return with_iframe(scope + '#1'); }) 18 .then(function() { return with_iframe(scope + '#1'); })
19 .then(function(f) { 19 .then(function(f) {
20 frame1 = f; 20 frame1 = f;
21 // To be sure Clients.matchAll() iterates in the same order. 21 // To be sure Clients.matchAll() iterates in the same order.
22 f.focus(); 22 f.focus();
23 return with_iframe(scope + '#2'); 23 return with_iframe(scope + '#2');
24 }) 24 })
25 .then(function(f) { 25 .then(function(f) {
26 frame2 = f; 26 frame2 = f;
27 var channel = new MessageChannel(); 27 var channel = new MessageChannel();
28 channel.port1.onmessage = t.step_func(on_message); 28 channel.port1.onmessage = t.step_func(on_message);
29 f.contentWindow.navigator.serviceWorker.controller.postMessage( 29 f.contentWindow.navigator.serviceWorker.controller.postMessage(
30 {port:channel.port2}, [channel.port2]); 30 {port:channel.port2}, [channel.port2]);
31 }) 31 })
32 .catch(unreached_rejection(t)); 32 .catch(unreached_rejection(t));
33 }, 'Client.id returns the client\'s UUID.'); 33 }, 'Client.id returns the client\'s ID.');
34
35 // A regex object for UUID(http://tools.ietf.org/html/rfc4122) validation.
36 var pattern = new RegExp(['^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-',
37 '9a-f]{3}-[0-9a-f]{12}$'].join(''), 'i');
38
39 function validate_uuid(id) {
40 return !!id.match(pattern);
41 }
42 34
43 function on_message(e) { 35 function on_message(e) {
44 // The result of two sequential clients.matchAll() calls in the SW. 36 // The result of two sequential clients.matchAll() calls in the SW.
45 // 1st matchAll() results in e.data[0], e.data[1]. 37 // 1st matchAll() results in e.data[0], e.data[1].
46 // 2nd matchAll() results in e.data[2], e.data[3]. 38 // 2nd matchAll() results in e.data[2], e.data[3].
47 assert_equals(e.data.length, 4); 39 assert_equals(e.data.length, 4);
48 // All should be valid UUIDs. 40 // All should be string values
falken 2017/03/28 07:24:39 nit: period at end of sentence
mike3 2017/03/28 20:45:08 Acknowledged.
49 assert_true(validate_uuid(e.data[0])); 41 assert_equals(typeof e.data[0], 'string');
50 assert_true(validate_uuid(e.data[1])); 42 assert_equals(typeof e.data[1], 'string');
51 assert_true(validate_uuid(e.data[2])); 43 assert_equals(typeof e.data[2], 'string');
52 assert_true(validate_uuid(e.data[3])); 44 assert_equals(typeof e.data[3], 'string');
53 // Different clients should have different ids. 45 // Different clients should have different ids.
54 assert_not_equals(e.data[0], e.data[1]); 46 assert_not_equals(e.data[0], e.data[1]);
55 assert_not_equals(e.data[2], e.data[3]); 47 assert_not_equals(e.data[2], e.data[3]);
56 // Same clients should have an identical id. 48 // Same clients should have an identical id.
57 assert_equals(e.data[0], e.data[2]); 49 assert_equals(e.data[0], e.data[2]);
58 assert_equals(e.data[1], e.data[3]); 50 assert_equals(e.data[1], e.data[3]);
59 frame1.remove(); 51 frame1.remove();
60 frame2.remove(); 52 frame2.remove();
61 service_worker_unregister_and_done(test, scope); 53 service_worker_unregister_and_done(test, scope);
62 } 54 }
63 </script> 55 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698