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

Unified Diff: chrome/test/data/extensions/platform_apps/web_view/focus_visibility/window.js

Issue 2648263006: <webview>: Synchronize WebViewFocusInteractiveTest.FocusAndVisibility (Closed)
Patch Set: Address ehsank's comments. Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/data/extensions/platform_apps/web_view/focus_visibility/window.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..485ecc82ae5eb5be64c4a23ef4a60619c4837d0c 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,41 @@
// 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() {
+ // With BrowserPlugin <webview> this renderer might see all events targetted
+ // to the <webview> before ultimately forwarding to the <webview>. Suppress
+ // the events once the webview with active.
+ // OTOH in OOPIF-<webiew>, keyup is only ever dispatched to one renderer.
+ // (The keyup that changes focus to the <webview> is sent to the embedder
+ // but activeElement is the <webview> by that point.)
+ 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 +44,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 +61,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 +77,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';
« no previous file with comments | « chrome/test/data/extensions/platform_apps/web_view/focus_visibility/window.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698