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

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

Issue 1211253007: ServiceWorker: Add LayoutTest for WindowClient.navigate(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 5 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 // Test helper that is meant as a mini test framework to be used from a service 1 // Test helper that is meant as a mini test framework to be used from a service
2 // worker that runs some tests and send results back to its client. 2 // worker that runs some tests and send results back to its client.
3 // 3 //
4 // A simple usage of this framework would consist of calling initialize() to 4 // A simple usage of this framework would consist of calling initialize() to
5 // setup then runNextTestOrQuit() in order to start running the methods defined 5 // setup then runNextTestOrQuit() in order to start running the methods defined
6 // by TESTS. Then, tests can start sending messages back to the client using 6 // by TESTS. Then, tests can start sending messages back to the client using
7 // postMessage(). 7 // postMessage().
8 // 8 //
9 // Example: 9 // Example:
10 // var TESTS = [ 10 // var TESTS = [
(...skipping 21 matching lines...) Expand all
32 } 32 }
33 33
34 self.postMessage = function(msg) { 34 self.postMessage = function(msg) {
35 client.postMessage(msg); 35 client.postMessage(msg);
36 } 36 }
37 37
38 // Run the next test in TESTS if any. Otherwise sends a 'quit' message. and 38 // Run the next test in TESTS if any. Otherwise sends a 'quit' message. and
39 // stops. 39 // stops.
40 // In order for that call to succeed, the script MUST have a TESTS array 40 // In order for that call to succeed, the script MUST have a TESTS array
41 // defined. 41 // defined.
42 self.runNextTestOrQuit = function() { 42 self.runNextTestOrQuit = function(data) {
43 ++currentTest; 43 ++currentTest;
44 if (currentTest >= TESTS.length) { 44 if (currentTest >= TESTS.length) {
45 client.postMessage('quit'); 45 client.postMessage('quit');
46 return; 46 return;
47 } 47 }
48 TESTS[currentTest](); 48 TESTS[currentTest](data);
49 } 49 }
50 50
51 // This method will use the |client| in order to synthesize a notificationclick 51 // This method will use the |client| in order to synthesize a notificationclick
52 // event. The client will then use the testRunner. 52 // event. The client will then use the testRunner.
53 // The returned promise will be resolved with the notificationclick event 53 // The returned promise will be resolved with the notificationclick event
54 // object. 54 // object.
55 self.synthesizeNotificationClick = function() { 55 self.synthesizeNotificationClick = function() {
56 var promise = new Promise(function(resolve) { 56 var promise = new Promise(function(resolve) {
57 var title = "fake notification"; 57 var title = "fake notification";
58 registration.showNotification(title).then(function() { 58 registration.showNotification(title).then(function() {
59 client.postMessage({type: 'click', title: title}); 59 client.postMessage({type: 'click', title: title});
60 }); 60 });
61 61
62 var handler = function(e) { 62 var handler = function(e) {
63 resolve(e); 63 resolve(e);
64 e.notification.close(); 64 e.notification.close();
65 self.removeEventListener('notificationclick', handler); 65 self.removeEventListener('notificationclick', handler);
66 }; 66 };
67 67
68 self.addEventListener('notificationclick', handler); 68 self.addEventListener('notificationclick', handler);
69 }); 69 });
70 70
71 return promise; 71 return promise;
72 } 72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698