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

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

Issue 11724002: Move ContentScripts out of Extension (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_unref_browser_action
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/content_scripts/content_scripts_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 testing::Test::SetUp();
128 ManifestHandler::Register(extension_manifest_keys::kContentScripts,
129 new ContentScriptsHandler);
130 }
123 }; 131 };
124 132
125 // We persist location values in the preferences, so this is a sanity test that 133 // We persist location values in the preferences, so this is a sanity test that
126 // someone doesn't accidentally change them. 134 // someone doesn't accidentally change them.
127 TEST(ExtensionTest, LocationValuesTest) { 135 TEST_F(ExtensionTest, LocationValuesTest) {
128 ASSERT_EQ(0, Extension::INVALID); 136 ASSERT_EQ(0, Extension::INVALID);
129 ASSERT_EQ(1, Extension::INTERNAL); 137 ASSERT_EQ(1, Extension::INTERNAL);
130 ASSERT_EQ(2, Extension::EXTERNAL_PREF); 138 ASSERT_EQ(2, Extension::EXTERNAL_PREF);
131 ASSERT_EQ(3, Extension::EXTERNAL_REGISTRY); 139 ASSERT_EQ(3, Extension::EXTERNAL_REGISTRY);
132 ASSERT_EQ(4, Extension::LOAD); 140 ASSERT_EQ(4, Extension::LOAD);
133 ASSERT_EQ(5, Extension::COMPONENT); 141 ASSERT_EQ(5, Extension::COMPONENT);
134 ASSERT_EQ(6, Extension::EXTERNAL_PREF_DOWNLOAD); 142 ASSERT_EQ(6, Extension::EXTERNAL_PREF_DOWNLOAD);
135 ASSERT_EQ(7, Extension::EXTERNAL_POLICY_DOWNLOAD); 143 ASSERT_EQ(7, Extension::EXTERNAL_POLICY_DOWNLOAD);
136 } 144 }
137 145
138 TEST(ExtensionTest, LocationPriorityTest) { 146 TEST_F(ExtensionTest, LocationPriorityTest) {
139 for (int i = 0; i < Extension::NUM_LOCATIONS; i++) { 147 for (int i = 0; i < Extension::NUM_LOCATIONS; i++) {
140 Extension::Location loc = static_cast<Extension::Location>(i); 148 Extension::Location loc = static_cast<Extension::Location>(i);
141 149
142 // INVALID is not a valid location. 150 // INVALID is not a valid location.
143 if (loc == Extension::INVALID) 151 if (loc == Extension::INVALID)
144 continue; 152 continue;
145 153
146 // Comparing a location that has no rank will hit a CHECK. Do a 154 // 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. 155 // compare with every valid location, to be sure each one is covered.
148 156
(...skipping 16 matching lines...) Expand all
165 Extension::GetHigherPriorityLocation( 173 Extension::GetHigherPriorityLocation(
166 Extension::EXTERNAL_POLICY_DOWNLOAD, 174 Extension::EXTERNAL_POLICY_DOWNLOAD,
167 Extension::EXTERNAL_PREF)); 175 Extension::EXTERNAL_PREF));
168 176
169 ASSERT_EQ(Extension::EXTERNAL_PREF, 177 ASSERT_EQ(Extension::EXTERNAL_PREF,
170 Extension::GetHigherPriorityLocation( 178 Extension::GetHigherPriorityLocation(
171 Extension::INTERNAL, 179 Extension::INTERNAL,
172 Extension::EXTERNAL_PREF)); 180 Extension::EXTERNAL_PREF));
173 } 181 }
174 182
175 TEST(ExtensionTest, GetResourceURLAndPath) { 183 TEST_F(ExtensionTest, GetResourceURLAndPath) {
176 scoped_refptr<Extension> extension = LoadManifestStrict("empty_manifest", 184 scoped_refptr<Extension> extension = LoadManifestStrict("empty_manifest",
177 "empty.json"); 185 "empty.json");
178 EXPECT_TRUE(extension.get()); 186 EXPECT_TRUE(extension.get());
179 187
180 EXPECT_EQ(extension->url().spec() + "bar/baz.js", 188 EXPECT_EQ(extension->url().spec() + "bar/baz.js",
181 Extension::GetResourceURL(extension->url(), "bar/baz.js").spec()); 189 Extension::GetResourceURL(extension->url(), "bar/baz.js").spec());
182 EXPECT_EQ(extension->url().spec() + "baz.js", 190 EXPECT_EQ(extension->url().spec() + "baz.js",
183 Extension::GetResourceURL(extension->url(), 191 Extension::GetResourceURL(extension->url(),
184 "bar/../baz.js").spec()); 192 "bar/../baz.js").spec());
185 EXPECT_EQ(extension->url().spec() + "baz.js", 193 EXPECT_EQ(extension->url().spec() + "baz.js",
186 Extension::GetResourceURL(extension->url(), "../baz.js").spec()); 194 Extension::GetResourceURL(extension->url(), "../baz.js").spec());
187 195
188 // Test that absolute-looking paths ("/"-prefixed) are pasted correctly. 196 // Test that absolute-looking paths ("/"-prefixed) are pasted correctly.
189 EXPECT_EQ(extension->url().spec() + "test.html", 197 EXPECT_EQ(extension->url().spec() + "test.html",
190 extension->GetResourceURL("/test.html").spec()); 198 extension->GetResourceURL("/test.html").spec());
191 } 199 }
192 200
193 TEST(ExtensionTest, GetAbsolutePathNoError) { 201 TEST_F(ExtensionTest, GetAbsolutePathNoError) {
194 scoped_refptr<Extension> extension = LoadManifestStrict("absolute_path", 202 scoped_refptr<Extension> extension = LoadManifestStrict("absolute_path",
195 "absolute.json"); 203 "absolute.json");
196 EXPECT_TRUE(extension.get()); 204 EXPECT_TRUE(extension.get());
197 std::string err; 205 std::string err;
198 Extension::InstallWarningVector warnings; 206 Extension::InstallWarningVector warnings;
199 EXPECT_TRUE(extension_file_util::ValidateExtension(extension.get(), 207 EXPECT_TRUE(extension_file_util::ValidateExtension(extension.get(),
200 &err, &warnings)); 208 &err, &warnings));
201 EXPECT_EQ(0U, warnings.size()); 209 EXPECT_EQ(0U, warnings.size());
202 210
203 EXPECT_EQ(extension->path().AppendASCII("test.html").value(), 211 EXPECT_EQ(extension->path().AppendASCII("test.html").value(),
204 extension->GetResource("test.html").GetFilePath().value()); 212 extension->GetResource("test.html").GetFilePath().value());
205 EXPECT_EQ(extension->path().AppendASCII("test.js").value(), 213 EXPECT_EQ(extension->path().AppendASCII("test.js").value(),
206 extension->GetResource("test.js").GetFilePath().value()); 214 extension->GetResource("test.js").GetFilePath().value());
207 } 215 }
208 216
209 TEST(ExtensionTest, LoadPageActionHelper) { 217 TEST_F(ExtensionTest, LoadPageActionHelper) {
210 scoped_ptr<ActionInfo> action; 218 scoped_ptr<ActionInfo> action;
211 219
212 // First try with an empty dictionary. 220 // First try with an empty dictionary.
213 action = LoadAction("page_action_empty.json"); 221 action = LoadAction("page_action_empty.json");
214 ASSERT_TRUE(action != NULL); 222 ASSERT_TRUE(action != NULL);
215 223
216 // Now setup some values to use in the action. 224 // Now setup some values to use in the action.
217 const std::string id("MyExtensionActionId"); 225 const std::string id("MyExtensionActionId");
218 const std::string name("MyExtensionActionName"); 226 const std::string name("MyExtensionActionName");
219 std::string img1("image1.png"); 227 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. 314 // Setting popup to "" is the same as having no popup.
307 action = LoadAction("page_action_empty_popup.json"); 315 action = LoadAction("page_action_empty_popup.json");
308 316
309 ASSERT_TRUE(NULL != action.get()); 317 ASSERT_TRUE(NULL != action.get());
310 EXPECT_TRUE(action->default_popup_url.is_empty()); 318 EXPECT_TRUE(action->default_popup_url.is_empty());
311 ASSERT_STREQ( 319 ASSERT_STREQ(
312 "", 320 "",
313 action->default_popup_url.spec().c_str()); 321 action->default_popup_url.spec().c_str());
314 } 322 }
315 323
316 TEST(ExtensionTest, IdIsValid) { 324 TEST_F(ExtensionTest, IdIsValid) {
317 EXPECT_TRUE(Extension::IdIsValid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); 325 EXPECT_TRUE(Extension::IdIsValid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
318 EXPECT_TRUE(Extension::IdIsValid("pppppppppppppppppppppppppppppppp")); 326 EXPECT_TRUE(Extension::IdIsValid("pppppppppppppppppppppppppppppppp"));
319 EXPECT_TRUE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnop")); 327 EXPECT_TRUE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnop"));
320 EXPECT_TRUE(Extension::IdIsValid("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP")); 328 EXPECT_TRUE(Extension::IdIsValid("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"));
321 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno")); 329 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno"));
322 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnopa")); 330 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnopa"));
323 EXPECT_FALSE(Extension::IdIsValid("0123456789abcdef0123456789abcdef")); 331 EXPECT_FALSE(Extension::IdIsValid("0123456789abcdef0123456789abcdef"));
324 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnoq")); 332 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmnoq"));
325 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno0")); 333 EXPECT_FALSE(Extension::IdIsValid("abcdefghijklmnopabcdefghijklmno0"));
326 } 334 }
327 335
328 TEST(ExtensionTest, GenerateID) { 336 TEST_F(ExtensionTest, GenerateID) {
329 const uint8 public_key_info[] = { 337 const uint8 public_key_info[] = {
330 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 338 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, 339 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, 340 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, 341 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, 342 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, 343 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, 344 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, 345 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, 346 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, 347 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, 348 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, 349 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, 350 0x53, 0x56, 0xa6, 0x83, 0xa2, 0xce, 0x93, 0x93, 0xe7, 0x1f, 0x0f, 0xe6,
343 0x0f, 0x02, 0x03, 0x01, 0x00, 0x01 351 0x0f, 0x02, 0x03, 0x01, 0x00, 0x01
344 }; 352 };
345 353
346 std::string extension_id; 354 std::string extension_id;
347 EXPECT_TRUE( 355 EXPECT_TRUE(
348 Extension::GenerateId( 356 Extension::GenerateId(
349 std::string(reinterpret_cast<const char*>(&public_key_info[0]), 357 std::string(reinterpret_cast<const char*>(&public_key_info[0]),
350 arraysize(public_key_info)), 358 arraysize(public_key_info)),
351 &extension_id)); 359 &extension_id));
352 EXPECT_EQ("melddjfinppjdikinhbgehiennejpfhp", extension_id); 360 EXPECT_EQ("melddjfinppjdikinhbgehiennejpfhp", extension_id);
353 } 361 }
354 362
355 // This test ensures that the mimetype sniffing code stays in sync with the 363 // 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. 364 // actual crx files that we test other parts of the system with.
357 TEST(ExtensionTest, MimeTypeSniffing) { 365 TEST_F(ExtensionTest, MimeTypeSniffing) {
358 FilePath path; 366 FilePath path;
359 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); 367 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
360 path = path.AppendASCII("extensions").AppendASCII("good.crx"); 368 path = path.AppendASCII("extensions").AppendASCII("good.crx");
361 369
362 std::string data; 370 std::string data;
363 ASSERT_TRUE(file_util::ReadFileToString(path, &data)); 371 ASSERT_TRUE(file_util::ReadFileToString(path, &data));
364 372
365 std::string result; 373 std::string result;
366 EXPECT_TRUE(net::SniffMimeType(data.c_str(), data.size(), 374 EXPECT_TRUE(net::SniffMimeType(data.c_str(), data.size(),
367 GURL("http://www.example.com/foo.crx"), "", &result)); 375 GURL("http://www.example.com/foo.crx"), "", &result));
368 EXPECT_EQ(std::string(Extension::kMimeType), result); 376 EXPECT_EQ(std::string(Extension::kMimeType), result);
369 377
370 data.clear(); 378 data.clear();
371 result.clear(); 379 result.clear();
372 path = path.DirName().AppendASCII("bad_magic.crx"); 380 path = path.DirName().AppendASCII("bad_magic.crx");
373 ASSERT_TRUE(file_util::ReadFileToString(path, &data)); 381 ASSERT_TRUE(file_util::ReadFileToString(path, &data));
374 EXPECT_TRUE(net::SniffMimeType(data.c_str(), data.size(), 382 EXPECT_TRUE(net::SniffMimeType(data.c_str(), data.size(),
375 GURL("http://www.example.com/foo.crx"), "", &result)); 383 GURL("http://www.example.com/foo.crx"), "", &result));
376 EXPECT_EQ("application/octet-stream", result); 384 EXPECT_EQ("application/octet-stream", result);
377 } 385 }
378 386
379 TEST(ExtensionTest, EffectiveHostPermissions) { 387 TEST_F(ExtensionTest, EffectiveHostPermissions) {
380 scoped_refptr<Extension> extension; 388 scoped_refptr<Extension> extension;
381 URLPatternSet hosts; 389 URLPatternSet hosts;
382 390
383 extension = LoadManifest("effective_host_permissions", "empty.json"); 391 extension = LoadManifest("effective_host_permissions", "empty.json");
384 EXPECT_EQ(0u, extension->GetEffectiveHostPermissions().patterns().size()); 392 EXPECT_EQ(0u, extension->GetEffectiveHostPermissions().patterns().size());
385 EXPECT_FALSE(hosts.MatchesURL(GURL("http://www.google.com"))); 393 EXPECT_FALSE(hosts.MatchesURL(GURL("http://www.google.com")));
386 EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts()); 394 EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts());
387 395
388 extension = LoadManifest("effective_host_permissions", "one_host.json"); 396 extension = LoadManifest("effective_host_permissions", "one_host.json");
389 hosts = extension->GetEffectiveHostPermissions(); 397 hosts = extension->GetEffectiveHostPermissions();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 454
447 static bool CheckSocketPermission(scoped_refptr<Extension> extension, 455 static bool CheckSocketPermission(scoped_refptr<Extension> extension,
448 SocketPermissionRequest::OperationType type, 456 SocketPermissionRequest::OperationType type,
449 const char* host, 457 const char* host,
450 int port) { 458 int port) {
451 SocketPermission::CheckParam param(type, host, port); 459 SocketPermission::CheckParam param(type, host, port);
452 return extension->CheckAPIPermissionWithParam( 460 return extension->CheckAPIPermissionWithParam(
453 APIPermission::kSocket, &param); 461 APIPermission::kSocket, &param);
454 } 462 }
455 463
456 TEST(ExtensionTest, SocketPermissions) { 464 TEST_F(ExtensionTest, SocketPermissions) {
457 // Set feature current channel to appropriate value. 465 // Set feature current channel to appropriate value.
458 Feature::ScopedCurrentChannel scoped_channel( 466 Feature::ScopedCurrentChannel scoped_channel(
459 chrome::VersionInfo::CHANNEL_DEV); 467 chrome::VersionInfo::CHANNEL_DEV);
460 scoped_refptr<Extension> extension; 468 scoped_refptr<Extension> extension;
461 std::string error; 469 std::string error;
462 470
463 extension = LoadManifest("socket_permissions", "empty.json"); 471 extension = LoadManifest("socket_permissions", "empty.json");
464 EXPECT_FALSE(CheckSocketPermission(extension, 472 EXPECT_FALSE(CheckSocketPermission(extension,
465 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); 473 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80));
466 474
(...skipping 26 matching lines...) Expand all
493 return skia::ImageOperations::Resize(source, 501 return skia::ImageOperations::Resize(source,
494 skia::ImageOperations::RESIZE_LANCZOS3, 502 skia::ImageOperations::RESIZE_LANCZOS3,
495 size, 503 size,
496 size); 504 size);
497 } 505 }
498 506
499 static bool SizeEquals(const SkBitmap& bitmap, const gfx::Size& size) { 507 static bool SizeEquals(const SkBitmap& bitmap, const gfx::Size& size) {
500 return bitmap.width() == size.width() && bitmap.height() == size.height(); 508 return bitmap.width() == size.width() && bitmap.height() == size.height();
501 } 509 }
502 510
503 TEST(ExtensionTest, ImageCaching) { 511 TEST_F(ExtensionTest, ImageCaching) {
504 FilePath path; 512 FilePath path;
505 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); 513 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
506 path = path.AppendASCII("extensions"); 514 path = path.AppendASCII("extensions");
507 515
508 // Initialize the Extension. 516 // Initialize the Extension.
509 std::string errors; 517 std::string errors;
510 DictionaryValue values; 518 DictionaryValue values;
511 values.SetString(keys::kName, "test"); 519 values.SetString(keys::kName, "test");
512 values.SetString(keys::kVersion, "0.1"); 520 values.SetString(keys::kVersion, "0.1");
513 scoped_refptr<Extension> extension(Extension::Create( 521 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), 575 EXPECT_TRUE(SizeEquals(extension->GetCachedImage(resource, original_size),
568 original_size)); 576 original_size));
569 EXPECT_TRUE(SizeEquals(extension->GetCachedImage(resource, size128), 577 EXPECT_TRUE(SizeEquals(extension->GetCachedImage(resource, size128),
570 original_size)); 578 original_size));
571 EXPECT_EQ(extension->GetCachedImage(resource, original_size).getPixels(), 579 EXPECT_EQ(extension->GetCachedImage(resource, original_size).getPixels(),
572 extension->GetCachedImage(resource, size128).getPixels()); 580 extension->GetCachedImage(resource, size128).getPixels());
573 } 581 }
574 582
575 // This tests the API permissions with an empty manifest (one that just 583 // This tests the API permissions with an empty manifest (one that just
576 // specifies a name and a version and nothing else). 584 // specifies a name and a version and nothing else).
577 TEST(ExtensionTest, ApiPermissions) { 585 TEST_F(ExtensionTest, ApiPermissions) {
578 const struct { 586 const struct {
579 const char* permission_name; 587 const char* permission_name;
580 bool expect_success; 588 bool expect_success;
581 } kTests[] = { 589 } kTests[] = {
582 // Negative test. 590 // Negative test.
583 { "non_existing_permission", false }, 591 { "non_existing_permission", false },
584 // Test default module/package permission. 592 // Test default module/package permission.
585 { "browserAction", true }, 593 { "browserAction", true },
586 { "devtools", true }, 594 { "devtools", true },
587 { "extension", true }, 595 { "extension", true },
(...skipping 24 matching lines...) Expand all
612 scoped_refptr<Extension> extension; 620 scoped_refptr<Extension> extension;
613 extension = LoadManifest("empty_manifest", "empty.json"); 621 extension = LoadManifest("empty_manifest", "empty.json");
614 622
615 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { 623 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) {
616 EXPECT_EQ(kTests[i].expect_success, 624 EXPECT_EQ(kTests[i].expect_success,
617 extension->HasAPIPermission(kTests[i].permission_name)) 625 extension->HasAPIPermission(kTests[i].permission_name))
618 << "Permission being tested: " << kTests[i].permission_name; 626 << "Permission being tested: " << kTests[i].permission_name;
619 } 627 }
620 } 628 }
621 629
622 TEST(ExtensionTest, GetPermissionMessages_ManyApiPermissions) { 630 TEST_F(ExtensionTest, GetPermissionMessages_ManyApiPermissions) {
623 scoped_refptr<Extension> extension; 631 scoped_refptr<Extension> extension;
624 extension = LoadManifest("permissions", "many-apis.json"); 632 extension = LoadManifest("permissions", "many-apis.json");
625 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 633 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
626 ASSERT_EQ(6u, warnings.size()); 634 ASSERT_EQ(6u, warnings.size());
627 EXPECT_EQ("Access your data on api.flickr.com", 635 EXPECT_EQ("Access your data on api.flickr.com",
628 UTF16ToUTF8(warnings[0])); 636 UTF16ToUTF8(warnings[0]));
629 EXPECT_EQ("Read and modify your bookmarks", UTF16ToUTF8(warnings[1])); 637 EXPECT_EQ("Read and modify your bookmarks", UTF16ToUTF8(warnings[1]));
630 EXPECT_EQ("Detect your physical location", UTF16ToUTF8(warnings[2])); 638 EXPECT_EQ("Detect your physical location", UTF16ToUTF8(warnings[2]));
631 EXPECT_EQ("Read and modify your browsing history", UTF16ToUTF8(warnings[3])); 639 EXPECT_EQ("Read and modify your browsing history", UTF16ToUTF8(warnings[3]));
632 EXPECT_EQ("Access your tabs and browsing activity", UTF16ToUTF8(warnings[4])); 640 EXPECT_EQ("Access your tabs and browsing activity", UTF16ToUTF8(warnings[4]));
633 EXPECT_EQ("Manage your apps, extensions, and themes", 641 EXPECT_EQ("Manage your apps, extensions, and themes",
634 UTF16ToUTF8(warnings[5])); 642 UTF16ToUTF8(warnings[5]));
635 } 643 }
636 644
637 TEST(ExtensionTest, GetPermissionMessages_ManyHosts) { 645 TEST_F(ExtensionTest, GetPermissionMessages_ManyHosts) {
638 scoped_refptr<Extension> extension; 646 scoped_refptr<Extension> extension;
639 extension = LoadManifest("permissions", "many-hosts.json"); 647 extension = LoadManifest("permissions", "many-hosts.json");
640 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 648 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
641 ASSERT_EQ(1u, warnings.size()); 649 ASSERT_EQ(1u, warnings.size());
642 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", 650 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com",
643 UTF16ToUTF8(warnings[0])); 651 UTF16ToUTF8(warnings[0]));
644 } 652 }
645 653
646 TEST(ExtensionTest, GetPermissionMessages_Plugins) { 654 TEST_F(ExtensionTest, GetPermissionMessages_Plugins) {
647 scoped_refptr<Extension> extension; 655 scoped_refptr<Extension> extension;
648 extension = LoadManifest("permissions", "plugins.json"); 656 extension = LoadManifest("permissions", "plugins.json");
649 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 657 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
650 // We don't parse the plugins key on Chrome OS, so it should not ask for any 658 // We don't parse the plugins key on Chrome OS, so it should not ask for any
651 // permissions. 659 // permissions.
652 #if defined(OS_CHROMEOS) 660 #if defined(OS_CHROMEOS)
653 ASSERT_EQ(0u, warnings.size()); 661 ASSERT_EQ(0u, warnings.size());
654 #else 662 #else
655 ASSERT_EQ(1u, warnings.size()); 663 ASSERT_EQ(1u, warnings.size());
656 EXPECT_EQ("Access all data on your computer and the websites you visit", 664 EXPECT_EQ("Access all data on your computer and the websites you visit",
657 UTF16ToUTF8(warnings[0])); 665 UTF16ToUTF8(warnings[0]));
658 #endif 666 #endif
659 } 667 }
660 668
661 TEST(ExtensionTest, WantsFileAccess) { 669 TEST_F(ExtensionTest, WantsFileAccess) {
662 scoped_refptr<Extension> extension; 670 scoped_refptr<Extension> extension;
663 GURL file_url("file:///etc/passwd"); 671 GURL file_url("file:///etc/passwd");
664 672
665 // <all_urls> permission 673 // <all_urls> permission
666 extension = LoadManifest("permissions", "permissions_all_urls.json"); 674 extension = LoadManifest("permissions", "permissions_all_urls.json");
667 EXPECT_TRUE(extension->wants_file_access()); 675 EXPECT_TRUE(extension->wants_file_access());
668 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 676 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
669 file_url, file_url, -1, NULL, NULL)); 677 file_url, file_url, -1, NULL, NULL));
670 extension = LoadManifest( 678 extension = LoadManifest(
671 "permissions", "permissions_all_urls.json", Extension::ALLOW_FILE_ACCESS); 679 "permissions", "permissions_all_urls.json", Extension::ALLOW_FILE_ACCESS);
(...skipping 20 matching lines...) Expand all
692 extension = LoadManifest("permissions", "permissions_http_scheme.json", 700 extension = LoadManifest("permissions", "permissions_http_scheme.json",
693 Extension::ALLOW_FILE_ACCESS); 701 Extension::ALLOW_FILE_ACCESS);
694 EXPECT_FALSE(extension->wants_file_access()); 702 EXPECT_FALSE(extension->wants_file_access());
695 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 703 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
696 file_url, file_url, -1, NULL, NULL)); 704 file_url, file_url, -1, NULL, NULL));
697 705
698 // <all_urls> content script match 706 // <all_urls> content script match
699 extension = LoadManifest("permissions", "content_script_all_urls.json"); 707 extension = LoadManifest("permissions", "content_script_all_urls.json");
700 EXPECT_TRUE(extension->wants_file_access()); 708 EXPECT_TRUE(extension->wants_file_access());
701 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 709 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
702 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 710 file_url,
711 file_url,
712 -1,
713 &ContentScriptsInfo::GetContentScripts(extension)[0],
714 NULL));
703 extension = LoadManifest("permissions", "content_script_all_urls.json", 715 extension = LoadManifest("permissions", "content_script_all_urls.json",
704 Extension::ALLOW_FILE_ACCESS); 716 Extension::ALLOW_FILE_ACCESS);
705 EXPECT_TRUE(extension->wants_file_access()); 717 EXPECT_TRUE(extension->wants_file_access());
706 EXPECT_TRUE(extension->CanExecuteScriptOnPage( 718 EXPECT_TRUE(extension->CanExecuteScriptOnPage(
707 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 719 file_url,
720 file_url,
721 -1,
722 &ContentScriptsInfo::GetContentScripts(extension)[0],
723 NULL));
708 724
709 // file:///* content script match 725 // file:///* content script match
710 extension = LoadManifest("permissions", "content_script_file_scheme.json"); 726 extension = LoadManifest("permissions", "content_script_file_scheme.json");
711 EXPECT_TRUE(extension->wants_file_access()); 727 EXPECT_TRUE(extension->wants_file_access());
712 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 728 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
713 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 729 file_url,
730 file_url,
731 -1,
732 &ContentScriptsInfo::GetContentScripts(extension)[0],
733 NULL));
714 extension = LoadManifest("permissions", "content_script_file_scheme.json", 734 extension = LoadManifest("permissions", "content_script_file_scheme.json",
715 Extension::ALLOW_FILE_ACCESS); 735 Extension::ALLOW_FILE_ACCESS);
716 EXPECT_TRUE(extension->wants_file_access()); 736 EXPECT_TRUE(extension->wants_file_access());
717 EXPECT_TRUE(extension->CanExecuteScriptOnPage( 737 EXPECT_TRUE(extension->CanExecuteScriptOnPage(
718 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 738 file_url,
739 file_url,
740 -1,
741 &ContentScriptsInfo::GetContentScripts(extension)[0],
742 NULL));
719 743
720 // http://* content script match 744 // http://* content script match
721 extension = LoadManifest("permissions", "content_script_http_scheme.json"); 745 extension = LoadManifest("permissions", "content_script_http_scheme.json");
722 EXPECT_FALSE(extension->wants_file_access()); 746 EXPECT_FALSE(extension->wants_file_access());
723 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 747 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
724 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 748 file_url,
749 file_url,
750 -1,
751 &ContentScriptsInfo::GetContentScripts(extension)[0],
752 NULL));
725 extension = LoadManifest("permissions", "content_script_http_scheme.json", 753 extension = LoadManifest("permissions", "content_script_http_scheme.json",
726 Extension::ALLOW_FILE_ACCESS); 754 Extension::ALLOW_FILE_ACCESS);
727 EXPECT_FALSE(extension->wants_file_access()); 755 EXPECT_FALSE(extension->wants_file_access());
728 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 756 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
729 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 757 file_url,
758 file_url,
759 -1,
760 &ContentScriptsInfo::GetContentScripts(extension)[0], NULL));
Yoyo Zhou 2013/01/04 00:13:30 NULL on a new line?
Devlin 2013/01/11 20:30:02 Done.
730 } 761 }
731 762
732 TEST(ExtensionTest, ExtraFlags) { 763 TEST_F(ExtensionTest, ExtraFlags) {
733 scoped_refptr<Extension> extension; 764 scoped_refptr<Extension> extension;
734 extension = LoadManifest("app", "manifest.json", Extension::FROM_WEBSTORE); 765 extension = LoadManifest("app", "manifest.json", Extension::FROM_WEBSTORE);
735 EXPECT_TRUE(extension->from_webstore()); 766 EXPECT_TRUE(extension->from_webstore());
736 767
737 extension = LoadManifest("app", "manifest.json", Extension::FROM_BOOKMARK); 768 extension = LoadManifest("app", "manifest.json", Extension::FROM_BOOKMARK);
738 EXPECT_TRUE(extension->from_bookmark()); 769 EXPECT_TRUE(extension->from_bookmark());
739 770
740 extension = LoadManifest("app", "manifest.json", Extension::NO_FLAGS); 771 extension = LoadManifest("app", "manifest.json", Extension::NO_FLAGS);
741 EXPECT_FALSE(extension->from_bookmark()); 772 EXPECT_FALSE(extension->from_bookmark());
742 EXPECT_FALSE(extension->from_webstore()); 773 EXPECT_FALSE(extension->from_webstore());
743 } 774 }
744 775
745 TEST(ExtensionTest, BrowserActionSynthesizesCommand) { 776 TEST_F(ExtensionTest, BrowserActionSynthesizesCommand) {
746 scoped_refptr<Extension> extension; 777 scoped_refptr<Extension> extension;
747 778
748 extension = LoadManifest("api_test/browser_action/synthesized", 779 extension = LoadManifest("api_test/browser_action/synthesized",
749 "manifest.json"); 780 "manifest.json");
750 // An extension with a browser action but no extension command specified 781 // An extension with a browser action but no extension command specified
751 // should get a command assigned to it. 782 // should get a command assigned to it.
752 const Command* command = extension->browser_action_command(); 783 const Command* command = extension->browser_action_command();
753 ASSERT_TRUE(command != NULL); 784 ASSERT_TRUE(command != NULL);
754 ASSERT_EQ(ui::VKEY_UNKNOWN, command->accelerator().key_code()); 785 ASSERT_EQ(ui::VKEY_UNKNOWN, command->accelerator().key_code());
755 } 786 }
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2)); 1047 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2));
1017 1048
1018 extension->ClearTabSpecificPermissions(1); 1049 extension->ClearTabSpecificPermissions(1);
1019 EXPECT_FALSE(extension->GetTabSpecificPermissions(1).get()); 1050 EXPECT_FALSE(extension->GetTabSpecificPermissions(1).get());
1020 1051
1021 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 0)); 1052 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 0));
1022 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 1)); 1053 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 1));
1023 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2)); 1054 EXPECT_TRUE(AllowedExclusivelyOnTab(extension, no_urls, 2));
1024 } 1055 }
1025 1056
1026 TEST(ExtensionTest, GenerateId) { 1057 TEST_F(ExtensionTest, GenerateId) {
1027 std::string result; 1058 std::string result;
1028 EXPECT_TRUE(Extension::GenerateId("", &result)); 1059 EXPECT_TRUE(Extension::GenerateId("", &result));
1029 1060
1030 EXPECT_TRUE(Extension::GenerateId("test", &result)); 1061 EXPECT_TRUE(Extension::GenerateId("test", &result));
1031 EXPECT_EQ(result, "jpignaibiiemhngfjkcpokkamffknabf"); 1062 EXPECT_EQ(result, "jpignaibiiemhngfjkcpokkamffknabf");
1032 1063
1033 EXPECT_TRUE(Extension::GenerateId("_", &result)); 1064 EXPECT_TRUE(Extension::GenerateId("_", &result));
1034 EXPECT_EQ(result, "ncocknphbhhlhkikpnnlmbcnbgdempcd"); 1065 EXPECT_EQ(result, "ncocknphbhhlhkikpnnlmbcnbgdempcd");
1035 1066
1036 EXPECT_TRUE(Extension::GenerateId( 1067 EXPECT_TRUE(Extension::GenerateId(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 EXPECT_EQ("", error); 1120 EXPECT_EQ("", error);
1090 return extension; 1121 return extension;
1091 } 1122 }
1092 1123
1093 static const char kValidUpdateUrl1[] = 1124 static const char kValidUpdateUrl1[] =
1094 "http://clients2.google.com/service/update2/crx"; 1125 "http://clients2.google.com/service/update2/crx";
1095 static const char kValidUpdateUrl2[] = 1126 static const char kValidUpdateUrl2[] =
1096 "https://clients2.google.com/service/update2/crx"; 1127 "https://clients2.google.com/service/update2/crx";
1097 } 1128 }
1098 1129
1099 TEST(ExtensionTest, GetSyncTypeNormalExtensionNoUpdateUrl) { 1130 TEST_F(ExtensionTest, GetSyncTypeNormalExtensionNoUpdateUrl) {
1100 scoped_refptr<Extension> extension( 1131 scoped_refptr<Extension> extension(
1101 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1132 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1102 Extension::INTERNAL, 0, FilePath(), 1133 Extension::INTERNAL, 0, FilePath(),
1103 Extension::NO_FLAGS)); 1134 Extension::NO_FLAGS));
1104 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1135 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1105 } 1136 }
1106 1137
1107 TEST(ExtensionTest, GetSyncTypeUserScriptValidUpdateUrl) { 1138 TEST_F(ExtensionTest, GetSyncTypeUserScriptValidUpdateUrl) {
1108 scoped_refptr<Extension> extension( 1139 scoped_refptr<Extension> extension(
1109 MakeSyncTestExtension(USER_SCRIPT, GURL(kValidUpdateUrl1), GURL(), 1140 MakeSyncTestExtension(USER_SCRIPT, GURL(kValidUpdateUrl1), GURL(),
1110 Extension::INTERNAL, 0, FilePath(), 1141 Extension::INTERNAL, 0, FilePath(),
1111 Extension::NO_FLAGS)); 1142 Extension::NO_FLAGS));
1112 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1143 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1113 } 1144 }
1114 1145
1115 TEST(ExtensionTest, GetSyncTypeUserScriptNoUpdateUrl) { 1146 TEST_F(ExtensionTest, GetSyncTypeUserScriptNoUpdateUrl) {
1116 scoped_refptr<Extension> extension( 1147 scoped_refptr<Extension> extension(
1117 MakeSyncTestExtension(USER_SCRIPT, GURL(), GURL(), 1148 MakeSyncTestExtension(USER_SCRIPT, GURL(), GURL(),
1118 Extension::INTERNAL, 0, FilePath(), 1149 Extension::INTERNAL, 0, FilePath(),
1119 Extension::NO_FLAGS)); 1150 Extension::NO_FLAGS));
1120 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1151 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1121 } 1152 }
1122 1153
1123 TEST(ExtensionTest, GetSyncTypeThemeNoUpdateUrl) { 1154 TEST_F(ExtensionTest, GetSyncTypeThemeNoUpdateUrl) {
1124 scoped_refptr<Extension> extension( 1155 scoped_refptr<Extension> extension(
1125 MakeSyncTestExtension(THEME, GURL(), GURL(), 1156 MakeSyncTestExtension(THEME, GURL(), GURL(),
1126 Extension::INTERNAL, 0, FilePath(), 1157 Extension::INTERNAL, 0, FilePath(),
1127 Extension::NO_FLAGS)); 1158 Extension::NO_FLAGS));
1128 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1159 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1129 } 1160 }
1130 1161
1131 TEST(ExtensionTest, GetSyncTypeExtensionWithLaunchUrl) { 1162 TEST_F(ExtensionTest, GetSyncTypeExtensionWithLaunchUrl) {
1132 scoped_refptr<Extension> extension( 1163 scoped_refptr<Extension> extension(
1133 MakeSyncTestExtension(EXTENSION, GURL(), GURL("http://www.google.com"), 1164 MakeSyncTestExtension(EXTENSION, GURL(), GURL("http://www.google.com"),
1134 Extension::INTERNAL, 0, FilePath(), 1165 Extension::INTERNAL, 0, FilePath(),
1135 Extension::NO_FLAGS)); 1166 Extension::NO_FLAGS));
1136 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1167 EXPECT_NE(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1137 } 1168 }
1138 1169
1139 TEST(ExtensionTest, GetSyncTypeExtensionExternal) { 1170 TEST_F(ExtensionTest, GetSyncTypeExtensionExternal) {
1140 scoped_refptr<Extension> extension( 1171 scoped_refptr<Extension> extension(
1141 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1172 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1142 Extension::EXTERNAL_PREF, 0, FilePath(), 1173 Extension::EXTERNAL_PREF, 0, FilePath(),
1143 Extension::NO_FLAGS)); 1174 Extension::NO_FLAGS));
1144 1175
1145 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1176 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1146 } 1177 }
1147 1178
1148 TEST(ExtensionTest, GetSyncTypeUserScriptThirdPartyUpdateUrl) { 1179 TEST_F(ExtensionTest, GetSyncTypeUserScriptThirdPartyUpdateUrl) {
1149 scoped_refptr<Extension> extension( 1180 scoped_refptr<Extension> extension(
1150 MakeSyncTestExtension( 1181 MakeSyncTestExtension(
1151 USER_SCRIPT, GURL("http://third-party.update_url.com"), GURL(), 1182 USER_SCRIPT, GURL("http://third-party.update_url.com"), GURL(),
1152 Extension::INTERNAL, 0, FilePath(), Extension::NO_FLAGS)); 1183 Extension::INTERNAL, 0, FilePath(), Extension::NO_FLAGS));
1153 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1184 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1154 } 1185 }
1155 1186
1156 TEST(ExtensionTest, OnlyDisplayAppsInLauncher) { 1187 TEST_F(ExtensionTest, OnlyDisplayAppsInLauncher) {
1157 scoped_refptr<Extension> extension( 1188 scoped_refptr<Extension> extension(
1158 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1189 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1159 Extension::INTERNAL, 0, FilePath(), 1190 Extension::INTERNAL, 0, FilePath(),
1160 Extension::NO_FLAGS)); 1191 Extension::NO_FLAGS));
1161 1192
1162 EXPECT_FALSE(extension->ShouldDisplayInAppLauncher()); 1193 EXPECT_FALSE(extension->ShouldDisplayInAppLauncher());
1163 EXPECT_FALSE(extension->ShouldDisplayInNewTabPage()); 1194 EXPECT_FALSE(extension->ShouldDisplayInNewTabPage());
1164 1195
1165 scoped_refptr<Extension> app( 1196 scoped_refptr<Extension> app(
1166 MakeSyncTestExtension(APP, GURL(), GURL("http://www.google.com"), 1197 MakeSyncTestExtension(APP, GURL(), GURL("http://www.google.com"),
1167 Extension::INTERNAL, 0, FilePath(), 1198 Extension::INTERNAL, 0, FilePath(),
1168 Extension::NO_FLAGS)); 1199 Extension::NO_FLAGS));
1169 EXPECT_TRUE(app->ShouldDisplayInAppLauncher()); 1200 EXPECT_TRUE(app->ShouldDisplayInAppLauncher());
1170 EXPECT_TRUE(app->ShouldDisplayInNewTabPage()); 1201 EXPECT_TRUE(app->ShouldDisplayInNewTabPage());
1171 } 1202 }
1172 1203
1173 TEST(ExtensionTest, DisplayInXManifestProperties) { 1204 TEST_F(ExtensionTest, DisplayInXManifestProperties) {
1174 DictionaryValue manifest; 1205 DictionaryValue manifest;
1175 manifest.SetString(keys::kName, "TestComponentApp"); 1206 manifest.SetString(keys::kName, "TestComponentApp");
1176 manifest.SetString(keys::kVersion, "0.0.0.0"); 1207 manifest.SetString(keys::kVersion, "0.0.0.0");
1177 manifest.SetString(keys::kApp, "true"); 1208 manifest.SetString(keys::kApp, "true");
1178 manifest.SetString(keys::kPlatformAppBackgroundPage, ""); 1209 manifest.SetString(keys::kPlatformAppBackgroundPage, "");
1179 1210
1180 std::string error; 1211 std::string error;
1181 scoped_refptr<Extension> app; 1212 scoped_refptr<Extension> app;
1182 1213
1183 // Default to true. 1214 // Default to true.
(...skipping 28 matching lines...) Expand all
1212 EXPECT_TRUE(app->ShouldDisplayInAppLauncher()); 1243 EXPECT_TRUE(app->ShouldDisplayInAppLauncher());
1213 EXPECT_FALSE(app->ShouldDisplayInNewTabPage()); 1244 EXPECT_FALSE(app->ShouldDisplayInNewTabPage());
1214 1245
1215 // Error checking. 1246 // Error checking.
1216 manifest.SetString(keys::kDisplayInNewTabPage, "invalid"); 1247 manifest.SetString(keys::kDisplayInNewTabPage, "invalid");
1217 app = Extension::Create( 1248 app = Extension::Create(
1218 FilePath(), Extension::COMPONENT, manifest, 0, &error); 1249 FilePath(), Extension::COMPONENT, manifest, 0, &error);
1219 EXPECT_EQ(error, std::string(errors::kInvalidDisplayInNewTabPage)); 1250 EXPECT_EQ(error, std::string(errors::kInvalidDisplayInNewTabPage));
1220 } 1251 }
1221 1252
1222 TEST(ExtensionTest, OnlySyncInternal) { 1253 TEST_F(ExtensionTest, OnlySyncInternal) {
1223 scoped_refptr<Extension> extension_internal( 1254 scoped_refptr<Extension> extension_internal(
1224 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1255 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1225 Extension::INTERNAL, 0, FilePath(), 1256 Extension::INTERNAL, 0, FilePath(),
1226 Extension::NO_FLAGS)); 1257 Extension::NO_FLAGS));
1227 EXPECT_TRUE(extension_internal->IsSyncable()); 1258 EXPECT_TRUE(extension_internal->IsSyncable());
1228 1259
1229 scoped_refptr<Extension> extension_noninternal( 1260 scoped_refptr<Extension> extension_noninternal(
1230 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1261 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1231 Extension::COMPONENT, 0, FilePath(), 1262 Extension::COMPONENT, 0, FilePath(),
1232 Extension::NO_FLAGS)); 1263 Extension::NO_FLAGS));
1233 EXPECT_FALSE(extension_noninternal->IsSyncable()); 1264 EXPECT_FALSE(extension_noninternal->IsSyncable());
1234 } 1265 }
1235 1266
1236 TEST(ExtensionTest, DontSyncDefault) { 1267 TEST_F(ExtensionTest, DontSyncDefault) {
1237 scoped_refptr<Extension> extension_default( 1268 scoped_refptr<Extension> extension_default(
1238 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1269 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1239 Extension::INTERNAL, 0, FilePath(), 1270 Extension::INTERNAL, 0, FilePath(),
1240 Extension::WAS_INSTALLED_BY_DEFAULT)); 1271 Extension::WAS_INSTALLED_BY_DEFAULT));
1241 EXPECT_FALSE(extension_default->IsSyncable()); 1272 EXPECT_FALSE(extension_default->IsSyncable());
1242 } 1273 }
1243 1274
1244 TEST(ExtensionTest, OptionalOnlyPermission) { 1275 TEST_F(ExtensionTest, OptionalOnlyPermission) {
1245 // Set feature current channel to dev because the only permission that must 1276 // Set feature current channel to dev because the only permission that must
1246 // be optional (usbDevices) is only available on dev channel. 1277 // be optional (usbDevices) is only available on dev channel.
1247 Feature::ScopedCurrentChannel scoped_channel( 1278 Feature::ScopedCurrentChannel scoped_channel(
1248 chrome::VersionInfo::CHANNEL_DEV); 1279 chrome::VersionInfo::CHANNEL_DEV);
1249 1280
1250 scoped_refptr<Extension> extension; 1281 scoped_refptr<Extension> extension;
1251 std::string error; 1282 std::string error;
1252 extension = LoadManifestUnchecked("optional_only_permission", 1283 extension = LoadManifestUnchecked("optional_only_permission",
1253 "manifest1.json", 1284 "manifest1.json",
1254 Extension::INTERNAL, Extension::NO_FLAGS, 1285 Extension::INTERNAL, Extension::NO_FLAGS,
1255 &error); 1286 &error);
1256 EXPECT_TRUE(extension == NULL); 1287 EXPECT_TRUE(extension == NULL);
1257 ASSERT_EQ(ErrorUtils::FormatErrorMessage( 1288 ASSERT_EQ(ErrorUtils::FormatErrorMessage(
1258 errors::kPermissionMustBeOptional, "usbDevices"), error); 1289 errors::kPermissionMustBeOptional, "usbDevices"), error);
1259 1290
1260 error.clear(); 1291 error.clear();
1261 extension = LoadManifestUnchecked("optional_only_permission", 1292 extension = LoadManifestUnchecked("optional_only_permission",
1262 "manifest2.json", 1293 "manifest2.json",
1263 Extension::INTERNAL, Extension::NO_FLAGS, 1294 Extension::INTERNAL, Extension::NO_FLAGS,
1264 &error); 1295 &error);
1265 EXPECT_TRUE(extension != NULL); 1296 EXPECT_TRUE(extension != NULL);
1266 EXPECT_TRUE(error.empty()); 1297 EXPECT_TRUE(error.empty());
1267 } 1298 }
1268 1299
1269 // These last 2 tests don't make sense on Chrome OS, where extension plugins 1300 // These last 2 tests don't make sense on Chrome OS, where extension plugins
1270 // are not allowed. 1301 // are not allowed.
1271 #if !defined(OS_CHROMEOS) 1302 #if !defined(OS_CHROMEOS)
1272 TEST(ExtensionTest, GetSyncTypeExtensionWithPlugin) { 1303 TEST_F(ExtensionTest, GetSyncTypeExtensionWithPlugin) {
1273 scoped_refptr<Extension> extension( 1304 scoped_refptr<Extension> extension(
1274 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1305 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1275 Extension::INTERNAL, 1, FilePath(), 1306 Extension::INTERNAL, 1, FilePath(),
1276 Extension::NO_FLAGS)); 1307 Extension::NO_FLAGS));
1277 if (extension) 1308 if (extension)
1278 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1309 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1279 } 1310 }
1280 1311
1281 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { 1312 TEST_F(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) {
1282 scoped_refptr<Extension> extension( 1313 scoped_refptr<Extension> extension(
1283 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1314 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1284 Extension::INTERNAL, 2, FilePath(), 1315 Extension::INTERNAL, 2, FilePath(),
1285 Extension::NO_FLAGS)); 1316 Extension::NO_FLAGS));
1286 if (extension) 1317 if (extension)
1287 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1318 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1288 } 1319 }
1289 #endif // !defined(OS_CHROMEOS) 1320 #endif // !defined(OS_CHROMEOS)
1290 1321
1291 } // namespace extensions 1322 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698