OLD | NEW |
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 "chrome/browser/extensions/extension_sync_data.h" | 5 #include "chrome/browser/extensions/extension_sync_data.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/version.h" | 9 #include "base/version.h" |
10 #include "sync/protocol/extension_specifics.pb.h" | 10 #include "sync/protocol/extension_specifics.pb.h" |
11 #include "sync/protocol/sync.pb.h" | 11 #include "sync/protocol/sync.pb.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
14 | 14 |
15 namespace extensions { | 15 namespace extensions { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 const char kValidId[] = "abcdefghijklmnopabcdefghijklmnop"; | 19 const char kValidId[] = "abcdefghijklmnopabcdefghijklmnop"; |
20 const char kVersion[] = "1.0.0.1"; | 20 const char kVersion[] = "1.0.0.1"; |
21 const char kValidUpdateUrl[] = | 21 const char kValidUpdateUrl[] = |
22 "https://clients2.google.com/service/update2/crx"; | 22 "https://clients2.google.com/service/update2/crx"; |
23 const char kName[] = "MyExtension"; | 23 const char kName[] = "MyExtension"; |
24 | 24 |
25 // Serializes a protobuf structure (entity specifics) into an ExtensionSyncData | 25 // Serializes a protobuf structure (entity specifics) into an ExtensionSyncData |
26 // and back again, and confirms that the input is the same as the output. | 26 // and back again, and confirms that the input is the same as the output. |
27 void ProtobufToSyncDataEqual(const sync_pb::EntitySpecifics& entity) { | 27 void ProtobufToSyncDataEqual(const sync_pb::EntitySpecifics& entity) { |
28 syncer::SyncData sync_data = | 28 syncer::SyncData sync_data = |
29 syncer::SyncData::CreateLocalData("sync_tag", "non_unique_title", entity); | 29 syncer::SyncData::CreateLocalData("sync_tag", "non_unique_title", entity); |
30 ExtensionSyncData extension_sync_data(sync_data); | 30 scoped_ptr<ExtensionSyncData> extension_sync_data = |
31 syncer::SyncData output_sync_data = extension_sync_data.GetSyncData(); | 31 ExtensionSyncData::CreateFromSyncData(sync_data); |
| 32 ASSERT_TRUE(extension_sync_data.get()); |
| 33 syncer::SyncData output_sync_data = extension_sync_data->GetSyncData(); |
32 const sync_pb::ExtensionSpecifics& output = | 34 const sync_pb::ExtensionSpecifics& output = |
33 output_sync_data.GetSpecifics().extension(); | 35 output_sync_data.GetSpecifics().extension(); |
34 const sync_pb::ExtensionSpecifics& input = entity.extension(); | 36 const sync_pb::ExtensionSpecifics& input = entity.extension(); |
35 | 37 |
36 // Check for field-by-field quality. It'd be nice if we could use | 38 // Check for field-by-field quality. It'd be nice if we could use |
37 // AssertionResults here (instead of EXPECT_EQ) so that we could get valid | 39 // AssertionResults here (instead of EXPECT_EQ) so that we could get valid |
38 // line numbers, but it's not worth the ugliness of the verbose comparison. | 40 // line numbers, but it's not worth the ugliness of the verbose comparison. |
39 EXPECT_EQ(input.id(), output.id()); | 41 EXPECT_EQ(input.id(), output.id()); |
40 EXPECT_EQ(input.name(), output.name()); | 42 EXPECT_EQ(input.name(), output.name()); |
41 EXPECT_EQ(input.version(), output.version()); | 43 EXPECT_EQ(input.version(), output.version()); |
42 EXPECT_EQ(input.update_url(), output.update_url()); | 44 EXPECT_EQ(input.update_url(), output.update_url()); |
43 EXPECT_EQ(input.enabled(), output.enabled()); | 45 EXPECT_EQ(input.enabled(), output.enabled()); |
44 EXPECT_EQ(input.incognito_enabled(), output.incognito_enabled()); | 46 EXPECT_EQ(input.incognito_enabled(), output.incognito_enabled()); |
45 EXPECT_EQ(input.remote_install(), output.remote_install()); | 47 EXPECT_EQ(input.remote_install(), output.remote_install()); |
46 EXPECT_EQ(input.installed_by_custodian(), output.installed_by_custodian()); | 48 EXPECT_EQ(input.installed_by_custodian(), output.installed_by_custodian()); |
47 EXPECT_EQ(input.has_all_urls_enabled(), output.has_all_urls_enabled()); | 49 EXPECT_EQ(input.has_all_urls_enabled(), output.has_all_urls_enabled()); |
48 if (input.has_all_urls_enabled()) | 50 if (input.has_all_urls_enabled()) |
49 EXPECT_EQ(input.all_urls_enabled(), output.all_urls_enabled()); | 51 EXPECT_EQ(input.all_urls_enabled(), output.all_urls_enabled()); |
50 } | 52 } |
51 | 53 |
52 // Serializes an ExtensionSyncData into a protobuf structure and back again, and | 54 // Serializes an ExtensionSyncData into a protobuf structure and back again, and |
53 // confirms that the input is the same as the output. | 55 // confirms that the input is the same as the output. |
54 void SyncDataToProtobufEqual(const ExtensionSyncData& input) { | 56 void SyncDataToProtobufEqual(const ExtensionSyncData& input) { |
55 syncer::SyncData sync_data = input.GetSyncData(); | 57 syncer::SyncData sync_data = input.GetSyncData(); |
56 ExtensionSyncData output(sync_data); | 58 scoped_ptr<ExtensionSyncData> output = |
| 59 ExtensionSyncData::CreateFromSyncData(sync_data); |
| 60 ASSERT_TRUE(output.get()); |
57 | 61 |
58 EXPECT_EQ(input.id(), output.id()); | 62 EXPECT_EQ(input.id(), output->id()); |
59 EXPECT_EQ(input.uninstalled(), output.uninstalled()); | 63 EXPECT_EQ(input.uninstalled(), output->uninstalled()); |
60 EXPECT_EQ(input.enabled(), output.enabled()); | 64 EXPECT_EQ(input.enabled(), output->enabled()); |
61 EXPECT_EQ(input.incognito_enabled(), output.incognito_enabled()); | 65 EXPECT_EQ(input.incognito_enabled(), output->incognito_enabled()); |
62 EXPECT_EQ(input.remote_install(), output.remote_install()); | 66 EXPECT_EQ(input.remote_install(), output->remote_install()); |
63 EXPECT_EQ(input.installed_by_custodian(), output.installed_by_custodian()); | 67 EXPECT_EQ(input.installed_by_custodian(), output->installed_by_custodian()); |
64 EXPECT_EQ(input.all_urls_enabled(), output.all_urls_enabled()); | 68 EXPECT_EQ(input.all_urls_enabled(), output->all_urls_enabled()); |
65 EXPECT_TRUE(input.version().Equals(output.version())); | 69 EXPECT_TRUE(input.version().Equals(output->version())); |
66 EXPECT_EQ(input.update_url(), output.update_url()); | 70 EXPECT_EQ(input.update_url(), output->update_url()); |
67 EXPECT_EQ(input.name(), output.name()); | 71 EXPECT_EQ(input.name(), output->name()); |
68 } | 72 } |
69 | 73 |
70 } // namespace | 74 } // namespace |
71 | 75 |
72 class ExtensionSyncDataTest : public testing::Test { | 76 class ExtensionSyncDataTest : public testing::Test { |
73 }; | 77 }; |
74 | 78 |
75 // Tests the conversion process from a protobuf to an ExtensionSyncData and vice | 79 // Tests the conversion process from a protobuf to an ExtensionSyncData and vice |
76 // versa. | 80 // versa. |
77 TEST_F(ExtensionSyncDataTest, ExtensionSyncDataForExtension) { | 81 TEST_F(ExtensionSyncDataTest, ExtensionSyncDataForExtension) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 131 |
128 extension_sync_data.PopulateFromExtensionSpecifics(*extension_specifics); | 132 extension_sync_data.PopulateFromExtensionSpecifics(*extension_specifics); |
129 EXPECT_FALSE(extension_specifics->has_all_urls_enabled()); | 133 EXPECT_FALSE(extension_specifics->has_all_urls_enabled()); |
130 EXPECT_EQ(ExtensionSyncData::BOOLEAN_UNSET, | 134 EXPECT_EQ(ExtensionSyncData::BOOLEAN_UNSET, |
131 extension_sync_data.all_urls_enabled()); | 135 extension_sync_data.all_urls_enabled()); |
132 | 136 |
133 SyncDataToProtobufEqual(extension_sync_data); | 137 SyncDataToProtobufEqual(extension_sync_data); |
134 } | 138 } |
135 | 139 |
136 } // namespace extensions | 140 } // namespace extensions |
OLD | NEW |