Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / browser / web_contents / web_contents_view_aura_browsertest.cc
blobb25344ea4e9ec497c0568dc35ba357a3655546a9
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
3 // found in the LICENSE file.
5 #include "content/browser/web_contents/web_contents_view_aura.h"
7 #include "base/command_line.h"
8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/test/test_timeouts.h"
11 #include "base/values.h"
12 #if defined(OS_WIN)
13 #include "base/win/windows_version.h"
14 #endif
15 #include "content/browser/frame_host/navigation_controller_impl.h"
16 #include "content/browser/frame_host/navigation_entry_impl.h"
17 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h"
18 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
19 #include "content/browser/web_contents/web_contents_impl.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"
23 #include "content/common/view_messages.h"
24 #include "content/public/browser/browser_message_filter.h"
25 #include "content/public/browser/render_frame_host.h"
26 #include "content/public/browser/web_contents_delegate.h"
27 #include "content/public/browser/web_contents_observer.h"
28 #include "content/public/common/content_switches.h"
29 #include "content/public/test/browser_test_utils.h"
30 #include "content/public/test/content_browser_test.h"
31 #include "content/public/test/content_browser_test_utils.h"
32 #include "content/public/test/test_renderer_host.h"
33 #include "content/public/test/test_utils.h"
34 #include "content/shell/browser/shell.h"
35 #include "ui/aura/window.h"
36 #include "ui/aura/window_tree_host.h"
37 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
38 #include "ui/events/event_processor.h"
39 #include "ui/events/event_switches.h"
40 #include "ui/events/event_utils.h"
41 #include "ui/events/test/event_generator.h"
43 namespace {
45 // TODO(tdresser): Find a way to avoid sleeping like this. See crbug.com/405282
46 // for details.
47 void GiveItSomeTime() {
48 base::RunLoop run_loop;
49 base::MessageLoop::current()->PostDelayedTask(
50 FROM_HERE,
51 run_loop.QuitClosure(),
52 base::TimeDelta::FromMillisecondsD(10));
53 run_loop.Run();
56 // WebContentsDelegate which tracks vertical overscroll updates.
57 class VerticalOverscrollTracker : public content::WebContentsDelegate {
58 public:
59 VerticalOverscrollTracker() : count_(0), completed_(false) {}
60 ~VerticalOverscrollTracker() override {}
62 int num_overscroll_updates() const {
63 return count_;
66 bool overscroll_completed() const {
67 return completed_;
70 void Reset() {
71 count_ = 0;
72 completed_ = false;
75 private:
76 bool CanOverscrollContent() const override { return true; }
78 void OverscrollUpdate(float delta_y) override { ++count_; }
80 void OverscrollComplete() override { completed_ = true; }
82 int count_;
83 bool completed_;
85 DISALLOW_COPY_AND_ASSIGN(VerticalOverscrollTracker);
88 } //namespace
91 namespace content {
93 // This class keeps track of the RenderViewHost whose screenshot was captured.
94 class ScreenshotTracker : public NavigationEntryScreenshotManager {
95 public:
96 explicit ScreenshotTracker(NavigationControllerImpl* controller)
97 : NavigationEntryScreenshotManager(controller),
98 screenshot_taken_for_(NULL),
99 waiting_for_screenshots_(0) {
102 ~ScreenshotTracker() override {}
104 RenderViewHost* screenshot_taken_for() { return screenshot_taken_for_; }
106 void Reset() {
107 screenshot_taken_for_ = NULL;
108 screenshot_set_.clear();
111 void SetScreenshotInterval(int interval_ms) {
112 SetMinScreenshotIntervalMS(interval_ms);
115 void WaitUntilScreenshotIsReady() {
116 if (!waiting_for_screenshots_)
117 return;
118 message_loop_runner_ = new content::MessageLoopRunner;
119 message_loop_runner_->Run();
122 bool ScreenshotSetForEntry(NavigationEntryImpl* entry) const {
123 return screenshot_set_.count(entry) > 0;
126 private:
127 // Overridden from NavigationEntryScreenshotManager:
128 void TakeScreenshotImpl(RenderViewHost* host,
129 NavigationEntryImpl* entry) override {
130 ++waiting_for_screenshots_;
131 screenshot_taken_for_ = host;
132 NavigationEntryScreenshotManager::TakeScreenshotImpl(host, entry);
135 void OnScreenshotSet(NavigationEntryImpl* entry) override {
136 --waiting_for_screenshots_;
137 screenshot_set_[entry] = true;
138 NavigationEntryScreenshotManager::OnScreenshotSet(entry);
139 if (waiting_for_screenshots_ == 0 && message_loop_runner_.get())
140 message_loop_runner_->Quit();
143 RenderViewHost* screenshot_taken_for_;
144 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
145 int waiting_for_screenshots_;
146 std::map<NavigationEntryImpl*, bool> screenshot_set_;
148 DISALLOW_COPY_AND_ASSIGN(ScreenshotTracker);
151 class NavigationWatcher : public WebContentsObserver {
152 public:
153 explicit NavigationWatcher(WebContents* contents)
154 : WebContentsObserver(contents),
155 navigated_(false),
156 should_quit_loop_(false) {
159 ~NavigationWatcher() override {}
161 void WaitUntilNavigationStarts() {
162 if (navigated_)
163 return;
164 should_quit_loop_ = true;
165 base::MessageLoop::current()->Run();
168 private:
169 // Overridden from WebContentsObserver:
170 void DidStartNavigationToPendingEntry(
171 const GURL& validated_url,
172 NavigationController::ReloadType reload_type) override {
173 navigated_ = true;
174 if (should_quit_loop_)
175 base::MessageLoop::current()->Quit();
178 bool navigated_;
179 bool should_quit_loop_;
181 DISALLOW_COPY_AND_ASSIGN(NavigationWatcher);
184 class InputEventMessageFilterWaitsForAcks : public BrowserMessageFilter {
185 public:
186 InputEventMessageFilterWaitsForAcks()
187 : BrowserMessageFilter(InputMsgStart),
188 type_(blink::WebInputEvent::Undefined),
189 state_(INPUT_EVENT_ACK_STATE_UNKNOWN) {}
191 void WaitForAck(blink::WebInputEvent::Type type) {
192 base::RunLoop run_loop;
193 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure());
194 base::AutoReset<blink::WebInputEvent::Type> reset_type(&type_, type);
195 run_loop.Run();
198 InputEventAckState last_ack_state() const { return state_; }
200 protected:
201 ~InputEventMessageFilterWaitsForAcks() override {}
203 private:
204 void ReceivedEventAck(blink::WebInputEvent::Type type,
205 InputEventAckState state) {
206 if (type_ == type) {
207 state_ = state;
208 quit_.Run();
212 // BrowserMessageFilter:
213 bool OnMessageReceived(const IPC::Message& message) override {
214 if (message.type() == InputHostMsg_HandleInputEvent_ACK::ID) {
215 InputHostMsg_HandleInputEvent_ACK::Param params;
216 InputHostMsg_HandleInputEvent_ACK::Read(&message, &params);
217 blink::WebInputEvent::Type type = params.a.type;
218 InputEventAckState ack = params.a.state;
219 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
220 base::Bind(&InputEventMessageFilterWaitsForAcks::ReceivedEventAck,
221 this, type, ack));
223 return false;
226 base::Closure quit_;
227 blink::WebInputEvent::Type type_;
228 InputEventAckState state_;
230 DISALLOW_COPY_AND_ASSIGN(InputEventMessageFilterWaitsForAcks);
233 class WebContentsViewAuraTest : public ContentBrowserTest {
234 public:
235 WebContentsViewAuraTest()
236 : screenshot_manager_(NULL) {
239 // Executes the javascript synchronously and makes sure the returned value is
240 // freed properly.
241 void ExecuteSyncJSFunction(RenderFrameHost* rfh, const std::string& jscript) {
242 scoped_ptr<base::Value> value =
243 content::ExecuteScriptAndGetValue(rfh, jscript);
246 // Starts the test server and navigates to the given url. Sets a large enough
247 // size to the root window. Returns after the navigation to the url is
248 // complete.
249 void StartTestWithPage(const std::string& url) {
250 ASSERT_TRUE(test_server()->Start());
251 GURL test_url(test_server()->GetURL(url));
252 NavigateToURL(shell(), test_url);
254 WebContentsImpl* web_contents =
255 static_cast<WebContentsImpl*>(shell()->web_contents());
256 NavigationControllerImpl* controller = &web_contents->GetController();
258 screenshot_manager_ = new ScreenshotTracker(controller);
259 controller->SetScreenshotManager(screenshot_manager_);
262 void SetUpCommandLine(CommandLine* cmd) override {
263 cmd->AppendSwitchASCII(switches::kTouchEvents,
264 switches::kTouchEventsEnabled);
267 void TestOverscrollNavigation(bool touch_handler) {
268 ASSERT_NO_FATAL_FAILURE(
269 StartTestWithPage("files/overscroll_navigation.html"));
270 WebContentsImpl* web_contents =
271 static_cast<WebContentsImpl*>(shell()->web_contents());
272 NavigationController& controller = web_contents->GetController();
273 RenderFrameHost* main_frame = web_contents->GetMainFrame();
275 EXPECT_FALSE(controller.CanGoBack());
276 EXPECT_FALSE(controller.CanGoForward());
277 int index = -1;
278 scoped_ptr<base::Value> value =
279 content::ExecuteScriptAndGetValue(main_frame, "get_current()");
280 ASSERT_TRUE(value->GetAsInteger(&index));
281 EXPECT_EQ(0, index);
283 if (touch_handler)
284 ExecuteSyncJSFunction(main_frame, "install_touch_handler()");
286 ExecuteSyncJSFunction(main_frame, "navigate_next()");
287 ExecuteSyncJSFunction(main_frame, "navigate_next()");
288 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()");
289 ASSERT_TRUE(value->GetAsInteger(&index));
290 EXPECT_EQ(2, index);
291 EXPECT_TRUE(controller.CanGoBack());
292 EXPECT_FALSE(controller.CanGoForward());
294 aura::Window* content = web_contents->GetContentNativeView();
295 gfx::Rect bounds = content->GetBoundsInRootWindow();
296 ui::test::EventGenerator generator(content->GetRootWindow(), content);
297 const int kScrollDurationMs = 20;
298 const int kScrollSteps = 10;
301 // Do a swipe-right now. That should navigate backwards.
302 base::string16 expected_title = base::ASCIIToUTF16("Title: #1");
303 content::TitleWatcher title_watcher(web_contents, expected_title);
304 generator.GestureScrollSequence(
305 gfx::Point(bounds.x() + 2, bounds.y() + 10),
306 gfx::Point(bounds.right() - 10, bounds.y() + 10),
307 base::TimeDelta::FromMilliseconds(kScrollDurationMs),
308 kScrollSteps);
309 base::string16 actual_title = title_watcher.WaitAndGetTitle();
310 EXPECT_EQ(expected_title, actual_title);
311 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()");
312 ASSERT_TRUE(value->GetAsInteger(&index));
313 EXPECT_EQ(1, index);
314 EXPECT_TRUE(controller.CanGoBack());
315 EXPECT_TRUE(controller.CanGoForward());
319 // Do a fling-right now. That should navigate backwards.
320 base::string16 expected_title = base::ASCIIToUTF16("Title:");
321 content::TitleWatcher title_watcher(web_contents, expected_title);
322 generator.GestureScrollSequence(
323 gfx::Point(bounds.x() + 2, bounds.y() + 10),
324 gfx::Point(bounds.right() - 10, bounds.y() + 10),
325 base::TimeDelta::FromMilliseconds(kScrollDurationMs),
326 kScrollSteps);
327 base::string16 actual_title = title_watcher.WaitAndGetTitle();
328 EXPECT_EQ(expected_title, actual_title);
329 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()");
330 ASSERT_TRUE(value->GetAsInteger(&index));
331 EXPECT_EQ(0, index);
332 EXPECT_FALSE(controller.CanGoBack());
333 EXPECT_TRUE(controller.CanGoForward());
337 // Do a swipe-left now. That should navigate forward.
338 base::string16 expected_title = base::ASCIIToUTF16("Title: #1");
339 content::TitleWatcher title_watcher(web_contents, expected_title);
340 generator.GestureScrollSequence(
341 gfx::Point(bounds.right() - 10, bounds.y() + 10),
342 gfx::Point(bounds.x() + 2, bounds.y() + 10),
343 base::TimeDelta::FromMilliseconds(kScrollDurationMs),
344 kScrollSteps);
345 base::string16 actual_title = title_watcher.WaitAndGetTitle();
346 EXPECT_EQ(expected_title, actual_title);
347 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()");
348 ASSERT_TRUE(value->GetAsInteger(&index));
349 EXPECT_EQ(1, index);
350 EXPECT_TRUE(controller.CanGoBack());
351 EXPECT_TRUE(controller.CanGoForward());
355 int GetCurrentIndex() {
356 WebContentsImpl* web_contents =
357 static_cast<WebContentsImpl*>(shell()->web_contents());
358 RenderFrameHost* main_frame = web_contents->GetMainFrame();
359 int index = -1;
360 scoped_ptr<base::Value> value;
361 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()");
362 if (!value->GetAsInteger(&index))
363 index = -1;
364 return index;
367 int ExecuteScriptAndExtractInt(const std::string& script) {
368 int value = 0;
369 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
370 shell()->web_contents(),
371 "domAutomationController.send(" + script + ")",
372 &value));
373 return value;
376 RenderViewHost* GetRenderViewHost() const {
377 RenderViewHost* const rvh = shell()->web_contents()->GetRenderViewHost();
378 CHECK(rvh);
379 return rvh;
382 RenderWidgetHostImpl* GetRenderWidgetHost() const {
383 RenderWidgetHostImpl* const rwh =
384 RenderWidgetHostImpl::From(shell()
385 ->web_contents()
386 ->GetRenderWidgetHostView()
387 ->GetRenderWidgetHost());
388 CHECK(rwh);
389 return rwh;
392 RenderWidgetHostViewBase* GetRenderWidgetHostView() const {
393 return static_cast<RenderWidgetHostViewBase*>(
394 GetRenderViewHost()->GetView());
397 InputEventMessageFilterWaitsForAcks* filter() {
398 return filter_.get();
401 void WaitAFrame() {
402 uint32 frame = GetRenderWidgetHostView()->RendererFrameNumber();
403 while (!GetRenderWidgetHost()->ScheduleComposite())
404 GiveItSomeTime();
405 while (GetRenderWidgetHostView()->RendererFrameNumber() == frame)
406 GiveItSomeTime();
409 protected:
410 ScreenshotTracker* screenshot_manager() { return screenshot_manager_; }
411 void set_min_screenshot_interval(int interval_ms) {
412 screenshot_manager_->SetScreenshotInterval(interval_ms);
415 void AddInputEventMessageFilter() {
416 filter_ = new InputEventMessageFilterWaitsForAcks();
417 GetRenderWidgetHost()->GetProcess()->AddFilter(filter_.get());
420 private:
421 ScreenshotTracker* screenshot_manager_;
422 scoped_refptr<InputEventMessageFilterWaitsForAcks> filter_;
424 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAuraTest);
427 // Flaky on Windows: http://crbug.com/305722
428 #if defined(OS_WIN)
429 #define MAYBE_OverscrollNavigation DISABLED_OverscrollNavigation
430 #else
431 #define MAYBE_OverscrollNavigation OverscrollNavigation
432 #endif
434 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, MAYBE_OverscrollNavigation) {
435 TestOverscrollNavigation(false);
438 // Flaky on Windows (might be related to the above test):
439 // http://crbug.com/305722
440 #if defined(OS_WIN)
441 #define MAYBE_OverscrollNavigationWithTouchHandler \
442 DISABLED_OverscrollNavigationWithTouchHandler
443 #else
444 #define MAYBE_OverscrollNavigationWithTouchHandler \
445 OverscrollNavigationWithTouchHandler
446 #endif
447 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
448 MAYBE_OverscrollNavigationWithTouchHandler) {
449 TestOverscrollNavigation(true);
452 // Disabled because the test always fails the first time it runs on the Win Aura
453 // bots, and usually but not always passes second-try (See crbug.com/179532).
454 #if defined(OS_WIN)
455 #define MAYBE_QuickOverscrollDirectionChange \
456 DISABLED_QuickOverscrollDirectionChange
457 #else
458 #define MAYBE_QuickOverscrollDirectionChange QuickOverscrollDirectionChange
459 #endif
460 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
461 MAYBE_QuickOverscrollDirectionChange) {
462 ASSERT_NO_FATAL_FAILURE(
463 StartTestWithPage("files/overscroll_navigation.html"));
464 WebContentsImpl* web_contents =
465 static_cast<WebContentsImpl*>(shell()->web_contents());
466 RenderFrameHost* main_frame = web_contents->GetMainFrame();
468 // This test triggers a large number of animations. Speed them up to ensure
469 // the test completes within its time limit.
470 ui::ScopedAnimationDurationScaleMode fast_duration_mode(
471 ui::ScopedAnimationDurationScaleMode::FAST_DURATION);
473 // Make sure the page has both back/forward history.
474 ExecuteSyncJSFunction(main_frame, "navigate_next()");
475 EXPECT_EQ(1, GetCurrentIndex());
476 ExecuteSyncJSFunction(main_frame, "navigate_next()");
477 EXPECT_EQ(2, GetCurrentIndex());
478 web_contents->GetController().GoBack();
479 EXPECT_EQ(1, GetCurrentIndex());
481 aura::Window* content = web_contents->GetContentNativeView();
482 ui::EventProcessor* dispatcher = content->GetHost()->event_processor();
483 gfx::Rect bounds = content->GetBoundsInRootWindow();
485 base::TimeDelta timestamp = ui::EventTimeForNow();
486 ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
487 gfx::Point(bounds.x() + bounds.width() / 2, bounds.y() + 5),
488 0, timestamp);
489 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press);
490 ASSERT_FALSE(details.dispatcher_destroyed);
491 EXPECT_EQ(1, GetCurrentIndex());
493 timestamp += base::TimeDelta::FromMilliseconds(10);
494 ui::TouchEvent move1(ui::ET_TOUCH_MOVED,
495 gfx::Point(bounds.right() - 10, bounds.y() + 5),
496 0, timestamp);
497 details = dispatcher->OnEventFromSource(&move1);
498 ASSERT_FALSE(details.dispatcher_destroyed);
499 EXPECT_EQ(1, GetCurrentIndex());
501 // Swipe back from the right edge, back to the left edge, back to the right
502 // edge.
504 for (int x = bounds.right() - 10; x >= bounds.x() + 10; x-= 10) {
505 timestamp += base::TimeDelta::FromMilliseconds(10);
506 ui::TouchEvent inc(ui::ET_TOUCH_MOVED,
507 gfx::Point(x, bounds.y() + 5),
508 0, timestamp);
509 details = dispatcher->OnEventFromSource(&inc);
510 ASSERT_FALSE(details.dispatcher_destroyed);
511 EXPECT_EQ(1, GetCurrentIndex());
514 for (int x = bounds.x() + 10; x <= bounds.width() - 10; x+= 10) {
515 timestamp += base::TimeDelta::FromMilliseconds(10);
516 ui::TouchEvent inc(ui::ET_TOUCH_MOVED,
517 gfx::Point(x, bounds.y() + 5),
518 0, timestamp);
519 details = dispatcher->OnEventFromSource(&inc);
520 ASSERT_FALSE(details.dispatcher_destroyed);
521 EXPECT_EQ(1, GetCurrentIndex());
524 for (int x = bounds.width() - 10; x >= bounds.x() + 10; x-= 10) {
525 timestamp += base::TimeDelta::FromMilliseconds(10);
526 ui::TouchEvent inc(ui::ET_TOUCH_MOVED,
527 gfx::Point(x, bounds.y() + 5),
528 0, timestamp);
529 details = dispatcher->OnEventFromSource(&inc);
530 ASSERT_FALSE(details.dispatcher_destroyed);
531 EXPECT_EQ(1, GetCurrentIndex());
534 // Do not end the overscroll sequence.
537 // Tests that the page has has a screenshot when navigation happens:
538 // - from within the page (from a JS function)
539 // - interactively, when user does an overscroll gesture
540 // - interactively, when user navigates in history without the overscroll
541 // gesture.
542 // Flaky on Windows (http://crbug.com/357311). Might be related to
543 // OverscrollNavigation test.
544 // Flaky on Ozone (http://crbug.com/399676).
545 // Flaky on ChromeOS (http://crbug.com/405945).
546 #if defined(OS_WIN) || defined(USE_OZONE) || defined(OS_CHROMEOS)
547 #define MAYBE_OverscrollScreenshot DISABLED_OverscrollScreenshot
548 #else
549 #define MAYBE_OverscrollScreenshot OverscrollScreenshot
550 #endif
551 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, MAYBE_OverscrollScreenshot) {
552 // Disable the test for WinXP. See http://crbug/294116.
553 #if defined(OS_WIN)
554 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
555 LOG(WARNING) << "Test disabled due to unknown bug on WinXP.";
556 return;
558 #endif
560 ASSERT_NO_FATAL_FAILURE(
561 StartTestWithPage("files/overscroll_navigation.html"));
562 WebContentsImpl* web_contents =
563 static_cast<WebContentsImpl*>(shell()->web_contents());
564 RenderFrameHost* main_frame = web_contents->GetMainFrame();
566 set_min_screenshot_interval(0);
568 // Do a few navigations initiated by the page.
569 // Screenshots should never be captured since these are all in-page
570 // navigations.
571 ExecuteSyncJSFunction(main_frame, "navigate_next()");
572 EXPECT_EQ(1, GetCurrentIndex());
573 ExecuteSyncJSFunction(main_frame, "navigate_next()");
574 EXPECT_EQ(2, GetCurrentIndex());
575 screenshot_manager()->WaitUntilScreenshotIsReady();
577 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
578 web_contents->GetController().GetEntryAtIndex(2));
579 EXPECT_FALSE(entry->screenshot().get());
581 entry = NavigationEntryImpl::FromNavigationEntry(
582 web_contents->GetController().GetEntryAtIndex(1));
583 EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry));
585 entry = NavigationEntryImpl::FromNavigationEntry(
586 web_contents->GetController().GetEntryAtIndex(0));
587 EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry));
589 ExecuteSyncJSFunction(main_frame, "navigate_next()");
590 screenshot_manager()->WaitUntilScreenshotIsReady();
592 entry = NavigationEntryImpl::FromNavigationEntry(
593 web_contents->GetController().GetEntryAtIndex(2));
594 EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry));
596 entry = NavigationEntryImpl::FromNavigationEntry(
597 web_contents->GetController().GetEntryAtIndex(3));
598 EXPECT_FALSE(entry->screenshot().get());
600 // Now, swipe right to navigate backwards. This should navigate away from
601 // index 3 to index 2.
602 base::string16 expected_title = base::ASCIIToUTF16("Title: #2");
603 content::TitleWatcher title_watcher(web_contents, expected_title);
604 aura::Window* content = web_contents->GetContentNativeView();
605 gfx::Rect bounds = content->GetBoundsInRootWindow();
606 ui::test::EventGenerator generator(content->GetRootWindow(), content);
607 generator.GestureScrollSequence(
608 gfx::Point(bounds.x() + 2, bounds.y() + 10),
609 gfx::Point(bounds.right() - 10, bounds.y() + 10),
610 base::TimeDelta::FromMilliseconds(20),
612 base::string16 actual_title = title_watcher.WaitAndGetTitle();
613 EXPECT_EQ(expected_title, actual_title);
614 EXPECT_EQ(2, GetCurrentIndex());
615 screenshot_manager()->WaitUntilScreenshotIsReady();
616 entry = NavigationEntryImpl::FromNavigationEntry(
617 web_contents->GetController().GetEntryAtIndex(3));
618 EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry));
621 // Navigate a couple more times.
622 ExecuteSyncJSFunction(main_frame, "navigate_next()");
623 EXPECT_EQ(3, GetCurrentIndex());
624 ExecuteSyncJSFunction(main_frame, "navigate_next()");
625 EXPECT_EQ(4, GetCurrentIndex());
626 screenshot_manager()->WaitUntilScreenshotIsReady();
627 entry = NavigationEntryImpl::FromNavigationEntry(
628 web_contents->GetController().GetEntryAtIndex(4));
629 EXPECT_FALSE(entry->screenshot().get());
632 // Navigate back in history.
633 base::string16 expected_title = base::ASCIIToUTF16("Title: #3");
634 content::TitleWatcher title_watcher(web_contents, expected_title);
635 web_contents->GetController().GoBack();
636 base::string16 actual_title = title_watcher.WaitAndGetTitle();
637 EXPECT_EQ(expected_title, actual_title);
638 EXPECT_EQ(3, GetCurrentIndex());
639 screenshot_manager()->WaitUntilScreenshotIsReady();
640 entry = NavigationEntryImpl::FromNavigationEntry(
641 web_contents->GetController().GetEntryAtIndex(4));
642 EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry));
646 // Crashes under ThreadSanitizer, http://crbug.com/356758.
647 #if defined(THREAD_SANITIZER)
648 #define MAYBE_ScreenshotForSwappedOutRenderViews \
649 DISABLED_ScreenshotForSwappedOutRenderViews
650 #else
651 #define MAYBE_ScreenshotForSwappedOutRenderViews \
652 ScreenshotForSwappedOutRenderViews
653 #endif
654 // Tests that screenshot is taken correctly when navigation causes a
655 // RenderViewHost to be swapped out.
656 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
657 MAYBE_ScreenshotForSwappedOutRenderViews) {
658 ASSERT_NO_FATAL_FAILURE(
659 StartTestWithPage("files/overscroll_navigation.html"));
660 // Create a new server with a different site.
661 net::SpawnedTestServer https_server(
662 net::SpawnedTestServer::TYPE_HTTPS,
663 net::SpawnedTestServer::kLocalhost,
664 base::FilePath(FILE_PATH_LITERAL("content/test/data")));
665 ASSERT_TRUE(https_server.Start());
667 WebContentsImpl* web_contents =
668 static_cast<WebContentsImpl*>(shell()->web_contents());
669 set_min_screenshot_interval(0);
671 struct {
672 GURL url;
673 int transition;
674 } navigations[] = {
675 { https_server.GetURL("files/title1.html"),
676 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR },
677 { test_server()->GetURL("files/title2.html"),
678 ui::PAGE_TRANSITION_AUTO_BOOKMARK },
679 { https_server.GetURL("files/title3.html"),
680 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR },
681 { GURL(), 0 }
684 screenshot_manager()->Reset();
685 for (int i = 0; !navigations[i].url.is_empty(); ++i) {
686 // Navigate via the user initiating a navigation from the UI.
687 NavigationController::LoadURLParams params(navigations[i].url);
688 params.transition_type =
689 ui::PageTransitionFromInt(navigations[i].transition);
691 RenderViewHost* old_host = web_contents->GetRenderViewHost();
692 web_contents->GetController().LoadURLWithParams(params);
693 WaitForLoadStop(web_contents);
694 screenshot_manager()->WaitUntilScreenshotIsReady();
696 EXPECT_NE(old_host, web_contents->GetRenderViewHost())
697 << navigations[i].url.spec();
698 EXPECT_EQ(old_host, screenshot_manager()->screenshot_taken_for());
700 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
701 web_contents->GetController().GetEntryAtOffset(-1));
702 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry));
704 entry = NavigationEntryImpl::FromNavigationEntry(
705 web_contents->GetController().GetLastCommittedEntry());
706 EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry));
707 EXPECT_FALSE(entry->screenshot().get());
708 screenshot_manager()->Reset();
711 // Increase the minimum interval between taking screenshots.
712 set_min_screenshot_interval(60000);
714 // Navigate again. This should not take any screenshot because of the
715 // increased screenshot interval.
716 NavigationController::LoadURLParams params(navigations[0].url);
717 params.transition_type = ui::PageTransitionFromInt(navigations[0].transition);
718 web_contents->GetController().LoadURLWithParams(params);
719 WaitForLoadStop(web_contents);
720 screenshot_manager()->WaitUntilScreenshotIsReady();
722 EXPECT_EQ(NULL, screenshot_manager()->screenshot_taken_for());
725 // Tests that navigations resulting from reloads, history.replaceState,
726 // and history.pushState do not capture screenshots.
727 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, ReplaceStateReloadPushState) {
728 ASSERT_NO_FATAL_FAILURE(
729 StartTestWithPage("files/overscroll_navigation.html"));
730 WebContentsImpl* web_contents =
731 static_cast<WebContentsImpl*>(shell()->web_contents());
732 RenderFrameHost* main_frame = web_contents->GetMainFrame();
734 set_min_screenshot_interval(0);
735 screenshot_manager()->Reset();
736 ExecuteSyncJSFunction(main_frame, "use_replace_state()");
737 screenshot_manager()->WaitUntilScreenshotIsReady();
738 // history.replaceState shouldn't capture a screenshot
739 EXPECT_FALSE(screenshot_manager()->screenshot_taken_for());
740 screenshot_manager()->Reset();
741 web_contents->GetController().Reload(true);
742 WaitForLoadStop(web_contents);
743 // reloading the page shouldn't capture a screenshot
744 // TODO (mfomitchev): currently broken. Uncomment when
745 // FrameHostMsg_DidCommitProvisionalLoad_Params.was_within_same_page
746 // is populated properly when reloading the page.
747 //EXPECT_FALSE(screenshot_manager()->screenshot_taken_for());
748 screenshot_manager()->Reset();
749 ExecuteSyncJSFunction(main_frame, "use_push_state()");
750 screenshot_manager()->WaitUntilScreenshotIsReady();
751 // pushing a state shouldn't capture a screenshot
752 // TODO (mfomitchev): currently broken. Uncomment when
753 // FrameHostMsg_DidCommitProvisionalLoad_Params.was_within_same_page
754 // is populated properly when pushState is used.
755 //EXPECT_FALSE(screenshot_manager()->screenshot_taken_for());
758 // TODO(sadrul): This test is disabled because it reparents in a way the
759 // FocusController does not support. This code would crash in
760 // a production build. It only passed prior to this revision
761 // because testing used the old FocusManager which did some
762 // different (osbolete) processing. TODO(sadrul) to figure out
763 // how this test should work that mimics production code a bit
764 // better.
765 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
766 DISABLED_ContentWindowReparent) {
767 ASSERT_NO_FATAL_FAILURE(
768 StartTestWithPage("files/overscroll_navigation.html"));
770 scoped_ptr<aura::Window> window(new aura::Window(NULL));
771 window->Init(aura::WINDOW_LAYER_NOT_DRAWN);
773 WebContentsImpl* web_contents =
774 static_cast<WebContentsImpl*>(shell()->web_contents());
775 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()");
776 EXPECT_EQ(1, GetCurrentIndex());
778 aura::Window* content = web_contents->GetContentNativeView();
779 gfx::Rect bounds = content->GetBoundsInRootWindow();
780 ui::test::EventGenerator generator(content->GetRootWindow(), content);
781 generator.GestureScrollSequence(
782 gfx::Point(bounds.x() + 2, bounds.y() + 10),
783 gfx::Point(bounds.right() - 10, bounds.y() + 10),
784 base::TimeDelta::FromMilliseconds(20),
787 window->AddChild(shell()->web_contents()->GetContentNativeView());
790 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, ContentWindowClose) {
791 ASSERT_NO_FATAL_FAILURE(
792 StartTestWithPage("files/overscroll_navigation.html"));
794 WebContentsImpl* web_contents =
795 static_cast<WebContentsImpl*>(shell()->web_contents());
796 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()");
797 EXPECT_EQ(1, GetCurrentIndex());
799 aura::Window* content = web_contents->GetContentNativeView();
800 gfx::Rect bounds = content->GetBoundsInRootWindow();
801 ui::test::EventGenerator generator(content->GetRootWindow(), content);
802 generator.GestureScrollSequence(
803 gfx::Point(bounds.x() + 2, bounds.y() + 10),
804 gfx::Point(bounds.right() - 10, bounds.y() + 10),
805 base::TimeDelta::FromMilliseconds(20),
808 delete web_contents->GetContentNativeView();
812 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
813 // This appears to be flaky in the same was as the other overscroll
814 // tests. Enabling for non-Windows platforms.
815 // See http://crbug.com/369871.
816 // For linux, see http://crbug.com/381294
817 #define MAYBE_RepeatedQuickOverscrollGestures DISABLED_RepeatedQuickOverscrollGestures
818 #else
819 #define MAYBE_RepeatedQuickOverscrollGestures RepeatedQuickOverscrollGestures
820 #endif
822 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
823 MAYBE_RepeatedQuickOverscrollGestures) {
824 ASSERT_NO_FATAL_FAILURE(
825 StartTestWithPage("files/overscroll_navigation.html"));
827 WebContentsImpl* web_contents =
828 static_cast<WebContentsImpl*>(shell()->web_contents());
829 NavigationController& controller = web_contents->GetController();
830 RenderFrameHost* main_frame = web_contents->GetMainFrame();
831 ExecuteSyncJSFunction(main_frame, "install_touch_handler()");
833 // Navigate twice, then navigate back in history once.
834 ExecuteSyncJSFunction(main_frame, "navigate_next()");
835 ExecuteSyncJSFunction(main_frame, "navigate_next()");
836 EXPECT_EQ(2, GetCurrentIndex());
837 EXPECT_TRUE(controller.CanGoBack());
838 EXPECT_FALSE(controller.CanGoForward());
840 web_contents->GetController().GoBack();
841 WaitForLoadStop(web_contents);
842 EXPECT_EQ(1, GetCurrentIndex());
843 EXPECT_EQ(base::ASCIIToUTF16("Title: #1"), web_contents->GetTitle());
844 EXPECT_TRUE(controller.CanGoBack());
845 EXPECT_TRUE(controller.CanGoForward());
847 aura::Window* content = web_contents->GetContentNativeView();
848 gfx::Rect bounds = content->GetBoundsInRootWindow();
849 ui::test::EventGenerator generator(content->GetRootWindow(), content);
851 // Do a swipe left to start a forward navigation. Then quickly do a swipe
852 // right.
853 base::string16 expected_title = base::ASCIIToUTF16("Title: #2");
854 content::TitleWatcher title_watcher(web_contents, expected_title);
855 NavigationWatcher nav_watcher(web_contents);
857 generator.GestureScrollSequence(
858 gfx::Point(bounds.right() - 10, bounds.y() + 10),
859 gfx::Point(bounds.x() + 2, bounds.y() + 10),
860 base::TimeDelta::FromMilliseconds(2000),
861 10);
862 nav_watcher.WaitUntilNavigationStarts();
864 generator.GestureScrollSequence(
865 gfx::Point(bounds.x() + 2, bounds.y() + 10),
866 gfx::Point(bounds.right() - 10, bounds.y() + 10),
867 base::TimeDelta::FromMilliseconds(2000),
868 10);
869 base::string16 actual_title = title_watcher.WaitAndGetTitle();
870 EXPECT_EQ(expected_title, actual_title);
872 EXPECT_EQ(2, GetCurrentIndex());
873 EXPECT_TRUE(controller.CanGoBack());
874 EXPECT_FALSE(controller.CanGoForward());
877 // Verify that hiding a parent of the renderer will hide the content too.
878 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, HideContentOnParenHide) {
879 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/title1.html"));
880 WebContentsImpl* web_contents =
881 static_cast<WebContentsImpl*>(shell()->web_contents());
882 aura::Window* content = web_contents->GetNativeView()->parent();
883 EXPECT_TRUE(web_contents->should_normally_be_visible());
884 content->Hide();
885 EXPECT_FALSE(web_contents->should_normally_be_visible());
886 content->Show();
887 EXPECT_TRUE(web_contents->should_normally_be_visible());
890 // Ensure that SnapToPhysicalPixelBoundary() is called on WebContentsView parent
891 // change. This is a regression test for http://crbug.com/388908.
892 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, WebContentsViewReparent) {
893 ASSERT_NO_FATAL_FAILURE(
894 StartTestWithPage("files/overscroll_navigation.html"));
896 scoped_ptr<aura::Window> window(new aura::Window(NULL));
897 window->Init(aura::WINDOW_LAYER_NOT_DRAWN);
899 RenderWidgetHostViewAura* rwhva =
900 static_cast<RenderWidgetHostViewAura*>(
901 shell()->web_contents()->GetRenderWidgetHostView());
902 rwhva->ResetHasSnappedToBoundary();
903 EXPECT_FALSE(rwhva->has_snapped_to_boundary());
904 window->AddChild(shell()->web_contents()->GetNativeView());
905 EXPECT_TRUE(rwhva->has_snapped_to_boundary());
908 // Flaky on some platforms, likely for the same reason as other flaky overscroll
909 // tests. http://crbug.com/305722
910 // TODO(tdresser): Re-enable this once eager GR is back on. See
911 // crbug.com/410280.
912 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
913 #define MAYBE_OverscrollNavigationTouchThrottling \
914 DISABLED_OverscrollNavigationTouchThrottling
915 #else
916 #define MAYBE_OverscrollNavigationTouchThrottling \
917 DISABLED_OverscrollNavigationTouchThrottling
918 #endif
920 // Tests that touch moves are not throttled when performing a scroll gesture on
921 // a non-scrollable area, except during gesture-nav.
922 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
923 MAYBE_OverscrollNavigationTouchThrottling) {
924 ASSERT_NO_FATAL_FAILURE(
925 StartTestWithPage("files/overscroll_navigation.html"));
927 AddInputEventMessageFilter();
929 WebContentsImpl* web_contents =
930 static_cast<WebContentsImpl*>(shell()->web_contents());
931 aura::Window* content = web_contents->GetContentNativeView();
932 gfx::Rect bounds = content->GetBoundsInRootWindow();
933 const int dx = 20;
935 ExecuteSyncJSFunction(web_contents->GetMainFrame(),
936 "install_touchmove_handler()");
938 WaitAFrame();
940 for (int navigated = 0; navigated <= 1; ++navigated) {
941 if (navigated) {
942 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()");
943 ExecuteSyncJSFunction(web_contents->GetMainFrame(),
944 "reset_touchmove_count()");
946 // Send touch press.
947 SyntheticWebTouchEvent touch;
948 touch.PressPoint(bounds.x() + 2, bounds.y() + 10);
949 GetRenderWidgetHost()->ForwardTouchEventWithLatencyInfo(touch,
950 ui::LatencyInfo());
951 filter()->WaitForAck(blink::WebInputEvent::TouchStart);
952 WaitAFrame();
954 // Assert on the ack, because we'll end up waiting for acks that will never
955 // come if this is not true.
956 ASSERT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, filter()->last_ack_state());
958 // Send first touch move, and then a scroll begin.
959 touch.MovePoint(0, bounds.x() + 20 + 1 * dx, bounds.y() + 100);
960 GetRenderWidgetHost()->ForwardTouchEventWithLatencyInfo(touch,
961 ui::LatencyInfo());
962 filter()->WaitForAck(blink::WebInputEvent::TouchMove);
963 ASSERT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, filter()->last_ack_state());
965 blink::WebGestureEvent scroll_begin =
966 SyntheticWebGestureEventBuilder::BuildScrollBegin(1, 1);
967 GetRenderWidgetHost()->ForwardGestureEventWithLatencyInfo(
968 scroll_begin, ui::LatencyInfo());
969 // Scroll begin ignores ack disposition, so don't wait for the ack.
970 WaitAFrame();
972 // First touchmove already sent, start at 2.
973 for (int i = 2; i <= 10; ++i) {
974 // Send a touch move, followed by a scroll update
975 touch.MovePoint(0, bounds.x() + 20 + i * dx, bounds.y() + 100);
976 GetRenderWidgetHost()->ForwardTouchEventWithLatencyInfo(
977 touch, ui::LatencyInfo());
978 WaitAFrame();
980 blink::WebGestureEvent scroll_update =
981 SyntheticWebGestureEventBuilder::BuildScrollUpdate(dx, 5, 0);
983 GetRenderWidgetHost()->ForwardGestureEventWithLatencyInfo(
984 scroll_update, ui::LatencyInfo());
986 WaitAFrame();
989 touch.ReleasePoint(0);
990 GetRenderWidgetHost()->ForwardTouchEventWithLatencyInfo(touch,
991 ui::LatencyInfo());
992 WaitAFrame();
994 blink::WebGestureEvent scroll_end;
995 scroll_end.type = blink::WebInputEvent::GestureScrollEnd;
996 GetRenderWidgetHost()->ForwardGestureEventWithLatencyInfo(
997 scroll_end, ui::LatencyInfo());
998 WaitAFrame();
1000 if (!navigated)
1001 EXPECT_EQ(10, ExecuteScriptAndExtractInt("touchmoveCount"));
1002 else
1003 EXPECT_GT(10, ExecuteScriptAndExtractInt("touchmoveCount"));
1007 // Test that vertical overscroll updates are sent only when a user overscrolls
1008 // vertically.
1009 #if defined(OS_WIN)
1010 #define MAYBE_VerticalOverscroll DISABLED_VerticalOverscroll
1011 #else
1012 #define MAYBE_VerticalOverscroll VerticalOverscroll
1013 #endif
1015 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, MAYBE_VerticalOverscroll) {
1016 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1017 switches::kScrollEndEffect, "1");
1019 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("about:blank"));
1020 WebContentsImpl* web_contents =
1021 static_cast<WebContentsImpl*>(shell()->web_contents());
1022 VerticalOverscrollTracker tracker;
1023 web_contents->SetDelegate(&tracker);
1025 // This test triggers a large number of animations. Speed them up to ensure
1026 // the test completes within its time limit.
1027 ui::ScopedAnimationDurationScaleMode fast_duration_mode(
1028 ui::ScopedAnimationDurationScaleMode::FAST_DURATION);
1030 aura::Window* content = web_contents->GetContentNativeView();
1031 ui::EventProcessor* dispatcher = content->GetHost()->event_processor();
1032 gfx::Rect bounds = content->GetBoundsInRootWindow();
1034 // Overscroll horizontally.
1036 int kXStep = bounds.width() / 10;
1037 gfx::Point location(bounds.right() - kXStep, bounds.y() + 5);
1038 base::TimeDelta timestamp = ui::EventTimeForNow();
1039 ui::TouchEvent press(
1040 ui::ET_TOUCH_PRESSED,
1041 location,
1043 timestamp);
1044 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press);
1045 ASSERT_FALSE(details.dispatcher_destroyed);
1046 WaitAFrame();
1047 location -= gfx::Vector2d(kXStep, 0);
1048 timestamp += base::TimeDelta::FromMilliseconds(10);
1050 while (location.x() > bounds.x() + kXStep) {
1051 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, location, 0, timestamp);
1052 details = dispatcher->OnEventFromSource(&inc);
1053 ASSERT_FALSE(details.dispatcher_destroyed);
1054 WaitAFrame();
1055 location -= gfx::Vector2d(10, 0);
1056 timestamp += base::TimeDelta::FromMilliseconds(10);
1059 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, location, 0, timestamp);
1060 details = dispatcher->OnEventFromSource(&press);
1061 ASSERT_FALSE(details.dispatcher_destroyed);
1062 WaitAFrame();
1064 EXPECT_EQ(0, tracker.num_overscroll_updates());
1065 EXPECT_FALSE(tracker.overscroll_completed());
1068 // Overscroll vertically.
1070 tracker.Reset();
1072 int kYStep = bounds.height() / 10;
1073 gfx::Point location(bounds.x() + 10, bounds.y() + kYStep);
1074 base::TimeDelta timestamp = ui::EventTimeForNow();
1075 ui::TouchEvent press(
1076 ui::ET_TOUCH_PRESSED,
1077 location,
1079 timestamp);
1080 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press);
1081 ASSERT_FALSE(details.dispatcher_destroyed);
1082 WaitAFrame();
1083 location += gfx::Vector2d(0, kYStep);
1084 timestamp += base::TimeDelta::FromMilliseconds(10);
1086 while (location.y() < bounds.bottom() - kYStep) {
1087 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, location, 0, timestamp);
1088 details = dispatcher->OnEventFromSource(&inc);
1089 ASSERT_FALSE(details.dispatcher_destroyed);
1090 WaitAFrame();
1091 location += gfx::Vector2d(0, kYStep);
1092 timestamp += base::TimeDelta::FromMilliseconds(10);
1095 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, location, 0, timestamp);
1096 details = dispatcher->OnEventFromSource(&release);
1097 ASSERT_FALSE(details.dispatcher_destroyed);
1098 WaitAFrame();
1100 EXPECT_LT(0, tracker.num_overscroll_updates());
1101 EXPECT_TRUE(tracker.overscroll_completed());
1104 // Start out overscrolling vertically, then switch directions and finish
1105 // overscrolling horizontally.
1107 tracker.Reset();
1109 int kXStep = bounds.width() / 10;
1110 int kYStep = bounds.height() / 10;
1111 gfx::Point location = bounds.origin() + gfx::Vector2d(0, kYStep);
1112 base::TimeDelta timestamp = ui::EventTimeForNow();
1113 ui::TouchEvent press(
1114 ui::ET_TOUCH_PRESSED,
1115 location,
1117 timestamp);
1118 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press);
1119 ASSERT_FALSE(details.dispatcher_destroyed);
1120 WaitAFrame();
1121 location += gfx::Vector2d(0, kYStep);
1122 timestamp += base::TimeDelta::FromMilliseconds(10);
1124 for (size_t i = 0; i < 3; ++i) {
1125 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, location, 0, timestamp);
1126 details = dispatcher->OnEventFromSource(&inc);
1127 ASSERT_FALSE(details.dispatcher_destroyed);
1128 WaitAFrame();
1129 location += gfx::Vector2d(0, kYStep);
1130 timestamp += base::TimeDelta::FromMilliseconds(10);
1133 while (location.x() < bounds.right() - kXStep) {
1134 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, location, 0, timestamp);
1135 details = dispatcher->OnEventFromSource(&inc);
1136 ASSERT_FALSE(details.dispatcher_destroyed);
1137 WaitAFrame();
1138 location += gfx::Vector2d(kXStep, 0);
1139 timestamp += base::TimeDelta::FromMilliseconds(10);
1142 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, location, 0, timestamp);
1143 details = dispatcher->OnEventFromSource(&release);
1144 ASSERT_FALSE(details.dispatcher_destroyed);
1145 WaitAFrame();
1147 EXPECT_LT(0, tracker.num_overscroll_updates());
1148 EXPECT_FALSE(tracker.overscroll_completed());
1152 } // namespace content