summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_file_util_unittest.cc
diff options
context:
space:
mode:
authorcira@chromium.org <cira@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-18 21:07:39 +0000
committercira@chromium.org <cira@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-18 21:07:39 +0000
commit42b6f0f83579563a94bd9fdeec83574a1a932f18 (patch)
treebfdb770830f27f306eaeca8da46a6dd9e7ed8647 /chrome/browser/extensions/extension_file_util_unittest.cc
parent60ad3e2b8540ba00a2e5d0624fd2796e7780b11c (diff)
downloadchromium_src-42b6f0f83579563a94bd9fdeec83574a1a932f18.zip
chromium_src-42b6f0f83579563a94bd9fdeec83574a1a932f18.tar.gz
chromium_src-42b6f0f83579563a94bd9fdeec83574a1a932f18.tar.bz2
CL is the same as http://codereview.chromium.org/173487, but had to be moved to new CL number because I switched machines.
Implemented the rest of loading/parsing logic for extension i18n: 1. Loading message catalogs for default and application locale. 2. Parsing JSON and replacing placeholders with actual content within a message. 3. Creating unified dictionary (union of default and application dictionaries, where application dict. has priority for common messages). New class ExtensionMessageBundle holds new dictionary, and parses data. It's injected into Extension. ExtensionMessageHandler::ReplaceVariablesInString can replace both $placeholders$ and __MSG_messages__ in given string (HTML, manifest, actual message string...). Implemented actual manifest name/description replacement too, as an example. Extension is now pretty agnostic about localization, and this makes it easier to use message bundles with things that are not extensions... BUG=12131 Review URL: http://codereview.chromium.org/202063 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26609 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_file_util_unittest.cc')
-rw-r--r--chrome/browser/extensions/extension_file_util_unittest.cc72
1 files changed, 21 insertions, 51 deletions
diff --git a/chrome/browser/extensions/extension_file_util_unittest.cc b/chrome/browser/extensions/extension_file_util_unittest.cc
index 9f99606..7230ecd 100644
--- a/chrome/browser/extensions/extension_file_util_unittest.cc
+++ b/chrome/browser/extensions/extension_file_util_unittest.cc
@@ -10,7 +10,6 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_constants.h"
-#include "chrome/common/json_value_serializer.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace keys = extension_manifest_keys;
@@ -111,66 +110,37 @@ TEST(ExtensionFileUtil, CompareToInstalledVersion) {
temp.path(), kBadId, kMissingVersion, "1.0.0", &version_dir));
}
-// Creates minimal manifest, with or without default_locale section.
-bool CreateMinimalManifest(const std::string& locale,
- const FilePath& manifest_path) {
- DictionaryValue manifest;
-
- manifest.SetString(keys::kVersion, "1.0.0.0");
- manifest.SetString(keys::kName, "my extension");
- if (!locale.empty()) {
- manifest.SetString(keys::kDefaultLocale, locale);
- }
-
- JSONFileValueSerializer serializer(manifest_path);
- return serializer.Serialize(manifest);
-}
-
TEST(ExtensionFileUtil, LoadExtensionWithValidLocales) {
- ScopedTempDir temp;
- ASSERT_TRUE(temp.CreateUniqueTempDir());
- ASSERT_TRUE(CreateMinimalManifest(
- "en_US", temp.path().AppendASCII(Extension::kManifestFilename)));
-
- FilePath src_path = temp.path().AppendASCII(Extension::kLocaleFolder);
- ASSERT_TRUE(file_util::CreateDirectory(src_path));
-
- FilePath locale_1 = src_path.AppendASCII("sr");
- ASSERT_TRUE(file_util::CreateDirectory(locale_1));
-
- std::string data = "foobar";
- ASSERT_TRUE(
- file_util::WriteFile(locale_1.AppendASCII(Extension::kMessagesFilename),
- data.c_str(), data.length()));
-
- FilePath locale_2 = src_path.AppendASCII("en_US");
- ASSERT_TRUE(file_util::CreateDirectory(locale_2));
-
- ASSERT_TRUE(
- file_util::WriteFile(locale_2.AppendASCII(Extension::kMessagesFilename),
- data.c_str(), data.length()));
+ FilePath install_dir;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
+ install_dir = install_dir.AppendASCII("extensions")
+ .AppendASCII("good")
+ .AppendASCII("Extensions")
+ .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
+ .AppendASCII("1.0.0.0");
std::string error;
scoped_ptr<Extension> extension(
- extension_file_util::LoadExtension(temp.path(), false, &error));
- ASSERT_FALSE(extension == NULL);
- EXPECT_EQ(static_cast<unsigned int>(2),
- extension->supported_locales().size());
- EXPECT_EQ("en-US", extension->default_locale());
+ extension_file_util::LoadExtension(install_dir, false, &error));
+ ASSERT_TRUE(extension != NULL);
+ EXPECT_EQ("The first extension that I made.", extension->description());
}
TEST(ExtensionFileUtil, LoadExtensionWithoutLocalesFolder) {
- ScopedTempDir temp;
- ASSERT_TRUE(temp.CreateUniqueTempDir());
- ASSERT_TRUE(CreateMinimalManifest(
- "", temp.path().AppendASCII(Extension::kManifestFilename)));
+ FilePath install_dir;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
+ install_dir = install_dir.AppendASCII("extensions")
+ .AppendASCII("good")
+ .AppendASCII("Extensions")
+ .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa")
+ .AppendASCII("1.0");
std::string error;
scoped_ptr<Extension> extension(
- extension_file_util::LoadExtension(temp.path(), false, &error));
+ extension_file_util::LoadExtension(install_dir, false, &error));
ASSERT_FALSE(extension == NULL);
- EXPECT_TRUE(extension->supported_locales().empty());
- EXPECT_TRUE(extension->default_locale().empty());
+ EXPECT_TRUE(NULL == extension->message_bundle());
+ EXPECT_TRUE(error.empty());
}
TEST(ExtensionFileUtil, CheckIllegalFilenamesNoUnderscores) {
@@ -180,7 +150,7 @@ TEST(ExtensionFileUtil, CheckIllegalFilenamesNoUnderscores) {
FilePath src_path = temp.path().AppendASCII("some_dir");
ASSERT_TRUE(file_util::CreateDirectory(src_path));
- std::string data = "foobar";
+ std::string data = "{ \"name\": { \"message\": \"foobar\" } }";
ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("some_file.txt"),
data.c_str(), data.length()));
std::string error;