| OLD | NEW |
| 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 2778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2789 base::TimeDelta::FromMilliseconds(10)); | 2789 base::TimeDelta::FromMilliseconds(10)); |
| 2790 run_loop.Run(); | 2790 run_loop.Run(); |
| 2791 } | 2791 } |
| 2792 frame_watcher_->WaitFrames(1); | 2792 frame_watcher_->WaitFrames(1); |
| 2793 } | 2793 } |
| 2794 | 2794 |
| 2795 private: | 2795 private: |
| 2796 scoped_refptr<content::FrameWatcher> frame_watcher_; | 2796 scoped_refptr<content::FrameWatcher> frame_watcher_; |
| 2797 }; | 2797 }; |
| 2798 | 2798 |
| 2799 class FocusWaiter : public views::FocusChangeListener { | |
| 2800 public: | |
| 2801 explicit FocusWaiter(views::View* view_to_wait_for) | |
| 2802 : view_to_wait_for_(view_to_wait_for) { | |
| 2803 view_to_wait_for_->GetFocusManager()->AddFocusChangeListener(this); | |
| 2804 } | |
| 2805 ~FocusWaiter() override { | |
| 2806 view_to_wait_for_->GetFocusManager()->RemoveFocusChangeListener(this); | |
| 2807 } | |
| 2808 | |
| 2809 void Wait() { | |
| 2810 if (view_to_wait_for_->HasFocus()) | |
| 2811 return; | |
| 2812 | |
| 2813 base::MessageLoop::current()->Run(); | |
| 2814 } | |
| 2815 | |
| 2816 // FocusChangeListener implementation. | |
| 2817 void OnWillChangeFocus(views::View* focused_before, | |
| 2818 views::View* focused_now) override {} | |
| 2819 void OnDidChangeFocus(views::View* focused_before, | |
| 2820 views::View* focused_now) override { | |
| 2821 if (view_to_wait_for_ == focused_now) | |
| 2822 base::MessageLoop::current()->QuitWhenIdle(); | |
| 2823 } | |
| 2824 | |
| 2825 private: | |
| 2826 views::View* view_to_wait_for_; | |
| 2827 | |
| 2828 DISALLOW_COPY_AND_ASSIGN(FocusWaiter); | |
| 2829 }; | |
| 2830 | |
| 2831 // The following test verifies that a views::WebView hosting an embedder | 2799 // The following test verifies that a views::WebView hosting an embedder |
| 2832 // gains focus on touchstart. | 2800 // gains focus on touchstart. |
| 2833 IN_PROC_BROWSER_TEST_F(WebViewFocusTest, TouchFocusesEmbedder) { | 2801 IN_PROC_BROWSER_TEST_F(WebViewFocusTest, TouchFocusesEmbedder) { |
| 2834 LoadAppWithGuest("web_view/accept_touch_events"); | 2802 LoadAppWithGuest("web_view/accept_touch_events"); |
| 2835 | 2803 |
| 2836 content::WebContents* web_contents = GetEmbedderWebContents(); | 2804 content::WebContents* web_contents = GetEmbedderWebContents(); |
| 2837 content::RenderViewHost* embedder_rvh = web_contents->GetRenderViewHost(); | 2805 content::RenderViewHost* embedder_rvh = web_contents->GetRenderViewHost(); |
| 2838 | 2806 |
| 2839 bool embedder_has_touch_handler = | 2807 bool embedder_has_touch_handler = |
| 2840 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh); | 2808 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2880 EXPECT_FALSE(aura_webview->HasFocus()); | 2848 EXPECT_FALSE(aura_webview->HasFocus()); |
| 2881 | 2849 |
| 2882 // Compute location of guest within embedder so we can more accurately | 2850 // Compute location of guest within embedder so we can more accurately |
| 2883 // target our touch event. | 2851 // target our touch event. |
| 2884 gfx::Rect guest_rect = GetGuestWebContents()->GetContainerBounds(); | 2852 gfx::Rect guest_rect = GetGuestWebContents()->GetContainerBounds(); |
| 2885 gfx::Point embedder_origin = | 2853 gfx::Point embedder_origin = |
| 2886 GetEmbedderWebContents()->GetContainerBounds().origin(); | 2854 GetEmbedderWebContents()->GetContainerBounds().origin(); |
| 2887 guest_rect.Offset(-embedder_origin.x(), -embedder_origin.y()); | 2855 guest_rect.Offset(-embedder_origin.x(), -embedder_origin.y()); |
| 2888 | 2856 |
| 2889 // Generate and send synthetic touch event. | 2857 // Generate and send synthetic touch event. |
| 2890 FocusWaiter waiter(aura_webview); | |
| 2891 content::SimulateTouchPressAt(GetEmbedderWebContents(), | 2858 content::SimulateTouchPressAt(GetEmbedderWebContents(), |
| 2892 guest_rect.CenterPoint()); | 2859 guest_rect.CenterPoint()); |
| 2893 | 2860 EXPECT_TRUE(aura_webview->HasFocus()); |
| 2894 // Wait for the TouchStart to propagate and restore focus. Test times out | |
| 2895 // on failure. | |
| 2896 waiter.Wait(); | |
| 2897 } | 2861 } |
| 2898 #endif | 2862 #endif |
| 2899 | 2863 |
| 2900 #if defined(ENABLE_TASK_MANAGER) | 2864 #if defined(ENABLE_TASK_MANAGER) |
| 2901 | 2865 |
| 2902 namespace { | 2866 namespace { |
| 2903 | 2867 |
| 2904 base::string16 GetExpectedPrefix(content::WebContents* web_contents) { | 2868 base::string16 GetExpectedPrefix(content::WebContents* web_contents) { |
| 2905 DCHECK(web_contents); | 2869 DCHECK(web_contents); |
| 2906 guest_view::GuestViewBase* guest = | 2870 guest_view::GuestViewBase* guest = |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2981 // 4 tasks expected. The order is arbitrary. | 2945 // 4 tasks expected. The order is arbitrary. |
| 2982 // Tab: about:blank, | 2946 // Tab: about:blank, |
| 2983 // Background Page: <webview> task manager test, | 2947 // Background Page: <webview> task manager test, |
| 2984 // App: <webview> task manager test, | 2948 // App: <webview> task manager test, |
| 2985 // Webview: WebViewed test content. | 2949 // Webview: WebViewed test content. |
| 2986 EXPECT_EQ(4U, task_manager.tasks().size()); | 2950 EXPECT_EQ(4U, task_manager.tasks().size()); |
| 2987 EXPECT_TRUE(HasExpectedGuestTask(task_manager, guest_contents)); | 2951 EXPECT_TRUE(HasExpectedGuestTask(task_manager, guest_contents)); |
| 2988 } | 2952 } |
| 2989 | 2953 |
| 2990 #endif // defined(ENABLE_TASK_MANAGER) | 2954 #endif // defined(ENABLE_TASK_MANAGER) |
| OLD | NEW |