Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: content/browser/web_contents/web_contents_view_aura_browsertest.cc

Issue 417343003: Don't capture screenshots for in-page navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Whitepace Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 and history.replaceState,
570 // do not capture screenshots while navigations resulting from 567 // and histrory.pushState do not capture screenshots.
Charlie Reis 2014/07/25 22:07:40 history
mfomitchev 2014/07/25 22:29:15 Done.
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 EXPECT_FALSE(screenshot_manager()->screenshot_taken_for());
590 screenshot_manager()->Reset(); 586 screenshot_manager()->Reset();
591 ExecuteSyncJSFunction(main_frame, "use_push_state()"); 587 ExecuteSyncJSFunction(main_frame, "use_push_state()");
592 screenshot_manager()->WaitUntilScreenshotIsReady(); 588 screenshot_manager()->WaitUntilScreenshotIsReady();
593 // pushing a state should capture a screenshot 589 // pushing a state shouldn't capture a screenshot
594 EXPECT_TRUE(screenshot_manager()->screenshot_taken_for()); 590 EXPECT_FALSE(screenshot_manager()->screenshot_taken_for());
Charlie Reis 2014/07/25 22:07:40 How did this pass? pushState changes the URL path
mfomitchev 2014/07/25 22:29:15 responded above
595 } 591 }
596 592
597 // TODO(sadrul): This test is disabled because it reparents in a way the 593 // TODO(sadrul): This test is disabled because it reparents in a way the
598 // FocusController does not support. This code would crash in 594 // FocusController does not support. This code would crash in
599 // a production build. It only passed prior to this revision 595 // a production build. It only passed prior to this revision
600 // because testing used the old FocusManager which did some 596 // because testing used the old FocusManager which did some
601 // different (osbolete) processing. TODO(sadrul) to figure out 597 // different (osbolete) processing. TODO(sadrul) to figure out
602 // how this test should work that mimics production code a bit 598 // how this test should work that mimics production code a bit
603 // better. 599 // better.
604 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, 600 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 static_cast<WebContentsImpl*>(shell()->web_contents()); 716 static_cast<WebContentsImpl*>(shell()->web_contents());
721 aura::Window* content = web_contents->GetNativeView()->parent(); 717 aura::Window* content = web_contents->GetNativeView()->parent();
722 EXPECT_TRUE(web_contents->should_normally_be_visible()); 718 EXPECT_TRUE(web_contents->should_normally_be_visible());
723 content->Hide(); 719 content->Hide();
724 EXPECT_FALSE(web_contents->should_normally_be_visible()); 720 EXPECT_FALSE(web_contents->should_normally_be_visible());
725 content->Show(); 721 content->Show();
726 EXPECT_TRUE(web_contents->should_normally_be_visible()); 722 EXPECT_TRUE(web_contents->should_normally_be_visible());
727 } 723 }
728 724
729 } // namespace content 725 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698