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

Side by Side Diff: LayoutTests/http/tests/serviceworker/chromium/resources/notificationclick-can-openwindow.js

Issue 896043004: Tests for WaitUntilObserver and focus/openining windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@sw_client_focus_cleanup
Patch Set: cleanups and review comments Created 5 years, 10 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 var client = null;
2
3 function initialize() {
4 return self.clients.getAll().then(function(clients) {
5 client = clients[0];
6 });
7 }
8
9 function synthesizeNotificationClick() {
10 var promise = new Promise(function(resolver) {
11 var title = "fake notification";
12 registration.showNotification(title).then(function() {
13 client.postMessage({type: 'click', title: title});
14 });
15
16 var handler = function(e) {
17 resolver(e);
18 e.notification.close();
19 self.removeEventListener('notificationclick', handler);
20 };
21
22 self.addEventListener('notificationclick', handler);
23 });
24
25 return promise;
26 }
27
28 var CURRENT_TEST = -1;
29 var TESTS = [
30 function testWithNoNotificationClick() {
31 clients.openWindow('/foo.html').catch(function() {
32 client.postMessage('openWindow() outside of a notificationclick even t failed');
33 }).then(runNextTestOrQuit);
34 },
35
36 function testInStackOutOfWaitUntil() {
37 synthesizeNotificationClick().then(function() {
38 clients.openWindow('/foo.html').then(function() {
39 client.postMessage('openWindow() in notificationclick outside of waitUntil but in stack succeeded');
40 }).then(runNextTestOrQuit);
41 });
42 },
43
44 function testOutOfStackOutOfWaitUntil() {
45 synthesizeNotificationClick().then(function() {
46 self.clients.getAll().then(function() {
47 clients.openWindow('/foo.html').catch(function() {
48 client.postMessage('openWindow() in notificationclick outsid e of waitUntil not in stack failed');
49 }).then(runNextTestOrQuit);
50 });
51 });
52 },
53
54 function testInWaitUntilAsyncAndDoubleCall() {
55 synthesizeNotificationClick().then(function(e) {
56 e.waitUntil(self.clients.getAll().then(function() {
57 return clients.openWindow('/foo.html').then(function() {
58 client.postMessage('openWindow() in notificationclick\'s wai tUntil suceeded');
59 }).then(runNextTestOrQuit);
60 }));
61 });
62 },
63
64 function testDoubleCallInWaitUntilAsync() {
65 synthesizeNotificationClick().then(function(e) {
66 e.waitUntil(self.clients.getAll().then(function() {
67 return clients.openWindow('/foo.html').then(function() {
68 return clients.openWindow('/foo.html');
69 }).catch(function() {
70 client.postMessage('openWindow() called twice failed');
71 }).then(runNextTestOrQuit);
72 }));
73 });
74 },
75
76
77 function testWaitUntilTimeout() {
78 var p = new Promise(function(resolve) {
79 setTimeout(function() {
80 resolve();
81 }, 2000);
82 });
83
84 synthesizeNotificationClick().then(function(e) {
85 e.waitUntil(p.then(function() {
86 return clients.openWindow('/foo.html').catch(function() {
87 client.postMessage('openWindow() failed after timeout');
88 }).then(runNextTestOrQuit);
89 }));
90 });
91 },
92
93 function testFocusWindowOpenWindowCombo() {
94 synthesizeNotificationClick().then(function(e) {
95 e.waitUntil(client.focus().then(function() {
96 clients.openWindow().catch(function() {
97 client.postMessage('openWindow() failed because a window was focused before');
98 }).then(runNextTestOrQuit);
99 }));
100 });
101 },
102 ];
103
104 function runNextTestOrQuit() {
dominicc (has gone to gerrit) 2015/02/13 03:45:11 You could put this, the thing that starts it, and
mlamouri (slow - plz ping) 2015/02/13 10:18:09 I have two other CLs testing .focus() and .openWin
105 ++CURRENT_TEST;
106 if (CURRENT_TEST >= TESTS.length) {
107 client.postMessage('quit');
108 return;
109 }
110 TESTS[CURRENT_TEST]();
111 }
112
113 self.onmessage = function(e) {
114 switch(e.data) {
115 case "start":
116 initialize().then(runNextTestOrQuit);
117 break;
118 }
119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698