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

Side by Side Diff: chrome/browser/extensions/api/storage/settings_sync_unittest.cc

Issue 2310683002: Remove most ScopedVector usage from c/b/extensions. (Closed)
Patch Set: remove scoped_vector includes Created 4 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/json/json_reader.h" 12 #include "base/json/json_reader.h"
13 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
14 #include "base/memory/linked_ptr.h"
15 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
16 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
17 #include "base/run_loop.h" 16 #include "base/run_loop.h"
18 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
19 #include "build/build_config.h" 18 #include "build/build_config.h"
20 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" 19 #include "chrome/browser/extensions/api/storage/settings_sync_util.h"
21 #include "chrome/browser/extensions/api/storage/sync_value_store_cache.h" 20 #include "chrome/browser/extensions/api/storage/sync_value_store_cache.h"
22 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h" 21 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h"
23 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
24 #include "components/sync/api/sync_change_processor.h" 23 #include "components/sync/api/sync_change_processor.h"
(...skipping 22 matching lines...) Expand all
47 namespace util = settings_test_util; 46 namespace util = settings_test_util;
48 47
49 namespace { 48 namespace {
50 49
51 // To save typing ValueStore::DEFAULTS everywhere. 50 // To save typing ValueStore::DEFAULTS everywhere.
52 const ValueStore::WriteOptions DEFAULTS = ValueStore::DEFAULTS; 51 const ValueStore::WriteOptions DEFAULTS = ValueStore::DEFAULTS;
53 52
54 // More saving typing. Maps extension IDs to a list of sync changes for that 53 // More saving typing. Maps extension IDs to a list of sync changes for that
55 // extension. 54 // extension.
56 using SettingSyncDataMultimap = 55 using SettingSyncDataMultimap =
57 std::map<std::string, linked_ptr<SettingSyncDataList>>; 56 std::map<std::string, std::unique_ptr<SettingSyncDataList>>;
58 57
59 // Gets the pretty-printed JSON for a value. 58 // Gets the pretty-printed JSON for a value.
60 static std::string GetJson(const base::Value& value) { 59 static std::string GetJson(const base::Value& value) {
61 std::string json; 60 std::string json;
62 base::JSONWriter::WriteWithOptions( 61 base::JSONWriter::WriteWithOptions(
63 value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); 62 value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
64 return json; 63 return json;
65 } 64 }
66 65
67 // Returns whether two Values are equal. 66 // Returns whether two Values are equal.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 const syncer::SyncChangeList& change_list) override { 112 const syncer::SyncChangeList& change_list) override {
114 if (fail_all_requests_) { 113 if (fail_all_requests_) {
115 return syncer::SyncError( 114 return syncer::SyncError(
116 FROM_HERE, 115 FROM_HERE,
117 syncer::SyncError::DATATYPE_ERROR, 116 syncer::SyncError::DATATYPE_ERROR,
118 "MockSyncChangeProcessor: configured to fail", 117 "MockSyncChangeProcessor: configured to fail",
119 change_list[0].sync_data().GetDataType()); 118 change_list[0].sync_data().GetDataType());
120 } 119 }
121 for (syncer::SyncChangeList::const_iterator it = change_list.begin(); 120 for (syncer::SyncChangeList::const_iterator it = change_list.begin();
122 it != change_list.end(); ++it) { 121 it != change_list.end(); ++it) {
123 changes_.push_back(new SettingSyncData(*it)); 122 changes_.push_back(base::MakeUnique<SettingSyncData>(*it));
124 } 123 }
125 return syncer::SyncError(); 124 return syncer::SyncError();
126 } 125 }
127 126
128 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override { 127 syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const override {
129 return syncer::SyncDataList(); 128 return syncer::SyncDataList();
130 } 129 }
131 130
132 // Mock methods. 131 // Mock methods.
133 132
134 const SettingSyncDataList& changes() { return changes_; } 133 const SettingSyncDataList& changes() { return changes_; }
135 134
136 void ClearChanges() { 135 void ClearChanges() {
137 changes_.clear(); 136 changes_.clear();
138 } 137 }
139 138
140 void set_fail_all_requests(bool fail_all_requests) { 139 void set_fail_all_requests(bool fail_all_requests) {
141 fail_all_requests_ = fail_all_requests; 140 fail_all_requests_ = fail_all_requests;
142 } 141 }
143 142
144 // Returns the only change for a given extension setting. If there is not 143 // Returns the only change for a given extension setting. If there is not
145 // exactly 1 change for that key, a test assertion will fail. 144 // exactly 1 change for that key, a test assertion will fail.
146 SettingSyncData* GetOnlyChange(const std::string& extension_id, 145 SettingSyncData* GetOnlyChange(const std::string& extension_id,
147 const std::string& key) { 146 const std::string& key) {
148 std::vector<SettingSyncData*> matching_changes; 147 std::vector<SettingSyncData*> matching_changes;
149 for (SettingSyncDataList::iterator it = changes_.begin(); 148 for (const std::unique_ptr<SettingSyncData>& change : changes_) {
150 it != changes_.end(); ++it) { 149 if (change->extension_id() == extension_id && change->key() == key)
151 if ((*it)->extension_id() == extension_id && (*it)->key() == key) { 150 matching_changes.push_back(change.get());
152 matching_changes.push_back(*it);
153 }
154 } 151 }
155 if (matching_changes.empty()) { 152 if (matching_changes.empty()) {
156 ADD_FAILURE() << "No matching changes for " << extension_id << "/" << 153 ADD_FAILURE() << "No matching changes for " << extension_id << "/" <<
157 key << " (out of " << changes_.size() << ")"; 154 key << " (out of " << changes_.size() << ")";
158 return nullptr; 155 return nullptr;
159 } 156 }
160 if (matching_changes.size() != 1u) { 157 if (matching_changes.size() != 1u) {
161 ADD_FAILURE() << matching_changes.size() << " matching changes for " << 158 ADD_FAILURE() << matching_changes.size() << " matching changes for " <<
162 extension_id << "/" << key << " (out of " << changes_.size() << ")"; 159 extension_id << "/" << key << " (out of " << changes_.size() << ")";
163 } 160 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 230 }
234 231
235 // Gets all the sync data from the SyncableService for a sync type as a map 232 // Gets all the sync data from the SyncableService for a sync type as a map
236 // from extension id to its sync data. 233 // from extension id to its sync data.
237 SettingSyncDataMultimap GetAllSyncData(syncer::ModelType model_type) { 234 SettingSyncDataMultimap GetAllSyncData(syncer::ModelType model_type) {
238 syncer::SyncDataList as_list = 235 syncer::SyncDataList as_list =
239 GetSyncableService(model_type)->GetAllSyncData(model_type); 236 GetSyncableService(model_type)->GetAllSyncData(model_type);
240 SettingSyncDataMultimap as_map; 237 SettingSyncDataMultimap as_map;
241 for (syncer::SyncDataList::iterator it = as_list.begin(); 238 for (syncer::SyncDataList::iterator it = as_list.begin();
242 it != as_list.end(); ++it) { 239 it != as_list.end(); ++it) {
243 SettingSyncData* sync_data = new SettingSyncData(*it); 240 std::unique_ptr<SettingSyncData> sync_data(new SettingSyncData(*it));
244 linked_ptr<SettingSyncDataList>& list_for_extension = 241 std::unique_ptr<SettingSyncDataList>& list_for_extension =
245 as_map[sync_data->extension_id()]; 242 as_map[sync_data->extension_id()];
246 if (!list_for_extension.get()) 243 if (!list_for_extension)
247 list_for_extension.reset(new SettingSyncDataList()); 244 list_for_extension.reset(new SettingSyncDataList());
248 list_for_extension->push_back(sync_data); 245 list_for_extension->push_back(std::move(sync_data));
249 } 246 }
250 return as_map; 247 return as_map;
251 } 248 }
252 249
253 // This class uses it's TestingValueStore in such a way that it always mints 250 // This class uses it's TestingValueStore in such a way that it always mints
254 // new TestingValueStore instances. 251 // new TestingValueStore instances.
255 TestingValueStore* GetExisting(const ExtensionId& extension_id) { 252 TestingValueStore* GetExisting(const ExtensionId& extension_id) {
256 return static_cast<TestingValueStore*>( 253 return static_cast<TestingValueStore*>(
257 storage_factory_->GetExisting(extension_id)); 254 storage_factory_->GetExisting(extension_id));
258 } 255 }
(...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 new base::StringValue("value")); 1340 new base::StringValue("value"));
1344 EXPECT_TRUE(base::Value::Equals(&expected_data, &data->settings())); 1341 EXPECT_TRUE(base::Value::Equals(&expected_data, &data->settings()));
1345 } 1342 }
1346 1343
1347 // Test dots in keys going to sync. 1344 // Test dots in keys going to sync.
1348 { 1345 {
1349 std::unique_ptr<base::Value> string_value(new base::StringValue("spot")); 1346 std::unique_ptr<base::Value> string_value(new base::StringValue("spot"));
1350 storage->Set(DEFAULTS, "key.with.spot", *string_value); 1347 storage->Set(DEFAULTS, "key.with.spot", *string_value);
1351 1348
1352 ASSERT_EQ(1u, sync_processor_->changes().size()); 1349 ASSERT_EQ(1u, sync_processor_->changes().size());
1353 SettingSyncData* sync_data = sync_processor_->changes()[0]; 1350 SettingSyncData* sync_data = sync_processor_->changes()[0].get();
1354 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, sync_data->change_type()); 1351 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, sync_data->change_type());
1355 EXPECT_EQ("ext", sync_data->extension_id()); 1352 EXPECT_EQ("ext", sync_data->extension_id());
1356 EXPECT_EQ("key.with.spot", sync_data->key()); 1353 EXPECT_EQ("key.with.spot", sync_data->key());
1357 EXPECT_TRUE(sync_data->value().Equals(string_value.get())); 1354 EXPECT_TRUE(sync_data->value().Equals(string_value.get()));
1358 } 1355 }
1359 } 1356 }
1360 1357
1361 // In other (frontend) tests, we assume that the result of GetStorage 1358 // In other (frontend) tests, we assume that the result of GetStorage
1362 // is a pointer to the a Storage owned by a Frontend object, but for 1359 // is a pointer to the a Storage owned by a Frontend object, but for
1363 // the unlimitedStorage case, this might not be true. So, write the 1360 // the unlimitedStorage case, this might not be true. So, write the
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 settings_namespace::SYNC, 1408 settings_namespace::SYNC,
1412 base::Bind(&UnlimitedSyncStorageTestCallback)); 1409 base::Bind(&UnlimitedSyncStorageTestCallback));
1413 frontend_->RunWithStorage(extension, 1410 frontend_->RunWithStorage(extension,
1414 settings_namespace::LOCAL, 1411 settings_namespace::LOCAL,
1415 base::Bind(&UnlimitedLocalStorageTestCallback)); 1412 base::Bind(&UnlimitedLocalStorageTestCallback));
1416 1413
1417 base::RunLoop().RunUntilIdle(); 1414 base::RunLoop().RunUntilIdle();
1418 } 1415 }
1419 1416
1420 } // namespace extensions 1417 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698