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

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

Issue 11742005: Move [Homepage,Options,Update,DevTools]URL 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/extension_action/action_info.h" 16 #include "chrome/common/extensions/api/extension_action/action_info.h"
17 #include "chrome/common/extensions/api/extension_urls/extension_urls_handler.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::kUpdateURL,
129 new UpdateURLHandler);
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 EXPECT_FALSE(extension->wants_file_access()); 730 EXPECT_FALSE(extension->wants_file_access());
723 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 731 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
724 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 732 file_url, file_url, -1, &extension->content_scripts()[0], NULL));
725 extension = LoadManifest("permissions", "content_script_http_scheme.json", 733 extension = LoadManifest("permissions", "content_script_http_scheme.json",
726 Extension::ALLOW_FILE_ACCESS); 734 Extension::ALLOW_FILE_ACCESS);
727 EXPECT_FALSE(extension->wants_file_access()); 735 EXPECT_FALSE(extension->wants_file_access());
728 EXPECT_FALSE(extension->CanExecuteScriptOnPage( 736 EXPECT_FALSE(extension->CanExecuteScriptOnPage(
729 file_url, file_url, -1, &extension->content_scripts()[0], NULL)); 737 file_url, file_url, -1, &extension->content_scripts()[0], NULL));
730 } 738 }
731 739
732 TEST(ExtensionTest, ExtraFlags) { 740 TEST_F(ExtensionTest, ExtraFlags) {
733 scoped_refptr<Extension> extension; 741 scoped_refptr<Extension> extension;
734 extension = LoadManifest("app", "manifest.json", Extension::FROM_WEBSTORE); 742 extension = LoadManifest("app", "manifest.json", Extension::FROM_WEBSTORE);
735 EXPECT_TRUE(extension->from_webstore()); 743 EXPECT_TRUE(extension->from_webstore());
736 744
737 extension = LoadManifest("app", "manifest.json", Extension::FROM_BOOKMARK); 745 extension = LoadManifest("app", "manifest.json", Extension::FROM_BOOKMARK);
738 EXPECT_TRUE(extension->from_bookmark()); 746 EXPECT_TRUE(extension->from_bookmark());
739 747
740 extension = LoadManifest("app", "manifest.json", Extension::NO_FLAGS); 748 extension = LoadManifest("app", "manifest.json", Extension::NO_FLAGS);
741 EXPECT_FALSE(extension->from_bookmark()); 749 EXPECT_FALSE(extension->from_bookmark());
742 EXPECT_FALSE(extension->from_webstore()); 750 EXPECT_FALSE(extension->from_webstore());
743 } 751 }
744 752
745 TEST(ExtensionTest, BrowserActionSynthesizesCommand) { 753 TEST_F(ExtensionTest, BrowserActionSynthesizesCommand) {
746 scoped_refptr<Extension> extension; 754 scoped_refptr<Extension> extension;
747 755
748 extension = LoadManifest("api_test/browser_action/synthesized", 756 extension = LoadManifest("api_test/browser_action/synthesized",
749 "manifest.json"); 757 "manifest.json");
750 // An extension with a browser action but no extension command specified 758 // An extension with a browser action but no extension command specified
751 // should get a command assigned to it. 759 // should get a command assigned to it.
752 const Command* command = extension->browser_action_command(); 760 const Command* command = extension->browser_action_command();
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 }
(...skipping 260 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

Powered by Google App Engine
This is Rietveld 408576698