Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / content / browser / web_contents / web_contents_view_aura_browsertest.cc
blobc20a888ee93e8e23124e8ba631fffa0cfb64c562
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/web_contents/web_contents_impl.h"
19 #include "content/browser/web_contents/web_contents_view.h"
20 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/web_contents_observer.h"
22 #include "content/public/common/content_switches.h"
23 #include "content/public/test/browser_test_utils.h"
24 #include "content/public/test/content_browser_test.h"
25 #include "content/public/test/content_browser_test_utils.h"
26 #include "content/public/test/test_utils.h"
27 #include "content/shell/browser/shell.h"
28 #include "ui/aura/test/event_generator.h"
29 #include "ui/aura/window.h"
30 #include "ui/aura/window_tree_host.h"
31 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
32 #include "ui/events/event_processor.h"
34 namespace content {
36 // This class keeps track of the RenderViewHost whose screenshot was captured.
37 class ScreenshotTracker : public NavigationEntryScreenshotManager {
38 public:
39 explicit ScreenshotTracker(NavigationControllerImpl* controller)
40 : NavigationEntryScreenshotManager(controller),
41 screenshot_taken_for_(NULL),
42 waiting_for_screenshots_(0) {
45 virtual ~ScreenshotTracker() {
48 RenderViewHost* screenshot_taken_for() { return screenshot_taken_for_; }
50 void Reset() {
51 screenshot_taken_for_ = NULL;
52 screenshot_set_.clear();
55 void SetScreenshotInterval(int interval_ms) {
56 SetMinScreenshotIntervalMS(interval_ms);
59 void WaitUntilScreenshotIsReady() {
60 if (!waiting_for_screenshots_)
61 return;
62 message_loop_runner_ = new content::MessageLoopRunner;
63 message_loop_runner_->Run();
66 bool ScreenshotSetForEntry(NavigationEntryImpl* entry) const {
67 return screenshot_set_.count(entry) > 0;
70 private:
71 // Overridden from NavigationEntryScreenshotManager:
72 virtual void TakeScreenshotImpl(RenderViewHost* host,
73 NavigationEntryImpl* entry) OVERRIDE {
74 ++waiting_for_screenshots_;
75 screenshot_taken_for_ = host;
76 NavigationEntryScreenshotManager::TakeScreenshotImpl(host, entry);
79 virtual void OnScreenshotSet(NavigationEntryImpl* entry) OVERRIDE {
80 --waiting_for_screenshots_;
81 screenshot_set_[entry] = true;
82 NavigationEntryScreenshotManager::OnScreenshotSet(entry);
83 if (waiting_for_screenshots_ == 0 && message_loop_runner_.get())
84 message_loop_runner_->Quit();
87 RenderViewHost* screenshot_taken_for_;
88 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
89 int waiting_for_screenshots_;
90 std::map<NavigationEntryImpl*, bool> screenshot_set_;
92 DISALLOW_COPY_AND_ASSIGN(ScreenshotTracker);
95 class NavigationWatcher : public WebContentsObserver {
96 public:
97 explicit NavigationWatcher(WebContents* contents)
98 : WebContentsObserver(contents),
99 navigated_(false),
100 should_quit_loop_(false) {
103 virtual ~NavigationWatcher() {}
105 void WaitUntilNavigationStarts() {
106 if (navigated_)
107 return;
108 should_quit_loop_ = true;
109 base::MessageLoop::current()->Run();
112 private:
113 // Overridden from WebContentsObserver:
114 virtual void AboutToNavigateRenderView(RenderViewHost* host) OVERRIDE {
115 navigated_ = true;
116 if (should_quit_loop_)
117 base::MessageLoop::current()->Quit();
120 bool navigated_;
121 bool should_quit_loop_;
123 DISALLOW_COPY_AND_ASSIGN(NavigationWatcher);
126 class WebContentsViewAuraTest : public ContentBrowserTest {
127 public:
128 WebContentsViewAuraTest()
129 : screenshot_manager_(NULL) {
132 // Executes the javascript synchronously and makes sure the returned value is
133 // freed properly.
134 void ExecuteSyncJSFunction(RenderFrameHost* rfh, const std::string& jscript) {
135 scoped_ptr<base::Value> value =
136 content::ExecuteScriptAndGetValue(rfh, jscript);
139 // Starts the test server and navigates to the given url. Sets a large enough
140 // size to the root window. Returns after the navigation to the url is
141 // complete.
142 void StartTestWithPage(const std::string& url) {
143 ASSERT_TRUE(test_server()->Start());
144 GURL test_url(test_server()->GetURL(url));
145 NavigateToURL(shell(), test_url);
147 WebContentsImpl* web_contents =
148 static_cast<WebContentsImpl*>(shell()->web_contents());
149 NavigationControllerImpl* controller = &web_contents->GetController();
151 screenshot_manager_ = new ScreenshotTracker(controller);
152 controller->SetScreenshotManager(screenshot_manager_);
155 void TestOverscrollNavigation(bool touch_handler) {
156 ASSERT_NO_FATAL_FAILURE(
157 StartTestWithPage("files/overscroll_navigation.html"));
158 WebContentsImpl* web_contents =
159 static_cast<WebContentsImpl*>(shell()->web_contents());
160 NavigationController& controller = web_contents->GetController();
161 RenderFrameHost* main_frame = web_contents->GetMainFrame();
162 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>(
163 web_contents->GetView());
164 view_aura->SetupOverlayWindowForTesting();
166 EXPECT_FALSE(controller.CanGoBack());
167 EXPECT_FALSE(controller.CanGoForward());
168 int index = -1;
169 scoped_ptr<base::Value> value =
170 content::ExecuteScriptAndGetValue(main_frame, "get_current()");
171 ASSERT_TRUE(value->GetAsInteger(&index));
172 EXPECT_EQ(0, index);
174 if (touch_handler)
175 ExecuteSyncJSFunction(main_frame, "install_touch_handler()");
177 ExecuteSyncJSFunction(main_frame, "navigate_next()");
178 ExecuteSyncJSFunction(main_frame, "navigate_next()");
179 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()");
180 ASSERT_TRUE(value->GetAsInteger(&index));
181 EXPECT_EQ(2, index);
182 EXPECT_TRUE(controller.CanGoBack());
183 EXPECT_FALSE(controller.CanGoForward());
185 aura::Window* content = web_contents->GetContentNativeView();
186 gfx::Rect bounds = content->GetBoundsInRootWindow();
187 aura::test::EventGenerator generator(content->GetRootWindow(), content);
188 const int kScrollDurationMs = 20;
189 const int kScrollSteps = 10;
192 // Do a swipe-right now. That should navigate backwards.
193 base::string16 expected_title = base::ASCIIToUTF16("Title: #1");
194 content::TitleWatcher title_watcher(web_contents, expected_title);
195 generator.GestureScrollSequence(
196 gfx::Point(bounds.x() + 2, bounds.y() + 10),
197 gfx::Point(bounds.right() - 10, bounds.y() + 10),
198 base::TimeDelta::FromMilliseconds(kScrollDurationMs),
199 kScrollSteps);
200 base::string16 actual_title = title_watcher.WaitAndGetTitle();
201 EXPECT_EQ(expected_title, actual_title);
202 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()");
203 ASSERT_TRUE(value->GetAsInteger(&index));
204 EXPECT_EQ(1, index);
205 EXPECT_TRUE(controller.CanGoBack());
206 EXPECT_TRUE(controller.CanGoForward());
210 // Do a fling-right now. That should navigate backwards.
211 base::string16 expected_title = base::ASCIIToUTF16("Title:");
212 content::TitleWatcher title_watcher(web_contents, expected_title);
213 generator.GestureScrollSequence(
214 gfx::Point(bounds.x() + 2, bounds.y() + 10),
215 gfx::Point(bounds.right() - 10, bounds.y() + 10),
216 base::TimeDelta::FromMilliseconds(kScrollDurationMs),
217 kScrollSteps);
218 base::string16 actual_title = title_watcher.WaitAndGetTitle();
219 EXPECT_EQ(expected_title, actual_title);
220 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()");
221 ASSERT_TRUE(value->GetAsInteger(&index));
222 EXPECT_EQ(0, index);
223 EXPECT_FALSE(controller.CanGoBack());
224 EXPECT_TRUE(controller.CanGoForward());
228 // Do a swipe-left now. That should navigate forward.
229 base::string16 expected_title = base::ASCIIToUTF16("Title: #1");
230 content::TitleWatcher title_watcher(web_contents, expected_title);
231 generator.GestureScrollSequence(
232 gfx::Point(bounds.right() - 10, bounds.y() + 10),
233 gfx::Point(bounds.x() + 2, bounds.y() + 10),
234 base::TimeDelta::FromMilliseconds(kScrollDurationMs),
235 kScrollSteps);
236 base::string16 actual_title = title_watcher.WaitAndGetTitle();
237 EXPECT_EQ(expected_title, actual_title);
238 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()");
239 ASSERT_TRUE(value->GetAsInteger(&index));
240 EXPECT_EQ(1, index);
241 EXPECT_TRUE(controller.CanGoBack());
242 EXPECT_TRUE(controller.CanGoForward());
246 int GetCurrentIndex() {
247 WebContentsImpl* web_contents =
248 static_cast<WebContentsImpl*>(shell()->web_contents());
249 RenderFrameHost* main_frame = web_contents->GetMainFrame();
250 int index = -1;
251 scoped_ptr<base::Value> value;
252 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()");
253 if (!value->GetAsInteger(&index))
254 index = -1;
255 return index;
258 protected:
259 ScreenshotTracker* screenshot_manager() { return screenshot_manager_; }
260 void set_min_screenshot_interval(int interval_ms) {
261 screenshot_manager_->SetScreenshotInterval(interval_ms);
264 private:
265 ScreenshotTracker* screenshot_manager_;
267 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAuraTest);
270 // Flaky on Windows (perhaps just Win-Aura): http://crbug.com/305722
271 #if defined(OS_WIN)
272 #define MAYBE_OverscrollNavigation DISABLED_OverscrollNavigation
273 #else
274 #define MAYBE_OverscrollNavigation OverscrollNavigation
275 #endif
276 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, MAYBE_OverscrollNavigation) {
277 TestOverscrollNavigation(false);
280 // Flaky on Windows (perhaps just Win-Aura): http://crbug.com/305722
281 #if defined(OS_WIN)
282 #define MAYBE_OverscrollNavigationWithTouchHandler \
283 DISABLED_OverscrollNavigationWithTouchHandler
284 #else
285 #define MAYBE_OverscrollNavigationWithTouchHandler \
286 OverscrollNavigationWithTouchHandler
287 #endif
288 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
289 MAYBE_OverscrollNavigationWithTouchHandler) {
290 TestOverscrollNavigation(true);
293 // Disabled because the test always fails the first time it runs on the Win Aura
294 // bots, and usually but not always passes second-try (See crbug.com/179532).
295 #if defined(OS_WIN)
296 #define MAYBE_QuickOverscrollDirectionChange \
297 DISABLED_QuickOverscrollDirectionChange
298 #else
299 #define MAYBE_QuickOverscrollDirectionChange QuickOverscrollDirectionChange
300 #endif
301 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
302 MAYBE_QuickOverscrollDirectionChange) {
303 ASSERT_NO_FATAL_FAILURE(
304 StartTestWithPage("files/overscroll_navigation.html"));
305 WebContentsImpl* web_contents =
306 static_cast<WebContentsImpl*>(shell()->web_contents());
307 RenderFrameHost* main_frame = web_contents->GetMainFrame();
309 // This test triggers a large number of animations. Speed them up to ensure
310 // the test completes within its time limit.
311 ui::ScopedAnimationDurationScaleMode fast_duration_mode(
312 ui::ScopedAnimationDurationScaleMode::FAST_DURATION);
314 // Make sure the page has both back/forward history.
315 ExecuteSyncJSFunction(main_frame, "navigate_next()");
316 EXPECT_EQ(1, GetCurrentIndex());
317 ExecuteSyncJSFunction(main_frame, "navigate_next()");
318 EXPECT_EQ(2, GetCurrentIndex());
319 web_contents->GetController().GoBack();
320 EXPECT_EQ(1, GetCurrentIndex());
322 aura::Window* content = web_contents->GetContentNativeView();
323 ui::EventProcessor* dispatcher = content->GetHost()->event_processor();
324 gfx::Rect bounds = content->GetBoundsInRootWindow();
326 base::TimeDelta timestamp;
327 ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
328 gfx::Point(bounds.x() + bounds.width() / 2, bounds.y() + 5),
329 0, timestamp);
330 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press);
331 ASSERT_FALSE(details.dispatcher_destroyed);
332 EXPECT_EQ(1, GetCurrentIndex());
334 timestamp += base::TimeDelta::FromMilliseconds(10);
335 ui::TouchEvent move1(ui::ET_TOUCH_MOVED,
336 gfx::Point(bounds.right() - 10, bounds.y() + 5),
337 0, timestamp);
338 details = dispatcher->OnEventFromSource(&move1);
339 ASSERT_FALSE(details.dispatcher_destroyed);
340 EXPECT_EQ(1, GetCurrentIndex());
342 // Swipe back from the right edge, back to the left edge, back to the right
343 // edge.
345 for (int x = bounds.right() - 10; x >= bounds.x() + 10; x-= 10) {
346 timestamp += base::TimeDelta::FromMilliseconds(10);
347 ui::TouchEvent inc(ui::ET_TOUCH_MOVED,
348 gfx::Point(x, bounds.y() + 5),
349 0, timestamp);
350 details = dispatcher->OnEventFromSource(&inc);
351 ASSERT_FALSE(details.dispatcher_destroyed);
352 EXPECT_EQ(1, GetCurrentIndex());
355 for (int x = bounds.x() + 10; x <= bounds.width() - 10; x+= 10) {
356 timestamp += base::TimeDelta::FromMilliseconds(10);
357 ui::TouchEvent inc(ui::ET_TOUCH_MOVED,
358 gfx::Point(x, bounds.y() + 5),
359 0, timestamp);
360 details = dispatcher->OnEventFromSource(&inc);
361 ASSERT_FALSE(details.dispatcher_destroyed);
362 EXPECT_EQ(1, GetCurrentIndex());
365 for (int x = bounds.width() - 10; x >= bounds.x() + 10; x-= 10) {
366 timestamp += base::TimeDelta::FromMilliseconds(10);
367 ui::TouchEvent inc(ui::ET_TOUCH_MOVED,
368 gfx::Point(x, bounds.y() + 5),
369 0, timestamp);
370 details = dispatcher->OnEventFromSource(&inc);
371 ASSERT_FALSE(details.dispatcher_destroyed);
372 EXPECT_EQ(1, GetCurrentIndex());
375 // Do not end the overscroll sequence.
378 // Tests that the page has has a screenshot when navigation happens:
379 // - from within the page (from a JS function)
380 // - interactively, when user does an overscroll gesture
381 // - interactively, when user navigates in history without the overscroll
382 // gesture.
383 #if defined(OS_WIN)
384 // http://crbug.com/357311
385 #define MAYBE_OverscrollScreenshot DISABLED_OverscrollScreenshot
386 #else
387 #define MAYBE_OverscrollScreenshot OverscrollScreenshot
388 #endif
389 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, MAYBE_OverscrollScreenshot) {
390 // Disable the test for WinXP. See http://crbug/294116.
391 #if defined(OS_WIN)
392 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
393 LOG(WARNING) << "Test disabled due to unknown bug on WinXP.";
394 return;
396 #endif
398 ASSERT_NO_FATAL_FAILURE(
399 StartTestWithPage("files/overscroll_navigation.html"));
400 WebContentsImpl* web_contents =
401 static_cast<WebContentsImpl*>(shell()->web_contents());
402 RenderFrameHost* main_frame = web_contents->GetMainFrame();
404 set_min_screenshot_interval(0);
406 // Do a few navigations initiated by the page.
407 ExecuteSyncJSFunction(main_frame, "navigate_next()");
408 EXPECT_EQ(1, GetCurrentIndex());
409 ExecuteSyncJSFunction(main_frame, "navigate_next()");
410 EXPECT_EQ(2, GetCurrentIndex());
411 screenshot_manager()->WaitUntilScreenshotIsReady();
413 // The current entry won't have any screenshots. But the entries in the
414 // history should now have screenshots.
415 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
416 web_contents->GetController().GetEntryAtIndex(2));
417 EXPECT_FALSE(entry->screenshot().get());
419 entry = NavigationEntryImpl::FromNavigationEntry(
420 web_contents->GetController().GetEntryAtIndex(1));
421 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry));
423 entry = NavigationEntryImpl::FromNavigationEntry(
424 web_contents->GetController().GetEntryAtIndex(0));
425 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry));
427 // Navigate again. Index 2 should now have a screenshot.
428 ExecuteSyncJSFunction(main_frame, "navigate_next()");
429 EXPECT_EQ(3, GetCurrentIndex());
430 screenshot_manager()->WaitUntilScreenshotIsReady();
432 entry = NavigationEntryImpl::FromNavigationEntry(
433 web_contents->GetController().GetEntryAtIndex(2));
434 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry));
436 entry = NavigationEntryImpl::FromNavigationEntry(
437 web_contents->GetController().GetEntryAtIndex(3));
438 EXPECT_FALSE(entry->screenshot().get());
441 // Now, swipe right to navigate backwards. This should navigate away from
442 // index 3 to index 2, and index 3 should have a screenshot.
443 base::string16 expected_title = base::ASCIIToUTF16("Title: #2");
444 content::TitleWatcher title_watcher(web_contents, expected_title);
445 aura::Window* content = web_contents->GetContentNativeView();
446 gfx::Rect bounds = content->GetBoundsInRootWindow();
447 aura::test::EventGenerator generator(content->GetRootWindow(), content);
448 generator.GestureScrollSequence(
449 gfx::Point(bounds.x() + 2, bounds.y() + 10),
450 gfx::Point(bounds.right() - 10, bounds.y() + 10),
451 base::TimeDelta::FromMilliseconds(20),
453 base::string16 actual_title = title_watcher.WaitAndGetTitle();
454 EXPECT_EQ(expected_title, actual_title);
455 EXPECT_EQ(2, GetCurrentIndex());
456 screenshot_manager()->WaitUntilScreenshotIsReady();
457 entry = NavigationEntryImpl::FromNavigationEntry(
458 web_contents->GetController().GetEntryAtIndex(3));
459 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry));
462 // Navigate a couple more times.
463 ExecuteSyncJSFunction(main_frame, "navigate_next()");
464 EXPECT_EQ(3, GetCurrentIndex());
465 ExecuteSyncJSFunction(main_frame, "navigate_next()");
466 EXPECT_EQ(4, GetCurrentIndex());
467 screenshot_manager()->WaitUntilScreenshotIsReady();
468 entry = NavigationEntryImpl::FromNavigationEntry(
469 web_contents->GetController().GetEntryAtIndex(4));
470 EXPECT_FALSE(entry->screenshot().get());
473 // Navigate back in history.
474 base::string16 expected_title = base::ASCIIToUTF16("Title: #3");
475 content::TitleWatcher title_watcher(web_contents, expected_title);
476 web_contents->GetController().GoBack();
477 base::string16 actual_title = title_watcher.WaitAndGetTitle();
478 EXPECT_EQ(expected_title, actual_title);
479 EXPECT_EQ(3, GetCurrentIndex());
480 screenshot_manager()->WaitUntilScreenshotIsReady();
481 entry = NavigationEntryImpl::FromNavigationEntry(
482 web_contents->GetController().GetEntryAtIndex(4));
483 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry));
487 // Crashes under ThreadSanitizer, http://crbug.com/356758.
488 #if defined(THREAD_SANITIZER)
489 #define MAYBE_ScreenshotForSwappedOutRenderViews \
490 DISABLED_ScreenshotForSwappedOutRenderViews
491 #else
492 #define MAYBE_ScreenshotForSwappedOutRenderViews \
493 ScreenshotForSwappedOutRenderViews
494 #endif
495 // Tests that screenshot is taken correctly when navigation causes a
496 // RenderViewHost to be swapped out.
497 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
498 MAYBE_ScreenshotForSwappedOutRenderViews) {
499 ASSERT_NO_FATAL_FAILURE(
500 StartTestWithPage("files/overscroll_navigation.html"));
501 // Create a new server with a different site.
502 net::SpawnedTestServer https_server(
503 net::SpawnedTestServer::TYPE_HTTPS,
504 net::SpawnedTestServer::kLocalhost,
505 base::FilePath(FILE_PATH_LITERAL("content/test/data")));
506 ASSERT_TRUE(https_server.Start());
508 WebContentsImpl* web_contents =
509 static_cast<WebContentsImpl*>(shell()->web_contents());
510 set_min_screenshot_interval(0);
512 struct {
513 GURL url;
514 int transition;
515 } navigations[] = {
516 { https_server.GetURL("files/title1.html"),
517 PAGE_TRANSITION_TYPED | PAGE_TRANSITION_FROM_ADDRESS_BAR },
518 { test_server()->GetURL("files/title2.html"),
519 PAGE_TRANSITION_AUTO_BOOKMARK },
520 { https_server.GetURL("files/title3.html"),
521 PAGE_TRANSITION_TYPED | PAGE_TRANSITION_FROM_ADDRESS_BAR },
522 { GURL(), 0 }
525 screenshot_manager()->Reset();
526 for (int i = 0; !navigations[i].url.is_empty(); ++i) {
527 // Navigate via the user initiating a navigation from the UI.
528 NavigationController::LoadURLParams params(navigations[i].url);
529 params.transition_type = PageTransitionFromInt(navigations[i].transition);
531 RenderViewHost* old_host = web_contents->GetRenderViewHost();
532 web_contents->GetController().LoadURLWithParams(params);
533 WaitForLoadStop(web_contents);
534 screenshot_manager()->WaitUntilScreenshotIsReady();
536 EXPECT_NE(old_host, web_contents->GetRenderViewHost())
537 << navigations[i].url.spec();
538 EXPECT_EQ(old_host, screenshot_manager()->screenshot_taken_for());
540 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
541 web_contents->GetController().GetEntryAtOffset(-1));
542 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry));
544 entry = NavigationEntryImpl::FromNavigationEntry(
545 web_contents->GetController().GetLastCommittedEntry());
546 EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry));
547 EXPECT_FALSE(entry->screenshot().get());
548 screenshot_manager()->Reset();
551 // Increase the minimum interval between taking screenshots.
552 set_min_screenshot_interval(60000);
554 // Navigate again. This should not take any screenshot because of the
555 // increased screenshot interval.
556 NavigationController::LoadURLParams params(navigations[0].url);
557 params.transition_type = PageTransitionFromInt(navigations[0].transition);
558 web_contents->GetController().LoadURLWithParams(params);
559 WaitForLoadStop(web_contents);
560 screenshot_manager()->WaitUntilScreenshotIsReady();
562 EXPECT_EQ(NULL, screenshot_manager()->screenshot_taken_for());
565 // TODO(sadrul): This test is disabled because it reparents in a way the
566 // FocusController does not support. This code would crash in
567 // a production build. It only passed prior to this revision
568 // because testing used the old FocusManager which did some
569 // different (osbolete) processing. TODO(sadrul) to figure out
570 // how this test should work that mimics production code a bit
571 // better.
572 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
573 DISABLED_ContentWindowReparent) {
574 ASSERT_NO_FATAL_FAILURE(
575 StartTestWithPage("files/overscroll_navigation.html"));
577 scoped_ptr<aura::Window> window(new aura::Window(NULL));
578 window->Init(aura::WINDOW_LAYER_NOT_DRAWN);
580 WebContentsImpl* web_contents =
581 static_cast<WebContentsImpl*>(shell()->web_contents());
582 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()");
583 EXPECT_EQ(1, GetCurrentIndex());
585 aura::Window* content = web_contents->GetContentNativeView();
586 gfx::Rect bounds = content->GetBoundsInRootWindow();
587 aura::test::EventGenerator generator(content->GetRootWindow(), content);
588 generator.GestureScrollSequence(
589 gfx::Point(bounds.x() + 2, bounds.y() + 10),
590 gfx::Point(bounds.right() - 10, bounds.y() + 10),
591 base::TimeDelta::FromMilliseconds(20),
594 window->AddChild(shell()->web_contents()->GetContentNativeView());
597 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
598 ContentWindowClose) {
599 ASSERT_NO_FATAL_FAILURE(
600 StartTestWithPage("files/overscroll_navigation.html"));
602 WebContentsImpl* web_contents =
603 static_cast<WebContentsImpl*>(shell()->web_contents());
604 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()");
605 EXPECT_EQ(1, GetCurrentIndex());
607 aura::Window* content = web_contents->GetContentNativeView();
608 gfx::Rect bounds = content->GetBoundsInRootWindow();
609 aura::test::EventGenerator generator(content->GetRootWindow(), content);
610 generator.GestureScrollSequence(
611 gfx::Point(bounds.x() + 2, bounds.y() + 10),
612 gfx::Point(bounds.right() - 10, bounds.y() + 10),
613 base::TimeDelta::FromMilliseconds(20),
616 delete web_contents->GetContentNativeView();
619 // TODO(dalecurtis): Test disabled due to flakiness. http://crbug.com/369871.
620 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
621 DISABLED_RepeatedQuickOverscrollGestures) {
622 ASSERT_NO_FATAL_FAILURE(
623 StartTestWithPage("files/overscroll_navigation.html"));
625 WebContentsImpl* web_contents =
626 static_cast<WebContentsImpl*>(shell()->web_contents());
627 NavigationController& controller = web_contents->GetController();
628 RenderFrameHost* main_frame = web_contents->GetMainFrame();
629 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>(
630 web_contents->GetView());
631 view_aura->SetupOverlayWindowForTesting();
632 ExecuteSyncJSFunction(main_frame, "install_touch_handler()");
634 // Navigate twice, then navigate back in history once.
635 ExecuteSyncJSFunction(main_frame, "navigate_next()");
636 ExecuteSyncJSFunction(main_frame, "navigate_next()");
637 EXPECT_EQ(2, GetCurrentIndex());
638 EXPECT_TRUE(controller.CanGoBack());
639 EXPECT_FALSE(controller.CanGoForward());
641 web_contents->GetController().GoBack();
642 WaitForLoadStop(web_contents);
643 EXPECT_EQ(1, GetCurrentIndex());
644 EXPECT_EQ(base::ASCIIToUTF16("Title: #1"), web_contents->GetTitle());
645 EXPECT_TRUE(controller.CanGoBack());
646 EXPECT_TRUE(controller.CanGoForward());
648 aura::Window* content = web_contents->GetContentNativeView();
649 gfx::Rect bounds = content->GetBoundsInRootWindow();
650 aura::test::EventGenerator generator(content->GetRootWindow(), content);
652 // Do a swipe left to start a forward navigation. Then quickly do a swipe
653 // right.
654 base::string16 expected_title = base::ASCIIToUTF16("Title: #2");
655 content::TitleWatcher title_watcher(web_contents, expected_title);
656 NavigationWatcher nav_watcher(web_contents);
658 generator.GestureScrollSequence(
659 gfx::Point(bounds.right() - 10, bounds.y() + 10),
660 gfx::Point(bounds.x() + 2, bounds.y() + 10),
661 base::TimeDelta::FromMilliseconds(2000),
662 10);
663 nav_watcher.WaitUntilNavigationStarts();
665 generator.GestureScrollSequence(
666 gfx::Point(bounds.x() + 2, bounds.y() + 10),
667 gfx::Point(bounds.right() - 10, bounds.y() + 10),
668 base::TimeDelta::FromMilliseconds(2000),
669 10);
670 base::string16 actual_title = title_watcher.WaitAndGetTitle();
671 EXPECT_EQ(expected_title, actual_title);
673 EXPECT_EQ(2, GetCurrentIndex());
674 EXPECT_TRUE(controller.CanGoBack());
675 EXPECT_FALSE(controller.CanGoForward());
678 } // namespace content