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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/client-id.html

Issue 2778903002: Upstream service worker `client` tests to WPT (Closed)
Patch Set: Remove unnecessary branch 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
(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 test;
8 var scope = 'resources/blank.html?client-id';
9 var frame1, frame2;
10
11 async_test(function(t) {
12 test = t;
13 service_worker_unregister_and_register(
14 t, 'resources/client-id-worker.js', scope)
15 .then(function(registration) {
16 return wait_for_state(t, registration.installing, 'activated');
17 })
18 .then(function() { return with_iframe(scope + '#1'); })
19 .then(function(f) {
20 frame1 = f;
21 // To be sure Clients.matchAll() iterates in the same order.
22 f.focus();
23 return with_iframe(scope + '#2');
24 })
25 .then(function(f) {
26 frame2 = f;
27 var channel = new MessageChannel();
28 channel.port1.onmessage = t.step_func(on_message);
29 f.contentWindow.navigator.serviceWorker.controller.postMessage(
30 {port:channel.port2}, [channel.port2]);
31 })
32 .catch(unreached_rejection(t));
33 }, 'Client.id returns the client\'s UUID.');
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
43 function on_message(e) {
44 // The result of two sequential clients.matchAll() calls in the SW.
45 // 1st matchAll() results in e.data[0], e.data[1].
46 // 2nd matchAll() results in e.data[2], e.data[3].
47 assert_equals(e.data.length, 4);
48 // All should be valid UUIDs.
49 assert_true(validate_uuid(e.data[0]));
50 assert_true(validate_uuid(e.data[1]));
51 assert_true(validate_uuid(e.data[2]));
52 assert_true(validate_uuid(e.data[3]));
53 // Different clients should have different ids.
54 assert_not_equals(e.data[0], e.data[1]);
55 assert_not_equals(e.data[2], e.data[3]);
56 // Same clients should have an identical id.
57 assert_equals(e.data[0], e.data[2]);
58 assert_equals(e.data[1], e.data[3]);
59 frame1.remove();
60 frame2.remove();
61 service_worker_unregister_and_done(test, scope);
62 }
63 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698