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

Side by Side Diff: webkit/blob/local_file_stream_reader_unittest.cc

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
« no previous file with comments | « webkit/blob/local_file_stream_reader.cc ('k') | webkit/blob/shareable_file_reference.h » ('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 "webkit/blob/local_file_stream_reader.h" 5 #include "webkit/blob/local_file_stream_reader.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 74 }
75 75
76 virtual void TearDown() OVERRIDE { 76 virtual void TearDown() OVERRIDE {
77 // Give another chance for deleted streams to perform Close. 77 // Give another chance for deleted streams to perform Close.
78 MessageLoop::current()->RunUntilIdle(); 78 MessageLoop::current()->RunUntilIdle();
79 file_thread_.Stop(); 79 file_thread_.Stop();
80 } 80 }
81 81
82 protected: 82 protected:
83 LocalFileStreamReader* CreateFileReader( 83 LocalFileStreamReader* CreateFileReader(
84 const FilePath& path, 84 const base::FilePath& path,
85 int64 initial_offset, 85 int64 initial_offset,
86 const base::Time& expected_modification_time) { 86 const base::Time& expected_modification_time) {
87 return new LocalFileStreamReader( 87 return new LocalFileStreamReader(
88 file_task_runner(), 88 file_task_runner(),
89 path, 89 path,
90 initial_offset, 90 initial_offset,
91 expected_modification_time); 91 expected_modification_time);
92 } 92 }
93 93
94 void TouchTestFile() { 94 void TouchTestFile() {
95 base::Time new_modified_time = 95 base::Time new_modified_time =
96 test_file_modification_time() - base::TimeDelta::FromSeconds(1); 96 test_file_modification_time() - base::TimeDelta::FromSeconds(1);
97 ASSERT_TRUE(file_util::TouchFile(test_path(), 97 ASSERT_TRUE(file_util::TouchFile(test_path(),
98 test_file_modification_time(), 98 test_file_modification_time(),
99 new_modified_time)); 99 new_modified_time));
100 } 100 }
101 101
102 base::MessageLoopProxy* file_task_runner() const { 102 base::MessageLoopProxy* file_task_runner() const {
103 return file_thread_.message_loop_proxy().get(); 103 return file_thread_.message_loop_proxy().get();
104 } 104 }
105 105
106 FilePath test_dir() const { return dir_.path(); } 106 base::FilePath test_dir() const { return dir_.path(); }
107 FilePath test_path() const { return dir_.path().AppendASCII("test"); } 107 base::FilePath test_path() const { return dir_.path().AppendASCII("test"); }
108 base::Time test_file_modification_time() const { 108 base::Time test_file_modification_time() const {
109 return test_file_modification_time_; 109 return test_file_modification_time_;
110 } 110 }
111 111
112 void EnsureFileTaskFinished() { 112 void EnsureFileTaskFinished() {
113 file_task_runner()->PostTaskAndReply( 113 file_task_runner()->PostTaskAndReply(
114 FROM_HERE, base::Bind(&EmptyCallback), base::Bind(&QuitLoop)); 114 FROM_HERE, base::Bind(&EmptyCallback), base::Bind(&QuitLoop));
115 MessageLoop::current()->Run(); 115 MessageLoop::current()->Run();
116 } 116 }
117 117
118 private: 118 private:
119 MessageLoop message_loop_; 119 MessageLoop message_loop_;
120 base::Thread file_thread_; 120 base::Thread file_thread_;
121 base::ScopedTempDir dir_; 121 base::ScopedTempDir dir_;
122 base::Time test_file_modification_time_; 122 base::Time test_file_modification_time_;
123 }; 123 };
124 124
125 TEST_F(LocalFileStreamReaderTest, NonExistent) { 125 TEST_F(LocalFileStreamReaderTest, NonExistent) {
126 FilePath nonexistent_path = test_dir().AppendASCII("nonexistent"); 126 base::FilePath nonexistent_path = test_dir().AppendASCII("nonexistent");
127 scoped_ptr<LocalFileStreamReader> reader( 127 scoped_ptr<LocalFileStreamReader> reader(
128 CreateFileReader(nonexistent_path, 0, base::Time())); 128 CreateFileReader(nonexistent_path, 0, base::Time()));
129 int result = 0; 129 int result = 0;
130 std::string data; 130 std::string data;
131 ReadFromReader(reader.get(), &data, 10, &result); 131 ReadFromReader(reader.get(), &data, 10, &result);
132 ASSERT_EQ(net::ERR_FILE_NOT_FOUND, result); 132 ASSERT_EQ(net::ERR_FILE_NOT_FOUND, result);
133 ASSERT_EQ(0U, data.size()); 133 ASSERT_EQ(0U, data.size());
134 } 134 }
135 135
136 TEST_F(LocalFileStreamReaderTest, Empty) { 136 TEST_F(LocalFileStreamReaderTest, Empty) {
137 FilePath empty_path = test_dir().AppendASCII("empty"); 137 base::FilePath empty_path = test_dir().AppendASCII("empty");
138 base::PlatformFileError error = base::PLATFORM_FILE_OK; 138 base::PlatformFileError error = base::PLATFORM_FILE_OK;
139 base::PlatformFile file = base::CreatePlatformFile( 139 base::PlatformFile file = base::CreatePlatformFile(
140 empty_path, 140 empty_path,
141 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_READ, 141 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_READ,
142 NULL, &error); 142 NULL, &error);
143 ASSERT_EQ(base::PLATFORM_FILE_OK, error); 143 ASSERT_EQ(base::PLATFORM_FILE_OK, error);
144 ASSERT_NE(base::kInvalidPlatformFileValue, file); 144 ASSERT_NE(base::kInvalidPlatformFileValue, file);
145 base::ClosePlatformFile(file); 145 base::ClosePlatformFile(file);
146 146
147 scoped_ptr<LocalFileStreamReader> reader( 147 scoped_ptr<LocalFileStreamReader> reader(
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 int rv = reader->Read(buf, buf->size(), base::Bind(&NeverCalled)); 252 int rv = reader->Read(buf, buf->size(), base::Bind(&NeverCalled));
253 ASSERT_TRUE(rv == net::ERR_IO_PENDING || rv >= 0); 253 ASSERT_TRUE(rv == net::ERR_IO_PENDING || rv >= 0);
254 254
255 // Delete immediately. 255 // Delete immediately.
256 // Should not crash; nor should NeverCalled be callback. 256 // Should not crash; nor should NeverCalled be callback.
257 reader.reset(); 257 reader.reset();
258 EnsureFileTaskFinished(); 258 EnsureFileTaskFinished();
259 } 259 }
260 260
261 } // namespace webkit_blob 261 } // namespace webkit_blob
OLDNEW
« no previous file with comments | « webkit/blob/local_file_stream_reader.cc ('k') | webkit/blob/shareable_file_reference.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698