OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "app/l10n_util.h" |
| 6 #include "base/file_util.h" |
| 7 #include "base/path_service.h" |
| 8 #include "base/scoped_temp_dir.h" |
| 9 #include "chrome/common/extensions/extension.h" |
| 10 #include "chrome/common/extensions/extension_resource.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 TEST(ExtensionResourceTest, CreateEmptyResource) { |
| 14 ExtensionResource resource; |
| 15 |
| 16 EXPECT_TRUE(resource.extension_root().empty()); |
| 17 EXPECT_TRUE(resource.relative_path().empty()); |
| 18 EXPECT_TRUE(resource.GetFilePath().empty()); |
| 19 } |
| 20 |
| 21 TEST(ExtensionResourceTest, CreateWithMissingResourceOnDisk) { |
| 22 FilePath path; |
| 23 ExtensionResource resource(path.AppendASCII("foo"), path.AppendASCII("bar")); |
| 24 |
| 25 EXPECT_TRUE(path.AppendASCII("foo") == resource.extension_root()); |
| 26 EXPECT_TRUE(path.AppendASCII("bar") == resource.relative_path()); |
| 27 EXPECT_TRUE(path.AppendASCII("foo").AppendASCII("bar") == |
| 28 resource.GetFilePath()); |
| 29 EXPECT_FALSE(resource.GetFilePath().empty()); |
| 30 } |
| 31 |
| 32 TEST(ExtensionResourceTest, CreateWithBothResourcesOnDisk) { |
| 33 ScopedTempDir temp; |
| 34 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 35 |
| 36 const char* filename = "res.ico"; |
| 37 FilePath root_resource = temp.path().AppendASCII(filename); |
| 38 std::string data = "some foo"; |
| 39 ASSERT_TRUE(file_util::WriteFile(root_resource.AppendASCII(filename), |
| 40 data.c_str(), data.length())); |
| 41 |
| 42 FilePath l10n_path = temp.path().AppendASCII(Extension::kLocaleFolder); |
| 43 ASSERT_TRUE(file_util::CreateDirectory(l10n_path)); |
| 44 |
| 45 static std::string current_locale = l10n_util::GetApplicationLocale(L""); |
| 46 std::replace(current_locale.begin(), current_locale.end(), '-', '_'); |
| 47 l10n_path = l10n_path.AppendASCII(current_locale); |
| 48 ASSERT_TRUE(file_util::CreateDirectory(l10n_path)); |
| 49 |
| 50 ASSERT_TRUE(file_util::WriteFile(l10n_path.AppendASCII(filename), |
| 51 data.c_str(), data.length())); |
| 52 |
| 53 FilePath path; |
| 54 ExtensionResource resource(temp.path(), FilePath().AppendASCII(filename)); |
| 55 FilePath resolved_path = resource.GetFilePath(); |
| 56 |
| 57 EXPECT_TRUE(l10n_path.AppendASCII(filename) == resolved_path); |
| 58 EXPECT_TRUE(temp.path() == resource.extension_root()); |
| 59 EXPECT_TRUE(FilePath().AppendASCII(filename) == resource.relative_path()); |
| 60 } |
OLD | NEW |