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

Side by Side Diff: chrome/browser/platform_util_unittest.cc

Issue 2317123002: c/browser, c/common, components O-P: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Just rebased Created 4 years, 3 months 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
« no previous file with comments | « no previous file | chrome/browser/policy/cloud/cloud_policy_browsertest.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/platform_util.h" 5 #include "chrome/browser/platform_util.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 const int kTestFileDataLength = arraysize(kTestFileData) - 1; 150 const int kTestFileDataLength = arraysize(kTestFileData) - 1;
151 151
152 // This prevents platfrom_util from invoking any shell or external APIs 152 // This prevents platfrom_util from invoking any shell or external APIs
153 // during tests. Doing so may result in external applications being launched 153 // during tests. Doing so may result in external applications being launched
154 // and intefering with tests. 154 // and intefering with tests.
155 internal::DisableShellOperationsForTesting(); 155 internal::DisableShellOperationsForTesting();
156 156
157 ASSERT_TRUE(directory_.CreateUniqueTempDir()); 157 ASSERT_TRUE(directory_.CreateUniqueTempDir());
158 158
159 // A valid file. 159 // A valid file.
160 existing_file_ = directory_.path().AppendASCII("test_file.txt"); 160 existing_file_ = directory_.GetPath().AppendASCII("test_file.txt");
161 ASSERT_EQ( 161 ASSERT_EQ(
162 kTestFileDataLength, 162 kTestFileDataLength,
163 base::WriteFile(existing_file_, kTestFileData, kTestFileDataLength)); 163 base::WriteFile(existing_file_, kTestFileData, kTestFileDataLength));
164 164
165 // A valid folder. 165 // A valid folder.
166 existing_folder_ = directory_.path().AppendASCII("test_folder"); 166 existing_folder_ = directory_.GetPath().AppendASCII("test_folder");
167 ASSERT_TRUE(base::CreateDirectory(existing_folder_)); 167 ASSERT_TRUE(base::CreateDirectory(existing_folder_));
168 168
169 // A non-existent path. 169 // A non-existent path.
170 nowhere_ = directory_.path().AppendASCII("nowhere"); 170 nowhere_ = directory_.GetPath().AppendASCII("nowhere");
171 171
172 SetUpPlatformFixture(directory_.path()); 172 SetUpPlatformFixture(directory_.GetPath());
173 } 173 }
174 174
175 OpenOperationResult CallOpenItem(const base::FilePath& path, 175 OpenOperationResult CallOpenItem(const base::FilePath& path,
176 OpenItemType item_type) { 176 OpenItemType item_type) {
177 base::RunLoop run_loop; 177 base::RunLoop run_loop;
178 OpenOperationResult result = OPEN_SUCCEEDED; 178 OpenOperationResult result = OPEN_SUCCEEDED;
179 OpenOperationCallback callback = 179 OpenOperationCallback callback =
180 base::Bind(&OnOpenOperationDone, run_loop.QuitClosure(), &result); 180 base::Bind(&OnOpenOperationDone, run_loop.QuitClosure(), &result);
181 OpenItem(GetProfile(), path, item_type, callback); 181 OpenItem(GetProfile(), path, item_type, callback);
182 run_loop.Run(); 182 run_loop.Run();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 218 }
219 219
220 #if defined(OS_POSIX) 220 #if defined(OS_POSIX)
221 // Symbolic links are currently only supported on Posix. Windows technically 221 // Symbolic links are currently only supported on Posix. Windows technically
222 // supports it as well, but not on Windows XP. 222 // supports it as well, but not on Windows XP.
223 class PlatformUtilPosixTest : public PlatformUtilTest { 223 class PlatformUtilPosixTest : public PlatformUtilTest {
224 public: 224 public:
225 void SetUp() override { 225 void SetUp() override {
226 ASSERT_NO_FATAL_FAILURE(PlatformUtilTest::SetUp()); 226 ASSERT_NO_FATAL_FAILURE(PlatformUtilTest::SetUp());
227 227
228 symlink_to_file_ = directory_.path().AppendASCII("l_file.txt"); 228 symlink_to_file_ = directory_.GetPath().AppendASCII("l_file.txt");
229 ASSERT_TRUE(base::CreateSymbolicLink(existing_file_, symlink_to_file_)); 229 ASSERT_TRUE(base::CreateSymbolicLink(existing_file_, symlink_to_file_));
230 symlink_to_folder_ = directory_.path().AppendASCII("l_folder"); 230 symlink_to_folder_ = directory_.GetPath().AppendASCII("l_folder");
231 ASSERT_TRUE(base::CreateSymbolicLink(existing_folder_, symlink_to_folder_)); 231 ASSERT_TRUE(base::CreateSymbolicLink(existing_folder_, symlink_to_folder_));
232 symlink_to_nowhere_ = directory_.path().AppendASCII("l_nowhere"); 232 symlink_to_nowhere_ = directory_.GetPath().AppendASCII("l_nowhere");
233 ASSERT_TRUE(base::CreateSymbolicLink(nowhere_, symlink_to_nowhere_)); 233 ASSERT_TRUE(base::CreateSymbolicLink(nowhere_, symlink_to_nowhere_));
234 } 234 }
235 235
236 protected: 236 protected:
237 base::FilePath symlink_to_file_; 237 base::FilePath symlink_to_file_;
238 base::FilePath symlink_to_folder_; 238 base::FilePath symlink_to_folder_;
239 base::FilePath symlink_to_nowhere_; 239 base::FilePath symlink_to_nowhere_;
240 }; 240 };
241 #endif // OS_POSIX 241 #endif // OS_POSIX
242 242
(...skipping 14 matching lines...) Expand all
257 EXPECT_EQ(OPEN_FAILED_PATH_NOT_FOUND, 257 EXPECT_EQ(OPEN_FAILED_PATH_NOT_FOUND,
258 CallOpenItem(symlink_to_folder_, OPEN_FOLDER)); 258 CallOpenItem(symlink_to_folder_, OPEN_FOLDER));
259 EXPECT_EQ(OPEN_FAILED_PATH_NOT_FOUND, 259 EXPECT_EQ(OPEN_FAILED_PATH_NOT_FOUND,
260 CallOpenItem(symlink_to_file_, OPEN_FOLDER)); 260 CallOpenItem(symlink_to_file_, OPEN_FOLDER));
261 EXPECT_EQ(OPEN_FAILED_PATH_NOT_FOUND, 261 EXPECT_EQ(OPEN_FAILED_PATH_NOT_FOUND,
262 CallOpenItem(symlink_to_nowhere_, OPEN_FOLDER)); 262 CallOpenItem(symlink_to_nowhere_, OPEN_FOLDER));
263 } 263 }
264 264
265 TEST_F(PlatformUtilTest, OpenFileWithUnhandledFileType) { 265 TEST_F(PlatformUtilTest, OpenFileWithUnhandledFileType) {
266 base::FilePath unhandled_file = 266 base::FilePath unhandled_file =
267 directory_.path().AppendASCII("myfile.filetype"); 267 directory_.GetPath().AppendASCII("myfile.filetype");
268 ASSERT_EQ(3, base::WriteFile(unhandled_file, "cat", 3)); 268 ASSERT_EQ(3, base::WriteFile(unhandled_file, "cat", 3));
269 EXPECT_EQ(OPEN_FAILED_NO_HANLDER_FOR_FILE_TYPE, 269 EXPECT_EQ(OPEN_FAILED_NO_HANLDER_FOR_FILE_TYPE,
270 CallOpenItem(unhandled_file, OPEN_FILE)); 270 CallOpenItem(unhandled_file, OPEN_FILE));
271 } 271 }
272 #endif // OS_CHROMEOS 272 #endif // OS_CHROMEOS
273 273
274 #if defined(OS_POSIX) && !defined(OS_CHROMEOS) 274 #if defined(OS_POSIX) && !defined(OS_CHROMEOS)
275 // On all other Posix platforms, the symbolic link tests should work as 275 // On all other Posix platforms, the symbolic link tests should work as
276 // expected. 276 // expected.
277 277
278 TEST_F(PlatformUtilPosixTest, OpenFileWithPosixSymlinks) { 278 TEST_F(PlatformUtilPosixTest, OpenFileWithPosixSymlinks) {
279 EXPECT_EQ(OPEN_SUCCEEDED, CallOpenItem(symlink_to_file_, OPEN_FILE)); 279 EXPECT_EQ(OPEN_SUCCEEDED, CallOpenItem(symlink_to_file_, OPEN_FILE));
280 EXPECT_EQ(OPEN_FAILED_INVALID_TYPE, 280 EXPECT_EQ(OPEN_FAILED_INVALID_TYPE,
281 CallOpenItem(symlink_to_folder_, OPEN_FILE)); 281 CallOpenItem(symlink_to_folder_, OPEN_FILE));
282 EXPECT_EQ(OPEN_FAILED_PATH_NOT_FOUND, 282 EXPECT_EQ(OPEN_FAILED_PATH_NOT_FOUND,
283 CallOpenItem(symlink_to_nowhere_, OPEN_FILE)); 283 CallOpenItem(symlink_to_nowhere_, OPEN_FILE));
284 } 284 }
285 285
286 TEST_F(PlatformUtilPosixTest, OpenFolderWithPosixSymlinks) { 286 TEST_F(PlatformUtilPosixTest, OpenFolderWithPosixSymlinks) {
287 EXPECT_EQ(OPEN_SUCCEEDED, CallOpenItem(symlink_to_folder_, OPEN_FOLDER)); 287 EXPECT_EQ(OPEN_SUCCEEDED, CallOpenItem(symlink_to_folder_, OPEN_FOLDER));
288 EXPECT_EQ(OPEN_FAILED_INVALID_TYPE, 288 EXPECT_EQ(OPEN_FAILED_INVALID_TYPE,
289 CallOpenItem(symlink_to_file_, OPEN_FOLDER)); 289 CallOpenItem(symlink_to_file_, OPEN_FOLDER));
290 EXPECT_EQ(OPEN_FAILED_PATH_NOT_FOUND, 290 EXPECT_EQ(OPEN_FAILED_PATH_NOT_FOUND,
291 CallOpenItem(symlink_to_nowhere_, OPEN_FOLDER)); 291 CallOpenItem(symlink_to_nowhere_, OPEN_FOLDER));
292 } 292 }
293 #endif // OS_POSIX && !OS_CHROMEOS 293 #endif // OS_POSIX && !OS_CHROMEOS
294 294
295 } // namespace platform_util 295 } // namespace platform_util
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/policy/cloud/cloud_policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698