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

Side by Side Diff: chrome/common/extensions/api/common_extension_api_unittest.cc

Issue 2888073002: Remove raw DictionaryValue::Set in //chrome (Closed)
Patch Set: Fix Tests Created 3 years, 7 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 "extensions/common/extension_api.h" 5 #include "extensions/common/extension_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h"
17 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
18 #include "base/path_service.h" 19 #include "base/path_service.h"
19 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
20 #include "base/values.h" 21 #include "base/values.h"
21 #include "chrome/common/chrome_paths.h" 22 #include "chrome/common/chrome_paths.h"
22 #include "chrome/common/extensions/extension_features_unittest.h" 23 #include "chrome/common/extensions/extension_features_unittest.h"
23 #include "extensions/common/extension.h" 24 #include "extensions/common/extension.h"
24 #include "extensions/common/extension_builder.h" 25 #include "extensions/common/extension_builder.h"
25 #include "extensions/common/features/feature_session_type.h" 26 #include "extensions/common/features/feature_session_type.h"
26 #include "extensions/common/features/simple_feature.h" 27 #include "extensions/common/features/simple_feature.h"
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 base::DictionaryValue manifest; 425 base::DictionaryValue manifest;
425 manifest.SetString("name", "extension"); 426 manifest.SetString("name", "extension");
426 manifest.SetString("version", "1.0"); 427 manifest.SetString("version", "1.0");
427 manifest.SetInteger("manifest_version", 2); 428 manifest.SetInteger("manifest_version", 2);
428 { 429 {
429 std::unique_ptr<base::ListValue> permissions_list(new base::ListValue()); 430 std::unique_ptr<base::ListValue> permissions_list(new base::ListValue());
430 for (std::set<std::string>::const_iterator i = permissions.begin(); 431 for (std::set<std::string>::const_iterator i = permissions.begin();
431 i != permissions.end(); ++i) { 432 i != permissions.end(); ++i) {
432 permissions_list->AppendString(*i); 433 permissions_list->AppendString(*i);
433 } 434 }
434 manifest.Set("permissions", permissions_list.release()); 435 manifest.Set("permissions", std::move(permissions_list));
435 } 436 }
436 437
437 std::string error; 438 std::string error;
438 scoped_refptr<Extension> extension(Extension::Create( 439 scoped_refptr<Extension> extension(Extension::Create(
439 base::FilePath(), Manifest::UNPACKED, 440 base::FilePath(), Manifest::UNPACKED,
440 manifest, Extension::NO_FLAGS, &error)); 441 manifest, Extension::NO_FLAGS, &error));
441 CHECK(extension.get()); 442 CHECK(extension.get());
442 CHECK(error.empty()); 443 CHECK(error.empty());
443 444
444 return extension; 445 return extension;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 CheckAliasStatus::NOT_ALLOWED)); 506 CheckAliasStatus::NOT_ALLOWED));
506 EXPECT_FALSE(extension_api->IsAnyFeatureAvailableToContext( 507 EXPECT_FALSE(extension_api->IsAnyFeatureAvailableToContext(
507 *api_features.GetFeature("history"), nullptr, 508 *api_features.GetFeature("history"), nullptr,
508 Feature::CONTENT_SCRIPT_CONTEXT, GURL(), CheckAliasStatus::NOT_ALLOWED)); 509 Feature::CONTENT_SCRIPT_CONTEXT, GURL(), CheckAliasStatus::NOT_ALLOWED));
509 } 510 }
510 511
511 scoped_refptr<Extension> CreateHostedApp() { 512 scoped_refptr<Extension> CreateHostedApp() {
512 base::DictionaryValue values; 513 base::DictionaryValue values;
513 values.SetString(manifest_keys::kName, "test"); 514 values.SetString(manifest_keys::kName, "test");
514 values.SetString(manifest_keys::kVersion, "0.1"); 515 values.SetString(manifest_keys::kVersion, "0.1");
515 values.Set(manifest_keys::kWebURLs, new base::ListValue()); 516 values.Set(manifest_keys::kWebURLs, base::MakeUnique<base::ListValue>());
516 values.SetString(manifest_keys::kLaunchWebURL, 517 values.SetString(manifest_keys::kLaunchWebURL,
517 "http://www.example.com"); 518 "http://www.example.com");
518 std::string error; 519 std::string error;
519 scoped_refptr<Extension> extension(Extension::Create( 520 scoped_refptr<Extension> extension(Extension::Create(
520 base::FilePath(), Manifest::INTERNAL, values, Extension::NO_FLAGS, 521 base::FilePath(), Manifest::INTERNAL, values, Extension::NO_FLAGS,
521 &error)); 522 &error));
522 CHECK(extension.get()); 523 CHECK(extension.get());
523 return extension; 524 return extension;
524 } 525 }
525 526
526 scoped_refptr<Extension> CreatePackagedAppWithPermissions( 527 scoped_refptr<Extension> CreatePackagedAppWithPermissions(
527 const std::set<std::string>& permissions) { 528 const std::set<std::string>& permissions) {
528 base::DictionaryValue values; 529 base::DictionaryValue values;
529 values.SetString(manifest_keys::kName, "test"); 530 values.SetString(manifest_keys::kName, "test");
530 values.SetString(manifest_keys::kVersion, "0.1"); 531 values.SetString(manifest_keys::kVersion, "0.1");
531 values.SetString(manifest_keys::kPlatformAppBackground, 532 values.SetString(manifest_keys::kPlatformAppBackground,
532 "http://www.example.com"); 533 "http://www.example.com");
533 534
534 base::DictionaryValue* app = new base::DictionaryValue(); 535 auto app = base::MakeUnique<base::DictionaryValue>();
535 base::DictionaryValue* background = new base::DictionaryValue(); 536 auto background = base::MakeUnique<base::DictionaryValue>();
536 base::ListValue* scripts = new base::ListValue(); 537 auto scripts = base::MakeUnique<base::ListValue>();
537 scripts->AppendString("test.js"); 538 scripts->AppendString("test.js");
538 background->Set("scripts", scripts); 539 background->Set("scripts", std::move(scripts));
539 app->Set("background", background); 540 app->Set("background", std::move(background));
540 values.Set(manifest_keys::kApp, app); 541 values.Set(manifest_keys::kApp, std::move(app));
541 { 542 {
542 std::unique_ptr<base::ListValue> permissions_list(new base::ListValue()); 543 auto permissions_list = base::MakeUnique<base::ListValue>();
543 for (std::set<std::string>::const_iterator i = permissions.begin(); 544 for (std::set<std::string>::const_iterator i = permissions.begin();
544 i != permissions.end(); ++i) { 545 i != permissions.end(); ++i) {
545 permissions_list->AppendString(*i); 546 permissions_list->AppendString(*i);
546 } 547 }
547 values.Set("permissions", permissions_list.release()); 548 values.Set("permissions", std::move(permissions_list));
548 } 549 }
549 550
550 std::string error; 551 std::string error;
551 scoped_refptr<Extension> extension(Extension::Create( 552 scoped_refptr<Extension> extension(Extension::Create(
552 base::FilePath(), Manifest::INTERNAL, values, Extension::NO_FLAGS, 553 base::FilePath(), Manifest::INTERNAL, values, Extension::NO_FLAGS,
553 &error)); 554 &error));
554 CHECK(extension.get()) << error; 555 CHECK(extension.get()) << error;
555 return extension; 556 return extension;
556 } 557 }
557 558
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 CheckAliasStatus::NOT_ALLOWED) 947 CheckAliasStatus::NOT_ALLOWED)
947 .is_available()); 948 .is_available());
948 EXPECT_FALSE(extension_api 949 EXPECT_FALSE(extension_api
949 ->IsAvailable("pageAction", extension.get(), 950 ->IsAvailable("pageAction", extension.get(),
950 Feature::BLESSED_EXTENSION_CONTEXT, GURL(), 951 Feature::BLESSED_EXTENSION_CONTEXT, GURL(),
951 CheckAliasStatus::NOT_ALLOWED) 952 CheckAliasStatus::NOT_ALLOWED)
952 .is_available()); 953 .is_available());
953 } 954 }
954 955
955 } // namespace extensions 956 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698