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

Side by Side Diff: net/url_request/url_request_file_dir_job_unittest.cc

Issue 2265873002: Adjust callers and networking delegates in net/ to modified APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@URLRequestRead
Patch Set: Matt's comments 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "net/url_request/url_request_file_dir_job.h" 5 #include "net/url_request/url_request_file_dir_job.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 request->Start(); 119 request->Start();
120 ASSERT_TRUE(directory.Delete()); 120 ASSERT_TRUE(directory.Delete());
121 121
122 // Since the DirectoryLister is running on the network thread, this 122 // Since the DirectoryLister is running on the network thread, this
123 // will spin the message loop until the read error is returned to the 123 // will spin the message loop until the read error is returned to the
124 // URLRequestFileDirJob. 124 // URLRequestFileDirJob.
125 base::RunLoop().RunUntilIdle(); 125 base::RunLoop().RunUntilIdle();
126 ASSERT_TRUE(delegate_.got_response_started()); 126 ASSERT_TRUE(delegate_.got_response_started());
127 127
128 int bytes_read = 0; 128 int bytes_read = request->Read(buffer_.get(), kBufferSize);
129 EXPECT_FALSE(request->Read(buffer_.get(), kBufferSize, &bytes_read));
130 129
131 // The URLRequestFileDirJobShould return the cached read error synchronously. 130 // The URLRequestFileDirJobShould return the cached read error synchronously.
132 // If it's not returned synchronously, the code path this is intended to test 131 // If it's not returned synchronously, the code path this is intended to test
133 // was not executed. 132 // was not executed.
134 EXPECT_THAT(request->status().ToNetError(), IsError(ERR_FILE_NOT_FOUND)); 133 EXPECT_THAT(bytes_read, ERR_FILE_NOT_FOUND);
mmenke 2016/09/01 16:57:25 This should be "EXPECT_THAT(bytes_read, IsError(ER
maksims (do not use this acc) 2016/09/02 12:31:53 Done.
135 } 134 }
136 135
137 // Test the case where reading the response completes synchronously. 136 // Test the case where reading the response completes synchronously.
138 TEST_F(URLRequestFileDirTest, DirectoryWithASingleFileSync) { 137 TEST_F(URLRequestFileDirTest, DirectoryWithASingleFileSync) {
139 base::ScopedTempDir directory; 138 base::ScopedTempDir directory;
140 ASSERT_TRUE(directory.CreateUniqueTempDir()); 139 ASSERT_TRUE(directory.CreateUniqueTempDir());
141 base::FilePath path; 140 base::FilePath path;
142 base::CreateTemporaryFileInDir(directory.path(), &path); 141 base::CreateTemporaryFileInDir(directory.path(), &path);
143 142
144 TestJobFactory factory(directory.path()); 143 TestJobFactory factory(directory.path());
145 context_.set_job_factory(&factory); 144 context_.set_job_factory(&factory);
146 145
147 std::unique_ptr<URLRequest> request(context_.CreateRequest( 146 std::unique_ptr<URLRequest> request(context_.CreateRequest(
148 FilePathToFileURL(path), DEFAULT_PRIORITY, &delegate_)); 147 FilePathToFileURL(path), DEFAULT_PRIORITY, &delegate_));
149 request->Start(); 148 request->Start();
150 EXPECT_TRUE(request->is_pending()); 149 EXPECT_TRUE(request->is_pending());
151 150
152 // Since the DirectoryLister is running on the network thread, this will spin 151 // Since the DirectoryLister is running on the network thread, this will spin
153 // the message loop until the URLRequetsFileDirJob has received the 152 // the message loop until the URLRequetsFileDirJob has received the
154 // entire directory listing and cached it. 153 // entire directory listing and cached it.
155 base::RunLoop().RunUntilIdle(); 154 base::RunLoop().RunUntilIdle();
156 155
157 int bytes_read = 0;
158 // This will complete synchronously, since the URLRequetsFileDirJob had 156 // This will complete synchronously, since the URLRequetsFileDirJob had
159 // directory listing cached in memory. 157 // directory listing cached in memory.
160 EXPECT_TRUE(request->Read(buffer_.get(), kBufferSize, &bytes_read)); 158 int bytes_read = request->Read(buffer_.get(), kBufferSize);
161
162 EXPECT_EQ(URLRequestStatus::SUCCESS, request->status().status());
163 159
164 ASSERT_GT(bytes_read, 0); 160 ASSERT_GT(bytes_read, 0);
165 ASSERT_LE(bytes_read, kBufferSize); 161 ASSERT_LE(bytes_read, kBufferSize);
166 std::string data(buffer_->data(), bytes_read); 162 std::string data(buffer_->data(), bytes_read);
167 EXPECT_TRUE(data.find(directory.path().BaseName().MaybeAsASCII()) != 163 EXPECT_TRUE(data.find(directory.path().BaseName().MaybeAsASCII()) !=
168 std::string::npos); 164 std::string::npos);
169 EXPECT_TRUE(data.find(path.BaseName().MaybeAsASCII()) != std::string::npos); 165 EXPECT_TRUE(data.find(path.BaseName().MaybeAsASCII()) != std::string::npos);
170 } 166 }
171 167
172 // Test the case where reading the response completes asynchronously. 168 // Test the case where reading the response completes asynchronously.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 ASSERT_GT(delegate.bytes_received(), 0); 244 ASSERT_GT(delegate.bytes_received(), 0);
249 ASSERT_LE(delegate.bytes_received(), kBufferSize); 245 ASSERT_LE(delegate.bytes_received(), kBufferSize);
250 EXPECT_TRUE(delegate.data_received().find( 246 EXPECT_TRUE(delegate.data_received().find(
251 directory.path().BaseName().MaybeAsASCII()) != 247 directory.path().BaseName().MaybeAsASCII()) !=
252 std::string::npos); 248 std::string::npos);
253 } 249 }
254 250
255 } // namespace 251 } // namespace
256 252
257 } // namespace net 253 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698