| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/web_contents/web_contents_view_aura.h" | 5 #include "content/browser/web_contents/web_contents_view_aura.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 | 401 |
| 402 ASSERT_NO_FATAL_FAILURE( | 402 ASSERT_NO_FATAL_FAILURE( |
| 403 StartTestWithPage("files/overscroll_navigation.html")); | 403 StartTestWithPage("files/overscroll_navigation.html")); |
| 404 WebContentsImpl* web_contents = | 404 WebContentsImpl* web_contents = |
| 405 static_cast<WebContentsImpl*>(shell()->web_contents()); | 405 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 406 RenderFrameHost* main_frame = web_contents->GetMainFrame(); | 406 RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
| 407 | 407 |
| 408 set_min_screenshot_interval(0); | 408 set_min_screenshot_interval(0); |
| 409 | 409 |
| 410 // Do a few navigations initiated by the page. | 410 // Do a few navigations initiated by the page. |
| 411 // Screenshots should never be captured since these are all in-page |
| 412 // navigations. |
| 411 ExecuteSyncJSFunction(main_frame, "navigate_next()"); | 413 ExecuteSyncJSFunction(main_frame, "navigate_next()"); |
| 412 EXPECT_EQ(1, GetCurrentIndex()); | 414 EXPECT_EQ(1, GetCurrentIndex()); |
| 413 ExecuteSyncJSFunction(main_frame, "navigate_next()"); | 415 ExecuteSyncJSFunction(main_frame, "navigate_next()"); |
| 414 EXPECT_EQ(2, GetCurrentIndex()); | 416 EXPECT_EQ(2, GetCurrentIndex()); |
| 415 screenshot_manager()->WaitUntilScreenshotIsReady(); | 417 screenshot_manager()->WaitUntilScreenshotIsReady(); |
| 416 | 418 |
| 417 // The current entry won't have any screenshots. But the entries in the | |
| 418 // history should now have screenshots. | |
| 419 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( | 419 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( |
| 420 web_contents->GetController().GetEntryAtIndex(2)); | 420 web_contents->GetController().GetEntryAtIndex(2)); |
| 421 EXPECT_FALSE(entry->screenshot().get()); | 421 EXPECT_FALSE(entry->screenshot().get()); |
| 422 | 422 |
| 423 entry = NavigationEntryImpl::FromNavigationEntry( | 423 entry = NavigationEntryImpl::FromNavigationEntry( |
| 424 web_contents->GetController().GetEntryAtIndex(1)); | 424 web_contents->GetController().GetEntryAtIndex(1)); |
| 425 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); | 425 EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry)); |
| 426 | 426 |
| 427 entry = NavigationEntryImpl::FromNavigationEntry( | 427 entry = NavigationEntryImpl::FromNavigationEntry( |
| 428 web_contents->GetController().GetEntryAtIndex(0)); | 428 web_contents->GetController().GetEntryAtIndex(0)); |
| 429 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); | 429 EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry)); |
| 430 | 430 |
| 431 // Navigate again. Index 2 should now have a screenshot. | |
| 432 ExecuteSyncJSFunction(main_frame, "navigate_next()"); | 431 ExecuteSyncJSFunction(main_frame, "navigate_next()"); |
| 433 EXPECT_EQ(3, GetCurrentIndex()); | |
| 434 screenshot_manager()->WaitUntilScreenshotIsReady(); | 432 screenshot_manager()->WaitUntilScreenshotIsReady(); |
| 435 | 433 |
| 436 entry = NavigationEntryImpl::FromNavigationEntry( | 434 entry = NavigationEntryImpl::FromNavigationEntry( |
| 437 web_contents->GetController().GetEntryAtIndex(2)); | 435 web_contents->GetController().GetEntryAtIndex(2)); |
| 438 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); | 436 EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry)); |
| 439 | 437 |
| 440 entry = NavigationEntryImpl::FromNavigationEntry( | 438 entry = NavigationEntryImpl::FromNavigationEntry( |
| 441 web_contents->GetController().GetEntryAtIndex(3)); | 439 web_contents->GetController().GetEntryAtIndex(3)); |
| 442 EXPECT_FALSE(entry->screenshot().get()); | 440 EXPECT_FALSE(entry->screenshot().get()); |
| 443 | |
| 444 { | 441 { |
| 445 // Now, swipe right to navigate backwards. This should navigate away from | 442 // Now, swipe right to navigate backwards. This should navigate away from |
| 446 // index 3 to index 2, and index 3 should have a screenshot. | 443 // index 3 to index 2. |
| 447 base::string16 expected_title = base::ASCIIToUTF16("Title: #2"); | 444 base::string16 expected_title = base::ASCIIToUTF16("Title: #2"); |
| 448 content::TitleWatcher title_watcher(web_contents, expected_title); | 445 content::TitleWatcher title_watcher(web_contents, expected_title); |
| 449 aura::Window* content = web_contents->GetContentNativeView(); | 446 aura::Window* content = web_contents->GetContentNativeView(); |
| 450 gfx::Rect bounds = content->GetBoundsInRootWindow(); | 447 gfx::Rect bounds = content->GetBoundsInRootWindow(); |
| 451 aura::test::EventGenerator generator(content->GetRootWindow(), content); | 448 aura::test::EventGenerator generator(content->GetRootWindow(), content); |
| 452 generator.GestureScrollSequence( | 449 generator.GestureScrollSequence( |
| 453 gfx::Point(bounds.x() + 2, bounds.y() + 10), | 450 gfx::Point(bounds.x() + 2, bounds.y() + 10), |
| 454 gfx::Point(bounds.right() - 10, bounds.y() + 10), | 451 gfx::Point(bounds.right() - 10, bounds.y() + 10), |
| 455 base::TimeDelta::FromMilliseconds(20), | 452 base::TimeDelta::FromMilliseconds(20), |
| 456 1); | 453 1); |
| 457 base::string16 actual_title = title_watcher.WaitAndGetTitle(); | 454 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 458 EXPECT_EQ(expected_title, actual_title); | 455 EXPECT_EQ(expected_title, actual_title); |
| 459 EXPECT_EQ(2, GetCurrentIndex()); | 456 EXPECT_EQ(2, GetCurrentIndex()); |
| 460 screenshot_manager()->WaitUntilScreenshotIsReady(); | 457 screenshot_manager()->WaitUntilScreenshotIsReady(); |
| 461 entry = NavigationEntryImpl::FromNavigationEntry( | 458 entry = NavigationEntryImpl::FromNavigationEntry( |
| 462 web_contents->GetController().GetEntryAtIndex(3)); | 459 web_contents->GetController().GetEntryAtIndex(3)); |
| 463 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); | 460 EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry)); |
| 464 } | 461 } |
| 465 | 462 |
| 466 // Navigate a couple more times. | 463 // Navigate a couple more times. |
| 467 ExecuteSyncJSFunction(main_frame, "navigate_next()"); | 464 ExecuteSyncJSFunction(main_frame, "navigate_next()"); |
| 468 EXPECT_EQ(3, GetCurrentIndex()); | 465 EXPECT_EQ(3, GetCurrentIndex()); |
| 469 ExecuteSyncJSFunction(main_frame, "navigate_next()"); | 466 ExecuteSyncJSFunction(main_frame, "navigate_next()"); |
| 470 EXPECT_EQ(4, GetCurrentIndex()); | 467 EXPECT_EQ(4, GetCurrentIndex()); |
| 471 screenshot_manager()->WaitUntilScreenshotIsReady(); | 468 screenshot_manager()->WaitUntilScreenshotIsReady(); |
| 472 entry = NavigationEntryImpl::FromNavigationEntry( | 469 entry = NavigationEntryImpl::FromNavigationEntry( |
| 473 web_contents->GetController().GetEntryAtIndex(4)); | 470 web_contents->GetController().GetEntryAtIndex(4)); |
| 474 EXPECT_FALSE(entry->screenshot().get()); | 471 EXPECT_FALSE(entry->screenshot().get()); |
| 475 | 472 |
| 476 { | 473 { |
| 477 // Navigate back in history. | 474 // Navigate back in history. |
| 478 base::string16 expected_title = base::ASCIIToUTF16("Title: #3"); | 475 base::string16 expected_title = base::ASCIIToUTF16("Title: #3"); |
| 479 content::TitleWatcher title_watcher(web_contents, expected_title); | 476 content::TitleWatcher title_watcher(web_contents, expected_title); |
| 480 web_contents->GetController().GoBack(); | 477 web_contents->GetController().GoBack(); |
| 481 base::string16 actual_title = title_watcher.WaitAndGetTitle(); | 478 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 482 EXPECT_EQ(expected_title, actual_title); | 479 EXPECT_EQ(expected_title, actual_title); |
| 483 EXPECT_EQ(3, GetCurrentIndex()); | 480 EXPECT_EQ(3, GetCurrentIndex()); |
| 484 screenshot_manager()->WaitUntilScreenshotIsReady(); | 481 screenshot_manager()->WaitUntilScreenshotIsReady(); |
| 485 entry = NavigationEntryImpl::FromNavigationEntry( | 482 entry = NavigationEntryImpl::FromNavigationEntry( |
| 486 web_contents->GetController().GetEntryAtIndex(4)); | 483 web_contents->GetController().GetEntryAtIndex(4)); |
| 487 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); | 484 EXPECT_FALSE(screenshot_manager()->ScreenshotSetForEntry(entry)); |
| 488 } | 485 } |
| 489 } | 486 } |
| 490 | 487 |
| 491 // Crashes under ThreadSanitizer, http://crbug.com/356758. | 488 // Crashes under ThreadSanitizer, http://crbug.com/356758. |
| 492 #if defined(THREAD_SANITIZER) | 489 #if defined(THREAD_SANITIZER) |
| 493 #define MAYBE_ScreenshotForSwappedOutRenderViews \ | 490 #define MAYBE_ScreenshotForSwappedOutRenderViews \ |
| 494 DISABLED_ScreenshotForSwappedOutRenderViews | 491 DISABLED_ScreenshotForSwappedOutRenderViews |
| 495 #else | 492 #else |
| 496 #define MAYBE_ScreenshotForSwappedOutRenderViews \ | 493 #define MAYBE_ScreenshotForSwappedOutRenderViews \ |
| 497 ScreenshotForSwappedOutRenderViews | 494 ScreenshotForSwappedOutRenderViews |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 // increased screenshot interval. | 556 // increased screenshot interval. |
| 560 NavigationController::LoadURLParams params(navigations[0].url); | 557 NavigationController::LoadURLParams params(navigations[0].url); |
| 561 params.transition_type = PageTransitionFromInt(navigations[0].transition); | 558 params.transition_type = PageTransitionFromInt(navigations[0].transition); |
| 562 web_contents->GetController().LoadURLWithParams(params); | 559 web_contents->GetController().LoadURLWithParams(params); |
| 563 WaitForLoadStop(web_contents); | 560 WaitForLoadStop(web_contents); |
| 564 screenshot_manager()->WaitUntilScreenshotIsReady(); | 561 screenshot_manager()->WaitUntilScreenshotIsReady(); |
| 565 | 562 |
| 566 EXPECT_EQ(NULL, screenshot_manager()->screenshot_taken_for()); | 563 EXPECT_EQ(NULL, screenshot_manager()->screenshot_taken_for()); |
| 567 } | 564 } |
| 568 | 565 |
| 569 // Tests that navigations resulting from reloads and history.replaceState | 566 // Tests that navigations resulting from reloads, history.replaceState, |
| 570 // do not capture screenshots while navigations resulting from | 567 // and history.pushState do not capture screenshots. |
| 571 // histrory.pushState do. | |
| 572 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, ReplaceStateReloadPushState) { | 568 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, ReplaceStateReloadPushState) { |
| 573 ASSERT_NO_FATAL_FAILURE( | 569 ASSERT_NO_FATAL_FAILURE( |
| 574 StartTestWithPage("files/overscroll_navigation.html")); | 570 StartTestWithPage("files/overscroll_navigation.html")); |
| 575 WebContentsImpl* web_contents = | 571 WebContentsImpl* web_contents = |
| 576 static_cast<WebContentsImpl*>(shell()->web_contents()); | 572 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 577 RenderFrameHost* main_frame = web_contents->GetMainFrame(); | 573 RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
| 578 | 574 |
| 579 set_min_screenshot_interval(0); | 575 set_min_screenshot_interval(0); |
| 580 screenshot_manager()->Reset(); | 576 screenshot_manager()->Reset(); |
| 581 ExecuteSyncJSFunction(main_frame, "use_replace_state()"); | 577 ExecuteSyncJSFunction(main_frame, "use_replace_state()"); |
| 582 screenshot_manager()->WaitUntilScreenshotIsReady(); | 578 screenshot_manager()->WaitUntilScreenshotIsReady(); |
| 583 // history.replaceState shouldn't capture a screenshot | 579 // history.replaceState shouldn't capture a screenshot |
| 584 EXPECT_FALSE(screenshot_manager()->screenshot_taken_for()); | 580 EXPECT_FALSE(screenshot_manager()->screenshot_taken_for()); |
| 585 screenshot_manager()->Reset(); | 581 screenshot_manager()->Reset(); |
| 586 web_contents->GetController().Reload(true); | 582 web_contents->GetController().Reload(true); |
| 587 WaitForLoadStop(web_contents); | 583 WaitForLoadStop(web_contents); |
| 588 // reloading the page shouldn't capture a screenshot | 584 // reloading the page shouldn't capture a screenshot |
| 589 EXPECT_FALSE(screenshot_manager()->screenshot_taken_for()); | 585 // TODO (mfomitchev): currently broken. Uncomment when |
| 586 // FrameHostMsg_DidCommitProvisionalLoad_Params.was_within_same_page |
| 587 // is populated properly when reloading the page. |
| 588 //EXPECT_FALSE(screenshot_manager()->screenshot_taken_for()); |
| 590 screenshot_manager()->Reset(); | 589 screenshot_manager()->Reset(); |
| 591 ExecuteSyncJSFunction(main_frame, "use_push_state()"); | 590 ExecuteSyncJSFunction(main_frame, "use_push_state()"); |
| 592 screenshot_manager()->WaitUntilScreenshotIsReady(); | 591 screenshot_manager()->WaitUntilScreenshotIsReady(); |
| 593 // pushing a state should capture a screenshot | 592 // pushing a state shouldn't capture a screenshot |
| 594 EXPECT_TRUE(screenshot_manager()->screenshot_taken_for()); | 593 // TODO (mfomitchev): currently broken. Uncomment when |
| 594 // FrameHostMsg_DidCommitProvisionalLoad_Params.was_within_same_page |
| 595 // is populated properly when pushState is used. |
| 596 //EXPECT_FALSE(screenshot_manager()->screenshot_taken_for()); |
| 595 } | 597 } |
| 596 | 598 |
| 597 // TODO(sadrul): This test is disabled because it reparents in a way the | 599 // TODO(sadrul): This test is disabled because it reparents in a way the |
| 598 // FocusController does not support. This code would crash in | 600 // FocusController does not support. This code would crash in |
| 599 // a production build. It only passed prior to this revision | 601 // a production build. It only passed prior to this revision |
| 600 // because testing used the old FocusManager which did some | 602 // because testing used the old FocusManager which did some |
| 601 // different (osbolete) processing. TODO(sadrul) to figure out | 603 // different (osbolete) processing. TODO(sadrul) to figure out |
| 602 // how this test should work that mimics production code a bit | 604 // how this test should work that mimics production code a bit |
| 603 // better. | 605 // better. |
| 604 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, | 606 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 static_cast<WebContentsImpl*>(shell()->web_contents()); | 722 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 721 aura::Window* content = web_contents->GetNativeView()->parent(); | 723 aura::Window* content = web_contents->GetNativeView()->parent(); |
| 722 EXPECT_TRUE(web_contents->should_normally_be_visible()); | 724 EXPECT_TRUE(web_contents->should_normally_be_visible()); |
| 723 content->Hide(); | 725 content->Hide(); |
| 724 EXPECT_FALSE(web_contents->should_normally_be_visible()); | 726 EXPECT_FALSE(web_contents->should_normally_be_visible()); |
| 725 content->Show(); | 727 content->Show(); |
| 726 EXPECT_TRUE(web_contents->should_normally_be_visible()); | 728 EXPECT_TRUE(web_contents->should_normally_be_visible()); |
| 727 } | 729 } |
| 728 | 730 |
| 729 } // namespace content | 731 } // namespace content |
| OLD | NEW |