| 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 2786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2797 base::TimeDelta::FromMilliseconds(10)); | 2797 base::TimeDelta::FromMilliseconds(10)); |
| 2798 run_loop.Run(); | 2798 run_loop.Run(); |
| 2799 } | 2799 } |
| 2800 frame_watcher_->WaitFrames(1); | 2800 frame_watcher_->WaitFrames(1); |
| 2801 } | 2801 } |
| 2802 | 2802 |
| 2803 private: | 2803 private: |
| 2804 scoped_refptr<content::FrameWatcher> frame_watcher_; | 2804 scoped_refptr<content::FrameWatcher> frame_watcher_; |
| 2805 }; | 2805 }; |
| 2806 | 2806 |
| 2807 class FocusWaiter : public views::FocusChangeListener { | |
| 2808 public: | |
| 2809 explicit FocusWaiter(views::View* view_to_wait_for) | |
| 2810 : view_to_wait_for_(view_to_wait_for) { | |
| 2811 view_to_wait_for_->GetFocusManager()->AddFocusChangeListener(this); | |
| 2812 } | |
| 2813 ~FocusWaiter() override { | |
| 2814 view_to_wait_for_->GetFocusManager()->RemoveFocusChangeListener(this); | |
| 2815 } | |
| 2816 | |
| 2817 void Wait() { | |
| 2818 if (view_to_wait_for_->HasFocus()) | |
| 2819 return; | |
| 2820 | |
| 2821 base::MessageLoop::current()->Run(); | |
| 2822 } | |
| 2823 | |
| 2824 // FocusChangeListener implementation. | |
| 2825 void OnWillChangeFocus(views::View* focused_before, | |
| 2826 views::View* focused_now) override {} | |
| 2827 void OnDidChangeFocus(views::View* focused_before, | |
| 2828 views::View* focused_now) override { | |
| 2829 if (view_to_wait_for_ == focused_now) | |
| 2830 base::MessageLoop::current()->QuitWhenIdle(); | |
| 2831 } | |
| 2832 | |
| 2833 private: | |
| 2834 views::View* view_to_wait_for_; | |
| 2835 | |
| 2836 DISALLOW_COPY_AND_ASSIGN(FocusWaiter); | |
| 2837 }; | |
| 2838 | |
| 2839 // The following test verifies that a views::WebView hosting an embedder | 2807 // The following test verifies that a views::WebView hosting an embedder |
| 2840 // gains focus on touchstart. | 2808 // gains focus on touchstart. |
| 2841 IN_PROC_BROWSER_TEST_F(WebViewFocusTest, TouchFocusesEmbedder) { | 2809 IN_PROC_BROWSER_TEST_F(WebViewFocusTest, TouchFocusesEmbedder) { |
| 2842 LoadAppWithGuest("web_view/accept_touch_events"); | 2810 LoadAppWithGuest("web_view/accept_touch_events"); |
| 2843 | 2811 |
| 2844 content::WebContents* web_contents = GetEmbedderWebContents(); | 2812 content::WebContents* web_contents = GetEmbedderWebContents(); |
| 2845 content::RenderViewHost* embedder_rvh = web_contents->GetRenderViewHost(); | 2813 content::RenderViewHost* embedder_rvh = web_contents->GetRenderViewHost(); |
| 2846 | 2814 |
| 2847 bool embedder_has_touch_handler = | 2815 bool embedder_has_touch_handler = |
| 2848 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh); | 2816 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2888 EXPECT_FALSE(aura_webview->HasFocus()); | 2856 EXPECT_FALSE(aura_webview->HasFocus()); |
| 2889 | 2857 |
| 2890 // Compute location of guest within embedder so we can more accurately | 2858 // Compute location of guest within embedder so we can more accurately |
| 2891 // target our touch event. | 2859 // target our touch event. |
| 2892 gfx::Rect guest_rect = GetGuestWebContents()->GetContainerBounds(); | 2860 gfx::Rect guest_rect = GetGuestWebContents()->GetContainerBounds(); |
| 2893 gfx::Point embedder_origin = | 2861 gfx::Point embedder_origin = |
| 2894 GetEmbedderWebContents()->GetContainerBounds().origin(); | 2862 GetEmbedderWebContents()->GetContainerBounds().origin(); |
| 2895 guest_rect.Offset(-embedder_origin.x(), -embedder_origin.y()); | 2863 guest_rect.Offset(-embedder_origin.x(), -embedder_origin.y()); |
| 2896 | 2864 |
| 2897 // Generate and send synthetic touch event. | 2865 // Generate and send synthetic touch event. |
| 2898 FocusWaiter waiter(aura_webview); | |
| 2899 content::SimulateTouchPressAt(GetEmbedderWebContents(), | 2866 content::SimulateTouchPressAt(GetEmbedderWebContents(), |
| 2900 guest_rect.CenterPoint()); | 2867 guest_rect.CenterPoint()); |
| 2901 | 2868 EXPECT_TRUE(aura_webview->HasFocus()); |
| 2902 // Wait for the TouchStart to propagate and restore focus. Test times out | |
| 2903 // on failure. | |
| 2904 waiter.Wait(); | |
| 2905 } | 2869 } |
| 2906 #endif | 2870 #endif |
| 2907 | 2871 |
| 2908 #if defined(ENABLE_TASK_MANAGER) | 2872 #if defined(ENABLE_TASK_MANAGER) |
| 2909 | 2873 |
| 2910 namespace { | 2874 namespace { |
| 2911 | 2875 |
| 2912 base::string16 GetExpectedPrefix(content::WebContents* web_contents) { | 2876 base::string16 GetExpectedPrefix(content::WebContents* web_contents) { |
| 2913 DCHECK(web_contents); | 2877 DCHECK(web_contents); |
| 2914 guest_view::GuestViewBase* guest = | 2878 guest_view::GuestViewBase* guest = |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2989 // 4 tasks expected. The order is arbitrary. | 2953 // 4 tasks expected. The order is arbitrary. |
| 2990 // Tab: about:blank, | 2954 // Tab: about:blank, |
| 2991 // Background Page: <webview> task manager test, | 2955 // Background Page: <webview> task manager test, |
| 2992 // App: <webview> task manager test, | 2956 // App: <webview> task manager test, |
| 2993 // Webview: WebViewed test content. | 2957 // Webview: WebViewed test content. |
| 2994 EXPECT_EQ(4U, task_manager.tasks().size()); | 2958 EXPECT_EQ(4U, task_manager.tasks().size()); |
| 2995 EXPECT_TRUE(HasExpectedGuestTask(task_manager, guest_contents)); | 2959 EXPECT_TRUE(HasExpectedGuestTask(task_manager, guest_contents)); |
| 2996 } | 2960 } |
| 2997 | 2961 |
| 2998 #endif // defined(ENABLE_TASK_MANAGER) | 2962 #endif // defined(ENABLE_TASK_MANAGER) |
| OLD | NEW |