OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/version.h" | 8 #include "base/version.h" |
9 #include "chrome/browser/sync/protocol/app_specifics.pb.h" | |
10 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | |
11 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
13 | 11 |
14 namespace { | 12 namespace { |
15 | 13 |
16 #if defined(OS_WIN) | |
17 const FilePath::CharType kExtensionFilePath[] = FILE_PATH_LITERAL("c:\\foo"); | |
18 #elif defined(OS_POSIX) | |
19 const FilePath::CharType kExtensionFilePath[] = FILE_PATH_LITERAL("/foo"); | |
20 #endif | |
21 | |
22 const char kValidId[] = "abcdefghijklmnopabcdefghijklmnop"; | |
23 const char kValidVersion[] = "0.0.0.0"; | |
24 const char kVersion1[] = "1.0.0.1"; | |
25 const char kVersion2[] = "1.0.1.0"; | |
26 const char kVersion3[] = "1.1.0.0"; | |
27 const char kValidUpdateUrl1[] = | |
28 "http://clients2.google.com/service/update2/crx"; | |
29 const char kValidUpdateUrl2[] = | |
30 "https://clients2.google.com/service/update2/crx"; | |
31 const char kName[] = "MyExtension"; | |
32 const char kName2[] = "MyExtension2"; | |
33 | |
34 class ExtensionSyncDataTest : public testing::Test { | 14 class ExtensionSyncDataTest : public testing::Test { |
35 }; | 15 }; |
36 | 16 |
37 TEST_F(ExtensionSyncDataTest, SyncDataToExtensionSyncData) { | 17 bool ExtensionSyncDataEqual(const ExtensionSyncData& a, |
38 sync_pb::EntitySpecifics entity; | 18 const ExtensionSyncData& b) { |
39 sync_pb::ExtensionSpecifics* extension_specifics = | 19 return |
40 entity.MutableExtension(sync_pb::extension); | 20 (a.id == b.id) && |
41 extension_specifics->set_id(kValidId); | 21 (a.enabled == b.enabled) && |
42 extension_specifics->set_update_url(kValidUpdateUrl2); | 22 (a.incognito_enabled == b.incognito_enabled) && |
43 extension_specifics->set_enabled(false); | 23 (a.version.Equals(b.version)) && |
44 extension_specifics->set_incognito_enabled(true); | 24 (a.update_url == b.update_url) && |
45 extension_specifics->set_version(kVersion1); | 25 (a.name == b.name); |
46 extension_specifics->set_name(kName); | |
47 SyncData sync_data = | |
48 SyncData::CreateLocalData("sync_tag", "non_unique_title", entity); | |
49 | |
50 ExtensionSyncData extension_sync_data(sync_data); | |
51 EXPECT_EQ(extension_specifics->id(), extension_sync_data.id()); | |
52 EXPECT_EQ(extension_specifics->version(), | |
53 extension_sync_data.version().GetString()); | |
54 EXPECT_EQ(extension_specifics->update_url(), | |
55 extension_sync_data.update_url().spec()); | |
56 EXPECT_EQ(extension_specifics->enabled(), extension_sync_data.enabled()); | |
57 EXPECT_EQ(extension_specifics->incognito_enabled(), | |
58 extension_sync_data.incognito_enabled()); | |
59 EXPECT_EQ(extension_specifics->name(), extension_sync_data.name()); | |
60 EXPECT_FALSE(extension_sync_data.uninstalled()); | |
61 } | 26 } |
62 | 27 |
63 TEST_F(ExtensionSyncDataTest, ExtensionSyncDataToSyncData) { | 28 TEST_F(ExtensionSyncDataTest, MergeOlder) { |
64 sync_pb::EntitySpecifics entity; | 29 ExtensionSyncData data; |
65 sync_pb::ExtensionSpecifics* input_extension = | 30 data.id = "id"; |
66 entity.MutableExtension(sync_pb::extension); | 31 data.enabled = true; |
67 input_extension->set_id(kValidId); | 32 data.incognito_enabled = false; |
68 input_extension->set_update_url(kValidUpdateUrl2); | 33 { |
69 input_extension->set_enabled(true); | 34 scoped_ptr<Version> version(Version::GetVersionFromString("1.2.0.0")); |
70 input_extension->set_incognito_enabled(false); | 35 data.version = *version; |
71 input_extension->set_version(kVersion1); | 36 } |
72 input_extension->set_name(kName); | 37 data.update_url = GURL("http://www.old.com"); |
73 SyncData sync_data = | 38 data.name = "data"; |
74 SyncData::CreateLocalData("sync_tag", "non_unique_title", entity); | |
75 ExtensionSyncData extension_sync_data(sync_data); | |
76 | 39 |
77 SyncData output_sync_data = extension_sync_data.GetSyncData(); | 40 ExtensionSyncData new_data; |
78 const sync_pb::ExtensionSpecifics& output_specifics = | 41 new_data.id = "id"; |
79 output_sync_data.GetSpecifics().GetExtension(sync_pb::extension); | 42 new_data.enabled = false; |
80 EXPECT_EQ(extension_sync_data.id(), output_specifics.id()); | 43 new_data.incognito_enabled = true; |
81 EXPECT_EQ(extension_sync_data.update_url().spec(), | 44 { |
82 output_specifics.update_url()); | 45 scoped_ptr<Version> version(Version::GetVersionFromString("1.1.0.0")); |
83 EXPECT_EQ(extension_sync_data.enabled(), output_specifics.enabled()); | 46 new_data.version = *version; |
84 EXPECT_EQ(extension_sync_data.incognito_enabled(), | 47 } |
85 output_specifics.incognito_enabled()); | 48 new_data.update_url = GURL("http://www.new.com"); |
86 EXPECT_EQ(extension_sync_data.version().GetString(), | 49 new_data.name = "new_data"; |
87 output_specifics.version()); | 50 |
88 EXPECT_EQ(extension_sync_data.name(), output_specifics.name()); | 51 ExtensionSyncData expected_data = data; |
| 52 expected_data.enabled = new_data.enabled; |
| 53 expected_data.incognito_enabled = new_data.incognito_enabled; |
| 54 |
| 55 data.Merge(new_data); |
| 56 EXPECT_TRUE(ExtensionSyncDataEqual(data, expected_data)); |
| 57 } |
| 58 |
| 59 TEST_F(ExtensionSyncDataTest, MergeNewer) { |
| 60 ExtensionSyncData data; |
| 61 data.id = "id"; |
| 62 data.enabled = true; |
| 63 data.incognito_enabled = false; |
| 64 { |
| 65 scoped_ptr<Version> version(Version::GetVersionFromString("1.2.0.0")); |
| 66 data.version = *version; |
| 67 } |
| 68 data.update_url = GURL("http://www.old.com"); |
| 69 data.name = "data"; |
| 70 |
| 71 ExtensionSyncData new_data; |
| 72 new_data.id = "id"; |
| 73 new_data.enabled = false; |
| 74 new_data.incognito_enabled = true; |
| 75 { |
| 76 scoped_ptr<Version> version(Version::GetVersionFromString("1.3.0.0")); |
| 77 new_data.version = *version; |
| 78 } |
| 79 new_data.update_url = GURL("http://www.new.com"); |
| 80 new_data.name = "new_data"; |
| 81 |
| 82 data.Merge(new_data); |
| 83 EXPECT_TRUE(ExtensionSyncDataEqual(data, new_data)); |
89 } | 84 } |
90 | 85 |
91 } // namespace | 86 } // namespace |
OLD | NEW |