| OLD | NEW |
| 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 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 RunUntilIdle(); | 842 RunUntilIdle(); |
| 843 EXPECT_EQ(2U, page_added_count()); | 843 EXPECT_EQ(2U, page_added_count()); |
| 844 EXPECT_EQ(0U, model_removed_count()); | 844 EXPECT_EQ(0U, model_removed_count()); |
| 845 ASSERT_EQ(2U, GetAllPages().size()); | 845 ASSERT_EQ(2U, GetAllPages().size()); |
| 846 const OfflinePageItem* second_page = FindPageForOfflineId(offline_id_3); | 846 const OfflinePageItem* second_page = FindPageForOfflineId(offline_id_3); |
| 847 ASSERT_TRUE(second_page); | 847 ASSERT_TRUE(second_page); |
| 848 EXPECT_EQ(client_id_3, second_page->client_id); | 848 EXPECT_EQ(client_id_3, second_page->client_id); |
| 849 EXPECT_EQ(offline_id_3, second_page->offline_id); | 849 EXPECT_EQ(offline_id_3, second_page->offline_id); |
| 850 } | 850 } |
| 851 | 851 |
| 852 // Simulates a same page navigation and checks we snapshot correctly with last_n | 852 // Simulates a same document navigation and checks we snapshot correctly with |
| 853 // and downloads. | 853 // last_n and downloads. |
| 854 TEST_F(RecentTabHelperTest, SaveSamePageNavigationSnapshots) { | 854 TEST_F(RecentTabHelperTest, SaveSameDocumentNavigationSnapshots) { |
| 855 // Navigates and load fully then hide the tab so that a snapshot is created. | 855 // Navigates and load fully then hide the tab so that a snapshot is created. |
| 856 NavigateAndCommit(kTestPageUrl); | 856 NavigateAndCommit(kTestPageUrl); |
| 857 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); | 857 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); |
| 858 FastForwardSnapshotController(); | 858 FastForwardSnapshotController(); |
| 859 recent_tab_helper()->WasHidden(); | 859 recent_tab_helper()->WasHidden(); |
| 860 RunUntilIdle(); | 860 RunUntilIdle(); |
| 861 EXPECT_EQ(1U, page_added_count()); | 861 EXPECT_EQ(1U, page_added_count()); |
| 862 EXPECT_EQ(0U, model_removed_count()); | 862 EXPECT_EQ(0U, model_removed_count()); |
| 863 ASSERT_EQ(1U, GetAllPages().size()); | 863 ASSERT_EQ(1U, GetAllPages().size()); |
| 864 | 864 |
| 865 // Now navigates same page and check the results of hiding the tab again. | 865 // Now navigates same page and check the results of hiding the tab again. |
| 866 // Another snapshot should be created to the updated URL. | 866 // Another snapshot should be created to the updated URL. |
| 867 const GURL kTestPageUrlWithSegment(kTestPageUrl.spec() + "#aaa"); | 867 const GURL kTestPageUrlWithFragment(kTestPageUrl.spec() + "#aaa"); |
| 868 NavigateAndCommit(kTestPageUrlWithSegment); | 868 NavigateAndCommit(kTestPageUrlWithFragment); |
| 869 recent_tab_helper()->WasHidden(); | 869 recent_tab_helper()->WasHidden(); |
| 870 RunUntilIdle(); | 870 RunUntilIdle(); |
| 871 EXPECT_EQ(2U, page_added_count()); | 871 EXPECT_EQ(2U, page_added_count()); |
| 872 EXPECT_EQ(1U, model_removed_count()); | 872 EXPECT_EQ(1U, model_removed_count()); |
| 873 ASSERT_EQ(1U, GetAllPages().size()); | 873 ASSERT_EQ(1U, GetAllPages().size()); |
| 874 EXPECT_EQ(kTestPageUrlWithSegment, GetAllPages()[0].url); | 874 EXPECT_EQ(kTestPageUrlWithFragment, GetAllPages()[0].url); |
| 875 | 875 |
| 876 // Now create a download request and check the snapshot is properly created. | 876 // Now create a download request and check the snapshot is properly created. |
| 877 const ClientId client_id = NewDownloadClientId(); | 877 const ClientId client_id = NewDownloadClientId(); |
| 878 const int64_t offline_id = 153L; | 878 const int64_t offline_id = 153L; |
| 879 recent_tab_helper()->ObserveAndDownloadCurrentPage(client_id, offline_id); | 879 recent_tab_helper()->ObserveAndDownloadCurrentPage(client_id, offline_id); |
| 880 RunUntilIdle(); | 880 RunUntilIdle(); |
| 881 EXPECT_EQ(3U, page_added_count()); | 881 EXPECT_EQ(3U, page_added_count()); |
| 882 EXPECT_EQ(1U, model_removed_count()); | 882 EXPECT_EQ(1U, model_removed_count()); |
| 883 ASSERT_EQ(2U, GetAllPages().size()); | 883 ASSERT_EQ(2U, GetAllPages().size()); |
| 884 const OfflinePageItem* downloads_page = FindPageForOfflineId(offline_id); | 884 const OfflinePageItem* downloads_page = FindPageForOfflineId(offline_id); |
| 885 EXPECT_EQ(kTestPageUrlWithSegment, downloads_page->url); | 885 EXPECT_EQ(kTestPageUrlWithFragment, downloads_page->url); |
| 886 EXPECT_EQ(client_id, downloads_page->client_id); | 886 EXPECT_EQ(client_id, downloads_page->client_id); |
| 887 EXPECT_EQ(offline_id, downloads_page->offline_id); | 887 EXPECT_EQ(offline_id, downloads_page->offline_id); |
| 888 } | 888 } |
| 889 | 889 |
| 890 // 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. |
| 891 TEST_F(RecentTabHelperTest, ReloadIsTrackedAsNavigationAndSavedOnlyUponLoad) { | 891 TEST_F(RecentTabHelperTest, ReloadIsTrackedAsNavigationAndSavedOnlyUponLoad) { |
| 892 // 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. |
| 893 NavigateAndCommit(kTestPageUrl); | 893 NavigateAndCommit(kTestPageUrl); |
| 894 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); | 894 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); |
| 895 FastForwardSnapshotController(); | 895 FastForwardSnapshotController(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 // moment a snapshot should be created. | 939 // moment a snapshot should be created. |
| 940 recent_tab_helper()->WasShown(); | 940 recent_tab_helper()->WasShown(); |
| 941 recent_tab_helper()->WasHidden(); | 941 recent_tab_helper()->WasHidden(); |
| 942 RunUntilIdle(); | 942 RunUntilIdle(); |
| 943 EXPECT_EQ(1U, page_added_count()); | 943 EXPECT_EQ(1U, page_added_count()); |
| 944 EXPECT_EQ(0U, model_removed_count()); | 944 EXPECT_EQ(0U, model_removed_count()); |
| 945 ASSERT_EQ(1U, GetAllPages().size()); | 945 ASSERT_EQ(1U, GetAllPages().size()); |
| 946 } | 946 } |
| 947 | 947 |
| 948 } // namespace offline_pages | 948 } // namespace offline_pages |
| OLD | NEW |