| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/files/file_proxy.h" | 5 #include "base/files/file_proxy.h" | 
| 6 | 6 | 
| 7 #include <map> | 7 #include <map> | 
| 8 | 8 | 
| 9 #include "base/bind.h" | 9 #include "base/bind.h" | 
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" | 
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 200 | 200 | 
| 201   // Make sure the written data can be read from the returned path. | 201   // Make sure the written data can be read from the returned path. | 
| 202   std::string data; | 202   std::string data; | 
| 203   EXPECT_TRUE(ReadFileToString(path_, &data)); | 203   EXPECT_TRUE(ReadFileToString(path_, &data)); | 
| 204   EXPECT_EQ("test", data); | 204   EXPECT_EQ("test", data); | 
| 205 | 205 | 
| 206   // Make sure we can & do delete the created file to prevent leaks on the bots. | 206   // Make sure we can & do delete the created file to prevent leaks on the bots. | 
| 207   EXPECT_TRUE(base::DeleteFile(path_, false)); | 207   EXPECT_TRUE(base::DeleteFile(path_, false)); | 
| 208 } | 208 } | 
| 209 | 209 | 
|  | 210 TEST_F(FileProxyTest, SetAndTake) { | 
|  | 211   File file(test_path(), File::FLAG_CREATE | File::FLAG_READ); | 
|  | 212   ASSERT_TRUE(file.IsValid()); | 
|  | 213   FileProxy proxy(file_task_runner()); | 
|  | 214   EXPECT_FALSE(proxy.IsValid()); | 
|  | 215   proxy.SetFile(file.Pass()); | 
|  | 216   EXPECT_TRUE(proxy.IsValid()); | 
|  | 217   EXPECT_FALSE(file.IsValid()); | 
|  | 218 | 
|  | 219   file = proxy.TakeFile(); | 
|  | 220   EXPECT_FALSE(proxy.IsValid()); | 
|  | 221   EXPECT_TRUE(file.IsValid()); | 
|  | 222 } | 
|  | 223 | 
| 210 TEST_F(FileProxyTest, GetInfo) { | 224 TEST_F(FileProxyTest, GetInfo) { | 
| 211   // Setup. | 225   // Setup. | 
| 212   ASSERT_EQ(4, base::WriteFile(test_path(), "test", 4)); | 226   ASSERT_EQ(4, base::WriteFile(test_path(), "test", 4)); | 
| 213   File::Info expected_info; | 227   File::Info expected_info; | 
| 214   GetFileInfo(test_path(), &expected_info); | 228   GetFileInfo(test_path(), &expected_info); | 
| 215 | 229 | 
| 216   // Run. | 230   // Run. | 
| 217   FileProxy proxy(file_task_runner()); | 231   FileProxy proxy(file_task_runner()); | 
| 218   CreateProxy(File::FLAG_OPEN | File::FLAG_READ, &proxy); | 232   CreateProxy(File::FLAG_OPEN | File::FLAG_READ, &proxy); | 
| 219   proxy.GetInfo( | 233   proxy.GetInfo( | 
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 350   char buffer[53]; | 364   char buffer[53]; | 
| 351   EXPECT_EQ(53, base::ReadFile(test_path(), buffer, 53)); | 365   EXPECT_EQ(53, base::ReadFile(test_path(), buffer, 53)); | 
| 352   int i = 0; | 366   int i = 0; | 
| 353   for (; i < 10; ++i) | 367   for (; i < 10; ++i) | 
| 354     EXPECT_EQ(kTestData[i], buffer[i]); | 368     EXPECT_EQ(kTestData[i], buffer[i]); | 
| 355   for (; i < 53; ++i) | 369   for (; i < 53; ++i) | 
| 356     EXPECT_EQ(0, buffer[i]); | 370     EXPECT_EQ(0, buffer[i]); | 
| 357 } | 371 } | 
| 358 | 372 | 
| 359 }  // namespace base | 373 }  // namespace base | 
| OLD | NEW | 
|---|