web_contents_view_aura_browsertest.cc revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
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/renderer_host/render_view_host_impl.h" 16#include "content/browser/web_contents/navigation_controller_impl.h" 17#include "content/browser/web_contents/navigation_entry_impl.h" 18#include "content/browser/web_contents/web_contents_impl.h" 19#include "content/browser/web_contents/web_contents_screenshot_manager.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->GetRootWindow()->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 280IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 281 OverscrollNavigation) { 282 TestOverscrollNavigation(false); 283} 284 285IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 286 OverscrollNavigationWithTouchHandler) { 287 TestOverscrollNavigation(true); 288} 289 290// Disabled because the test always fails the first time it runs on the Win Aura 291// bots, and usually but not always passes second-try (See crbug.com/179532). 292#if defined(OS_WIN) 293#define MAYBE_QuickOverscrollDirectionChange \ 294 DISABLED_QuickOverscrollDirectionChange 295#else 296#define MAYBE_QuickOverscrollDirectionChange QuickOverscrollDirectionChange 297#endif 298IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 299 MAYBE_QuickOverscrollDirectionChange) { 300 ASSERT_NO_FATAL_FAILURE( 301 StartTestWithPage("files/overscroll_navigation.html")); 302 WebContentsImpl* web_contents = 303 static_cast<WebContentsImpl*>(shell()->web_contents()); 304 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( 305 web_contents->GetRenderViewHost()); 306 307 // This test triggers a large number of animations. Speed them up to ensure 308 // the test completes within its time limit. 309 ui::ScopedAnimationDurationScaleMode fast_duration_mode( 310 ui::ScopedAnimationDurationScaleMode::FAST_DURATION); 311 312 // Make sure the page has both back/forward history. 313 ExecuteSyncJSFunction(view_host, "navigate_next()"); 314 EXPECT_EQ(1, GetCurrentIndex()); 315 ExecuteSyncJSFunction(view_host, "navigate_next()"); 316 EXPECT_EQ(2, GetCurrentIndex()); 317 web_contents->GetController().GoBack(); 318 EXPECT_EQ(1, GetCurrentIndex()); 319 320 aura::Window* content = web_contents->GetView()->GetContentNativeView(); 321 aura::RootWindow* root_window = content->GetRootWindow(); 322 gfx::Rect bounds = content->GetBoundsInRootWindow(); 323 324 base::TimeDelta timestamp; 325 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, 326 gfx::Point(bounds.x() + bounds.width() / 2, bounds.y() + 5), 327 0, timestamp); 328 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 329 EXPECT_EQ(1, GetCurrentIndex()); 330 331 timestamp += base::TimeDelta::FromMilliseconds(10); 332 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, 333 gfx::Point(bounds.right() - 10, bounds.y() + 5), 334 0, timestamp); 335 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); 336 EXPECT_EQ(1, GetCurrentIndex()); 337 338 // Swipe back from the right edge, back to the left edge, back to the right 339 // edge. 340 341 for (int x = bounds.right() - 10; x >= bounds.x() + 10; x-= 10) { 342 timestamp += base::TimeDelta::FromMilliseconds(10); 343 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, 344 gfx::Point(x, bounds.y() + 5), 345 0, timestamp); 346 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&inc); 347 EXPECT_EQ(1, GetCurrentIndex()); 348 } 349 350 for (int x = bounds.x() + 10; x <= bounds.width() - 10; x+= 10) { 351 timestamp += base::TimeDelta::FromMilliseconds(10); 352 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, 353 gfx::Point(x, bounds.y() + 5), 354 0, timestamp); 355 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&inc); 356 EXPECT_EQ(1, GetCurrentIndex()); 357 } 358 359 for (int x = bounds.width() - 10; x >= bounds.x() + 10; x-= 10) { 360 timestamp += base::TimeDelta::FromMilliseconds(10); 361 ui::TouchEvent inc(ui::ET_TOUCH_MOVED, 362 gfx::Point(x, bounds.y() + 5), 363 0, timestamp); 364 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&inc); 365 EXPECT_EQ(1, GetCurrentIndex()); 366 } 367 368 // Do not end the overscroll sequence. 369} 370 371// Tests that the page has has a screenshot when navigation happens: 372// - from within the page (from a JS function) 373// - interactively, when user does an overscroll gesture 374// - interactively, when user navigates in history without the overscroll 375// gesture. 376IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, OverscrollScreenshot) { 377 // Disable the test for WinXP. See http://crbug/294116. 378#if defined(OS_WIN) 379 if (base::win::GetVersion() < base::win::VERSION_VISTA) { 380 LOG(WARNING) << "Test disabled due to unknown bug on WinXP."; 381 return; 382 } 383#endif 384 385 ASSERT_NO_FATAL_FAILURE( 386 StartTestWithPage("files/overscroll_navigation.html")); 387 WebContentsImpl* web_contents = 388 static_cast<WebContentsImpl*>(shell()->web_contents()); 389 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( 390 web_contents->GetRenderViewHost()); 391 392 set_min_screenshot_interval(0); 393 394 // Do a few navigations initiated by the page. 395 ExecuteSyncJSFunction(view_host, "navigate_next()"); 396 EXPECT_EQ(1, GetCurrentIndex()); 397 ExecuteSyncJSFunction(view_host, "navigate_next()"); 398 EXPECT_EQ(2, GetCurrentIndex()); 399 screenshot_manager()->WaitUntilScreenshotIsReady(); 400 401 // The current entry won't have any screenshots. But the entries in the 402 // history should now have screenshots. 403 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( 404 web_contents->GetController().GetEntryAtIndex(2)); 405 EXPECT_FALSE(entry->screenshot().get()); 406 407 entry = NavigationEntryImpl::FromNavigationEntry( 408 web_contents->GetController().GetEntryAtIndex(1)); 409 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 410 411 entry = NavigationEntryImpl::FromNavigationEntry( 412 web_contents->GetController().GetEntryAtIndex(0)); 413 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 414 415 // Navigate again. Index 2 should now have a screenshot. 416 ExecuteSyncJSFunction(view_host, "navigate_next()"); 417 EXPECT_EQ(3, GetCurrentIndex()); 418 screenshot_manager()->WaitUntilScreenshotIsReady(); 419 420 entry = NavigationEntryImpl::FromNavigationEntry( 421 web_contents->GetController().GetEntryAtIndex(2)); 422 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 423 424 entry = NavigationEntryImpl::FromNavigationEntry( 425 web_contents->GetController().GetEntryAtIndex(3)); 426 EXPECT_FALSE(entry->screenshot().get()); 427 428 { 429 // Now, swipe right to navigate backwards. This should navigate away from 430 // index 3 to index 2, and index 3 should have a screenshot. 431 string16 expected_title = ASCIIToUTF16("Title: #2"); 432 content::TitleWatcher title_watcher(web_contents, expected_title); 433 aura::Window* content = web_contents->GetView()->GetContentNativeView(); 434 gfx::Rect bounds = content->GetBoundsInRootWindow(); 435 aura::test::EventGenerator generator(content->GetRootWindow(), content); 436 generator.GestureScrollSequence( 437 gfx::Point(bounds.x() + 2, bounds.y() + 10), 438 gfx::Point(bounds.right() - 10, bounds.y() + 10), 439 base::TimeDelta::FromMilliseconds(20), 440 1); 441 string16 actual_title = title_watcher.WaitAndGetTitle(); 442 EXPECT_EQ(expected_title, actual_title); 443 EXPECT_EQ(2, GetCurrentIndex()); 444 screenshot_manager()->WaitUntilScreenshotIsReady(); 445 entry = NavigationEntryImpl::FromNavigationEntry( 446 web_contents->GetController().GetEntryAtIndex(3)); 447 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 448 } 449 450 // Navigate a couple more times. 451 ExecuteSyncJSFunction(view_host, "navigate_next()"); 452 EXPECT_EQ(3, GetCurrentIndex()); 453 ExecuteSyncJSFunction(view_host, "navigate_next()"); 454 EXPECT_EQ(4, GetCurrentIndex()); 455 screenshot_manager()->WaitUntilScreenshotIsReady(); 456 entry = NavigationEntryImpl::FromNavigationEntry( 457 web_contents->GetController().GetEntryAtIndex(4)); 458 EXPECT_FALSE(entry->screenshot().get()); 459 460 { 461 // Navigate back in history. 462 string16 expected_title = ASCIIToUTF16("Title: #3"); 463 content::TitleWatcher title_watcher(web_contents, expected_title); 464 web_contents->GetController().GoBack(); 465 string16 actual_title = title_watcher.WaitAndGetTitle(); 466 EXPECT_EQ(expected_title, actual_title); 467 EXPECT_EQ(3, GetCurrentIndex()); 468 screenshot_manager()->WaitUntilScreenshotIsReady(); 469 entry = NavigationEntryImpl::FromNavigationEntry( 470 web_contents->GetController().GetEntryAtIndex(4)); 471 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 472 } 473} 474 475// Tests that screenshot is taken correctly when navigation causes a 476// RenderViewHost to be swapped out. 477IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 478 ScreenshotForSwappedOutRenderViews) { 479 ASSERT_NO_FATAL_FAILURE( 480 StartTestWithPage("files/overscroll_navigation.html")); 481 // Create a new server with a different site. 482 net::SpawnedTestServer https_server( 483 net::SpawnedTestServer::TYPE_HTTPS, 484 net::SpawnedTestServer::kLocalhost, 485 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); 486 ASSERT_TRUE(https_server.Start()); 487 488 WebContentsImpl* web_contents = 489 static_cast<WebContentsImpl*>(shell()->web_contents()); 490 set_min_screenshot_interval(0); 491 492 struct { 493 GURL url; 494 int transition; 495 } navigations[] = { 496 { https_server.GetURL("files/title1.html"), 497 PAGE_TRANSITION_TYPED | PAGE_TRANSITION_FROM_ADDRESS_BAR }, 498 { test_server()->GetURL("files/title2.html"), 499 PAGE_TRANSITION_AUTO_BOOKMARK }, 500 { https_server.GetURL("files/title3.html"), 501 PAGE_TRANSITION_TYPED | PAGE_TRANSITION_FROM_ADDRESS_BAR }, 502 { GURL(), 0 } 503 }; 504 505 screenshot_manager()->Reset(); 506 for (int i = 0; !navigations[i].url.is_empty(); ++i) { 507 // Navigate via the user initiating a navigation from the UI. 508 NavigationController::LoadURLParams params(navigations[i].url); 509 params.transition_type = PageTransitionFromInt(navigations[i].transition); 510 511 RenderViewHost* old_host = web_contents->GetRenderViewHost(); 512 web_contents->GetController().LoadURLWithParams(params); 513 WaitForLoadStop(web_contents); 514 screenshot_manager()->WaitUntilScreenshotIsReady(); 515 516 EXPECT_NE(old_host, web_contents->GetRenderViewHost()) 517 << navigations[i].url.spec(); 518 EXPECT_EQ(old_host, screenshot_manager()->screenshot_taken_for()); 519 520 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( 521 web_contents->GetController().GetEntryAtOffset(-1)); 522 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 523 524 entry = NavigationEntryImpl::FromNavigationEntry( 525 web_contents->GetController().GetLastCommittedEntry()); 526 EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry)); 527 EXPECT_FALSE(entry->screenshot().get()); 528 screenshot_manager()->Reset(); 529 } 530 531 // Increase the minimum interval between taking screenshots. 532 set_min_screenshot_interval(60000); 533 534 // Navigate again. This should not take any screenshot because of the 535 // increased screenshot interval. 536 NavigationController::LoadURLParams params(navigations[0].url); 537 params.transition_type = PageTransitionFromInt(navigations[0].transition); 538 web_contents->GetController().LoadURLWithParams(params); 539 WaitForLoadStop(web_contents); 540 screenshot_manager()->WaitUntilScreenshotIsReady(); 541 542 EXPECT_EQ(NULL, screenshot_manager()->screenshot_taken_for()); 543} 544 545// Failing on win7_aura trybot (see crbug.com/260983). 546#if defined(OS_WIN) 547#define MAYBE_ContentWindowReparent \ 548 DISABLED_ContentWindowReparent 549#else 550#define MAYBE_ContentWindowReparent ContentWindowReparent 551#endif 552IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 553 MAYBE_ContentWindowReparent) { 554 ASSERT_NO_FATAL_FAILURE( 555 StartTestWithPage("files/overscroll_navigation.html")); 556 557 scoped_ptr<aura::Window> window(new aura::Window(NULL)); 558 window->Init(ui::LAYER_NOT_DRAWN); 559 560 WebContentsImpl* web_contents = 561 static_cast<WebContentsImpl*>(shell()->web_contents()); 562 ExecuteSyncJSFunction(web_contents->GetRenderViewHost(), "navigate_next()"); 563 EXPECT_EQ(1, GetCurrentIndex()); 564 565 aura::Window* content = web_contents->GetView()->GetContentNativeView(); 566 gfx::Rect bounds = content->GetBoundsInRootWindow(); 567 aura::test::EventGenerator generator(content->GetRootWindow(), content); 568 generator.GestureScrollSequence( 569 gfx::Point(bounds.x() + 2, bounds.y() + 10), 570 gfx::Point(bounds.right() - 10, bounds.y() + 10), 571 base::TimeDelta::FromMilliseconds(20), 572 1); 573 574 window->AddChild(shell()->web_contents()->GetView()->GetContentNativeView()); 575} 576 577IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 578 ContentWindowClose) { 579 ASSERT_NO_FATAL_FAILURE( 580 StartTestWithPage("files/overscroll_navigation.html")); 581 582 WebContentsImpl* web_contents = 583 static_cast<WebContentsImpl*>(shell()->web_contents()); 584 ExecuteSyncJSFunction(web_contents->GetRenderViewHost(), "navigate_next()"); 585 EXPECT_EQ(1, GetCurrentIndex()); 586 587 aura::Window* content = web_contents->GetView()->GetContentNativeView(); 588 gfx::Rect bounds = content->GetBoundsInRootWindow(); 589 aura::test::EventGenerator generator(content->GetRootWindow(), content); 590 generator.GestureScrollSequence( 591 gfx::Point(bounds.x() + 2, bounds.y() + 10), 592 gfx::Point(bounds.right() - 10, bounds.y() + 10), 593 base::TimeDelta::FromMilliseconds(20), 594 1); 595 596 delete web_contents->GetView()->GetContentNativeView(); 597} 598 599IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 600 RepeatedQuickOverscrollGestures) { 601 ASSERT_NO_FATAL_FAILURE( 602 StartTestWithPage("files/overscroll_navigation.html")); 603 604 WebContentsImpl* web_contents = 605 static_cast<WebContentsImpl*>(shell()->web_contents()); 606 NavigationController& controller = web_contents->GetController(); 607 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( 608 web_contents->GetRenderViewHost()); 609 WebContentsViewAura* view_aura = static_cast<WebContentsViewAura*>( 610 web_contents->GetView()); 611 view_aura->SetupOverlayWindowForTesting(); 612 ExecuteSyncJSFunction(view_host, "install_touch_handler()"); 613 614 // Navigate twice, then navigate back in history once. 615 ExecuteSyncJSFunction(view_host, "navigate_next()"); 616 ExecuteSyncJSFunction(view_host, "navigate_next()"); 617 EXPECT_EQ(2, GetCurrentIndex()); 618 EXPECT_TRUE(controller.CanGoBack()); 619 EXPECT_FALSE(controller.CanGoForward()); 620 621 web_contents->GetController().GoBack(); 622 WaitForLoadStop(web_contents); 623 EXPECT_EQ(1, GetCurrentIndex()); 624 EXPECT_EQ(base::ASCIIToUTF16("Title: #1"), web_contents->GetTitle()); 625 EXPECT_TRUE(controller.CanGoBack()); 626 EXPECT_TRUE(controller.CanGoForward()); 627 628 aura::Window* content = web_contents->GetView()->GetContentNativeView(); 629 gfx::Rect bounds = content->GetBoundsInRootWindow(); 630 aura::test::EventGenerator generator(content->GetRootWindow(), content); 631 632 // Do a swipe left to start a forward navigation. Then quickly do a swipe 633 // right. 634 string16 expected_title = ASCIIToUTF16("Title: #2"); 635 content::TitleWatcher title_watcher(web_contents, expected_title); 636 NavigationWatcher nav_watcher(web_contents); 637 638 generator.GestureScrollSequence( 639 gfx::Point(bounds.right() - 10, bounds.y() + 10), 640 gfx::Point(bounds.x() + 2, bounds.y() + 10), 641 base::TimeDelta::FromMilliseconds(2000), 642 10); 643 nav_watcher.WaitUntilNavigationStarts(); 644 645 generator.GestureScrollSequence( 646 gfx::Point(bounds.x() + 2, bounds.y() + 10), 647 gfx::Point(bounds.right() - 10, bounds.y() + 10), 648 base::TimeDelta::FromMilliseconds(2000), 649 10); 650 string16 actual_title = title_watcher.WaitAndGetTitle(); 651 EXPECT_EQ(expected_title, actual_title); 652 653 EXPECT_EQ(2, GetCurrentIndex()); 654 EXPECT_TRUE(controller.CanGoBack()); 655 EXPECT_FALSE(controller.CanGoForward()); 656} 657 658} // namespace content 659