Chromium Code Reviews| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 if (dictionary.GetString(path, &out)) { | 24 if (dictionary.GetString(path, &out)) { |
| 25 return (out == expected_value); | 25 return (out == expected_value); |
| 26 } | 26 } |
| 27 | 27 |
| 28 return false; | 28 return false; |
| 29 } | 29 } |
| 30 | 30 |
| 31 TEST(IdMappingHelperTest, SetIdsForDevices) { | 31 TEST(IdMappingHelperTest, SetIdsForDevices) { |
| 32 ScopedVector<DeviceInfo> devices; | 32 ScopedVector<DeviceInfo> devices; |
| 33 | 33 |
| 34 devices.push_back(new DeviceInfo( | 34 devices.push_back(new DeviceInfo(base::GenerateGUID(), |
| 35 base::GenerateGUID(), "abc Device", "XYZ v1", "XYZ SyncAgent v1", | 35 "abc Device", |
| 36 sync_pb::SyncEnums_DeviceType_TYPE_LINUX)); | 36 "XYZ v1", |
| 37 "XYZ SyncAgent v1", | |
| 38 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, | |
| 39 "device_id")); | |
|
rlarocque
2014/07/16 00:44:31
Not that it really matters, but would it be more r
pavely
2014/07/16 21:35:59
Done.
| |
| 37 | 40 |
| 38 devices.push_back(new DeviceInfo( | 41 devices.push_back(new DeviceInfo(base::GenerateGUID(), |
| 39 base::GenerateGUID(), "def Device", "XYZ v1", "XYZ SyncAgent v1", | 42 "def Device", |
| 40 sync_pb::SyncEnums_DeviceType_TYPE_LINUX)); | 43 "XYZ v1", |
| 44 "XYZ SyncAgent v1", | |
| 45 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, | |
| 46 "device_id")); | |
| 41 | 47 |
| 42 base::DictionaryValue dictionary; | 48 base::DictionaryValue dictionary; |
| 43 | 49 |
| 44 CreateMappingForUnmappedDevices(&(devices.get()), &dictionary); | 50 CreateMappingForUnmappedDevices(&(devices.get()), &dictionary); |
| 45 | 51 |
| 46 std::string public_id1 = devices[0]->public_id(); | 52 std::string public_id1 = devices[0]->public_id(); |
| 47 std::string public_id2 = devices[1]->public_id(); | 53 std::string public_id2 = devices[1]->public_id(); |
| 48 | 54 |
| 49 EXPECT_FALSE(public_id1.empty()); | 55 EXPECT_FALSE(public_id1.empty()); |
| 50 EXPECT_FALSE(public_id2.empty()); | 56 EXPECT_FALSE(public_id2.empty()); |
| 51 | 57 |
| 52 EXPECT_NE(public_id1, public_id2); | 58 EXPECT_NE(public_id1, public_id2); |
| 53 | 59 |
| 54 // Now add a third device. | 60 // Now add a third device. |
| 55 devices.push_back(new DeviceInfo( | 61 devices.push_back(new DeviceInfo(base::GenerateGUID(), |
| 56 base::GenerateGUID(), "ghi Device", "XYZ v1", "XYZ SyncAgent v1", | 62 "ghi Device", |
| 57 sync_pb::SyncEnums_DeviceType_TYPE_LINUX)); | 63 "XYZ v1", |
| 64 "XYZ SyncAgent v1", | |
| 65 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, | |
| 66 "device_id")); | |
| 58 | 67 |
| 59 CreateMappingForUnmappedDevices(&(devices.get()), &dictionary); | 68 CreateMappingForUnmappedDevices(&(devices.get()), &dictionary); |
| 60 | 69 |
| 61 // Now make sure the existing ids are not changed. | 70 // Now make sure the existing ids are not changed. |
| 62 EXPECT_EQ(public_id1, devices[0]->public_id()); | 71 EXPECT_EQ(public_id1, devices[0]->public_id()); |
| 63 EXPECT_EQ(public_id2, devices[1]->public_id()); | 72 EXPECT_EQ(public_id2, devices[1]->public_id()); |
| 64 | 73 |
| 65 // Now make sure the id for third device is non empty and different. | 74 // Now make sure the id for third device is non empty and different. |
| 66 std::string public_id3 = devices[2]->public_id(); | 75 std::string public_id3 = devices[2]->public_id(); |
| 67 EXPECT_FALSE(public_id3.empty()); | 76 EXPECT_FALSE(public_id3.empty()); |
| 68 EXPECT_NE(public_id3, public_id1); | 77 EXPECT_NE(public_id3, public_id1); |
| 69 EXPECT_NE(public_id3, public_id2); | 78 EXPECT_NE(public_id3, public_id2); |
| 70 | 79 |
| 71 // Verify the dictionary. | 80 // Verify the dictionary. |
| 72 EXPECT_TRUE(VerifyDictionary(public_id1, devices[0]->guid(), dictionary)); | 81 EXPECT_TRUE(VerifyDictionary(public_id1, devices[0]->guid(), dictionary)); |
| 73 EXPECT_TRUE(VerifyDictionary(public_id2, devices[1]->guid(), dictionary)); | 82 EXPECT_TRUE(VerifyDictionary(public_id2, devices[1]->guid(), dictionary)); |
| 74 EXPECT_TRUE(VerifyDictionary(public_id3, devices[2]->guid(), dictionary)); | 83 EXPECT_TRUE(VerifyDictionary(public_id3, devices[2]->guid(), dictionary)); |
| 75 | 84 |
| 76 EXPECT_EQ(dictionary.size(), 3U); | 85 EXPECT_EQ(dictionary.size(), 3U); |
| 77 } | 86 } |
| 78 } // namespace extensions | 87 } // namespace extensions |
| OLD | NEW |