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

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

Issue 2109503009: Refactor net tests to use GMock matchers for checking net::Error results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to contents.txt files Created 4 years, 5 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"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "net/base/filename_util.h" 16 #include "net/base/filename_util.h"
17 #include "net/base/io_buffer.h" 17 #include "net/base/io_buffer.h"
18 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
19 #include "net/test/gtest_util.h"
19 #include "net/url_request/url_request.h" 20 #include "net/url_request/url_request.h"
20 #include "net/url_request/url_request_test_util.h" 21 #include "net/url_request/url_request_test_util.h"
22 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
22 24
25 using net::test::IsError;
26 using net::test::IsOk;
27
23 namespace net { 28 namespace net {
24 29
25 namespace { 30 namespace {
26 31
27 const int kBufferSize = 4096; 32 const int kBufferSize = 4096;
28 33
29 class TestJobFactory : public URLRequestJobFactory { 34 class TestJobFactory : public URLRequestJobFactory {
30 public: 35 public:
31 explicit TestJobFactory(const base::FilePath& path) : path_(path) {} 36 explicit TestJobFactory(const base::FilePath& path) : path_(path) {}
32 ~TestJobFactory() override {} 37 ~TestJobFactory() override {}
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // URLRequestFileDirJob. 124 // URLRequestFileDirJob.
120 base::RunLoop().RunUntilIdle(); 125 base::RunLoop().RunUntilIdle();
121 ASSERT_TRUE(delegate_.got_response_started()); 126 ASSERT_TRUE(delegate_.got_response_started());
122 127
123 int bytes_read = 0; 128 int bytes_read = 0;
124 EXPECT_FALSE(request->Read(buffer_.get(), kBufferSize, &bytes_read)); 129 EXPECT_FALSE(request->Read(buffer_.get(), kBufferSize, &bytes_read));
125 130
126 // The URLRequestFileDirJobShould return the cached read error synchronously. 131 // The URLRequestFileDirJobShould return the cached read error synchronously.
127 // If it's not returned synchronously, the code path this is intended to test 132 // If it's not returned synchronously, the code path this is intended to test
128 // was not executed. 133 // was not executed.
129 EXPECT_EQ(ERR_FILE_NOT_FOUND, request->status().ToNetError()); 134 EXPECT_THAT(request->status().ToNetError(), IsError(ERR_FILE_NOT_FOUND));
130 } 135 }
131 136
132 // Test the case where reading the response completes synchronously. 137 // Test the case where reading the response completes synchronously.
133 TEST_F(URLRequestFileDirTest, DirectoryWithASingleFileSync) { 138 TEST_F(URLRequestFileDirTest, DirectoryWithASingleFileSync) {
134 base::ScopedTempDir directory; 139 base::ScopedTempDir directory;
135 ASSERT_TRUE(directory.CreateUniqueTempDir()); 140 ASSERT_TRUE(directory.CreateUniqueTempDir());
136 base::FilePath path; 141 base::FilePath path;
137 base::CreateTemporaryFileInDir(directory.path(), &path); 142 base::CreateTemporaryFileInDir(directory.path(), &path);
138 143
139 TestJobFactory factory(directory.path()); 144 TestJobFactory factory(directory.path());
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 ASSERT_GT(delegate.bytes_received(), 0); 248 ASSERT_GT(delegate.bytes_received(), 0);
244 ASSERT_LE(delegate.bytes_received(), kBufferSize); 249 ASSERT_LE(delegate.bytes_received(), kBufferSize);
245 EXPECT_TRUE(delegate.data_received().find( 250 EXPECT_TRUE(delegate.data_received().find(
246 directory.path().BaseName().MaybeAsASCII()) != 251 directory.path().BaseName().MaybeAsASCII()) !=
247 std::string::npos); 252 std::string::npos);
248 } 253 }
249 254
250 } // namespace 255 } // namespace
251 256
252 } // namespace net 257 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_fetcher_response_writer_unittest.cc ('k') | net/url_request/url_request_ftp_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698