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

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

Issue 11275088: Remove implicit scoped_refptr operator T* Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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_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/json/json_string_value_serializer.h" 8 #include "base/json/json_string_value_serializer.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 84 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
85 install_dir = install_dir.AppendASCII("extensions") 85 install_dir = install_dir.AppendASCII("extensions")
86 .AppendASCII("good") 86 .AppendASCII("good")
87 .AppendASCII("Extensions") 87 .AppendASCII("Extensions")
88 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 88 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
89 .AppendASCII("1.0.0.0"); 89 .AppendASCII("1.0.0.0");
90 90
91 std::string error; 91 std::string error;
92 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 92 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
93 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 93 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error));
94 ASSERT_TRUE(extension != NULL); 94 ASSERT_TRUE(extension.get() != NULL);
95 EXPECT_EQ("The first extension that I made.", extension->description()); 95 EXPECT_EQ("The first extension that I made.", extension->description());
96 } 96 }
97 97
98 TEST(ExtensionFileUtil, LoadExtensionWithoutLocalesFolder) { 98 TEST(ExtensionFileUtil, LoadExtensionWithoutLocalesFolder) {
99 FilePath install_dir; 99 FilePath install_dir;
100 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 100 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
101 install_dir = install_dir.AppendASCII("extensions") 101 install_dir = install_dir.AppendASCII("extensions")
102 .AppendASCII("good") 102 .AppendASCII("good")
103 .AppendASCII("Extensions") 103 .AppendASCII("Extensions")
104 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") 104 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa")
105 .AppendASCII("1.0"); 105 .AppendASCII("1.0");
106 106
107 std::string error; 107 std::string error;
108 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 108 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
109 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 109 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error));
110 ASSERT_FALSE(extension == NULL); 110 ASSERT_FALSE(extension.get() == NULL);
111 EXPECT_TRUE(error.empty()); 111 EXPECT_TRUE(error.empty());
112 } 112 }
113 113
114 #if defined(OS_WIN) 114 #if defined(OS_WIN)
115 // http://crbug.com/106381 115 // http://crbug.com/106381
116 #define CheckIllegalFilenamesNoUnderscores \ 116 #define CheckIllegalFilenamesNoUnderscores \
117 DISABLED_CheckIllegalFilenamesNoUnderscores 117 DISABLED_CheckIllegalFilenamesNoUnderscores
118 #endif 118 #endif
119 TEST(ExtensionFileUtil, CheckIllegalFilenamesNoUnderscores) { 119 TEST(ExtensionFileUtil, CheckIllegalFilenamesNoUnderscores) {
120 ScopedTempDir temp; 120 ScopedTempDir temp;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 173 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
174 install_dir = install_dir.AppendASCII("extensions") 174 install_dir = install_dir.AppendASCII("extensions")
175 .AppendASCII("bad") 175 .AppendASCII("bad")
176 .AppendASCII("Extensions") 176 .AppendASCII("Extensions")
177 .AppendASCII("dddddddddddddddddddddddddddddddd") 177 .AppendASCII("dddddddddddddddddddddddddddddddd")
178 .AppendASCII("1.0"); 178 .AppendASCII("1.0");
179 179
180 std::string error; 180 std::string error;
181 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 181 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
182 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 182 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error));
183 ASSERT_TRUE(extension == NULL); 183 ASSERT_TRUE(extension.get() == NULL);
184 ASSERT_FALSE(error.empty()); 184 ASSERT_FALSE(error.empty());
185 ASSERT_STREQ("Manifest file is missing or unreadable.", error.c_str()); 185 ASSERT_STREQ("Manifest file is missing or unreadable.", error.c_str());
186 } 186 }
187 187
188 TEST(ExtensionFileUtil, LoadExtensionGivesHelpfullErrorOnBadManifest) { 188 TEST(ExtensionFileUtil, LoadExtensionGivesHelpfullErrorOnBadManifest) {
189 FilePath install_dir; 189 FilePath install_dir;
190 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 190 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
191 install_dir = install_dir.AppendASCII("extensions") 191 install_dir = install_dir.AppendASCII("extensions")
192 .AppendASCII("bad") 192 .AppendASCII("bad")
193 .AppendASCII("Extensions") 193 .AppendASCII("Extensions")
194 .AppendASCII("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") 194 .AppendASCII("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")
195 .AppendASCII("1.0"); 195 .AppendASCII("1.0");
196 196
197 std::string error; 197 std::string error;
198 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 198 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
199 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 199 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error));
200 ASSERT_TRUE(extension == NULL); 200 ASSERT_TRUE(extension.get() == NULL);
201 ASSERT_FALSE(error.empty()); 201 ASSERT_FALSE(error.empty());
202 ASSERT_STREQ("Manifest is not valid JSON. " 202 ASSERT_STREQ("Manifest is not valid JSON. "
203 "Line: 2, column: 16, Syntax error.", error.c_str()); 203 "Line: 2, column: 16, Syntax error.", error.c_str());
204 } 204 }
205 205
206 TEST(ExtensionFileUtil, FailLoadingNonUTF8Scripts) { 206 TEST(ExtensionFileUtil, FailLoadingNonUTF8Scripts) {
207 FilePath install_dir; 207 FilePath install_dir;
208 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 208 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
209 install_dir = install_dir.AppendASCII("extensions") 209 install_dir = install_dir.AppendASCII("extensions")
210 .AppendASCII("bad") 210 .AppendASCII("bad")
211 .AppendASCII("bad_encoding"); 211 .AppendASCII("bad_encoding");
212 212
213 std::string error; 213 std::string error;
214 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 214 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
215 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 215 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error));
216 ASSERT_TRUE(extension == NULL); 216 ASSERT_TRUE(extension.get() == NULL);
217 ASSERT_STREQ("Could not load file 'bad_encoding.js' for content script. " 217 ASSERT_STREQ("Could not load file 'bad_encoding.js' for content script. "
218 "It isn't UTF-8 encoded.", error.c_str()); 218 "It isn't UTF-8 encoded.", error.c_str());
219 } 219 }
220 220
221 TEST(ExtensionFileUtil, ExtensionURLToRelativeFilePath) { 221 TEST(ExtensionFileUtil, ExtensionURLToRelativeFilePath) {
222 #define URL_PREFIX "chrome-extension://extension-id/" 222 #define URL_PREFIX "chrome-extension://extension-id/"
223 struct TestCase { 223 struct TestCase {
224 const char* url; 224 const char* url;
225 const char* expected_relative_path; 225 const char* expected_relative_path;
226 } test_cases[] = { 226 } test_cases[] = {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 base::StringPrintf( 377 base::StringPrintf(
378 "{ \"name\": \"Test\", \"version\": \"1.0\", " 378 "{ \"name\": \"Test\", \"version\": \"1.0\", "
379 " \"theme\": { \"images\": { \"theme_frame\": \"%s\" } }" 379 " \"theme\": { \"images\": { \"theme_frame\": \"%s\" } }"
380 "}", non_ascii_file.c_str()); 380 "}", non_ascii_file.c_str());
381 std::string error; 381 std::string error;
382 scoped_refptr<Extension> extension = LoadExtensionManifest( 382 scoped_refptr<Extension> extension = LoadExtensionManifest(
383 kManifest, temp.path(), Extension::LOAD, 0, &error); 383 kManifest, temp.path(), Extension::LOAD, 0, &error);
384 ASSERT_TRUE(extension.get()) << error; 384 ASSERT_TRUE(extension.get()) << error;
385 385
386 Extension::InstallWarningVector warnings; 386 Extension::InstallWarningVector warnings;
387 EXPECT_TRUE(extension_file_util::ValidateExtension(extension, 387 EXPECT_TRUE(extension_file_util::ValidateExtension(extension.get(),
388 &error, &warnings)) << 388 &error, &warnings)) <<
389 error; 389 error;
390 EXPECT_EQ(0U, warnings.size()); 390 EXPECT_EQ(0U, warnings.size());
391 } 391 }
392 392
393 #if defined(OS_WIN) 393 #if defined(OS_WIN)
394 // This test hangs on Windows sometimes. http://crbug.com/110279 394 // This test hangs on Windows sometimes. http://crbug.com/110279
395 #define MAYBE_BackgroundScriptsMustExist DISABLED_BackgroundScriptsMustExist 395 #define MAYBE_BackgroundScriptsMustExist DISABLED_BackgroundScriptsMustExist
396 #else 396 #else
397 #define MAYBE_BackgroundScriptsMustExist BackgroundScriptsMustExist 397 #define MAYBE_BackgroundScriptsMustExist BackgroundScriptsMustExist
(...skipping 10 matching lines...) Expand all
408 ListValue* scripts = new ListValue(); 408 ListValue* scripts = new ListValue();
409 scripts->Append(Value::CreateStringValue("foo.js")); 409 scripts->Append(Value::CreateStringValue("foo.js"));
410 value->Set("background.scripts", scripts); 410 value->Set("background.scripts", scripts);
411 411
412 std::string error; 412 std::string error;
413 Extension::InstallWarningVector warnings; 413 Extension::InstallWarningVector warnings;
414 scoped_refptr<Extension> extension = LoadExtensionManifest( 414 scoped_refptr<Extension> extension = LoadExtensionManifest(
415 value.get(), temp.path(), Extension::LOAD, 0, &error); 415 value.get(), temp.path(), Extension::LOAD, 0, &error);
416 ASSERT_TRUE(extension.get()) << error; 416 ASSERT_TRUE(extension.get()) << error;
417 417
418 EXPECT_FALSE(extension_file_util::ValidateExtension(extension, 418 EXPECT_FALSE(extension_file_util::ValidateExtension(extension.get(),
419 &error, &warnings)); 419 &error, &warnings));
420 EXPECT_EQ(l10n_util::GetStringFUTF8( 420 EXPECT_EQ(l10n_util::GetStringFUTF8(
421 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, ASCIIToUTF16("foo.js")), 421 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, ASCIIToUTF16("foo.js")),
422 error); 422 error);
423 EXPECT_EQ(0U, warnings.size()); 423 EXPECT_EQ(0U, warnings.size());
424 424
425 scripts->Clear(); 425 scripts->Clear();
426 scripts->Append(Value::CreateStringValue("http://google.com/foo.js")); 426 scripts->Append(Value::CreateStringValue("http://google.com/foo.js"));
427 427
428 extension = LoadExtensionManifest(value.get(), temp.path(), Extension::LOAD, 428 extension = LoadExtensionManifest(value.get(), temp.path(), Extension::LOAD,
429 0, &error); 429 0, &error);
430 ASSERT_TRUE(extension.get()) << error; 430 ASSERT_TRUE(extension.get()) << error;
431 431
432 warnings.clear(); 432 warnings.clear();
433 EXPECT_FALSE(extension_file_util::ValidateExtension(extension, 433 EXPECT_FALSE(extension_file_util::ValidateExtension(extension.get(),
434 &error, &warnings)); 434 &error, &warnings));
435 EXPECT_EQ(l10n_util::GetStringFUTF8( 435 EXPECT_EQ(l10n_util::GetStringFUTF8(
436 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, 436 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED,
437 ASCIIToUTF16("http://google.com/foo.js")), 437 ASCIIToUTF16("http://google.com/foo.js")),
438 error); 438 error);
439 EXPECT_EQ(0U, warnings.size()); 439 EXPECT_EQ(0U, warnings.size());
440 } 440 }
441 441
442 // Private key, generated by Chrome specifically for this test, and 442 // Private key, generated by Chrome specifically for this test, and
443 // never used elsewhere. 443 // never used elsewhere.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 534
535 // Try to install an extension with a zero-length icon file. 535 // Try to install an extension with a zero-length icon file.
536 FilePath ext_dir = install_dir.AppendASCII("extensions") 536 FilePath ext_dir = install_dir.AppendASCII("extensions")
537 .AppendASCII("bad") 537 .AppendASCII("bad")
538 .AppendASCII("Extensions") 538 .AppendASCII("Extensions")
539 .AppendASCII("ffffffffffffffffffffffffffffffff"); 539 .AppendASCII("ffffffffffffffffffffffffffffffff");
540 540
541 std::string error; 541 std::string error;
542 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 542 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
543 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 543 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error));
544 ASSERT_TRUE(extension == NULL); 544 ASSERT_TRUE(extension.get() == NULL);
545 ASSERT_STREQ("Could not load extension icon 'icon.png'.", 545 ASSERT_STREQ("Could not load extension icon 'icon.png'.",
546 error.c_str()); 546 error.c_str());
547 547
548 // Try to install an extension with a zero-length browser action icon file. 548 // Try to install an extension with a zero-length browser action icon file.
549 ext_dir = install_dir.AppendASCII("extensions") 549 ext_dir = install_dir.AppendASCII("extensions")
550 .AppendASCII("bad") 550 .AppendASCII("bad")
551 .AppendASCII("Extensions") 551 .AppendASCII("Extensions")
552 .AppendASCII("gggggggggggggggggggggggggggggggg"); 552 .AppendASCII("gggggggggggggggggggggggggggggggg");
553 553
554 scoped_refptr<Extension> extension2(extension_file_util::LoadExtension( 554 scoped_refptr<Extension> extension2(extension_file_util::LoadExtension(
555 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 555 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error));
556 ASSERT_TRUE(extension2 == NULL); 556 ASSERT_TRUE(extension2.get() == NULL);
557 ASSERT_STREQ("Could not load icon 'icon.png' for browser action.", 557 ASSERT_STREQ("Could not load icon 'icon.png' for browser action.",
558 error.c_str()); 558 error.c_str());
559 559
560 // Try to install an extension with a zero-length page action icon file. 560 // Try to install an extension with a zero-length page action icon file.
561 ext_dir = install_dir.AppendASCII("extensions") 561 ext_dir = install_dir.AppendASCII("extensions")
562 .AppendASCII("bad") 562 .AppendASCII("bad")
563 .AppendASCII("Extensions") 563 .AppendASCII("Extensions")
564 .AppendASCII("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"); 564 .AppendASCII("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
565 565
566 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension( 566 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension(
567 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 567 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error));
568 ASSERT_TRUE(extension3 == NULL); 568 ASSERT_TRUE(extension3.get() == NULL);
569 ASSERT_STREQ("Could not load icon 'icon.png' for page action.", 569 ASSERT_STREQ("Could not load icon 'icon.png' for page action.",
570 error.c_str()); 570 error.c_str());
571 } 571 }
572 572
573 // TODO(aa): More tests as motivation allows. Maybe steal some from 573 // TODO(aa): More tests as motivation allows. Maybe steal some from
574 // ExtensionService? Many of them could probably be tested here without the 574 // ExtensionService? Many of them could probably be tested here without the
575 // MessageLoop shenanigans. 575 // MessageLoop shenanigans.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698