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"
13 #include "base/win/windows_version.h"
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/common/view_messages.h"
21 #include "content/public/browser/render_frame_host.h"
22 #include "content/public/browser/web_contents_observer.h"
23 #include "content/public/common/content_switches.h"
24 #include "content/public/test/browser_test_utils.h"
25 #include "content/public/test/content_browser_test.h"
26 #include "content/public/test/content_browser_test_utils.h"
27 #include "content/public/test/test_renderer_host.h"
28 #include "content/public/test/test_utils.h"
29 #include "content/shell/browser/shell.h"
30 #include "ui/aura/test/event_generator.h"
31 #include "ui/aura/window.h"
32 #include "ui/aura/window_tree_host.h"
33 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
34 #include "ui/events/event_processor.h"
35 #include "ui/events/event_utils.h"
39 // This class keeps track of the RenderViewHost whose screenshot was captured.
40 class ScreenshotTracker
: public NavigationEntryScreenshotManager
{
42 explicit ScreenshotTracker(NavigationControllerImpl
* controller
)
43 : NavigationEntryScreenshotManager(controller
),
44 screenshot_taken_for_(NULL
),
45 waiting_for_screenshots_(0) {
48 virtual ~ScreenshotTracker() {
51 RenderViewHost
* screenshot_taken_for() { return screenshot_taken_for_
; }
54 screenshot_taken_for_
= NULL
;
55 screenshot_set_
.clear();
58 void SetScreenshotInterval(int interval_ms
) {
59 SetMinScreenshotIntervalMS(interval_ms
);
62 void WaitUntilScreenshotIsReady() {
63 if (!waiting_for_screenshots_
)
65 message_loop_runner_
= new content::MessageLoopRunner
;
66 message_loop_runner_
->Run();
69 bool ScreenshotSetForEntry(NavigationEntryImpl
* entry
) const {
70 return screenshot_set_
.count(entry
) > 0;
74 // Overridden from NavigationEntryScreenshotManager:
75 virtual void TakeScreenshotImpl(RenderViewHost
* host
,
76 NavigationEntryImpl
* entry
) OVERRIDE
{
77 ++waiting_for_screenshots_
;
78 screenshot_taken_for_
= host
;
79 NavigationEntryScreenshotManager::TakeScreenshotImpl(host
, entry
);
82 virtual void OnScreenshotSet(NavigationEntryImpl
* entry
) OVERRIDE
{
83 --waiting_for_screenshots_
;
84 screenshot_set_
[entry
] = true;
85 NavigationEntryScreenshotManager::OnScreenshotSet(entry
);
86 if (waiting_for_screenshots_
== 0 && message_loop_runner_
.get())
87 message_loop_runner_
->Quit();
90 RenderViewHost
* screenshot_taken_for_
;
91 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner_
;
92 int waiting_for_screenshots_
;
93 std::map
<NavigationEntryImpl
*, bool> screenshot_set_
;
95 DISALLOW_COPY_AND_ASSIGN(ScreenshotTracker
);
98 class NavigationWatcher
: public WebContentsObserver
{
100 explicit NavigationWatcher(WebContents
* contents
)
101 : WebContentsObserver(contents
),
103 should_quit_loop_(false) {
106 virtual ~NavigationWatcher() {}
108 void WaitUntilNavigationStarts() {
111 should_quit_loop_
= true;
112 base::MessageLoop::current()->Run();
116 // Overridden from WebContentsObserver:
117 virtual void AboutToNavigateRenderView(RenderViewHost
* host
) OVERRIDE
{
119 if (should_quit_loop_
)
120 base::MessageLoop::current()->Quit();
124 bool should_quit_loop_
;
126 DISALLOW_COPY_AND_ASSIGN(NavigationWatcher
);
129 class WebContentsViewAuraTest
: public ContentBrowserTest
{
131 WebContentsViewAuraTest()
132 : screenshot_manager_(NULL
) {
135 // Executes the javascript synchronously and makes sure the returned value is
137 void ExecuteSyncJSFunction(RenderFrameHost
* rfh
, const std::string
& jscript
) {
138 scoped_ptr
<base::Value
> value
=
139 content::ExecuteScriptAndGetValue(rfh
, jscript
);
142 // Starts the test server and navigates to the given url. Sets a large enough
143 // size to the root window. Returns after the navigation to the url is
145 void StartTestWithPage(const std::string
& url
) {
146 ASSERT_TRUE(test_server()->Start());
147 GURL
test_url(test_server()->GetURL(url
));
148 NavigateToURL(shell(), test_url
);
150 WebContentsImpl
* web_contents
=
151 static_cast<WebContentsImpl
*>(shell()->web_contents());
152 NavigationControllerImpl
* controller
= &web_contents
->GetController();
154 screenshot_manager_
= new ScreenshotTracker(controller
);
155 controller
->SetScreenshotManager(screenshot_manager_
);
158 void TestOverscrollNavigation(bool touch_handler
) {
159 ASSERT_NO_FATAL_FAILURE(
160 StartTestWithPage("files/overscroll_navigation.html"));
161 WebContentsImpl
* web_contents
=
162 static_cast<WebContentsImpl
*>(shell()->web_contents());
163 NavigationController
& controller
= web_contents
->GetController();
164 RenderFrameHost
* main_frame
= web_contents
->GetMainFrame();
166 EXPECT_FALSE(controller
.CanGoBack());
167 EXPECT_FALSE(controller
.CanGoForward());
169 scoped_ptr
<base::Value
> value
=
170 content::ExecuteScriptAndGetValue(main_frame
, "get_current()");
171 ASSERT_TRUE(value
->GetAsInteger(&index
));
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
));
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
),
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
));
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
),
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
));
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
),
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
));
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();
251 scoped_ptr
<base::Value
> value
;
252 value
= content::ExecuteScriptAndGetValue(main_frame
, "get_current()");
253 if (!value
->GetAsInteger(&index
))
259 ScreenshotTracker
* screenshot_manager() { return screenshot_manager_
; }
260 void set_min_screenshot_interval(int interval_ms
) {
261 screenshot_manager_
->SetScreenshotInterval(interval_ms
);
265 ScreenshotTracker
* screenshot_manager_
;
267 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAuraTest
);
270 // Flaky on Windows: http://crbug.com/305722
272 #define MAYBE_OverscrollNavigation DISABLED_OverscrollNavigation
274 #define MAYBE_OverscrollNavigation OverscrollNavigation
277 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
, MAYBE_OverscrollNavigation
) {
278 TestOverscrollNavigation(false);
281 // Flaky on Windows (might be related to the above test):
282 // http://crbug.com/305722
284 #define MAYBE_OverscrollNavigationWithTouchHandler \
285 DISABLED_OverscrollNavigationWithTouchHandler
287 #define MAYBE_OverscrollNavigationWithTouchHandler \
288 OverscrollNavigationWithTouchHandler
290 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
,
291 MAYBE_OverscrollNavigationWithTouchHandler
) {
292 TestOverscrollNavigation(true);
295 // Disabled because the test always fails the first time it runs on the Win Aura
296 // bots, and usually but not always passes second-try (See crbug.com/179532).
298 #define MAYBE_QuickOverscrollDirectionChange \
299 DISABLED_QuickOverscrollDirectionChange
301 #define MAYBE_QuickOverscrollDirectionChange QuickOverscrollDirectionChange
303 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
,
304 MAYBE_QuickOverscrollDirectionChange
) {
305 ASSERT_NO_FATAL_FAILURE(
306 StartTestWithPage("files/overscroll_navigation.html"));
307 WebContentsImpl
* web_contents
=
308 static_cast<WebContentsImpl
*>(shell()->web_contents());
309 RenderFrameHost
* main_frame
= web_contents
->GetMainFrame();
311 // This test triggers a large number of animations. Speed them up to ensure
312 // the test completes within its time limit.
313 ui::ScopedAnimationDurationScaleMode
fast_duration_mode(
314 ui::ScopedAnimationDurationScaleMode::FAST_DURATION
);
316 // Make sure the page has both back/forward history.
317 ExecuteSyncJSFunction(main_frame
, "navigate_next()");
318 EXPECT_EQ(1, GetCurrentIndex());
319 ExecuteSyncJSFunction(main_frame
, "navigate_next()");
320 EXPECT_EQ(2, GetCurrentIndex());
321 web_contents
->GetController().GoBack();
322 EXPECT_EQ(1, GetCurrentIndex());
324 aura::Window
* content
= web_contents
->GetContentNativeView();
325 ui::EventProcessor
* dispatcher
= content
->GetHost()->event_processor();
326 gfx::Rect bounds
= content
->GetBoundsInRootWindow();
328 base::TimeDelta timestamp
= ui::EventTimeForNow();
329 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
330 gfx::Point(bounds
.x() + bounds
.width() / 2, bounds
.y() + 5),
332 ui::EventDispatchDetails details
= dispatcher
->OnEventFromSource(&press
);
333 ASSERT_FALSE(details
.dispatcher_destroyed
);
334 EXPECT_EQ(1, GetCurrentIndex());
336 timestamp
+= base::TimeDelta::FromMilliseconds(10);
337 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
,
338 gfx::Point(bounds
.right() - 10, bounds
.y() + 5),
340 details
= dispatcher
->OnEventFromSource(&move1
);
341 ASSERT_FALSE(details
.dispatcher_destroyed
);
342 EXPECT_EQ(1, GetCurrentIndex());
344 // Swipe back from the right edge, back to the left edge, back to the right
347 for (int x
= bounds
.right() - 10; x
>= bounds
.x() + 10; x
-= 10) {
348 timestamp
+= base::TimeDelta::FromMilliseconds(10);
349 ui::TouchEvent
inc(ui::ET_TOUCH_MOVED
,
350 gfx::Point(x
, bounds
.y() + 5),
352 details
= dispatcher
->OnEventFromSource(&inc
);
353 ASSERT_FALSE(details
.dispatcher_destroyed
);
354 EXPECT_EQ(1, GetCurrentIndex());
357 for (int x
= bounds
.x() + 10; x
<= bounds
.width() - 10; x
+= 10) {
358 timestamp
+= base::TimeDelta::FromMilliseconds(10);
359 ui::TouchEvent
inc(ui::ET_TOUCH_MOVED
,
360 gfx::Point(x
, bounds
.y() + 5),
362 details
= dispatcher
->OnEventFromSource(&inc
);
363 ASSERT_FALSE(details
.dispatcher_destroyed
);
364 EXPECT_EQ(1, GetCurrentIndex());
367 for (int x
= bounds
.width() - 10; x
>= bounds
.x() + 10; x
-= 10) {
368 timestamp
+= base::TimeDelta::FromMilliseconds(10);
369 ui::TouchEvent
inc(ui::ET_TOUCH_MOVED
,
370 gfx::Point(x
, bounds
.y() + 5),
372 details
= dispatcher
->OnEventFromSource(&inc
);
373 ASSERT_FALSE(details
.dispatcher_destroyed
);
374 EXPECT_EQ(1, GetCurrentIndex());
377 // Do not end the overscroll sequence.
380 // Tests that the page has has a screenshot when navigation happens:
381 // - from within the page (from a JS function)
382 // - interactively, when user does an overscroll gesture
383 // - interactively, when user navigates in history without the overscroll
385 // Flaky on Windows (http://crbug.com/357311). Might be related to
386 // OverscrollNavigation test.
388 #define MAYBE_OverscrollScreenshot DISABLED_OverscrollScreenshot
390 #define MAYBE_OverscrollScreenshot OverscrollScreenshot
393 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
, MAYBE_OverscrollScreenshot
) {
394 // Disable the test for WinXP. See http://crbug/294116.
396 if (base::win::GetVersion() < base::win::VERSION_VISTA
) {
397 LOG(WARNING
) << "Test disabled due to unknown bug on WinXP.";
402 ASSERT_NO_FATAL_FAILURE(
403 StartTestWithPage("files/overscroll_navigation.html"));
404 WebContentsImpl
* web_contents
=
405 static_cast<WebContentsImpl
*>(shell()->web_contents());
406 RenderFrameHost
* main_frame
= web_contents
->GetMainFrame();
408 set_min_screenshot_interval(0);
410 // Do a few navigations initiated by the page.
411 ExecuteSyncJSFunction(main_frame
, "navigate_next()");
412 EXPECT_EQ(1, GetCurrentIndex());
413 ExecuteSyncJSFunction(main_frame
, "navigate_next()");
414 EXPECT_EQ(2, GetCurrentIndex());
415 screenshot_manager()->WaitUntilScreenshotIsReady();
417 // The current entry won't have any screenshots. But the entries in the
418 // history should now have screenshots.
419 NavigationEntryImpl
* entry
= NavigationEntryImpl::FromNavigationEntry(
420 web_contents
->GetController().GetEntryAtIndex(2));
421 EXPECT_FALSE(entry
->screenshot().get());
423 entry
= NavigationEntryImpl::FromNavigationEntry(
424 web_contents
->GetController().GetEntryAtIndex(1));
425 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry
));
427 entry
= NavigationEntryImpl::FromNavigationEntry(
428 web_contents
->GetController().GetEntryAtIndex(0));
429 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry
));
431 // Navigate again. Index 2 should now have a screenshot.
432 ExecuteSyncJSFunction(main_frame
, "navigate_next()");
433 EXPECT_EQ(3, GetCurrentIndex());
434 screenshot_manager()->WaitUntilScreenshotIsReady();
436 entry
= NavigationEntryImpl::FromNavigationEntry(
437 web_contents
->GetController().GetEntryAtIndex(2));
438 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry
));
440 entry
= NavigationEntryImpl::FromNavigationEntry(
441 web_contents
->GetController().GetEntryAtIndex(3));
442 EXPECT_FALSE(entry
->screenshot().get());
445 // Now, swipe right to navigate backwards. This should navigate away from
446 // index 3 to index 2, and index 3 should have a screenshot.
447 base::string16 expected_title
= base::ASCIIToUTF16("Title: #2");
448 content::TitleWatcher
title_watcher(web_contents
, expected_title
);
449 aura::Window
* content
= web_contents
->GetContentNativeView();
450 gfx::Rect bounds
= content
->GetBoundsInRootWindow();
451 aura::test::EventGenerator
generator(content
->GetRootWindow(), content
);
452 generator
.GestureScrollSequence(
453 gfx::Point(bounds
.x() + 2, bounds
.y() + 10),
454 gfx::Point(bounds
.right() - 10, bounds
.y() + 10),
455 base::TimeDelta::FromMilliseconds(20),
457 base::string16 actual_title
= title_watcher
.WaitAndGetTitle();
458 EXPECT_EQ(expected_title
, actual_title
);
459 EXPECT_EQ(2, GetCurrentIndex());
460 screenshot_manager()->WaitUntilScreenshotIsReady();
461 entry
= NavigationEntryImpl::FromNavigationEntry(
462 web_contents
->GetController().GetEntryAtIndex(3));
463 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry
));
466 // Navigate a couple more times.
467 ExecuteSyncJSFunction(main_frame
, "navigate_next()");
468 EXPECT_EQ(3, GetCurrentIndex());
469 ExecuteSyncJSFunction(main_frame
, "navigate_next()");
470 EXPECT_EQ(4, GetCurrentIndex());
471 screenshot_manager()->WaitUntilScreenshotIsReady();
472 entry
= NavigationEntryImpl::FromNavigationEntry(
473 web_contents
->GetController().GetEntryAtIndex(4));
474 EXPECT_FALSE(entry
->screenshot().get());
477 // Navigate back in history.
478 base::string16 expected_title
= base::ASCIIToUTF16("Title: #3");
479 content::TitleWatcher
title_watcher(web_contents
, expected_title
);
480 web_contents
->GetController().GoBack();
481 base::string16 actual_title
= title_watcher
.WaitAndGetTitle();
482 EXPECT_EQ(expected_title
, actual_title
);
483 EXPECT_EQ(3, GetCurrentIndex());
484 screenshot_manager()->WaitUntilScreenshotIsReady();
485 entry
= NavigationEntryImpl::FromNavigationEntry(
486 web_contents
->GetController().GetEntryAtIndex(4));
487 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry
));
491 // Crashes under ThreadSanitizer, http://crbug.com/356758.
492 #if defined(THREAD_SANITIZER)
493 #define MAYBE_ScreenshotForSwappedOutRenderViews \
494 DISABLED_ScreenshotForSwappedOutRenderViews
496 #define MAYBE_ScreenshotForSwappedOutRenderViews \
497 ScreenshotForSwappedOutRenderViews
499 // Tests that screenshot is taken correctly when navigation causes a
500 // RenderViewHost to be swapped out.
501 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
,
502 MAYBE_ScreenshotForSwappedOutRenderViews
) {
503 ASSERT_NO_FATAL_FAILURE(
504 StartTestWithPage("files/overscroll_navigation.html"));
505 // Create a new server with a different site.
506 net::SpawnedTestServer
https_server(
507 net::SpawnedTestServer::TYPE_HTTPS
,
508 net::SpawnedTestServer::kLocalhost
,
509 base::FilePath(FILE_PATH_LITERAL("content/test/data")));
510 ASSERT_TRUE(https_server
.Start());
512 WebContentsImpl
* web_contents
=
513 static_cast<WebContentsImpl
*>(shell()->web_contents());
514 set_min_screenshot_interval(0);
520 { https_server
.GetURL("files/title1.html"),
521 PAGE_TRANSITION_TYPED
| PAGE_TRANSITION_FROM_ADDRESS_BAR
},
522 { test_server()->GetURL("files/title2.html"),
523 PAGE_TRANSITION_AUTO_BOOKMARK
},
524 { https_server
.GetURL("files/title3.html"),
525 PAGE_TRANSITION_TYPED
| PAGE_TRANSITION_FROM_ADDRESS_BAR
},
529 screenshot_manager()->Reset();
530 for (int i
= 0; !navigations
[i
].url
.is_empty(); ++i
) {
531 // Navigate via the user initiating a navigation from the UI.
532 NavigationController::LoadURLParams
params(navigations
[i
].url
);
533 params
.transition_type
= PageTransitionFromInt(navigations
[i
].transition
);
535 RenderViewHost
* old_host
= web_contents
->GetRenderViewHost();
536 web_contents
->GetController().LoadURLWithParams(params
);
537 WaitForLoadStop(web_contents
);
538 screenshot_manager()->WaitUntilScreenshotIsReady();
540 EXPECT_NE(old_host
, web_contents
->GetRenderViewHost())
541 << navigations
[i
].url
.spec();
542 EXPECT_EQ(old_host
, screenshot_manager()->screenshot_taken_for());
544 NavigationEntryImpl
* entry
= NavigationEntryImpl::FromNavigationEntry(
545 web_contents
->GetController().GetEntryAtOffset(-1));
546 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry
));
548 entry
= NavigationEntryImpl::FromNavigationEntry(
549 web_contents
->GetController().GetLastCommittedEntry());
550 EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry
));
551 EXPECT_FALSE(entry
->screenshot().get());
552 screenshot_manager()->Reset();
555 // Increase the minimum interval between taking screenshots.
556 set_min_screenshot_interval(60000);
558 // Navigate again. This should not take any screenshot because of the
559 // increased screenshot interval.
560 NavigationController::LoadURLParams
params(navigations
[0].url
);
561 params
.transition_type
= PageTransitionFromInt(navigations
[0].transition
);
562 web_contents
->GetController().LoadURLWithParams(params
);
563 WaitForLoadStop(web_contents
);
564 screenshot_manager()->WaitUntilScreenshotIsReady();
566 EXPECT_EQ(NULL
, screenshot_manager()->screenshot_taken_for());
569 // Tests that navigations resulting from reloads and history.replaceState
570 // do not capture screenshots while navigations resulting from
571 // histrory.pushState do.
572 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
, ReplaceStateReloadPushState
) {
573 ASSERT_NO_FATAL_FAILURE(
574 StartTestWithPage("files/overscroll_navigation.html"));
575 WebContentsImpl
* web_contents
=
576 static_cast<WebContentsImpl
*>(shell()->web_contents());
577 RenderFrameHost
* main_frame
= web_contents
->GetMainFrame();
579 set_min_screenshot_interval(0);
580 screenshot_manager()->Reset();
581 ExecuteSyncJSFunction(main_frame
, "use_replace_state()");
582 screenshot_manager()->WaitUntilScreenshotIsReady();
583 // history.replaceState shouldn't capture a screenshot
584 EXPECT_FALSE(screenshot_manager()->screenshot_taken_for());
585 screenshot_manager()->Reset();
586 web_contents
->GetController().Reload(true);
587 WaitForLoadStop(web_contents
);
588 // reloading the page shouldn't capture a screenshot
589 EXPECT_FALSE(screenshot_manager()->screenshot_taken_for());
590 screenshot_manager()->Reset();
591 ExecuteSyncJSFunction(main_frame
, "use_push_state()");
592 screenshot_manager()->WaitUntilScreenshotIsReady();
593 // pushing a state should capture a screenshot
594 EXPECT_TRUE(screenshot_manager()->screenshot_taken_for());
597 // TODO(sadrul): This test is disabled because it reparents in a way the
598 // FocusController does not support. This code would crash in
599 // a production build. It only passed prior to this revision
600 // because testing used the old FocusManager which did some
601 // different (osbolete) processing. TODO(sadrul) to figure out
602 // how this test should work that mimics production code a bit
604 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
,
605 DISABLED_ContentWindowReparent
) {
606 ASSERT_NO_FATAL_FAILURE(
607 StartTestWithPage("files/overscroll_navigation.html"));
609 scoped_ptr
<aura::Window
> window(new aura::Window(NULL
));
610 window
->Init(aura::WINDOW_LAYER_NOT_DRAWN
);
612 WebContentsImpl
* web_contents
=
613 static_cast<WebContentsImpl
*>(shell()->web_contents());
614 ExecuteSyncJSFunction(web_contents
->GetMainFrame(), "navigate_next()");
615 EXPECT_EQ(1, GetCurrentIndex());
617 aura::Window
* content
= web_contents
->GetContentNativeView();
618 gfx::Rect bounds
= content
->GetBoundsInRootWindow();
619 aura::test::EventGenerator
generator(content
->GetRootWindow(), content
);
620 generator
.GestureScrollSequence(
621 gfx::Point(bounds
.x() + 2, bounds
.y() + 10),
622 gfx::Point(bounds
.right() - 10, bounds
.y() + 10),
623 base::TimeDelta::FromMilliseconds(20),
626 window
->AddChild(shell()->web_contents()->GetContentNativeView());
629 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
, ContentWindowClose
) {
630 ASSERT_NO_FATAL_FAILURE(
631 StartTestWithPage("files/overscroll_navigation.html"));
633 WebContentsImpl
* web_contents
=
634 static_cast<WebContentsImpl
*>(shell()->web_contents());
635 ExecuteSyncJSFunction(web_contents
->GetMainFrame(), "navigate_next()");
636 EXPECT_EQ(1, GetCurrentIndex());
638 aura::Window
* content
= web_contents
->GetContentNativeView();
639 gfx::Rect bounds
= content
->GetBoundsInRootWindow();
640 aura::test::EventGenerator
generator(content
->GetRootWindow(), content
);
641 generator
.GestureScrollSequence(
642 gfx::Point(bounds
.x() + 2, bounds
.y() + 10),
643 gfx::Point(bounds
.right() - 10, bounds
.y() + 10),
644 base::TimeDelta::FromMilliseconds(20),
647 delete web_contents
->GetContentNativeView();
651 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
652 // This appears to be flaky in the same was as the other overscroll
653 // tests. Enabling for non-Windows platforms.
654 // See http://crbug.com/369871.
655 // For linux, see http://crbug.com/381294
656 #define MAYBE_RepeatedQuickOverscrollGestures DISABLED_RepeatedQuickOverscrollGestures
658 #define MAYBE_RepeatedQuickOverscrollGestures RepeatedQuickOverscrollGestures
661 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
,
662 MAYBE_RepeatedQuickOverscrollGestures
) {
663 ASSERT_NO_FATAL_FAILURE(
664 StartTestWithPage("files/overscroll_navigation.html"));
666 WebContentsImpl
* web_contents
=
667 static_cast<WebContentsImpl
*>(shell()->web_contents());
668 NavigationController
& controller
= web_contents
->GetController();
669 RenderFrameHost
* main_frame
= web_contents
->GetMainFrame();
670 ExecuteSyncJSFunction(main_frame
, "install_touch_handler()");
672 // Navigate twice, then navigate back in history once.
673 ExecuteSyncJSFunction(main_frame
, "navigate_next()");
674 ExecuteSyncJSFunction(main_frame
, "navigate_next()");
675 EXPECT_EQ(2, GetCurrentIndex());
676 EXPECT_TRUE(controller
.CanGoBack());
677 EXPECT_FALSE(controller
.CanGoForward());
679 web_contents
->GetController().GoBack();
680 WaitForLoadStop(web_contents
);
681 EXPECT_EQ(1, GetCurrentIndex());
682 EXPECT_EQ(base::ASCIIToUTF16("Title: #1"), web_contents
->GetTitle());
683 EXPECT_TRUE(controller
.CanGoBack());
684 EXPECT_TRUE(controller
.CanGoForward());
686 aura::Window
* content
= web_contents
->GetContentNativeView();
687 gfx::Rect bounds
= content
->GetBoundsInRootWindow();
688 aura::test::EventGenerator
generator(content
->GetRootWindow(), content
);
690 // Do a swipe left to start a forward navigation. Then quickly do a swipe
692 base::string16 expected_title
= base::ASCIIToUTF16("Title: #2");
693 content::TitleWatcher
title_watcher(web_contents
, expected_title
);
694 NavigationWatcher
nav_watcher(web_contents
);
696 generator
.GestureScrollSequence(
697 gfx::Point(bounds
.right() - 10, bounds
.y() + 10),
698 gfx::Point(bounds
.x() + 2, bounds
.y() + 10),
699 base::TimeDelta::FromMilliseconds(2000),
701 nav_watcher
.WaitUntilNavigationStarts();
703 generator
.GestureScrollSequence(
704 gfx::Point(bounds
.x() + 2, bounds
.y() + 10),
705 gfx::Point(bounds
.right() - 10, bounds
.y() + 10),
706 base::TimeDelta::FromMilliseconds(2000),
708 base::string16 actual_title
= title_watcher
.WaitAndGetTitle();
709 EXPECT_EQ(expected_title
, actual_title
);
711 EXPECT_EQ(2, GetCurrentIndex());
712 EXPECT_TRUE(controller
.CanGoBack());
713 EXPECT_FALSE(controller
.CanGoForward());
716 // Verify that hiding a parent of the renderer will hide the content too.
717 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
, HideContentOnParenHide
) {
718 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/title1.html"));
719 WebContentsImpl
* web_contents
=
720 static_cast<WebContentsImpl
*>(shell()->web_contents());
721 aura::Window
* content
= web_contents
->GetNativeView()->parent();
722 EXPECT_TRUE(web_contents
->should_normally_be_visible());
724 EXPECT_FALSE(web_contents
->should_normally_be_visible());
726 EXPECT_TRUE(web_contents
->should_normally_be_visible());
729 } // namespace content