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

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

Issue 2682523002: Use TaskScheduler in directory_lister.cc. (Closed)
Patch Set: remove ScopedTaskScheduler from TokenBindingURLRequestTest Created 3 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
« no previous file with comments | « net/url_request/url_request_file_dir_job.cc ('k') | net/url_request/url_request_unittest.cc » ('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 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/message_loop/message_loop.h"
15 #include "base/run_loop.h" 16 #include "base/run_loop.h"
16 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/test/scoped_task_scheduler.h"
17 #include "net/base/filename_util.h" 18 #include "net/base/filename_util.h"
18 #include "net/base/io_buffer.h" 19 #include "net/base/io_buffer.h"
19 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
20 #include "net/test/gtest_util.h" 21 #include "net/test/gtest_util.h"
21 #include "net/url_request/url_request.h" 22 #include "net/url_request/url_request.h"
22 #include "net/url_request/url_request_test_util.h" 23 #include "net/url_request/url_request_test_util.h"
23 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 26
26 using net::test::IsError; 27 using net::test::IsError;
27 using net::test::IsOk; 28 using net::test::IsOk;
28 29
29 namespace net { 30 namespace net {
30 31
31 namespace { 32 namespace {
32 33
33 const int kBufferSize = 4096; 34 const int kBufferSize = 4096;
34 35
35 class TestJobFactory : public URLRequestJobFactory { 36 class TestJobFactory : public URLRequestJobFactory {
36 public: 37 public:
37 explicit TestJobFactory(const base::FilePath& path) : path_(path) {} 38 explicit TestJobFactory(const base::FilePath& path) : path_(path) {}
38 ~TestJobFactory() override {} 39 ~TestJobFactory() override {}
39 40
40 URLRequestJob* MaybeCreateJobWithProtocolHandler( 41 URLRequestJob* MaybeCreateJobWithProtocolHandler(
41 const std::string& scheme, 42 const std::string& scheme,
42 URLRequest* request, 43 URLRequest* request,
43 NetworkDelegate* network_delegate) const override { 44 NetworkDelegate* network_delegate) const override {
44 URLRequestJob* job = new URLRequestFileDirJob( 45 URLRequestJob* job =
45 request, network_delegate, path_, base::ThreadTaskRunnerHandle::Get()); 46 new URLRequestFileDirJob(request, network_delegate, path_);
46 47
47 return job; 48 return job;
48 } 49 }
49 50
50 URLRequestJob* MaybeInterceptRedirect(URLRequest* request, 51 URLRequestJob* MaybeInterceptRedirect(URLRequest* request,
51 NetworkDelegate* network_delegate, 52 NetworkDelegate* network_delegate,
52 const GURL& location) const override { 53 const GURL& location) const override {
53 return nullptr; 54 return nullptr;
54 } 55 }
55 56
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 bool got_response_started() const { return got_response_started_; } 91 bool got_response_started() const { return got_response_started_; }
91 92
92 private: 93 private:
93 bool got_response_started_ = false; 94 bool got_response_started_ = false;
94 95
95 DISALLOW_COPY_AND_ASSIGN(TestDirectoryURLRequestDelegate); 96 DISALLOW_COPY_AND_ASSIGN(TestDirectoryURLRequestDelegate);
96 }; 97 };
97 98
98 class URLRequestFileDirTest : public testing::Test { 99 class URLRequestFileDirTest : public testing::Test {
99 public: 100 public:
100 URLRequestFileDirTest() : buffer_(new IOBuffer(kBufferSize)) {} 101 URLRequestFileDirTest()
102 : scoped_task_scheduler_(base::MessageLoop::current()),
103 buffer_(new IOBuffer(kBufferSize)) {}
101 104
102 protected: 105 protected:
106 base::test::ScopedTaskScheduler scoped_task_scheduler_;
103 TestURLRequestContext context_; 107 TestURLRequestContext context_;
104 TestDirectoryURLRequestDelegate delegate_; 108 TestDirectoryURLRequestDelegate delegate_;
105 scoped_refptr<IOBuffer> buffer_; 109 scoped_refptr<IOBuffer> buffer_;
106 }; 110 };
107 111
108 TEST_F(URLRequestFileDirTest, ListCompletionOnNoPending) { 112 TEST_F(URLRequestFileDirTest, ListCompletionOnNoPending) {
109 base::ScopedTempDir directory; 113 base::ScopedTempDir directory;
110 // It is necessary to pass an existing directory to UrlRequest object, 114 // It is necessary to pass an existing directory to UrlRequest object,
111 // but it will be deleted for testing purpose after request is started. 115 // but it will be deleted for testing purpose after request is started.
112 ASSERT_TRUE(directory.CreateUniqueTempDir()); 116 ASSERT_TRUE(directory.CreateUniqueTempDir());
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 ASSERT_GT(delegate.bytes_received(), 0); 249 ASSERT_GT(delegate.bytes_received(), 0);
246 ASSERT_LE(delegate.bytes_received(), kBufferSize); 250 ASSERT_LE(delegate.bytes_received(), kBufferSize);
247 EXPECT_TRUE(delegate.data_received().find( 251 EXPECT_TRUE(delegate.data_received().find(
248 directory.GetPath().BaseName().MaybeAsASCII()) != 252 directory.GetPath().BaseName().MaybeAsASCII()) !=
249 std::string::npos); 253 std::string::npos);
250 } 254 }
251 255
252 } // namespace 256 } // namespace
253 257
254 } // namespace net 258 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_file_dir_job.cc ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698