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

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

Issue 12093036: Move Extension Location and Type enums to Manifest, and move InstallWarning to its own file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_file_util.h" 5 #include "chrome/common/extensions/extension_file_util.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
14 #include "chrome/common/extensions/api/extension_action/browser_action_handler.h " 14 #include "chrome/common/extensions/api/extension_action/browser_action_handler.h "
15 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" 15 #include "chrome/common/extensions/api/i18n/default_locale_handler.h"
16 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/extensions/extension_manifest_constants.h" 17 #include "chrome/common/extensions/extension_manifest_constants.h"
18 #include "chrome/common/extensions/manifest.h"
18 #include "chrome/common/extensions/manifest_handler.h" 19 #include "chrome/common/extensions/manifest_handler.h"
19 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
20 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 24
24 using extensions::Extension; 25 using extensions::Extension;
26 using extensions::Manifest;
25 27
26 namespace keys = extension_manifest_keys; 28 namespace keys = extension_manifest_keys;
27 29
28 class ExtensionFileUtilTest : public testing::Test { 30 class ExtensionFileUtilTest : public testing::Test {
29 protected: 31 protected:
30 virtual void SetUp() OVERRIDE { 32 virtual void SetUp() OVERRIDE {
31 testing::Test::SetUp(); 33 testing::Test::SetUp();
32 extensions::ManifestHandler::Register( 34 extensions::ManifestHandler::Register(
33 extension_manifest_keys::kBrowserAction, 35 extension_manifest_keys::kBrowserAction,
34 new extensions::BrowserActionHandler); 36 new extensions::BrowserActionHandler);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 FilePath install_dir; 119 FilePath install_dir;
118 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 120 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
119 install_dir = install_dir.AppendASCII("extensions") 121 install_dir = install_dir.AppendASCII("extensions")
120 .AppendASCII("good") 122 .AppendASCII("good")
121 .AppendASCII("Extensions") 123 .AppendASCII("Extensions")
122 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 124 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
123 .AppendASCII("1.0.0.0"); 125 .AppendASCII("1.0.0.0");
124 126
125 std::string error; 127 std::string error;
126 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 128 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
127 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 129 install_dir, Manifest::LOAD, Extension::NO_FLAGS, &error));
128 ASSERT_TRUE(extension != NULL); 130 ASSERT_TRUE(extension != NULL);
129 EXPECT_EQ("The first extension that I made.", extension->description()); 131 EXPECT_EQ("The first extension that I made.", extension->description());
130 } 132 }
131 133
132 TEST_F(ExtensionFileUtilTest, LoadExtensionWithoutLocalesFolder) { 134 TEST_F(ExtensionFileUtilTest, LoadExtensionWithoutLocalesFolder) {
133 FilePath install_dir; 135 FilePath install_dir;
134 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 136 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
135 install_dir = install_dir.AppendASCII("extensions") 137 install_dir = install_dir.AppendASCII("extensions")
136 .AppendASCII("good") 138 .AppendASCII("good")
137 .AppendASCII("Extensions") 139 .AppendASCII("Extensions")
138 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") 140 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa")
139 .AppendASCII("1.0"); 141 .AppendASCII("1.0");
140 142
141 std::string error; 143 std::string error;
142 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 144 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
143 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 145 install_dir, Manifest::LOAD, Extension::NO_FLAGS, &error));
144 ASSERT_FALSE(extension == NULL); 146 ASSERT_FALSE(extension == NULL);
145 EXPECT_TRUE(error.empty()); 147 EXPECT_TRUE(error.empty());
146 } 148 }
147 149
148 #if defined(OS_WIN) 150 #if defined(OS_WIN)
149 // http://crbug.com/106381 151 // http://crbug.com/106381
150 #define CheckIllegalFilenamesNoUnderscores \ 152 #define CheckIllegalFilenamesNoUnderscores \
151 DISABLED_CheckIllegalFilenamesNoUnderscores 153 DISABLED_CheckIllegalFilenamesNoUnderscores
152 #endif 154 #endif
153 TEST_F(ExtensionFileUtilTest, CheckIllegalFilenamesNoUnderscores) { 155 TEST_F(ExtensionFileUtilTest, CheckIllegalFilenamesNoUnderscores) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 FilePath install_dir; 209 FilePath install_dir;
208 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 210 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
209 install_dir = install_dir.AppendASCII("extensions") 211 install_dir = install_dir.AppendASCII("extensions")
210 .AppendASCII("bad") 212 .AppendASCII("bad")
211 .AppendASCII("Extensions") 213 .AppendASCII("Extensions")
212 .AppendASCII("dddddddddddddddddddddddddddddddd") 214 .AppendASCII("dddddddddddddddddddddddddddddddd")
213 .AppendASCII("1.0"); 215 .AppendASCII("1.0");
214 216
215 std::string error; 217 std::string error;
216 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 218 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
217 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 219 install_dir, Manifest::LOAD, Extension::NO_FLAGS, &error));
218 ASSERT_TRUE(extension == NULL); 220 ASSERT_TRUE(extension == NULL);
219 ASSERT_FALSE(error.empty()); 221 ASSERT_FALSE(error.empty());
220 ASSERT_STREQ("Manifest file is missing or unreadable.", error.c_str()); 222 ASSERT_STREQ("Manifest file is missing or unreadable.", error.c_str());
221 } 223 }
222 224
223 TEST_F(ExtensionFileUtilTest, LoadExtensionGivesHelpfullErrorOnBadManifest) { 225 TEST_F(ExtensionFileUtilTest, LoadExtensionGivesHelpfullErrorOnBadManifest) {
224 FilePath install_dir; 226 FilePath install_dir;
225 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 227 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
226 install_dir = install_dir.AppendASCII("extensions") 228 install_dir = install_dir.AppendASCII("extensions")
227 .AppendASCII("bad") 229 .AppendASCII("bad")
228 .AppendASCII("Extensions") 230 .AppendASCII("Extensions")
229 .AppendASCII("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") 231 .AppendASCII("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")
230 .AppendASCII("1.0"); 232 .AppendASCII("1.0");
231 233
232 std::string error; 234 std::string error;
233 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 235 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
234 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 236 install_dir, Manifest::LOAD, Extension::NO_FLAGS, &error));
235 ASSERT_TRUE(extension == NULL); 237 ASSERT_TRUE(extension == NULL);
236 ASSERT_FALSE(error.empty()); 238 ASSERT_FALSE(error.empty());
237 ASSERT_STREQ("Manifest is not valid JSON. " 239 ASSERT_STREQ("Manifest is not valid JSON. "
238 "Line: 2, column: 16, Syntax error.", error.c_str()); 240 "Line: 2, column: 16, Syntax error.", error.c_str());
239 } 241 }
240 242
241 TEST_F(ExtensionFileUtilTest, FailLoadingNonUTF8Scripts) { 243 TEST_F(ExtensionFileUtilTest, FailLoadingNonUTF8Scripts) {
242 FilePath install_dir; 244 FilePath install_dir;
243 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 245 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
244 install_dir = install_dir.AppendASCII("extensions") 246 install_dir = install_dir.AppendASCII("extensions")
245 .AppendASCII("bad") 247 .AppendASCII("bad")
246 .AppendASCII("bad_encoding"); 248 .AppendASCII("bad_encoding");
247 249
248 std::string error; 250 std::string error;
249 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 251 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
250 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 252 install_dir, Manifest::LOAD, Extension::NO_FLAGS, &error));
251 ASSERT_TRUE(extension == NULL); 253 ASSERT_TRUE(extension == NULL);
252 ASSERT_STREQ("Could not load file 'bad_encoding.js' for content script. " 254 ASSERT_STREQ("Could not load file 'bad_encoding.js' for content script. "
253 "It isn't UTF-8 encoded.", error.c_str()); 255 "It isn't UTF-8 encoded.", error.c_str());
254 } 256 }
255 257
256 TEST_F(ExtensionFileUtilTest, ExtensionURLToRelativeFilePath) { 258 TEST_F(ExtensionFileUtilTest, ExtensionURLToRelativeFilePath) {
257 #define URL_PREFIX "chrome-extension://extension-id/" 259 #define URL_PREFIX "chrome-extension://extension-id/"
258 struct TestCase { 260 struct TestCase {
259 const char* url; 261 const char* url;
260 const char* expected_relative_path; 262 const char* expected_relative_path;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 EXPECT_EQ(expected_path.value(), actual_path.value()) << 363 EXPECT_EQ(expected_path.value(), actual_path.value()) <<
362 " For the path " << url; 364 " For the path " << url;
363 } 365 }
364 // Remove temp files. 366 // Remove temp files.
365 ASSERT_TRUE(file_util::Delete(root_path, true)); 367 ASSERT_TRUE(file_util::Delete(root_path, true));
366 } 368 }
367 369
368 static scoped_refptr<Extension> LoadExtensionManifest( 370 static scoped_refptr<Extension> LoadExtensionManifest(
369 DictionaryValue* manifest, 371 DictionaryValue* manifest,
370 const FilePath& manifest_dir, 372 const FilePath& manifest_dir,
371 Extension::Location location, 373 Manifest::Location location,
372 int extra_flags, 374 int extra_flags,
373 std::string* error) { 375 std::string* error) {
374 scoped_refptr<Extension> extension = Extension::Create( 376 scoped_refptr<Extension> extension = Extension::Create(
375 manifest_dir, location, *manifest, extra_flags, error); 377 manifest_dir, location, *manifest, extra_flags, error);
376 return extension; 378 return extension;
377 } 379 }
378 380
379 static scoped_refptr<Extension> LoadExtensionManifest( 381 static scoped_refptr<Extension> LoadExtensionManifest(
380 const std::string& manifest_value, 382 const std::string& manifest_value,
381 const FilePath& manifest_dir, 383 const FilePath& manifest_dir,
382 Extension::Location location, 384 Manifest::Location location,
383 int extra_flags, 385 int extra_flags,
384 std::string* error) { 386 std::string* error) {
385 JSONStringValueSerializer serializer(manifest_value); 387 JSONStringValueSerializer serializer(manifest_value);
386 scoped_ptr<Value> result(serializer.Deserialize(NULL, error)); 388 scoped_ptr<Value> result(serializer.Deserialize(NULL, error));
387 if (!result.get()) 389 if (!result.get())
388 return NULL; 390 return NULL;
389 CHECK_EQ(Value::TYPE_DICTIONARY, result->GetType()); 391 CHECK_EQ(Value::TYPE_DICTIONARY, result->GetType());
390 return LoadExtensionManifest(static_cast<DictionaryValue*>(result.get()), 392 return LoadExtensionManifest(static_cast<DictionaryValue*>(result.get()),
391 manifest_dir, 393 manifest_dir,
392 location, 394 location,
(...skipping 15 matching lines...) Expand all
408 non_ascii_file)); 410 non_ascii_file));
409 file_util::WriteFile(non_ascii_path, "", 0); 411 file_util::WriteFile(non_ascii_path, "", 0);
410 412
411 std::string kManifest = 413 std::string kManifest =
412 base::StringPrintf( 414 base::StringPrintf(
413 "{ \"name\": \"Test\", \"version\": \"1.0\", " 415 "{ \"name\": \"Test\", \"version\": \"1.0\", "
414 " \"theme\": { \"images\": { \"theme_frame\": \"%s\" } }" 416 " \"theme\": { \"images\": { \"theme_frame\": \"%s\" } }"
415 "}", non_ascii_file.c_str()); 417 "}", non_ascii_file.c_str());
416 std::string error; 418 std::string error;
417 scoped_refptr<Extension> extension = LoadExtensionManifest( 419 scoped_refptr<Extension> extension = LoadExtensionManifest(
418 kManifest, temp.path(), Extension::LOAD, 0, &error); 420 kManifest, temp.path(), Manifest::LOAD, 0, &error);
419 ASSERT_TRUE(extension.get()) << error; 421 ASSERT_TRUE(extension.get()) << error;
420 422
421 Extension::InstallWarningVector warnings; 423 std::vector<extensions::InstallWarning> warnings;
422 EXPECT_TRUE(extension_file_util::ValidateExtension(extension, 424 EXPECT_TRUE(extension_file_util::ValidateExtension(extension,
423 &error, &warnings)) << 425 &error, &warnings)) <<
424 error; 426 error;
425 EXPECT_EQ(0U, warnings.size()); 427 EXPECT_EQ(0U, warnings.size());
426 } 428 }
427 429
428 #if defined(OS_WIN) 430 #if defined(OS_WIN)
429 // This test hangs on Windows sometimes. http://crbug.com/110279 431 // This test hangs on Windows sometimes. http://crbug.com/110279
430 #define MAYBE_BackgroundScriptsMustExist DISABLED_BackgroundScriptsMustExist 432 #define MAYBE_BackgroundScriptsMustExist DISABLED_BackgroundScriptsMustExist
431 #else 433 #else
432 #define MAYBE_BackgroundScriptsMustExist BackgroundScriptsMustExist 434 #define MAYBE_BackgroundScriptsMustExist BackgroundScriptsMustExist
433 #endif 435 #endif
434 TEST_F(ExtensionFileUtilTest, MAYBE_BackgroundScriptsMustExist) { 436 TEST_F(ExtensionFileUtilTest, MAYBE_BackgroundScriptsMustExist) {
435 base::ScopedTempDir temp; 437 base::ScopedTempDir temp;
436 ASSERT_TRUE(temp.CreateUniqueTempDir()); 438 ASSERT_TRUE(temp.CreateUniqueTempDir());
437 439
438 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 440 scoped_ptr<DictionaryValue> value(new DictionaryValue());
439 value->SetString("name", "test"); 441 value->SetString("name", "test");
440 value->SetString("version", "1"); 442 value->SetString("version", "1");
441 value->SetInteger("manifest_version", 1); 443 value->SetInteger("manifest_version", 1);
442 444
443 ListValue* scripts = new ListValue(); 445 ListValue* scripts = new ListValue();
444 scripts->Append(Value::CreateStringValue("foo.js")); 446 scripts->Append(Value::CreateStringValue("foo.js"));
445 value->Set("background.scripts", scripts); 447 value->Set("background.scripts", scripts);
446 448
447 std::string error; 449 std::string error;
448 Extension::InstallWarningVector warnings; 450 std::vector<extensions::InstallWarning> warnings;
449 scoped_refptr<Extension> extension = LoadExtensionManifest( 451 scoped_refptr<Extension> extension = LoadExtensionManifest(
450 value.get(), temp.path(), Extension::LOAD, 0, &error); 452 value.get(), temp.path(), Manifest::LOAD, 0, &error);
451 ASSERT_TRUE(extension.get()) << error; 453 ASSERT_TRUE(extension.get()) << error;
452 454
453 EXPECT_FALSE(extension_file_util::ValidateExtension(extension, 455 EXPECT_FALSE(extension_file_util::ValidateExtension(extension,
454 &error, &warnings)); 456 &error, &warnings));
455 EXPECT_EQ(l10n_util::GetStringFUTF8( 457 EXPECT_EQ(l10n_util::GetStringFUTF8(
456 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, ASCIIToUTF16("foo.js")), 458 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, ASCIIToUTF16("foo.js")),
457 error); 459 error);
458 EXPECT_EQ(0U, warnings.size()); 460 EXPECT_EQ(0U, warnings.size());
459 461
460 scripts->Clear(); 462 scripts->Clear();
461 scripts->Append(Value::CreateStringValue("http://google.com/foo.js")); 463 scripts->Append(Value::CreateStringValue("http://google.com/foo.js"));
462 464
463 extension = LoadExtensionManifest(value.get(), temp.path(), Extension::LOAD, 465 extension = LoadExtensionManifest(value.get(), temp.path(), Manifest::LOAD,
464 0, &error); 466 0, &error);
465 ASSERT_TRUE(extension.get()) << error; 467 ASSERT_TRUE(extension.get()) << error;
466 468
467 warnings.clear(); 469 warnings.clear();
468 EXPECT_FALSE(extension_file_util::ValidateExtension(extension, 470 EXPECT_FALSE(extension_file_util::ValidateExtension(extension,
469 &error, &warnings)); 471 &error, &warnings));
470 EXPECT_EQ(l10n_util::GetStringFUTF8( 472 EXPECT_EQ(l10n_util::GetStringFUTF8(
471 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, 473 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED,
472 ASCIIToUTF16("http://google.com/foo.js")), 474 ASCIIToUTF16("http://google.com/foo.js")),
473 error); 475 error);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 " \"manifest_version\": 2,\n" 536 " \"manifest_version\": 2,\n"
535 " \"description\": \"The first extension that I made.\"\n" 537 " \"description\": \"The first extension that I made.\"\n"
536 "}\n"; 538 "}\n";
537 ASSERT_TRUE(file_util::WriteFile(ext_path.AppendASCII("manifest.json"), 539 ASSERT_TRUE(file_util::WriteFile(ext_path.AppendASCII("manifest.json"),
538 manifest, strlen(manifest))); 540 manifest, strlen(manifest)));
539 ASSERT_TRUE(file_util::WriteFile(ext_path.AppendASCII("a_key.pem"), 541 ASSERT_TRUE(file_util::WriteFile(ext_path.AppendASCII("a_key.pem"),
540 private_key, strlen(private_key))); 542 private_key, strlen(private_key)));
541 543
542 std::string error; 544 std::string error;
543 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 545 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
544 ext_path, "the_id", Extension::EXTERNAL_PREF, 546 ext_path, "the_id", Manifest::EXTERNAL_PREF,
545 Extension::NO_FLAGS, &error)); 547 Extension::NO_FLAGS, &error));
546 ASSERT_TRUE(extension.get()) << error; 548 ASSERT_TRUE(extension.get()) << error;
547 ASSERT_EQ(1u, extension->install_warnings().size()); 549 ASSERT_EQ(1u, extension->install_warnings().size());
548 EXPECT_THAT( 550 EXPECT_THAT(
549 extension->install_warnings(), 551 extension->install_warnings(),
550 testing::ElementsAre( 552 testing::ElementsAre(
551 testing::Field( 553 testing::Field(
552 &Extension::InstallWarning::message, 554 &extensions::InstallWarning::message,
553 testing::ContainsRegex( 555 testing::ContainsRegex(
554 "extension includes the key file.*ext_root.a_key.pem")))); 556 "extension includes the key file.*ext_root.a_key.pem"))));
555 557
556 // Turn the warning into an error with ERROR_ON_PRIVATE_KEY. 558 // Turn the warning into an error with ERROR_ON_PRIVATE_KEY.
557 extension = extension_file_util::LoadExtension( 559 extension = extension_file_util::LoadExtension(
558 ext_path, "the_id", Extension::EXTERNAL_PREF, 560 ext_path, "the_id", Manifest::EXTERNAL_PREF,
559 Extension::ERROR_ON_PRIVATE_KEY, &error); 561 Extension::ERROR_ON_PRIVATE_KEY, &error);
560 EXPECT_FALSE(extension.get()); 562 EXPECT_FALSE(extension.get());
561 EXPECT_THAT(error, 563 EXPECT_THAT(error,
562 testing::ContainsRegex( 564 testing::ContainsRegex(
563 "extension includes the key file.*ext_root.a_key.pem")); 565 "extension includes the key file.*ext_root.a_key.pem"));
564 } 566 }
565 567
566 TEST_F(ExtensionFileUtilTest, CheckZeroLengthImageFile) { 568 TEST_F(ExtensionFileUtilTest, CheckZeroLengthImageFile) {
567 FilePath install_dir; 569 FilePath install_dir;
568 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 570 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
569 571
570 // Try to install an extension with a zero-length icon file. 572 // Try to install an extension with a zero-length icon file.
571 FilePath ext_dir = install_dir.AppendASCII("extensions") 573 FilePath ext_dir = install_dir.AppendASCII("extensions")
572 .AppendASCII("bad") 574 .AppendASCII("bad")
573 .AppendASCII("Extensions") 575 .AppendASCII("Extensions")
574 .AppendASCII("ffffffffffffffffffffffffffffffff"); 576 .AppendASCII("ffffffffffffffffffffffffffffffff");
575 577
576 std::string error; 578 std::string error;
577 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 579 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
578 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 580 ext_dir, Manifest::LOAD, Extension::NO_FLAGS, &error));
579 ASSERT_TRUE(extension == NULL); 581 ASSERT_TRUE(extension == NULL);
580 ASSERT_STREQ("Could not load extension icon 'icon.png'.", 582 ASSERT_STREQ("Could not load extension icon 'icon.png'.",
581 error.c_str()); 583 error.c_str());
582 584
583 // Try to install an extension with a zero-length browser action icon file. 585 // Try to install an extension with a zero-length browser action icon file.
584 ext_dir = install_dir.AppendASCII("extensions") 586 ext_dir = install_dir.AppendASCII("extensions")
585 .AppendASCII("bad") 587 .AppendASCII("bad")
586 .AppendASCII("Extensions") 588 .AppendASCII("Extensions")
587 .AppendASCII("gggggggggggggggggggggggggggggggg"); 589 .AppendASCII("gggggggggggggggggggggggggggggggg");
588 590
589 scoped_refptr<Extension> extension2(extension_file_util::LoadExtension( 591 scoped_refptr<Extension> extension2(extension_file_util::LoadExtension(
590 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 592 ext_dir, Manifest::LOAD, Extension::NO_FLAGS, &error));
591 ASSERT_TRUE(extension2 == NULL); 593 ASSERT_TRUE(extension2 == NULL);
592 ASSERT_STREQ("Could not load icon 'icon.png' for browser action.", 594 ASSERT_STREQ("Could not load icon 'icon.png' for browser action.",
593 error.c_str()); 595 error.c_str());
594 596
595 // Try to install an extension with a zero-length page action icon file. 597 // Try to install an extension with a zero-length page action icon file.
596 ext_dir = install_dir.AppendASCII("extensions") 598 ext_dir = install_dir.AppendASCII("extensions")
597 .AppendASCII("bad") 599 .AppendASCII("bad")
598 .AppendASCII("Extensions") 600 .AppendASCII("Extensions")
599 .AppendASCII("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"); 601 .AppendASCII("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
600 602
601 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension( 603 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension(
602 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 604 ext_dir, Manifest::LOAD, Extension::NO_FLAGS, &error));
603 ASSERT_TRUE(extension3 == NULL); 605 ASSERT_TRUE(extension3 == NULL);
604 ASSERT_STREQ("Could not load icon 'icon.png' for page action.", 606 ASSERT_STREQ("Could not load icon 'icon.png' for page action.",
605 error.c_str()); 607 error.c_str());
606 } 608 }
607 609
608 // TODO(aa): More tests as motivation allows. Maybe steal some from 610 // TODO(aa): More tests as motivation allows. Maybe steal some from
609 // ExtensionService? Many of them could probably be tested here without the 611 // ExtensionService? Many of them could probably be tested here without the
610 // MessageLoop shenanigans. 612 // MessageLoop shenanigans.
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_file_util.cc ('k') | chrome/common/extensions/extension_l10n_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698