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

Side by Side Diff: components/wifi_sync/wifi_credential_syncable_service_unittest.cc

Issue 1917673002: Convert //components/[u-z]* from scoped_ptr to std::unique_ptr (Closed) 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/wifi_sync/wifi_credential_syncable_service.h" 5 #include "components/wifi_sync/wifi_credential_syncable_service.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8
9 #include <memory>
8 #include <string> 10 #include <string>
9 #include <utility> 11 #include <utility>
10 #include <vector> 12 #include <vector>
11 13
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/ptr_util.h"
14 #include "base/time/time.h" 16 #include "base/time/time.h"
15 #include "base/tracked_objects.h" 17 #include "base/tracked_objects.h"
16 #include "components/wifi_sync/wifi_config_delegate.h" 18 #include "components/wifi_sync/wifi_config_delegate.h"
17 #include "components/wifi_sync/wifi_credential.h" 19 #include "components/wifi_sync/wifi_credential.h"
18 #include "components/wifi_sync/wifi_security_class.h" 20 #include "components/wifi_sync/wifi_security_class.h"
19 #include "sync/api/attachments/attachment_id.h" 21 #include "sync/api/attachments/attachment_id.h"
20 #include "sync/api/fake_sync_change_processor.h" 22 #include "sync/api/fake_sync_change_processor.h"
21 #include "sync/api/sync_change.h" 23 #include "sync/api/sync_change.h"
22 #include "sync/api/sync_data.h" 24 #include "sync/api/sync_data.h"
23 #include "sync/api/sync_error.h" 25 #include "sync/api/sync_error.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 DISALLOW_COPY_AND_ASSIGN(FakeWifiConfigDelegate); 62 DISALLOW_COPY_AND_ASSIGN(FakeWifiConfigDelegate);
61 }; 63 };
62 64
63 // Unit tests for WifiCredentialSyncableService. 65 // Unit tests for WifiCredentialSyncableService.
64 class WifiCredentialSyncableServiceTest : public testing::Test { 66 class WifiCredentialSyncableServiceTest : public testing::Test {
65 protected: 67 protected:
66 WifiCredentialSyncableServiceTest() 68 WifiCredentialSyncableServiceTest()
67 : config_delegate_(new FakeWifiConfigDelegate()), 69 : config_delegate_(new FakeWifiConfigDelegate()),
68 change_processor_(nullptr) { 70 change_processor_(nullptr) {
69 syncable_service_.reset( 71 syncable_service_.reset(
70 new WifiCredentialSyncableService(make_scoped_ptr(config_delegate_))); 72 new WifiCredentialSyncableService(base::WrapUnique(config_delegate_)));
71 } 73 }
72 74
73 // Wrappers for methods in WifiCredentialSyncableService. 75 // Wrappers for methods in WifiCredentialSyncableService.
74 syncer::SyncError ProcessSyncChanges( 76 syncer::SyncError ProcessSyncChanges(
75 const syncer::SyncChangeList& change_list) { 77 const syncer::SyncChangeList& change_list) {
76 return syncable_service_->ProcessSyncChanges(FROM_HERE, change_list); 78 return syncable_service_->ProcessSyncChanges(FROM_HERE, change_list);
77 } 79 }
78 bool AddToSyncedNetworks(const std::string& item_id, 80 bool AddToSyncedNetworks(const std::string& item_id,
79 const WifiCredential& credential) { 81 const WifiCredential& credential) {
80 return syncable_service_->AddToSyncedNetworks(item_id, credential); 82 return syncable_service_->AddToSyncedNetworks(item_id, credential);
81 } 83 }
82 84
83 // Returns the number of change requests received by 85 // Returns the number of change requests received by
84 // |change_processor_|. 86 // |change_processor_|.
85 int change_processor_changes_size() { 87 int change_processor_changes_size() {
86 CHECK(change_processor_); 88 CHECK(change_processor_);
87 return change_processor_->changes().size(); 89 return change_processor_->changes().size();
88 } 90 }
89 91
90 // Returns the number of times AddToLocalNetworks has been called on 92 // Returns the number of times AddToLocalNetworks has been called on
91 // |config_delegate_|. 93 // |config_delegate_|.
92 unsigned int config_delegate_add_count() { 94 unsigned int config_delegate_add_count() {
93 return config_delegate_->add_count(); 95 return config_delegate_->add_count();
94 } 96 }
95 97
96 // Returns a new WifiCredential constructed from the given parameters. 98 // Returns a new WifiCredential constructed from the given parameters.
97 WifiCredential MakeCredential(const std::string& ssid, 99 WifiCredential MakeCredential(const std::string& ssid,
98 WifiSecurityClass security_class, 100 WifiSecurityClass security_class,
99 const std::string& passphrase) { 101 const std::string& passphrase) {
100 scoped_ptr<WifiCredential> credential = WifiCredential::Create( 102 std::unique_ptr<WifiCredential> credential = WifiCredential::Create(
101 WifiCredential::MakeSsidBytesForTest(ssid), security_class, passphrase); 103 WifiCredential::MakeSsidBytesForTest(ssid), security_class, passphrase);
102 CHECK(credential); 104 CHECK(credential);
103 return *credential; 105 return *credential;
104 } 106 }
105 107
106 // Returns a new EntitySpecifics protobuf, with the 108 // Returns a new EntitySpecifics protobuf, with the
107 // wifi_credential_specifics fields populated with the given 109 // wifi_credential_specifics fields populated with the given
108 // parameters. 110 // parameters.
109 sync_pb::EntitySpecifics MakeWifiCredentialSpecifics( 111 sync_pb::EntitySpecifics MakeWifiCredentialSpecifics(
110 const std::string& ssid, 112 const std::string& ssid,
(...skipping 21 matching lines...) Expand all
132 return syncer::SyncChange( 134 return syncer::SyncChange(
133 FROM_HERE, syncer::SyncChange::ACTION_ADD, 135 FROM_HERE, syncer::SyncChange::ACTION_ADD,
134 syncer::SyncData::CreateRemoteData( 136 syncer::SyncData::CreateRemoteData(
135 sync_item_id, 137 sync_item_id,
136 MakeWifiCredentialSpecifics(ssid, security_class, passphrase), 138 MakeWifiCredentialSpecifics(ssid, security_class, passphrase),
137 base::Time(), syncer::AttachmentIdList(), 139 base::Time(), syncer::AttachmentIdList(),
138 syncer::AttachmentServiceProxyForTest::Create())); 140 syncer::AttachmentServiceProxyForTest::Create()));
139 } 141 }
140 142
141 void StartSyncing() { 143 void StartSyncing() {
142 scoped_ptr<FakeSyncChangeProcessor> change_processor( 144 std::unique_ptr<FakeSyncChangeProcessor> change_processor(
143 new FakeSyncChangeProcessor()); 145 new FakeSyncChangeProcessor());
144 change_processor_ = change_processor.get(); 146 change_processor_ = change_processor.get();
145 syncable_service_->MergeDataAndStartSyncing( 147 syncable_service_->MergeDataAndStartSyncing(
146 syncer::WIFI_CREDENTIALS, syncer::SyncDataList(), 148 syncer::WIFI_CREDENTIALS, syncer::SyncDataList(),
147 std::move(change_processor), 149 std::move(change_processor),
148 make_scoped_ptr(new SyncErrorFactoryMock())); 150 base::WrapUnique(new SyncErrorFactoryMock()));
149 } 151 }
150 152
151 private: 153 private:
152 scoped_ptr<WifiCredentialSyncableService> syncable_service_; 154 std::unique_ptr<WifiCredentialSyncableService> syncable_service_;
153 FakeWifiConfigDelegate* config_delegate_; // Owned by |syncable_service_| 155 FakeWifiConfigDelegate* config_delegate_; // Owned by |syncable_service_|
154 FakeSyncChangeProcessor* change_processor_; // Owned by |syncable_service_| 156 FakeSyncChangeProcessor* change_processor_; // Owned by |syncable_service_|
155 157
156 DISALLOW_COPY_AND_ASSIGN(WifiCredentialSyncableServiceTest); 158 DISALLOW_COPY_AND_ASSIGN(WifiCredentialSyncableServiceTest);
157 }; 159 };
158 160
159 } // namespace 161 } // namespace
160 162
161 TEST_F(WifiCredentialSyncableServiceTest, ProcessSyncChangesNotStarted) { 163 TEST_F(WifiCredentialSyncableServiceTest, ProcessSyncChangesNotStarted) {
162 syncer::SyncError sync_error(ProcessSyncChanges(syncer::SyncChangeList())); 164 syncer::SyncError sync_error(ProcessSyncChanges(syncer::SyncChangeList()));
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 MakeCredential(kSsidNonUtf8, SECURITY_CLASS_NONE, ""))); 335 MakeCredential(kSsidNonUtf8, SECURITY_CLASS_NONE, "")));
334 EXPECT_EQ(1, change_processor_changes_size()); 336 EXPECT_EQ(1, change_processor_changes_size());
335 EXPECT_FALSE( 337 EXPECT_FALSE(
336 AddToSyncedNetworks( 338 AddToSyncedNetworks(
337 "fake-item-id", 339 "fake-item-id",
338 MakeCredential(kSsidNonUtf8, SECURITY_CLASS_NONE, ""))); 340 MakeCredential(kSsidNonUtf8, SECURITY_CLASS_NONE, "")));
339 EXPECT_EQ(1, change_processor_changes_size()); 341 EXPECT_EQ(1, change_processor_changes_size());
340 } 342 }
341 343
342 } // namespace wifi_sync 344 } // namespace wifi_sync
OLDNEW
« no previous file with comments | « components/wifi_sync/wifi_credential_syncable_service_factory.cc ('k') | components/wifi_sync/wifi_credential_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698