OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/extensions/external_cache.h" | 5 #include "chrome/browser/chromeos/extensions/external_cache.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 void AddInstalledExtension(const std::string& id, | 134 void AddInstalledExtension(const std::string& id, |
135 const std::string& version) { | 135 const std::string& version) { |
136 installed_extensions_[id] = version; | 136 installed_extensions_[id] = version; |
137 } | 137 } |
138 | 138 |
139 private: | 139 private: |
140 content::TestBrowserThreadBundle thread_bundle_; | 140 content::TestBrowserThreadBundle thread_bundle_; |
141 | 141 |
142 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 142 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
143 scoped_ptr<net::TestURLFetcherFactory> fetcher_factory_; | 143 std::unique_ptr<net::TestURLFetcherFactory> fetcher_factory_; |
144 | 144 |
145 scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_; | 145 std::unique_ptr<base::SequencedWorkerPoolOwner> pool_owner_; |
146 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; | 146 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; |
147 | 147 |
148 base::ScopedTempDir cache_dir_; | 148 base::ScopedTempDir cache_dir_; |
149 base::ScopedTempDir temp_dir_; | 149 base::ScopedTempDir temp_dir_; |
150 scoped_ptr<base::DictionaryValue> prefs_; | 150 std::unique_ptr<base::DictionaryValue> prefs_; |
151 std::map<std::string, std::string> installed_extensions_; | 151 std::map<std::string, std::string> installed_extensions_; |
152 | 152 |
153 ScopedTestDeviceSettingsService test_device_settings_service_; | 153 ScopedTestDeviceSettingsService test_device_settings_service_; |
154 ScopedTestCrosSettings test_cros_settings_; | 154 ScopedTestCrosSettings test_cros_settings_; |
155 | 155 |
156 DISALLOW_COPY_AND_ASSIGN(ExternalCacheTest); | 156 DISALLOW_COPY_AND_ASSIGN(ExternalCacheTest); |
157 }; | 157 }; |
158 | 158 |
159 TEST_F(ExternalCacheTest, Basic) { | 159 TEST_F(ExternalCacheTest, Basic) { |
160 base::FilePath cache_dir(CreateCacheDir(false)); | 160 base::FilePath cache_dir(CreateCacheDir(false)); |
161 ExternalCache external_cache(cache_dir, request_context_getter(), | 161 ExternalCache external_cache(cache_dir, request_context_getter(), |
162 background_task_runner(), this, true, false); | 162 background_task_runner(), this, true, false); |
163 | 163 |
164 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 164 std::unique_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
165 base::DictionaryValue* dict = CreateEntryWithUpdateUrl(true); | 165 base::DictionaryValue* dict = CreateEntryWithUpdateUrl(true); |
166 prefs->Set(kTestExtensionId1, dict); | 166 prefs->Set(kTestExtensionId1, dict); |
167 CreateExtensionFile(cache_dir, kTestExtensionId1, "1"); | 167 CreateExtensionFile(cache_dir, kTestExtensionId1, "1"); |
168 dict = CreateEntryWithUpdateUrl(true); | 168 dict = CreateEntryWithUpdateUrl(true); |
169 prefs->Set(kTestExtensionId2, dict); | 169 prefs->Set(kTestExtensionId2, dict); |
170 prefs->Set(kTestExtensionId3, CreateEntryWithUpdateUrl(false)); | 170 prefs->Set(kTestExtensionId3, CreateEntryWithUpdateUrl(false)); |
171 CreateExtensionFile(cache_dir, kTestExtensionId3, "3"); | 171 CreateExtensionFile(cache_dir, kTestExtensionId3, "3"); |
172 prefs->Set(kTestExtensionId4, CreateEntryWithUpdateUrl(false)); | 172 prefs->Set(kTestExtensionId4, CreateEntryWithUpdateUrl(false)); |
173 | 173 |
174 external_cache.UpdateExtensionsList(std::move(prefs)); | 174 external_cache.UpdateExtensionsList(std::move(prefs)); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 256 |
257 // Damaged file should be removed from disk. | 257 // Damaged file should be removed from disk. |
258 external_cache.OnDamagedFileDetected( | 258 external_cache.OnDamagedFileDetected( |
259 GetExtensionFile(cache_dir, kTestExtensionId2, "2")); | 259 GetExtensionFile(cache_dir, kTestExtensionId2, "2")); |
260 WaitForCompletion(); | 260 WaitForCompletion(); |
261 EXPECT_EQ(provided_prefs()->size(), 3ul); | 261 EXPECT_EQ(provided_prefs()->size(), 3ul); |
262 EXPECT_FALSE(base::PathExists( | 262 EXPECT_FALSE(base::PathExists( |
263 GetExtensionFile(cache_dir, kTestExtensionId2, "2"))); | 263 GetExtensionFile(cache_dir, kTestExtensionId2, "2"))); |
264 | 264 |
265 // Shutdown with callback OnExtensionListsUpdated that clears prefs. | 265 // Shutdown with callback OnExtensionListsUpdated that clears prefs. |
266 scoped_ptr<base::DictionaryValue> empty(new base::DictionaryValue); | 266 std::unique_ptr<base::DictionaryValue> empty(new base::DictionaryValue); |
267 external_cache.Shutdown( | 267 external_cache.Shutdown( |
268 base::Bind(&ExternalCacheTest::OnExtensionListsUpdated, | 268 base::Bind(&ExternalCacheTest::OnExtensionListsUpdated, |
269 base::Unretained(this), | 269 base::Unretained(this), |
270 base::Unretained(empty.get()))); | 270 base::Unretained(empty.get()))); |
271 WaitForCompletion(); | 271 WaitForCompletion(); |
272 EXPECT_EQ(provided_prefs()->size(), 0ul); | 272 EXPECT_EQ(provided_prefs()->size(), 0ul); |
273 | 273 |
274 // After Shutdown directory shouldn't be touched. | 274 // After Shutdown directory shouldn't be touched. |
275 external_cache.OnDamagedFileDetected( | 275 external_cache.OnDamagedFileDetected( |
276 GetExtensionFile(cache_dir, kTestExtensionId4, "4")); | 276 GetExtensionFile(cache_dir, kTestExtensionId4, "4")); |
277 WaitForCompletion(); | 277 WaitForCompletion(); |
278 EXPECT_TRUE(base::PathExists( | 278 EXPECT_TRUE(base::PathExists( |
279 GetExtensionFile(cache_dir, kTestExtensionId4, "4"))); | 279 GetExtensionFile(cache_dir, kTestExtensionId4, "4"))); |
280 } | 280 } |
281 | 281 |
282 TEST_F(ExternalCacheTest, PreserveInstalled) { | 282 TEST_F(ExternalCacheTest, PreserveInstalled) { |
283 base::FilePath cache_dir(CreateCacheDir(false)); | 283 base::FilePath cache_dir(CreateCacheDir(false)); |
284 ExternalCache external_cache(cache_dir, request_context_getter(), | 284 ExternalCache external_cache(cache_dir, request_context_getter(), |
285 background_task_runner(), this, true, false); | 285 background_task_runner(), this, true, false); |
286 | 286 |
287 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 287 std::unique_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
288 prefs->Set(kTestExtensionId1, CreateEntryWithUpdateUrl(true)); | 288 prefs->Set(kTestExtensionId1, CreateEntryWithUpdateUrl(true)); |
289 prefs->Set(kTestExtensionId2, CreateEntryWithUpdateUrl(true)); | 289 prefs->Set(kTestExtensionId2, CreateEntryWithUpdateUrl(true)); |
290 | 290 |
291 AddInstalledExtension(kTestExtensionId1, "1"); | 291 AddInstalledExtension(kTestExtensionId1, "1"); |
292 | 292 |
293 external_cache.UpdateExtensionsList(std::move(prefs)); | 293 external_cache.UpdateExtensionsList(std::move(prefs)); |
294 WaitForCompletion(); | 294 WaitForCompletion(); |
295 | 295 |
296 ASSERT_TRUE(provided_prefs()); | 296 ASSERT_TRUE(provided_prefs()); |
297 EXPECT_EQ(provided_prefs()->size(), 1ul); | 297 EXPECT_EQ(provided_prefs()->size(), 1ul); |
298 | 298 |
299 // File not in cache but extension installed. | 299 // File not in cache but extension installed. |
300 const base::DictionaryValue* entry1 = NULL; | 300 const base::DictionaryValue* entry1 = NULL; |
301 ASSERT_TRUE(provided_prefs()->GetDictionary(kTestExtensionId1, &entry1)); | 301 ASSERT_TRUE(provided_prefs()->GetDictionary(kTestExtensionId1, &entry1)); |
302 EXPECT_TRUE(entry1->HasKey( | 302 EXPECT_TRUE(entry1->HasKey( |
303 extensions::ExternalProviderImpl::kExternalUpdateUrl)); | 303 extensions::ExternalProviderImpl::kExternalUpdateUrl)); |
304 EXPECT_FALSE(entry1->HasKey( | 304 EXPECT_FALSE(entry1->HasKey( |
305 extensions::ExternalProviderImpl::kExternalCrx)); | 305 extensions::ExternalProviderImpl::kExternalCrx)); |
306 EXPECT_FALSE(entry1->HasKey( | 306 EXPECT_FALSE(entry1->HasKey( |
307 extensions::ExternalProviderImpl::kExternalVersion)); | 307 extensions::ExternalProviderImpl::kExternalVersion)); |
308 } | 308 } |
309 | 309 |
310 } // namespace chromeos | 310 } // namespace chromeos |
OLD | NEW |