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

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

Issue 1928393003: Using separate directories based on LifetimeType. Base URL: https://chromium.googlesource.com/chromium/src.git@master
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/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/test/test_mock_time_task_runner.h" 20 #include "base/test/test_mock_time_task_runner.h"
21 #include "base/thread_task_runner_handle.h" 21 #include "base/thread_task_runner_handle.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "components/offline_pages/offline_page_client_policy.h"
23 #include "components/offline_pages/offline_page_feature.h" 24 #include "components/offline_pages/offline_page_feature.h"
24 #include "components/offline_pages/offline_page_item.h" 25 #include "components/offline_pages/offline_page_item.h"
25 #include "components/offline_pages/offline_page_test_archiver.h" 26 #include "components/offline_pages/offline_page_test_archiver.h"
26 #include "components/offline_pages/offline_page_test_store.h" 27 #include "components/offline_pages/offline_page_test_store.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 #include "url/gurl.h" 29 #include "url/gurl.h"
29 30
30 using SavePageResult = offline_pages::OfflinePageModel::SavePageResult; 31 using SavePageResult = offline_pages::OfflinePageModel::SavePageResult;
31 using DeletePageResult = offline_pages::OfflinePageModel::DeletePageResult; 32 using DeletePageResult = offline_pages::OfflinePageModel::DeletePageResult;
32 using GetAllPagesResult = offline_pages::OfflinePageModel::GetAllPagesResult; 33 using GetAllPagesResult = offline_pages::OfflinePageModel::GetAllPagesResult;
33 using CheckPagesExistOfflineResult = 34 using CheckPagesExistOfflineResult =
34 offline_pages::OfflinePageModel::CheckPagesExistOfflineResult; 35 offline_pages::OfflinePageModel::CheckPagesExistOfflineResult;
36 using ArchiveDirs = offline_pages::OfflinePageModel::ArchiveDirs;
37 using LifetimeType = offline_pages::LifetimePolicy::LifetimeType;
35 38
36 namespace offline_pages { 39 namespace offline_pages {
37 40
38 namespace { 41 namespace {
39 const char kTestClientNamespace[] = "CLIENT_NAMESPACE"; 42 const char kTestClientNamespace[] = "CLIENT_NAMESPACE";
40 const GURL kTestUrl("http://example.com"); 43 const GURL kTestUrl("http://example.com");
41 const GURL kTestUrl2("http://other.page.com"); 44 const GURL kTestUrl2("http://other.page.com");
42 const GURL kTestUrl3("http://test.xyz"); 45 const GURL kTestUrl3("http://test.xyz");
43 const GURL kFileUrl("file:///foo"); 46 const GURL kFileUrl("file:///foo");
44 const ClientId kTestClientId1(kTestClientNamespace, "1234"); 47 const ClientId kTestClientId1(kTestClientNamespace, "1234");
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 137
135 int64_t last_deleted_offline_id() const { return last_deleted_offline_id_; } 138 int64_t last_deleted_offline_id() const { return last_deleted_offline_id_; }
136 139
137 ClientId last_deleted_client_id() const { return last_deleted_client_id_; } 140 ClientId last_deleted_client_id() const { return last_deleted_client_id_; }
138 141
139 const base::FilePath& last_archiver_path() { return last_archiver_path_; } 142 const base::FilePath& last_archiver_path() { return last_archiver_path_; }
140 143
141 private: 144 private:
142 scoped_refptr<base::TestMockTimeTaskRunner> task_runner_; 145 scoped_refptr<base::TestMockTimeTaskRunner> task_runner_;
143 base::ThreadTaskRunnerHandle task_runner_handle_; 146 base::ThreadTaskRunnerHandle task_runner_handle_;
147 ArchiveDirs archive_dirs_;
144 base::ScopedTempDir temp_dir_; 148 base::ScopedTempDir temp_dir_;
145 149
146 std::unique_ptr<OfflinePageModel> model_; 150 std::unique_ptr<OfflinePageModel> model_;
147 GetAllPagesResult all_pages_; 151 GetAllPagesResult all_pages_;
148 SavePageResult last_save_result_; 152 SavePageResult last_save_result_;
149 int64_t last_save_offline_id_; 153 int64_t last_save_offline_id_;
150 DeletePageResult last_delete_result_; 154 DeletePageResult last_delete_result_;
151 base::FilePath last_archiver_path_; 155 base::FilePath last_archiver_path_;
152 int64_t last_deleted_offline_id_; 156 int64_t last_deleted_offline_id_;
153 ClientId last_deleted_client_id_; 157 ClientId last_deleted_client_id_;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 this, url, result, kTestFileSize, base::ThreadTaskRunnerHandle::Get())); 241 this, url, result, kTestFileSize, base::ThreadTaskRunnerHandle::Get()));
238 } 242 }
239 243
240 std::unique_ptr<OfflinePageMetadataStore> OfflinePageModelTest::BuildStore() { 244 std::unique_ptr<OfflinePageMetadataStore> OfflinePageModelTest::BuildStore() {
241 return std::unique_ptr<OfflinePageMetadataStore>( 245 return std::unique_ptr<OfflinePageMetadataStore>(
242 new OfflinePageTestStore(base::ThreadTaskRunnerHandle::Get())); 246 new OfflinePageTestStore(base::ThreadTaskRunnerHandle::Get()));
243 } 247 }
244 248
245 std::unique_ptr<OfflinePageModel> OfflinePageModelTest::BuildModel( 249 std::unique_ptr<OfflinePageModel> OfflinePageModelTest::BuildModel(
246 std::unique_ptr<OfflinePageMetadataStore> store) { 250 std::unique_ptr<OfflinePageMetadataStore> store) {
251 archive_dirs_.insert(
252 std::make_pair(LifetimeType::TEMPORARY, temp_dir_.path()));
247 return std::unique_ptr<OfflinePageModel>(new OfflinePageModel( 253 return std::unique_ptr<OfflinePageModel>(new OfflinePageModel(
248 std::move(store), temp_dir_.path(), base::ThreadTaskRunnerHandle::Get())); 254 std::move(store), archive_dirs_, base::ThreadTaskRunnerHandle::Get()));
249 } 255 }
250 256
251 void OfflinePageModelTest::ResetModel() { 257 void OfflinePageModelTest::ResetModel() {
252 model_->RemoveObserver(this); 258 model_->RemoveObserver(this);
253 OfflinePageTestStore* old_store = GetStore(); 259 OfflinePageTestStore* old_store = GetStore();
254 std::unique_ptr<OfflinePageMetadataStore> new_store( 260 std::unique_ptr<OfflinePageMetadataStore> new_store(
255 new OfflinePageTestStore(*old_store)); 261 new OfflinePageTestStore(*old_store));
256 model_ = BuildModel(std::move(new_store)); 262 model_ = BuildModel(std::move(new_store));
257 model_->AddObserver(this); 263 model_->AddObserver(this);
258 PumpLoop(); 264 PumpLoop();
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList); 945 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList);
940 feature_list2->InitializeFromCommandLine( 946 feature_list2->InitializeFromCommandLine(
941 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," + 947 std::string(offline_pages::kOfflineBookmarksFeature.name) + "," +
942 offline_pages::kOfflinePagesBackgroundLoadingFeature.name, 948 offline_pages::kOfflinePagesBackgroundLoadingFeature.name,
943 ""); 949 "");
944 base::FeatureList::SetInstance(std::move(feature_list2)); 950 base::FeatureList::SetInstance(std::move(feature_list2));
945 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled()); 951 EXPECT_TRUE(offline_pages::IsOfflinePagesBackgroundLoadingEnabled());
946 } 952 }
947 953
948 } // namespace offline_pages 954 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_model.cc ('k') | components/offline_pages/offline_page_test_archiver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698