OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // The path doesn't exist on disk, we will be returned an empty path. | 45 // The path doesn't exist on disk, we will be returned an empty path. |
46 EXPECT_EQ(root_path.value(), resource.extension_root().value()); | 46 EXPECT_EQ(root_path.value(), resource.extension_root().value()); |
47 EXPECT_EQ(relative_path.value(), resource.relative_path().value()); | 47 EXPECT_EQ(relative_path.value(), resource.relative_path().value()); |
48 EXPECT_TRUE(resource.GetFilePath().empty()); | 48 EXPECT_TRUE(resource.GetFilePath().empty()); |
49 } | 49 } |
50 | 50 |
51 TEST(ExtensionResourceTest, ResourcesOutsideOfPath) { | 51 TEST(ExtensionResourceTest, ResourcesOutsideOfPath) { |
52 base::ScopedTempDir temp; | 52 base::ScopedTempDir temp; |
53 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 53 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
54 | 54 |
55 base::FilePath inner_dir = temp.path().AppendASCII("directory"); | 55 base::FilePath inner_dir = temp.GetPath().AppendASCII("directory"); |
56 ASSERT_TRUE(base::CreateDirectory(inner_dir)); | 56 ASSERT_TRUE(base::CreateDirectory(inner_dir)); |
57 base::FilePath sub_dir = inner_dir.AppendASCII("subdir"); | 57 base::FilePath sub_dir = inner_dir.AppendASCII("subdir"); |
58 ASSERT_TRUE(base::CreateDirectory(sub_dir)); | 58 ASSERT_TRUE(base::CreateDirectory(sub_dir)); |
59 base::FilePath inner_file = inner_dir.AppendASCII("inner"); | 59 base::FilePath inner_file = inner_dir.AppendASCII("inner"); |
60 base::FilePath outer_file = temp.path().AppendASCII("outer"); | 60 base::FilePath outer_file = temp.GetPath().AppendASCII("outer"); |
61 ASSERT_TRUE(base::WriteFile(outer_file, "X", 1)); | 61 ASSERT_TRUE(base::WriteFile(outer_file, "X", 1)); |
62 ASSERT_TRUE(base::WriteFile(inner_file, "X", 1)); | 62 ASSERT_TRUE(base::WriteFile(inner_file, "X", 1)); |
63 std::string extension_id = crx_file::id_util::GenerateId("test"); | 63 std::string extension_id = crx_file::id_util::GenerateId("test"); |
64 | 64 |
65 #if defined(OS_POSIX) | 65 #if defined(OS_POSIX) |
66 base::FilePath symlink_file = inner_dir.AppendASCII("symlink"); | 66 base::FilePath symlink_file = inner_dir.AppendASCII("symlink"); |
67 base::CreateSymbolicLink( | 67 base::CreateSymbolicLink( |
68 base::FilePath().AppendASCII("..").AppendASCII("outer"), | 68 base::FilePath().AppendASCII("..").AppendASCII("outer"), |
69 symlink_file); | 69 symlink_file); |
70 #endif | 70 #endif |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 EXPECT_FALSE(r6.GetFilePath().empty()); | 117 EXPECT_FALSE(r6.GetFilePath().empty()); |
118 #endif | 118 #endif |
119 } | 119 } |
120 | 120 |
121 TEST(ExtensionResourceTest, CreateWithAllResourcesOnDisk) { | 121 TEST(ExtensionResourceTest, CreateWithAllResourcesOnDisk) { |
122 base::ScopedTempDir temp; | 122 base::ScopedTempDir temp; |
123 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 123 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
124 | 124 |
125 // Create resource in the extension root. | 125 // Create resource in the extension root. |
126 const char* filename = "res.ico"; | 126 const char* filename = "res.ico"; |
127 base::FilePath root_resource = temp.path().AppendASCII(filename); | 127 base::FilePath root_resource = temp.GetPath().AppendASCII(filename); |
128 std::string data = "some foo"; | 128 std::string data = "some foo"; |
129 ASSERT_TRUE(base::WriteFile(root_resource, data.c_str(), data.length())); | 129 ASSERT_TRUE(base::WriteFile(root_resource, data.c_str(), data.length())); |
130 | 130 |
131 // Create l10n resources (for current locale and its parents). | 131 // Create l10n resources (for current locale and its parents). |
132 base::FilePath l10n_path = | 132 base::FilePath l10n_path = temp.GetPath().Append(kLocaleFolder); |
133 temp.path().Append(kLocaleFolder); | |
134 ASSERT_TRUE(base::CreateDirectory(l10n_path)); | 133 ASSERT_TRUE(base::CreateDirectory(l10n_path)); |
135 | 134 |
136 std::vector<std::string> locales; | 135 std::vector<std::string> locales; |
137 l10n_util::GetParentLocales(l10n_util::GetApplicationLocale(std::string()), | 136 l10n_util::GetParentLocales(l10n_util::GetApplicationLocale(std::string()), |
138 &locales); | 137 &locales); |
139 ASSERT_FALSE(locales.empty()); | 138 ASSERT_FALSE(locales.empty()); |
140 for (size_t i = 0; i < locales.size(); i++) { | 139 for (size_t i = 0; i < locales.size(); i++) { |
141 base::FilePath make_path; | 140 base::FilePath make_path; |
142 make_path = l10n_path.AppendASCII(locales[i]); | 141 make_path = l10n_path.AppendASCII(locales[i]); |
143 ASSERT_TRUE(base::CreateDirectory(make_path)); | 142 ASSERT_TRUE(base::CreateDirectory(make_path)); |
144 ASSERT_TRUE(base::WriteFile(make_path.AppendASCII(filename), | 143 ASSERT_TRUE(base::WriteFile(make_path.AppendASCII(filename), |
145 data.c_str(), data.length())); | 144 data.c_str(), data.length())); |
146 } | 145 } |
147 | 146 |
148 base::FilePath path; | 147 base::FilePath path; |
149 std::string extension_id = crx_file::id_util::GenerateId("test"); | 148 std::string extension_id = crx_file::id_util::GenerateId("test"); |
150 ExtensionResource resource(extension_id, temp.path(), | 149 ExtensionResource resource(extension_id, temp.GetPath(), |
151 base::FilePath().AppendASCII(filename)); | 150 base::FilePath().AppendASCII(filename)); |
152 const base::FilePath& resolved_path = resource.GetFilePath(); | 151 const base::FilePath& resolved_path = resource.GetFilePath(); |
153 | 152 |
154 base::FilePath expected_path; | 153 base::FilePath expected_path; |
155 // Expect default path only, since fallback logic is disabled. | 154 // Expect default path only, since fallback logic is disabled. |
156 // See http://crbug.com/27359. | 155 // See http://crbug.com/27359. |
157 expected_path = base::MakeAbsoluteFilePath(root_resource); | 156 expected_path = base::MakeAbsoluteFilePath(root_resource); |
158 ASSERT_FALSE(expected_path.empty()); | 157 ASSERT_FALSE(expected_path.empty()); |
159 | 158 |
160 EXPECT_EQ(ToLower(expected_path.value()), ToLower(resolved_path.value())); | 159 EXPECT_EQ(ToLower(expected_path.value()), ToLower(resolved_path.value())); |
161 EXPECT_EQ(ToLower(temp.path().value()), | 160 EXPECT_EQ(ToLower(temp.GetPath().value()), |
162 ToLower(resource.extension_root().value())); | 161 ToLower(resource.extension_root().value())); |
163 EXPECT_EQ(ToLower(base::FilePath().AppendASCII(filename).value()), | 162 EXPECT_EQ(ToLower(base::FilePath().AppendASCII(filename).value()), |
164 ToLower(resource.relative_path().value())); | 163 ToLower(resource.relative_path().value())); |
165 } | 164 } |
166 | 165 |
167 } // namespace extensions | 166 } // namespace extensions |
OLD | NEW |