Index: chrome/browser/apps/guest_view/web_view_browsertest.cc |
diff --git a/chrome/browser/apps/guest_view/web_view_browsertest.cc b/chrome/browser/apps/guest_view/web_view_browsertest.cc |
index 9dc906ce740d031bb3f5781cbcb7011c4dc9925d..fde0ce8a89ea4b0f6912d78c5d2995ff82d187c4 100644 |
--- a/chrome/browser/apps/guest_view/web_view_browsertest.cc |
+++ b/chrome/browser/apps/guest_view/web_view_browsertest.cc |
@@ -2,6 +2,8 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include <queue> |
+ |
#include "base/location.h" |
#include "base/path_service.h" |
#include "base/process/process.h" |
@@ -27,6 +29,8 @@ |
#include "components/guest_view/browser/guest_view_manager.h" |
#include "components/guest_view/browser/guest_view_manager_factory.h" |
#include "components/guest_view/browser/test_guest_view_manager.h" |
+#include "content/browser/renderer_host/render_widget_host_impl.h" |
+#include "content/common/input/synthetic_web_input_event_builders.h" |
#include "content/public/browser/gpu_data_manager.h" |
#include "content/public/browser/interstitial_page.h" |
#include "content/public/browser/interstitial_page_delegate.h" |
@@ -52,8 +56,11 @@ |
#include "net/test/embedded_test_server/embedded_test_server.h" |
#include "net/test/embedded_test_server/http_request.h" |
#include "net/test/embedded_test_server/http_response.h" |
+#include "ui/aura/window.h" |
#include "ui/gfx/switches.h" |
#include "ui/gl/gl_switches.h" |
+#include "ui/views/view.h" |
+#include "ui/views/widget/widget.h" |
#if defined(ENABLE_PLUGINS) |
#include "content/public/browser/plugin_service.h" |
@@ -206,6 +213,30 @@ void ExecuteScriptWaitForTitle(content::WebContents* web_contents, |
EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
} |
+void GiveItSomeTime(int ms) { |
+ base::RunLoop run_loop; |
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
+ FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromMilliseconds(ms)); |
+ run_loop.Run(); |
+} |
+ |
+views::View* FindWebView(views::View* v) { |
+ std::queue<views::View*> queue; |
+ queue.push(v); |
+ while (!queue.empty()) { |
+ views::View* current = queue.front(); |
+ queue.pop(); |
+ if (std::string(current->GetClassName()).find("WebView") != |
+ std::string::npos) { |
+ return current; |
+ } |
+ |
+ for (int i = 0; i < current->child_count(); ++i) |
+ queue.push(current->child_at(i)); |
+ } |
+ return nullptr; |
+} |
+ |
} // namespace |
// This class intercepts media access request from the embedder. The request |
@@ -2372,3 +2403,69 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestGarbageCollect) { |
TestHelper("testGarbageCollect", "web_view/shim", NO_TEST_SERVER); |
GetGuestViewManager()->WaitForSingleViewGarbageCollected(); |
} |
+ |
+typedef WebViewTest WebViewFocusTest; |
wjmaclean
2015/06/18 18:37:48
I just realized, these needs to be in a
#if defi
|
+ |
+// The following test verifies that a views::WebView hosting an embedder |
+// gains focus on touchstart. |
+IN_PROC_BROWSER_TEST_F(WebViewFocusTest, TouchFocusesEmbedder) { |
+ LoadAppWithGuest("web_view/accept_touch_events"); |
+ |
+ content::WebContents* web_contents = GetEmbedderWebContents(); |
+ content::RenderViewHost* embedder_rvh = web_contents->GetRenderViewHost(); |
+ |
+ bool embedder_has_touch_handler = |
+ content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh); |
+ EXPECT_FALSE(embedder_has_touch_handler); |
+ |
+ SendMessageToGuestAndWait("install-touch-handler", "installed-touch-handler"); |
+ |
+ // Note that we need to wait for the installed/registered touch handler to |
+ // appear in browser process before querying |embedder_rvh|. |
+ // In practice, since we do a roundrtip from browser process to guest and |
+ // back, this is sufficient. |
+ embedder_has_touch_handler = |
+ content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh); |
+ EXPECT_TRUE(embedder_has_touch_handler); |
+ |
+ extensions::AppWindow* app_window = GetFirstAppWindowForBrowser(browser()); |
+ aura::Window* window = app_window->GetNativeWindow(); |
+ EXPECT_TRUE(app_window); |
+ EXPECT_TRUE(window); |
+ views::Widget* widget = views::Widget::GetWidgetForNativeView(window); |
+ EXPECT_TRUE(widget->GetRootView()); |
+ // We only expect a single views::webview in the view hierarchy. |
+ views::View* aura_webview = FindWebView(widget->GetRootView()); |
+ ASSERT_TRUE(aura_webview); |
+ gfx::Rect bounds(aura_webview->bounds()); |
+ EXPECT_TRUE(aura_webview->IsFocusable()); |
+ |
+ views::View* padding_view = new views::View(); |
+ padding_view->SetBounds(bounds.x() + bounds.width(), 0, 100, 100); |
+ padding_view->SetFocusable(true); |
+ aura_webview->parent()->AddChildView(padding_view); |
+ padding_view->SetPosition(gfx::Point(bounds.x() + bounds.width(), 0)); |
+ |
+ EXPECT_TRUE(aura_webview->HasFocus()); |
+ padding_view->RequestFocus(); |
+ EXPECT_TRUE(padding_view->HasFocus()); |
+ EXPECT_FALSE(aura_webview->HasFocus()); |
+ |
+ // We'll give this a fairly long delay, as the cost otherwise is having the |
+ // test timeout. |
+ GiveItSomeTime(100 /* milliseconds */); |
wjmaclean
2015/06/18 18:37:48
I'll add a bug number to explain this.
|
+ |
+ // Generate and send synthetic touch event. |
+ content::SyntheticWebTouchEvent touch; |
+ // TODO(wjmaclean): This is fragile ... if anyone alters the location/size |
+ // of the webview in accept_touch_events then this may miss its target. |
+ touch.PressPoint(10, 10); |
+ content::RenderWidgetHostImpl* widget_host = |
+ content::RenderWidgetHostImpl::From(web_contents->GetRenderViewHost()); |
+ widget_host->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); |
+ |
+ // Wait for the TouchStart to propagate and restore focus. Test times out |
+ // on failure. |
+ while (!aura_webview->HasFocus()) |
+ base::MessageLoop::current()->RunUntilIdle(); |
+} |