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

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

Issue 2824623002: Last_n: Delete previously saved snapshot when navigating. (Closed)
Patch Set: Annotated method with @MainThread; comment updates 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 if the tab while the tab is 378 // Checks that last_n will not save a snapshot while the tab is being presented
379 // presented as a custom tab. Download requests should be unaffected though. 379 // 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 // Navigate with the same URL until the page is minimally loaded then hide the 503 // Reload the same URL until the page is minimally loaded. The previous
504 // tab. The previous snapshot should be removed and a new one taken. 504 // snapshot should have been removed.
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(0U, model_removed_count()); 509 EXPECT_EQ(1U, model_removed_count());
510 ASSERT_EQ(1U, GetAllPages().size()); 510 ASSERT_EQ(0U, GetAllPages().size());
511 511
512 // Hide the tab and a new snapshot should be taken.
512 recent_tab_helper()->WasHidden(); 513 recent_tab_helper()->WasHidden();
513 RunUntilIdle(); 514 RunUntilIdle();
514 EXPECT_EQ(2U, page_added_count()); 515 EXPECT_EQ(2U, page_added_count());
515 EXPECT_EQ(1U, model_removed_count()); 516 EXPECT_EQ(1U, model_removed_count());
516 ASSERT_EQ(1U, GetAllPages().size()); 517 ASSERT_EQ(1U, GetAllPages().size());
517 EXPECT_EQ(kTestPageUrl, GetAllPages()[0].url); 518 EXPECT_EQ(kTestPageUrl, GetAllPages()[0].url);
518 EXPECT_NE(first_offline_id, GetAllPages()[0].offline_id); 519 EXPECT_NE(first_offline_id, GetAllPages()[0].offline_id);
519 } 520 }
520 521
521 // Triggers two last_n captures for two different page loads of the same URL 522 // 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
558 NavigateAndCommit(kTestPageUrl); 559 NavigateAndCommit(kTestPageUrl);
559 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 560 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
560 FastForwardSnapshotController(); 561 FastForwardSnapshotController();
561 recent_tab_helper()->WasHidden(); 562 recent_tab_helper()->WasHidden();
562 RunUntilIdle(); 563 RunUntilIdle();
563 EXPECT_EQ(1U, page_added_count()); 564 EXPECT_EQ(1U, page_added_count());
564 EXPECT_EQ(0U, model_removed_count()); 565 EXPECT_EQ(0U, model_removed_count());
565 ASSERT_EQ(1U, GetAllPages().size()); 566 ASSERT_EQ(1U, GetAllPages().size());
566 EXPECT_EQ(kTestPageUrl, GetAllPages()[0].url); 567 EXPECT_EQ(kTestPageUrl, GetAllPages()[0].url);
567 568
568 // Fully load the second URL then hide the tab and check for a single snapshot 569 // Fully load the second URL. The previous snapshot should have been deleted.
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(0U, model_removed_count()); 574 EXPECT_EQ(1U, model_removed_count());
575 ASSERT_EQ(1U, GetAllPages().size()); 575 ASSERT_EQ(0U, GetAllPages().size());
576 576
577 // Then hide the tab and check for a single snapshot of the new page.
577 recent_tab_helper()->WasHidden(); 578 recent_tab_helper()->WasHidden();
578 RunUntilIdle(); 579 RunUntilIdle();
579 EXPECT_EQ(2U, page_added_count()); 580 EXPECT_EQ(2U, page_added_count());
580 EXPECT_EQ(1U, model_removed_count()); 581 EXPECT_EQ(1U, model_removed_count());
581 ASSERT_EQ(1U, GetAllPages().size()); 582 ASSERT_EQ(1U, GetAllPages().size());
582 EXPECT_EQ(kTestPageUrlOther, GetAllPages()[0].url); 583 EXPECT_EQ(kTestPageUrlOther, GetAllPages()[0].url);
583 } 584 }
584 585
585 // Fully loads a page where last_n captures two snapshots. Then triggers two 586 // Fully loads a page where last_n captures two snapshots. Then triggers two
586 // snapshot requests by downloads. Should end up with three offline pages: one 587 // snapshot requests by downloads. Should end up with three offline pages: one
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 EXPECT_EQ(153L, page.offline_id); 725 EXPECT_EQ(153L, page.offline_id);
725 726
726 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 727 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
727 FastForwardSnapshotController(); 728 FastForwardSnapshotController();
728 EXPECT_EQ(2U, page_added_count()); 729 EXPECT_EQ(2U, page_added_count());
729 EXPECT_EQ(1U, model_removed_count()); 730 EXPECT_EQ(1U, model_removed_count());
730 ASSERT_EQ(1U, GetAllPages().size()); 731 ASSERT_EQ(1U, GetAllPages().size());
731 } 732 }
732 733
733 // Simulates a download request to offline the current page made after loading 734 // Simulates a download request to offline the current page made after loading
734 // is completed. Should end up with one offline pages. 735 // is completed. Should end up with one offline page.
735 TEST_F(RecentTabHelperTest, DownloadRequestAfterFullyLoad) { 736 TEST_F(RecentTabHelperTest, DownloadRequestAfterFullyLoad) {
736 NavigateAndCommit(kTestPageUrl); 737 NavigateAndCommit(kTestPageUrl);
737 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 738 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
738 FastForwardSnapshotController(); 739 FastForwardSnapshotController();
739 EXPECT_TRUE(model()->is_loaded()); 740 EXPECT_TRUE(model()->is_loaded());
740 ASSERT_EQ(0U, GetAllPages().size()); 741 ASSERT_EQ(0U, GetAllPages().size());
741 742
742 const ClientId client_id = NewDownloadClientId(); 743 const ClientId client_id = NewDownloadClientId();
743 recent_tab_helper()->ObserveAndDownloadCurrentPage(client_id, 153L); 744 recent_tab_helper()->ObserveAndDownloadCurrentPage(client_id, 153L);
744 RunUntilIdle(); 745 RunUntilIdle();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 // Tests that a page reloaded is tracked as an actual load and properly saved. 891 // Tests that a page reloaded is tracked as an actual load and properly saved.
891 TEST_F(RecentTabHelperTest, ReloadIsTrackedAsNavigationAndSavedOnlyUponLoad) { 892 TEST_F(RecentTabHelperTest, ReloadIsTrackedAsNavigationAndSavedOnlyUponLoad) {
892 // Navigates and load fully then hide the tab so that a snapshot is created. 893 // Navigates and load fully then hide the tab so that a snapshot is created.
893 NavigateAndCommit(kTestPageUrl); 894 NavigateAndCommit(kTestPageUrl);
894 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 895 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
895 FastForwardSnapshotController(); 896 FastForwardSnapshotController();
896 recent_tab_helper()->WasHidden(); 897 recent_tab_helper()->WasHidden();
897 RunUntilIdle(); 898 RunUntilIdle();
898 ASSERT_EQ(1U, GetAllPages().size()); 899 ASSERT_EQ(1U, GetAllPages().size());
899 900
900 // Starts a reload and hides the tab. No new snapshot should be saved. 901 // Starts a reload and hides the tab before it minimally load. The previous
902 // snapshot should be removed.
901 controller().Reload(content::ReloadType::NORMAL, false); 903 controller().Reload(content::ReloadType::NORMAL, false);
902 content::WebContentsTester* web_contents_tester = 904 content::WebContentsTester* web_contents_tester =
903 content::WebContentsTester::For(web_contents()); 905 content::WebContentsTester::For(web_contents());
904 web_contents_tester->CommitPendingNavigation(); 906 web_contents_tester->CommitPendingNavigation();
905 recent_tab_helper()->WasHidden(); 907 recent_tab_helper()->WasHidden();
906 RunUntilIdle(); 908 RunUntilIdle();
907 EXPECT_EQ(1U, page_added_count()); 909 EXPECT_EQ(1U, page_added_count());
908 EXPECT_EQ(0U, model_removed_count()); 910 EXPECT_EQ(1U, model_removed_count());
909 ASSERT_EQ(1U, GetAllPages().size()); 911 ASSERT_EQ(0U, GetAllPages().size());
910 912
911 // Finish loading and hide the tab. A new snapshot should be created. 913 // Finish loading and hide the tab. A new snapshot should be created.
912 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 914 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
913 FastForwardSnapshotController(); 915 FastForwardSnapshotController();
914 recent_tab_helper()->WasHidden(); 916 recent_tab_helper()->WasHidden();
915 RunUntilIdle(); 917 RunUntilIdle();
916 EXPECT_EQ(2U, page_added_count()); 918 EXPECT_EQ(2U, page_added_count());
917 EXPECT_EQ(1U, model_removed_count()); 919 EXPECT_EQ(1U, model_removed_count());
918 ASSERT_EQ(1U, GetAllPages().size()); 920 ASSERT_EQ(1U, GetAllPages().size());
919 } 921 }
(...skipping 19 matching lines...) Expand all
939 // moment a snapshot should be created. 941 // moment a snapshot should be created.
940 recent_tab_helper()->WasShown(); 942 recent_tab_helper()->WasShown();
941 recent_tab_helper()->WasHidden(); 943 recent_tab_helper()->WasHidden();
942 RunUntilIdle(); 944 RunUntilIdle();
943 EXPECT_EQ(1U, page_added_count()); 945 EXPECT_EQ(1U, page_added_count());
944 EXPECT_EQ(0U, model_removed_count()); 946 EXPECT_EQ(0U, model_removed_count());
945 ASSERT_EQ(1U, GetAllPages().size()); 947 ASSERT_EQ(1U, GetAllPages().size());
946 } 948 }
947 949
948 } // namespace offline_pages 950 } // 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