| Index: extensions/common/message_bundle_unittest.cc
|
| diff --git a/extensions/common/message_bundle_unittest.cc b/extensions/common/message_bundle_unittest.cc
|
| index 45bd0e115424ec050a72efb97adb3adf7784404d..bafbf9d63b81f1916f99d223c2d5782bc3507b96 100644
|
| --- a/extensions/common/message_bundle_unittest.cc
|
| +++ b/extensions/common/message_bundle_unittest.cc
|
| @@ -12,7 +12,6 @@
|
|
|
| #include "base/i18n/rtl.h"
|
| #include "base/macros.h"
|
| -#include "base/memory/linked_ptr.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/values.h"
|
| @@ -74,29 +73,28 @@ class MessageBundleTest : public testing::Test {
|
| SetDictionary(name, message_tree, dict);
|
| }
|
|
|
| - // Caller owns the memory.
|
| - base::DictionaryValue* CreateGoodDictionary() {
|
| - base::DictionaryValue* dict = new base::DictionaryValue;
|
| - CreateMessageTree("n1", "message1 $a$ $b$", true, dict);
|
| - CreateMessageTree("n2", "message2 $c$", true, dict);
|
| - CreateMessageTree("n3", "message3", false, dict);
|
| + std::unique_ptr<base::DictionaryValue> CreateGoodDictionary() {
|
| + std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
|
| + CreateMessageTree("n1", "message1 $a$ $b$", true, dict.get());
|
| + CreateMessageTree("n2", "message2 $c$", true, dict.get());
|
| + CreateMessageTree("n3", "message3", false, dict.get());
|
| return dict;
|
| }
|
|
|
| - // Caller owns the memory.
|
| - base::DictionaryValue* CreateBadDictionary(enum BadDictionary what_is_bad) {
|
| - base::DictionaryValue* dict = CreateGoodDictionary();
|
| + std::unique_ptr<base::DictionaryValue> CreateBadDictionary(
|
| + enum BadDictionary what_is_bad) {
|
| + std::unique_ptr<base::DictionaryValue> dict = CreateGoodDictionary();
|
| // Now remove/break things.
|
| switch (what_is_bad) {
|
| case INVALID_NAME:
|
| - CreateMessageTree("n 5", "nevermind", false, dict);
|
| + CreateMessageTree("n 5", "nevermind", false, dict.get());
|
| break;
|
| case NAME_NOT_A_TREE:
|
| dict->SetString("n4", "whatever");
|
| break;
|
| case EMPTY_NAME_TREE: {
|
| base::DictionaryValue* empty_tree = new base::DictionaryValue;
|
| - SetDictionary("n4", empty_tree, dict);
|
| + SetDictionary("n4", empty_tree, dict.get());
|
| }
|
| break;
|
| case MISSING_MESSAGE:
|
| @@ -107,7 +105,7 @@ class MessageBundleTest : public testing::Test {
|
| break;
|
| case EMPTY_PLACEHOLDER_TREE: {
|
| base::DictionaryValue* empty_tree = new base::DictionaryValue;
|
| - SetDictionary("n1.placeholders", empty_tree, dict);
|
| + SetDictionary("n1.placeholders", empty_tree, dict.get());
|
| }
|
| break;
|
| case CONTENT_MISSING:
|
| @@ -161,7 +159,7 @@ class MessageBundleTest : public testing::Test {
|
| }
|
|
|
| std::unique_ptr<MessageBundle> handler_;
|
| - std::vector<linked_ptr<base::DictionaryValue> > catalogs_;
|
| + std::vector<std::unique_ptr<base::DictionaryValue>> catalogs_;
|
| };
|
|
|
| TEST_F(MessageBundleTest, ReservedMessagesCount) {
|
| @@ -176,8 +174,7 @@ TEST_F(MessageBundleTest, InitEmptyDictionaries) {
|
| }
|
|
|
| TEST_F(MessageBundleTest, InitGoodDefaultDict) {
|
| - catalogs_.push_back(
|
| - linked_ptr<base::DictionaryValue>(CreateGoodDictionary()));
|
| + catalogs_.push_back(CreateGoodDictionary());
|
| CreateMessageBundle();
|
|
|
| EXPECT_TRUE(handler_.get() != NULL);
|
| @@ -190,10 +187,8 @@ TEST_F(MessageBundleTest, InitGoodDefaultDict) {
|
| }
|
|
|
| TEST_F(MessageBundleTest, InitAppDictConsultedFirst) {
|
| - catalogs_.push_back(
|
| - linked_ptr<base::DictionaryValue>(CreateGoodDictionary()));
|
| - catalogs_.push_back(
|
| - linked_ptr<base::DictionaryValue>(CreateGoodDictionary()));
|
| + catalogs_.push_back(CreateGoodDictionary());
|
| + catalogs_.push_back(CreateGoodDictionary());
|
|
|
| base::DictionaryValue* app_dict = catalogs_[0].get();
|
| // Flip placeholders in message of n1 tree.
|
| @@ -216,10 +211,8 @@ TEST_F(MessageBundleTest, InitAppDictConsultedFirst) {
|
| }
|
|
|
| TEST_F(MessageBundleTest, InitBadAppDict) {
|
| - catalogs_.push_back(
|
| - linked_ptr<base::DictionaryValue>(CreateBadDictionary(INVALID_NAME)));
|
| - catalogs_.push_back(
|
| - linked_ptr<base::DictionaryValue>(CreateGoodDictionary()));
|
| + catalogs_.push_back(CreateBadDictionary(INVALID_NAME));
|
| + catalogs_.push_back(CreateGoodDictionary());
|
|
|
| std::string error = CreateMessageBundle();
|
|
|
| @@ -227,45 +220,44 @@ TEST_F(MessageBundleTest, InitBadAppDict) {
|
| EXPECT_EQ("Name of a key \"n 5\" is invalid. Only ASCII [a-z], "
|
| "[A-Z], [0-9] and \"_\" are allowed.", error);
|
|
|
| - catalogs_[0].reset(CreateBadDictionary(NAME_NOT_A_TREE));
|
| + catalogs_[0] = CreateBadDictionary(NAME_NOT_A_TREE);
|
| handler_.reset(MessageBundle::Create(catalogs_, &error));
|
| EXPECT_TRUE(handler_.get() == NULL);
|
| EXPECT_EQ("Not a valid tree for key n4.", error);
|
|
|
| - catalogs_[0].reset(CreateBadDictionary(EMPTY_NAME_TREE));
|
| + catalogs_[0] = CreateBadDictionary(EMPTY_NAME_TREE);
|
| handler_.reset(MessageBundle::Create(catalogs_, &error));
|
| EXPECT_TRUE(handler_.get() == NULL);
|
| EXPECT_EQ("There is no \"message\" element for key n4.", error);
|
|
|
| - catalogs_[0].reset(CreateBadDictionary(MISSING_MESSAGE));
|
| + catalogs_[0] = CreateBadDictionary(MISSING_MESSAGE);
|
| handler_.reset(MessageBundle::Create(catalogs_, &error));
|
| EXPECT_TRUE(handler_.get() == NULL);
|
| EXPECT_EQ("There is no \"message\" element for key n1.", error);
|
|
|
| - catalogs_[0].reset(CreateBadDictionary(PLACEHOLDER_NOT_A_TREE));
|
| + catalogs_[0] = CreateBadDictionary(PLACEHOLDER_NOT_A_TREE);
|
| handler_.reset(MessageBundle::Create(catalogs_, &error));
|
| EXPECT_TRUE(handler_.get() == NULL);
|
| EXPECT_EQ("Not a valid \"placeholders\" element for key n1.", error);
|
|
|
| - catalogs_[0].reset(CreateBadDictionary(EMPTY_PLACEHOLDER_TREE));
|
| + catalogs_[0] = CreateBadDictionary(EMPTY_PLACEHOLDER_TREE);
|
| handler_.reset(MessageBundle::Create(catalogs_, &error));
|
| EXPECT_TRUE(handler_.get() == NULL);
|
| EXPECT_EQ("Variable $a$ used but not defined.", error);
|
|
|
| - catalogs_[0].reset(CreateBadDictionary(CONTENT_MISSING));
|
| + catalogs_[0] = CreateBadDictionary(CONTENT_MISSING);
|
| handler_.reset(MessageBundle::Create(catalogs_, &error));
|
| EXPECT_TRUE(handler_.get() == NULL);
|
| EXPECT_EQ("Invalid \"content\" element for key n1.", error);
|
|
|
| - catalogs_[0].reset(CreateBadDictionary(MESSAGE_PLACEHOLDER_DOESNT_MATCH));
|
| + catalogs_[0] = CreateBadDictionary(MESSAGE_PLACEHOLDER_DOESNT_MATCH);
|
| handler_.reset(MessageBundle::Create(catalogs_, &error));
|
| EXPECT_TRUE(handler_.get() == NULL);
|
| EXPECT_EQ("Variable $a$ used but not defined.", error);
|
| }
|
|
|
| TEST_F(MessageBundleTest, ReservedMessagesOverrideDeveloperMessages) {
|
| - catalogs_.push_back(
|
| - linked_ptr<base::DictionaryValue>(CreateGoodDictionary()));
|
| + catalogs_.push_back(CreateGoodDictionary());
|
|
|
| base::DictionaryValue* dict = catalogs_[0].get();
|
| CreateMessageTree(MessageBundle::kUILocaleKey, "x", false, dict);
|
|
|