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

Unified Diff: chrome/browser/apps/guest_view/web_view_browsertest.cc

Issue 2116663002: Test for BrowserPlugin-based WebView Focus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revise surface waiting. Created 4 years, 5 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
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 5cd24d4cde654f215d2607f88e736b488591f8a7..b7a9c9fcb3a14bc66fb753ed3d561f129ed51104 100644
--- a/chrome/browser/apps/guest_view/web_view_browsertest.cc
+++ b/chrome/browser/apps/guest_view/web_view_browsertest.cc
@@ -3340,6 +3340,95 @@ INSTANTIATE_TEST_CASE_P(WebViewScrollBubbling,
WebViewGuestScrollTouchTest,
testing::Combine(testing::Bool(), testing::Bool()));
+#if defined(USE_AURA)
+class WebViewGuestTouchFocusTest : public WebViewTestBase {
+ public:
+ WebViewGuestTouchFocusTest() {}
+ void SetUpCommandLine(base::CommandLine* command_line) override {
+ WebViewTestBase::SetUpCommandLine(command_line);
+
+ command_line->AppendSwitchASCII(switches::kTouchEvents,
+ switches::kTouchEventsEnabled);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(WebViewGuestTouchFocusTest);
+};
+
+class FocusChangeWaiter {
+ public:
+ explicit FocusChangeWaiter(content::WebContents* web_contents,
+ bool expected_focus)
+ : web_contents_(web_contents), expected_focus_(expected_focus) {}
+ ~FocusChangeWaiter() {}
+
+ void WaitForFocusChange() {
+ while (expected_focus_ !=
+ IsWebContentsBrowserPluginFocused(web_contents_)) {
+ base::RunLoop().RunUntilIdle();
+ }
+ }
+
+ private:
+ content::WebContents* web_contents_;
+ bool expected_focus_;
+};
+
+IN_PROC_BROWSER_TEST_F(WebViewGuestTouchFocusTest,
+ TouchFocusesBrowserPluginInEmbedder) {
+ // This test is only relevant for non-OOPIF WebView.
+ if (content::BrowserPluginGuestMode::UseCrossProcessFramesForGuests())
+ return;
+
+ LoadAppWithGuest("web_view/guest_focus_test");
+
+ // Lookup relevant information about guest and embedder.
+ content::WebContents* embedder_contents = GetEmbedderWebContents();
+
+ std::vector<content::WebContents*> guest_web_contents_list;
+ GetGuestViewManager()->WaitForNumGuestsCreated(1u);
+ GetGuestViewManager()->GetGuestWebContentsList(&guest_web_contents_list);
+ ASSERT_EQ(1u, guest_web_contents_list.size());
+
+ content::WebContents* guest_contents = guest_web_contents_list[0];
+
+ gfx::Rect embedder_rect = embedder_contents->GetContainerBounds();
+ gfx::Rect guest_rect = guest_contents->GetContainerBounds();
+
+ guest_rect.set_x(guest_rect.x() - embedder_rect.x());
+ guest_rect.set_y(guest_rect.y() - embedder_rect.y());
+ embedder_rect.set_x(0);
+ embedder_rect.set_y(0);
+
+ // Don't send events that need to be routed until we know the child's surface
+ // is ready for hit testing.
+ WaitForGuestSurfaceReady(guest_contents);
+
+ // 1) BrowserPlugin should not be focused at start.
+ EXPECT_FALSE(IsWebContentsBrowserPluginFocused(guest_contents));
+
+ // 2) Send touch event to guest, now BrowserPlugin should get focus.
+ {
+ gfx::Point point = guest_rect.CenterPoint();
+ FocusChangeWaiter focus_waiter(guest_contents, true);
+ SendRoutedTouchTapSequence(embedder_contents, point);
+ SendRoutedGestureTapSequence(embedder_contents, point);
+ focus_waiter.WaitForFocusChange();
+ EXPECT_TRUE(IsWebContentsBrowserPluginFocused(guest_contents));
+ }
+
+ // 3) Send touch start to embedder, now BrowserPlugin should lose focus.
+ {
+ gfx::Point point(10, 10);
+ FocusChangeWaiter focus_waiter(guest_contents, false);
+ SendRoutedTouchTapSequence(embedder_contents, point);
+ SendRoutedGestureTapSequence(embedder_contents,point);
+ focus_waiter.WaitForFocusChange();
+ EXPECT_FALSE(IsWebContentsBrowserPluginFocused(guest_contents));
+ }
+}
+#endif
+
IN_PROC_BROWSER_TEST_P(WebViewGuestScrollTouchTest,
TestGuestGestureScrollsBubble) {
// Just in case we're running ChromeOS tests, we need to make sure the

Powered by Google App Engine
This is Rietveld 408576698