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

Side by Side Diff: chrome/common/extensions/extension_unittest.cc

Issue 11662013: Move Commands from Extension to CommandsHandler (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_unref_script_badge
Patch Set: Created 7 years, 11 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
OLDNEW
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/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/json/json_file_value_serializer.h" 10 #include "base/json/json_file_value_serializer.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/common/chrome_paths.h" 15 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/extensions/api/commands/commands_handler.h"
16 #include "chrome/common/extensions/api/extension_action/action_info.h" 17 #include "chrome/common/extensions/api/extension_action/action_info.h"
17 #include "chrome/common/extensions/command.h" 18 #include "chrome/common/extensions/command.h"
18 #include "chrome/common/extensions/extension_file_util.h" 19 #include "chrome/common/extensions/extension_file_util.h"
19 #include "chrome/common/extensions/extension_manifest_constants.h" 20 #include "chrome/common/extensions/extension_manifest_constants.h"
20 #include "chrome/common/extensions/extension_resource.h" 21 #include "chrome/common/extensions/extension_resource.h"
21 #include "chrome/common/extensions/features/feature.h" 22 #include "chrome/common/extensions/features/feature.h"
23 #include "chrome/common/extensions/manifest_handler.h"
22 #include "chrome/common/extensions/permissions/api_permission.h" 24 #include "chrome/common/extensions/permissions/api_permission.h"
23 #include "chrome/common/extensions/permissions/permission_set.h" 25 #include "chrome/common/extensions/permissions/permission_set.h"
24 #include "chrome/common/extensions/permissions/socket_permission.h" 26 #include "chrome/common/extensions/permissions/socket_permission.h"
25 #include "chrome/common/extensions/permissions/usb_device_permission.h" 27 #include "chrome/common/extensions/permissions/usb_device_permission.h"
26 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
27 #include "extensions/common/error_utils.h" 29 #include "extensions/common/error_utils.h"
28 #include "googleurl/src/gurl.h" 30 #include "googleurl/src/gurl.h"
29 #include "net/base/mime_sniffer.h" 31 #include "net/base/mime_sniffer.h"
30 #include "net/base/mock_host_resolver.h" 32 #include "net/base/mock_host_resolver.h"
31 #include "skia/ext/image_operations.h" 33 #include "skia/ext/image_operations.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 std::string error; 115 std::string error;
114 scoped_refptr<Extension> extension = LoadManifestUnchecked("page_action", 116 scoped_refptr<Extension> extension = LoadManifestUnchecked("page_action",
115 manifest, Extension::INTERNAL, Extension::NO_FLAGS, &error); 117 manifest, Extension::INTERNAL, Extension::NO_FLAGS, &error);
116 EXPECT_FALSE(extension); 118 EXPECT_FALSE(extension);
117 EXPECT_EQ(expected_error, error); 119 EXPECT_EQ(expected_error, error);
118 } 120 }
119 121
120 } 122 }
121 123
122 class ExtensionTest : public testing::Test { 124 class ExtensionTest : public testing::Test {
125 protected:
126 virtual void SetUp() OVERRIDE {
127 ManifestHandler::Register(extension_manifest_keys::kCommands,
128 new CommandsHandler);
129 }
123 }; 130 };
124 131
125 // We persist location values in the preferences, so this is a sanity test that 132 // We persist location values in the preferences, so this is a sanity test that
126 // someone doesn't accidentally change them. 133 // someone doesn't accidentally change them.
127 TEST(ExtensionTest, LocationValuesTest) { 134 TEST_F(ExtensionTest, LocationValuesTest) {
128 ASSERT_EQ(0, Extension::INVALID); 135 ASSERT_EQ(0, Extension::INVALID);
129 ASSERT_EQ(1, Extension::INTERNAL); 136 ASSERT_EQ(1, Extension::INTERNAL);
130 ASSERT_EQ(2, Extension::EXTERNAL_PREF); 137 ASSERT_EQ(2, Extension::EXTERNAL_PREF);
131 ASSERT_EQ(3, Extension::EXTERNAL_REGISTRY); 138 ASSERT_EQ(3, Extension::EXTERNAL_REGISTRY);
132 ASSERT_EQ(4, Extension::LOAD); 139 ASSERT_EQ(4, Extension::LOAD);
133 ASSERT_EQ(5, Extension::COMPONENT); 140 ASSERT_EQ(5, Extension::COMPONENT);
134 ASSERT_EQ(6, Extension::EXTERNAL_PREF_DOWNLOAD); 141 ASSERT_EQ(6, Extension::EXTERNAL_PREF_DOWNLOAD);
135 ASSERT_EQ(7, Extension::EXTERNAL_POLICY_DOWNLOAD); 142 ASSERT_EQ(7, Extension::EXTERNAL_POLICY_DOWNLOAD);
136 } 143 }
137 144
138 TEST(ExtensionTest, LocationPriorityTest) { 145 TEST_F(ExtensionTest, LocationPriorityTest) {
139 for (int i = 0; i < Extension::NUM_LOCATIONS; i++) { 146 for (int i = 0; i < Extension::NUM_LOCATIONS; i++) {
140 Extension::Location loc = static_cast<Extension::Location>(i); 147 Extension::Location loc = static_cast<Extension::Location>(i);
141 148
142 // INVALID is not a valid location. 149 // INVALID is not a valid location.
143 if (loc == Extension::INVALID) 150 if (loc == Extension::INVALID)
144 continue; 151 continue;
145 152
146 // Comparing a location that has no rank will hit a CHECK. Do a 153 // Comparing a location that has no rank will hit a CHECK. Do a
147 // compare with every valid location, to be sure each one is covered. 154 // compare with every valid location, to be sure each one is covered.
148 155
(...skipping 16 matching lines...) Expand all
165 Extension::GetHigherPriorityLocation( 172 Extension::GetHigherPriorityLocation(
166 Extension::EXTERNAL_POLICY_DOWNLOAD, 173 Extension::EXTERNAL_POLICY_DOWNLOAD,
167 Extension::EXTERNAL_PREF)); 174 Extension::EXTERNAL_PREF));
168 175
169 ASSERT_EQ(Extension::EXTERNAL_PREF, 176 ASSERT_EQ(Extension::EXTERNAL_PREF,
170 Extension::GetHigherPriorityLocation( 177 Extension::GetHigherPriorityLocation(
171 Extension::INTERNAL, 178 Extension::INTERNAL,
172 Extension::EXTERNAL_PREF)); 179 Extension::EXTERNAL_PREF));
173 } 180 }
174 181
175 TEST(ExtensionTest, GetResourceURLAndPath) { 182 TEST_F(ExtensionTest, GetResourceURLAndPath) {
176 scoped_refptr<Extension> extension = LoadManifestStrict("empty_manifest", 183 scoped_refptr<Extension> extension = LoadManifestStrict("empty_manifest",
177 "empty.json"); 184 "empty.json");
178 EXPECT_TRUE(extension.get()); 185 EXPECT_TRUE(extension.get());
179 186
180 EXPECT_EQ(extension->url().spec() + "bar/baz.js", 187 EXPECT_EQ(extension->url().spec() + "bar/baz.js",
181 Extension::GetResourceURL(extension->url(), "bar/baz.js").spec()); 188 Extension::GetResourceURL(extension->url(), "bar/baz.js").spec());
182 EXPECT_EQ(extension->url().spec() + "baz.js", 189 EXPECT_EQ(extension->url().spec() + "baz.js",
183 Extension::GetResourceURL(extension->url(), 190 Extension::GetResourceURL(extension->url(),
184 "bar/../baz.js").spec()); 191 "bar/../baz.js").spec());
185 EXPECT_EQ(extension->url().spec() + "baz.js", 192 EXPECT_EQ(extension->url().spec() + "baz.js",
186 Extension::GetResourceURL(extension->url(), "../baz.js").spec()); 193 Extension::GetResourceURL(extension->url(), "../baz.js").spec());
187 194
188 // Test that absolute-looking paths ("/"-prefixed) are pasted correctly. 195 // Test that absolute-looking paths ("/"-prefixed) are pasted correctly.
189 EXPECT_EQ(extension->url().spec() + "test.html", 196 EXPECT_EQ(extension->url().spec() + "test.html",
190 extension->GetResourceURL("/test.html").spec()); 197 extension->GetResourceURL("/test.html").spec());
191 } 198 }
192 199
193 TEST(ExtensionTest, GetAbsolutePathNoError) { 200 TEST_F(ExtensionTest, GetAbsolutePathNoError) {
194 scoped_refptr<Extension> extension = LoadManifestStrict("absolute_path", 201 scoped_refptr<Extension> extension = LoadManifestStrict("absolute_path",
195 "absolute.json"); 202 "absolute.json");
196 EXPECT_TRUE(extension.get()); 203 EXPECT_TRUE(extension.get());
197 std::string err; 204 std::string err;
198 Extension::InstallWarningVector warnings; 205 Extension::InstallWarningVector warnings;
199 EXPECT_TRUE(extension_file_util::ValidateExtension(extension.get(), 206 EXPECT_TRUE(extension_file_util::ValidateExtension(extension.get(),
200 &err, &warnings)); 207 &err, &warnings));
201 EXPECT_EQ(0U, warnings.size()); 208 EXPECT_EQ(0U, warnings.size());
202 209
203 EXPECT_EQ(extension->path().AppendASCII("test.html").value(), 210 EXPECT_EQ(extension->path().AppendASCII("test.html").value(),
204 extension->GetResource("test.html").GetFilePath().value()); 211 extension->GetResource("test.html").GetFilePath().value());
205 EXPECT_EQ(extension->path().AppendASCII("test.js").value(), 212 EXPECT_EQ(extension->path().AppendASCII("test.js").value(),
206 extension->GetResource("test.js").GetFilePath().value()); 213 extension->GetResource("test.js").GetFilePath().value());
207 } 214 }
208 215
209 TEST(ExtensionTest, LoadPageActionHelper) { 216 TEST_F(ExtensionTest, LoadPageActionHelper) {
210 scoped_ptr<ActionInfo> action; 217 scoped_ptr<ActionInfo> action;
211 218
212 // First try with an empty dictionary. 219 // First try with an empty dictionary.
213 action = LoadAction("page_action_empty.json"); 220 action = LoadAction("page_action_empty.json");
214 ASSERT_TRUE(action != NULL); 221 ASSERT_TRUE(action != NULL);
215 222
216 // Now setup some values to use in the action. 223 // Now setup some values to use in the action.
217 const std::string id("MyExtensionActionId"); 224 const std::string id("MyExtensionActionId");
218 const std::string name("MyExtensionActionName"); 225 const std::string name("MyExtensionActionName");
219 std::string img1("image1.png"); 226 std::string img1("image1.png");
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 // Setting popup to "" is the same as having no popup. 313 // Setting popup to "" is the same as having no popup.
307 action = LoadAction("page_action_empty_popup.json"); 314 action = LoadAction("page_action_empty_popup.json");
308 315
309 ASSERT_TRUE(NULL != action.get()); 316 ASSERT_TRUE(NULL != action.get());
310 EXPECT_TRUE(action->default_popup_url.is_empty()); 317 EXPECT_TRUE(action->default_popup_url.is_empty());
311 ASSERT_STREQ( 318 ASSERT_STREQ(
312 "", 319 "",
313 action->default_popup_url.spec().c_str()); 320 action->default_popup_url.spec().c_str());
314 } 321 }
315 322
316 TEST(ExtensionTest, IdIsValid) { 323 TEST_F(ExtensionTest, IdIsValid) {
317 EXPECT_TRUE(Extension::IdIsValid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); 324 EXPECT_TRUE(Extension::IdIsValid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
318 EXPECT_TRUE(Extension::IdIsValid("pppppppppppppppppppppppppppppppp")); 325 EXPECT_TRUE(Extension::IdIsValid("pppppppppppppppppppppppppppppppp"));
319 EXPECT_TRUE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnop")); 326 EXPECT_TRUE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnop"));
320 EXPECT_TRUE(Extension::IdIsValid("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP")); 327 EXPECT_TRUE(Extension::IdIsValid("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"));
321 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno")); 328 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno"));
322 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnopa")); 329 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnopa"));
323 EXPECT_FALSE(Extension::IdIsValid("0123456789abcdef0123456789abcdef")); 330 EXPECT_FALSE(Extension::IdIsValid("0123456789abcdef0123456789abcdef"));
324 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnoq")); 331 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnoq"));
325 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno0")); 332 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno0"));
326 } 333 }
327 334
328 TEST(ExtensionTest, GenerateID) { 335 TEST_F(ExtensionTest, GenerateID) {
329 const uint8 public_key_info[] = { 336 const uint8 public_key_info[] = {
330 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 337 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
331 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 338 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81,
332 0x89, 0x02, 0x81, 0x81, 0x00, 0xb8, 0x7f, 0x2b, 0x20, 0xdc, 0x7c, 0x9b, 339 0x89, 0x02, 0x81, 0x81, 0x00, 0xb8, 0x7f, 0x2b, 0x20, 0xdc, 0x7c, 0x9b,
333 0x0c, 0xdc, 0x51, 0x61, 0x99, 0x0d, 0x36, 0x0f, 0xd4, 0x66, 0x88, 0x08, 340 0x0c, 0xdc, 0x51, 0x61, 0x99, 0x0d, 0x36, 0x0f, 0xd4, 0x66, 0x88, 0x08,
334 0x55, 0x84, 0xd5, 0x3a, 0xbf, 0x2b, 0xa4, 0x64, 0x85, 0x7b, 0x0c, 0x04, 341 0x55, 0x84, 0xd5, 0x3a, 0xbf, 0x2b, 0xa4, 0x64, 0x85, 0x7b, 0x0c, 0x04,
335 0x13, 0x3f, 0x8d, 0xf4, 0xbc, 0x38, 0x0d, 0x49, 0xfe, 0x6b, 0xc4, 0x5a, 342 0x13, 0x3f, 0x8d, 0xf4, 0xbc, 0x38, 0x0d, 0x49, 0xfe, 0x6b, 0xc4, 0x5a,
336 0xb0, 0x40, 0x53, 0x3a, 0xd7, 0x66, 0x09, 0x0f, 0x9e, 0x36, 0x74, 0x30, 343 0xb0, 0x40, 0x53, 0x3a, 0xd7, 0x66, 0x09, 0x0f, 0x9e, 0x36, 0x74, 0x30,
337 0xda, 0x8a, 0x31, 0x4f, 0x1f, 0x14, 0x50, 0xd7, 0xc7, 0x20, 0x94, 0x17, 344 0xda, 0x8a, 0x31, 0x4f, 0x1f, 0x14, 0x50, 0xd7, 0xc7, 0x20, 0x94, 0x17,
338 0xde, 0x4e, 0xb9, 0x57, 0x5e, 0x7e, 0x0a, 0xe5, 0xb2, 0x65, 0x7a, 0x89, 345 0xde, 0x4e, 0xb9, 0x57, 0x5e, 0x7e, 0x0a, 0xe5, 0xb2, 0x65, 0x7a, 0x89,
339 0x4e, 0xb6, 0x47, 0xff, 0x1c, 0xbd, 0xb7, 0x38, 0x13, 0xaf, 0x47, 0x85, 346 0x4e, 0xb6, 0x47, 0xff, 0x1c, 0xbd, 0xb7, 0x38, 0x13, 0xaf, 0x47, 0x85,
340 0x84, 0x32, 0x33, 0xf3, 0x17, 0x49, 0xbf, 0xe9, 0x96, 0xd0, 0xd6, 0x14, 347 0x84, 0x32, 0x33, 0xf3, 0x17, 0x49, 0xbf, 0xe9, 0x96, 0xd0, 0xd6, 0x14,
341 0x6f, 0x13, 0x8d, 0xc5, 0xfc, 0x2c, 0x72, 0xba, 0xac, 0xea, 0x7e, 0x18, 348 0x6f, 0x13, 0x8d, 0xc5, 0xfc, 0x2c, 0x72, 0xba, 0xac, 0xea, 0x7e, 0x18,
342 0x53, 0x56, 0xa6, 0x83, 0xa2, 0xce, 0x93, 0x93, 0xe7, 0x1f, 0x0f, 0xe6, 349 0x53, 0x56, 0xa6, 0x83, 0xa2, 0xce, 0x93, 0x93, 0xe7, 0x1f, 0x0f, 0xe6,
343 0x0f, 0x02, 0x03, 0x01, 0x00, 0x01 350 0x0f, 0x02, 0x03, 0x01, 0x00, 0x01
344 }; 351 };
345 352
346 std::string extension_id; 353 std::string extension_id;
347 EXPECT_TRUE( 354 EXPECT_TRUE(
348 Extension::GenerateId( 355 Extension::GenerateId(
349 std::string(reinterpret_cast<const char*>(&public_key_info[0]), 356 std::string(reinterpret_cast<const char*>(&public_key_info[0]),
350 arraysize(public_key_info)), 357 arraysize(public_key_info)),
351 &extension_id)); 358 &extension_id));
352 EXPECT_EQ("melddjfinppjdikinhbgehiennejpfhp", extension_id); 359 EXPECT_EQ("melddjfinppjdikinhbgehiennejpfhp", extension_id);
353 } 360 }
354 361
355 // This test ensures that the mimetype sniffing code stays in sync with the 362 // This test ensures that the mimetype sniffing code stays in sync with the
356 // actual crx files that we test other parts of the system with. 363 // actual crx files that we test other parts of the system with.
357 TEST(ExtensionTest, MimeTypeSniffing) { 364 TEST_F(ExtensionTest, MimeTypeSniffing) {
358 FilePath path; 365 FilePath path;
359 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); 366 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
360 path = path.AppendASCII("extensions").AppendASCII("good.crx"); 367 path = path.AppendASCII("extensions").AppendASCII("good.crx");
361 368
362 std::string data; 369 std::string data;
363 ASSERT_TRUE(file_util::ReadFileToString(path, &data)); 370 ASSERT_TRUE(file_util::ReadFileToString(path, &data));
364 371
365 std::string result; 372 std::string result;
366 EXPECT_TRUE(net::SniffMimeType(data.c_str(), data.size(), 373 EXPECT_TRUE(net::SniffMimeType(data.c_str(), data.size(),
367 GURL("http://www.example.com/foo.crx"), "", &result)); 374 GURL("http://www.example.com/foo.crx"), "", &result));
368 EXPECT_EQ(std::string(Extension::kMimeType), result); 375 EXPECT_EQ(std::string(Extension::kMimeType), result);
369 376
370 data.clear(); 377 data.clear();
371 result.clear(); 378 result.clear();
372 path = path.DirName().AppendASCII("bad_magic.crx"); 379 path = path.DirName().AppendASCII("bad_magic.crx");
373 ASSERT_TRUE(file_util::ReadFileToString(path, &data)); 380 ASSERT_TRUE(file_util::ReadFileToString(path, &data));
374 EXPECT_TRUE(net::SniffMimeType(data.c_str(), data.size(), 381 EXPECT_TRUE(net::SniffMimeType(data.c_str(), data.size(),
375 GURL("http://www.example.com/foo.crx"), "", &result)); 382 GURL("http://www.example.com/foo.crx"), "", &result));
376 EXPECT_EQ("application/octet-stream", result); 383 EXPECT_EQ("application/octet-stream", result);
377 } 384 }
378 385
379 TEST(ExtensionTest, EffectiveHostPermissions) { 386 TEST_F(ExtensionTest, EffectiveHostPermissions) {
380 scoped_refptr<Extension> extension; 387 scoped_refptr<Extension> extension;
381 URLPatternSet hosts; 388 URLPatternSet hosts;
382 389
383 extension = LoadManifest("effective_host_permissions", "empty.json"); 390 extension = LoadManifest("effective_host_permissions", "empty.json");
384 EXPECT_EQ(0u, extension->GetEffectiveHostPermissions().patterns().size()); 391 EXPECT_EQ(0u, extension->GetEffectiveHostPermissions().patterns().size());
385 EXPECT_FALSE(hosts.MatchesURL(GURL("http://www.google.com"))); 392 EXPECT_FALSE(hosts.MatchesURL(GURL("http://www.google.com")));
386 EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts()); 393 EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts());
387 394
388 extension = LoadManifest("effective_host_permissions", "one_host.json"); 395 extension = LoadManifest("effective_host_permissions", "one_host.json");
389 hosts = extension->GetEffectiveHostPermissions(); 396 hosts = extension->GetEffectiveHostPermissions();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 453
447 static bool CheckSocketPermission(scoped_refptr<Extension> extension, 454 static bool CheckSocketPermission(scoped_refptr<Extension> extension,
448 SocketPermissionRequest::OperationType type, 455 SocketPermissionRequest::OperationType type,
449 const char* host, 456 const char* host,
450 int port) { 457 int port) {
451 SocketPermission::CheckParam param(type, host, port); 458 SocketPermission::CheckParam param(type, host, port);
452 return extension->CheckAPIPermissionWithParam( 459 return extension->CheckAPIPermissionWithParam(
453 APIPermission::kSocket, &param); 460 APIPermission::kSocket, &param);
454 } 461 }
455 462
456 TEST(ExtensionTest, SocketPermissions) { 463 TEST_F(ExtensionTest, SocketPermissions) {
457 // Set feature current channel to appropriate value. 464 // Set feature current channel to appropriate value.
458 Feature::ScopedCurrentChannel scoped_channel( 465 Feature::ScopedCurrentChannel scoped_channel(
459 chrome::VersionInfo::CHANNEL_DEV); 466 chrome::VersionInfo::CHANNEL_DEV);
460 scoped_refptr<Extension> extension; 467 scoped_refptr<Extension> extension;
461 std::string error; 468 std::string error;
462 469
463 extension = LoadManifest("socket_permissions", "empty.json"); 470 extension = LoadManifest("socket_permissions", "empty.json");
464 EXPECT_FALSE(CheckSocketPermission(extension, 471 EXPECT_FALSE(CheckSocketPermission(extension,
465 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); 472 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80));
466 473
(...skipping 26 matching lines...) Expand all
493 return skia::ImageOperations::Resize(source, 500 return skia::ImageOperations::Resize(source,
494 skia::ImageOperations::RESIZE_LANCZOS3, 501 skia::ImageOperations::RESIZE_LANCZOS3,
495 size, 502 size,
496 size); 503 size);
497 } 504 }
498 505
499 static bool SizeEquals(const SkBitmap& bitmap, const gfx::Size& size) { 506 static bool SizeEquals(const SkBitmap& bitmap, const gfx::Size& size) {
500 return bitmap.width() == size.width() && bitmap.height() == size.height(); 507 return bitmap.width() == size.width() && bitmap.height() == size.height();
501 } 508 }
502 509
503 TEST(ExtensionTest, ImageCaching) { 510 TEST_F(ExtensionTest, ImageCaching) {
504 FilePath path; 511 FilePath path;
505 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); 512 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
506 path = path.AppendASCII("extensions"); 513 path = path.AppendASCII("extensions");
507 514
508 // Initialize the Extension. 515 // Initialize the Extension.
509 std::string errors; 516 std::string errors;
510 DictionaryValue values; 517 DictionaryValue values;
511 values.SetString(keys::kName, "test"); 518 values.SetString(keys::kName, "test");
512 values.SetString(keys::kVersion, "0.1"); 519 values.SetString(keys::kVersion, "0.1");
513 scoped_refptr<Extension> extension(Extension::Create( 520 scoped_refptr<Extension> extension(Extension::Create(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 EXPECT_TRUE(SizeEquals(extension->GetCachedImage(resource, original_size), 574 EXPECT_TRUE(SizeEquals(extension->GetCachedImage(resource, original_size),
568 original_size)); 575 original_size));
569 EXPECT_TRUE(SizeEquals(extension->GetCachedImage(resource, size128), 576 EXPECT_TRUE(SizeEquals(extension->GetCachedImage(resource, size128),
570 original_size)); 577 original_size));
571 EXPECT_EQ(extension->GetCachedImage(resource, original_size).getPixels(), 578 EXPECT_EQ(extension->GetCachedImage(resource, original_size).getPixels(),
572 extension->GetCachedImage(resource, size128).getPixels()); 579 extension->GetCachedImage(resource, size128).getPixels());
573 } 580 }
574 581
575 // This tests the API permissions with an empty manifest (one that just 582 // This tests the API permissions with an empty manifest (one that just
576 // specifies a name and a version and nothing else). 583 // specifies a name and a version and nothing else).
577 TEST(ExtensionTest, ApiPermissions) { 584 TEST_F(ExtensionTest, ApiPermissions) {
578 const struct { 585 const struct {
579 const char* permission_name; 586 const char* permission_name;
580 bool expect_success; 587 bool expect_success;
581 } kTests[] = { 588 } kTests[] = {
582 // Negative test. 589 // Negative test.
583 { "non_existing_permission", false }, 590 { "non_existing_permission", false },
584 // Test default module/package permission. 591 // Test default module/package permission.
585 { "browserAction", true }, 592 { "browserAction", true },
586 { "devtools", true }, 593 { "devtools", true },
587 { "extension", true }, 594 { "extension", true },
(...skipping 24 matching lines...) Expand all
612 scoped_refptr<Extension> extension; 619 scoped_refptr<Extension> extension;
613 extension = LoadManifest("empty_manifest", "empty.json"); 620 extension = LoadManifest("empty_manifest", "empty.json");
614 621
615 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { 622 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) {
616 EXPECT_EQ(kTests[i].expect_success, 623 EXPECT_EQ(kTests[i].expect_success,
617 extension->HasAPIPermission(kTests[i].permission_name)) 624 extension->HasAPIPermission(kTests[i].permission_name))
618 << "Permission being tested: " << kTests[i].permission_name; 625 << "Permission being tested: " << kTests[i].permission_name;
619 } 626 }
620 } 627 }
621 628
622 TEST(ExtensionTest, GetPermissionMessages_ManyApiPermissions) { 629 TEST_F(ExtensionTest, GetPermissionMessages_ManyApiPermissions) {
623 scoped_refptr<Extension> extension; 630 scoped_refptr<Extension> extension;
624 extension = LoadManifest("permissions", "many-apis.json"); 631 extension = LoadManifest("permissions", "many-apis.json");
625 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 632 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
626 ASSERT_EQ(6u, warnings.size()); 633 ASSERT_EQ(6u, warnings.size());
627 EXPECT_EQ("Access your data on api.flickr.com", 634 EXPECT_EQ("Access your data on api.flickr.com",
628 UTF16ToUTF8(warnings[0])); 635 UTF16ToUTF8(warnings[0]));
629 EXPECT_EQ("Read and modify your bookmarks", UTF16ToUTF8(warnings[1])); 636 EXPECT_EQ("Read and modify your bookmarks", UTF16ToUTF8(warnings[1]));
630 EXPECT_EQ("Detect your physical location", UTF16ToUTF8(warnings[2])); 637 EXPECT_EQ("Detect your physical location", UTF16ToUTF8(warnings[2]));
631 EXPECT_EQ("Read and modify your browsing history", UTF16ToUTF8(warnings[3])); 638 EXPECT_EQ("Read and modify your browsing history", UTF16ToUTF8(warnings[3]));
632 EXPECT_EQ("Access your tabs and browsing activity", UTF16ToUTF8(warnings[4])); 639 EXPECT_EQ("Access your tabs and browsing activity", UTF16ToUTF8(warnings[4]));
633 EXPECT_EQ("Manage your apps, extensions, and themes", 640 EXPECT_EQ("Manage your apps, extensions, and themes",
634 UTF16ToUTF8(warnings[5])); 641 UTF16ToUTF8(warnings[5]));
635 } 642 }
636 643
637 TEST(ExtensionTest, GetPermissionMessages_ManyHosts) { 644 TEST_F(ExtensionTest, GetPermissionMessages_ManyHosts) {
638 scoped_refptr<Extension> extension; 645 scoped_refptr<Extension> extension;
639 extension = LoadManifest("permissions", "many-hosts.json"); 646 extension = LoadManifest("permissions", "many-hosts.json");
640 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 647 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
641 ASSERT_EQ(1u, warnings.size()); 648 ASSERT_EQ(1u, warnings.size());
642 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", 649 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com",
643 UTF16ToUTF8(warnings[0])); 650 UTF16ToUTF8(warnings[0]));
644 } 651 }
645 652
646 TEST(ExtensionTest, GetPermissionMessages_Plugins) { 653 TEST_F(ExtensionTest, GetPermissionMessages_Plugins) {
647 scoped_refptr<Extension> extension; 654 scoped_refptr<Extension> extension;
648 extension = LoadManifest("permissions", "plugins.json"); 655 extension = LoadManifest("permissions", "plugins.json");
649 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 656 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
650 // We don't parse the plugins key on Chrome OS, so it should not ask for any 657 // We don't parse the plugins key on Chrome OS, so it should not ask for any
651 // permissions. 658 // permissions.
652 #if defined(OS_CHROMEOS) 659 #if defined(OS_CHROMEOS)
653 ASSERT_EQ(0u, warnings.size()); 660 ASSERT_EQ(0u, warnings.size());
654 #else 661 #else
655 ASSERT_EQ(1u, warnings.size()); 662 ASSERT_EQ(1u, warnings.size());
656 EXPECT_EQ("Access all data on your computer and the websites you visit", 663 EXPECT_EQ("Access all data on your computer and the websites you visit",
657 UTF16ToUTF8(warnings[0])); 664 UTF16ToUTF8(warnings[0]));
658 #endif 665 #endif
659 } 666 }
660 667
661 TEST(ExtensionTest, WantsFileAccess) { 668 TEST_F(ExtensionTest, WantsFileAccess) {
662 scoped_refptr<Extension> extension; 669 scoped_refptr<Extension> extension;
663 GURL file_url("file:///etc/passwd"); 670 GURL file_url("file:///etc/passwd");
664 671
665 // <all_urls> permission 672 // <all_urls> permission
666 extension = LoadManifest("permissions", "permissions_all_urls.json"); 673 extension = LoadManifest("permissions", "permissions_all_urls.json");
667 EXPECT_TRUE(extension->wants_file_access()); 674 EXPECT_TRUE(extension->wants_file_access());
668 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 675 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
669 file_url, file_url, -1, NULL, NULL)); 676 file_url, file_url, -1, NULL, NULL));
670 extension = LoadManifest( 677 extension = LoadManifest(
671 "permissions", "permissions_all_urls.json", Extension::ALLOW_FILE_ACCESS); 678 "permissions", "permissions_all_urls.json", Extension::ALLOW_FILE_ACCESS);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 EXPECT_FALSE(extension->wants_file_access()); 729 EXPECT_FALSE(extension->wants_file_access());
723 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 730 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
724 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 731 file_url, file_url, -1, &extension->content_scripts()[0], NULL));
725 extension = LoadManifest("permissions", "content_script_http_scheme.json", 732 extension = LoadManifest("permissions", "content_script_http_scheme.json",
726 Extension::ALLOW_FILE_ACCESS); 733 Extension::ALLOW_FILE_ACCESS);
727 EXPECT_FALSE(extension->wants_file_access()); 734 EXPECT_FALSE(extension->wants_file_access());
728 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 735 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
729 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 736 file_url, file_url, -1, &extension->content_scripts()[0], NULL));
730 } 737 }
731 738
732 TEST(ExtensionTest, ExtraFlags) { 739 TEST_F(ExtensionTest, ExtraFlags) {
733 scoped_refptr<Extension> extension; 740 scoped_refptr<Extension> extension;
734 extension = LoadManifest("app", "manifest.json", Extension::FROM_WEBSTORE); 741 extension = LoadManifest("app", "manifest.json", Extension::FROM_WEBSTORE);
735 EXPECT_TRUE(extension->from_webstore()); 742 EXPECT_TRUE(extension->from_webstore());
736 743
737 extension = LoadManifest("app", "manifest.json", Extension::FROM_BOOKMARK); 744 extension = LoadManifest("app", "manifest.json", Extension::FROM_BOOKMARK);
738 EXPECT_TRUE(extension->from_bookmark()); 745 EXPECT_TRUE(extension->from_bookmark());
739 746
740 extension = LoadManifest("app", "manifest.json", Extension::NO_FLAGS); 747 extension = LoadManifest("app", "manifest.json", Extension::NO_FLAGS);
741 EXPECT_FALSE(extension->from_bookmark()); 748 EXPECT_FALSE(extension->from_bookmark());
742 EXPECT_FALSE(extension->from_webstore()); 749 EXPECT_FALSE(extension->from_webstore());
743 } 750 }
744 751
745 TEST(ExtensionTest, BrowserActionSynthesizesCommand) { 752 TEST_F(ExtensionTest, BrowserActionSynthesizesCommand) {
746 scoped_refptr<Extension> extension; 753 scoped_refptr<Extension> extension;
747 754
748 extension = LoadManifest("api_test/browser_action/synthesized", 755 extension = LoadManifest("api_test/browser_action/synthesized",
749 "manifest.json"); 756 "manifest.json");
750 // An extension with a browser action but no extension command specified 757 // An extension with a browser action but no extension command specified
751 // should get a command assigned to it. 758 // should get a command assigned to it.
752 const Command* command = extension->browser_action_command(); 759 const extensions::Command* command =
760 CommandsInfo::GetBrowserActionCommand(extension);
753 ASSERT_TRUE(command != NULL); 761 ASSERT_TRUE(command != NULL);
754 ASSERT_EQ(ui::VKEY_UNKNOWN, command->accelerator().key_code()); 762 ASSERT_EQ(ui::VKEY_UNKNOWN, command->accelerator().key_code());
755 } 763 }
756 764
757 // Base class for testing the CanExecuteScriptOnPage and CanCaptureVisiblePage 765 // Base class for testing the CanExecuteScriptOnPage and CanCaptureVisiblePage
758 // methods of Extension for extensions with various permissions. 766 // methods of Extension for extensions with various permissions.
759 class ExtensionScriptAndCaptureVisibleTest : public testing::Test { 767 class ExtensionScriptAndCaptureVisibleTest : public testing::Test {
760 protected: 768 protected:
761 ExtensionScriptAndCaptureVisibleTest() 769 ExtensionScriptAndCaptureVisibleTest()
762 : http_url("http://www.google.com"), 770 : http_url("http://www.google.com"),
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2)); 1024 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2));
1017 1025
1018 extension->ClearTabSpecificPermissions(1); 1026 extension->ClearTabSpecificPermissions(1);
1019 EXPECT_FALSE(extension->GetTabSpecificPermissions(1).get()); 1027 EXPECT_FALSE(extension->GetTabSpecificPermissions(1).get());
1020 1028
1021 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 0)); 1029 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 0));
1022 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 1)); 1030 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 1));
1023 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2)); 1031 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2));
1024 } 1032 }
1025 1033
1026 TEST(ExtensionTest, GenerateId) { 1034 TEST_F(ExtensionTest, GenerateId) {
1027 std::string result; 1035 std::string result;
1028 EXPECT_TRUE(Extension::GenerateId("", &result)); 1036 EXPECT_TRUE(Extension::GenerateId("", &result));
1029 1037
1030 EXPECT_TRUE(Extension::GenerateId("test", &result)); 1038 EXPECT_TRUE(Extension::GenerateId("test", &result));
1031 EXPECT_EQ(result, "jpignaibiiemhngfjkcpokkamffknabf"); 1039 EXPECT_EQ(result, "jpignaibiiemhngfjkcpokkamffknabf");
1032 1040
1033 EXPECT_TRUE(Extension::GenerateId("_", &result)); 1041 EXPECT_TRUE(Extension::GenerateId("_", &result));
1034 EXPECT_EQ(result, "ncocknphbhhlhkikpnnlmbcnbgdempcd"); 1042 EXPECT_EQ(result, "ncocknphbhhlhkikpnnlmbcnbgdempcd");
1035 1043
1036 EXPECT_TRUE(Extension::GenerateId( 1044 EXPECT_TRUE(Extension::GenerateId(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 EXPECT_EQ("", error); 1097 EXPECT_EQ("", error);
1090 return extension; 1098 return extension;
1091 } 1099 }
1092 1100
1093 static const char kValidUpdateUrl1[] = 1101 static const char kValidUpdateUrl1[] =
1094 "http://clients2.google.com/service/update2/crx"; 1102 "http://clients2.google.com/service/update2/crx";
1095 static const char kValidUpdateUrl2[] = 1103 static const char kValidUpdateUrl2[] =
1096 "https://clients2.google.com/service/update2/crx"; 1104 "https://clients2.google.com/service/update2/crx";
1097 } 1105 }
1098 1106
1099 TEST(ExtensionTest, GetSyncTypeNormalExtensionNoUpdateUrl) { 1107 TEST_F(ExtensionTest, GetSyncTypeNormalExtensionNoUpdateUrl) {
1100 scoped_refptr<Extension> extension( 1108 scoped_refptr<Extension> extension(
1101 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1109 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1102 Extension::INTERNAL, 0, FilePath(), 1110 Extension::INTERNAL, 0, FilePath(),
1103 Extension::NO_FLAGS)); 1111 Extension::NO_FLAGS));
1104 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1112 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1105 } 1113 }
1106 1114
1107 TEST(ExtensionTest, GetSyncTypeUserScriptValidUpdateUrl) { 1115 TEST_F(ExtensionTest, GetSyncTypeUserScriptValidUpdateUrl) {
1108 scoped_refptr<Extension> extension( 1116 scoped_refptr<Extension> extension(
1109 MakeSyncTestExtension(USER_SCRIPT, GURL(kValidUpdateUrl1), GURL(), 1117 MakeSyncTestExtension(USER_SCRIPT, GURL(kValidUpdateUrl1), GURL(),
1110 Extension::INTERNAL, 0, FilePath(), 1118 Extension::INTERNAL, 0, FilePath(),
1111 Extension::NO_FLAGS)); 1119 Extension::NO_FLAGS));
1112 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1120 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1113 } 1121 }
1114 1122
1115 TEST(ExtensionTest, GetSyncTypeUserScriptNoUpdateUrl) { 1123 TEST_F(ExtensionTest, GetSyncTypeUserScriptNoUpdateUrl) {
1116 scoped_refptr<Extension> extension( 1124 scoped_refptr<Extension> extension(
1117 MakeSyncTestExtension(USER_SCRIPT, GURL(), GURL(), 1125 MakeSyncTestExtension(USER_SCRIPT, GURL(), GURL(),
1118 Extension::INTERNAL, 0, FilePath(), 1126 Extension::INTERNAL, 0, FilePath(),
1119 Extension::NO_FLAGS)); 1127 Extension::NO_FLAGS));
1120 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1128 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1121 } 1129 }
1122 1130
1123 TEST(ExtensionTest, GetSyncTypeThemeNoUpdateUrl) { 1131 TEST_F(ExtensionTest, GetSyncTypeThemeNoUpdateUrl) {
1124 scoped_refptr<Extension> extension( 1132 scoped_refptr<Extension> extension(
1125 MakeSyncTestExtension(THEME, GURL(), GURL(), 1133 MakeSyncTestExtension(THEME, GURL(), GURL(),
1126 Extension::INTERNAL, 0, FilePath(), 1134 Extension::INTERNAL, 0, FilePath(),
1127 Extension::NO_FLAGS)); 1135 Extension::NO_FLAGS));
1128 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1136 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1129 } 1137 }
1130 1138
1131 TEST(ExtensionTest, GetSyncTypeExtensionWithLaunchUrl) { 1139 TEST_F(ExtensionTest, GetSyncTypeExtensionWithLaunchUrl) {
1132 scoped_refptr<Extension> extension( 1140 scoped_refptr<Extension> extension(
1133 MakeSyncTestExtension(EXTENSION, GURL(), GURL("http://www.google.com"), 1141 MakeSyncTestExtension(EXTENSION, GURL(), GURL("http://www.google.com"),
1134 Extension::INTERNAL, 0, FilePath(), 1142 Extension::INTERNAL, 0, FilePath(),
1135 Extension::NO_FLAGS)); 1143 Extension::NO_FLAGS));
1136 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1144 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1137 } 1145 }
1138 1146
1139 TEST(ExtensionTest, GetSyncTypeExtensionExternal) { 1147 TEST_F(ExtensionTest, GetSyncTypeExtensionExternal) {
1140 scoped_refptr<Extension> extension( 1148 scoped_refptr<Extension> extension(
1141 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1149 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1142 Extension::EXTERNAL_PREF, 0, FilePath(), 1150 Extension::EXTERNAL_PREF, 0, FilePath(),
1143 Extension::NO_FLAGS)); 1151 Extension::NO_FLAGS));
1144 1152
1145 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1153 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1146 } 1154 }
1147 1155
1148 TEST(ExtensionTest, GetSyncTypeUserScriptThirdPartyUpdateUrl) { 1156 TEST_F(ExtensionTest, GetSyncTypeUserScriptThirdPartyUpdateUrl) {
1149 scoped_refptr<Extension> extension( 1157 scoped_refptr<Extension> extension(
1150 MakeSyncTestExtension( 1158 MakeSyncTestExtension(
1151 USER_SCRIPT, GURL("http://third-party.update_url.com"), GURL(), 1159 USER_SCRIPT, GURL("http://third-party.update_url.com"), GURL(),
1152 Extension::INTERNAL, 0, FilePath(), Extension::NO_FLAGS)); 1160 Extension::INTERNAL, 0, FilePath(), Extension::NO_FLAGS));
1153 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1161 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1154 } 1162 }
1155 1163
1156 TEST(ExtensionTest, OnlyDisplayAppsInLauncher) { 1164 TEST_F(ExtensionTest, OnlyDisplayAppsInLauncher) {
1157 scoped_refptr<Extension> extension( 1165 scoped_refptr<Extension> extension(
1158 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1166 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1159 Extension::INTERNAL, 0, FilePath(), 1167 Extension::INTERNAL, 0, FilePath(),
1160 Extension::NO_FLAGS)); 1168 Extension::NO_FLAGS));
1161 1169
1162 EXPECT_FALSE(extension->ShouldDisplayInAppLauncher()); 1170 EXPECT_FALSE(extension->ShouldDisplayInAppLauncher());
1163 EXPECT_FALSE(extension->ShouldDisplayInNewTabPage()); 1171 EXPECT_FALSE(extension->ShouldDisplayInNewTabPage());
1164 1172
1165 scoped_refptr<Extension> app( 1173 scoped_refptr<Extension> app(
1166 MakeSyncTestExtension(APP, GURL(), GURL("http://www.google.com"), 1174 MakeSyncTestExtension(APP, GURL(), GURL("http://www.google.com"),
1167 Extension::INTERNAL, 0, FilePath(), 1175 Extension::INTERNAL, 0, FilePath(),
1168 Extension::NO_FLAGS)); 1176 Extension::NO_FLAGS));
1169 EXPECT_TRUE(app->ShouldDisplayInAppLauncher()); 1177 EXPECT_TRUE(app->ShouldDisplayInAppLauncher());
1170 EXPECT_TRUE(app->ShouldDisplayInNewTabPage()); 1178 EXPECT_TRUE(app->ShouldDisplayInNewTabPage());
1171 } 1179 }
1172 1180
1173 TEST(ExtensionTest, DisplayInXManifestProperties) { 1181 TEST_F(ExtensionTest, DisplayInXManifestProperties) {
1174 DictionaryValue manifest; 1182 DictionaryValue manifest;
1175 manifest.SetString(keys::kName, "TestComponentApp"); 1183 manifest.SetString(keys::kName, "TestComponentApp");
1176 manifest.SetString(keys::kVersion, "0.0.0.0"); 1184 manifest.SetString(keys::kVersion, "0.0.0.0");
1177 manifest.SetString(keys::kApp, "true"); 1185 manifest.SetString(keys::kApp, "true");
1178 manifest.SetString(keys::kPlatformAppBackgroundPage, ""); 1186 manifest.SetString(keys::kPlatformAppBackgroundPage, "");
1179 1187
1180 std::string error; 1188 std::string error;
1181 scoped_refptr<Extension> app; 1189 scoped_refptr<Extension> app;
1182 1190
1183 // Default to true. 1191 // Default to true.
(...skipping 28 matching lines...) Expand all
1212 EXPECT_TRUE(app->ShouldDisplayInAppLauncher()); 1220 EXPECT_TRUE(app->ShouldDisplayInAppLauncher());
1213 EXPECT_FALSE(app->ShouldDisplayInNewTabPage()); 1221 EXPECT_FALSE(app->ShouldDisplayInNewTabPage());
1214 1222
1215 // Error checking. 1223 // Error checking.
1216 manifest.SetString(keys::kDisplayInNewTabPage, "invalid"); 1224 manifest.SetString(keys::kDisplayInNewTabPage, "invalid");
1217 app = Extension::Create( 1225 app = Extension::Create(
1218 FilePath(), Extension::COMPONENT, manifest, 0, &error); 1226 FilePath(), Extension::COMPONENT, manifest, 0, &error);
1219 EXPECT_EQ(error, std::string(errors::kInvalidDisplayInNewTabPage)); 1227 EXPECT_EQ(error, std::string(errors::kInvalidDisplayInNewTabPage));
1220 } 1228 }
1221 1229
1222 TEST(ExtensionTest, OnlySyncInternal) { 1230 TEST_F(ExtensionTest, OnlySyncInternal) {
1223 scoped_refptr<Extension> extension_internal( 1231 scoped_refptr<Extension> extension_internal(
1224 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1232 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1225 Extension::INTERNAL, 0, FilePath(), 1233 Extension::INTERNAL, 0, FilePath(),
1226 Extension::NO_FLAGS)); 1234 Extension::NO_FLAGS));
1227 EXPECT_TRUE(extension_internal->IsSyncable()); 1235 EXPECT_TRUE(extension_internal->IsSyncable());
1228 1236
1229 scoped_refptr<Extension> extension_noninternal( 1237 scoped_refptr<Extension> extension_noninternal(
1230 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1238 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1231 Extension::COMPONENT, 0, FilePath(), 1239 Extension::COMPONENT, 0, FilePath(),
1232 Extension::NO_FLAGS)); 1240 Extension::NO_FLAGS));
1233 EXPECT_FALSE(extension_noninternal->IsSyncable()); 1241 EXPECT_FALSE(extension_noninternal->IsSyncable());
1234 } 1242 }
1235 1243
1236 TEST(ExtensionTest, DontSyncDefault) { 1244 TEST_F(ExtensionTest, DontSyncDefault) {
1237 scoped_refptr<Extension> extension_default( 1245 scoped_refptr<Extension> extension_default(
1238 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1246 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1239 Extension::INTERNAL, 0, FilePath(), 1247 Extension::INTERNAL, 0, FilePath(),
1240 Extension::WAS_INSTALLED_BY_DEFAULT)); 1248 Extension::WAS_INSTALLED_BY_DEFAULT));
1241 EXPECT_FALSE(extension_default->IsSyncable()); 1249 EXPECT_FALSE(extension_default->IsSyncable());
1242 } 1250 }
1243 1251
1244 TEST(ExtensionTest, OptionalOnlyPermission) { 1252 TEST_F(ExtensionTest, OptionalOnlyPermission) {
1245 // Set feature current channel to dev because the only permission that must 1253 // Set feature current channel to dev because the only permission that must
1246 // be optional (usbDevices) is only available on dev channel. 1254 // be optional (usbDevices) is only available on dev channel.
1247 Feature::ScopedCurrentChannel scoped_channel( 1255 Feature::ScopedCurrentChannel scoped_channel(
1248 chrome::VersionInfo::CHANNEL_DEV); 1256 chrome::VersionInfo::CHANNEL_DEV);
1249 1257
1250 scoped_refptr<Extension> extension; 1258 scoped_refptr<Extension> extension;
1251 std::string error; 1259 std::string error;
1252 extension = LoadManifestUnchecked("optional_only_permission", 1260 extension = LoadManifestUnchecked("optional_only_permission",
1253 "manifest1.json", 1261 "manifest1.json",
1254 Extension::INTERNAL, Extension::NO_FLAGS, 1262 Extension::INTERNAL, Extension::NO_FLAGS,
1255 &error); 1263 &error);
1256 EXPECT_TRUE(extension == NULL); 1264 EXPECT_TRUE(extension == NULL);
1257 ASSERT_EQ(ErrorUtils::FormatErrorMessage( 1265 ASSERT_EQ(ErrorUtils::FormatErrorMessage(
1258 errors::kPermissionMustBeOptional, "usbDevices"), error); 1266 errors::kPermissionMustBeOptional, "usbDevices"), error);
1259 1267
1260 error.clear(); 1268 error.clear();
1261 extension = LoadManifestUnchecked("optional_only_permission", 1269 extension = LoadManifestUnchecked("optional_only_permission",
1262 "manifest2.json", 1270 "manifest2.json",
1263 Extension::INTERNAL, Extension::NO_FLAGS, 1271 Extension::INTERNAL, Extension::NO_FLAGS,
1264 &error); 1272 &error);
1265 EXPECT_TRUE(extension != NULL); 1273 EXPECT_TRUE(extension != NULL);
1266 EXPECT_TRUE(error.empty()); 1274 EXPECT_TRUE(error.empty());
1267 } 1275 }
1268 1276
1269 // These last 2 tests don't make sense on Chrome OS, where extension plugins 1277 // These last 2 tests don't make sense on Chrome OS, where extension plugins
1270 // are not allowed. 1278 // are not allowed.
1271 #if !defined(OS_CHROMEOS) 1279 #if !defined(OS_CHROMEOS)
1272 TEST(ExtensionTest, GetSyncTypeExtensionWithPlugin) { 1280 TEST_F(ExtensionTest, GetSyncTypeExtensionWithPlugin) {
1273 scoped_refptr<Extension> extension( 1281 scoped_refptr<Extension> extension(
1274 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1282 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1275 Extension::INTERNAL, 1, FilePath(), 1283 Extension::INTERNAL, 1, FilePath(),
1276 Extension::NO_FLAGS)); 1284 Extension::NO_FLAGS));
1277 if (extension) 1285 if (extension)
1278 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1286 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1279 } 1287 }
1280 1288
1281 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { 1289 TEST_F(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) {
1282 scoped_refptr<Extension> extension( 1290 scoped_refptr<Extension> extension(
1283 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1291 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1284 Extension::INTERNAL, 2, FilePath(), 1292 Extension::INTERNAL, 2, FilePath(),
1285 Extension::NO_FLAGS)); 1293 Extension::NO_FLAGS));
1286 if (extension) 1294 if (extension)
1287 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1295 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1288 } 1296 }
1289 #endif // !defined(OS_CHROMEOS) 1297 #endif // !defined(OS_CHROMEOS)
1290 1298
1291 } // namespace extensions 1299 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | chrome/common/extensions/manifest_tests/extension_manifests_command_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698