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

Side by Side Diff: LayoutTests/http/tests/serviceworker/resources/test-helpers.js

Issue 265943003: Add blink-side binding code for navigator.serviceWorker.current (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebased cached properties access tests Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Adapter for testharness.js-style tests with Service Workers 1 // Adapter for testharness.js-style tests with Service Workers
2 2
3 function service_worker_test(url, description) { 3 function service_worker_test(url, description) {
4 var t = async_test(description); 4 var t = async_test(description);
5 t.step(function() { 5 t.step(function() {
6 6
7 navigator.serviceWorker.register(url, {scope:'nonexistent'}).then( 7 navigator.serviceWorker.register(url, {scope:'nonexistent'}).then(
8 t.step_func(function(worker) { 8 t.step_func(function(worker) {
9 var messageChannel = new MessageChannel(); 9 var messageChannel = new MessageChannel();
10 messageChannel.port1.onmessage = t.step_func(onMessage); 10 messageChannel.port1.onmessage = t.step_func(onMessage);
11 worker.postMessage({port:messageChannel.port2}, [messageChannel. port2]); 11 worker.postMessage({port:messageChannel.port2}, [messageChannel. port2]);
12 }), 12 }),
13 t.step_func(function(reason) { 13 unreached_rejection(t, 'Registration should succeed, but failed')
14 assert_unreached('Registration should succeed, but failed: ' + r eason.name); 14 );
15 }));
16 15
17 function onMessage(e) { 16 function onMessage(e) {
18 assert_equals(e.data, 'pass'); 17 assert_equals(e.data, 'pass');
19 t.done(); 18 t.done();
20 } 19 }
21 }); 20 });
22 } 21 }
23 22
24 // FIXME: Replace this with test.unreached_func(desc) once testharness.js is upd ated 23 // FIXME: Replace this with test.unreached_func(desc) once testharness.js is upd ated
25 // Use with unexpected event handlers or Promise rejection. 24 // Use with unexpected event handlers or Promise rejection.
26 // E.g.: 25 // E.g.:
27 // onbadevent = fail(t, 'Should only see good events'); 26 // onbadevent = fail(t, 'Should only see good events');
28 // Promise.then(...).catch(fail(t, 'Rejection is never fun')); 27 // Promise.then(...).catch(fail(t, 'Rejection is never fun'));
29 function unreached_func(test, desc) { 28 function unreached_func(test, desc) {
30 return test.step_func(function() { 29 return test.step_func(function() {
31 assert_unreached(desc); 30 assert_unreached(desc);
32 }); 31 });
33 } 32 }
34 33
35 // Rejection-specific helper that provides more details 34 // Rejection-specific helper that provides more details
36 function unreached_rejection(test, prefix) { 35 function unreached_rejection(test, prefix) {
37 return test.step_func(function(reason) { 36 return test.step_func(function(reason) {
38 assert_unreached(prefix + ': ' + reason.name); 37 assert_unreached(prefix + ': ' + reason.name);
39 }); 38 });
40 } 39 }
40
41 // FIXME: Clean up the iframe when the test completes.
42 function with_iframe(url, f) {
43 var frame = document.createElement('iframe');
44 frame.src = url;
45 frame.onload = function() {
46 f(frame);
47 };
48 document.body.appendChild(frame);
49 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698