OLD | NEW |
---|---|
(Empty) | |
1 // This helper will setup a small test framework that will use TESTS and run | |
Michael van Ouwerkerk
2015/02/18 10:55:47
Please rename this file to windowclient-focus-work
mlamouri (slow - plz ping)
2015/02/18 11:34:55
It would be inconsistent with:
- notificationclick
| |
2 // them iteratively and call self.postMessage('quit') when done. | |
Michael van Ouwerkerk
2015/02/18 10:55:47
Iteratively, sure. Sequentially though?
mlamouri (slow - plz ping)
2015/02/18 11:34:55
Done. Change the other files.
| |
3 // This helper also exposes |client|, |postMessage()|, |runNextTestOrQuit()|, | |
Michael van Ouwerkerk
2015/02/18 10:55:47
This helper does not expose runNextTestOrQuit, it
mlamouri (slow - plz ping)
2015/02/18 11:34:55
sw-test-helpers.js is the helper.
| |
4 // |synthesizeNotificationClick()| and |initialize()|. | |
5 importScripts('sw-test-helpers.js'); | |
6 | |
7 var nestedClients = []; | |
Michael van Ouwerkerk
2015/02/18 10:55:47
Please document this global.
mlamouri (slow - plz ping)
2015/02/18 11:34:55
Done.
| |
8 | |
9 // Override self.initiaze() from sw-test-helpers.js | |
Michael van Ouwerkerk
2015/02/18 10:55:47
initialize
mlamouri (slow - plz ping)
2015/02/18 11:34:55
Done.
| |
10 self.initialize = function() { | |
11 return self.clients.getAll().then(function(clients) { | |
12 clients.forEach(function(c) { | |
13 // All clients are iframes but one of them embeds the other ones. We | |
14 // want to use that one as the main |client|. | |
15 // It's url ends with '.html' while the others ends with '.html?X' | |
Michael van Ouwerkerk
2015/02/18 10:55:47
Its
mlamouri (slow - plz ping)
2015/02/18 11:34:55
Done.
| |
16 if (c.url.search(/\.html\?[0-9]/) != -1) | |
Michael van Ouwerkerk
2015/02/18 10:55:47
I think this is more readable by avoiding a regex:
mlamouri (slow - plz ping)
2015/02/18 11:34:55
I would have bet I tried to write some code in Chr
| |
17 nestedClients.push(c); | |
18 else | |
19 client = c; | |
Michael van Ouwerkerk
2015/02/18 10:55:47
Is this not declared as a global explicitly? Pleas
mlamouri (slow - plz ping)
2015/02/18 11:34:56
It's documented in the first block of comment.
| |
20 }); | |
21 }); | |
22 } | |
Michael van Ouwerkerk
2015/02/18 10:55:47
semicolon
mlamouri (slow - plz ping)
2015/02/18 11:34:55
Done.
| |
23 | |
24 function getNumberOfFocusedClients() { | |
25 return self.clients.getAll().then(function(clients) { | |
26 var focusedClients = 0; | |
27 clients.forEach(function(c) { | |
Michael van Ouwerkerk
2015/02/18 10:55:47
Please avoid single character variable names unles
mlamouri (slow - plz ping)
2015/02/18 11:34:55
I do not use |client| on purpose to prevent confus
| |
28 if (c.focused) | |
29 ++focusedClients; | |
30 }); | |
31 return focusedClients; | |
32 }); | |
33 } | |
34 | |
35 var TESTS = [ | |
36 function testWithoutClick() { | |
37 client.focus().catch(function(e) { | |
38 self.postMessage('focus() can\'t focus a window without a user inter action'); | |
39 self.postMessage('focus() error is ' + e.name); | |
40 }).then(runNextTestOrQuit); | |
41 }, | |
42 | |
43 function testFocusingFrame() { | |
44 synthesizeNotificationClick().then(function(e) { | |
45 client.focus().then(function(c) { | |
46 self.postMessage('focus() succeeded'); | |
47 self.postMessage('focus() result: ' + c); | |
48 self.postMessage(' url: ' + c.url); | |
49 self.postMessage(' visibilityState: ' + c.visibilityState); | |
50 self.postMessage(' focused: ' + c.focused); | |
51 self.postMessage(' frameType: ' + c.frameType); | |
52 }).then(getNumberOfFocusedClients) | |
53 .then(function(count) { | |
54 // There should be 1 focused client at that point. | |
Michael van Ouwerkerk
2015/02/18 10:55:47
s/that/this/g
mlamouri (slow - plz ping)
2015/02/18 11:34:55
Done.
| |
55 self.postMessage('focused clients: ' + count); | |
56 }).then(runNextTestOrQuit); | |
57 }); | |
58 }, | |
59 | |
60 function testFocusNestedFrames() { | |
Michael van Ouwerkerk
2015/02/18 10:55:47
Maybe rename to |testFocusNestedFrame| as you expe
mlamouri (slow - plz ping)
2015/02/18 11:34:55
Done.
| |
61 synthesizeNotificationClick().then(function(e) { | |
Michael van Ouwerkerk
2015/02/18 10:55:47
What is e?
mlamouri (slow - plz ping)
2015/02/18 11:34:55
event. Not used.
| |
62 nestedClients[0].focus().then(function(c) { | |
63 self.postMessage('focus() succeeded'); | |
64 self.postMessage('focus() result: ' + c); | |
65 self.postMessage(' url: ' + c.url); | |
66 self.postMessage(' visibilityState: ' + c.visibilityState); | |
67 self.postMessage(' focused: ' + c.focused); | |
68 self.postMessage(' frameType: ' + c.frameType); | |
69 }).then(getNumberOfFocusedClients) | |
70 .then(function(count) { | |
71 // There should be 2 focused client at that point. | |
Michael van Ouwerkerk
2015/02/18 10:55:47
clients
mlamouri (slow - plz ping)
2015/02/18 11:34:55
Done.
| |
72 self.postMessage('focused clients: ' + count); | |
73 }).then(runNextTestOrQuit); | |
74 }); | |
75 }, | |
76 | |
77 function testFocusOtherNestedFrames() { | |
78 synthesizeNotificationClick().then(function(e) { | |
79 nestedClients[1].focus().then(function(c) { | |
80 self.postMessage('focus() succeeded'); | |
81 self.postMessage('focus() result: ' + c); | |
82 self.postMessage(' url: ' + c.url); | |
83 self.postMessage(' visibilityState: ' + c.visibilityState); | |
84 self.postMessage(' focused: ' + c.focused); | |
85 self.postMessage(' frameType: ' + c.frameType); | |
86 }).then(getNumberOfFocusedClients) | |
87 .then(function(count) { | |
88 // There should be 2 focused client at that point. | |
Michael van Ouwerkerk
2015/02/18 10:55:47
Why? Presumably because focusing this frame blurre
mlamouri (slow - plz ping)
2015/02/18 11:34:55
Add a comment to explain.
| |
89 self.postMessage('focused clients: ' + count); | |
90 }).then(runNextTestOrQuit); | |
91 }); | |
92 }, | |
93 | |
94 function testFocusOpenedWindow() { | |
95 synthesizeNotificationClick().then(function(e) { | |
96 return self.clients.openWindow('windowclient-focus.html?3'); | |
97 }).then(function(c) { | |
98 synthesizeNotificationClick().then(function(e) { | |
99 c.focus().then(function() { | |
100 self.postMessage('focus() succeeded'); | |
101 self.postMessage('focus() result: ' + c); | |
102 self.postMessage(' url: ' + c.url); | |
103 self.postMessage(' visibilityState: ' + c.visibilityState); | |
104 self.postMessage(' focused: ' + c.focused); | |
105 self.postMessage(' frameType: ' + c.frameType); | |
106 }).then(getNumberOfFocusedClients) | |
107 .then(function(count) { | |
108 // There should be 1 focused client at that point. | |
109 self.postMessage('focused clients: ' + count); | |
110 }).then(runNextTestOrQuit); | |
111 }); | |
112 }); | |
113 } | |
114 ]; | |
115 | |
116 self.onmessage = function(e) { | |
117 if (e.data == "start") { | |
Michael van Ouwerkerk
2015/02/18 10:55:47
single quotes for js string literals
mlamouri (slow - plz ping)
2015/02/18 11:34:55
Done.
| |
118 initialize().then(runNextTestOrQuit); | |
119 } else { | |
120 initialize().then(function() { | |
121 self.postMessage('received unexpected message'); | |
122 self.postMessage('quit'); | |
123 }); | |
124 } | |
125 } | |
Michael van Ouwerkerk
2015/02/18 10:55:47
semicolon
mlamouri (slow - plz ping)
2015/02/18 11:34:55
Done.
| |
OLD | NEW |