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

Side by Side Diff: chrome/browser/android/offline_pages/recent_tab_helper_unittest.cc

Issue 2825973002: Revert of Last_n: Delete previously saved snapshot when navigating. (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « chrome/browser/android/offline_pages/recent_tab_helper.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/android/offline_pages/recent_tab_helper.h" 5 #include "chrome/browser/android/offline_pages/recent_tab_helper.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 ASSERT_EQ(0U, GetAllPages().size()); 368 ASSERT_EQ(0U, GetAllPages().size());
369 369
370 // But the following download request should work normally 370 // But the following download request should work normally
371 recent_tab_helper()->ObserveAndDownloadCurrentPage(NewDownloadClientId(), 371 recent_tab_helper()->ObserveAndDownloadCurrentPage(NewDownloadClientId(),
372 123L); 372 123L);
373 RunUntilIdle(); 373 RunUntilIdle();
374 EXPECT_EQ(1U, page_added_count()); 374 EXPECT_EQ(1U, page_added_count());
375 ASSERT_EQ(1U, GetAllPages().size()); 375 ASSERT_EQ(1U, GetAllPages().size());
376 } 376 }
377 377
378 // Checks that last_n will not save a snapshot while the tab is being presented 378 // Checks that last_n will not save a snapshot if the tab while the tab is
379 // as a custom tab. Download requests should be unaffected though. 379 // presented as a custom tab. Download requests should be unaffected though.
380 TEST_F(RecentTabHelperTest, LastNWontSaveCustomTab) { 380 TEST_F(RecentTabHelperTest, LastNWontSaveCustomTab) {
381 // Simulates the tab running as a custom tab. 381 // Simulates the tab running as a custom tab.
382 default_test_delegate()->set_is_custom_tab(true); 382 default_test_delegate()->set_is_custom_tab(true);
383 383
384 // Navigate and finish loading then hide the tab. Nothing should be saved. 384 // Navigate and finish loading then hide the tab. Nothing should be saved.
385 NavigateAndCommit(kTestPageUrl); 385 NavigateAndCommit(kTestPageUrl);
386 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 386 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
387 FastForwardSnapshotController(); 387 FastForwardSnapshotController();
388 recent_tab_helper()->WasHidden(); 388 recent_tab_helper()->WasHidden();
389 RunUntilIdle(); 389 RunUntilIdle();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 493 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
494 FastForwardSnapshotController(); 494 FastForwardSnapshotController();
495 recent_tab_helper()->WasHidden(); 495 recent_tab_helper()->WasHidden();
496 RunUntilIdle(); 496 RunUntilIdle();
497 EXPECT_EQ(1U, page_added_count()); 497 EXPECT_EQ(1U, page_added_count());
498 EXPECT_EQ(0U, model_removed_count()); 498 EXPECT_EQ(0U, model_removed_count());
499 ASSERT_EQ(1U, GetAllPages().size()); 499 ASSERT_EQ(1U, GetAllPages().size());
500 EXPECT_EQ(kTestPageUrl, GetAllPages()[0].url); 500 EXPECT_EQ(kTestPageUrl, GetAllPages()[0].url);
501 int64_t first_offline_id = GetAllPages()[0].offline_id; 501 int64_t first_offline_id = GetAllPages()[0].offline_id;
502 502
503 // Reload the same URL until the page is minimally loaded. The previous 503 // Navigate with the same URL until the page is minimally loaded then hide the
504 // snapshot should have been removed. 504 // tab. The previous snapshot should be removed and a new one taken.
505 NavigateAndCommitTyped(kTestPageUrl); 505 NavigateAndCommitTyped(kTestPageUrl);
506 recent_tab_helper()->DocumentAvailableInMainFrame(); 506 recent_tab_helper()->DocumentAvailableInMainFrame();
507 FastForwardSnapshotController(); 507 FastForwardSnapshotController();
508 EXPECT_EQ(1U, page_added_count()); 508 EXPECT_EQ(1U, page_added_count());
509 EXPECT_EQ(1U, model_removed_count()); 509 EXPECT_EQ(0U, model_removed_count());
510 ASSERT_EQ(0U, GetAllPages().size()); 510 ASSERT_EQ(1U, GetAllPages().size());
511 511
512 // Hide the tab and a new snapshot should be taken.
513 recent_tab_helper()->WasHidden(); 512 recent_tab_helper()->WasHidden();
514 RunUntilIdle(); 513 RunUntilIdle();
515 EXPECT_EQ(2U, page_added_count()); 514 EXPECT_EQ(2U, page_added_count());
516 EXPECT_EQ(1U, model_removed_count()); 515 EXPECT_EQ(1U, model_removed_count());
517 ASSERT_EQ(1U, GetAllPages().size()); 516 ASSERT_EQ(1U, GetAllPages().size());
518 EXPECT_EQ(kTestPageUrl, GetAllPages()[0].url); 517 EXPECT_EQ(kTestPageUrl, GetAllPages()[0].url);
519 EXPECT_NE(first_offline_id, GetAllPages()[0].offline_id); 518 EXPECT_NE(first_offline_id, GetAllPages()[0].offline_id);
520 } 519 }
521 520
522 // Triggers two last_n captures for two different page loads of the same URL 521 // Triggers two last_n captures for two different page loads of the same URL
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 NavigateAndCommit(kTestPageUrl); 558 NavigateAndCommit(kTestPageUrl);
560 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 559 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
561 FastForwardSnapshotController(); 560 FastForwardSnapshotController();
562 recent_tab_helper()->WasHidden(); 561 recent_tab_helper()->WasHidden();
563 RunUntilIdle(); 562 RunUntilIdle();
564 EXPECT_EQ(1U, page_added_count()); 563 EXPECT_EQ(1U, page_added_count());
565 EXPECT_EQ(0U, model_removed_count()); 564 EXPECT_EQ(0U, model_removed_count());
566 ASSERT_EQ(1U, GetAllPages().size()); 565 ASSERT_EQ(1U, GetAllPages().size());
567 EXPECT_EQ(kTestPageUrl, GetAllPages()[0].url); 566 EXPECT_EQ(kTestPageUrl, GetAllPages()[0].url);
568 567
569 // Fully load the second URL. The previous snapshot should have been deleted. 568 // Fully load the second URL then hide the tab and check for a single snapshot
569 // of the new page.
570 NavigateAndCommitTyped(kTestPageUrlOther); 570 NavigateAndCommitTyped(kTestPageUrlOther);
571 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 571 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
572 FastForwardSnapshotController(); 572 FastForwardSnapshotController();
573 EXPECT_EQ(1U, page_added_count()); 573 EXPECT_EQ(1U, page_added_count());
574 EXPECT_EQ(1U, model_removed_count()); 574 EXPECT_EQ(0U, model_removed_count());
575 ASSERT_EQ(0U, GetAllPages().size()); 575 ASSERT_EQ(1U, GetAllPages().size());
576 576
577 // Then hide the tab and check for a single snapshot of the new page.
578 recent_tab_helper()->WasHidden(); 577 recent_tab_helper()->WasHidden();
579 RunUntilIdle(); 578 RunUntilIdle();
580 EXPECT_EQ(2U, page_added_count()); 579 EXPECT_EQ(2U, page_added_count());
581 EXPECT_EQ(1U, model_removed_count()); 580 EXPECT_EQ(1U, model_removed_count());
582 ASSERT_EQ(1U, GetAllPages().size()); 581 ASSERT_EQ(1U, GetAllPages().size());
583 EXPECT_EQ(kTestPageUrlOther, GetAllPages()[0].url); 582 EXPECT_EQ(kTestPageUrlOther, GetAllPages()[0].url);
584 } 583 }
585 584
586 // Fully loads a page where last_n captures two snapshots. Then triggers two 585 // Fully loads a page where last_n captures two snapshots. Then triggers two
587 // snapshot requests by downloads. Should end up with three offline pages: one 586 // snapshot requests by downloads. Should end up with three offline pages: one
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 EXPECT_EQ(153L, page.offline_id); 724 EXPECT_EQ(153L, page.offline_id);
726 725
727 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 726 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
728 FastForwardSnapshotController(); 727 FastForwardSnapshotController();
729 EXPECT_EQ(2U, page_added_count()); 728 EXPECT_EQ(2U, page_added_count());
730 EXPECT_EQ(1U, model_removed_count()); 729 EXPECT_EQ(1U, model_removed_count());
731 ASSERT_EQ(1U, GetAllPages().size()); 730 ASSERT_EQ(1U, GetAllPages().size());
732 } 731 }
733 732
734 // Simulates a download request to offline the current page made after loading 733 // Simulates a download request to offline the current page made after loading
735 // is completed. Should end up with one offline page. 734 // is completed. Should end up with one offline pages.
736 TEST_F(RecentTabHelperTest, DownloadRequestAfterFullyLoad) { 735 TEST_F(RecentTabHelperTest, DownloadRequestAfterFullyLoad) {
737 NavigateAndCommit(kTestPageUrl); 736 NavigateAndCommit(kTestPageUrl);
738 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 737 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
739 FastForwardSnapshotController(); 738 FastForwardSnapshotController();
740 EXPECT_TRUE(model()->is_loaded()); 739 EXPECT_TRUE(model()->is_loaded());
741 ASSERT_EQ(0U, GetAllPages().size()); 740 ASSERT_EQ(0U, GetAllPages().size());
742 741
743 const ClientId client_id = NewDownloadClientId(); 742 const ClientId client_id = NewDownloadClientId();
744 recent_tab_helper()->ObserveAndDownloadCurrentPage(client_id, 153L); 743 recent_tab_helper()->ObserveAndDownloadCurrentPage(client_id, 153L);
745 RunUntilIdle(); 744 RunUntilIdle();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 // Tests that a page reloaded is tracked as an actual load and properly saved. 890 // Tests that a page reloaded is tracked as an actual load and properly saved.
892 TEST_F(RecentTabHelperTest, ReloadIsTrackedAsNavigationAndSavedOnlyUponLoad) { 891 TEST_F(RecentTabHelperTest, ReloadIsTrackedAsNavigationAndSavedOnlyUponLoad) {
893 // Navigates and load fully then hide the tab so that a snapshot is created. 892 // Navigates and load fully then hide the tab so that a snapshot is created.
894 NavigateAndCommit(kTestPageUrl); 893 NavigateAndCommit(kTestPageUrl);
895 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 894 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
896 FastForwardSnapshotController(); 895 FastForwardSnapshotController();
897 recent_tab_helper()->WasHidden(); 896 recent_tab_helper()->WasHidden();
898 RunUntilIdle(); 897 RunUntilIdle();
899 ASSERT_EQ(1U, GetAllPages().size()); 898 ASSERT_EQ(1U, GetAllPages().size());
900 899
901 // Starts a reload and hides the tab before it minimally load. The previous 900 // Starts a reload and hides the tab. No new snapshot should be saved.
902 // snapshot should be removed.
903 controller().Reload(content::ReloadType::NORMAL, false); 901 controller().Reload(content::ReloadType::NORMAL, false);
904 content::WebContentsTester* web_contents_tester = 902 content::WebContentsTester* web_contents_tester =
905 content::WebContentsTester::For(web_contents()); 903 content::WebContentsTester::For(web_contents());
906 web_contents_tester->CommitPendingNavigation(); 904 web_contents_tester->CommitPendingNavigation();
907 recent_tab_helper()->WasHidden(); 905 recent_tab_helper()->WasHidden();
908 RunUntilIdle(); 906 RunUntilIdle();
909 EXPECT_EQ(1U, page_added_count()); 907 EXPECT_EQ(1U, page_added_count());
910 EXPECT_EQ(1U, model_removed_count()); 908 EXPECT_EQ(0U, model_removed_count());
911 ASSERT_EQ(0U, GetAllPages().size()); 909 ASSERT_EQ(1U, GetAllPages().size());
912 910
913 // Finish loading and hide the tab. A new snapshot should be created. 911 // Finish loading and hide the tab. A new snapshot should be created.
914 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 912 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
915 FastForwardSnapshotController(); 913 FastForwardSnapshotController();
916 recent_tab_helper()->WasHidden(); 914 recent_tab_helper()->WasHidden();
917 RunUntilIdle(); 915 RunUntilIdle();
918 EXPECT_EQ(2U, page_added_count()); 916 EXPECT_EQ(2U, page_added_count());
919 EXPECT_EQ(1U, model_removed_count()); 917 EXPECT_EQ(1U, model_removed_count());
920 ASSERT_EQ(1U, GetAllPages().size()); 918 ASSERT_EQ(1U, GetAllPages().size());
921 } 919 }
(...skipping 19 matching lines...) Expand all
941 // moment a snapshot should be created. 939 // moment a snapshot should be created.
942 recent_tab_helper()->WasShown(); 940 recent_tab_helper()->WasShown();
943 recent_tab_helper()->WasHidden(); 941 recent_tab_helper()->WasHidden();
944 RunUntilIdle(); 942 RunUntilIdle();
945 EXPECT_EQ(1U, page_added_count()); 943 EXPECT_EQ(1U, page_added_count());
946 EXPECT_EQ(0U, model_removed_count()); 944 EXPECT_EQ(0U, model_removed_count());
947 ASSERT_EQ(1U, GetAllPages().size()); 945 ASSERT_EQ(1U, GetAllPages().size());
948 } 946 }
949 947
950 } // namespace offline_pages 948 } // namespace offline_pages
OLDNEW
« no previous file with comments | « chrome/browser/android/offline_pages/recent_tab_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698