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

Side by Side Diff: components/offline_pages/offline_page_model_unittest.cc

Issue 1976163004: [Offline Pages] Adds Rappor metrics measuring what domains are saved & viewed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no-store
Patch Set: Created 4 years, 7 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
OLDNEW
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.h" 5 #include "components/offline_pages/offline_page_model.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/memory/weak_ptr.h"
16 #include "base/optional.h" 17 #include "base/optional.h"
17 #include "base/run_loop.h" 18 #include "base/run_loop.h"
18 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
19 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
21 #include "base/test/test_mock_time_task_runner.h" 22 #include "base/test/test_mock_time_task_runner.h"
22 #include "base/thread_task_runner_handle.h" 23 #include "base/thread_task_runner_handle.h"
23 #include "base/time/time.h" 24 #include "base/time/time.h"
24 #include "components/offline_pages/client_policy_controller.h" 25 #include "components/offline_pages/client_policy_controller.h"
25 #include "components/offline_pages/offline_page_client_policy.h" 26 #include "components/offline_pages/offline_page_client_policy.h"
26 #include "components/offline_pages/offline_page_feature.h" 27 #include "components/offline_pages/offline_page_feature.h"
27 #include "components/offline_pages/offline_page_item.h" 28 #include "components/offline_pages/offline_page_item.h"
28 #include "components/offline_pages/offline_page_storage_manager.h" 29 #include "components/offline_pages/offline_page_storage_manager.h"
29 #include "components/offline_pages/offline_page_test_archiver.h" 30 #include "components/offline_pages/offline_page_test_archiver.h"
30 #include "components/offline_pages/offline_page_test_store.h" 31 #include "components/offline_pages/offline_page_test_store.h"
31 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
32 #include "url/gurl.h" 33 #include "url/gurl.h"
33 34
34 using SavePageResult = offline_pages::OfflinePageModel::SavePageResult; 35 using SavePageResult = offline_pages::OfflinePageModel::SavePageResult;
35 using DeletePageResult = offline_pages::OfflinePageModel::DeletePageResult; 36 using DeletePageResult = offline_pages::OfflinePageModel::DeletePageResult;
36 using SingleOfflinePageItemResult = 37 using SingleOfflinePageItemResult =
37 offline_pages::OfflinePageModel::SingleOfflinePageItemResult; 38 offline_pages::OfflinePageModel::SingleOfflinePageItemResult;
38 using MultipleOfflinePageItemResult = 39 using MultipleOfflinePageItemResult =
39 offline_pages::OfflinePageModel::MultipleOfflinePageItemResult; 40 offline_pages::OfflinePageModel::MultipleOfflinePageItemResult;
40 using CheckPagesExistOfflineResult = 41 using CheckPagesExistOfflineResult =
41 offline_pages::OfflinePageModel::CheckPagesExistOfflineResult; 42 offline_pages::OfflinePageModel::CheckPagesExistOfflineResult;
42 using MultipleOfflineIdResult = 43 using MultipleOfflineIdResult =
43 offline_pages::OfflinePageModel::MultipleOfflineIdResult; 44 offline_pages::OfflinePageModel::MultipleOfflineIdResult;
44 45
46 namespace rappor {
47 class RapporService;
48 }
49
45 namespace offline_pages { 50 namespace offline_pages {
46 51
47 namespace { 52 namespace {
48 const char kTestClientNamespace[] = "CLIENT_NAMESPACE"; 53 const char kTestClientNamespace[] = "CLIENT_NAMESPACE";
49 const GURL kTestUrl("http://example.com"); 54 const GURL kTestUrl("http://example.com");
50 const GURL kTestUrl2("http://other.page.com"); 55 const GURL kTestUrl2("http://other.page.com");
51 const GURL kTestUrl3("http://test.xyz"); 56 const GURL kTestUrl3("http://test.xyz");
52 const GURL kFileUrl("file:///foo"); 57 const GURL kFileUrl("file:///foo");
53 const ClientId kTestClientId1(kTestClientNamespace, "1234"); 58 const ClientId kTestClientId1(kTestClientNamespace, "1234");
54 const ClientId kTestClientId2(kTestClientNamespace, "5678"); 59 const ClientId kTestClientId2(kTestClientNamespace, "5678");
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 this, url, result, kTestFileSize, base::ThreadTaskRunnerHandle::Get())); 272 this, url, result, kTestFileSize, base::ThreadTaskRunnerHandle::Get()));
268 } 273 }
269 274
270 std::unique_ptr<OfflinePageMetadataStore> OfflinePageModelTest::BuildStore() { 275 std::unique_ptr<OfflinePageMetadataStore> OfflinePageModelTest::BuildStore() {
271 return std::unique_ptr<OfflinePageMetadataStore>( 276 return std::unique_ptr<OfflinePageMetadataStore>(
272 new OfflinePageTestStore(base::ThreadTaskRunnerHandle::Get())); 277 new OfflinePageTestStore(base::ThreadTaskRunnerHandle::Get()));
273 } 278 }
274 279
275 std::unique_ptr<OfflinePageModel> OfflinePageModelTest::BuildModel( 280 std::unique_ptr<OfflinePageModel> OfflinePageModelTest::BuildModel(
276 std::unique_ptr<OfflinePageMetadataStore> store) { 281 std::unique_ptr<OfflinePageMetadataStore> store) {
277 return std::unique_ptr<OfflinePageModel>(new OfflinePageModel( 282 return std::unique_ptr<OfflinePageModel>(
278 std::move(store), temp_dir_.path(), base::ThreadTaskRunnerHandle::Get())); 283 new OfflinePageModel(std::move(store), temp_dir_.path(),
284 base::WeakPtr<rappor::RapporService>(),
285 base::ThreadTaskRunnerHandle::Get()));
279 } 286 }
280 287
281 void OfflinePageModelTest::ResetModel() { 288 void OfflinePageModelTest::ResetModel() {
282 model_->RemoveObserver(this); 289 model_->RemoveObserver(this);
283 OfflinePageTestStore* old_store = GetStore(); 290 OfflinePageTestStore* old_store = GetStore();
284 std::unique_ptr<OfflinePageMetadataStore> new_store( 291 std::unique_ptr<OfflinePageMetadataStore> new_store(
285 new OfflinePageTestStore(*old_store)); 292 new OfflinePageTestStore(*old_store));
286 model_ = BuildModel(std::move(new_store)); 293 model_ = BuildModel(std::move(new_store));
287 model_->AddObserver(this); 294 model_->AddObserver(this);
288 PumpLoop(); 295 PumpLoop();
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList); 1043 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList);
1037 feature_list2->InitializeFromCommandLine( 1044 feature_list2->InitializeFromCommandLine(
1038 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," + 1045 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," +
1039 offline_pages::kOfflinePagesBackgroundLoadingFeature.name, 1046 offline_pages::kOfflinePagesBackgroundLoadingFeature.name,
1040 ""); 1047 "");
1041 base::FeatureList::SetInstance(std::move(feature_list2)); 1048 base::FeatureList::SetInstance(std::move(feature_list2));
1042 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); 1049 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled());
1043 } 1050 }
1044 1051
1045 } // namespace offline_pages 1052 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698