OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_message_bundle.h" | 5 #include "chrome/common/extensions/extension_message_bundle.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
| 10 #include "app/l10n_util.h" |
10 #include "base/linked_ptr.h" | 11 #include "base/linked_ptr.h" |
11 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/common/extensions/extension_constants.h" |
| 16 #include "chrome/common/extensions/extension_error_utils.h" |
| 17 #include "chrome/common/extensions/extension_l10n_util.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
15 | 19 |
16 namespace { | 20 namespace errors = extension_manifest_errors; |
17 | 21 |
18 // Helper method for dictionary building. | 22 class ExtensionMessageBundleTest : public testing::Test { |
19 void SetDictionary(const std::wstring name, | 23 protected: |
20 DictionaryValue* target, | 24 enum BadDictionary { |
21 DictionaryValue* subtree) { | 25 INVALID_NAME, |
22 target->Set(name, static_cast<Value*>(subtree)); | 26 NAME_NOT_A_TREE, |
| 27 EMPTY_NAME_TREE, |
| 28 MISSING_MESSAGE, |
| 29 PLACEHOLDER_NOT_A_TREE, |
| 30 EMPTY_PLACEHOLDER_TREE, |
| 31 CONTENT_MISSING, |
| 32 MESSAGE_PLACEHOLDER_DOESNT_MATCH, |
| 33 }; |
| 34 |
| 35 // Helper method for dictionary building. |
| 36 void SetDictionary(const std::wstring name, |
| 37 DictionaryValue* subtree, |
| 38 DictionaryValue* target) { |
| 39 target->Set(name, static_cast<Value*>(subtree)); |
| 40 } |
| 41 |
| 42 void CreateContentTree(const std::wstring& name, |
| 43 const std::string content, |
| 44 DictionaryValue* dict) { |
| 45 DictionaryValue* content_tree = new DictionaryValue; |
| 46 content_tree->SetString(ExtensionMessageBundle::kContentKey, content); |
| 47 SetDictionary(name, content_tree, dict); |
| 48 } |
| 49 |
| 50 void CreatePlaceholdersTree(DictionaryValue* dict) { |
| 51 DictionaryValue* placeholders_tree = new DictionaryValue; |
| 52 CreateContentTree(L"a", "A", placeholders_tree); |
| 53 CreateContentTree(L"b", "B", placeholders_tree); |
| 54 CreateContentTree(L"c", "C", placeholders_tree); |
| 55 SetDictionary(ExtensionMessageBundle::kPlaceholdersKey, |
| 56 placeholders_tree, |
| 57 dict); |
| 58 } |
| 59 |
| 60 void CreateMessageTree(const std::wstring& name, |
| 61 const std::string& message, |
| 62 bool create_placeholder_subtree, |
| 63 DictionaryValue* dict) { |
| 64 DictionaryValue* message_tree = new DictionaryValue; |
| 65 if (create_placeholder_subtree) |
| 66 CreatePlaceholdersTree(message_tree); |
| 67 message_tree->SetString(ExtensionMessageBundle::kMessageKey, message); |
| 68 SetDictionary(name, message_tree, dict); |
| 69 } |
| 70 |
| 71 // Caller owns the memory. |
| 72 DictionaryValue* CreateGoodDictionary() { |
| 73 DictionaryValue* dict = new DictionaryValue; |
| 74 CreateMessageTree(L"n1", "message1 $a$ $b$", true, dict); |
| 75 CreateMessageTree(L"n2", "message2 $c$", true, dict); |
| 76 CreateMessageTree(L"n3", "message3", false, dict); |
| 77 return dict; |
| 78 } |
| 79 |
| 80 // Caller owns the memory. |
| 81 DictionaryValue* CreateBadDictionary(enum BadDictionary what_is_bad) { |
| 82 DictionaryValue* dict = CreateGoodDictionary(); |
| 83 // Now remove/break things. |
| 84 switch (what_is_bad) { |
| 85 case INVALID_NAME: |
| 86 CreateMessageTree(L"n 5", "nevermind", false, dict); |
| 87 break; |
| 88 case NAME_NOT_A_TREE: |
| 89 dict->SetString(L"n4", "whatever"); |
| 90 break; |
| 91 case EMPTY_NAME_TREE: { |
| 92 DictionaryValue* empty_tree = new DictionaryValue; |
| 93 SetDictionary(L"n4", empty_tree, dict); |
| 94 } |
| 95 break; |
| 96 case MISSING_MESSAGE: |
| 97 dict->Remove(L"n1.message", NULL); |
| 98 break; |
| 99 case PLACEHOLDER_NOT_A_TREE: |
| 100 dict->SetString(L"n1.placeholders", "whatever"); |
| 101 break; |
| 102 case EMPTY_PLACEHOLDER_TREE: { |
| 103 DictionaryValue* empty_tree = new DictionaryValue; |
| 104 SetDictionary(L"n1.placeholders", empty_tree, dict); |
| 105 } |
| 106 break; |
| 107 case CONTENT_MISSING: |
| 108 dict->Remove(L"n1.placeholders.a.content", NULL); |
| 109 break; |
| 110 case MESSAGE_PLACEHOLDER_DOESNT_MATCH: |
| 111 DictionaryValue* value; |
| 112 dict->Remove(L"n1.placeholders.a", NULL); |
| 113 dict->GetDictionary(L"n1.placeholders", &value); |
| 114 CreateContentTree(L"x", "X", value); |
| 115 break; |
| 116 } |
| 117 |
| 118 return dict; |
| 119 } |
| 120 |
| 121 unsigned int ReservedMessagesCount() { |
| 122 // Update when adding new reserved messages. |
| 123 return 5U; |
| 124 } |
| 125 |
| 126 void CheckReservedMessages(ExtensionMessageBundle* handler) { |
| 127 std::string ui_locale = extension_l10n_util::CurrentLocaleOrDefault(); |
| 128 EXPECT_EQ(ui_locale, |
| 129 handler->GetL10nMessage(ExtensionMessageBundle::kUILocaleKey)); |
| 130 |
| 131 std::string text_dir = "ltr"; |
| 132 if (l10n_util::GetTextDirectionForLocale(ui_locale.c_str()) == |
| 133 l10n_util::RIGHT_TO_LEFT) |
| 134 text_dir = "rtl"; |
| 135 |
| 136 EXPECT_EQ(text_dir, handler->GetL10nMessage( |
| 137 ExtensionMessageBundle::kBidiDirectionKey)); |
| 138 } |
| 139 |
| 140 bool AppendReservedMessages(const std::string& application_locale) { |
| 141 std::string error; |
| 142 return handler_->AppendReservedMessages(application_locale, &error); |
| 143 } |
| 144 |
| 145 std::string CreateMessageBundle() { |
| 146 std::string error; |
| 147 handler_.reset(ExtensionMessageBundle::Create(catalogs_, &error)); |
| 148 |
| 149 return error; |
| 150 } |
| 151 |
| 152 void ClearDictionary() { |
| 153 handler_->dictionary_.clear(); |
| 154 } |
| 155 |
| 156 bool IsValidName(std::string name) { |
| 157 return ExtensionMessageBundle::IsValidName(name); |
| 158 } |
| 159 |
| 160 scoped_ptr<ExtensionMessageBundle> handler_; |
| 161 std::vector<linked_ptr<DictionaryValue> > catalogs_; |
| 162 }; |
| 163 |
| 164 TEST_F(ExtensionMessageBundleTest, ReservedMessagesCount) { |
| 165 ASSERT_EQ(5U, ReservedMessagesCount()); |
23 } | 166 } |
24 | 167 |
25 void CreateContentTree(const std::wstring& name, | 168 TEST_F(ExtensionMessageBundleTest, InitEmptyDictionaries) { |
26 const std::string content, | 169 CreateMessageBundle(); |
27 DictionaryValue* dict) { | 170 EXPECT_TRUE(handler_.get() != NULL); |
28 DictionaryValue* content_tree = new DictionaryValue; | 171 EXPECT_EQ(0U + ReservedMessagesCount(), handler_->size()); |
29 content_tree->SetString(ExtensionMessageBundle::kContentKey, content); | 172 CheckReservedMessages(handler_.get()); |
30 SetDictionary(name, dict, content_tree); | |
31 } | 173 } |
32 | 174 |
33 void CreatePlaceholdersTree(DictionaryValue* dict) { | 175 TEST_F(ExtensionMessageBundleTest, InitGoodDefaultDict) { |
34 DictionaryValue* placeholders_tree = new DictionaryValue; | 176 catalogs_.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary())); |
35 CreateContentTree(L"a", "A", placeholders_tree); | 177 CreateMessageBundle(); |
36 CreateContentTree(L"b", "B", placeholders_tree); | 178 |
37 CreateContentTree(L"c", "C", placeholders_tree); | 179 EXPECT_TRUE(handler_.get() != NULL); |
38 SetDictionary(ExtensionMessageBundle::kPlaceholdersKey, | 180 EXPECT_EQ(3U + ReservedMessagesCount(), handler_->size()); |
39 dict, | 181 |
40 placeholders_tree); | 182 EXPECT_EQ("message1 A B", handler_->GetL10nMessage("n1")); |
| 183 EXPECT_EQ("message2 C", handler_->GetL10nMessage("n2")); |
| 184 EXPECT_EQ("message3", handler_->GetL10nMessage("n3")); |
| 185 CheckReservedMessages(handler_.get()); |
41 } | 186 } |
42 | 187 |
43 void CreateMessageTree(const std::wstring& name, | 188 TEST_F(ExtensionMessageBundleTest, InitAppDictConsultedFirst) { |
44 const std::string& message, | 189 catalogs_.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary())); |
45 bool create_placeholder_subtree, | 190 catalogs_.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary())); |
46 DictionaryValue* dict) { | |
47 DictionaryValue* message_tree = new DictionaryValue; | |
48 if (create_placeholder_subtree) | |
49 CreatePlaceholdersTree(message_tree); | |
50 message_tree->SetString(ExtensionMessageBundle::kMessageKey, message); | |
51 SetDictionary(name, dict, message_tree); | |
52 } | |
53 | 191 |
54 // Caller owns the memory. | 192 DictionaryValue* app_dict = catalogs_[0].get(); |
55 DictionaryValue* CreateGoodDictionary() { | |
56 DictionaryValue* dict = new DictionaryValue; | |
57 CreateMessageTree(L"n1", "message1 $a$ $b$", true, dict); | |
58 CreateMessageTree(L"n2", "message2 $c$", true, dict); | |
59 CreateMessageTree(L"n3", "message3", false, dict); | |
60 return dict; | |
61 } | |
62 | |
63 enum BadDictionary { | |
64 INVALID_NAME, | |
65 NAME_NOT_A_TREE, | |
66 EMPTY_NAME_TREE, | |
67 MISSING_MESSAGE, | |
68 PLACEHOLDER_NOT_A_TREE, | |
69 EMPTY_PLACEHOLDER_TREE, | |
70 CONTENT_MISSING, | |
71 MESSAGE_PLACEHOLDER_DOESNT_MATCH, | |
72 }; | |
73 | |
74 // Caller owns the memory. | |
75 DictionaryValue* CreateBadDictionary(enum BadDictionary what_is_bad) { | |
76 DictionaryValue* dict = CreateGoodDictionary(); | |
77 // Now remove/break things. | |
78 switch (what_is_bad) { | |
79 case INVALID_NAME: | |
80 CreateMessageTree(L"n 5", "nevermind", false, dict); | |
81 break; | |
82 case NAME_NOT_A_TREE: | |
83 dict->SetString(L"n4", "whatever"); | |
84 break; | |
85 case EMPTY_NAME_TREE: { | |
86 DictionaryValue* empty_tree = new DictionaryValue; | |
87 SetDictionary(L"n4", dict, empty_tree); | |
88 } | |
89 break; | |
90 case MISSING_MESSAGE: | |
91 dict->Remove(L"n1.message", NULL); | |
92 break; | |
93 case PLACEHOLDER_NOT_A_TREE: | |
94 dict->SetString(L"n1.placeholders", "whatever"); | |
95 break; | |
96 case EMPTY_PLACEHOLDER_TREE: { | |
97 DictionaryValue* empty_tree = new DictionaryValue; | |
98 SetDictionary(L"n1.placeholders", dict, empty_tree); | |
99 } | |
100 break; | |
101 case CONTENT_MISSING: | |
102 dict->Remove(L"n1.placeholders.a.content", NULL); | |
103 break; | |
104 case MESSAGE_PLACEHOLDER_DOESNT_MATCH: | |
105 DictionaryValue* value; | |
106 dict->Remove(L"n1.placeholders.a", NULL); | |
107 dict->GetDictionary(L"n1.placeholders", &value); | |
108 CreateContentTree(L"x", "X", value); | |
109 break; | |
110 } | |
111 | |
112 return dict; | |
113 } | |
114 | |
115 TEST(ExtensionMessageBundle, InitEmptyDictionaries) { | |
116 std::vector<linked_ptr<DictionaryValue> > catalogs; | |
117 std::string error; | |
118 scoped_ptr<ExtensionMessageBundle> handler( | |
119 ExtensionMessageBundle::Create(catalogs, &error)); | |
120 | |
121 EXPECT_TRUE(handler.get() != NULL); | |
122 EXPECT_EQ(0U, handler->size()); | |
123 } | |
124 | |
125 TEST(ExtensionMessageBundle, InitGoodDefaultDict) { | |
126 std::vector<linked_ptr<DictionaryValue> > catalogs; | |
127 catalogs.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary())); | |
128 | |
129 std::string error; | |
130 scoped_ptr<ExtensionMessageBundle> handler( | |
131 ExtensionMessageBundle::Create(catalogs, &error)); | |
132 | |
133 EXPECT_TRUE(handler.get() != NULL); | |
134 EXPECT_EQ(3U, handler->size()); | |
135 | |
136 EXPECT_EQ("message1 A B", handler->GetL10nMessage("n1")); | |
137 EXPECT_EQ("message2 C", handler->GetL10nMessage("n2")); | |
138 EXPECT_EQ("message3", handler->GetL10nMessage("n3")); | |
139 } | |
140 | |
141 TEST(ExtensionMessageBundle, InitAppDictConsultedFirst) { | |
142 std::vector<linked_ptr<DictionaryValue> > catalogs; | |
143 catalogs.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary())); | |
144 catalogs.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary())); | |
145 | |
146 DictionaryValue* app_dict = catalogs[0].get(); | |
147 // Flip placeholders in message of n1 tree. | 193 // Flip placeholders in message of n1 tree. |
148 app_dict->SetString(L"n1.message", "message1 $b$ $a$"); | 194 app_dict->SetString(L"n1.message", "message1 $b$ $a$"); |
149 // Remove one message from app dict. | 195 // Remove one message from app dict. |
150 app_dict->Remove(L"n2", NULL); | 196 app_dict->Remove(L"n2", NULL); |
151 // Replace n3 with N3. | 197 // Replace n3 with N3. |
152 app_dict->Remove(L"n3", NULL); | 198 app_dict->Remove(L"n3", NULL); |
153 CreateMessageTree(L"N3", "message3_app_dict", false, app_dict); | 199 CreateMessageTree(L"N3", "message3_app_dict", false, app_dict); |
154 | 200 |
155 std::string error; | 201 CreateMessageBundle(); |
156 scoped_ptr<ExtensionMessageBundle> handler( | |
157 ExtensionMessageBundle::Create(catalogs, &error)); | |
158 | 202 |
159 EXPECT_TRUE(handler.get() != NULL); | 203 EXPECT_TRUE(handler_.get() != NULL); |
160 EXPECT_EQ(3U, handler->size()); | 204 EXPECT_EQ(3U + ReservedMessagesCount(), handler_->size()); |
161 | 205 |
162 EXPECT_EQ("message1 B A", handler->GetL10nMessage("n1")); | 206 EXPECT_EQ("message1 B A", handler_->GetL10nMessage("n1")); |
163 EXPECT_EQ("message2 C", handler->GetL10nMessage("n2")); | 207 EXPECT_EQ("message2 C", handler_->GetL10nMessage("n2")); |
164 EXPECT_EQ("message3_app_dict", handler->GetL10nMessage("n3")); | 208 EXPECT_EQ("message3_app_dict", handler_->GetL10nMessage("n3")); |
| 209 CheckReservedMessages(handler_.get()); |
165 } | 210 } |
166 | 211 |
167 TEST(ExtensionMessageBundle, InitBadAppDict) { | 212 TEST_F(ExtensionMessageBundleTest, InitBadAppDict) { |
168 std::vector<linked_ptr<DictionaryValue> > catalogs; | 213 catalogs_.push_back( |
169 catalogs.push_back( | |
170 linked_ptr<DictionaryValue>(CreateBadDictionary(INVALID_NAME))); | 214 linked_ptr<DictionaryValue>(CreateBadDictionary(INVALID_NAME))); |
171 catalogs.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary())); | 215 catalogs_.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary())); |
172 | 216 |
173 std::string error; | 217 std::string error = CreateMessageBundle(); |
174 scoped_ptr<ExtensionMessageBundle> handler( | |
175 ExtensionMessageBundle::Create(catalogs, &error)); | |
176 | 218 |
177 EXPECT_TRUE(handler.get() == NULL); | 219 EXPECT_TRUE(handler_.get() == NULL); |
178 EXPECT_EQ("Name of a key \"n 5\" is invalid. Only ASCII [a-z], " | 220 EXPECT_EQ("Name of a key \"n 5\" is invalid. Only ASCII [a-z], " |
179 "[A-Z], [0-9] and \"_\" are allowed.", error); | 221 "[A-Z], [0-9] and \"_\" are allowed.", error); |
180 | 222 |
181 catalogs[0].reset(CreateBadDictionary(NAME_NOT_A_TREE)); | 223 catalogs_[0].reset(CreateBadDictionary(NAME_NOT_A_TREE)); |
182 handler.reset(ExtensionMessageBundle::Create(catalogs, &error)); | 224 handler_.reset(ExtensionMessageBundle::Create(catalogs_, &error)); |
183 EXPECT_TRUE(handler.get() == NULL); | 225 EXPECT_TRUE(handler_.get() == NULL); |
184 EXPECT_EQ("Not a valid tree for key n4.", error); | 226 EXPECT_EQ("Not a valid tree for key n4.", error); |
185 | 227 |
186 catalogs[0].reset(CreateBadDictionary(EMPTY_NAME_TREE)); | 228 catalogs_[0].reset(CreateBadDictionary(EMPTY_NAME_TREE)); |
187 handler.reset(ExtensionMessageBundle::Create(catalogs, &error)); | 229 handler_.reset(ExtensionMessageBundle::Create(catalogs_, &error)); |
188 EXPECT_TRUE(handler.get() == NULL); | 230 EXPECT_TRUE(handler_.get() == NULL); |
189 EXPECT_EQ("There is no \"message\" element for key n4.", error); | 231 EXPECT_EQ("There is no \"message\" element for key n4.", error); |
190 | 232 |
191 catalogs[0].reset(CreateBadDictionary(MISSING_MESSAGE)); | 233 catalogs_[0].reset(CreateBadDictionary(MISSING_MESSAGE)); |
192 handler.reset(ExtensionMessageBundle::Create(catalogs, &error)); | 234 handler_.reset(ExtensionMessageBundle::Create(catalogs_, &error)); |
193 EXPECT_TRUE(handler.get() == NULL); | 235 EXPECT_TRUE(handler_.get() == NULL); |
194 EXPECT_EQ("There is no \"message\" element for key n1.", error); | 236 EXPECT_EQ("There is no \"message\" element for key n1.", error); |
195 | 237 |
196 catalogs[0].reset(CreateBadDictionary(PLACEHOLDER_NOT_A_TREE)); | 238 catalogs_[0].reset(CreateBadDictionary(PLACEHOLDER_NOT_A_TREE)); |
197 handler.reset(ExtensionMessageBundle::Create(catalogs, &error)); | 239 handler_.reset(ExtensionMessageBundle::Create(catalogs_, &error)); |
198 EXPECT_TRUE(handler.get() == NULL); | 240 EXPECT_TRUE(handler_.get() == NULL); |
199 EXPECT_EQ("Not a valid \"placeholders\" element for key n1.", error); | 241 EXPECT_EQ("Not a valid \"placeholders\" element for key n1.", error); |
200 | 242 |
201 catalogs[0].reset(CreateBadDictionary(EMPTY_PLACEHOLDER_TREE)); | 243 catalogs_[0].reset(CreateBadDictionary(EMPTY_PLACEHOLDER_TREE)); |
202 handler.reset(ExtensionMessageBundle::Create(catalogs, &error)); | 244 handler_.reset(ExtensionMessageBundle::Create(catalogs_, &error)); |
203 EXPECT_TRUE(handler.get() == NULL); | 245 EXPECT_TRUE(handler_.get() == NULL); |
204 EXPECT_EQ("Variable $a$ used but not defined.", error); | 246 EXPECT_EQ("Variable $a$ used but not defined.", error); |
205 | 247 |
206 catalogs[0].reset(CreateBadDictionary(CONTENT_MISSING)); | 248 catalogs_[0].reset(CreateBadDictionary(CONTENT_MISSING)); |
207 handler.reset(ExtensionMessageBundle::Create(catalogs, &error)); | 249 handler_.reset(ExtensionMessageBundle::Create(catalogs_, &error)); |
208 EXPECT_TRUE(handler.get() == NULL); | 250 EXPECT_TRUE(handler_.get() == NULL); |
209 EXPECT_EQ("Invalid \"content\" element for key n1.", error); | 251 EXPECT_EQ("Invalid \"content\" element for key n1.", error); |
210 | 252 |
211 catalogs[0].reset(CreateBadDictionary(MESSAGE_PLACEHOLDER_DOESNT_MATCH)); | 253 catalogs_[0].reset(CreateBadDictionary(MESSAGE_PLACEHOLDER_DOESNT_MATCH)); |
212 handler.reset(ExtensionMessageBundle::Create(catalogs, &error)); | 254 handler_.reset(ExtensionMessageBundle::Create(catalogs_, &error)); |
213 EXPECT_TRUE(handler.get() == NULL); | 255 EXPECT_TRUE(handler_.get() == NULL); |
214 EXPECT_EQ("Variable $a$ used but not defined.", error); | 256 EXPECT_EQ("Variable $a$ used but not defined.", error); |
215 } | 257 } |
216 | 258 |
| 259 TEST_F(ExtensionMessageBundleTest, ReservedMessagesOverrideDeveloperMessages) { |
| 260 catalogs_.push_back(linked_ptr<DictionaryValue>(CreateGoodDictionary())); |
| 261 |
| 262 DictionaryValue* dict = catalogs_[0].get(); |
| 263 CreateMessageTree( |
| 264 ASCIIToWide(ExtensionMessageBundle::kUILocaleKey), "x", false, dict); |
| 265 |
| 266 std::string error = CreateMessageBundle(); |
| 267 |
| 268 EXPECT_TRUE(handler_.get() == NULL); |
| 269 std::string expected_error = ExtensionErrorUtils::FormatErrorMessage( |
| 270 errors::kReservedMessageFound, ExtensionMessageBundle::kUILocaleKey); |
| 271 EXPECT_EQ(expected_error, error); |
| 272 } |
| 273 |
| 274 TEST_F(ExtensionMessageBundleTest, AppendReservedMessagesForLTR) { |
| 275 CreateMessageBundle(); |
| 276 |
| 277 ASSERT_TRUE(handler_.get() != NULL); |
| 278 ClearDictionary(); |
| 279 ASSERT_TRUE(AppendReservedMessages("en_US")); |
| 280 |
| 281 EXPECT_EQ("en_US", |
| 282 handler_->GetL10nMessage(ExtensionMessageBundle::kUILocaleKey)); |
| 283 EXPECT_EQ("ltr", handler_->GetL10nMessage( |
| 284 ExtensionMessageBundle::kBidiDirectionKey)); |
| 285 EXPECT_EQ("rtl", handler_->GetL10nMessage( |
| 286 ExtensionMessageBundle::kBidiReversedDirectionKey)); |
| 287 EXPECT_EQ("left", handler_->GetL10nMessage( |
| 288 ExtensionMessageBundle::kBidiStartEdgeKey)); |
| 289 EXPECT_EQ("right", handler_->GetL10nMessage( |
| 290 ExtensionMessageBundle::kBidiEndEdgeKey)); |
| 291 } |
| 292 |
| 293 TEST_F(ExtensionMessageBundleTest, AppendReservedMessagesForRTL) { |
| 294 CreateMessageBundle(); |
| 295 |
| 296 ASSERT_TRUE(handler_.get() != NULL); |
| 297 ClearDictionary(); |
| 298 ASSERT_TRUE(AppendReservedMessages("he")); |
| 299 |
| 300 EXPECT_EQ("he", |
| 301 handler_->GetL10nMessage(ExtensionMessageBundle::kUILocaleKey)); |
| 302 EXPECT_EQ("rtl", handler_->GetL10nMessage( |
| 303 ExtensionMessageBundle::kBidiDirectionKey)); |
| 304 EXPECT_EQ("ltr", handler_->GetL10nMessage( |
| 305 ExtensionMessageBundle::kBidiReversedDirectionKey)); |
| 306 EXPECT_EQ("right", handler_->GetL10nMessage( |
| 307 ExtensionMessageBundle::kBidiStartEdgeKey)); |
| 308 EXPECT_EQ("left", handler_->GetL10nMessage( |
| 309 ExtensionMessageBundle::kBidiEndEdgeKey)); |
| 310 } |
| 311 |
| 312 TEST_F(ExtensionMessageBundleTest, IsValidName) { |
| 313 EXPECT_TRUE(IsValidName("a__BV_9")); |
| 314 EXPECT_TRUE(IsValidName("@@a__BV_9")); |
| 315 EXPECT_FALSE(IsValidName("$a__BV_9$")); |
| 316 EXPECT_FALSE(IsValidName("a-BV-9")); |
| 317 EXPECT_FALSE(IsValidName("a#BV!9")); |
| 318 EXPECT_FALSE(IsValidName("a<b")); |
| 319 } |
| 320 |
217 struct ReplaceVariables { | 321 struct ReplaceVariables { |
218 const char* original; | 322 const char* original; |
219 const char* result; | 323 const char* result; |
220 const char* error; | 324 const char* error; |
221 const char* begin_delimiter; | 325 const char* begin_delimiter; |
222 const char* end_delimiter; | 326 const char* end_delimiter; |
223 bool pass; | 327 bool pass; |
224 }; | 328 }; |
225 | 329 |
226 TEST(ExtensionMessageBundle, ReplaceMessagesInText) { | 330 TEST(ExtensionMessageBundle, ReplaceMessagesInText) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 std::string error; | 386 std::string error; |
283 EXPECT_EQ(test_cases[i].pass, | 387 EXPECT_EQ(test_cases[i].pass, |
284 ExtensionMessageBundle::ReplaceVariables(messages, | 388 ExtensionMessageBundle::ReplaceVariables(messages, |
285 test_cases[i].begin_delimiter, | 389 test_cases[i].begin_delimiter, |
286 test_cases[i].end_delimiter, | 390 test_cases[i].end_delimiter, |
287 &text, | 391 &text, |
288 &error)); | 392 &error)); |
289 EXPECT_EQ(test_cases[i].result, text); | 393 EXPECT_EQ(test_cases[i].result, text); |
290 } | 394 } |
291 } | 395 } |
292 | |
293 } // namespace | |
OLD | NEW |