Index: LayoutTests/http/tests/serviceworker/chromium/resources/windowclient-focus.js |
diff --git a/LayoutTests/http/tests/serviceworker/chromium/resources/windowclient-focus.js b/LayoutTests/http/tests/serviceworker/chromium/resources/windowclient-focus.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..026bc83292eda8534c89da287c1cefa3f13b132f |
--- /dev/null |
+++ b/LayoutTests/http/tests/serviceworker/chromium/resources/windowclient-focus.js |
@@ -0,0 +1,125 @@ |
+// 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
|
+// 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.
|
+// 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.
|
+// |synthesizeNotificationClick()| and |initialize()|. |
+importScripts('sw-test-helpers.js'); |
+ |
+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.
|
+ |
+// 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.
|
+self.initialize = function() { |
+ return self.clients.getAll().then(function(clients) { |
+ clients.forEach(function(c) { |
+ // All clients are iframes but one of them embeds the other ones. We |
+ // want to use that one as the main |client|. |
+ // 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.
|
+ 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
|
+ nestedClients.push(c); |
+ else |
+ 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.
|
+ }); |
+ }); |
+} |
Michael van Ouwerkerk
2015/02/18 10:55:47
semicolon
mlamouri (slow - plz ping)
2015/02/18 11:34:55
Done.
|
+ |
+function getNumberOfFocusedClients() { |
+ return self.clients.getAll().then(function(clients) { |
+ var focusedClients = 0; |
+ 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
|
+ if (c.focused) |
+ ++focusedClients; |
+ }); |
+ return focusedClients; |
+ }); |
+} |
+ |
+var TESTS = [ |
+ function testWithoutClick() { |
+ client.focus().catch(function(e) { |
+ self.postMessage('focus() can\'t focus a window without a user interaction'); |
+ self.postMessage('focus() error is ' + e.name); |
+ }).then(runNextTestOrQuit); |
+ }, |
+ |
+ function testFocusingFrame() { |
+ synthesizeNotificationClick().then(function(e) { |
+ client.focus().then(function(c) { |
+ self.postMessage('focus() succeeded'); |
+ self.postMessage('focus() result: ' + c); |
+ self.postMessage(' url: ' + c.url); |
+ self.postMessage(' visibilityState: ' + c.visibilityState); |
+ self.postMessage(' focused: ' + c.focused); |
+ self.postMessage(' frameType: ' + c.frameType); |
+ }).then(getNumberOfFocusedClients) |
+ .then(function(count) { |
+ // 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.
|
+ self.postMessage('focused clients: ' + count); |
+ }).then(runNextTestOrQuit); |
+ }); |
+ }, |
+ |
+ 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.
|
+ 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.
|
+ nestedClients[0].focus().then(function(c) { |
+ self.postMessage('focus() succeeded'); |
+ self.postMessage('focus() result: ' + c); |
+ self.postMessage(' url: ' + c.url); |
+ self.postMessage(' visibilityState: ' + c.visibilityState); |
+ self.postMessage(' focused: ' + c.focused); |
+ self.postMessage(' frameType: ' + c.frameType); |
+ }).then(getNumberOfFocusedClients) |
+ .then(function(count) { |
+ // 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.
|
+ self.postMessage('focused clients: ' + count); |
+ }).then(runNextTestOrQuit); |
+ }); |
+ }, |
+ |
+ function testFocusOtherNestedFrames() { |
+ synthesizeNotificationClick().then(function(e) { |
+ nestedClients[1].focus().then(function(c) { |
+ self.postMessage('focus() succeeded'); |
+ self.postMessage('focus() result: ' + c); |
+ self.postMessage(' url: ' + c.url); |
+ self.postMessage(' visibilityState: ' + c.visibilityState); |
+ self.postMessage(' focused: ' + c.focused); |
+ self.postMessage(' frameType: ' + c.frameType); |
+ }).then(getNumberOfFocusedClients) |
+ .then(function(count) { |
+ // 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.
|
+ self.postMessage('focused clients: ' + count); |
+ }).then(runNextTestOrQuit); |
+ }); |
+ }, |
+ |
+ function testFocusOpenedWindow() { |
+ synthesizeNotificationClick().then(function(e) { |
+ return self.clients.openWindow('windowclient-focus.html?3'); |
+ }).then(function(c) { |
+ synthesizeNotificationClick().then(function(e) { |
+ c.focus().then(function() { |
+ self.postMessage('focus() succeeded'); |
+ self.postMessage('focus() result: ' + c); |
+ self.postMessage(' url: ' + c.url); |
+ self.postMessage(' visibilityState: ' + c.visibilityState); |
+ self.postMessage(' focused: ' + c.focused); |
+ self.postMessage(' frameType: ' + c.frameType); |
+ }).then(getNumberOfFocusedClients) |
+ .then(function(count) { |
+ // There should be 1 focused client at that point. |
+ self.postMessage('focused clients: ' + count); |
+ }).then(runNextTestOrQuit); |
+ }); |
+ }); |
+ } |
+]; |
+ |
+self.onmessage = function(e) { |
+ 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.
|
+ initialize().then(runNextTestOrQuit); |
+ } else { |
+ initialize().then(function() { |
+ self.postMessage('received unexpected message'); |
+ self.postMessage('quit'); |
+ }); |
+ } |
+} |
Michael van Ouwerkerk
2015/02/18 10:55:47
semicolon
mlamouri (slow - plz ping)
2015/02/18 11:34:55
Done.
|