OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/offline_pages/offline_page_model_impl.h" | 5 #include "components/offline_pages/offline_page_model_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/feature_list.h" | 13 #include "base/feature_list.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
| 16 #include "base/metrics/statistics_recorder.h" |
16 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
20 #include "base/test/histogram_tester.h" | 21 #include "base/test/histogram_tester.h" |
21 #include "base/test/scoped_feature_list.h" | 22 #include "base/test/scoped_feature_list.h" |
22 #include "base/test/test_mock_time_task_runner.h" | 23 #include "base/test/test_mock_time_task_runner.h" |
23 #include "base/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
24 #include "base/time/time.h" | 25 #include "base/time/time.h" |
25 #include "components/offline_pages/client_namespace_constants.h" | 26 #include "components/offline_pages/client_namespace_constants.h" |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 EXPECT_EQ(1UL, ids.size()); | 1034 EXPECT_EQ(1UL, ids.size()); |
1034 | 1035 |
1035 std::set<int64_t> id_set; | 1036 std::set<int64_t> id_set; |
1036 for (size_t i = 0; i < ids.size(); i++) { | 1037 for (size_t i = 0; i < ids.size(); i++) { |
1037 id_set.insert(ids[i]); | 1038 id_set.insert(ids[i]); |
1038 } | 1039 } |
1039 | 1040 |
1040 EXPECT_TRUE(id_set.find(offline2) != id_set.end()); | 1041 EXPECT_TRUE(id_set.find(offline2) != id_set.end()); |
1041 } | 1042 } |
1042 | 1043 |
| 1044 TEST_F(OfflinePageModelImplTest, DownloadMetrics) { |
| 1045 EXPECT_FALSE(HasPages(kUserRequestedNamespace)); |
| 1046 SavePage(kTestUrl, kTestUserRequestedClientId); |
| 1047 histograms().ExpectUniqueSample( |
| 1048 "OfflinePages.DownloadSavedPageDuplicateCount", 1, 1); |
| 1049 FastForwardBy(base::TimeDelta::FromMinutes(1)); |
| 1050 histograms().ExpectTotalCount( |
| 1051 "OfflinePages.DownloadSavedPageTimeSinceDuplicateSaved", 0); |
| 1052 SavePage(kTestUrl, kTestUserRequestedClientId); |
| 1053 histograms().ExpectTotalCount("OfflinePages.DownloadSavedPageDuplicateCount", |
| 1054 2); |
| 1055 histograms().ExpectBucketCount("OfflinePages.DownloadSavedPageDuplicateCount", |
| 1056 2, 1); |
| 1057 histograms().ExpectBucketCount("OfflinePages.DownloadSavedPageDuplicateCount", |
| 1058 1, 1); |
| 1059 histograms().ExpectTotalCount( |
| 1060 "OfflinePages.DownloadSavedPageTimeSinceDuplicateSaved", 1); |
| 1061 histograms().ExpectTotalCount( |
| 1062 "OfflinePages.DownloadDeletedPageDuplicateCount", 0); |
| 1063 |
| 1064 // void DeletePage(int64_t offline_id, const DeletePageCallback& callback) { |
| 1065 const std::vector<int64_t> ids = |
| 1066 GetOfflineIdsForClientId(kTestUserRequestedClientId); |
| 1067 ASSERT_EQ(2U, ids.size()); |
| 1068 |
| 1069 DeletePage(ids[0], base::Bind(&OfflinePageModelImplTest::OnDeletePageDone, |
| 1070 AsWeakPtr())); |
| 1071 PumpLoop(); |
| 1072 histograms().ExpectUniqueSample( |
| 1073 "OfflinePages.DownloadDeletedPageDuplicateCount", 2, 1); |
| 1074 DeletePage(ids[1], base::Bind(&OfflinePageModelImplTest::OnDeletePageDone, |
| 1075 AsWeakPtr())); |
| 1076 PumpLoop(); |
| 1077 // No change when we delete the last page. |
| 1078 histograms().ExpectTotalCount( |
| 1079 "OfflinePages.DownloadDeletedPageDuplicateCount", 2); |
| 1080 histograms().ExpectBucketCount( |
| 1081 "OfflinePages.DownloadDeletedPageDuplicateCount", 1, 1); |
| 1082 histograms().ExpectBucketCount( |
| 1083 "OfflinePages.DownloadDeletedPageDuplicateCount", 2, 1); |
| 1084 } |
| 1085 |
1043 TEST_F(OfflinePageModelImplTest, GetBestPage) { | 1086 TEST_F(OfflinePageModelImplTest, GetBestPage) { |
1044 // We will save 3 pages - two for the same URL, and one for a different URL. | 1087 // We will save 3 pages - two for the same URL, and one for a different URL. |
1045 // Correct behavior will pick the most recently saved page for the correct | 1088 // Correct behavior will pick the most recently saved page for the correct |
1046 // URL. | 1089 // URL. |
1047 std::pair<SavePageResult, int64_t> saved_pages[3]; | 1090 std::pair<SavePageResult, int64_t> saved_pages[3]; |
1048 saved_pages[0] = SavePage(kTestUrl, kTestClientId1); | 1091 saved_pages[0] = SavePage(kTestUrl, kTestClientId1); |
1049 saved_pages[1] = SavePage(kTestUrl, kTestClientId1); | 1092 saved_pages[1] = SavePage(kTestUrl, kTestClientId1); |
1050 saved_pages[2] = SavePage(kTestUrl2, kTestClientId2); | 1093 saved_pages[2] = SavePage(kTestUrl2, kTestClientId2); |
1051 | 1094 |
1052 for (const auto& save_result : saved_pages) { | 1095 for (const auto& save_result : saved_pages) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1187 // Check if feature is correctly enabled by command-line flag. | 1230 // Check if feature is correctly enabled by command-line flag. |
1188 scoped_feature_list.reset(new base::test::ScopedFeatureList); | 1231 scoped_feature_list.reset(new base::test::ScopedFeatureList); |
1189 scoped_feature_list->InitFromCommandLine( | 1232 scoped_feature_list->InitFromCommandLine( |
1190 std::string(kOfflineBookmarksFeature.name) + "," + | 1233 std::string(kOfflineBookmarksFeature.name) + "," + |
1191 kOfflinePagesSharingFeature.name, | 1234 kOfflinePagesSharingFeature.name, |
1192 ""); | 1235 ""); |
1193 EXPECT_TRUE(offline_pages::IsOfflinePagesSharingEnabled()); | 1236 EXPECT_TRUE(offline_pages::IsOfflinePagesSharingEnabled()); |
1194 } | 1237 } |
1195 | 1238 |
1196 } // namespace offline_pages | 1239 } // namespace offline_pages |
OLD | NEW |