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/version.h" | 9 #include "base/version.h" |
9 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 10 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
10 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
11 #include "chrome/common/extensions/extension_constants.h" | 12 #include "chrome/common/extensions/extension_constants.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 namespace browser_sync { | 15 namespace browser_sync { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
19 const FilePath::CharType kExtensionFilePath[] = FILE_PATH_LITERAL("c:\\foo"); | 20 const FilePath::CharType kExtensionFilePath[] = FILE_PATH_LITERAL("c:\\foo"); |
20 #elif defined(OS_POSIX) | 21 #elif defined(OS_POSIX) |
21 const FilePath::CharType kExtensionFilePath[] = FILE_PATH_LITERAL("/foo"); | 22 const FilePath::CharType kExtensionFilePath[] = FILE_PATH_LITERAL("/foo"); |
22 #endif | 23 #endif |
23 | 24 |
24 const char kValidId[] = "abcdefghijklmnopabcdefghijklmnop"; | 25 const char kValidId[] = "abcdefghijklmnopabcdefghijklmnop"; |
25 const char kValidVersion[] = "0.0.0.0"; | 26 const char kValidVersion[] = "0.0.0.0"; |
26 const char kVersion1[] = "1.0.0.1"; | 27 const char kVersion1[] = "1.0.0.1"; |
27 const char kVersion2[] = "1.0.1.0"; | 28 const char kVersion2[] = "1.0.1.0"; |
28 const char kVersion3[] = "1.1.0.0"; | 29 const char kVersion3[] = "1.1.0.0"; |
29 const char kValidUpdateUrl[] = "http://www.google.com/"; | 30 const char kValidUpdateUrl1[] = |
30 const char kValidUpdateUrl1[] = "http://www.1.com/"; | 31 "http://clients2.google.com/service/update2/crx"; |
31 const char kValidUpdateUrl2[] = "http://www.2.com/"; | 32 const char kValidUpdateUrl2[] = |
| 33 "https://clients2.google.com/service/update2/crx"; |
32 const char kName[] = "MyExtension"; | 34 const char kName[] = "MyExtension"; |
33 const char kName2[] = "MyExtension2"; | 35 const char kName2[] = "MyExtension2"; |
34 | 36 |
35 class ExtensionUtilTest : public testing::Test { | 37 class ExtensionUtilTest : public testing::Test { |
36 }; | 38 }; |
37 | 39 |
38 void MakePossiblySyncableExtension(bool is_theme, | 40 void MakePossiblySyncableExtension(bool is_theme, |
| 41 const GURL& update_url, |
39 const GURL& launch_url, | 42 const GURL& launch_url, |
40 bool converted_from_user_script, | 43 bool converted_from_user_script, |
41 Extension::Location location, | 44 Extension::Location location, |
| 45 int num_plugins, |
42 Extension* extension) { | 46 Extension* extension) { |
43 DictionaryValue source; | 47 DictionaryValue source; |
44 source.SetString(extension_manifest_keys::kName, | 48 source.SetString(extension_manifest_keys::kName, |
45 "PossiblySyncableExtension"); | 49 "PossiblySyncableExtension"); |
46 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); | 50 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); |
47 if (is_theme) { | 51 if (is_theme) { |
48 source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); | 52 source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); |
49 } | 53 } |
| 54 if (!update_url.is_empty()) { |
| 55 source.SetString(extension_manifest_keys::kUpdateURL, |
| 56 update_url.spec()); |
| 57 } |
50 if (!launch_url.is_empty()) { | 58 if (!launch_url.is_empty()) { |
51 source.SetString(extension_manifest_keys::kLaunchWebURL, | 59 source.SetString(extension_manifest_keys::kLaunchWebURL, |
52 launch_url.spec()); | 60 launch_url.spec()); |
53 } | 61 } |
54 if (!is_theme) { | 62 if (!is_theme) { |
55 source.SetBoolean(extension_manifest_keys::kConvertedFromUserScript, | 63 source.SetBoolean(extension_manifest_keys::kConvertedFromUserScript, |
56 converted_from_user_script); | 64 converted_from_user_script); |
| 65 ListValue* plugins = new ListValue(); |
| 66 for (int i = 0; i < num_plugins; ++i) { |
| 67 DictionaryValue* plugin = new DictionaryValue(); |
| 68 plugin->SetString(extension_manifest_keys::kPluginsPath, ""); |
| 69 plugins->Set(i, plugin); |
| 70 } |
| 71 source.Set(extension_manifest_keys::kPlugins, plugins); |
57 } | 72 } |
58 std::string error; | 73 std::string error; |
59 EXPECT_TRUE(extension->InitFromValue(source, false, &error)); | 74 EXPECT_TRUE(extension->InitFromValue(source, false, &error)); |
60 EXPECT_EQ("", error); | 75 EXPECT_EQ("", error); |
61 extension->set_location(location); | 76 extension->set_location(location); |
62 } | 77 } |
63 | 78 |
64 TEST_F(ExtensionUtilTest, IsSyncableExtension) { | 79 TEST_F(ExtensionUtilTest, IsSyncableExtension) { |
65 { | 80 { |
66 FilePath file_path(kExtensionFilePath); | 81 FilePath file_path(kExtensionFilePath); |
67 Extension extension(file_path); | 82 Extension extension(file_path); |
68 MakePossiblySyncableExtension(false, GURL(), false, | 83 MakePossiblySyncableExtension(false, GURL(), GURL(), false, |
69 Extension::INTERNAL, &extension); | 84 Extension::INTERNAL, 0, &extension); |
70 EXPECT_TRUE(IsExtensionSyncable(extension)); | 85 EXPECT_TRUE(IsExtensionSyncable(extension)); |
71 } | 86 } |
72 { | 87 { |
73 FilePath file_path(kExtensionFilePath); | 88 FilePath file_path(kExtensionFilePath); |
74 Extension extension(file_path); | 89 Extension extension(file_path); |
75 MakePossiblySyncableExtension(false, GURL(), true, | 90 MakePossiblySyncableExtension(false, GURL(kValidUpdateUrl1), GURL(), |
76 Extension::INTERNAL, &extension); | 91 true, Extension::INTERNAL, 0, &extension); |
77 EXPECT_TRUE(IsExtensionSyncable(extension)); | 92 EXPECT_TRUE(IsExtensionSyncable(extension)); |
78 } | 93 } |
79 { | 94 { |
80 FilePath file_path(kExtensionFilePath); | 95 FilePath file_path(kExtensionFilePath); |
81 Extension extension(file_path); | 96 Extension extension(file_path); |
82 MakePossiblySyncableExtension(true, GURL(), false, | 97 MakePossiblySyncableExtension(false, GURL(), GURL(), true, |
83 Extension::INTERNAL, &extension); | 98 Extension::INTERNAL, 0, &extension); |
| 99 EXPECT_TRUE(IsExtensionSyncable(extension)); |
| 100 } |
| 101 { |
| 102 FilePath file_path(kExtensionFilePath); |
| 103 Extension extension(file_path); |
| 104 MakePossiblySyncableExtension(true, GURL(), GURL(), false, |
| 105 Extension::INTERNAL, 0, &extension); |
84 EXPECT_FALSE(IsExtensionSyncable(extension)); | 106 EXPECT_FALSE(IsExtensionSyncable(extension)); |
85 } | 107 } |
86 // TODO(akalin): Test with a non-empty launch_url once apps are | 108 // TODO(akalin): Test with a non-empty launch_url once apps are |
87 // enabled by default. | 109 // enabled by default. |
88 { | 110 { |
89 FilePath file_path(kExtensionFilePath); | 111 FilePath file_path(kExtensionFilePath); |
90 Extension extension(file_path); | 112 Extension extension(file_path); |
91 MakePossiblySyncableExtension(false, GURL(), false, | 113 MakePossiblySyncableExtension(false, GURL(), GURL(), false, |
92 Extension::EXTERNAL_PREF, &extension); | 114 Extension::EXTERNAL_PREF, 0, &extension); |
| 115 EXPECT_FALSE(IsExtensionSyncable(extension)); |
| 116 } |
| 117 { |
| 118 FilePath file_path(kExtensionFilePath); |
| 119 Extension extension(file_path); |
| 120 MakePossiblySyncableExtension( |
| 121 false, GURL("http://third-party.update_url.com"), GURL(), true, |
| 122 Extension::INTERNAL, 0, &extension); |
| 123 EXPECT_FALSE(IsExtensionSyncable(extension)); |
| 124 } |
| 125 { |
| 126 FilePath file_path(kExtensionFilePath); |
| 127 Extension extension(file_path); |
| 128 MakePossiblySyncableExtension(false, GURL(), GURL(), true, |
| 129 Extension::INTERNAL, 1, &extension); |
| 130 EXPECT_FALSE(IsExtensionSyncable(extension)); |
| 131 } |
| 132 { |
| 133 FilePath file_path(kExtensionFilePath); |
| 134 Extension extension(file_path); |
| 135 MakePossiblySyncableExtension(false, GURL(), GURL(), true, |
| 136 Extension::INTERNAL, 2, &extension); |
93 EXPECT_FALSE(IsExtensionSyncable(extension)); | 137 EXPECT_FALSE(IsExtensionSyncable(extension)); |
94 } | 138 } |
95 } | 139 } |
96 | 140 |
97 TEST_F(ExtensionUtilTest, IsExtensionSpecificsUnset) { | 141 TEST_F(ExtensionUtilTest, IsExtensionSpecificsUnset) { |
98 { | 142 { |
99 sync_pb::ExtensionSpecifics specifics; | 143 sync_pb::ExtensionSpecifics specifics; |
100 EXPECT_TRUE(IsExtensionSpecificsUnset(specifics)); | 144 EXPECT_TRUE(IsExtensionSpecificsUnset(specifics)); |
101 } | 145 } |
102 | 146 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 } | 182 } |
139 | 183 |
140 TEST_F(ExtensionUtilTest, IsExtensionSpecificsValid) { | 184 TEST_F(ExtensionUtilTest, IsExtensionSpecificsValid) { |
141 sync_pb::ExtensionSpecifics specifics; | 185 sync_pb::ExtensionSpecifics specifics; |
142 EXPECT_FALSE(IsExtensionSpecificsValid(specifics)); | 186 EXPECT_FALSE(IsExtensionSpecificsValid(specifics)); |
143 specifics.set_id(kValidId); | 187 specifics.set_id(kValidId); |
144 EXPECT_FALSE(IsExtensionSpecificsValid(specifics)); | 188 EXPECT_FALSE(IsExtensionSpecificsValid(specifics)); |
145 specifics.set_version(kValidVersion); | 189 specifics.set_version(kValidVersion); |
146 EXPECT_TRUE(IsExtensionSpecificsValid(specifics)); | 190 EXPECT_TRUE(IsExtensionSpecificsValid(specifics)); |
147 EXPECT_FALSE(IsExtensionSpecificsUnset(specifics)); | 191 EXPECT_FALSE(IsExtensionSpecificsUnset(specifics)); |
148 specifics.set_update_url(kValidUpdateUrl); | 192 specifics.set_update_url(kValidUpdateUrl1); |
149 EXPECT_TRUE(IsExtensionSpecificsValid(specifics)); | 193 EXPECT_TRUE(IsExtensionSpecificsValid(specifics)); |
150 EXPECT_FALSE(IsExtensionSpecificsUnset(specifics)); | 194 EXPECT_FALSE(IsExtensionSpecificsUnset(specifics)); |
151 | 195 |
152 { | 196 { |
153 sync_pb::ExtensionSpecifics specifics_copy(specifics); | 197 sync_pb::ExtensionSpecifics specifics_copy(specifics); |
154 specifics_copy.set_id("invalid"); | 198 specifics_copy.set_id("invalid"); |
155 EXPECT_FALSE(IsExtensionSpecificsValid(specifics_copy)); | 199 EXPECT_FALSE(IsExtensionSpecificsValid(specifics_copy)); |
156 } | 200 } |
157 | 201 |
158 { | 202 { |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 source.SetString(extension_manifest_keys::kName, name); | 372 source.SetString(extension_manifest_keys::kName, name); |
329 std::string error; | 373 std::string error; |
330 EXPECT_TRUE(extension->InitFromValue(source, false, &error)); | 374 EXPECT_TRUE(extension->InitFromValue(source, false, &error)); |
331 EXPECT_EQ("", error); | 375 EXPECT_EQ("", error); |
332 extension->set_location(Extension::INTERNAL); | 376 extension->set_location(Extension::INTERNAL); |
333 } | 377 } |
334 | 378 |
335 TEST_F(ExtensionUtilTest, GetExtensionSpecificsHelper) { | 379 TEST_F(ExtensionUtilTest, GetExtensionSpecificsHelper) { |
336 FilePath file_path(kExtensionFilePath); | 380 FilePath file_path(kExtensionFilePath); |
337 Extension extension(file_path); | 381 Extension extension(file_path); |
338 MakeSyncableExtension(kValidVersion, kValidUpdateUrl, kName, | 382 MakeSyncableExtension(kValidVersion, kValidUpdateUrl1, kName, |
339 &extension); | 383 &extension); |
340 sync_pb::ExtensionSpecifics specifics; | 384 sync_pb::ExtensionSpecifics specifics; |
341 GetExtensionSpecificsHelper(extension, true, false, &specifics); | 385 GetExtensionSpecificsHelper(extension, true, false, &specifics); |
342 EXPECT_EQ(extension.id(), specifics.id()); | 386 EXPECT_EQ(extension.id(), specifics.id()); |
343 EXPECT_EQ(extension.VersionString(), kValidVersion); | 387 EXPECT_EQ(extension.VersionString(), kValidVersion); |
344 EXPECT_EQ(extension.update_url().spec(), kValidUpdateUrl); | 388 EXPECT_EQ(extension.update_url().spec(), kValidUpdateUrl1); |
345 EXPECT_TRUE(specifics.enabled()); | 389 EXPECT_TRUE(specifics.enabled()); |
346 EXPECT_FALSE(specifics.incognito_enabled()); | 390 EXPECT_FALSE(specifics.incognito_enabled()); |
347 EXPECT_EQ(kName, specifics.name()); | 391 EXPECT_EQ(kName, specifics.name()); |
348 } | 392 } |
349 | 393 |
350 TEST_F(ExtensionUtilTest, IsExtensionOutdated) { | 394 TEST_F(ExtensionUtilTest, IsExtensionOutdated) { |
351 FilePath file_path(kExtensionFilePath); | 395 FilePath file_path(kExtensionFilePath); |
352 Extension extension(file_path); | 396 Extension extension(file_path); |
353 MakeSyncableExtension(kVersion2, kValidUpdateUrl, kName, | 397 MakeSyncableExtension(kVersion2, kValidUpdateUrl1, kName, |
354 &extension); | 398 &extension); |
355 sync_pb::ExtensionSpecifics specifics; | 399 sync_pb::ExtensionSpecifics specifics; |
356 specifics.set_id(kValidId); | 400 specifics.set_id(kValidId); |
357 specifics.set_update_url(kValidUpdateUrl); | 401 specifics.set_update_url(kValidUpdateUrl1); |
358 | 402 |
359 specifics.set_version(kVersion1); | 403 specifics.set_version(kVersion1); |
360 EXPECT_FALSE(IsExtensionOutdated(extension, specifics)); | 404 EXPECT_FALSE(IsExtensionOutdated(extension, specifics)); |
361 specifics.set_version(kVersion2); | 405 specifics.set_version(kVersion2); |
362 EXPECT_FALSE(IsExtensionOutdated(extension, specifics)); | 406 EXPECT_FALSE(IsExtensionOutdated(extension, specifics)); |
363 specifics.set_version(kVersion3); | 407 specifics.set_version(kVersion3); |
364 EXPECT_TRUE(IsExtensionOutdated(extension, specifics)); | 408 EXPECT_TRUE(IsExtensionOutdated(extension, specifics)); |
365 } | 409 } |
366 | 410 |
367 // TODO(akalin): Make ExtensionsService/ExtensionUpdater testable | 411 // TODO(akalin): Make ExtensionsService/ExtensionUpdater testable |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 { | 467 { |
424 sync_pb::ExtensionSpecifics result = merged_specifics; | 468 sync_pb::ExtensionSpecifics result = merged_specifics; |
425 MergeExtensionSpecifics(specifics, true, &result); | 469 MergeExtensionSpecifics(specifics, true, &result); |
426 EXPECT_TRUE(AreExtensionSpecificsEqual(result, specifics)); | 470 EXPECT_TRUE(AreExtensionSpecificsEqual(result, specifics)); |
427 } | 471 } |
428 } | 472 } |
429 | 473 |
430 } // namespace | 474 } // namespace |
431 | 475 |
432 } // namespace browser_sync | 476 } // namespace browser_sync |
OLD | NEW |