web_contents_view_aura_browsertest.cc revision 0de6073388f4e2780db8536178b129cd8f6ab386
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. 4 5#include "content/browser/web_contents/web_contents_view_aura.h" 6 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" 33 34namespace content { 35 36// This class keeps track of the RenderViewHost whose screenshot was captured. 37class ScreenshotTracker : public NavigationEntryScreenshotManager { 38 public: 39 explicit ScreenshotTracker(NavigationControllerImpl* controller) 40 : NavigationEntryScreenshotManager(controller), 41 screenshot_taken_for_(NULL), 42 waiting_for_screenshots_(0) { 43 } 44 45 virtual ~ScreenshotTracker() { 46 } 47 48 RenderViewHost* screenshot_taken_for() { return screenshot_taken_for_; } 49 50 void Reset() { 51 screenshot_taken_for_ = NULL; 52 screenshot_set_.clear(); 53 } 54 55 void SetScreenshotInterval(int interval_ms) { 56 SetMinScreenshotIntervalMS(interval_ms); 57 } 58 59 void WaitUntilScreenshotIsReady() { 60 if (!waiting_for_screenshots_) 61 return; 62 message_loop_runner_ = new content::MessageLoopRunner; 63 message_loop_runner_->Run(); 64 } 65 66 bool ScreenshotSetForEntry(NavigationEntryImpl* entry) const { 67 return screenshot_set_.count(entry) > 0; 68 } 69 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); 77 } 78 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(); 85 } 86 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_; 91 92 DISALLOW_COPY_AND_ASSIGN(ScreenshotTracker); 93}; 94 95class NavigationWatcher : public WebContentsObserver { 96 public: 97 explicit NavigationWatcher(WebContents* contents) 98 : WebContentsObserver(contents), 99 navigated_(false), 100 should_quit_loop_(false) { 101 } 102 103 virtual ~NavigationWatcher() {} 104 105 void WaitUntilNavigationStarts() { 106 if (navigated_) 107 return; 108 should_quit_loop_ = true; 109 base::MessageLoop::current()->Run(); 110 } 111 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(); 118 } 119 120 bool navigated_; 121 bool should_quit_loop_; 122 123 DISALLOW_COPY_AND_ASSIGN(NavigationWatcher); 124}; 125 126class WebContentsViewAuraTest : public ContentBrowserTest { 127 public: 128 WebContentsViewAuraTest() 129 : screenshot_manager_(NULL) { 130 } 131 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); 137 } 138 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); 146 147 WebContentsImpl* web_contents = 148 static_cast<WebContentsImpl*>(shell()->web_contents()); 149 NavigationControllerImpl* controller = &web_contents->GetController(); 150 151 screenshot_manager_ = new ScreenshotTracker(controller); 152 controller->SetScreenshotManager(screenshot_manager_); 153 } 154 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(); 165 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); 173 174 if (touch_handler) 175 ExecuteSyncJSFunction(main_frame, "install_touch_handler()"); 176 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()); 184 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; 190 191 { 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()); 207 } 208 209 { 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()); 225 } 226 227 { 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()); 243 } 244 } 245 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; 256 } 257 258 protected: 259 ScreenshotTracker* screenshot_manager() { return screenshot_manager_; } 260 void set_min_screenshot_interval(int interval_ms) { 261 screenshot_manager_->SetScreenshotInterval(interval_ms); 262 } 263 264 private: 265 ScreenshotTracker* screenshot_manager_; 266 267 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAuraTest); 268}; 269 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 276IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, MAYBE_OverscrollNavigation) { 277 TestOverscrollNavigation(false); 278} 279 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 288IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 289 MAYBE_OverscrollNavigationWithTouchHandler) { 290 TestOverscrollNavigation(true); 291} 292 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 301IN_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(); 308 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); 313 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()); 321 322 aura::Window* content = web_contents->GetContentNativeView(); 323 ui::EventProcessor* dispatcher = content->GetHost()->event_processor(); 324 gfx::Rect bounds = content->GetBoundsInRootWindow(); 325 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()); 333 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()); 341 342 // Swipe back from the right edge, back to the left edge, back to the right 343 // edge. 344 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()); 353 } 354 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()); 363 } 364 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()); 373 } 374 375 // Do not end the overscroll sequence. 376} 377 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 389IN_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; 395 } 396#endif 397 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(); 403 404 set_min_screenshot_interval(0); 405 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(); 412 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()); 418 419 entry = NavigationEntryImpl::FromNavigationEntry( 420 web_contents->GetController().GetEntryAtIndex(1)); 421 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 422 423 entry = NavigationEntryImpl::FromNavigationEntry( 424 web_contents->GetController().GetEntryAtIndex(0)); 425 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 426 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(); 431 432 entry = NavigationEntryImpl::FromNavigationEntry( 433 web_contents->GetController().GetEntryAtIndex(2)); 434 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 435 436 entry = NavigationEntryImpl::FromNavigationEntry( 437 web_contents->GetController().GetEntryAtIndex(3)); 438 EXPECT_FALSE(entry->screenshot().get()); 439 440 { 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), 452 1); 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)); 460 } 461 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()); 471 472 { 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)); 484 } 485} 486 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. 497IN_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()); 507 508 WebContentsImpl* web_contents = 509 static_cast<WebContentsImpl*>(shell()->web_contents()); 510 set_min_screenshot_interval(0); 511 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 } 523 }; 524 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); 530 531 RenderViewHost* old_host = web_contents->GetRenderViewHost(); 532 web_contents->GetController().LoadURLWithParams(params); 533 WaitForLoadStop(web_contents); 534 screenshot_manager()->WaitUntilScreenshotIsReady(); 535 536 EXPECT_NE(old_host, web_contents->GetRenderViewHost()) 537 << navigations[i].url.spec(); 538 EXPECT_EQ(old_host, screenshot_manager()->screenshot_taken_for()); 539 540 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( 541 web_contents->GetController().GetEntryAtOffset(-1)); 542 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 543 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(); 549 } 550 551 // Increase the minimum interval between taking screenshots. 552 set_min_screenshot_interval(60000); 553 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(); 561 562 EXPECT_EQ(NULL, screenshot_manager()->screenshot_taken_for()); 563} 564 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. 572IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 573 DISABLED_ContentWindowReparent) { 574 ASSERT_NO_FATAL_FAILURE( 575 StartTestWithPage("files/overscroll_navigation.html")); 576 577 scoped_ptr<aura::Window> window(new aura::Window(NULL)); 578 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); 579 580 WebContentsImpl* web_contents = 581 static_cast<WebContentsImpl*>(shell()->web_contents()); 582 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); 583 EXPECT_EQ(1, GetCurrentIndex()); 584 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), 592 1); 593 594 window->AddChild(shell()->web_contents()->GetContentNativeView()); 595} 596 597IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 598 ContentWindowClose) { 599 ASSERT_NO_FATAL_FAILURE( 600 StartTestWithPage("files/overscroll_navigation.html")); 601 602 WebContentsImpl* web_contents = 603 static_cast<WebContentsImpl*>(shell()->web_contents()); 604 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); 605 EXPECT_EQ(1, GetCurrentIndex()); 606 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), 614 1); 615 616 delete web_contents->GetContentNativeView(); 617} 618 619 620#if defined(OS_WIN) 621// This appears to be flaky in the same was as the other overscroll 622// tests. Enabling for non-Windows platforms. 623// See http://crbug.com/369871. 624#define MAYBE_RepeatedQuickOverscrollGestures DISABLED_RepeatedQuickOverscrollGestures 625#else 626#define MAYBE_RepeatedQuickOverscrollGestures RepeatedQuickOverscrollGestures 627#endif 628 629IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 630 MAYBE_RepeatedQuickOverscrollGestures) { 631 ASSERT_NO_FATAL_FAILURE( 632 StartTestWithPage("files/overscroll_navigation.html")); 633 634 WebContentsImpl* web_contents = 635 static_cast<WebContentsImpl*>(shell()->web_contents()); 636 NavigationController& controller = web_contents->GetController(); 637 RenderFrameHost* main_frame = web_contents->GetMainFrame(); 638 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( 639 web_contents->GetView()); 640 view_aura->SetupOverlayWindowForTesting(); 641 ExecuteSyncJSFunction(main_frame, "install_touch_handler()"); 642 643 // Navigate twice, then navigate back in history once. 644 ExecuteSyncJSFunction(main_frame, "navigate_next()"); 645 ExecuteSyncJSFunction(main_frame, "navigate_next()"); 646 EXPECT_EQ(2, GetCurrentIndex()); 647 EXPECT_TRUE(controller.CanGoBack()); 648 EXPECT_FALSE(controller.CanGoForward()); 649 650 web_contents->GetController().GoBack(); 651 WaitForLoadStop(web_contents); 652 EXPECT_EQ(1, GetCurrentIndex()); 653 EXPECT_EQ(base::ASCIIToUTF16("Title: #1"), web_contents->GetTitle()); 654 EXPECT_TRUE(controller.CanGoBack()); 655 EXPECT_TRUE(controller.CanGoForward()); 656 657 aura::Window* content = web_contents->GetContentNativeView(); 658 gfx::Rect bounds = content->GetBoundsInRootWindow(); 659 aura::test::EventGenerator generator(content->GetRootWindow(), content); 660 661 // Do a swipe left to start a forward navigation. Then quickly do a swipe 662 // right. 663 base::string16 expected_title = base::ASCIIToUTF16("Title: #2"); 664 content::TitleWatcher title_watcher(web_contents, expected_title); 665 NavigationWatcher nav_watcher(web_contents); 666 667 generator.GestureScrollSequence( 668 gfx::Point(bounds.right() - 10, bounds.y() + 10), 669 gfx::Point(bounds.x() + 2, bounds.y() + 10), 670 base::TimeDelta::FromMilliseconds(2000), 671 10); 672 nav_watcher.WaitUntilNavigationStarts(); 673 674 generator.GestureScrollSequence( 675 gfx::Point(bounds.x() + 2, bounds.y() + 10), 676 gfx::Point(bounds.right() - 10, bounds.y() + 10), 677 base::TimeDelta::FromMilliseconds(2000), 678 10); 679 base::string16 actual_title = title_watcher.WaitAndGetTitle(); 680 EXPECT_EQ(expected_title, actual_title); 681 682 EXPECT_EQ(2, GetCurrentIndex()); 683 EXPECT_TRUE(controller.CanGoBack()); 684 EXPECT_FALSE(controller.CanGoForward()); 685} 686 687} // namespace content 688