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

Side by Side Diff: chrome/browser/apps/guest_view/web_view_browsertest.cc

Issue 1308273003: Resend unconsumed scroll update from guest back to embedder (WebView Scroll Bubble). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove GestureEventObserver now that we don't forward fling GestureScrollUpdates. Created 5 years, 3 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 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/process/process.h" 9 #include "base/process/process.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 19 matching lines...) Expand all
30 #include "components/content_settings/core/browser/host_content_settings_map.h" 30 #include "components/content_settings/core/browser/host_content_settings_map.h"
31 #include "components/guest_view/browser/guest_view_manager.h" 31 #include "components/guest_view/browser/guest_view_manager.h"
32 #include "components/guest_view/browser/guest_view_manager_delegate.h" 32 #include "components/guest_view/browser/guest_view_manager_delegate.h"
33 #include "components/guest_view/browser/guest_view_manager_factory.h" 33 #include "components/guest_view/browser/guest_view_manager_factory.h"
34 #include "components/guest_view/browser/test_guest_view_manager.h" 34 #include "components/guest_view/browser/test_guest_view_manager.h"
35 #include "content/public/browser/gpu_data_manager.h" 35 #include "content/public/browser/gpu_data_manager.h"
36 #include "content/public/browser/interstitial_page.h" 36 #include "content/public/browser/interstitial_page.h"
37 #include "content/public/browser/interstitial_page_delegate.h" 37 #include "content/public/browser/interstitial_page_delegate.h"
38 #include "content/public/browser/notification_service.h" 38 #include "content/public/browser/notification_service.h"
39 #include "content/public/browser/render_process_host.h" 39 #include "content/public/browser/render_process_host.h"
40 #include "content/public/browser/render_widget_host_view.h"
40 #include "content/public/browser/web_contents_delegate.h" 41 #include "content/public/browser/web_contents_delegate.h"
41 #include "content/public/common/child_process_host.h" 42 #include "content/public/common/child_process_host.h"
42 #include "content/public/common/content_switches.h" 43 #include "content/public/common/content_switches.h"
43 #include "content/public/test/browser_test_utils.h" 44 #include "content/public/test/browser_test_utils.h"
44 #include "content/public/test/fake_speech_recognition_manager.h" 45 #include "content/public/test/fake_speech_recognition_manager.h"
45 #include "content/public/test/test_renderer_host.h" 46 #include "content/public/test/test_renderer_host.h"
46 #include "extensions/browser/api/declarative/rules_registry.h" 47 #include "extensions/browser/api/declarative/rules_registry.h"
47 #include "extensions/browser/api/declarative/rules_registry_service.h" 48 #include "extensions/browser/api/declarative/rules_registry_service.h"
48 #include "extensions/browser/api/declarative/test_rules_registry.h" 49 #include "extensions/browser/api/declarative/test_rules_registry.h"
49 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" 50 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
50 #include "extensions/browser/api/extensions_api_client.h" 51 #include "extensions/browser/api/extensions_api_client.h"
51 #include "extensions/browser/app_window/native_app_window.h" 52 #include "extensions/browser/app_window/native_app_window.h"
52 #include "extensions/browser/guest_view/web_view/web_view_guest.h" 53 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
53 #include "extensions/common/extension.h" 54 #include "extensions/common/extension.h"
54 #include "extensions/common/extensions_client.h" 55 #include "extensions/common/extensions_client.h"
55 #include "extensions/test/extension_test_message_listener.h" 56 #include "extensions/test/extension_test_message_listener.h"
56 #include "media/base/media_switches.h" 57 #include "media/base/media_switches.h"
57 #include "net/test/embedded_test_server/embedded_test_server.h" 58 #include "net/test/embedded_test_server/embedded_test_server.h"
58 #include "net/test/embedded_test_server/http_request.h" 59 #include "net/test/embedded_test_server/http_request.h"
59 #include "net/test/embedded_test_server/http_response.h" 60 #include "net/test/embedded_test_server/http_response.h"
60 #include "ui/aura/window.h" 61 #include "ui/aura/window.h"
61 #include "ui/base/l10n/l10n_util.h" 62 #include "ui/base/l10n/l10n_util.h"
62 #include "ui/compositor/compositor.h" 63 #include "ui/compositor/compositor.h"
63 #include "ui/compositor/compositor_observer.h" 64 #include "ui/compositor/compositor_observer.h"
64 #include "ui/events/event_switches.h" 65 #include "ui/events/event_switches.h"
66 #include "ui/events/gesture_detection/gesture_provider_config_helper.h"
67 #include "ui/events/test/event_generator.h"
65 #include "ui/gfx/switches.h" 68 #include "ui/gfx/switches.h"
66 #include "ui/gl/gl_switches.h" 69 #include "ui/gl/gl_switches.h"
67 #include "ui/views/view.h" 70 #include "ui/views/view.h"
68 #include "ui/views/widget/widget.h" 71 #include "ui/views/widget/widget.h"
69 72
70 #if defined(ENABLE_PLUGINS) 73 #if defined(ENABLE_PLUGINS)
71 #include "content/public/browser/plugin_service.h" 74 #include "content/public/browser/plugin_service.h"
72 #include "content/public/common/webplugininfo.h" 75 #include "content/public/common/webplugininfo.h"
73 #include "content/public/test/ppapi_test_utils.h" 76 #include "content/public/test/ppapi_test_utils.h"
74 #endif 77 #endif
(...skipping 2445 matching lines...) Expand 10 before | Expand all | Expand 10 after
2520 "web_view/shim", NEEDS_TEST_SERVER); 2523 "web_view/shim", NEEDS_TEST_SERVER);
2521 } 2524 }
2522 2525
2523 // Tests that a WebView accessible resource can actually be loaded from a 2526 // Tests that a WebView accessible resource can actually be loaded from a
2524 // webpage in a WebView. 2527 // webpage in a WebView.
2525 IN_PROC_BROWSER_TEST_F(WebViewTest, LoadWebviewAccessibleResource) { 2528 IN_PROC_BROWSER_TEST_F(WebViewTest, LoadWebviewAccessibleResource) {
2526 TestHelper("testLoadWebviewAccessibleResource", 2529 TestHelper("testLoadWebviewAccessibleResource",
2527 "web_view/load_webview_accessible_resource", NEEDS_TEST_SERVER); 2530 "web_view/load_webview_accessible_resource", NEEDS_TEST_SERVER);
2528 } 2531 }
2529 2532
2533 class WebViewTouchTest : public WebViewTest {
2534 protected:
2535 void SetUpCommandLine(base::CommandLine* command_line) override {
2536 command_line->AppendSwitchASCII(switches::kTouchEvents,
2537 switches::kTouchEventsEnabled);
2538
2539 WebViewTest::SetUpCommandLine(command_line);
2540 }
2541 };
2542
2543 namespace {
2544
2545 class ScrollWaiter {
2546 public:
2547 explicit ScrollWaiter(content::RenderWidgetHostView* host_view)
2548 : host_view_(host_view),
2549 current_offset_(host_view_->GetLastScrollOffset()) {}
2550 ~ScrollWaiter() {}
2551
2552 void WaitForScrollChange() {
2553 while (current_offset_ == host_view_->GetLastScrollOffset())
2554 base::MessageLoop::current()->RunUntilIdle();
2555 }
2556
2557 private:
2558 content::RenderWidgetHostView* host_view_;
2559 gfx::Vector2dF current_offset_;
2560 };
2561
2562 } // namespace
2563
2564 // Tests that scrolls bubble from guest to embedder.
2565 IN_PROC_BROWSER_TEST_F(WebViewTest, TestGuestWheelScrollsBubble) {
2566 LoadAppWithGuest("web_view/scrollable_embedder_and_guest");
2567
2568 content::WebContents* embedder_contents = GetEmbedderWebContents();
2569
2570 std::vector<content::WebContents*> guest_web_contents_list;
2571 GetGuestViewManager()->WaitForNumGuestsCreated(1u);
2572 GetGuestViewManager()->GetGuestWebContentsList(&guest_web_contents_list);
2573 ASSERT_EQ(1u, guest_web_contents_list.size());
2574
2575 content::WebContents* guest_contents = guest_web_contents_list[0];
2576
2577
2578 // Send scroll gesture to embedder & verify.
2579 content::RenderWidgetHostView* embedder_host_view =
2580 embedder_contents->GetRenderWidgetHostView();
2581 EXPECT_EQ(gfx::Vector2dF(), embedder_host_view->GetLastScrollOffset());
2582
2583 float scroll_magnitude = 15.f;
2584
2585 {
2586 gfx::Point embedder_scroll_start(200, 40 + scroll_magnitude);
2587 gfx::Point embedder_scroll_end(200, 40);
2588 gfx::Vector2dF expected_offset(0.f, scroll_magnitude);
2589
2590 ScrollWaiter waiter(embedder_host_view);
2591
2592 ui::test::EventGenerator generator(
2593 embedder_contents->GetTopLevelNativeWindow(), embedder_scroll_start);
2594 generator.MoveMouseToInHost(embedder_scroll_start);
2595 generator.MoveMouseWheel(0, -scroll_magnitude);
2596 waiter.WaitForScrollChange();
2597 EXPECT_EQ(expected_offset, embedder_host_view->GetLastScrollOffset());
2598 }
2599
2600 content::RenderWidgetHostView* guest_host_view =
2601 guest_contents->GetRenderWidgetHostView();
2602 EXPECT_EQ(gfx::Vector2dF(), guest_host_view->GetLastScrollOffset());
2603
2604 // Send scroll gesture to guest and verify embedder scrolls.
2605 // Perform a scroll gesture of the same magnitude, but in the opposite
2606 // direction and centered over the GuestView this time.
2607 {
2608 gfx::Point guest_scroll_start(200, 120);
2609 gfx::Point guest_scroll_end(200, 120 + scroll_magnitude);
2610 ScrollWaiter waiter(embedder_host_view);
2611
2612 ui::test::EventGenerator generator(
2613 embedder_contents->GetTopLevelNativeWindow(), guest_scroll_start);
2614 generator.MoveMouseToInHost(guest_scroll_start);
2615 generator.MoveMouseWheel(0, scroll_magnitude);
2616
2617 waiter.WaitForScrollChange();
2618 EXPECT_EQ(gfx::Vector2dF(), embedder_host_view->GetLastScrollOffset());
2619 }
2620 }
2621
2622 IN_PROC_BROWSER_TEST_F(WebViewTouchTest, TestGuestGestureScrollsBubble) {
2623 LoadAppWithGuest("web_view/scrollable_embedder_and_guest");
2624
2625 content::WebContents* embedder_contents = GetEmbedderWebContents();
2626
2627 std::vector<content::WebContents*> guest_web_contents_list;
2628 GetGuestViewManager()->WaitForNumGuestsCreated(1u);
2629 GetGuestViewManager()->GetGuestWebContentsList(&guest_web_contents_list);
2630 ASSERT_EQ(1u, guest_web_contents_list.size());
2631
2632 content::WebContents* guest_contents = guest_web_contents_list[0];
2633
2634 // Send scroll gesture to embedder & verify.
2635 content::RenderWidgetHostView* embedder_host_view =
2636 embedder_contents->GetRenderWidgetHostView();
2637 EXPECT_EQ(gfx::Vector2dF(), embedder_host_view->GetLastScrollOffset());
2638
2639 float touch_slop = ui::GetGestureProviderConfig(
2640 ui::GestureProviderConfigType::CURRENT_PLATFORM)
2641 .gesture_detector_config.touch_slop;
2642 float scroll_magnitude = 15.f;
2643 float gesture_distance = scroll_magnitude + touch_slop;
2644
2645 {
2646 gfx::Point embedder_scroll_start(200, 40 + gesture_distance);
2647 gfx::Point embedder_scroll_end(200, 40);
2648 gfx::Vector2dF expected_offset(0.f, scroll_magnitude);
2649
2650 ScrollWaiter waiter(embedder_host_view);
2651
2652 ui::test::EventGenerator generator(
2653 embedder_contents->GetTopLevelNativeWindow(), embedder_scroll_start);
2654 generator.GestureScrollSequence(embedder_scroll_start, embedder_scroll_end,
2655 base::TimeDelta::FromMilliseconds(100), 1);
2656 waiter.WaitForScrollChange();
2657 EXPECT_EQ(expected_offset, embedder_host_view->GetLastScrollOffset());
2658 }
2659
2660 content::RenderWidgetHostView* guest_host_view =
2661 guest_contents->GetRenderWidgetHostView();
2662 EXPECT_EQ(gfx::Vector2dF(), guest_host_view->GetLastScrollOffset());
2663
2664 // Send scroll gesture to guest and verify embedder scrolls.
2665 // Perform a scroll gesture of the same magnitude, but in the opposite
2666 // direction and centered over the GuestView this time.
2667 {
2668 gfx::Point guest_scroll_start(200, 120);
2669 gfx::Point guest_scroll_end(200, 120 + gesture_distance);
2670 ScrollWaiter waiter(embedder_host_view);
2671
2672 ui::test::EventGenerator generator(
2673 embedder_contents->GetTopLevelNativeWindow(), guest_scroll_start);
2674 generator.GestureScrollSequence(guest_scroll_start, guest_scroll_end,
2675 base::TimeDelta::FromMilliseconds(100), 1);
2676
2677 waiter.WaitForScrollChange();
2678 EXPECT_EQ(gfx::Vector2dF(), embedder_host_view->GetLastScrollOffset());
2679 }
2680 }
2681
2530 #if defined(USE_AURA) 2682 #if defined(USE_AURA)
2531 // TODO(wjmaclean): when WebViewTest is re-enabled on the site-isolation 2683 // TODO(wjmaclean): when WebViewTest is re-enabled on the site-isolation
2532 // bots, then re-enable this test class as well. 2684 // bots, then re-enable this test class as well.
2533 // https://crbug.com/503751 2685 // https://crbug.com/503751
2534 class WebViewFocusTest : public WebViewTest { 2686 class WebViewFocusTest : public WebViewTest {
2535 public: 2687 public:
2536 ~WebViewFocusTest() override {} 2688 ~WebViewFocusTest() override {}
2537 2689
2538 void SetUpCommandLine(base::CommandLine* command_line) override { 2690 void SetUpCommandLine(base::CommandLine* command_line) override {
2539 WebViewTest::SetUpCommandLine(command_line); 2691 WebViewTest::SetUpCommandLine(command_line);
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
2746 const task_management::Task* task = task_manager.tasks().back(); 2898 const task_management::Task* task = task_manager.tasks().back();
2747 EXPECT_EQ(task_management::Task::GUEST, task->GetType()); 2899 EXPECT_EQ(task_management::Task::GUEST, task->GetType());
2748 const base::string16 title = task->title(); 2900 const base::string16 title = task->title();
2749 const base::string16 expected_prefix = GetExpectedPrefix(guest_contents); 2901 const base::string16 expected_prefix = GetExpectedPrefix(guest_contents);
2750 EXPECT_TRUE(base::StartsWith(title, 2902 EXPECT_TRUE(base::StartsWith(title,
2751 expected_prefix, 2903 expected_prefix,
2752 base::CompareCase::INSENSITIVE_ASCII)); 2904 base::CompareCase::INSENSITIVE_ASCII));
2753 } 2905 }
2754 2906
2755 #endif // defined(ENABLE_TASK_MANAGER) 2907 #endif // defined(ENABLE_TASK_MANAGER)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698