diff options
author | cira@chromium.org <cira@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-22 20:56:18 +0000 |
---|---|---|
committer | cira@chromium.org <cira@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-22 20:56:18 +0000 |
commit | af958dd5f74817150f58d762a1b99f05e5d355a6 (patch) | |
tree | 2d7b59b8a06d446e2caa9cfadc8ff69f1d78faa6 /chrome/common/extensions/extension_resource_unittest.cc | |
parent | 14e66f1c33488f4683337b5424170d2a27c98c07 (diff) | |
download | chromium_src-af958dd5f74817150f58d762a1b99f05e5d355a6.zip chromium_src-af958dd5f74817150f58d762a1b99f05e5d355a6.tar.gz chromium_src-af958dd5f74817150f58d762a1b99f05e5d355a6.tar.bz2 |
Loading local resources uses improved fallback algorithm.
Before:
_locales/current_locale/rel_path, then extension root/rel_path
Now:
_locales/{current_locale, parents}/rel_path, then extension root/rel_path
This change syncs local resource loading with catalog loading algo.
BUG=12131
Review URL: http://codereview.chromium.org/316013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29815 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/extension_resource_unittest.cc')
-rw-r--r-- | chrome/common/extensions/extension_resource_unittest.cc | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/chrome/common/extensions/extension_resource_unittest.cc b/chrome/common/extensions/extension_resource_unittest.cc index 7cc6ccf..6954408 100644 --- a/chrome/common/extensions/extension_resource_unittest.cc +++ b/chrome/common/extensions/extension_resource_unittest.cc @@ -8,6 +8,7 @@ #include "base/file_util.h" #include "base/path_service.h" #include "base/scoped_temp_dir.h" +#include "chrome/browser/extensions/extension_l10n_util.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_resource.h" @@ -42,33 +43,41 @@ TEST(ExtensionResourceTest, CreateWithMissingResourceOnDisk) { EXPECT_FALSE(resource.GetFilePath().empty()); } -TEST(ExtensionResourceTest, CreateWithBothResourcesOnDisk) { +TEST(ExtensionResourceTest, CreateWithAllResourcesOnDisk) { ScopedTempDir temp; ASSERT_TRUE(temp.CreateUniqueTempDir()); + // Create resource in the extension root. const char* filename = "res.ico"; FilePath root_resource = temp.path().AppendASCII(filename); std::string data = "some foo"; ASSERT_TRUE(file_util::WriteFile(root_resource.AppendASCII(filename), data.c_str(), data.length())); + // Create l10n resources (for current locale and its parents). FilePath l10n_path = temp.path().AppendASCII(Extension::kLocaleFolder); ASSERT_TRUE(file_util::CreateDirectory(l10n_path)); - static std::string current_locale = l10n_util::GetApplicationLocale(L""); - std::replace(current_locale.begin(), current_locale.end(), '-', '_'); - l10n_path = l10n_path.AppendASCII(current_locale); - ASSERT_TRUE(file_util::CreateDirectory(l10n_path)); - - ASSERT_TRUE(file_util::WriteFile(l10n_path.AppendASCII(filename), - data.c_str(), data.length())); + std::vector<std::string> locales; + extension_l10n_util::GetParentLocales(l10n_util::GetApplicationLocale(L""), + &locales); + for (size_t i = 0; i < locales.size(); i++) { + FilePath make_path; + make_path = l10n_path.AppendASCII(locales[i]); + ASSERT_TRUE(file_util::CreateDirectory(make_path)); + ASSERT_TRUE(file_util::WriteFile(make_path.AppendASCII(filename), + data.c_str(), data.length())); + } FilePath path; ExtensionResource resource(temp.path(), FilePath().AppendASCII(filename)); FilePath resolved_path = resource.GetFilePath(); - EXPECT_EQ(ToLower(l10n_path.AppendASCII(filename).value()), - ToLower(resolved_path.value())); + ASSERT_FALSE(locales.empty()); + FilePath expected_path; + expected_path = l10n_path.AppendASCII(locales[0]).AppendASCII(filename); + + EXPECT_EQ(ToLower(expected_path.value()), ToLower(resolved_path.value())); EXPECT_EQ(ToLower(temp.path().value()), ToLower(resource.extension_root().value())); EXPECT_EQ(ToLower(FilePath().AppendASCII(filename).value()), |