Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: extensions/common/extension_resource_unittest.cc

Issue 100573002: Move directory creation functions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « crypto/nss_util.cc ('k') | extensions/common/file_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "extensions/common/constants.h" 10 #include "extensions/common/constants.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 EXPECT_EQ(root_path.value(), resource.extension_root().value()); 43 EXPECT_EQ(root_path.value(), resource.extension_root().value());
44 EXPECT_EQ(relative_path.value(), resource.relative_path().value()); 44 EXPECT_EQ(relative_path.value(), resource.relative_path().value());
45 EXPECT_TRUE(resource.GetFilePath().empty()); 45 EXPECT_TRUE(resource.GetFilePath().empty());
46 } 46 }
47 47
48 TEST(ExtensionResourceTest, ResourcesOutsideOfPath) { 48 TEST(ExtensionResourceTest, ResourcesOutsideOfPath) {
49 base::ScopedTempDir temp; 49 base::ScopedTempDir temp;
50 ASSERT_TRUE(temp.CreateUniqueTempDir()); 50 ASSERT_TRUE(temp.CreateUniqueTempDir());
51 51
52 base::FilePath inner_dir = temp.path().AppendASCII("directory"); 52 base::FilePath inner_dir = temp.path().AppendASCII("directory");
53 ASSERT_TRUE(file_util::CreateDirectory(inner_dir)); 53 ASSERT_TRUE(base::CreateDirectory(inner_dir));
54 base::FilePath sub_dir = inner_dir.AppendASCII("subdir"); 54 base::FilePath sub_dir = inner_dir.AppendASCII("subdir");
55 ASSERT_TRUE(file_util::CreateDirectory(sub_dir)); 55 ASSERT_TRUE(base::CreateDirectory(sub_dir));
56 base::FilePath inner_file = inner_dir.AppendASCII("inner"); 56 base::FilePath inner_file = inner_dir.AppendASCII("inner");
57 base::FilePath outer_file = temp.path().AppendASCII("outer"); 57 base::FilePath outer_file = temp.path().AppendASCII("outer");
58 ASSERT_TRUE(file_util::WriteFile(outer_file, "X", 1)); 58 ASSERT_TRUE(file_util::WriteFile(outer_file, "X", 1));
59 ASSERT_TRUE(file_util::WriteFile(inner_file, "X", 1)); 59 ASSERT_TRUE(file_util::WriteFile(inner_file, "X", 1));
60 std::string extension_id = id_util::GenerateId("test"); 60 std::string extension_id = id_util::GenerateId("test");
61 61
62 #if defined(OS_POSIX) 62 #if defined(OS_POSIX)
63 base::FilePath symlink_file = inner_dir.AppendASCII("symlink"); 63 base::FilePath symlink_file = inner_dir.AppendASCII("symlink");
64 base::CreateSymbolicLink( 64 base::CreateSymbolicLink(
65 base::FilePath().AppendASCII("..").AppendASCII("outer"), 65 base::FilePath().AppendASCII("..").AppendASCII("outer"),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 121
122 // Create resource in the extension root. 122 // Create resource in the extension root.
123 const char* filename = "res.ico"; 123 const char* filename = "res.ico";
124 base::FilePath root_resource = temp.path().AppendASCII(filename); 124 base::FilePath root_resource = temp.path().AppendASCII(filename);
125 std::string data = "some foo"; 125 std::string data = "some foo";
126 ASSERT_TRUE(file_util::WriteFile(root_resource, data.c_str(), data.length())); 126 ASSERT_TRUE(file_util::WriteFile(root_resource, data.c_str(), data.length()));
127 127
128 // Create l10n resources (for current locale and its parents). 128 // Create l10n resources (for current locale and its parents).
129 base::FilePath l10n_path = 129 base::FilePath l10n_path =
130 temp.path().Append(kLocaleFolder); 130 temp.path().Append(kLocaleFolder);
131 ASSERT_TRUE(file_util::CreateDirectory(l10n_path)); 131 ASSERT_TRUE(base::CreateDirectory(l10n_path));
132 132
133 std::vector<std::string> locales; 133 std::vector<std::string> locales;
134 l10n_util::GetParentLocales(l10n_util::GetApplicationLocale(std::string()), 134 l10n_util::GetParentLocales(l10n_util::GetApplicationLocale(std::string()),
135 &locales); 135 &locales);
136 ASSERT_FALSE(locales.empty()); 136 ASSERT_FALSE(locales.empty());
137 for (size_t i = 0; i < locales.size(); i++) { 137 for (size_t i = 0; i < locales.size(); i++) {
138 base::FilePath make_path; 138 base::FilePath make_path;
139 make_path = l10n_path.AppendASCII(locales[i]); 139 make_path = l10n_path.AppendASCII(locales[i]);
140 ASSERT_TRUE(file_util::CreateDirectory(make_path)); 140 ASSERT_TRUE(base::CreateDirectory(make_path));
141 ASSERT_TRUE(file_util::WriteFile(make_path.AppendASCII(filename), 141 ASSERT_TRUE(file_util::WriteFile(make_path.AppendASCII(filename),
142 data.c_str(), data.length())); 142 data.c_str(), data.length()));
143 } 143 }
144 144
145 base::FilePath path; 145 base::FilePath path;
146 std::string extension_id = id_util::GenerateId("test"); 146 std::string extension_id = id_util::GenerateId("test");
147 ExtensionResource resource(extension_id, temp.path(), 147 ExtensionResource resource(extension_id, temp.path(),
148 base::FilePath().AppendASCII(filename)); 148 base::FilePath().AppendASCII(filename));
149 base::FilePath resolved_path = resource.GetFilePath(); 149 base::FilePath resolved_path = resource.GetFilePath();
150 150
151 base::FilePath expected_path; 151 base::FilePath expected_path;
152 // Expect default path only, since fallback logic is disabled. 152 // Expect default path only, since fallback logic is disabled.
153 // See http://crbug.com/27359. 153 // See http://crbug.com/27359.
154 expected_path = base::MakeAbsoluteFilePath(root_resource); 154 expected_path = base::MakeAbsoluteFilePath(root_resource);
155 ASSERT_FALSE(expected_path.empty()); 155 ASSERT_FALSE(expected_path.empty());
156 156
157 EXPECT_EQ(ToLower(expected_path.value()), ToLower(resolved_path.value())); 157 EXPECT_EQ(ToLower(expected_path.value()), ToLower(resolved_path.value()));
158 EXPECT_EQ(ToLower(temp.path().value()), 158 EXPECT_EQ(ToLower(temp.path().value()),
159 ToLower(resource.extension_root().value())); 159 ToLower(resource.extension_root().value()));
160 EXPECT_EQ(ToLower(base::FilePath().AppendASCII(filename).value()), 160 EXPECT_EQ(ToLower(base::FilePath().AppendASCII(filename).value()),
161 ToLower(resource.relative_path().value())); 161 ToLower(resource.relative_path().value()));
162 } 162 }
163 163
164 } // namespace extensions 164 } // namespace extensions
OLDNEW
« no previous file with comments | « crypto/nss_util.cc ('k') | extensions/common/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698