Index: chrome/test/data/extensions/platform_apps/web_view/focus/inject_focus_take_focus.js |
diff --git a/chrome/test/data/extensions/platform_apps/web_view/focus/inject_focus_take_focus.js b/chrome/test/data/extensions/platform_apps/web_view/focus/inject_focus_take_focus.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f8c653e7ba7a4cc8d56cca439112a5a2ec73a0e3 |
--- /dev/null |
+++ b/chrome/test/data/extensions/platform_apps/web_view/focus/inject_focus_take_focus.js |
@@ -0,0 +1,41 @@ |
+// Copyright 2017 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. |
+ |
+var embedder = null; |
+ |
+var LOG = function(msg) { |
+ window.console.log(msg); |
+}; |
+ |
+var sendMessage = function(msgArray) { |
+ if (embedder) { |
+ embedder.postMessage(JSON.stringify(msgArray), '*'); |
+ } |
+}; |
+ |
+var init = function() { |
+ var input = document.createElement('input'); |
+ input.style.width = '100%'; |
+ input.addEventListener('focus', function(e) { |
+ sendMessage(['focused']); |
+ }); |
+ |
+ document.body.appendChild(input); |
+ |
+ window.addEventListener('message', function(e) { |
+ var data = JSON.parse(e.data); |
+ embedder = e.source; |
+ LOG('message, data: ' + data); |
+ if (data[0] == 'connect') { |
+ sendMessage(['connected']); |
+ } else if (data[0] == 'request-coords') { |
+ var rect = input.getBoundingClientRect(); |
+ sendMessage(['response-coords', |
+ rect.left + 0.5 * rect.width, |
+ rect.top + 0.5 * rect.height]); |
+ } |
+ }); |
+}; |
+ |
+init(); |