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

Side by Side Diff: content/browser/web_contents/web_contents_view_aura_browsertest.cc

Issue 478023002: OverscrollController consumes scroll updates only during gesture-nav. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add TODO to clean up browsertest. Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/web_contents/web_contents_view_aura.h" 5 #include "content/browser/web_contents/web_contents_view_aura.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #if defined(OS_WIN) 12 #if defined(OS_WIN)
13 #include "base/win/windows_version.h" 13 #include "base/win/windows_version.h"
14 #endif 14 #endif
15 #include "content/browser/frame_host/navigation_controller_impl.h" 15 #include "content/browser/frame_host/navigation_controller_impl.h"
16 #include "content/browser/frame_host/navigation_entry_impl.h" 16 #include "content/browser/frame_host/navigation_entry_impl.h"
17 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" 17 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h"
18 #include "content/browser/renderer_host/render_widget_host_view_aura.h" 18 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
19 #include "content/browser/web_contents/web_contents_impl.h" 19 #include "content/browser/web_contents/web_contents_impl.h"
20 #include "content/browser/web_contents/web_contents_view.h" 20 #include "content/browser/web_contents/web_contents_view.h"
21 #include "content/common/input/synthetic_web_input_event_builders.h"
22 #include "content/common/input_messages.h"
21 #include "content/common/view_messages.h" 23 #include "content/common/view_messages.h"
24 #include "content/public/browser/browser_message_filter.h"
22 #include "content/public/browser/render_frame_host.h" 25 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/browser/web_contents_observer.h" 26 #include "content/public/browser/web_contents_observer.h"
24 #include "content/public/common/content_switches.h" 27 #include "content/public/common/content_switches.h"
25 #include "content/public/test/browser_test_utils.h" 28 #include "content/public/test/browser_test_utils.h"
26 #include "content/public/test/content_browser_test.h" 29 #include "content/public/test/content_browser_test.h"
27 #include "content/public/test/content_browser_test_utils.h" 30 #include "content/public/test/content_browser_test_utils.h"
28 #include "content/public/test/test_renderer_host.h" 31 #include "content/public/test/test_renderer_host.h"
29 #include "content/public/test/test_utils.h" 32 #include "content/public/test/test_utils.h"
30 #include "content/shell/browser/shell.h" 33 #include "content/shell/browser/shell.h"
31 #include "ui/aura/window.h" 34 #include "ui/aura/window.h"
32 #include "ui/aura/window_tree_host.h" 35 #include "ui/aura/window_tree_host.h"
33 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 36 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
34 #include "ui/events/event_processor.h" 37 #include "ui/events/event_processor.h"
38 #include "ui/events/event_switches.h"
35 #include "ui/events/event_utils.h" 39 #include "ui/events/event_utils.h"
36 #include "ui/events/test/event_generator.h" 40 #include "ui/events/test/event_generator.h"
37 41
42 namespace {
43
44 // TODO(tdresser): Find a way to avoid sleeping like this. See crbug.com/405282
danakj 2015/04/02 18:41:56 Would be awesome to follow up on this. I keep seei
45 // for details.
46 void GiveItSomeTime() {
47 base::RunLoop run_loop;
48 base::MessageLoop::current()->PostDelayedTask(
49 FROM_HERE,
50 run_loop.QuitClosure(),
51 base::TimeDelta::FromMillisecondsD(10));
52 run_loop.Run();
53 }
54
55 } //namespace
56
57
38 namespace content { 58 namespace content {
39 59
40 // This class keeps track of the RenderViewHost whose screenshot was captured. 60 // This class keeps track of the RenderViewHost whose screenshot was captured.
41 class ScreenshotTracker : public NavigationEntryScreenshotManager { 61 class ScreenshotTracker : public NavigationEntryScreenshotManager {
42 public: 62 public:
43 explicit ScreenshotTracker(NavigationControllerImpl* controller) 63 explicit ScreenshotTracker(NavigationControllerImpl* controller)
44 : NavigationEntryScreenshotManager(controller), 64 : NavigationEntryScreenshotManager(controller),
45 screenshot_taken_for_(NULL), 65 screenshot_taken_for_(NULL),
46 waiting_for_screenshots_(0) { 66 waiting_for_screenshots_(0) {
47 } 67 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 if (should_quit_loop_) 140 if (should_quit_loop_)
121 base::MessageLoop::current()->Quit(); 141 base::MessageLoop::current()->Quit();
122 } 142 }
123 143
124 bool navigated_; 144 bool navigated_;
125 bool should_quit_loop_; 145 bool should_quit_loop_;
126 146
127 DISALLOW_COPY_AND_ASSIGN(NavigationWatcher); 147 DISALLOW_COPY_AND_ASSIGN(NavigationWatcher);
128 }; 148 };
129 149
150 class InputEventMessageFilterWaitsForAcks : public BrowserMessageFilter {
151 public:
152 InputEventMessageFilterWaitsForAcks()
153 : BrowserMessageFilter(InputMsgStart),
154 type_(blink::WebInputEvent::Undefined),
155 state_(INPUT_EVENT_ACK_STATE_UNKNOWN) {}
156
157 void WaitForAck(blink::WebInputEvent::Type type) {
158 base::RunLoop run_loop;
159 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure());
160 base::AutoReset<blink::WebInputEvent::Type> reset_type(&type_, type);
161 run_loop.Run();
162 }
163
164 InputEventAckState last_ack_state() const { return state_; }
165
166 protected:
167 virtual ~InputEventMessageFilterWaitsForAcks() {}
168
169 private:
170 void ReceivedEventAck(blink::WebInputEvent::Type type,
171 InputEventAckState state) {
172 if (type_ == type) {
173 state_ = state;
174 quit_.Run();
175 }
176 }
177
178 // BrowserMessageFilter:
179 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
180 if (message.type() == InputHostMsg_HandleInputEvent_ACK::ID) {
181 InputHostMsg_HandleInputEvent_ACK::Param params;
182 InputHostMsg_HandleInputEvent_ACK::Read(&message, &params);
183 blink::WebInputEvent::Type type = params.a.type;
184 InputEventAckState ack = params.a.state;
185 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
186 base::Bind(&InputEventMessageFilterWaitsForAcks::ReceivedEventAck,
187 this, type, ack));
188 }
189 return false;
190 }
191
192 base::Closure quit_;
193 blink::WebInputEvent::Type type_;
194 InputEventAckState state_;
195
196 DISALLOW_COPY_AND_ASSIGN(InputEventMessageFilterWaitsForAcks);
197 };
198
130 class WebContentsViewAuraTest : public ContentBrowserTest { 199 class WebContentsViewAuraTest : public ContentBrowserTest {
131 public: 200 public:
132 WebContentsViewAuraTest() 201 WebContentsViewAuraTest()
133 : screenshot_manager_(NULL) { 202 : screenshot_manager_(NULL) {
134 } 203 }
135 204
136 // Executes the javascript synchronously and makes sure the returned value is 205 // Executes the javascript synchronously and makes sure the returned value is
137 // freed properly. 206 // freed properly.
138 void ExecuteSyncJSFunction(RenderFrameHost* rfh, const std::string& jscript) { 207 void ExecuteSyncJSFunction(RenderFrameHost* rfh, const std::string& jscript) {
139 scoped_ptr<base::Value> value = 208 scoped_ptr<base::Value> value =
140 content::ExecuteScriptAndGetValue(rfh, jscript); 209 content::ExecuteScriptAndGetValue(rfh, jscript);
141 } 210 }
142 211
143 // Starts the test server and navigates to the given url. Sets a large enough 212 // Starts the test server and navigates to the given url. Sets a large enough
144 // size to the root window. Returns after the navigation to the url is 213 // size to the root window. Returns after the navigation to the url is
145 // complete. 214 // complete.
146 void StartTestWithPage(const std::string& url) { 215 void StartTestWithPage(const std::string& url) {
147 ASSERT_TRUE(test_server()->Start()); 216 ASSERT_TRUE(test_server()->Start());
148 GURL test_url(test_server()->GetURL(url)); 217 GURL test_url(test_server()->GetURL(url));
149 NavigateToURL(shell(), test_url); 218 NavigateToURL(shell(), test_url);
150 219
151 WebContentsImpl* web_contents = 220 WebContentsImpl* web_contents =
152 static_cast<WebContentsImpl*>(shell()->web_contents()); 221 static_cast<WebContentsImpl*>(shell()->web_contents());
153 NavigationControllerImpl* controller = &web_contents->GetController(); 222 NavigationControllerImpl* controller = &web_contents->GetController();
154 223
155 screenshot_manager_ = new ScreenshotTracker(controller); 224 screenshot_manager_ = new ScreenshotTracker(controller);
156 controller->SetScreenshotManager(screenshot_manager_); 225 controller->SetScreenshotManager(screenshot_manager_);
157 } 226 }
158 227
228 virtual void SetUpCommandLine(CommandLine* cmd) OVERRIDE {
229 cmd->AppendSwitchASCII(switches::kTouchEvents,
230 switches::kTouchEventsEnabled);
231 }
232
159 void TestOverscrollNavigation(bool touch_handler) { 233 void TestOverscrollNavigation(bool touch_handler) {
160 ASSERT_NO_FATAL_FAILURE( 234 ASSERT_NO_FATAL_FAILURE(
161 StartTestWithPage("files/overscroll_navigation.html")); 235 StartTestWithPage("files/overscroll_navigation.html"));
162 WebContentsImpl* web_contents = 236 WebContentsImpl* web_contents =
163 static_cast<WebContentsImpl*>(shell()->web_contents()); 237 static_cast<WebContentsImpl*>(shell()->web_contents());
164 NavigationController& controller = web_contents->GetController(); 238 NavigationController& controller = web_contents->GetController();
165 RenderFrameHost* main_frame = web_contents->GetMainFrame(); 239 RenderFrameHost* main_frame = web_contents->GetMainFrame();
166 240
167 EXPECT_FALSE(controller.CanGoBack()); 241 EXPECT_FALSE(controller.CanGoBack());
168 EXPECT_FALSE(controller.CanGoForward()); 242 EXPECT_FALSE(controller.CanGoForward());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 static_cast<WebContentsImpl*>(shell()->web_contents()); 323 static_cast<WebContentsImpl*>(shell()->web_contents());
250 RenderFrameHost* main_frame = web_contents->GetMainFrame(); 324 RenderFrameHost* main_frame = web_contents->GetMainFrame();
251 int index = -1; 325 int index = -1;
252 scoped_ptr<base::Value> value; 326 scoped_ptr<base::Value> value;
253 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); 327 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()");
254 if (!value->GetAsInteger(&index)) 328 if (!value->GetAsInteger(&index))
255 index = -1; 329 index = -1;
256 return index; 330 return index;
257 } 331 }
258 332
333 int ExecuteScriptAndExtractInt(const std::string& script) {
334 int value = 0;
335 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
336 shell()->web_contents(),
337 "domAutomationController.send(" + script + ")",
338 &value));
339 return value;
340 }
341
342 RenderViewHost* GetRenderViewHost() const {
343 RenderViewHost* const rvh = shell()->web_contents()->GetRenderViewHost();
344 CHECK(rvh);
345 return rvh;
346 }
347
348 RenderWidgetHostImpl* GetRenderWidgetHost() const {
349 RenderWidgetHostImpl* const rwh =
350 RenderWidgetHostImpl::From(shell()
351 ->web_contents()
352 ->GetRenderWidgetHostView()
353 ->GetRenderWidgetHost());
354 CHECK(rwh);
355 return rwh;
356 }
357
358 RenderWidgetHostViewBase* GetRenderWidgetHostView() const {
359 return static_cast<RenderWidgetHostViewBase*>(
360 GetRenderViewHost()->GetView());
361 }
362
363 InputEventMessageFilterWaitsForAcks* filter() {
364 return filter_.get();
365 }
366
367 void WaitAFrame() {
368 uint32 frame = GetRenderWidgetHostView()->RendererFrameNumber();
369 while (!GetRenderWidgetHost()->ScheduleComposite())
370 GiveItSomeTime();
371 while (GetRenderWidgetHostView()->RendererFrameNumber() == frame)
372 GiveItSomeTime();
373 }
374
259 protected: 375 protected:
260 ScreenshotTracker* screenshot_manager() { return screenshot_manager_; } 376 ScreenshotTracker* screenshot_manager() { return screenshot_manager_; }
261 void set_min_screenshot_interval(int interval_ms) { 377 void set_min_screenshot_interval(int interval_ms) {
262 screenshot_manager_->SetScreenshotInterval(interval_ms); 378 screenshot_manager_->SetScreenshotInterval(interval_ms);
263 } 379 }
264 380
381 void AddInputEventMessageFilter() {
382 filter_ = new InputEventMessageFilterWaitsForAcks();
383 GetRenderWidgetHost()->GetProcess()->AddFilter(filter_);
384 }
385
265 private: 386 private:
266 ScreenshotTracker* screenshot_manager_; 387 ScreenshotTracker* screenshot_manager_;
388 scoped_refptr<InputEventMessageFilterWaitsForAcks> filter_;
267 389
268 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAuraTest); 390 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAuraTest);
269 }; 391 };
270 392
271 // Flaky on Windows: http://crbug.com/305722 393 // Flaky on Windows: http://crbug.com/305722
272 #if defined(OS_WIN) 394 #if defined(OS_WIN)
273 #define MAYBE_OverscrollNavigation DISABLED_OverscrollNavigation 395 #define MAYBE_OverscrollNavigation DISABLED_OverscrollNavigation
274 #else 396 #else
275 #define MAYBE_OverscrollNavigation OverscrollNavigation 397 #define MAYBE_OverscrollNavigation OverscrollNavigation
276 #endif 398 #endif
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 862
741 RenderWidgetHostViewAura* rwhva = 863 RenderWidgetHostViewAura* rwhva =
742 static_cast<RenderWidgetHostViewAura*>( 864 static_cast<RenderWidgetHostViewAura*>(
743 shell()->web_contents()->GetRenderWidgetHostView()); 865 shell()->web_contents()->GetRenderWidgetHostView());
744 rwhva->ResetHasSnappedToBoundary(); 866 rwhva->ResetHasSnappedToBoundary();
745 EXPECT_FALSE(rwhva->has_snapped_to_boundary()); 867 EXPECT_FALSE(rwhva->has_snapped_to_boundary());
746 window->AddChild(shell()->web_contents()->GetNativeView()); 868 window->AddChild(shell()->web_contents()->GetNativeView());
747 EXPECT_TRUE(rwhva->has_snapped_to_boundary()); 869 EXPECT_TRUE(rwhva->has_snapped_to_boundary());
748 } 870 }
749 871
872 // Flaky on Windows, likely for the same reason as other flaky overscroll tests.
873 // http://crbug.com/305722
874 #if defined(OS_WIN)
875 #define MAYBE_OverscrollNavigationTouchThrottling \
876 DISABLED_OverscrollNavigationTouchThrottling
877 #else
878 #define MAYBE_OverscrollNavigationTouchThrottling \
879 OverscrollNavigationTouchThrottling
880 #endif
881
882 // Tests that touch moves are not throttled when performing a scroll gesture on
883 // a non-scrollable area, except during gesture-nav.
884 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
885 MAYBE_OverscrollNavigationTouchThrottling) {
886 ASSERT_NO_FATAL_FAILURE(
887 StartTestWithPage("files/overscroll_navigation.html"));
888
889 AddInputEventMessageFilter();
890
891 WebContentsImpl* web_contents =
892 static_cast<WebContentsImpl*>(shell()->web_contents());
893 aura::Window* content = web_contents->GetContentNativeView();
894 gfx::Rect bounds = content->GetBoundsInRootWindow();
895 const int dx = 20;
896
897 ExecuteSyncJSFunction(web_contents->GetMainFrame(),
898 "install_touchmove_handler()");
899
900 WaitAFrame();
901
902 for (int navigated = 0; navigated <= 1; ++navigated) {
903 if (navigated) {
904 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()");
905 ExecuteSyncJSFunction(web_contents->GetMainFrame(),
906 "reset_touchmove_count()");
907 }
908 // Send touch press.
909 SyntheticWebTouchEvent touch;
910 touch.PressPoint(bounds.x() + 2, bounds.y() + 10);
911 GetRenderWidgetHost()->ForwardTouchEventWithLatencyInfo(touch,
912 ui::LatencyInfo());
913 filter()->WaitForAck(blink::WebInputEvent::TouchStart);
914 // Assert on the ack, because we'll end up waiting for acks that will never
915 // come if this is not true.
916 ASSERT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, filter()->last_ack_state());
917
918 // Send first touch move, and then a scroll begin.
919 touch.MovePoint(0, bounds.x() + 20 + 1 * dx, bounds.y() + 100);
920 GetRenderWidgetHost()->ForwardTouchEventWithLatencyInfo(touch,
921 ui::LatencyInfo());
922 filter()->WaitForAck(blink::WebInputEvent::TouchMove);
923 ASSERT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, filter()->last_ack_state());
924
925 blink::WebGestureEvent scroll_begin =
926 SyntheticWebGestureEventBuilder::BuildScrollBegin(1, 1);
927 GetRenderWidgetHost()->ForwardGestureEventWithLatencyInfo(
928 scroll_begin, ui::LatencyInfo());
929 // Scroll begin ignores ack disposition, so don't wait for the ack.
930 // GiveItSomeTime();
931 WaitAFrame();
932
933 // First touchmove already sent, start at 2.
934 for (int i = 2; i <= 10; ++i) {
935 // Send a touch move, followed by a scroll update
936 touch.MovePoint(0, bounds.x() + 20 + i * dx, bounds.y() + 100);
937 GetRenderWidgetHost()->ForwardTouchEventWithLatencyInfo(
938 touch, ui::LatencyInfo());
939 WaitAFrame();
940
941 blink::WebGestureEvent scroll_update =
942 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dx, 5, 0);
943
944 GetRenderWidgetHost()->ForwardGestureEventWithLatencyInfo(
945 scroll_update, ui::LatencyInfo());
946
947 WaitAFrame();
948 }
949
950 touch.ReleasePoint(0);
951 GetRenderWidgetHost()->ForwardTouchEventWithLatencyInfo(touch,
952 ui::LatencyInfo());
953 WaitAFrame();
954
955 blink::WebGestureEvent scroll_end;
956 scroll_end.type = blink::WebInputEvent::GestureScrollEnd;
957 GetRenderWidgetHost()->ForwardGestureEventWithLatencyInfo(
958 scroll_end, ui::LatencyInfo());
959 WaitAFrame();
960
961 if (!navigated)
962 EXPECT_EQ(10, ExecuteScriptAndExtractInt("touchmoveCount"));
963 else
964 EXPECT_GT(10, ExecuteScriptAndExtractInt("touchmoveCount"));
965 }
966 }
967
750 } // namespace content 968 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_view_aura.cc ('k') | content/test/data/overscroll_navigation.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698