web_contents_view_aura_browsertest.cc revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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/web_contents_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" 32 33namespace content { 34 35// This class keeps track of the RenderViewHost whose screenshot was captured. 36class ScreenshotTracker : public WebContentsScreenshotManager { 37 public: 38 explicit ScreenshotTracker(NavigationControllerImpl* controller) 39 : WebContentsScreenshotManager(controller), 40 screenshot_taken_for_(NULL), 41 waiting_for_screenshots_(0) { 42 } 43 44 virtual ~ScreenshotTracker() { 45 } 46 47 RenderViewHost* screenshot_taken_for() { return screenshot_taken_for_; } 48 49 void Reset() { 50 screenshot_taken_for_ = NULL; 51 screenshot_set_.clear(); 52 } 53 54 void SetScreenshotInterval(int interval_ms) { 55 SetMinScreenshotIntervalMS(interval_ms); 56 } 57 58 void WaitUntilScreenshotIsReady() { 59 if (!waiting_for_screenshots_) 60 return; 61 message_loop_runner_ = new content::MessageLoopRunner; 62 message_loop_runner_->Run(); 63 } 64 65 bool ScreenshotSetForEntry(NavigationEntryImpl* entry) const { 66 return screenshot_set_.count(entry) > 0; 67 } 68 69 private: 70 // Overridden from WebContentsScreenshotManager: 71 virtual void TakeScreenshotImpl(RenderViewHost* host, 72 NavigationEntryImpl* entry) OVERRIDE { 73 ++waiting_for_screenshots_; 74 screenshot_taken_for_ = host; 75 WebContentsScreenshotManager::TakeScreenshotImpl(host, entry); 76 } 77 78 virtual void OnScreenshotSet(NavigationEntryImpl* entry) OVERRIDE { 79 --waiting_for_screenshots_; 80 screenshot_set_[entry] = true; 81 WebContentsScreenshotManager::OnScreenshotSet(entry); 82 if (waiting_for_screenshots_ == 0 && message_loop_runner_.get()) 83 message_loop_runner_->Quit(); 84 } 85 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_; 90 91 DISALLOW_COPY_AND_ASSIGN(ScreenshotTracker); 92}; 93 94class NavigationWatcher : public WebContentsObserver { 95 public: 96 explicit NavigationWatcher(WebContents* contents) 97 : WebContentsObserver(contents), 98 navigated_(false), 99 should_quit_loop_(false) { 100 } 101 102 virtual ~NavigationWatcher() {} 103 104 void WaitUntilNavigationStarts() { 105 if (navigated_) 106 return; 107 should_quit_loop_ = true; 108 base::MessageLoop::current()->Run(); 109 } 110 111 private: 112 // Overridden from WebContentsObserver: 113 virtual void AboutToNavigateRenderView(RenderViewHost* host) OVERRIDE { 114 navigated_ = true; 115 if (should_quit_loop_) 116 base::MessageLoop::current()->Quit(); 117 } 118 119 bool navigated_; 120 bool should_quit_loop_; 121 122 DISALLOW_COPY_AND_ASSIGN(NavigationWatcher); 123}; 124 125class WebContentsViewAuraTest : public ContentBrowserTest { 126 public: 127 WebContentsViewAuraTest() 128 : screenshot_manager_(NULL) { 129 } 130 131 virtual void SetUp() OVERRIDE { 132 // TODO(jbauman): Remove this. http://crbug.com/268644 133 UseRealGLContexts(); 134 ContentBrowserTest::SetUp(); 135 } 136 137 // Executes the javascript synchronously and makes sure the returned value is 138 // freed properly. 139 void ExecuteSyncJSFunction(RenderViewHost* rvh, const std::string& jscript) { 140 scoped_ptr<base::Value> value = 141 content::ExecuteScriptAndGetValue(rvh, jscript); 142 } 143 144 // Starts the test server and navigates to the given url. Sets a large enough 145 // size to the root window. Returns after the navigation to the url is 146 // complete. 147 void StartTestWithPage(const std::string& url) { 148 ASSERT_TRUE(test_server()->Start()); 149 GURL test_url(test_server()->GetURL(url)); 150 NavigateToURL(shell(), test_url); 151 aura::Window* content = 152 shell()->web_contents()->GetView()->GetContentNativeView(); 153 content->GetDispatcher()->SetHostSize(gfx::Size(800, 600)); 154 155 WebContentsImpl* web_contents = 156 static_cast<WebContentsImpl*>(shell()->web_contents()); 157 NavigationControllerImpl* controller = &web_contents->GetController(); 158 159 screenshot_manager_ = new ScreenshotTracker(controller); 160 controller->SetScreenshotManager(screenshot_manager_); 161 } 162 163 void TestOverscrollNavigation(bool touch_handler) { 164 ASSERT_NO_FATAL_FAILURE( 165 StartTestWithPage("files/overscroll_navigation.html")); 166 WebContentsImpl* web_contents = 167 static_cast<WebContentsImpl*>(shell()->web_contents()); 168 NavigationController& controller = web_contents->GetController(); 169 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( 170 web_contents->GetRenderViewHost()); 171 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( 172 web_contents->GetView()); 173 view_aura->SetupOverlayWindowForTesting(); 174 175 EXPECT_FALSE(controller.CanGoBack()); 176 EXPECT_FALSE(controller.CanGoForward()); 177 int index = -1; 178 scoped_ptr<base::Value> value = 179 content::ExecuteScriptAndGetValue(view_host, "get_current()"); 180 ASSERT_TRUE(value->GetAsInteger(&index)); 181 EXPECT_EQ(0, index); 182 183 if (touch_handler) 184 ExecuteSyncJSFunction(view_host, "install_touch_handler()"); 185 186 ExecuteSyncJSFunction(view_host, "navigate_next()"); 187 ExecuteSyncJSFunction(view_host, "navigate_next()"); 188 value = content::ExecuteScriptAndGetValue(view_host, "get_current()"); 189 ASSERT_TRUE(value->GetAsInteger(&index)); 190 EXPECT_EQ(2, index); 191 EXPECT_TRUE(controller.CanGoBack()); 192 EXPECT_FALSE(controller.CanGoForward()); 193 194 aura::Window* content = web_contents->GetView()->GetContentNativeView(); 195 gfx::Rect bounds = content->GetBoundsInRootWindow(); 196 aura::test::EventGenerator generator(content->GetRootWindow(), content); 197 const int kScrollDurationMs = 20; 198 const int kScrollSteps = 10; 199 200 { 201 // Do a swipe-right now. That should navigate backwards. 202 string16 expected_title = ASCIIToUTF16("Title: #1"); 203 content::TitleWatcher title_watcher(web_contents, expected_title); 204 generator.GestureScrollSequence( 205 gfx::Point(bounds.x() + 2, bounds.y() + 10), 206 gfx::Point(bounds.right() - 10, bounds.y() + 10), 207 base::TimeDelta::FromMilliseconds(kScrollDurationMs), 208 kScrollSteps); 209 string16 actual_title = title_watcher.WaitAndGetTitle(); 210 EXPECT_EQ(expected_title, actual_title); 211 value = content::ExecuteScriptAndGetValue(view_host, "get_current()"); 212 ASSERT_TRUE(value->GetAsInteger(&index)); 213 EXPECT_EQ(1, index); 214 EXPECT_TRUE(controller.CanGoBack()); 215 EXPECT_TRUE(controller.CanGoForward()); 216 } 217 218 { 219 // Do a fling-right now. That should navigate backwards. 220 string16 expected_title = ASCIIToUTF16("Title:"); 221 content::TitleWatcher title_watcher(web_contents, expected_title); 222 generator.GestureScrollSequence( 223 gfx::Point(bounds.x() + 2, bounds.y() + 10), 224 gfx::Point(bounds.right() - 10, bounds.y() + 10), 225 base::TimeDelta::FromMilliseconds(kScrollDurationMs), 226 kScrollSteps); 227 string16 actual_title = title_watcher.WaitAndGetTitle(); 228 EXPECT_EQ(expected_title, actual_title); 229 value = content::ExecuteScriptAndGetValue(view_host, "get_current()"); 230 ASSERT_TRUE(value->GetAsInteger(&index)); 231 EXPECT_EQ(0, index); 232 EXPECT_FALSE(controller.CanGoBack()); 233 EXPECT_TRUE(controller.CanGoForward()); 234 } 235 236 { 237 // Do a swipe-left now. That should navigate forward. 238 string16 expected_title = ASCIIToUTF16("Title: #1"); 239 content::TitleWatcher title_watcher(web_contents, expected_title); 240 generator.GestureScrollSequence( 241 gfx::Point(bounds.right() - 10, bounds.y() + 10), 242 gfx::Point(bounds.x() + 2, bounds.y() + 10), 243 base::TimeDelta::FromMilliseconds(kScrollDurationMs), 244 kScrollSteps); 245 string16 actual_title = title_watcher.WaitAndGetTitle(); 246 EXPECT_EQ(expected_title, actual_title); 247 value = content::ExecuteScriptAndGetValue(view_host, "get_current()"); 248 ASSERT_TRUE(value->GetAsInteger(&index)); 249 EXPECT_EQ(1, index); 250 EXPECT_TRUE(controller.CanGoBack()); 251 EXPECT_TRUE(controller.CanGoForward()); 252 } 253 } 254 255 int GetCurrentIndex() { 256 WebContentsImpl* web_contents = 257 static_cast<WebContentsImpl*>(shell()->web_contents()); 258 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( 259 web_contents->GetRenderViewHost()); 260 int index = -1; 261 scoped_ptr<base::Value> value; 262 value = content::ExecuteScriptAndGetValue(view_host, "get_current()"); 263 if (!value->GetAsInteger(&index)) 264 index = -1; 265 return index; 266 } 267 268 protected: 269 ScreenshotTracker* screenshot_manager() { return screenshot_manager_; } 270 void set_min_screenshot_interval(int interval_ms) { 271 screenshot_manager_->SetScreenshotInterval(interval_ms); 272 } 273 274 private: 275 ScreenshotTracker* screenshot_manager_; 276 277 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAuraTest); 278}; 279 280// Flaky on Windows (perhaps just Win-Aura): http://crbug.com/305722 281#if defined(OS_WIN) 282#define MAYBE_OverscrollNavigation DISABLED_OverscrollNavigation 283#else 284#define MAYBE_OverscrollNavigation OverscrollNavigation 285#endif 286IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, MAYBE_OverscrollNavigation) { 287 TestOverscrollNavigation(false); 288} 289 290// Flaky on Windows (perhaps just Win-Aura): http://crbug.com/305722 291#if defined(OS_WIN) 292#define MAYBE_OverscrollNavigationWithTouchHandler \ 293 DISABLED_OverscrollNavigationWithTouchHandler 294#else 295#define MAYBE_OverscrollNavigationWithTouchHandler \ 296 OverscrollNavigationWithTouchHandler 297#endif 298IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 299 MAYBE_OverscrollNavigationWithTouchHandler) { 300 TestOverscrollNavigation(true); 301} 302 303// Disabled because the test always fails the first time it runs on the Win Aura 304// bots, and usually but not always passes second-try (See crbug.com/179532). 305#if defined(OS_WIN) 306#define MAYBE_QuickOverscrollDirectionChange \ 307 DISABLED_QuickOverscrollDirectionChange 308#else 309#define MAYBE_QuickOverscrollDirectionChange QuickOverscrollDirectionChange 310#endif 311IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 312 MAYBE_QuickOverscrollDirectionChange) { 313 ASSERT_NO_FATAL_FAILURE( 314 StartTestWithPage("files/overscroll_navigation.html")); 315 WebContentsImpl* web_contents = 316 static_cast<WebContentsImpl*>(shell()->web_contents()); 317 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( 318 web_contents->GetRenderViewHost()); 319 320 // This test triggers a large number of animations. Speed them up to ensure 321 // the test completes within its time limit. 322 ui::ScopedAnimationDurationScaleMode fast_duration_mode( 323 ui::ScopedAnimationDurationScaleMode::FAST_DURATION); 324 325 // Make sure the page has both back/forward history. 326 ExecuteSyncJSFunction(view_host, "navigate_next()"); 327 EXPECT_EQ(1, GetCurrentIndex()); 328 ExecuteSyncJSFunction(view_host, "navigate_next()"); 329 EXPECT_EQ(2, GetCurrentIndex()); 330 web_contents->GetController().GoBack(); 331 EXPECT_EQ(1, GetCurrentIndex()); 332 333 aura::Window* content = web_contents->GetView()->GetContentNativeView(); 334 aura::WindowEventDispatcher* dispatcher = content->GetDispatcher(); 335 gfx::Rect bounds = content->GetBoundsInRootWindow(); 336 337 base::TimeDelta timestamp; 338 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, 339 gfx::Point(bounds.x() + bounds.width() / 2, bounds.y() + 5), 340 0, timestamp); 341 dispatcher->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 342 EXPECT_EQ(1, GetCurrentIndex()); 343 344 timestamp += base::TimeDelta::FromMilliseconds(10); 345 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, 346 gfx::Point(bounds.right() - 10, bounds.y() + 5), 347 0, timestamp); 348 dispatcher->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); 349 EXPECT_EQ(1, GetCurrentIndex()); 350 351 // Swipe back from the right edge, back to the left edge, back to the right 352 // edge. 353 354 for (int x = bounds.right() - 10; x >= bounds.x() + 10; x-= 10) { 355 timestamp += base::TimeDelta::FromMilliseconds(10); 356 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, 357 gfx::Point(x, bounds.y() + 5), 358 0, timestamp); 359 dispatcher->AsRootWindowHostDelegate()->OnHostTouchEvent(&inc); 360 EXPECT_EQ(1, GetCurrentIndex()); 361 } 362 363 for (int x = bounds.x() + 10; x <= bounds.width() - 10; x+= 10) { 364 timestamp += base::TimeDelta::FromMilliseconds(10); 365 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, 366 gfx::Point(x, bounds.y() + 5), 367 0, timestamp); 368 dispatcher->AsRootWindowHostDelegate()->OnHostTouchEvent(&inc); 369 EXPECT_EQ(1, GetCurrentIndex()); 370 } 371 372 for (int x = bounds.width() - 10; x >= bounds.x() + 10; x-= 10) { 373 timestamp += base::TimeDelta::FromMilliseconds(10); 374 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, 375 gfx::Point(x, bounds.y() + 5), 376 0, timestamp); 377 dispatcher->AsRootWindowHostDelegate()->OnHostTouchEvent(&inc); 378 EXPECT_EQ(1, GetCurrentIndex()); 379 } 380 381 // Do not end the overscroll sequence. 382} 383 384// Tests that the page has has a screenshot when navigation happens: 385// - from within the page (from a JS function) 386// - interactively, when user does an overscroll gesture 387// - interactively, when user navigates in history without the overscroll 388// gesture. 389IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 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 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( 403 web_contents->GetRenderViewHost()); 404 405 set_min_screenshot_interval(0); 406 407 // Do a few navigations initiated by the page. 408 ExecuteSyncJSFunction(view_host, "navigate_next()"); 409 EXPECT_EQ(1, GetCurrentIndex()); 410 ExecuteSyncJSFunction(view_host, "navigate_next()"); 411 EXPECT_EQ(2, GetCurrentIndex()); 412 screenshot_manager()->WaitUntilScreenshotIsReady(); 413 414 // The current entry won't have any screenshots. But the entries in the 415 // history should now have screenshots. 416 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( 417 web_contents->GetController().GetEntryAtIndex(2)); 418 EXPECT_FALSE(entry->screenshot().get()); 419 420 entry = NavigationEntryImpl::FromNavigationEntry( 421 web_contents->GetController().GetEntryAtIndex(1)); 422 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 423 424 entry = NavigationEntryImpl::FromNavigationEntry( 425 web_contents->GetController().GetEntryAtIndex(0)); 426 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 427 428 // Navigate again. Index 2 should now have a screenshot. 429 ExecuteSyncJSFunction(view_host, "navigate_next()"); 430 EXPECT_EQ(3, GetCurrentIndex()); 431 screenshot_manager()->WaitUntilScreenshotIsReady(); 432 433 entry = NavigationEntryImpl::FromNavigationEntry( 434 web_contents->GetController().GetEntryAtIndex(2)); 435 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 436 437 entry = NavigationEntryImpl::FromNavigationEntry( 438 web_contents->GetController().GetEntryAtIndex(3)); 439 EXPECT_FALSE(entry->screenshot().get()); 440 441 { 442 // Now, swipe right to navigate backwards. This should navigate away from 443 // index 3 to index 2, and index 3 should have a screenshot. 444 string16 expected_title = ASCIIToUTF16("Title: #2"); 445 content::TitleWatcher title_watcher(web_contents, expected_title); 446 aura::Window* content = web_contents->GetView()->GetContentNativeView(); 447 gfx::Rect bounds = content->GetBoundsInRootWindow(); 448 aura::test::EventGenerator generator(content->GetRootWindow(), content); 449 generator.GestureScrollSequence( 450 gfx::Point(bounds.x() + 2, bounds.y() + 10), 451 gfx::Point(bounds.right() - 10, bounds.y() + 10), 452 base::TimeDelta::FromMilliseconds(20), 453 1); 454 string16 actual_title = title_watcher.WaitAndGetTitle(); 455 EXPECT_EQ(expected_title, actual_title); 456 EXPECT_EQ(2, GetCurrentIndex()); 457 screenshot_manager()->WaitUntilScreenshotIsReady(); 458 entry = NavigationEntryImpl::FromNavigationEntry( 459 web_contents->GetController().GetEntryAtIndex(3)); 460 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 461 } 462 463 // Navigate a couple more times. 464 ExecuteSyncJSFunction(view_host, "navigate_next()"); 465 EXPECT_EQ(3, GetCurrentIndex()); 466 ExecuteSyncJSFunction(view_host, "navigate_next()"); 467 EXPECT_EQ(4, GetCurrentIndex()); 468 screenshot_manager()->WaitUntilScreenshotIsReady(); 469 entry = NavigationEntryImpl::FromNavigationEntry( 470 web_contents->GetController().GetEntryAtIndex(4)); 471 EXPECT_FALSE(entry->screenshot().get()); 472 473 { 474 // Navigate back in history. 475 string16 expected_title = ASCIIToUTF16("Title: #3"); 476 content::TitleWatcher title_watcher(web_contents, expected_title); 477 web_contents->GetController().GoBack(); 478 string16 actual_title = title_watcher.WaitAndGetTitle(); 479 EXPECT_EQ(expected_title, actual_title); 480 EXPECT_EQ(3, GetCurrentIndex()); 481 screenshot_manager()->WaitUntilScreenshotIsReady(); 482 entry = NavigationEntryImpl::FromNavigationEntry( 483 web_contents->GetController().GetEntryAtIndex(4)); 484 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 485 } 486} 487 488// Tests that screenshot is taken correctly when navigation causes a 489// RenderViewHost to be swapped out. 490IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 491 ScreenshotForSwappedOutRenderViews) { 492 ASSERT_NO_FATAL_FAILURE( 493 StartTestWithPage("files/overscroll_navigation.html")); 494 // Create a new server with a different site. 495 net::SpawnedTestServer https_server( 496 net::SpawnedTestServer::TYPE_HTTPS, 497 net::SpawnedTestServer::kLocalhost, 498 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); 499 ASSERT_TRUE(https_server.Start()); 500 501 WebContentsImpl* web_contents = 502 static_cast<WebContentsImpl*>(shell()->web_contents()); 503 set_min_screenshot_interval(0); 504 505 struct { 506 GURL url; 507 int transition; 508 } navigations[] = { 509 { https_server.GetURL("files/title1.html"), 510 PAGE_TRANSITION_TYPED | PAGE_TRANSITION_FROM_ADDRESS_BAR }, 511 { test_server()->GetURL("files/title2.html"), 512 PAGE_TRANSITION_AUTO_BOOKMARK }, 513 { https_server.GetURL("files/title3.html"), 514 PAGE_TRANSITION_TYPED | PAGE_TRANSITION_FROM_ADDRESS_BAR }, 515 { GURL(), 0 } 516 }; 517 518 screenshot_manager()->Reset(); 519 for (int i = 0; !navigations[i].url.is_empty(); ++i) { 520 // Navigate via the user initiating a navigation from the UI. 521 NavigationController::LoadURLParams params(navigations[i].url); 522 params.transition_type = PageTransitionFromInt(navigations[i].transition); 523 524 RenderViewHost* old_host = web_contents->GetRenderViewHost(); 525 web_contents->GetController().LoadURLWithParams(params); 526 WaitForLoadStop(web_contents); 527 screenshot_manager()->WaitUntilScreenshotIsReady(); 528 529 EXPECT_NE(old_host, web_contents->GetRenderViewHost()) 530 << navigations[i].url.spec(); 531 EXPECT_EQ(old_host, screenshot_manager()->screenshot_taken_for()); 532 533 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( 534 web_contents->GetController().GetEntryAtOffset(-1)); 535 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 536 537 entry = NavigationEntryImpl::FromNavigationEntry( 538 web_contents->GetController().GetLastCommittedEntry()); 539 EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry)); 540 EXPECT_FALSE(entry->screenshot().get()); 541 screenshot_manager()->Reset(); 542 } 543 544 // Increase the minimum interval between taking screenshots. 545 set_min_screenshot_interval(60000); 546 547 // Navigate again. This should not take any screenshot because of the 548 // increased screenshot interval. 549 NavigationController::LoadURLParams params(navigations[0].url); 550 params.transition_type = PageTransitionFromInt(navigations[0].transition); 551 web_contents->GetController().LoadURLWithParams(params); 552 WaitForLoadStop(web_contents); 553 screenshot_manager()->WaitUntilScreenshotIsReady(); 554 555 EXPECT_EQ(NULL, screenshot_manager()->screenshot_taken_for()); 556} 557 558// TODO(sadrul): This test is disabled because it reparents in a way the 559// FocusController does not support. This code would crash in 560// a production build. It only passed prior to this revision 561// because testing used the old FocusManager which did some 562// different (osbolete) processing. TODO(sadrul) to figure out 563// how this test should work that mimics production code a bit 564// better. 565IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 566 DISABLED_ContentWindowReparent) { 567 ASSERT_NO_FATAL_FAILURE( 568 StartTestWithPage("files/overscroll_navigation.html")); 569 570 scoped_ptr<aura::Window> window(new aura::Window(NULL)); 571 window->Init(ui::LAYER_NOT_DRAWN); 572 573 WebContentsImpl* web_contents = 574 static_cast<WebContentsImpl*>(shell()->web_contents()); 575 ExecuteSyncJSFunction(web_contents->GetRenderViewHost(), "navigate_next()"); 576 EXPECT_EQ(1, GetCurrentIndex()); 577 578 aura::Window* content = web_contents->GetView()->GetContentNativeView(); 579 gfx::Rect bounds = content->GetBoundsInRootWindow(); 580 aura::test::EventGenerator generator(content->GetRootWindow(), content); 581 generator.GestureScrollSequence( 582 gfx::Point(bounds.x() + 2, bounds.y() + 10), 583 gfx::Point(bounds.right() - 10, bounds.y() + 10), 584 base::TimeDelta::FromMilliseconds(20), 585 1); 586 587 window->AddChild(shell()->web_contents()->GetView()->GetContentNativeView()); 588} 589 590IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 591 ContentWindowClose) { 592 ASSERT_NO_FATAL_FAILURE( 593 StartTestWithPage("files/overscroll_navigation.html")); 594 595 WebContentsImpl* web_contents = 596 static_cast<WebContentsImpl*>(shell()->web_contents()); 597 ExecuteSyncJSFunction(web_contents->GetRenderViewHost(), "navigate_next()"); 598 EXPECT_EQ(1, GetCurrentIndex()); 599 600 aura::Window* content = web_contents->GetView()->GetContentNativeView(); 601 gfx::Rect bounds = content->GetBoundsInRootWindow(); 602 aura::test::EventGenerator generator(content->GetRootWindow(), content); 603 generator.GestureScrollSequence( 604 gfx::Point(bounds.x() + 2, bounds.y() + 10), 605 gfx::Point(bounds.right() - 10, bounds.y() + 10), 606 base::TimeDelta::FromMilliseconds(20), 607 1); 608 609 delete web_contents->GetView()->GetContentNativeView(); 610} 611 612IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 613 RepeatedQuickOverscrollGestures) { 614 ASSERT_NO_FATAL_FAILURE( 615 StartTestWithPage("files/overscroll_navigation.html")); 616 617 WebContentsImpl* web_contents = 618 static_cast<WebContentsImpl*>(shell()->web_contents()); 619 NavigationController& controller = web_contents->GetController(); 620 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( 621 web_contents->GetRenderViewHost()); 622 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( 623 web_contents->GetView()); 624 view_aura->SetupOverlayWindowForTesting(); 625 ExecuteSyncJSFunction(view_host, "install_touch_handler()"); 626 627 // Navigate twice, then navigate back in history once. 628 ExecuteSyncJSFunction(view_host, "navigate_next()"); 629 ExecuteSyncJSFunction(view_host, "navigate_next()"); 630 EXPECT_EQ(2, GetCurrentIndex()); 631 EXPECT_TRUE(controller.CanGoBack()); 632 EXPECT_FALSE(controller.CanGoForward()); 633 634 web_contents->GetController().GoBack(); 635 WaitForLoadStop(web_contents); 636 EXPECT_EQ(1, GetCurrentIndex()); 637 EXPECT_EQ(base::ASCIIToUTF16("Title: #1"), web_contents->GetTitle()); 638 EXPECT_TRUE(controller.CanGoBack()); 639 EXPECT_TRUE(controller.CanGoForward()); 640 641 aura::Window* content = web_contents->GetView()->GetContentNativeView(); 642 gfx::Rect bounds = content->GetBoundsInRootWindow(); 643 aura::test::EventGenerator generator(content->GetRootWindow(), content); 644 645 // Do a swipe left to start a forward navigation. Then quickly do a swipe 646 // right. 647 string16 expected_title = ASCIIToUTF16("Title: #2"); 648 content::TitleWatcher title_watcher(web_contents, expected_title); 649 NavigationWatcher nav_watcher(web_contents); 650 651 generator.GestureScrollSequence( 652 gfx::Point(bounds.right() - 10, bounds.y() + 10), 653 gfx::Point(bounds.x() + 2, bounds.y() + 10), 654 base::TimeDelta::FromMilliseconds(2000), 655 10); 656 nav_watcher.WaitUntilNavigationStarts(); 657 658 generator.GestureScrollSequence( 659 gfx::Point(bounds.x() + 2, bounds.y() + 10), 660 gfx::Point(bounds.right() - 10, bounds.y() + 10), 661 base::TimeDelta::FromMilliseconds(2000), 662 10); 663 string16 actual_title = title_watcher.WaitAndGetTitle(); 664 EXPECT_EQ(expected_title, actual_title); 665 666 EXPECT_EQ(2, GetCurrentIndex()); 667 EXPECT_TRUE(controller.CanGoBack()); 668 EXPECT_FALSE(controller.CanGoForward()); 669} 670 671} // namespace content 672