| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_l10n_util.h" | 5 #include "extensions/common/extension_l10n_util.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/memory/linked_ptr.h" | |
| 13 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 14 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/values.h" | 15 #include "base/values.h" |
| 17 #include "extensions/common/constants.h" | 16 #include "extensions/common/constants.h" |
| 18 #include "extensions/common/error_utils.h" | 17 #include "extensions/common/error_utils.h" |
| 19 #include "extensions/common/extension_paths.h" | 18 #include "extensions/common/extension_paths.h" |
| 20 #include "extensions/common/manifest_constants.h" | 19 #include "extensions/common/manifest_constants.h" |
| 21 #include "extensions/common/message_bundle.h" | 20 #include "extensions/common/message_bundle.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 // JSON parser hides duplicates. We are going to get only one key/value | 203 // JSON parser hides duplicates. We are going to get only one key/value |
| 205 // pair at the end. | 204 // pair at the end. |
| 206 std::unique_ptr<MessageBundle> message_bundle( | 205 std::unique_ptr<MessageBundle> message_bundle( |
| 207 extension_l10n_util::LoadMessageCatalogs(src_path, "en", "sr", &error)); | 206 extension_l10n_util::LoadMessageCatalogs(src_path, "en", "sr", &error)); |
| 208 EXPECT_TRUE(NULL != message_bundle.get()); | 207 EXPECT_TRUE(NULL != message_bundle.get()); |
| 209 EXPECT_TRUE(error.empty()); | 208 EXPECT_TRUE(error.empty()); |
| 210 } | 209 } |
| 211 | 210 |
| 212 // Caller owns the returned object. | 211 // Caller owns the returned object. |
| 213 MessageBundle* CreateManifestBundle() { | 212 MessageBundle* CreateManifestBundle() { |
| 214 linked_ptr<base::DictionaryValue> catalog(new base::DictionaryValue); | 213 std::unique_ptr<base::DictionaryValue> catalog(new base::DictionaryValue); |
| 215 | 214 |
| 216 base::DictionaryValue* name_tree = new base::DictionaryValue(); | 215 base::DictionaryValue* name_tree = new base::DictionaryValue(); |
| 217 name_tree->SetString("message", "name"); | 216 name_tree->SetString("message", "name"); |
| 218 catalog->Set("name", name_tree); | 217 catalog->Set("name", name_tree); |
| 219 | 218 |
| 220 base::DictionaryValue* short_name_tree = new base::DictionaryValue(); | 219 base::DictionaryValue* short_name_tree = new base::DictionaryValue(); |
| 221 short_name_tree->SetString("message", "short_name"); | 220 short_name_tree->SetString("message", "short_name"); |
| 222 catalog->Set("short_name", short_name_tree); | 221 catalog->Set("short_name", short_name_tree); |
| 223 | 222 |
| 224 base::DictionaryValue* description_tree = new base::DictionaryValue(); | 223 base::DictionaryValue* description_tree = new base::DictionaryValue(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 252 | 251 |
| 253 base::DictionaryValue* second_command_description_tree = | 252 base::DictionaryValue* second_command_description_tree = |
| 254 new base::DictionaryValue(); | 253 new base::DictionaryValue(); |
| 255 second_command_description_tree->SetString("message", "second command"); | 254 second_command_description_tree->SetString("message", "second command"); |
| 256 catalog->Set("second_command_description", second_command_description_tree); | 255 catalog->Set("second_command_description", second_command_description_tree); |
| 257 | 256 |
| 258 base::DictionaryValue* url_country_tree = new base::DictionaryValue(); | 257 base::DictionaryValue* url_country_tree = new base::DictionaryValue(); |
| 259 url_country_tree->SetString("message", "de"); | 258 url_country_tree->SetString("message", "de"); |
| 260 catalog->Set("country", url_country_tree); | 259 catalog->Set("country", url_country_tree); |
| 261 | 260 |
| 262 std::vector<linked_ptr<base::DictionaryValue> > catalogs; | 261 std::vector<std::unique_ptr<base::DictionaryValue>> catalogs; |
| 263 catalogs.push_back(catalog); | 262 catalogs.push_back(std::move(catalog)); |
| 264 | 263 |
| 265 std::string error; | 264 std::string error; |
| 266 MessageBundle* bundle = MessageBundle::Create(catalogs, &error); | 265 MessageBundle* bundle = MessageBundle::Create(catalogs, &error); |
| 267 EXPECT_TRUE(bundle); | 266 EXPECT_TRUE(bundle); |
| 268 EXPECT_TRUE(error.empty()); | 267 EXPECT_TRUE(error.empty()); |
| 269 | 268 |
| 270 return bundle; | 269 return bundle; |
| 271 } | 270 } |
| 272 | 271 |
| 273 TEST(ExtensionL10nUtil, LocalizeEmptyManifest) { | 272 TEST(ExtensionL10nUtil, LocalizeEmptyManifest) { |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 extension_l10n_util::GetAllFallbackLocales("en_US", "all", &fallback_locales); | 635 extension_l10n_util::GetAllFallbackLocales("en_US", "all", &fallback_locales); |
| 637 ASSERT_EQ(3U, fallback_locales.size()); | 636 ASSERT_EQ(3U, fallback_locales.size()); |
| 638 | 637 |
| 639 CHECK_EQ("en_US", fallback_locales[0]); | 638 CHECK_EQ("en_US", fallback_locales[0]); |
| 640 CHECK_EQ("en", fallback_locales[1]); | 639 CHECK_EQ("en", fallback_locales[1]); |
| 641 CHECK_EQ("all", fallback_locales[2]); | 640 CHECK_EQ("all", fallback_locales[2]); |
| 642 } | 641 } |
| 643 | 642 |
| 644 } // namespace | 643 } // namespace |
| 645 } // namespace extensions | 644 } // namespace extensions |
| OLD | NEW |