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

Side by Side Diff: base/files/scoped_temp_dir_unittest.cc

Issue 125643002: Convert most of base and net to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use error_details() Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <string> 5 #include <string>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file.h"
8 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
9 #include "base/platform_file.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace base { 12 namespace base {
13 13
14 TEST(ScopedTempDir, FullPath) { 14 TEST(ScopedTempDir, FullPath) {
15 FilePath test_path; 15 FilePath test_path;
16 base::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_temp_dir"), 16 base::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_temp_dir"),
17 &test_path); 17 &test_path);
18 18
19 // Against an existing dir, it should get destroyed when leaving scope. 19 // Against an existing dir, it should get destroyed when leaving scope.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 EXPECT_TRUE(other_dir.Set(dir.Take())); 91 EXPECT_TRUE(other_dir.Set(dir.Take()));
92 EXPECT_TRUE(dir.CreateUniqueTempDir()); 92 EXPECT_TRUE(dir.CreateUniqueTempDir());
93 EXPECT_FALSE(dir.CreateUniqueTempDir()); 93 EXPECT_FALSE(dir.CreateUniqueTempDir());
94 EXPECT_FALSE(other_dir.CreateUniqueTempDir()); 94 EXPECT_FALSE(other_dir.CreateUniqueTempDir());
95 } 95 }
96 96
97 #if defined(OS_WIN) 97 #if defined(OS_WIN)
98 TEST(ScopedTempDir, LockedTempDir) { 98 TEST(ScopedTempDir, LockedTempDir) {
99 ScopedTempDir dir; 99 ScopedTempDir dir;
100 EXPECT_TRUE(dir.CreateUniqueTempDir()); 100 EXPECT_TRUE(dir.CreateUniqueTempDir());
101 int file_flags = base::PLATFORM_FILE_CREATE_ALWAYS | 101 base::File file(dir.path().Append(FILE_PATH_LITERAL("temp")),
102 base::PLATFORM_FILE_WRITE; 102 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
103 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; 103 EXPECT_TRUE(file.IsValid());
104 FilePath file_path(dir.path().Append(FILE_PATH_LITERAL("temp"))); 104 EXPECT_EQ(base::File::FILE_OK, file.error_details());
105 base::PlatformFile file = base::CreatePlatformFile(file_path, file_flags,
106 NULL, &error_code);
107 EXPECT_NE(base::kInvalidPlatformFileValue, file);
108 EXPECT_EQ(base::PLATFORM_FILE_OK, error_code);
109 EXPECT_FALSE(dir.Delete()); // We should not be able to delete. 105 EXPECT_FALSE(dir.Delete()); // We should not be able to delete.
110 EXPECT_FALSE(dir.path().empty()); // We should still have a valid path. 106 EXPECT_FALSE(dir.path().empty()); // We should still have a valid path.
111 EXPECT_TRUE(base::ClosePlatformFile(file)); 107 file.Close();
112 // Now, we should be able to delete. 108 // Now, we should be able to delete.
113 EXPECT_TRUE(dir.Delete()); 109 EXPECT_TRUE(dir.Delete());
114 } 110 }
115 #endif // defined(OS_WIN) 111 #endif // defined(OS_WIN)
116 112
117 } // namespace base 113 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | net/android/cert_verify_result_android.h » ('j') | net/disk_cache/simple/simple_synchronous_entry.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698