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: LayoutTests/http/tests/serviceworker/client-id.html

Issue 1209493002: Service Worker: Surface Client.id attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add a reference to RFC4122. Created 5 years, 6 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 scope = 'resources/blank.html?client-id';
8 var t = async_test('Test Client.id');
falken 2015/06/25 04:09:56 our style guide does async_test(function(t) { //te
jungkees 2015/06/25 07:48:36 Right. Corrected it accordingly.
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();
falken 2015/06/25 04:09:56 why do we need to focus()?
jungkees 2015/06/25 07:48:36 This is to be sure Clients.matchAll() calls iterat
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(http://tools.ietf.org/html/rfc4122) validation.
33 var pattern = new RegExp (['^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0',
falken 2015/06/25 04:09:56 nit: no space before the (
34 '-9a-f]{3}-[0-9a-f]{12}$'].join(''), 'i');
35 function validateUUID(id) {
falken 2015/06/25 04:09:56 nit: validate_uuid
36 return id.match(pattern) ? true : false;
37 }
38
39 function onMessage(e) {
falken 2015/06/25 04:09:56 nit: on_message
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>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698