summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions
diff options
context:
space:
mode:
authorcira@chromium.org <cira@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-23 17:47:28 +0000
committercira@chromium.org <cira@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-23 17:47:28 +0000
commitfe9d18904e553876bc9c738753ac6f2dae2577d1 (patch)
treeabaa4ca710fc74287cd8c9928fc8e79bc75d805d /chrome/common/extensions
parent2d3958e39351802e65e1ded5a010d19607034b1b (diff)
downloadchromium_src-fe9d18904e553876bc9c738753ac6f2dae2577d1.zip
chromium_src-fe9d18904e553876bc9c738753ac6f2dae2577d1.tar.gz
chromium_src-fe9d18904e553876bc9c738753ac6f2dae2577d1.tar.bz2
Revert 36966 - Trying to reland. It's the same as http://codereview.chromium.org/546040. Moved IsValidName to public (where it was before the change),
and made test cases for it cleaner by explicitly using std::string() around var name. Add reserved messages to ExtensionMessageBundle dictionary. They are of the form @@somename, i.e. @@ui_locale. It makes easier for developers to detect current UI locale (also available though window.navigator.language), or text direction. I'll use them for static message replacement later on too. Before this change developers would have to manualy add locale and text_dir messages and translate for all supported locales. Added 5 reserved messages: @@ui_locale @@bidi_dir @@bidi_reversed_dir @@bidi_start_edge @@bidi_end_edge See http://code.google.com/apis/gadgets/docs/i18n.html#BIDI on why are they usefull. Extended allowed charset for variable names with @. Added unittest for variable names. TBR=jshin@chromium.org Review URL: http://codereview.chromium.org/551120 TBR=cira@chromium.org Review URL: http://codereview.chromium.org/545183 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36967 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions')
-rw-r--r--chrome/common/extensions/extension_constants.cc2
-rw-r--r--chrome/common/extensions/extension_constants.h1
-rw-r--r--chrome/common/extensions/extension_message_bundle.cc60
-rw-r--r--chrome/common/extensions/extension_message_bundle.h24
-rw-r--r--chrome/common/extensions/extension_message_bundle_unittest.cc401
5 files changed, 153 insertions, 335 deletions
diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc
index 79ba6d1..d203552 100644
--- a/chrome/common/extensions/extension_constants.cc
+++ b/chrome/common/extensions/extension_constants.cc
@@ -205,8 +205,6 @@ const char* kLocalesMessagesFileMissing =
"Messages file is missing for locale.";
const char* kInvalidOptionsPage =
"Invalid value for 'options_page'.";
-const char* kReservedMessageFound =
- "Reserved key * found in message catalog.";
} // namespace extension_manifest_errors
namespace extension_urls {
diff --git a/chrome/common/extensions/extension_constants.h b/chrome/common/extensions/extension_constants.h
index 079a479..c28c583 100644
--- a/chrome/common/extensions/extension_constants.h
+++ b/chrome/common/extensions/extension_constants.h
@@ -137,7 +137,6 @@ namespace extension_manifest_errors {
extern const char* kLocalesTreeMissing;
extern const char* kLocalesMessagesFileMissing;
extern const char* kInvalidOptionsPage;
- extern const char* kReservedMessageFound;
} // namespace extension_manifest_errors
namespace extension_urls {
diff --git a/chrome/common/extensions/extension_message_bundle.cc b/chrome/common/extensions/extension_message_bundle.cc
index 6d53080..02038db 100644
--- a/chrome/common/extensions/extension_message_bundle.cc
+++ b/chrome/common/extensions/extension_message_bundle.cc
@@ -7,18 +7,11 @@
#include <string>
#include <vector>
-#include "app/l10n_util.h"
#include "base/hash_tables.h"
#include "base/linked_ptr.h"
#include "base/scoped_ptr.h"
-#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "base/values.h"
-#include "chrome/common/extensions/extension_constants.h"
-#include "chrome/common/extensions/extension_error_utils.h"
-#include "chrome/common/extensions/extension_l10n_util.h"
-
-namespace errors = extension_manifest_errors;
const wchar_t* ExtensionMessageBundle::kContentKey = L"content";
const wchar_t* ExtensionMessageBundle::kMessageKey = L"message";
@@ -29,18 +22,6 @@ const char* ExtensionMessageBundle::kPlaceholderEnd = "$";
const char* ExtensionMessageBundle::kMessageBegin = "__MSG_";
const char* ExtensionMessageBundle::kMessageEnd = "__";
-// Reserved messages names.
-const char* ExtensionMessageBundle::kUILocaleKey = "@@ui_locale";
-const char* ExtensionMessageBundle::kBidiDirectionKey = "@@bidi_dir";
-const char* ExtensionMessageBundle::kBidiReversedDirectionKey =
- "@@bidi_reversed_dir";
-const char* ExtensionMessageBundle::kBidiStartEdgeKey = "@@bidi_start_edge";
-const char* ExtensionMessageBundle::kBidiEndEdgeKey = "@@bidi_end_edge";
-
-// Reserved messages values.
-const char* ExtensionMessageBundle::kBidiLeftEdgeValue = "left";
-const char* ExtensionMessageBundle::kBidiRightEdgeValue = "right";
-
// Formats message in case we encounter a bad formed key in the JSON object.
// Returns false and sets |error| to actual error message.
static bool BadKeyMessage(const std::string& name, std::string* error) {
@@ -81,45 +62,6 @@ bool ExtensionMessageBundle::Init(const CatalogVector& locale_catalogs,
}
}
- if (!AppendReservedMessagesForLocale(
- extension_l10n_util::CurrentLocaleOrDefault(), error))
- return false;
-
- return true;
-}
-
-bool ExtensionMessageBundle::AppendReservedMessagesForLocale(
- const std::string& app_locale, std::string* error) {
- SubstitutionMap append_messages;
- append_messages[kUILocaleKey] = app_locale;
-
- // Calling l10n_util::GetTextDirection on non-UI threads doesn't seems safe,
- // so we use GetTextDirectionForLocale instead.
- if (l10n_util::GetTextDirectionForLocale(app_locale.c_str()) ==
- l10n_util::RIGHT_TO_LEFT) {
- append_messages[kBidiDirectionKey] = "rtl";
- append_messages[kBidiReversedDirectionKey] = "ltr";
- append_messages[kBidiStartEdgeKey] = kBidiRightEdgeValue;
- append_messages[kBidiEndEdgeKey] = kBidiLeftEdgeValue;
- } else {
- append_messages[kBidiDirectionKey] = "ltr";
- append_messages[kBidiReversedDirectionKey] = "rtl";
- append_messages[kBidiStartEdgeKey] = kBidiLeftEdgeValue;
- append_messages[kBidiEndEdgeKey] = kBidiRightEdgeValue;
- }
-
- // Add all reserved messages to the dictionary, but check for collisions.
- SubstitutionMap::iterator it = append_messages.begin();
- for (; it != append_messages.end(); ++it) {
- if (ContainsKey(dictionary_, it->first)) {
- *error = ExtensionErrorUtils::FormatErrorMessage(
- errors::kReservedMessageFound, it->first);
- return false;
- } else {
- dictionary_[it->first] = it->second;
- }
- }
-
return true;
}
@@ -273,7 +215,7 @@ bool ExtensionMessageBundle::IsValidName(const str& name) {
for (typename str::const_iterator it = name.begin(); it != name.end(); ++it) {
// Allow only ascii 0-9, a-z, A-Z, and _ in the name.
- if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it) && *it != '_' && *it != '@')
+ if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it) && *it != '_')
return false;
}
diff --git a/chrome/common/extensions/extension_message_bundle.h b/chrome/common/extensions/extension_message_bundle.h
index b90d3a4..b44805c 100644
--- a/chrome/common/extensions/extension_message_bundle.h
+++ b/chrome/common/extensions/extension_message_bundle.h
@@ -30,21 +30,6 @@ class ExtensionMessageBundle {
static const char* kMessageBegin;
static const char* kMessageEnd;
- // Reserved message names in the dictionary.
- // Update i18n documentation when adding new reserved value.
- static const char* kUILocaleKey;
- // See http://code.google.com/apis/gadgets/docs/i18n.html#BIDI for
- // description.
- // TODO(cira): point to chrome docs once they are out.
- static const char* kBidiDirectionKey;
- static const char* kBidiReversedDirectionKey;
- static const char* kBidiStartEdgeKey;
- static const char* kBidiEndEdgeKey;
-
- // Values for some of the reserved messages.
- static const char* kBidiLeftEdgeValue;
- static const char* kBidiRightEdgeValue;
-
// Creates ExtensionMessageBundle or returns NULL if there was an error.
// Expects locale_catalogs to be sorted from more specific to less specific,
// with default catalog at the end.
@@ -85,6 +70,7 @@ class ExtensionMessageBundle {
// Allow only ascii 0-9, a-z, A-Z, and _ in the variable name.
// Returns false if the input is empty or if it has illegal characters.
+ // Public for easier unittesting.
template<typename str>
static bool IsValidName(const str& name);
@@ -92,9 +78,6 @@ class ExtensionMessageBundle {
const SubstitutionMap* dictionary() const { return &dictionary_; }
private:
- // Testing friend.
- friend class ExtensionMessageBundleTest;
-
// Use Create to create ExtensionMessageBundle instance.
ExtensionMessageBundle();
@@ -104,11 +87,6 @@ class ExtensionMessageBundle {
// Returns false on error.
bool Init(const CatalogVector& locale_catalogs, std::string* error);
- // Appends locale specific reserved messages to the dictionary.
- // Returns false if there was a conflict with user defined messages.
- bool AppendReservedMessagesForLocale(const std::string& application_locale,
- std::string* error);
-
// Helper methods that navigate JSON tree and return simplified message.
// They replace all $PLACEHOLDERS$ with their value, and return just key/value
// of the message.
diff --git a/chrome/common/extensions/extension_message_bundle_unittest.cc b/chrome/common/extensions/extension_message_bundle_unittest.cc
index f4d1f77..9c27055 100644
--- a/chrome/common/extensions/extension_message_bundle_unittest.cc
+++ b/chrome/common/extensions/extension_message_bundle_unittest.cc
@@ -7,186 +7,143 @@
#include <string>
#include <vector>
-#include "app/l10n_util.h"
#include "base/linked_ptr.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/values.h"
-#include "chrome/common/extensions/extension_constants.h"
-#include "chrome/common/extensions/extension_error_utils.h"
-#include "chrome/common/extensions/extension_l10n_util.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace errors = extension_manifest_errors;
-
-class ExtensionMessageBundleTest : public testing::Test {
- protected:
- enum BadDictionary {
- INVALID_NAME,
- NAME_NOT_A_TREE,
- EMPTY_NAME_TREE,
- MISSING_MESSAGE,
- PLACEHOLDER_NOT_A_TREE,
- EMPTY_PLACEHOLDER_TREE,
- CONTENT_MISSING,
- MESSAGE_PLACEHOLDER_DOESNT_MATCH,
- };
-
- // Helper method for dictionary building.
- void SetDictionary(const std::wstring name,
- DictionaryValue* subtree,
- DictionaryValue* target) {
- target->Set(name, static_cast<Value*>(subtree));
- }
-
- void CreateContentTree(const std::wstring& name,
- const std::string content,
- DictionaryValue* dict) {
- DictionaryValue* content_tree = new DictionaryValue;
- content_tree->SetString(ExtensionMessageBundle::kContentKey, content);
- SetDictionary(name, content_tree, dict);
- }
-
- void CreatePlaceholdersTree(DictionaryValue* dict) {
- DictionaryValue* placeholders_tree = new DictionaryValue;
- CreateContentTree(L"a", "A", placeholders_tree);
- CreateContentTree(L"b", "B", placeholders_tree);
- CreateContentTree(L"c", "C", placeholders_tree);
- SetDictionary(ExtensionMessageBundle::kPlaceholdersKey,
- placeholders_tree,
- dict);
- }
-
- void CreateMessageTree(const std::wstring& name,
- const std::string& message,
- bool create_placeholder_subtree,
- DictionaryValue* dict) {
- DictionaryValue* message_tree = new DictionaryValue;
- if (create_placeholder_subtree)
- CreatePlaceholdersTree(message_tree);
- message_tree->SetString(ExtensionMessageBundle::kMessageKey, message);
- SetDictionary(name, message_tree, dict);
- }
-
- // Caller owns the memory.
- DictionaryValue* CreateGoodDictionary() {
- DictionaryValue* dict = new DictionaryValue;
- CreateMessageTree(L"n1", "message1 $a$ $b$", true, dict);
- CreateMessageTree(L"n2", "message2 $c$", true, dict);
- CreateMessageTree(L"n3", "message3", false, dict);
- return dict;
- }
-
- // Caller owns the memory.
- DictionaryValue* CreateBadDictionary(enum BadDictionary what_is_bad) {
- DictionaryValue* dict = CreateGoodDictionary();
- // Now remove/break things.
- switch (what_is_bad) {
- case INVALID_NAME:
- CreateMessageTree(L"n 5", "nevermind", false, dict);
- break;
- case NAME_NOT_A_TREE:
- dict->SetString(L"n4", "whatever");
- break;
- case EMPTY_NAME_TREE: {
- DictionaryValue* empty_tree = new DictionaryValue;
- SetDictionary(L"n4", empty_tree, dict);
- }
- break;
- case MISSING_MESSAGE:
- dict->Remove(L"n1.message", NULL);
- break;
- case PLACEHOLDER_NOT_A_TREE:
- dict->SetString(L"n1.placeholders", "whatever");
- break;
- case EMPTY_PLACEHOLDER_TREE: {
- DictionaryValue* empty_tree = new DictionaryValue;
- SetDictionary(L"n1.placeholders", empty_tree, dict);
- }
- break;
- case CONTENT_MISSING:
- dict->Remove(L"n1.placeholders.a.content", NULL);
- break;
- case MESSAGE_PLACEHOLDER_DOESNT_MATCH:
- DictionaryValue* value;
- dict->Remove(L"n1.placeholders.a", NULL);
- dict->GetDictionary(L"n1.placeholders", &value);
- CreateContentTree(L"x", "X", value);
- break;
- }
-
- return dict;
- }
+namespace {
- unsigned int ReservedMessagesCount() {
- // Update when adding new reserved messages.
- return 5U;
- }
+// Helper method for dictionary building.
+void SetDictionary(const std::wstring name,
+ DictionaryValue* target,
+ DictionaryValue* subtree) {
+ target->Set(name, static_cast<Value*>(subtree));
+}
- void CheckReservedMessages(ExtensionMessageBundle* handler) {
- std::string ui_locale = extension_l10n_util::CurrentLocaleOrDefault();
- EXPECT_EQ(ui_locale,
- handler->GetL10nMessage(ExtensionMessageBundle::kUILocaleKey));
+void CreateContentTree(const std::wstring& name,
+ const std::string content,
+ DictionaryValue* dict) {
+ DictionaryValue* content_tree = new DictionaryValue;
+ content_tree->SetString(ExtensionMessageBundle::kContentKey, content);
+ SetDictionary(name, dict, content_tree);
+}
- std::string text_dir = "ltr";
- if (l10n_util::GetTextDirectionForLocale(ui_locale.c_str()) ==
- l10n_util::RIGHT_TO_LEFT)
- text_dir = "rtl";
+void CreatePlaceholdersTree(DictionaryValue* dict) {
+ DictionaryValue* placeholders_tree = new DictionaryValue;
+ CreateContentTree(L"a", "A", placeholders_tree);
+ CreateContentTree(L"b", "B", placeholders_tree);
+ CreateContentTree(L"c", "C", placeholders_tree);
+ SetDictionary(ExtensionMessageBundle::kPlaceholdersKey,
+ dict,
+ placeholders_tree);
+}
- EXPECT_EQ(text_dir, handler->GetL10nMessage(
- ExtensionMessageBundle::kBidiDirectionKey));
- }
+void CreateMessageTree(const std::wstring& name,
+ const std::string& message,
+ bool create_placeholder_subtree,
+ DictionaryValue* dict) {
+ DictionaryValue* message_tree = new DictionaryValue;
+ if (create_placeholder_subtree)
+ CreatePlaceholdersTree(message_tree);
+ message_tree->SetString(ExtensionMessageBundle::kMessageKey, message);
+ SetDictionary(name, dict, message_tree);
+}
- bool AppendReservedMessages(const std::string& application_locale) {
- std::string error;
- return handler_->AppendReservedMessagesForLocale(
- application_locale, &error);
- }
+// Caller owns the memory.
+DictionaryValue* CreateGoodDictionary() {
+ DictionaryValue* dict = new DictionaryValue;
+ CreateMessageTree(L"n1", "message1 $a$ $b$", true, dict);
+ CreateMessageTree(L"n2", "message2 $c$", true, dict);
+ CreateMessageTree(L"n3", "message3", false, dict);
+ return dict;
+}
- std::string CreateMessageBundle() {
- std::string error;
- handler_.reset(ExtensionMessageBundle::Create(catalogs_, &error));
+enum BadDictionary {
+ INVALID_NAME,
+ NAME_NOT_A_TREE,
+ EMPTY_NAME_TREE,
+ MISSING_MESSAGE,
+ PLACEHOLDER_NOT_A_TREE,
+ EMPTY_PLACEHOLDER_TREE,
+ CONTENT_MISSING,
+ MESSAGE_PLACEHOLDER_DOESNT_MATCH,
+};
- return error;
+// Caller owns the memory.
+DictionaryValue* CreateBadDictionary(enum BadDictionary what_is_bad) {
+ DictionaryValue* dict = CreateGoodDictionary();
+ // Now remove/break things.
+ switch (what_is_bad) {
+ case INVALID_NAME:
+ CreateMessageTree(L"n 5", "nevermind", false, dict);
+ break;
+ case NAME_NOT_A_TREE:
+ dict->SetString(L"n4", "whatever");
+ break;
+ case EMPTY_NAME_TREE: {
+ DictionaryValue* empty_tree = new DictionaryValue;
+ SetDictionary(L"n4", dict, empty_tree);
+ }
+ break;
+ case MISSING_MESSAGE:
+ dict->Remove(L"n1.message", NULL);
+ break;
+ case PLACEHOLDER_NOT_A_TREE:
+ dict->SetString(L"n1.placeholders", "whatever");
+ break;
+ case EMPTY_PLACEHOLDER_TREE: {
+ DictionaryValue* empty_tree = new DictionaryValue;
+ SetDictionary(L"n1.placeholders", dict, empty_tree);
+ }
+ break;
+ case CONTENT_MISSING:
+ dict->Remove(L"n1.placeholders.a.content", NULL);
+ break;
+ case MESSAGE_PLACEHOLDER_DOESNT_MATCH:
+ DictionaryValue* value;
+ dict->Remove(L"n1.placeholders.a", NULL);
+ dict->GetDictionary(L"n1.placeholders", &value);
+ CreateContentTree(L"x", "X", value);
+ break;
}
- void ClearDictionary() {
- handler_->dictionary_.clear();
- }
+ return dict;
+}
- scoped_ptr<ExtensionMessageBundle> handler_;
- std::vector<linked_ptr<DictionaryValue> > catalogs_;
-};
+TEST(ExtensionMessageBundle, InitEmptyDictionaries) {
+ std::vector<linked_ptr<DictionaryValue> > catalogs;
+ std::string error;
+ scoped_ptr<ExtensionMessageBundle> handler(
+ ExtensionMessageBundle::Create(catalogs, &error));
-TEST_F(ExtensionMessageBundleTest, ReservedMessagesCount) {
- ASSERT_EQ(5U, ReservedMessagesCount());
+ EXPECT_TRUE(handler.get() != NULL);
+ EXPECT_EQ(0U, handler->size());
}
-TEST_F(ExtensionMessageBundleTest, InitEmptyDictionaries) {
- CreateMessageBundle();
- EXPECT_TRUE(handler_.get() != NULL);
- EXPECT_EQ(0U + ReservedMessagesCount(), handler_->size());
- CheckReservedMessages(handler_.get());
-}
+TEST(ExtensionMessageBundle, InitGoodDefaultDict) {
+ std::vector<linked_ptr<DictionaryValue> > catalogs;
+ catalogs.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary()));
-TEST_F(ExtensionMessageBundleTest, InitGoodDefaultDict) {
- catalogs_.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary()));
- CreateMessageBundle();
+ std::string error;
+ scoped_ptr<ExtensionMessageBundle> handler(
+ ExtensionMessageBundle::Create(catalogs, &error));
- EXPECT_TRUE(handler_.get() != NULL);
- EXPECT_EQ(3U + ReservedMessagesCount(), handler_->size());
+ EXPECT_TRUE(handler.get() != NULL);
+ EXPECT_EQ(3U, handler->size());
- EXPECT_EQ("message1 A B", handler_->GetL10nMessage("n1"));
- EXPECT_EQ("message2 C", handler_->GetL10nMessage("n2"));
- EXPECT_EQ("message3", handler_->GetL10nMessage("n3"));
- CheckReservedMessages(handler_.get());
+ EXPECT_EQ("message1 A B", handler->GetL10nMessage("n1"));
+ EXPECT_EQ("message2 C", handler->GetL10nMessage("n2"));
+ EXPECT_EQ("message3", handler->GetL10nMessage("n3"));
}
-TEST_F(ExtensionMessageBundleTest, InitAppDictConsultedFirst) {
- catalogs_.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary()));
- catalogs_.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary()));
+TEST(ExtensionMessageBundle, InitAppDictConsultedFirst) {
+ std::vector<linked_ptr<DictionaryValue> > catalogs;
+ catalogs.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary()));
+ catalogs.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary()));
- DictionaryValue* app_dict = catalogs_[0].get();
+ DictionaryValue* app_dict = catalogs[0].get();
// Flip placeholders in message of n1 tree.
app_dict->SetString(L"n1.message", "message1 $b$ $a$");
// Remove one message from app dict.
@@ -195,126 +152,68 @@ TEST_F(ExtensionMessageBundleTest, InitAppDictConsultedFirst) {
app_dict->Remove(L"n3", NULL);
CreateMessageTree(L"N3", "message3_app_dict", false, app_dict);
- CreateMessageBundle();
+ std::string error;
+ scoped_ptr<ExtensionMessageBundle> handler(
+ ExtensionMessageBundle::Create(catalogs, &error));
- EXPECT_TRUE(handler_.get() != NULL);
- EXPECT_EQ(3U + ReservedMessagesCount(), handler_->size());
+ EXPECT_TRUE(handler.get() != NULL);
+ EXPECT_EQ(3U, handler->size());
- EXPECT_EQ("message1 B A", handler_->GetL10nMessage("n1"));
- EXPECT_EQ("message2 C", handler_->GetL10nMessage("n2"));
- EXPECT_EQ("message3_app_dict", handler_->GetL10nMessage("n3"));
- CheckReservedMessages(handler_.get());
+ EXPECT_EQ("message1 B A", handler->GetL10nMessage("n1"));
+ EXPECT_EQ("message2 C", handler->GetL10nMessage("n2"));
+ EXPECT_EQ("message3_app_dict", handler->GetL10nMessage("n3"));
}
-TEST_F(ExtensionMessageBundleTest, InitBadAppDict) {
- catalogs_.push_back(
+TEST(ExtensionMessageBundle, InitBadAppDict) {
+ std::vector<linked_ptr<DictionaryValue> > catalogs;
+ catalogs.push_back(
linked_ptr<DictionaryValue>(CreateBadDictionary(INVALID_NAME)));
- catalogs_.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary()));
+ catalogs.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary()));
- std::string error = CreateMessageBundle();
+ std::string error;
+ scoped_ptr<ExtensionMessageBundle> handler(
+ ExtensionMessageBundle::Create(catalogs, &error));
- EXPECT_TRUE(handler_.get() == NULL);
+ EXPECT_TRUE(handler.get() == NULL);
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));
- handler_.reset(ExtensionMessageBundle::Create(catalogs_, &error));
- EXPECT_TRUE(handler_.get() == NULL);
+ catalogs[0].reset(CreateBadDictionary(NAME_NOT_A_TREE));
+ handler.reset(ExtensionMessageBundle::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));
- handler_.reset(ExtensionMessageBundle::Create(catalogs_, &error));
- EXPECT_TRUE(handler_.get() == NULL);
+ catalogs[0].reset(CreateBadDictionary(EMPTY_NAME_TREE));
+ handler.reset(ExtensionMessageBundle::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));
- handler_.reset(ExtensionMessageBundle::Create(catalogs_, &error));
- EXPECT_TRUE(handler_.get() == NULL);
+ catalogs[0].reset(CreateBadDictionary(MISSING_MESSAGE));
+ handler.reset(ExtensionMessageBundle::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));
- handler_.reset(ExtensionMessageBundle::Create(catalogs_, &error));
- EXPECT_TRUE(handler_.get() == NULL);
+ catalogs[0].reset(CreateBadDictionary(PLACEHOLDER_NOT_A_TREE));
+ handler.reset(ExtensionMessageBundle::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));
- handler_.reset(ExtensionMessageBundle::Create(catalogs_, &error));
- EXPECT_TRUE(handler_.get() == NULL);
+ catalogs[0].reset(CreateBadDictionary(EMPTY_PLACEHOLDER_TREE));
+ handler.reset(ExtensionMessageBundle::Create(catalogs, &error));
+ EXPECT_TRUE(handler.get() == NULL);
EXPECT_EQ("Variable $a$ used but not defined.", error);
- catalogs_[0].reset(CreateBadDictionary(CONTENT_MISSING));
- handler_.reset(ExtensionMessageBundle::Create(catalogs_, &error));
- EXPECT_TRUE(handler_.get() == NULL);
+ catalogs[0].reset(CreateBadDictionary(CONTENT_MISSING));
+ handler.reset(ExtensionMessageBundle::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));
- handler_.reset(ExtensionMessageBundle::Create(catalogs_, &error));
- EXPECT_TRUE(handler_.get() == NULL);
+ catalogs[0].reset(CreateBadDictionary(MESSAGE_PLACEHOLDER_DOESNT_MATCH));
+ handler.reset(ExtensionMessageBundle::Create(catalogs, &error));
+ EXPECT_TRUE(handler.get() == NULL);
EXPECT_EQ("Variable $a$ used but not defined.", error);
}
-TEST_F(ExtensionMessageBundleTest, ReservedMessagesOverrideDeveloperMessages) {
- catalogs_.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary()));
-
- DictionaryValue* dict = catalogs_[0].get();
- CreateMessageTree(
- ASCIIToWide(ExtensionMessageBundle::kUILocaleKey), "x", false, dict);
-
- std::string error = CreateMessageBundle();
-
- EXPECT_TRUE(handler_.get() == NULL);
- std::string expected_error = ExtensionErrorUtils::FormatErrorMessage(
- errors::kReservedMessageFound, ExtensionMessageBundle::kUILocaleKey);
- EXPECT_EQ(expected_error, error);
-}
-
-TEST_F(ExtensionMessageBundleTest, AppendReservedMessagesForLTR) {
- CreateMessageBundle();
-
- ASSERT_TRUE(handler_.get() != NULL);
- ClearDictionary();
- ASSERT_TRUE(AppendReservedMessages("en_US"));
-
- EXPECT_EQ("en_US",
- handler_->GetL10nMessage(ExtensionMessageBundle::kUILocaleKey));
- EXPECT_EQ("ltr", handler_->GetL10nMessage(
- ExtensionMessageBundle::kBidiDirectionKey));
- EXPECT_EQ("rtl", handler_->GetL10nMessage(
- ExtensionMessageBundle::kBidiReversedDirectionKey));
- EXPECT_EQ("left", handler_->GetL10nMessage(
- ExtensionMessageBundle::kBidiStartEdgeKey));
- EXPECT_EQ("right", handler_->GetL10nMessage(
- ExtensionMessageBundle::kBidiEndEdgeKey));
-}
-
-TEST_F(ExtensionMessageBundleTest, AppendReservedMessagesForRTL) {
- CreateMessageBundle();
-
- ASSERT_TRUE(handler_.get() != NULL);
- ClearDictionary();
- ASSERT_TRUE(AppendReservedMessages("he"));
-
- EXPECT_EQ("he",
- handler_->GetL10nMessage(ExtensionMessageBundle::kUILocaleKey));
- EXPECT_EQ("rtl", handler_->GetL10nMessage(
- ExtensionMessageBundle::kBidiDirectionKey));
- EXPECT_EQ("ltr", handler_->GetL10nMessage(
- ExtensionMessageBundle::kBidiReversedDirectionKey));
- EXPECT_EQ("right", handler_->GetL10nMessage(
- ExtensionMessageBundle::kBidiStartEdgeKey));
- EXPECT_EQ("left", handler_->GetL10nMessage(
- ExtensionMessageBundle::kBidiEndEdgeKey));
-}
-
-TEST_F(ExtensionMessageBundleTest, IsValidNameCheckValidCharacters) {
- EXPECT_TRUE(ExtensionMessageBundle::IsValidName(std::string("a__BV_9")));
- EXPECT_TRUE(ExtensionMessageBundle::IsValidName(std::string("@@a__BV_9")));
- EXPECT_FALSE(ExtensionMessageBundle::IsValidName(std::string("$a__BV_9$")));
- EXPECT_FALSE(ExtensionMessageBundle::IsValidName(std::string("a-BV-9")));
- EXPECT_FALSE(ExtensionMessageBundle::IsValidName(std::string("a#BV!9")));
- EXPECT_FALSE(ExtensionMessageBundle::IsValidName(std::string("a<b")));
-}
-
struct ReplaceVariables {
const char* original;
const char* result;
@@ -390,3 +289,5 @@ TEST(ExtensionMessageBundle, ReplaceMessagesInText) {
EXPECT_EQ(test_cases[i].result, text);
}
}
+
+} // namespace