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

Side by Side Diff: chrome/browser/chromeos/extensions/external_cache_unittest.cc

Issue 2765363004: Stop passing raw pointers to DictionaryValue::Set, part 2 (Closed)
Patch Set: Fix comments Created 3 years, 9 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 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 void CreateFile(const base::FilePath& file) { 109 void CreateFile(const base::FilePath& file) {
110 EXPECT_EQ(base::WriteFile(file, NULL, 0), 0); 110 EXPECT_EQ(base::WriteFile(file, NULL, 0), 0);
111 } 111 }
112 112
113 base::FilePath GetExtensionFile(const base::FilePath& dir, 113 base::FilePath GetExtensionFile(const base::FilePath& dir,
114 const std::string& id, 114 const std::string& id,
115 const std::string& version) { 115 const std::string& version) {
116 return dir.Append(id + "-" + version + ".crx"); 116 return dir.Append(id + "-" + version + ".crx");
117 } 117 }
118 118
119 base::DictionaryValue* CreateEntryWithUpdateUrl(bool from_webstore) { 119 std::unique_ptr<base::DictionaryValue> CreateEntryWithUpdateUrl(
120 base::DictionaryValue* entry = new base::DictionaryValue; 120 bool from_webstore) {
121 auto entry = base::MakeUnique<base::DictionaryValue>();
121 entry->SetString(extensions::ExternalProviderImpl::kExternalUpdateUrl, 122 entry->SetString(extensions::ExternalProviderImpl::kExternalUpdateUrl,
122 from_webstore ? extension_urls::GetWebstoreUpdateUrl().spec() 123 from_webstore ? extension_urls::GetWebstoreUpdateUrl().spec()
123 : kNonWebstoreUpdateUrl); 124 : kNonWebstoreUpdateUrl);
124 return entry; 125 return entry;
125 } 126 }
126 127
127 void WaitForCompletion() { 128 void WaitForCompletion() {
128 // Wait for background task completion that sends replay to UI thread. 129 // Wait for background task completion that sends replay to UI thread.
129 pool_owner_->pool()->FlushForTesting(); 130 pool_owner_->pool()->FlushForTesting();
130 // Wait for UI thread task completion. 131 // Wait for UI thread task completion.
(...skipping 24 matching lines...) Expand all
155 156
156 DISALLOW_COPY_AND_ASSIGN(ExternalCacheTest); 157 DISALLOW_COPY_AND_ASSIGN(ExternalCacheTest);
157 }; 158 };
158 159
159 TEST_F(ExternalCacheTest, Basic) { 160 TEST_F(ExternalCacheTest, Basic) {
160 base::FilePath cache_dir(CreateCacheDir(false)); 161 base::FilePath cache_dir(CreateCacheDir(false));
161 ExternalCache external_cache(cache_dir, request_context_getter(), 162 ExternalCache external_cache(cache_dir, request_context_getter(),
162 background_task_runner(), this, true, false); 163 background_task_runner(), this, true, false);
163 164
164 std::unique_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); 165 std::unique_ptr<base::DictionaryValue> prefs(new base::DictionaryValue);
165 base::DictionaryValue* dict = CreateEntryWithUpdateUrl(true); 166 prefs->Set(kTestExtensionId1, CreateEntryWithUpdateUrl(true));
166 prefs->Set(kTestExtensionId1, dict);
167 CreateExtensionFile(cache_dir, kTestExtensionId1, "1"); 167 CreateExtensionFile(cache_dir, kTestExtensionId1, "1");
168 dict = CreateEntryWithUpdateUrl(true); 168 prefs->Set(kTestExtensionId2, CreateEntryWithUpdateUrl(true));
169 prefs->Set(kTestExtensionId2, dict);
170 prefs->Set(kTestExtensionId3, CreateEntryWithUpdateUrl(false)); 169 prefs->Set(kTestExtensionId3, CreateEntryWithUpdateUrl(false));
171 CreateExtensionFile(cache_dir, kTestExtensionId3, "3"); 170 CreateExtensionFile(cache_dir, kTestExtensionId3, "3");
172 prefs->Set(kTestExtensionId4, CreateEntryWithUpdateUrl(false)); 171 prefs->Set(kTestExtensionId4, CreateEntryWithUpdateUrl(false));
173 172
174 external_cache.UpdateExtensionsList(std::move(prefs)); 173 external_cache.UpdateExtensionsList(std::move(prefs));
175 WaitForCompletion(); 174 WaitForCompletion();
176 175
177 ASSERT_TRUE(provided_prefs()); 176 ASSERT_TRUE(provided_prefs());
178 EXPECT_EQ(provided_prefs()->size(), 2ul); 177 EXPECT_EQ(provided_prefs()->size(), 2ul);
179 178
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 ASSERT_TRUE(provided_prefs()->GetDictionary(kTestExtensionId1, &entry1)); 300 ASSERT_TRUE(provided_prefs()->GetDictionary(kTestExtensionId1, &entry1));
302 EXPECT_TRUE(entry1->HasKey( 301 EXPECT_TRUE(entry1->HasKey(
303 extensions::ExternalProviderImpl::kExternalUpdateUrl)); 302 extensions::ExternalProviderImpl::kExternalUpdateUrl));
304 EXPECT_FALSE(entry1->HasKey( 303 EXPECT_FALSE(entry1->HasKey(
305 extensions::ExternalProviderImpl::kExternalCrx)); 304 extensions::ExternalProviderImpl::kExternalCrx));
306 EXPECT_FALSE(entry1->HasKey( 305 EXPECT_FALSE(entry1->HasKey(
307 extensions::ExternalProviderImpl::kExternalVersion)); 306 extensions::ExternalProviderImpl::kExternalVersion));
308 } 307 }
309 308
310 } // namespace chromeos 309 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698