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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <queue> 5 #include <queue>
6 #include <set> 6 #include <set>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 3322 matching lines...) Expand 10 before | Expand all | Expand 10 after
3333 gfx::Vector2d(0, scroll_magnitude)); 3333 gfx::Vector2d(0, scroll_magnitude));
3334 3334
3335 waiter.WaitForScrollChange(gfx::Vector2dF()); 3335 waiter.WaitForScrollChange(gfx::Vector2dF());
3336 } 3336 }
3337 } 3337 }
3338 3338
3339 INSTANTIATE_TEST_CASE_P(WebViewScrollBubbling, 3339 INSTANTIATE_TEST_CASE_P(WebViewScrollBubbling,
3340 WebViewGuestScrollTouchTest, 3340 WebViewGuestScrollTouchTest,
3341 testing::Combine(testing::Bool(), testing::Bool())); 3341 testing::Combine(testing::Bool(), testing::Bool()));
3342 3342
3343 #if defined(USE_AURA)
3344 class WebViewGuestTouchFocusTest : public WebViewTestBase {
3345 public:
3346 WebViewGuestTouchFocusTest() {}
3347 void SetUpCommandLine(base::CommandLine* command_line) override {
3348 WebViewTestBase::SetUpCommandLine(command_line);
3349
3350 command_line->AppendSwitchASCII(switches::kTouchEvents,
3351 switches::kTouchEventsEnabled);
3352 }
3353
3354 private:
3355 DISALLOW_COPY_AND_ASSIGN(WebViewGuestTouchFocusTest);
3356 };
3357
3358 class FocusChangeWaiter {
3359 public:
3360 explicit FocusChangeWaiter(content::WebContents* web_contents,
3361 bool expected_focus)
3362 : web_contents_(web_contents), expected_focus_(expected_focus) {}
3363 ~FocusChangeWaiter() {}
3364
3365 void WaitForFocusChange() {
3366 while (expected_focus_ !=
3367 IsWebContentsBrowserPluginFocused(web_contents_)) {
3368 base::RunLoop().RunUntilIdle();
3369 }
3370 }
3371
3372 private:
3373 content::WebContents* web_contents_;
3374 bool expected_focus_;
3375 };
3376
3377 IN_PROC_BROWSER_TEST_F(WebViewGuestTouchFocusTest,
3378 TouchFocusesBrowserPluginInEmbedder) {
3379 // This test is only relevant for non-OOPIF WebView.
3380 if (content::BrowserPluginGuestMode::UseCrossProcessFramesForGuests())
3381 return;
3382
3383 LoadAppWithGuest("web_view/guest_focus_test");
3384
3385 // Lookup relevant information about guest and embedder.
3386 content::WebContents* embedder_contents = GetEmbedderWebContents();
3387
3388 std::vector<content::WebContents*> guest_web_contents_list;
3389 GetGuestViewManager()->WaitForNumGuestsCreated(1u);
3390 GetGuestViewManager()->GetGuestWebContentsList(&guest_web_contents_list);
3391 ASSERT_EQ(1u, guest_web_contents_list.size());
3392
3393 content::WebContents* guest_contents = guest_web_contents_list[0];
3394
3395 gfx::Rect embedder_rect = embedder_contents->GetContainerBounds();
3396 gfx::Rect guest_rect = guest_contents->GetContainerBounds();
3397
3398 guest_rect.set_x(guest_rect.x() - embedder_rect.x());
3399 guest_rect.set_y(guest_rect.y() - embedder_rect.y());
3400 embedder_rect.set_x(0);
3401 embedder_rect.set_y(0);
3402
3403 // Don't send events that need to be routed until we know the child's surface
3404 // is ready for hit testing.
3405 WaitForGuestSurfaceReady(guest_contents);
3406
3407 // 1) BrowserPlugin should not be focused at start.
3408 EXPECT_FALSE(IsWebContentsBrowserPluginFocused(guest_contents));
3409
3410 // 2) Send touch event to guest, now BrowserPlugin should get focus.
3411 {
3412 gfx::Point point = guest_rect.CenterPoint();
3413 FocusChangeWaiter focus_waiter(guest_contents, true);
3414 SendRoutedTouchTapSequence(embedder_contents, point);
3415 SendRoutedGestureTapSequence(embedder_contents, point);
3416 focus_waiter.WaitForFocusChange();
3417 EXPECT_TRUE(IsWebContentsBrowserPluginFocused(guest_contents));
3418 }
3419
3420 // 3) Send touch start to embedder, now BrowserPlugin should lose focus.
3421 {
3422 gfx::Point point(10, 10);
3423 FocusChangeWaiter focus_waiter(guest_contents, false);
3424 SendRoutedTouchTapSequence(embedder_contents, point);
3425 SendRoutedGestureTapSequence(embedder_contents,point);
3426 focus_waiter.WaitForFocusChange();
3427 EXPECT_FALSE(IsWebContentsBrowserPluginFocused(guest_contents));
3428 }
3429 }
3430 #endif
3431
3343 IN_PROC_BROWSER_TEST_P(WebViewGuestScrollTouchTest, 3432 IN_PROC_BROWSER_TEST_P(WebViewGuestScrollTouchTest,
3344 TestGuestGestureScrollsBubble) { 3433 TestGuestGestureScrollsBubble) {
3345 // Just in case we're running ChromeOS tests, we need to make sure the 3434 // Just in case we're running ChromeOS tests, we need to make sure the
3346 // debounce interval is set to zero so our back-to-back gesture-scrolls don't 3435 // debounce interval is set to zero so our back-to-back gesture-scrolls don't
3347 // get munged together. Since the first scroll will be put on the fast 3436 // get munged together. Since the first scroll will be put on the fast
3348 // (compositor) path, while the second one should always be slow-path so it 3437 // (compositor) path, while the second one should always be slow-path so it
3349 // gets to BrowserPlugin, having them merged is definitely an error. 3438 // gets to BrowserPlugin, having them merged is definitely an error.
3350 ui::GestureConfiguration* gesture_config = 3439 ui::GestureConfiguration* gesture_config =
3351 ui::GestureConfiguration::GetInstance(); 3440 ui::GestureConfiguration::GetInstance();
3352 gesture_config->set_scroll_debounce_interval_in_ms(0); 3441 gesture_config->set_scroll_debounce_interval_in_ms(0);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
3586 gfx::Point embedder_origin = 3675 gfx::Point embedder_origin =
3587 GetEmbedderWebContents()->GetContainerBounds().origin(); 3676 GetEmbedderWebContents()->GetContainerBounds().origin();
3588 guest_rect.Offset(-embedder_origin.x(), -embedder_origin.y()); 3677 guest_rect.Offset(-embedder_origin.x(), -embedder_origin.y());
3589 3678
3590 // Generate and send synthetic touch event. 3679 // Generate and send synthetic touch event.
3591 content::SimulateTouchPressAt(GetEmbedderWebContents(), 3680 content::SimulateTouchPressAt(GetEmbedderWebContents(),
3592 guest_rect.CenterPoint()); 3681 guest_rect.CenterPoint());
3593 EXPECT_TRUE(aura_webview->HasFocus()); 3682 EXPECT_TRUE(aura_webview->HasFocus());
3594 } 3683 }
3595 #endif 3684 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698