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

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

Issue 12207167: Cleanup: Remove deprecated base::Value methods from chrome/common. Use base::Value too. (Closed) Base URL: svn://chrome-svn/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"
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 base::FilePath actual_path = 372 base::FilePath actual_path =
373 extension_file_util::ExtensionResourceURLToFilePath(url, root_path); 373 extension_file_util::ExtensionResourceURLToFilePath(url, root_path);
374 EXPECT_EQ(expected_path.value(), actual_path.value()) << 374 EXPECT_EQ(expected_path.value(), actual_path.value()) <<
375 " For the path " << url; 375 " For the path " << url;
376 } 376 }
377 // Remove temp files. 377 // Remove temp files.
378 ASSERT_TRUE(file_util::Delete(root_path, true)); 378 ASSERT_TRUE(file_util::Delete(root_path, true));
379 } 379 }
380 380
381 static scoped_refptr<Extension> LoadExtensionManifest( 381 static scoped_refptr<Extension> LoadExtensionManifest(
382 DictionaryValue* manifest, 382 base::DictionaryValue* manifest,
383 const base::FilePath& manifest_dir, 383 const base::FilePath& manifest_dir,
384 Manifest::Location location, 384 Manifest::Location location,
385 int extra_flags, 385 int extra_flags,
386 std::string* error) { 386 std::string* error) {
387 scoped_refptr<Extension> extension = Extension::Create( 387 scoped_refptr<Extension> extension = Extension::Create(
388 manifest_dir, location, *manifest, extra_flags, error); 388 manifest_dir, location, *manifest, extra_flags, error);
389 return extension; 389 return extension;
390 } 390 }
391 391
392 static scoped_refptr<Extension> LoadExtensionManifest( 392 static scoped_refptr<Extension> LoadExtensionManifest(
393 const std::string& manifest_value, 393 const std::string& manifest_value,
394 const base::FilePath& manifest_dir, 394 const base::FilePath& manifest_dir,
395 Manifest::Location location, 395 Manifest::Location location,
396 int extra_flags, 396 int extra_flags,
397 std::string* error) { 397 std::string* error) {
398 JSONStringValueSerializer serializer(manifest_value); 398 JSONStringValueSerializer serializer(manifest_value);
399 scoped_ptr<Value> result(serializer.Deserialize(NULL, error)); 399 scoped_ptr<base::Value> result(serializer.Deserialize(NULL, error));
400 if (!result.get()) 400 if (!result.get())
401 return NULL; 401 return NULL;
402 CHECK_EQ(Value::TYPE_DICTIONARY, result->GetType()); 402 CHECK_EQ(base::Value::TYPE_DICTIONARY, result->GetType());
403 return LoadExtensionManifest(static_cast<DictionaryValue*>(result.get()), 403 return LoadExtensionManifest(
404 manifest_dir, 404 static_cast<base::DictionaryValue*>(result.get()),
405 location, 405 manifest_dir,
406 extra_flags, 406 location,
407 error); 407 extra_flags,
408 error);
408 } 409 }
409 410
410 #if defined(OS_WIN) 411 #if defined(OS_WIN)
411 // http://crbug.com/108279 412 // http://crbug.com/108279
412 #define ValidateThemeUTF8 DISABLED_ValidateThemeUTF8 413 #define ValidateThemeUTF8 DISABLED_ValidateThemeUTF8
413 #endif 414 #endif
414 TEST_F(ExtensionFileUtilTest, ValidateThemeUTF8) { 415 TEST_F(ExtensionFileUtilTest, ValidateThemeUTF8) {
415 base::ScopedTempDir temp; 416 base::ScopedTempDir temp;
416 ASSERT_TRUE(temp.CreateUniqueTempDir()); 417 ASSERT_TRUE(temp.CreateUniqueTempDir());
417 418
(...skipping 23 matching lines...) Expand all
441 #if defined(OS_WIN) 442 #if defined(OS_WIN)
442 // This test hangs on Windows sometimes. http://crbug.com/110279 443 // This test hangs on Windows sometimes. http://crbug.com/110279
443 #define MAYBE_BackgroundScriptsMustExist DISABLED_BackgroundScriptsMustExist 444 #define MAYBE_BackgroundScriptsMustExist DISABLED_BackgroundScriptsMustExist
444 #else 445 #else
445 #define MAYBE_BackgroundScriptsMustExist BackgroundScriptsMustExist 446 #define MAYBE_BackgroundScriptsMustExist BackgroundScriptsMustExist
446 #endif 447 #endif
447 TEST_F(ExtensionFileUtilTest, MAYBE_BackgroundScriptsMustExist) { 448 TEST_F(ExtensionFileUtilTest, MAYBE_BackgroundScriptsMustExist) {
448 base::ScopedTempDir temp; 449 base::ScopedTempDir temp;
449 ASSERT_TRUE(temp.CreateUniqueTempDir()); 450 ASSERT_TRUE(temp.CreateUniqueTempDir());
450 451
451 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 452 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
452 value->SetString("name", "test"); 453 value->SetString("name", "test");
453 value->SetString("version", "1"); 454 value->SetString("version", "1");
454 value->SetInteger("manifest_version", 1); 455 value->SetInteger("manifest_version", 1);
455 456
456 ListValue* scripts = new ListValue(); 457 base::ListValue* scripts = new base::ListValue();
457 scripts->Append(Value::CreateStringValue("foo.js")); 458 scripts->Append(new base::StringValue("foo.js"));
458 value->Set("background.scripts", scripts); 459 value->Set("background.scripts", scripts);
459 460
460 std::string error; 461 std::string error;
461 std::vector<extensions::InstallWarning> warnings; 462 std::vector<extensions::InstallWarning> warnings;
462 scoped_refptr<Extension> extension = LoadExtensionManifest( 463 scoped_refptr<Extension> extension = LoadExtensionManifest(
463 value.get(), temp.path(), Manifest::LOAD, 0, &error); 464 value.get(), temp.path(), Manifest::LOAD, 0, &error);
464 ASSERT_TRUE(extension.get()) << error; 465 ASSERT_TRUE(extension.get()) << error;
465 466
466 EXPECT_FALSE(extension_file_util::ValidateExtension(extension, 467 EXPECT_FALSE(extension_file_util::ValidateExtension(extension,
467 &error, &warnings)); 468 &error, &warnings));
468 EXPECT_EQ(l10n_util::GetStringFUTF8( 469 EXPECT_EQ(l10n_util::GetStringFUTF8(
469 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, ASCIIToUTF16("foo.js")), 470 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, ASCIIToUTF16("foo.js")),
470 error); 471 error);
471 EXPECT_EQ(0U, warnings.size()); 472 EXPECT_EQ(0U, warnings.size());
472 473
473 scripts->Clear(); 474 scripts->Clear();
474 scripts->Append(Value::CreateStringValue("http://google.com/foo.js")); 475 scripts->Append(new base::StringValue("http://google.com/foo.js"));
475 476
476 extension = LoadExtensionManifest(value.get(), temp.path(), Manifest::LOAD, 477 extension = LoadExtensionManifest(value.get(), temp.path(), Manifest::LOAD,
477 0, &error); 478 0, &error);
478 ASSERT_TRUE(extension.get()) << error; 479 ASSERT_TRUE(extension.get()) << error;
479 480
480 warnings.clear(); 481 warnings.clear();
481 EXPECT_FALSE(extension_file_util::ValidateExtension(extension, 482 EXPECT_FALSE(extension_file_util::ValidateExtension(extension,
482 &error, &warnings)); 483 &error, &warnings));
483 EXPECT_EQ(l10n_util::GetStringFUTF8( 484 EXPECT_EQ(l10n_util::GetStringFUTF8(
484 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, 485 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension( 615 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension(
615 ext_dir, Manifest::LOAD, Extension::NO_FLAGS, &error)); 616 ext_dir, Manifest::LOAD, Extension::NO_FLAGS, &error));
616 ASSERT_TRUE(extension3 == NULL); 617 ASSERT_TRUE(extension3 == NULL);
617 ASSERT_STREQ("Could not load icon 'icon.png' for page action.", 618 ASSERT_STREQ("Could not load icon 'icon.png' for page action.",
618 error.c_str()); 619 error.c_str());
619 } 620 }
620 621
621 // TODO(aa): More tests as motivation allows. Maybe steal some from 622 // TODO(aa): More tests as motivation allows. Maybe steal some from
622 // ExtensionService? Many of them could probably be tested here without the 623 // ExtensionService? Many of them could probably be tested here without the
623 // MessageLoop shenanigans. 624 // MessageLoop shenanigans.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698