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

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

Issue 2698713002: Last_n: create snapshots from user triggers even if similar quality ones exist. (Closed)
Patch Set: Rebase. Created 3 years, 10 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 "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 EXPECT_EQ(download_client_id, downloads_page->client_id); 737 EXPECT_EQ(download_client_id, downloads_page->client_id);
738 738
739 const OfflinePageItem& last_n_page = 739 const OfflinePageItem& last_n_page =
740 GetAllPages()[0].offline_id != download_offline_id ? GetAllPages()[0] 740 GetAllPages()[0].offline_id != download_offline_id ? GetAllPages()[0]
741 : GetAllPages()[1]; 741 : GetAllPages()[1];
742 EXPECT_EQ(kTestPageUrl, last_n_page.url); 742 EXPECT_EQ(kTestPageUrl, last_n_page.url);
743 EXPECT_EQ(kLastNNamespace, last_n_page.client_id.name_space); 743 EXPECT_EQ(kLastNNamespace, last_n_page.client_id.name_space);
744 } 744 }
745 745
746 // Simulates multiple tab hidden events -- triggers for last_n snapshots -- 746 // Simulates multiple tab hidden events -- triggers for last_n snapshots --
747 // happening at the same loading stages. The duplicate events should not cause 747 // happening at the same loading stages. The duplicate events should create new
748 // new snapshots to be saved. 748 // snapshots (so that dynamic pages are properly persisted; navigation/loading
749 TEST_F(RecentTabHelperTest, DuplicateTabHiddenEventsShouldNotTriggerSnapshots) { 749 // signals are poor signals for those).
750 TEST_F(RecentTabHelperTest, DuplicateTabHiddenEventsShouldTriggerNewSnapshots) {
750 NavigateAndCommit(kTestPageUrl); 751 NavigateAndCommit(kTestPageUrl);
751 recent_tab_helper()->DocumentAvailableInMainFrame(); 752 recent_tab_helper()->DocumentAvailableInMainFrame();
752 FastForwardSnapshotController(); 753 FastForwardSnapshotController();
753 recent_tab_helper()->WasHidden(); 754 recent_tab_helper()->WasHidden();
754 RunUntilIdle(); 755 RunUntilIdle();
755 EXPECT_EQ(1U, page_added_count()); 756 EXPECT_EQ(1U, page_added_count());
756 EXPECT_EQ(0U, model_removed_count()); 757 EXPECT_EQ(0U, model_removed_count());
757 ASSERT_EQ(1U, GetAllPages().size()); 758 ASSERT_EQ(1U, GetAllPages().size());
758 759
759 recent_tab_helper()->WasHidden(); 760 recent_tab_helper()->WasHidden();
760 RunUntilIdle(); 761 RunUntilIdle();
761 EXPECT_EQ(1U, page_added_count()); 762 EXPECT_EQ(2U, page_added_count());
762 EXPECT_EQ(0U, model_removed_count()); 763 EXPECT_EQ(1U, model_removed_count());
763 ASSERT_EQ(1U, GetAllPages().size()); 764 ASSERT_EQ(1U, GetAllPages().size());
764 765
765 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 766 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
766 FastForwardSnapshotController(); 767 FastForwardSnapshotController();
767 recent_tab_helper()->WasHidden(); 768 recent_tab_helper()->WasHidden();
768 RunUntilIdle(); 769 RunUntilIdle();
769 EXPECT_EQ(2U, page_added_count()); 770 EXPECT_EQ(3U, page_added_count());
770 EXPECT_EQ(1U, model_removed_count()); 771 EXPECT_EQ(2U, model_removed_count());
771 ASSERT_EQ(1U, GetAllPages().size()); 772 ASSERT_EQ(1U, GetAllPages().size());
772 773
773 recent_tab_helper()->WasHidden(); 774 recent_tab_helper()->WasHidden();
774 RunUntilIdle(); 775 RunUntilIdle();
775 EXPECT_EQ(2U, page_added_count()); 776 EXPECT_EQ(4U, page_added_count());
776 EXPECT_EQ(1U, model_removed_count()); 777 EXPECT_EQ(3U, model_removed_count());
777 ASSERT_EQ(1U, GetAllPages().size()); 778 ASSERT_EQ(1U, GetAllPages().size());
778 } 779 }
779 780
780 // Simulates multiple download requests and verifies that overlapping requests 781 // Simulates multiple download requests and verifies that overlapping requests
781 // are ignored. 782 // are ignored.
782 TEST_F(RecentTabHelperTest, OverlappingDownloadRequestsAreIgnored) { 783 TEST_F(RecentTabHelperTest, OverlappingDownloadRequestsAreIgnored) {
783 // Navigates and commits then make two download snapshot requests. 784 // Navigates and commits then make two download snapshot requests.
784 NavigateAndCommit(kTestPageUrl); 785 NavigateAndCommit(kTestPageUrl);
785 const ClientId client_id_1 = NewDownloadClientId(); 786 const ClientId client_id_1 = NewDownloadClientId();
786 const int64_t offline_id_1 = 153L; 787 const int64_t offline_id_1 = 153L;
(...skipping 22 matching lines...) Expand all
809 RunUntilIdle(); 810 RunUntilIdle();
810 EXPECT_EQ(2U, page_added_count()); 811 EXPECT_EQ(2U, page_added_count());
811 EXPECT_EQ(0U, model_removed_count()); 812 EXPECT_EQ(0U, model_removed_count());
812 ASSERT_EQ(2U, GetAllPages().size()); 813 ASSERT_EQ(2U, GetAllPages().size());
813 const OfflinePageItem* second_page = FindPageForOfflineId(offline_id_3); 814 const OfflinePageItem* second_page = FindPageForOfflineId(offline_id_3);
814 ASSERT_TRUE(second_page); 815 ASSERT_TRUE(second_page);
815 EXPECT_EQ(client_id_3, second_page->client_id); 816 EXPECT_EQ(client_id_3, second_page->client_id);
816 EXPECT_EQ(offline_id_3, second_page->offline_id); 817 EXPECT_EQ(offline_id_3, second_page->offline_id);
817 } 818 }
818 819
820 // Simulates a same page navigation and checks we snapshot correctly with last_n
821 // and downloads.
822 TEST_F(RecentTabHelperTest, SaveSamePageNavigationSnapshots) {
823 // Navigates and load fully then hide the tab so that a snapshot is created.
824 NavigateAndCommit(kTestPageUrl);
825 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
826 FastForwardSnapshotController();
827 recent_tab_helper()->WasHidden();
828 RunUntilIdle();
829 EXPECT_EQ(1U, page_added_count());
830 EXPECT_EQ(0U, model_removed_count());
831 ASSERT_EQ(1U, GetAllPages().size());
832
833 // Now navigates same page and check the results of hiding the tab again.
834 // Another snapshot should be created to the updated URL.
835 const GURL kTestPageUrlWithSegment(kTestPageUrl.spec() + "#aaa");
836 NavigateAndCommit(kTestPageUrlWithSegment);
837 recent_tab_helper()->WasHidden();
838 RunUntilIdle();
839 EXPECT_EQ(2U, page_added_count());
840 EXPECT_EQ(1U, model_removed_count());
841 ASSERT_EQ(1U, GetAllPages().size());
842 EXPECT_EQ(kTestPageUrlWithSegment, GetAllPages()[0].url);
843
844 // Now create a download request and check the snapshot is properly created.
845 const ClientId client_id = NewDownloadClientId();
846 const int64_t offline_id = 153L;
847 recent_tab_helper()->ObserveAndDownloadCurrentPage(client_id, offline_id);
848 RunUntilIdle();
849 EXPECT_EQ(3U, page_added_count());
850 EXPECT_EQ(1U, model_removed_count());
851 ASSERT_EQ(2U, GetAllPages().size());
852 const OfflinePageItem* downloads_page = FindPageForOfflineId(offline_id);
853 EXPECT_EQ(kTestPageUrlWithSegment, downloads_page->url);
854 EXPECT_EQ(client_id, downloads_page->client_id);
855 EXPECT_EQ(offline_id, downloads_page->offline_id);
856 }
857
819 } // namespace offline_pages 858 } // 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