Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: chrome/browser/sync/glue/extension_util_unittest.cc

Issue 7564037: Apps/Extensions Sync refactoring -- delete most of the old glue, implement new sync API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Release build warning :-/ Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/glue/extension_util.h"
6
7 #include "base/file_path.h"
8 #include "base/values.h"
9 #include "chrome/browser/extensions/extension_sync_data.h"
10 #include "chrome/browser/sync/protocol/extension_specifics.pb.h"
11 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/extensions/extension_constants.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace browser_sync {
17
18 namespace {
19
20 #if defined(OS_WIN)
21 const FilePath::CharType kExtensionFilePath[] = FILE_PATH_LITERAL("c:\\foo");
22 #elif defined(OS_POSIX)
23 const FilePath::CharType kExtensionFilePath[] = FILE_PATH_LITERAL("/foo");
24 #endif
25
26 const char kValidId[] = "abcdefghijklmnopabcdefghijklmnop";
27 const char kValidVersion[] = "0.0.0.0";
28 const char kVersion1[] = "1.0.0.1";
29 const char kVersion2[] = "1.0.1.0";
30 const char kVersion3[] = "1.1.0.0";
31 const char kValidUpdateUrl1[] =
32 "http://clients2.google.com/service/update2/crx";
33 const char kValidUpdateUrl2[] =
34 "https://clients2.google.com/service/update2/crx";
35 const char kName[] = "MyExtension";
36 const char kName2[] = "MyExtension2";
37
38 class ExtensionUtilTest : public testing::Test {
39 };
40
41 scoped_refptr<Extension> MakeExtension(
42 bool is_theme, const GURL& update_url,
43 const GURL& launch_url,
44 bool converted_from_user_script,
45 Extension::Location location, int num_plugins,
46 const FilePath& extension_path) {
47 DictionaryValue source;
48 source.SetString(extension_manifest_keys::kName,
49 "PossiblySyncableExtension");
50 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0");
51 if (is_theme) {
52 source.Set(extension_manifest_keys::kTheme, new DictionaryValue());
53 }
54 if (!update_url.is_empty()) {
55 source.SetString(extension_manifest_keys::kUpdateURL,
56 update_url.spec());
57 }
58 if (!launch_url.is_empty()) {
59 source.SetString(extension_manifest_keys::kLaunchWebURL,
60 launch_url.spec());
61 }
62 if (!is_theme) {
63 source.SetBoolean(extension_manifest_keys::kConvertedFromUserScript,
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);
72 }
73
74 std::string error;
75 scoped_refptr<Extension> extension = Extension::Create(
76 extension_path, location, source, Extension::STRICT_ERROR_CHECKS, &error);
77 EXPECT_TRUE(extension);
78 EXPECT_EQ("", error);
79 return extension;
80 }
81
82 TEST_F(ExtensionUtilTest, IsExtensionValid) {
83 {
84 FilePath file_path(kExtensionFilePath);
85 scoped_refptr<Extension> extension(
86 MakeExtension(false, GURL(), GURL(), false,
87 Extension::INTERNAL, 0, file_path));
88 EXPECT_TRUE(IsExtensionValid(*extension));
89 }
90 {
91 FilePath file_path(kExtensionFilePath);
92 scoped_refptr<Extension> extension(
93 MakeExtension(false, GURL(kValidUpdateUrl1), GURL(),
94 true, Extension::INTERNAL, 0, file_path));
95 EXPECT_TRUE(IsExtensionValid(*extension));
96 }
97 {
98 FilePath file_path(kExtensionFilePath);
99 scoped_refptr<Extension> extension(
100 MakeExtension(false, GURL(), GURL(), true,
101 Extension::INTERNAL, 0, file_path));
102 EXPECT_TRUE(IsExtensionValid(*extension));
103 }
104 {
105 FilePath file_path(kExtensionFilePath);
106 scoped_refptr<Extension> extension(
107 MakeExtension(true, GURL(), GURL(), false,
108 Extension::INTERNAL, 0, file_path));
109 EXPECT_TRUE(IsExtensionValid(*extension));
110 }
111 {
112 FilePath file_path(kExtensionFilePath);
113 scoped_refptr<Extension> extension(
114 MakeExtension(false, GURL(),
115 GURL("http://www.google.com"), false,
116 Extension::INTERNAL, 0, file_path));
117 EXPECT_TRUE(IsExtensionValid(*extension));
118 }
119 {
120 FilePath file_path(kExtensionFilePath);
121 scoped_refptr<Extension> extension(
122 MakeExtension(false, GURL(), GURL(), false,
123 Extension::EXTERNAL_PREF, 0, file_path));
124 EXPECT_FALSE(IsExtensionValid(*extension));
125 }
126 {
127 FilePath file_path(kExtensionFilePath);
128 scoped_refptr<Extension> extension(
129 MakeExtension(
130 false, GURL("http://third-party.update_url.com"), GURL(), true,
131 Extension::INTERNAL, 0, file_path));
132 EXPECT_FALSE(IsExtensionValid(*extension));
133 }
134 // These last 2 tests don't make sense on Chrome OS, where extension plugins
135 // are not allowed.
136 #if !defined(OS_CHROMEOS)
137 {
138 FilePath file_path(kExtensionFilePath);
139 scoped_refptr<Extension> extension(
140 MakeExtension(false, GURL(), GURL(), true,
141 Extension::INTERNAL, 1, file_path));
142 EXPECT_FALSE(extension && IsExtensionValid(*extension));
143 }
144 {
145 FilePath file_path(kExtensionFilePath);
146 scoped_refptr<Extension> extension(
147 MakeExtension(false, GURL(), GURL(), true,
148 Extension::INTERNAL, 2, file_path));
149 EXPECT_FALSE(extension && IsExtensionValid(*extension));
150 }
151 #endif
152 }
153
154 TEST_F(ExtensionUtilTest, SpecificsToSyncData) {
155 sync_pb::ExtensionSpecifics specifics;
156 specifics.set_id(kValidId);
157 specifics.set_update_url(kValidUpdateUrl2);
158 specifics.set_enabled(false);
159 specifics.set_incognito_enabled(true);
160 specifics.set_version(kVersion1);
161 specifics.set_name(kName);
162
163 ExtensionSyncData sync_data;
164 EXPECT_TRUE(SpecificsToSyncData(specifics, &sync_data));
165 EXPECT_EQ(specifics.id(), sync_data.id);
166 EXPECT_EQ(specifics.version(), sync_data.version.GetString());
167 EXPECT_EQ(specifics.update_url(), sync_data.update_url.spec());
168 EXPECT_EQ(specifics.enabled(), sync_data.enabled);
169 EXPECT_EQ(specifics.incognito_enabled(), sync_data.incognito_enabled);
170 EXPECT_EQ(specifics.name(), sync_data.name);
171 }
172
173 TEST_F(ExtensionUtilTest, SyncDataToSpecifics) {
174 ExtensionSyncData sync_data;
175 sync_data.id = kValidId;
176 sync_data.update_url = GURL(kValidUpdateUrl2);
177 sync_data.enabled = true;
178 sync_data.incognito_enabled = false;
179 {
180 scoped_ptr<Version> version(Version::GetVersionFromString(kVersion1));
181 sync_data.version = *version;
182 }
183 sync_data.name = kName;
184
185 sync_pb::ExtensionSpecifics specifics;
186 SyncDataToSpecifics(sync_data, &specifics);
187 EXPECT_EQ(sync_data.id, specifics.id());
188 EXPECT_EQ(sync_data.update_url.spec(), specifics.update_url());
189 EXPECT_EQ(sync_data.enabled, specifics.enabled());
190 EXPECT_EQ(sync_data.incognito_enabled, specifics.incognito_enabled());
191 EXPECT_EQ(sync_data.version.GetString(), specifics.version());
192 EXPECT_EQ(sync_data.name, specifics.name());
193 }
194
195 } // namespace
196
197 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/extension_util.cc ('k') | chrome/browser/sync/profile_sync_factory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698