Chromium Code Reviews| Index: chrome/test/data/extensions/platform_apps/web_view/focus_visibility/window.js |
| diff --git a/chrome/test/data/extensions/platform_apps/web_view/focus_visibility/window.js b/chrome/test/data/extensions/platform_apps/web_view/focus_visibility/window.js |
| index 3fbeb490e99b1966c4b21e5ea00acd155ca91816..68f765aac02911faf25ae7f9cadb2168f424e26d 100644 |
| --- a/chrome/test/data/extensions/platform_apps/web_view/focus_visibility/window.js |
| +++ b/chrome/test/data/extensions/platform_apps/web_view/focus_visibility/window.js |
| @@ -1,6 +1,35 @@ |
| // Copyright 2015 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +// |
| +'use strict'; |
| + |
| +var isOopif = false; |
| +var webViewButtonFocused = false; |
| + |
| +var webviewReplyCallback = null; |
| + |
| +function listenForForKeyupAndButtonFocus() { |
| + window.addEventListener('keyup', function() { |
|
EhsanK
2017/01/25 17:57:58
Could you please add a short comment about why we
avallee
2017/01/25 18:50:18
Without the check non-oopif would double/early-ack
EhsanK
2017/01/25 19:31:37
Thanks!
|
| + if (isOopif || document.activeElement !== getWebView()) { |
| + chrome.test.sendMessage('WebViewInteractiveTest.KeyUp'); |
| + } |
| + }); |
| + window.addEventListener('message', function(e) { |
| + if (e.data === 'guest-keyup') { |
| + chrome.test.sendMessage('WebViewInteractiveTest.KeyUp'); |
| + } |
| + else if (e.data === 'focus-event') { |
| + webViewButtonFocused = true; |
| + } else { |
| + if (webviewReplyCallback) { |
| + var temp = webviewReplyCallback; |
| + webviewReplyCallback = null; |
| + temp(e.data); |
| + } |
| + } |
| + }); |
| +} |
| function setUpWebView(embedder) { |
| var webview = document.createElement('webview'); |
| @@ -9,7 +38,15 @@ function setUpWebView(embedder) { |
| var url = 'http://localhost:' + config.testServer.port |
| + '/extensions/platform_apps/web_view/focus_visibility/guest.html'; |
| webview.onloadstop = function() { |
| - chrome.test.sendMessage('WebViewInteractiveTest.WebViewInitialized'); |
| + function callback(e) { |
| + if (e.data === 'connected') { |
| + e.stopImmediatePropagation(); |
| + window.removeEventListener('message', callback); |
| + chrome.test.sendMessage('WebViewInteractiveTest.WebViewInitialized'); |
| + } |
| + }; |
| + window.addEventListener('message', callback); |
| + getWebView().contentWindow.postMessage('connect', '*'); |
| }; |
| webview.src = url; |
| console.log('Setting URL to "' + url + '".'); |
| @@ -18,17 +55,12 @@ function setUpWebView(embedder) { |
| function reset() { |
| getWebView().style.visibility = 'visible'; |
| - document.querySelector('button').focus(); |
| - webViewButtonReceivedFocus = false; |
| + document.querySelector('#before').focus(); |
| } |
| function sendMessageToWebViewAndReceiveReply(message, replyCallback) { |
| - function callback(e) { |
| - window.removeEventListener('message', callback); |
| - replyCallback(e.data); |
| - } |
| if (replyCallback) { |
| - window.addEventListener('message', callback); |
| + webviewReplyCallback = replyCallback; |
| } |
| getWebView().contentWindow.postMessage(message, '*'); |
| } |
| @@ -39,21 +71,27 @@ function getWebView() { |
| window.onAppMessage = function(command) { |
| switch (command) { |
| + case 'init-oopif': |
| + isOopif = true; |
| + // fallthrough |
| case 'init': |
| + listenForForKeyupAndButtonFocus(); |
| + document.querySelector('#before').focus(); |
| setUpWebView(document.querySelector('div')); |
| break; |
| case 'reset': |
| reset(); |
| - sendMessageToWebViewAndReceiveReply("reset", function() { |
| - chrome.test.sendMessage('WebViewInteractiveTest.DidReset'); |
| + sendMessageToWebViewAndReceiveReply("reset", function(reply) { |
| + if (reply === 'reset-complete') { |
| + webViewButtonFocused = false; |
| + chrome.test.sendMessage('WebViewInteractiveTest.DidReset'); |
| + } |
| }); |
| break; |
| case 'verify': |
| - sendMessageToWebViewAndReceiveReply('verify', function(result) { |
| - chrome.test.sendMessage(result === 'was-focused' ? |
| - 'WebViewInteractiveTest.WebViewButtonWasFocused' : |
| - 'WebViewInteractiveTest.WebViewButtonWasNotFocused'); |
| - }); |
| + chrome.test.sendMessage(webViewButtonFocused ? |
| + 'WebViewInteractiveTest.WebViewButtonWasFocused' : |
| + 'WebViewInteractiveTest.WebViewButtonWasNotFocused'); |
| break; |
| case 'hide-webview': |
| getWebView().style.visibility = 'hidden'; |