OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/sync/glue/extension_util.h" | 5 #include "chrome/browser/sync/glue/extension_util.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 9 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 const char kValidUpdateUrl1[] = | 29 const char kValidUpdateUrl1[] = |
30 "http://clients2.google.com/service/update2/crx"; | 30 "http://clients2.google.com/service/update2/crx"; |
31 const char kValidUpdateUrl2[] = | 31 const char kValidUpdateUrl2[] = |
32 "https://clients2.google.com/service/update2/crx"; | 32 "https://clients2.google.com/service/update2/crx"; |
33 const char kName[] = "MyExtension"; | 33 const char kName[] = "MyExtension"; |
34 const char kName2[] = "MyExtension2"; | 34 const char kName2[] = "MyExtension2"; |
35 | 35 |
36 class ExtensionUtilTest : public testing::Test { | 36 class ExtensionUtilTest : public testing::Test { |
37 }; | 37 }; |
38 | 38 |
39 void MakePossiblySyncableExtension(bool is_theme, | 39 void MakeExtension(bool is_theme, const GURL& update_url, |
40 const GURL& update_url, | 40 const GURL& launch_url, bool converted_from_user_script, |
41 const GURL& launch_url, | 41 Extension::Location location, int num_plugins, |
42 bool converted_from_user_script, | 42 Extension* extension) { |
43 Extension::Location location, | |
44 int num_plugins, | |
45 Extension* extension) { | |
46 DictionaryValue source; | 43 DictionaryValue source; |
47 source.SetString(extension_manifest_keys::kName, | 44 source.SetString(extension_manifest_keys::kName, |
48 "PossiblySyncableExtension"); | 45 "PossiblySyncableExtension"); |
49 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); | 46 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); |
50 if (is_theme) { | 47 if (is_theme) { |
51 source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); | 48 source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); |
52 } | 49 } |
53 if (!update_url.is_empty()) { | 50 if (!update_url.is_empty()) { |
54 source.SetString(extension_manifest_keys::kUpdateURL, | 51 source.SetString(extension_manifest_keys::kUpdateURL, |
55 update_url.spec()); | 52 update_url.spec()); |
(...skipping 12 matching lines...) Expand all Loading... |
68 plugins->Set(i, plugin); | 65 plugins->Set(i, plugin); |
69 } | 66 } |
70 source.Set(extension_manifest_keys::kPlugins, plugins); | 67 source.Set(extension_manifest_keys::kPlugins, plugins); |
71 } | 68 } |
72 std::string error; | 69 std::string error; |
73 EXPECT_TRUE(extension->InitFromValue(source, false, &error)); | 70 EXPECT_TRUE(extension->InitFromValue(source, false, &error)); |
74 EXPECT_EQ("", error); | 71 EXPECT_EQ("", error); |
75 extension->set_location(location); | 72 extension->set_location(location); |
76 } | 73 } |
77 | 74 |
78 TEST_F(ExtensionUtilTest, IsSyncableExtension) { | 75 TEST_F(ExtensionUtilTest, GetExtensionType) { |
79 { | 76 { |
80 FilePath file_path(kExtensionFilePath); | 77 FilePath file_path(kExtensionFilePath); |
81 Extension extension(file_path); | 78 Extension extension(file_path); |
82 MakePossiblySyncableExtension(false, GURL(), GURL(), false, | 79 MakeExtension(false, GURL(), GURL(), false, |
83 Extension::INTERNAL, 0, &extension); | 80 Extension::INTERNAL, 0, &extension); |
84 EXPECT_TRUE(IsExtensionSyncable(extension)); | 81 EXPECT_EQ(EXTENSION, GetExtensionType(extension)); |
85 } | 82 } |
86 { | 83 { |
87 FilePath file_path(kExtensionFilePath); | 84 FilePath file_path(kExtensionFilePath); |
88 Extension extension(file_path); | 85 Extension extension(file_path); |
89 MakePossiblySyncableExtension(false, GURL(kValidUpdateUrl1), GURL(), | 86 MakeExtension(true, GURL(), GURL(), false, |
90 true, Extension::INTERNAL, 0, &extension); | 87 Extension::INTERNAL, 0, &extension); |
91 EXPECT_TRUE(IsExtensionSyncable(extension)); | 88 EXPECT_EQ(THEME, GetExtensionType(extension)); |
92 } | 89 } |
93 { | 90 { |
94 FilePath file_path(kExtensionFilePath); | 91 FilePath file_path(kExtensionFilePath); |
95 Extension extension(file_path); | 92 Extension extension(file_path); |
96 MakePossiblySyncableExtension(false, GURL(), GURL(), true, | 93 MakeExtension(false, GURL(), GURL(), true, |
97 Extension::INTERNAL, 0, &extension); | 94 Extension::INTERNAL, 0, &extension); |
98 EXPECT_TRUE(IsExtensionSyncable(extension)); | 95 EXPECT_EQ(USER_SCRIPT, GetExtensionType(extension)); |
99 } | 96 } |
100 { | 97 { |
101 FilePath file_path(kExtensionFilePath); | 98 FilePath file_path(kExtensionFilePath); |
102 Extension extension(file_path); | 99 Extension extension(file_path); |
103 MakePossiblySyncableExtension(true, GURL(), GURL(), false, | 100 MakeExtension(false, GURL(), |
104 Extension::INTERNAL, 0, &extension); | 101 GURL("http://www.google.com"), false, |
105 EXPECT_FALSE(IsExtensionSyncable(extension)); | 102 Extension::INTERNAL, 0, &extension); |
| 103 EXPECT_EQ(APP, GetExtensionType(extension)); |
106 } | 104 } |
107 // TODO(akalin): Test with a non-empty launch_url once apps are | 105 } |
108 // enabled by default. | 106 |
| 107 TEST_F(ExtensionUtilTest, IsExtensionValid) { |
109 { | 108 { |
110 FilePath file_path(kExtensionFilePath); | 109 FilePath file_path(kExtensionFilePath); |
111 Extension extension(file_path); | 110 Extension extension(file_path); |
112 MakePossiblySyncableExtension(false, GURL(), GURL(), false, | 111 MakeExtension(false, GURL(), GURL(), false, |
113 Extension::EXTERNAL_PREF, 0, &extension); | 112 Extension::INTERNAL, 0, &extension); |
114 EXPECT_FALSE(IsExtensionSyncable(extension)); | 113 EXPECT_TRUE(IsExtensionValid(extension)); |
115 } | 114 } |
116 { | 115 { |
117 FilePath file_path(kExtensionFilePath); | 116 FilePath file_path(kExtensionFilePath); |
118 Extension extension(file_path); | 117 Extension extension(file_path); |
119 MakePossiblySyncableExtension( | 118 MakeExtension(false, GURL(kValidUpdateUrl1), GURL(), |
120 false, GURL("http://third-party.update_url.com"), GURL(), true, | 119 true, Extension::INTERNAL, 0, &extension); |
121 Extension::INTERNAL, 0, &extension); | 120 EXPECT_TRUE(IsExtensionValid(extension)); |
122 EXPECT_FALSE(IsExtensionSyncable(extension)); | |
123 } | 121 } |
124 { | 122 { |
125 FilePath file_path(kExtensionFilePath); | 123 FilePath file_path(kExtensionFilePath); |
126 Extension extension(file_path); | 124 Extension extension(file_path); |
127 MakePossiblySyncableExtension(false, GURL(), GURL(), true, | 125 MakeExtension(false, GURL(), GURL(), true, |
128 Extension::INTERNAL, 1, &extension); | 126 Extension::INTERNAL, 0, &extension); |
129 EXPECT_FALSE(IsExtensionSyncable(extension)); | 127 EXPECT_TRUE(IsExtensionValid(extension)); |
130 } | 128 } |
131 { | 129 { |
132 FilePath file_path(kExtensionFilePath); | 130 FilePath file_path(kExtensionFilePath); |
133 Extension extension(file_path); | 131 Extension extension(file_path); |
134 MakePossiblySyncableExtension(false, GURL(), GURL(), true, | 132 MakeExtension(true, GURL(), GURL(), false, |
135 Extension::INTERNAL, 2, &extension); | 133 Extension::INTERNAL, 0, &extension); |
136 EXPECT_FALSE(IsExtensionSyncable(extension)); | 134 EXPECT_TRUE(IsExtensionValid(extension)); |
| 135 } |
| 136 { |
| 137 FilePath file_path(kExtensionFilePath); |
| 138 Extension extension(file_path); |
| 139 MakeExtension(false, GURL(), |
| 140 GURL("http://www.google.com"), false, |
| 141 Extension::INTERNAL, 0, &extension); |
| 142 EXPECT_TRUE(IsExtensionValid(extension)); |
| 143 } |
| 144 { |
| 145 FilePath file_path(kExtensionFilePath); |
| 146 Extension extension(file_path); |
| 147 MakeExtension(false, GURL(), GURL(), false, |
| 148 Extension::EXTERNAL_PREF, 0, &extension); |
| 149 EXPECT_FALSE(IsExtensionValid(extension)); |
| 150 } |
| 151 { |
| 152 FilePath file_path(kExtensionFilePath); |
| 153 Extension extension(file_path); |
| 154 MakeExtension( |
| 155 false, GURL("http://third-party.update_url.com"), GURL(), true, |
| 156 Extension::INTERNAL, 0, &extension); |
| 157 EXPECT_FALSE(IsExtensionValid(extension)); |
| 158 } |
| 159 { |
| 160 FilePath file_path(kExtensionFilePath); |
| 161 Extension extension(file_path); |
| 162 MakeExtension(false, GURL(), GURL(), true, |
| 163 Extension::INTERNAL, 1, &extension); |
| 164 EXPECT_FALSE(IsExtensionValid(extension)); |
| 165 } |
| 166 { |
| 167 FilePath file_path(kExtensionFilePath); |
| 168 Extension extension(file_path); |
| 169 MakeExtension(false, GURL(), GURL(), true, |
| 170 Extension::INTERNAL, 2, &extension); |
| 171 EXPECT_FALSE(IsExtensionValid(extension)); |
137 } | 172 } |
138 } | 173 } |
139 | 174 |
| 175 TEST_F(ExtensionUtilTest, IsExtensionValidAndSyncable) { |
| 176 ExtensionTypeSet allowed_extension_types; |
| 177 allowed_extension_types.insert(EXTENSION); |
| 178 allowed_extension_types.insert(APP); |
| 179 { |
| 180 FilePath file_path(kExtensionFilePath); |
| 181 Extension extension(file_path); |
| 182 MakeExtension(false, GURL(), GURL(), false, |
| 183 Extension::INTERNAL, 0, &extension); |
| 184 EXPECT_TRUE(IsExtensionValidAndSyncable( |
| 185 extension, allowed_extension_types)); |
| 186 } |
| 187 { |
| 188 FilePath file_path(kExtensionFilePath); |
| 189 Extension extension(file_path); |
| 190 MakeExtension(false, GURL(), |
| 191 GURL("http://www.google.com"), false, |
| 192 Extension::INTERNAL, 0, &extension); |
| 193 EXPECT_TRUE(IsExtensionValidAndSyncable( |
| 194 extension, allowed_extension_types)); |
| 195 } |
| 196 { |
| 197 FilePath file_path(kExtensionFilePath); |
| 198 Extension extension(file_path); |
| 199 MakeExtension(false, GURL(), GURL(), true, |
| 200 Extension::INTERNAL, 0, &extension); |
| 201 EXPECT_FALSE(IsExtensionValidAndSyncable( |
| 202 extension, allowed_extension_types)); |
| 203 } |
| 204 { |
| 205 FilePath file_path(kExtensionFilePath); |
| 206 Extension extension(file_path); |
| 207 MakeExtension(false, GURL(), GURL(), false, |
| 208 Extension::EXTERNAL_PREF, 0, &extension); |
| 209 EXPECT_FALSE(IsExtensionValidAndSyncable( |
| 210 extension, allowed_extension_types)); |
| 211 } |
| 212 } |
| 213 |
| 214 |
140 TEST_F(ExtensionUtilTest, IsExtensionSpecificsUnset) { | 215 TEST_F(ExtensionUtilTest, IsExtensionSpecificsUnset) { |
141 { | 216 { |
142 sync_pb::ExtensionSpecifics specifics; | 217 sync_pb::ExtensionSpecifics specifics; |
143 EXPECT_TRUE(IsExtensionSpecificsUnset(specifics)); | 218 EXPECT_TRUE(IsExtensionSpecificsUnset(specifics)); |
144 } | 219 } |
145 | 220 |
146 { | 221 { |
147 sync_pb::ExtensionSpecifics specifics; | 222 sync_pb::ExtensionSpecifics specifics; |
148 specifics.set_id("a"); | 223 specifics.set_id("a"); |
149 EXPECT_FALSE(IsExtensionSpecificsUnset(specifics)); | 224 EXPECT_FALSE(IsExtensionSpecificsUnset(specifics)); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 { | 541 { |
467 sync_pb::ExtensionSpecifics result = merged_specifics; | 542 sync_pb::ExtensionSpecifics result = merged_specifics; |
468 MergeExtensionSpecifics(specifics, true, &result); | 543 MergeExtensionSpecifics(specifics, true, &result); |
469 EXPECT_TRUE(AreExtensionSpecificsEqual(result, specifics)); | 544 EXPECT_TRUE(AreExtensionSpecificsEqual(result, specifics)); |
470 } | 545 } |
471 } | 546 } |
472 | 547 |
473 } // namespace | 548 } // namespace |
474 | 549 |
475 } // namespace browser_sync | 550 } // namespace browser_sync |
OLD | NEW |