OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/extensions/api/signed_in_devices/signed_in_devices_api.
h" | 5 #include "chrome/browser/extensions/api/signed_in_devices/signed_in_devices_api.
h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 ~MockDeviceInfoTracker() override {} | 37 ~MockDeviceInfoTracker() override {} |
38 | 38 |
39 bool IsSyncing() const override { return !devices_.empty(); } | 39 bool IsSyncing() const override { return !devices_.empty(); } |
40 | 40 |
41 std::unique_ptr<DeviceInfo> GetDeviceInfo( | 41 std::unique_ptr<DeviceInfo> GetDeviceInfo( |
42 const std::string& client_id) const override { | 42 const std::string& client_id) const override { |
43 NOTREACHED(); | 43 NOTREACHED(); |
44 return std::unique_ptr<DeviceInfo>(); | 44 return std::unique_ptr<DeviceInfo>(); |
45 } | 45 } |
46 | 46 |
47 static DeviceInfo* CloneDeviceInfo(const DeviceInfo* device_info) { | 47 static std::unique_ptr<DeviceInfo> CloneDeviceInfo( |
48 return new DeviceInfo(device_info->guid(), | 48 const DeviceInfo& device_info) { |
49 device_info->client_name(), | 49 return base::MakeUnique<DeviceInfo>( |
50 device_info->chrome_version(), | 50 device_info.guid(), device_info.client_name(), |
51 device_info->sync_user_agent(), | 51 device_info.chrome_version(), device_info.sync_user_agent(), |
52 device_info->device_type(), | 52 device_info.device_type(), device_info.signin_scoped_device_id()); |
53 device_info->signin_scoped_device_id()); | |
54 } | 53 } |
55 | 54 |
56 ScopedVector<DeviceInfo> GetAllDeviceInfo() const override { | 55 std::vector<std::unique_ptr<DeviceInfo>> GetAllDeviceInfo() const override { |
57 ScopedVector<DeviceInfo> list; | 56 std::vector<std::unique_ptr<DeviceInfo>> list; |
58 | 57 |
59 for (std::vector<const DeviceInfo*>::const_iterator iter = devices_.begin(); | 58 for (const DeviceInfo* device : devices_) |
60 iter != devices_.end(); | 59 list.push_back(CloneDeviceInfo(*device)); |
61 ++iter) { | |
62 list.push_back(CloneDeviceInfo(*iter)); | |
63 } | |
64 | 60 |
65 return list; | 61 return list; |
66 } | 62 } |
67 | 63 |
68 void AddObserver(Observer* observer) override { NOTREACHED(); } | 64 void AddObserver(Observer* observer) override { NOTREACHED(); } |
69 | 65 |
70 void RemoveObserver(Observer* observer) override { NOTREACHED(); } | 66 void RemoveObserver(Observer* observer) override { NOTREACHED(); } |
71 | 67 |
72 int CountActiveDevices() const override { | 68 int CountActiveDevices() const override { |
73 NOTREACHED(); | 69 NOTREACHED(); |
(...skipping 28 matching lines...) Expand all Loading... |
102 DeviceInfo device_info2(base::GenerateGUID(), | 98 DeviceInfo device_info2(base::GenerateGUID(), |
103 "def Device", | 99 "def Device", |
104 "XYZ v2", | 100 "XYZ v2", |
105 "XYZ SyncAgent v2", | 101 "XYZ SyncAgent v2", |
106 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, | 102 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, |
107 "device_id"); | 103 "device_id"); |
108 | 104 |
109 device_tracker.Add(&device_info1); | 105 device_tracker.Add(&device_info1); |
110 device_tracker.Add(&device_info2); | 106 device_tracker.Add(&device_info2); |
111 | 107 |
112 ScopedVector<DeviceInfo> output1 = GetAllSignedInDevices( | 108 std::vector<std::unique_ptr<DeviceInfo>> output1 = GetAllSignedInDevices( |
113 extension_test->id(), &device_tracker, extension_prefs.prefs()); | 109 extension_test->id(), &device_tracker, extension_prefs.prefs()); |
114 | 110 |
115 std::string public_id1 = output1[0]->public_id(); | 111 std::string public_id1 = output1[0]->public_id(); |
116 std::string public_id2 = output1[1]->public_id(); | 112 std::string public_id2 = output1[1]->public_id(); |
117 | 113 |
118 EXPECT_FALSE(public_id1.empty()); | 114 EXPECT_FALSE(public_id1.empty()); |
119 EXPECT_FALSE(public_id2.empty()); | 115 EXPECT_FALSE(public_id2.empty()); |
120 EXPECT_NE(public_id1, public_id2); | 116 EXPECT_NE(public_id1, public_id2); |
121 | 117 |
122 // Add a third device and make sure the first 2 ids are retained and a new | 118 // Add a third device and make sure the first 2 ids are retained and a new |
123 // id is generated for the third device. | 119 // id is generated for the third device. |
124 DeviceInfo device_info3(base::GenerateGUID(), | 120 DeviceInfo device_info3(base::GenerateGUID(), |
125 "def Device", | 121 "def Device", |
126 "jkl v2", | 122 "jkl v2", |
127 "XYZ SyncAgent v2", | 123 "XYZ SyncAgent v2", |
128 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, | 124 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, |
129 "device_id"); | 125 "device_id"); |
130 | 126 |
131 device_tracker.Add(&device_info3); | 127 device_tracker.Add(&device_info3); |
132 | 128 |
133 ScopedVector<DeviceInfo> output2 = GetAllSignedInDevices( | 129 std::vector<std::unique_ptr<DeviceInfo>> output2 = GetAllSignedInDevices( |
134 extension_test->id(), &device_tracker, extension_prefs.prefs()); | 130 extension_test->id(), &device_tracker, extension_prefs.prefs()); |
135 | 131 |
136 EXPECT_EQ(output2[0]->public_id(), public_id1); | 132 EXPECT_EQ(output2[0]->public_id(), public_id1); |
137 EXPECT_EQ(output2[1]->public_id(), public_id2); | 133 EXPECT_EQ(output2[1]->public_id(), public_id2); |
138 | 134 |
139 std::string public_id3 = output2[2]->public_id(); | 135 std::string public_id3 = output2[2]->public_id(); |
140 EXPECT_FALSE(public_id3.empty()); | 136 EXPECT_FALSE(public_id3.empty()); |
141 EXPECT_NE(public_id3, public_id1); | 137 EXPECT_NE(public_id3, public_id1); |
142 EXPECT_NE(public_id3, public_id2); | 138 EXPECT_NE(public_id3, public_id2); |
143 } | 139 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 ProfileSyncServiceMockForExtensionTests* pss_mock = | 243 ProfileSyncServiceMockForExtensionTests* pss_mock = |
248 static_cast<ProfileSyncServiceMockForExtensionTests*>( | 244 static_cast<ProfileSyncServiceMockForExtensionTests*>( |
249 ProfileSyncServiceFactory::GetForProfile(profile())); | 245 ProfileSyncServiceFactory::GetForProfile(profile())); |
250 | 246 |
251 MockDeviceInfoTracker device_tracker; | 247 MockDeviceInfoTracker device_tracker; |
252 | 248 |
253 EXPECT_CALL(*pss_mock, GetDeviceInfoTracker()) | 249 EXPECT_CALL(*pss_mock, GetDeviceInfoTracker()) |
254 .WillOnce(Return(&device_tracker)); | 250 .WillOnce(Return(&device_tracker)); |
255 EXPECT_CALL(*pss_mock, Shutdown()); | 251 EXPECT_CALL(*pss_mock, Shutdown()); |
256 | 252 |
257 ScopedVector<DeviceInfo> output = GetAllSignedInDevices( | 253 std::vector<std::unique_ptr<DeviceInfo>> output = |
258 extension()->id(), profile()); | 254 GetAllSignedInDevices(extension()->id(), profile()); |
259 | 255 |
260 EXPECT_TRUE(output.empty()); | 256 EXPECT_TRUE(output.empty()); |
261 } | 257 } |
262 | 258 |
263 } // namespace extensions | 259 } // namespace extensions |
OLD | NEW |