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/renderer_host/render_view_host_impl.h"
19 #include "content/browser/web_contents/web_contents_impl.h"
20 #include "content/public/browser/web_contents_observer.h"
21 #include "content/public/browser/web_contents_view.h"
22 #include "content/public/common/content_switches.h"
23 #include "content/public/test/browser_test_utils.h"
24 #include "content/public/test/test_utils.h"
25 #include "content/shell/browser/shell.h"
26 #include "content/test/content_browser_test.h"
27 #include "content/test/content_browser_test_utils.h"
28 #include "ui/aura/root_window.h"
29 #include "ui/aura/test/event_generator.h"
30 #include "ui/aura/window.h"
31 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
35 // This class keeps track of the RenderViewHost whose screenshot was captured.
36 class ScreenshotTracker
: public NavigationEntryScreenshotManager
{
38 explicit ScreenshotTracker(NavigationControllerImpl
* controller
)
39 : NavigationEntryScreenshotManager(controller
),
40 screenshot_taken_for_(NULL
),
41 waiting_for_screenshots_(0) {
44 virtual ~ScreenshotTracker() {
47 RenderViewHost
* screenshot_taken_for() { return screenshot_taken_for_
; }
50 screenshot_taken_for_
= NULL
;
51 screenshot_set_
.clear();
54 void SetScreenshotInterval(int interval_ms
) {
55 SetMinScreenshotIntervalMS(interval_ms
);
58 void WaitUntilScreenshotIsReady() {
59 if (!waiting_for_screenshots_
)
61 message_loop_runner_
= new content::MessageLoopRunner
;
62 message_loop_runner_
->Run();
65 bool ScreenshotSetForEntry(NavigationEntryImpl
* entry
) const {
66 return screenshot_set_
.count(entry
) > 0;
70 // Overridden from NavigationEntryScreenshotManager:
71 virtual void TakeScreenshotImpl(RenderViewHost
* host
,
72 NavigationEntryImpl
* entry
) OVERRIDE
{
73 ++waiting_for_screenshots_
;
74 screenshot_taken_for_
= host
;
75 NavigationEntryScreenshotManager::TakeScreenshotImpl(host
, entry
);
78 virtual void OnScreenshotSet(NavigationEntryImpl
* entry
) OVERRIDE
{
79 --waiting_for_screenshots_
;
80 screenshot_set_
[entry
] = true;
81 NavigationEntryScreenshotManager::OnScreenshotSet(entry
);
82 if (waiting_for_screenshots_
== 0 && message_loop_runner_
.get())
83 message_loop_runner_
->Quit();
86 RenderViewHost
* screenshot_taken_for_
;
87 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner_
;
88 int waiting_for_screenshots_
;
89 std::map
<NavigationEntryImpl
*, bool> screenshot_set_
;
91 DISALLOW_COPY_AND_ASSIGN(ScreenshotTracker
);
94 class NavigationWatcher
: public WebContentsObserver
{
96 explicit NavigationWatcher(WebContents
* contents
)
97 : WebContentsObserver(contents
),
99 should_quit_loop_(false) {
102 virtual ~NavigationWatcher() {}
104 void WaitUntilNavigationStarts() {
107 should_quit_loop_
= true;
108 base::MessageLoop::current()->Run();
112 // Overridden from WebContentsObserver:
113 virtual void AboutToNavigateRenderView(RenderViewHost
* host
) OVERRIDE
{
115 if (should_quit_loop_
)
116 base::MessageLoop::current()->Quit();
120 bool should_quit_loop_
;
122 DISALLOW_COPY_AND_ASSIGN(NavigationWatcher
);
125 class WebContentsViewAuraTest
: public ContentBrowserTest
{
127 WebContentsViewAuraTest()
128 : screenshot_manager_(NULL
) {
131 // Executes the javascript synchronously and makes sure the returned value is
133 void ExecuteSyncJSFunction(RenderViewHost
* rvh
, const std::string
& jscript
) {
134 scoped_ptr
<base::Value
> value
=
135 content::ExecuteScriptAndGetValue(rvh
, jscript
);
138 // Starts the test server and navigates to the given url. Sets a large enough
139 // size to the root window. Returns after the navigation to the url is
141 void StartTestWithPage(const std::string
& url
) {
142 ASSERT_TRUE(test_server()->Start());
143 GURL
test_url(test_server()->GetURL(url
));
144 NavigateToURL(shell(), test_url
);
146 WebContentsImpl
* web_contents
=
147 static_cast<WebContentsImpl
*>(shell()->web_contents());
148 NavigationControllerImpl
* controller
= &web_contents
->GetController();
150 screenshot_manager_
= new ScreenshotTracker(controller
);
151 controller
->SetScreenshotManager(screenshot_manager_
);
154 void TestOverscrollNavigation(bool touch_handler
) {
155 ASSERT_NO_FATAL_FAILURE(
156 StartTestWithPage("files/overscroll_navigation.html"));
157 WebContentsImpl
* web_contents
=
158 static_cast<WebContentsImpl
*>(shell()->web_contents());
159 NavigationController
& controller
= web_contents
->GetController();
160 RenderViewHostImpl
* view_host
= static_cast<RenderViewHostImpl
*>(
161 web_contents
->GetRenderViewHost());
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());
169 scoped_ptr
<base::Value
> value
=
170 content::ExecuteScriptAndGetValue(view_host
, "get_current()");
171 ASSERT_TRUE(value
->GetAsInteger(&index
));
175 ExecuteSyncJSFunction(view_host
, "install_touch_handler()");
177 ExecuteSyncJSFunction(view_host
, "navigate_next()");
178 ExecuteSyncJSFunction(view_host
, "navigate_next()");
179 value
= content::ExecuteScriptAndGetValue(view_host
, "get_current()");
180 ASSERT_TRUE(value
->GetAsInteger(&index
));
182 EXPECT_TRUE(controller
.CanGoBack());
183 EXPECT_FALSE(controller
.CanGoForward());
185 aura::Window
* content
= web_contents
->GetView()->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(view_host
, "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(view_host
, "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(view_host
, "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 RenderViewHostImpl
* view_host
= static_cast<RenderViewHostImpl
*>(
250 web_contents
->GetRenderViewHost());
252 scoped_ptr
<base::Value
> value
;
253 value
= content::ExecuteScriptAndGetValue(view_host
, "get_current()");
254 if (!value
->GetAsInteger(&index
))
260 ScreenshotTracker
* screenshot_manager() { return screenshot_manager_
; }
261 void set_min_screenshot_interval(int interval_ms
) {
262 screenshot_manager_
->SetScreenshotInterval(interval_ms
);
266 ScreenshotTracker
* screenshot_manager_
;
268 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAuraTest
);
271 // Flaky on Windows (perhaps just Win-Aura): http://crbug.com/305722
273 #define MAYBE_OverscrollNavigation DISABLED_OverscrollNavigation
275 #define MAYBE_OverscrollNavigation OverscrollNavigation
277 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
, MAYBE_OverscrollNavigation
) {
278 TestOverscrollNavigation(false);
281 // Flaky on Windows (perhaps just Win-Aura): http://crbug.com/305722
283 #define MAYBE_OverscrollNavigationWithTouchHandler \
284 DISABLED_OverscrollNavigationWithTouchHandler
286 #define MAYBE_OverscrollNavigationWithTouchHandler \
287 OverscrollNavigationWithTouchHandler
289 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
,
290 MAYBE_OverscrollNavigationWithTouchHandler
) {
291 TestOverscrollNavigation(true);
294 // Disabled because the test always fails the first time it runs on the Win Aura
295 // bots, and usually but not always passes second-try (See crbug.com/179532).
297 #define MAYBE_QuickOverscrollDirectionChange \
298 DISABLED_QuickOverscrollDirectionChange
300 #define MAYBE_QuickOverscrollDirectionChange QuickOverscrollDirectionChange
302 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
,
303 MAYBE_QuickOverscrollDirectionChange
) {
304 ASSERT_NO_FATAL_FAILURE(
305 StartTestWithPage("files/overscroll_navigation.html"));
306 WebContentsImpl
* web_contents
=
307 static_cast<WebContentsImpl
*>(shell()->web_contents());
308 RenderViewHostImpl
* view_host
= static_cast<RenderViewHostImpl
*>(
309 web_contents
->GetRenderViewHost());
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(view_host
, "navigate_next()");
318 EXPECT_EQ(1, GetCurrentIndex());
319 ExecuteSyncJSFunction(view_host
, "navigate_next()");
320 EXPECT_EQ(2, GetCurrentIndex());
321 web_contents
->GetController().GoBack();
322 EXPECT_EQ(1, GetCurrentIndex());
324 aura::Window
* content
= web_contents
->GetView()->GetContentNativeView();
325 aura::WindowEventDispatcher
* dispatcher
= content
->GetDispatcher();
326 gfx::Rect bounds
= content
->GetBoundsInRootWindow();
328 base::TimeDelta timestamp
;
329 ui::TouchEvent
press(ui::ET_TOUCH_PRESSED
,
330 gfx::Point(bounds
.x() + bounds
.width() / 2, bounds
.y() + 5),
332 dispatcher
->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press
);
333 EXPECT_EQ(1, GetCurrentIndex());
335 timestamp
+= base::TimeDelta::FromMilliseconds(10);
336 ui::TouchEvent
move1(ui::ET_TOUCH_MOVED
,
337 gfx::Point(bounds
.right() - 10, bounds
.y() + 5),
339 dispatcher
->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move1
);
340 EXPECT_EQ(1, GetCurrentIndex());
342 // Swipe back from the right edge, back to the left edge, back to the right
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),
350 dispatcher
->AsWindowTreeHostDelegate()->OnHostTouchEvent(&inc
);
351 EXPECT_EQ(1, GetCurrentIndex());
354 for (int x
= bounds
.x() + 10; x
<= bounds
.width() - 10; x
+= 10) {
355 timestamp
+= base::TimeDelta::FromMilliseconds(10);
356 ui::TouchEvent
inc(ui::ET_TOUCH_MOVED
,
357 gfx::Point(x
, bounds
.y() + 5),
359 dispatcher
->AsWindowTreeHostDelegate()->OnHostTouchEvent(&inc
);
360 EXPECT_EQ(1, GetCurrentIndex());
363 for (int x
= bounds
.width() - 10; x
>= bounds
.x() + 10; x
-= 10) {
364 timestamp
+= base::TimeDelta::FromMilliseconds(10);
365 ui::TouchEvent
inc(ui::ET_TOUCH_MOVED
,
366 gfx::Point(x
, bounds
.y() + 5),
368 dispatcher
->AsWindowTreeHostDelegate()->OnHostTouchEvent(&inc
);
369 EXPECT_EQ(1, GetCurrentIndex());
372 // Do not end the overscroll sequence.
375 // Tests that the page has has a screenshot when navigation happens:
376 // - from within the page (from a JS function)
377 // - interactively, when user does an overscroll gesture
378 // - interactively, when user navigates in history without the overscroll
380 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
, OverscrollScreenshot
) {
381 // Disable the test for WinXP. See http://crbug/294116.
383 if (base::win::GetVersion() < base::win::VERSION_VISTA
) {
384 LOG(WARNING
) << "Test disabled due to unknown bug on WinXP.";
389 ASSERT_NO_FATAL_FAILURE(
390 StartTestWithPage("files/overscroll_navigation.html"));
391 WebContentsImpl
* web_contents
=
392 static_cast<WebContentsImpl
*>(shell()->web_contents());
393 RenderViewHostImpl
* view_host
= static_cast<RenderViewHostImpl
*>(
394 web_contents
->GetRenderViewHost());
396 set_min_screenshot_interval(0);
398 // Do a few navigations initiated by the page.
399 ExecuteSyncJSFunction(view_host
, "navigate_next()");
400 EXPECT_EQ(1, GetCurrentIndex());
401 ExecuteSyncJSFunction(view_host
, "navigate_next()");
402 EXPECT_EQ(2, GetCurrentIndex());
403 screenshot_manager()->WaitUntilScreenshotIsReady();
405 // The current entry won't have any screenshots. But the entries in the
406 // history should now have screenshots.
407 NavigationEntryImpl
* entry
= NavigationEntryImpl::FromNavigationEntry(
408 web_contents
->GetController().GetEntryAtIndex(2));
409 EXPECT_FALSE(entry
->screenshot().get());
411 entry
= NavigationEntryImpl::FromNavigationEntry(
412 web_contents
->GetController().GetEntryAtIndex(1));
413 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry
));
415 entry
= NavigationEntryImpl::FromNavigationEntry(
416 web_contents
->GetController().GetEntryAtIndex(0));
417 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry
));
419 // Navigate again. Index 2 should now have a screenshot.
420 ExecuteSyncJSFunction(view_host
, "navigate_next()");
421 EXPECT_EQ(3, GetCurrentIndex());
422 screenshot_manager()->WaitUntilScreenshotIsReady();
424 entry
= NavigationEntryImpl::FromNavigationEntry(
425 web_contents
->GetController().GetEntryAtIndex(2));
426 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry
));
428 entry
= NavigationEntryImpl::FromNavigationEntry(
429 web_contents
->GetController().GetEntryAtIndex(3));
430 EXPECT_FALSE(entry
->screenshot().get());
433 // Now, swipe right to navigate backwards. This should navigate away from
434 // index 3 to index 2, and index 3 should have a screenshot.
435 base::string16 expected_title
= base::ASCIIToUTF16("Title: #2");
436 content::TitleWatcher
title_watcher(web_contents
, expected_title
);
437 aura::Window
* content
= web_contents
->GetView()->GetContentNativeView();
438 gfx::Rect bounds
= content
->GetBoundsInRootWindow();
439 aura::test::EventGenerator
generator(content
->GetRootWindow(), content
);
440 generator
.GestureScrollSequence(
441 gfx::Point(bounds
.x() + 2, bounds
.y() + 10),
442 gfx::Point(bounds
.right() - 10, bounds
.y() + 10),
443 base::TimeDelta::FromMilliseconds(20),
445 base::string16 actual_title
= title_watcher
.WaitAndGetTitle();
446 EXPECT_EQ(expected_title
, actual_title
);
447 EXPECT_EQ(2, GetCurrentIndex());
448 screenshot_manager()->WaitUntilScreenshotIsReady();
449 entry
= NavigationEntryImpl::FromNavigationEntry(
450 web_contents
->GetController().GetEntryAtIndex(3));
451 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry
));
454 // Navigate a couple more times.
455 ExecuteSyncJSFunction(view_host
, "navigate_next()");
456 EXPECT_EQ(3, GetCurrentIndex());
457 ExecuteSyncJSFunction(view_host
, "navigate_next()");
458 EXPECT_EQ(4, GetCurrentIndex());
459 screenshot_manager()->WaitUntilScreenshotIsReady();
460 entry
= NavigationEntryImpl::FromNavigationEntry(
461 web_contents
->GetController().GetEntryAtIndex(4));
462 EXPECT_FALSE(entry
->screenshot().get());
465 // Navigate back in history.
466 base::string16 expected_title
= base::ASCIIToUTF16("Title: #3");
467 content::TitleWatcher
title_watcher(web_contents
, expected_title
);
468 web_contents
->GetController().GoBack();
469 base::string16 actual_title
= title_watcher
.WaitAndGetTitle();
470 EXPECT_EQ(expected_title
, actual_title
);
471 EXPECT_EQ(3, GetCurrentIndex());
472 screenshot_manager()->WaitUntilScreenshotIsReady();
473 entry
= NavigationEntryImpl::FromNavigationEntry(
474 web_contents
->GetController().GetEntryAtIndex(4));
475 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry
));
479 // Tests that screenshot is taken correctly when navigation causes a
480 // RenderViewHost to be swapped out.
481 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
,
482 ScreenshotForSwappedOutRenderViews
) {
483 ASSERT_NO_FATAL_FAILURE(
484 StartTestWithPage("files/overscroll_navigation.html"));
485 // Create a new server with a different site.
486 net::SpawnedTestServer
https_server(
487 net::SpawnedTestServer::TYPE_HTTPS
,
488 net::SpawnedTestServer::kLocalhost
,
489 base::FilePath(FILE_PATH_LITERAL("content/test/data")));
490 ASSERT_TRUE(https_server
.Start());
492 WebContentsImpl
* web_contents
=
493 static_cast<WebContentsImpl
*>(shell()->web_contents());
494 set_min_screenshot_interval(0);
500 { https_server
.GetURL("files/title1.html"),
501 PAGE_TRANSITION_TYPED
| PAGE_TRANSITION_FROM_ADDRESS_BAR
},
502 { test_server()->GetURL("files/title2.html"),
503 PAGE_TRANSITION_AUTO_BOOKMARK
},
504 { https_server
.GetURL("files/title3.html"),
505 PAGE_TRANSITION_TYPED
| PAGE_TRANSITION_FROM_ADDRESS_BAR
},
509 screenshot_manager()->Reset();
510 for (int i
= 0; !navigations
[i
].url
.is_empty(); ++i
) {
511 // Navigate via the user initiating a navigation from the UI.
512 NavigationController::LoadURLParams
params(navigations
[i
].url
);
513 params
.transition_type
= PageTransitionFromInt(navigations
[i
].transition
);
515 RenderViewHost
* old_host
= web_contents
->GetRenderViewHost();
516 web_contents
->GetController().LoadURLWithParams(params
);
517 WaitForLoadStop(web_contents
);
518 screenshot_manager()->WaitUntilScreenshotIsReady();
520 EXPECT_NE(old_host
, web_contents
->GetRenderViewHost())
521 << navigations
[i
].url
.spec();
522 EXPECT_EQ(old_host
, screenshot_manager()->screenshot_taken_for());
524 NavigationEntryImpl
* entry
= NavigationEntryImpl::FromNavigationEntry(
525 web_contents
->GetController().GetEntryAtOffset(-1));
526 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry
));
528 entry
= NavigationEntryImpl::FromNavigationEntry(
529 web_contents
->GetController().GetLastCommittedEntry());
530 EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry
));
531 EXPECT_FALSE(entry
->screenshot().get());
532 screenshot_manager()->Reset();
535 // Increase the minimum interval between taking screenshots.
536 set_min_screenshot_interval(60000);
538 // Navigate again. This should not take any screenshot because of the
539 // increased screenshot interval.
540 NavigationController::LoadURLParams
params(navigations
[0].url
);
541 params
.transition_type
= PageTransitionFromInt(navigations
[0].transition
);
542 web_contents
->GetController().LoadURLWithParams(params
);
543 WaitForLoadStop(web_contents
);
544 screenshot_manager()->WaitUntilScreenshotIsReady();
546 EXPECT_EQ(NULL
, screenshot_manager()->screenshot_taken_for());
549 // TODO(sadrul): This test is disabled because it reparents in a way the
550 // FocusController does not support. This code would crash in
551 // a production build. It only passed prior to this revision
552 // because testing used the old FocusManager which did some
553 // different (osbolete) processing. TODO(sadrul) to figure out
554 // how this test should work that mimics production code a bit
556 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
,
557 DISABLED_ContentWindowReparent
) {
558 ASSERT_NO_FATAL_FAILURE(
559 StartTestWithPage("files/overscroll_navigation.html"));
561 scoped_ptr
<aura::Window
> window(new aura::Window(NULL
));
562 window
->Init(aura::WINDOW_LAYER_NOT_DRAWN
);
564 WebContentsImpl
* web_contents
=
565 static_cast<WebContentsImpl
*>(shell()->web_contents());
566 ExecuteSyncJSFunction(web_contents
->GetRenderViewHost(), "navigate_next()");
567 EXPECT_EQ(1, GetCurrentIndex());
569 aura::Window
* content
= web_contents
->GetView()->GetContentNativeView();
570 gfx::Rect bounds
= content
->GetBoundsInRootWindow();
571 aura::test::EventGenerator
generator(content
->GetRootWindow(), content
);
572 generator
.GestureScrollSequence(
573 gfx::Point(bounds
.x() + 2, bounds
.y() + 10),
574 gfx::Point(bounds
.right() - 10, bounds
.y() + 10),
575 base::TimeDelta::FromMilliseconds(20),
578 window
->AddChild(shell()->web_contents()->GetView()->GetContentNativeView());
581 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
,
582 ContentWindowClose
) {
583 ASSERT_NO_FATAL_FAILURE(
584 StartTestWithPage("files/overscroll_navigation.html"));
586 WebContentsImpl
* web_contents
=
587 static_cast<WebContentsImpl
*>(shell()->web_contents());
588 ExecuteSyncJSFunction(web_contents
->GetRenderViewHost(), "navigate_next()");
589 EXPECT_EQ(1, GetCurrentIndex());
591 aura::Window
* content
= web_contents
->GetView()->GetContentNativeView();
592 gfx::Rect bounds
= content
->GetBoundsInRootWindow();
593 aura::test::EventGenerator
generator(content
->GetRootWindow(), content
);
594 generator
.GestureScrollSequence(
595 gfx::Point(bounds
.x() + 2, bounds
.y() + 10),
596 gfx::Point(bounds
.right() - 10, bounds
.y() + 10),
597 base::TimeDelta::FromMilliseconds(20),
600 delete web_contents
->GetView()->GetContentNativeView();
603 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest
,
604 RepeatedQuickOverscrollGestures
) {
605 ASSERT_NO_FATAL_FAILURE(
606 StartTestWithPage("files/overscroll_navigation.html"));
608 WebContentsImpl
* web_contents
=
609 static_cast<WebContentsImpl
*>(shell()->web_contents());
610 NavigationController
& controller
= web_contents
->GetController();
611 RenderViewHostImpl
* view_host
= static_cast<RenderViewHostImpl
*>(
612 web_contents
->GetRenderViewHost());
613 WebContentsViewAura
* view_aura
= static_cast<WebContentsViewAura
*>(
614 web_contents
->GetView());
615 view_aura
->SetupOverlayWindowForTesting();
616 ExecuteSyncJSFunction(view_host
, "install_touch_handler()");
618 // Navigate twice, then navigate back in history once.
619 ExecuteSyncJSFunction(view_host
, "navigate_next()");
620 ExecuteSyncJSFunction(view_host
, "navigate_next()");
621 EXPECT_EQ(2, GetCurrentIndex());
622 EXPECT_TRUE(controller
.CanGoBack());
623 EXPECT_FALSE(controller
.CanGoForward());
625 web_contents
->GetController().GoBack();
626 WaitForLoadStop(web_contents
);
627 EXPECT_EQ(1, GetCurrentIndex());
628 EXPECT_EQ(base::ASCIIToUTF16("Title: #1"), web_contents
->GetTitle());
629 EXPECT_TRUE(controller
.CanGoBack());
630 EXPECT_TRUE(controller
.CanGoForward());
632 aura::Window
* content
= web_contents
->GetView()->GetContentNativeView();
633 gfx::Rect bounds
= content
->GetBoundsInRootWindow();
634 aura::test::EventGenerator
generator(content
->GetRootWindow(), content
);
636 // Do a swipe left to start a forward navigation. Then quickly do a swipe
638 base::string16 expected_title
= base::ASCIIToUTF16("Title: #2");
639 content::TitleWatcher
title_watcher(web_contents
, expected_title
);
640 NavigationWatcher
nav_watcher(web_contents
);
642 generator
.GestureScrollSequence(
643 gfx::Point(bounds
.right() - 10, bounds
.y() + 10),
644 gfx::Point(bounds
.x() + 2, bounds
.y() + 10),
645 base::TimeDelta::FromMilliseconds(2000),
647 nav_watcher
.WaitUntilNavigationStarts();
649 generator
.GestureScrollSequence(
650 gfx::Point(bounds
.x() + 2, bounds
.y() + 10),
651 gfx::Point(bounds
.right() - 10, bounds
.y() + 10),
652 base::TimeDelta::FromMilliseconds(2000),
654 base::string16 actual_title
= title_watcher
.WaitAndGetTitle();
655 EXPECT_EQ(expected_title
, actual_title
);
657 EXPECT_EQ(2, GetCurrentIndex());
658 EXPECT_TRUE(controller
.CanGoBack());
659 EXPECT_FALSE(controller
.CanGoForward());
662 } // namespace content