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

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

Issue 2697843002: Add ScopedTaskScheduler in URLRequestDataJobFuzzerHarness. (Closed)
Patch Set: CR xunjieli #8 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 | « no previous file | no next file » | 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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 11 #include "base/run_loop.h"
11 #include "base/test/fuzzed_data_provider.h" 12 #include "base/test/fuzzed_data_provider.h"
13 #include "base/test/scoped_task_scheduler.h"
12 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
13 #include "net/http/http_request_headers.h" 15 #include "net/http/http_request_headers.h"
14 #include "net/url_request/data_protocol_handler.h" 16 #include "net/url_request/data_protocol_handler.h"
15 #include "net/url_request/url_request.h" 17 #include "net/url_request/url_request.h"
16 #include "net/url_request/url_request_job_factory_impl.h" 18 #include "net/url_request/url_request_job_factory_impl.h"
17 #include "net/url_request/url_request_test_util.h" 19 #include "net/url_request/url_request_test_util.h"
18 20
19 namespace { 21 namespace {
20 22
21 const size_t kMaxLengthForFuzzedRange = 32; 23 const size_t kMaxLengthForFuzzedRange = 32;
22 24
23 } // namespace 25 } // namespace
24 26
25 // This class tests creating and reading to completion a URLRequest with fuzzed 27 // This class tests creating and reading to completion a URLRequest with fuzzed
26 // input. The fuzzer provides a data: URL and optionally generates custom Range 28 // input. The fuzzer provides a data: URL and optionally generates custom Range
27 // headers. The amount of data read in each Read call is also fuzzed, as is 29 // headers. The amount of data read in each Read call is also fuzzed, as is
28 // the size of the IOBuffer to read data into. 30 // the size of the IOBuffer to read data into.
29 class URLRequestDataJobFuzzerHarness : public net::URLRequest::Delegate { 31 class URLRequestDataJobFuzzerHarness : public net::URLRequest::Delegate {
30 public: 32 public:
31 URLRequestDataJobFuzzerHarness() 33 URLRequestDataJobFuzzerHarness()
32 : context_(true), task_runner_(base::ThreadTaskRunnerHandle::Get()) { 34 : scoped_task_scheduler_(base::MessageLoop::current()),
35 task_runner_(base::ThreadTaskRunnerHandle::Get()),
36 context_(true) {
33 job_factory_.SetProtocolHandler( 37 job_factory_.SetProtocolHandler(
34 "data", base::MakeUnique<net::DataProtocolHandler>()); 38 "data", base::MakeUnique<net::DataProtocolHandler>());
35 context_.set_job_factory(&job_factory_); 39 context_.set_job_factory(&job_factory_);
36 context_.Init(); 40 context_.Init();
37 } 41 }
38 42
39 static URLRequestDataJobFuzzerHarness* GetInstance() { 43 static URLRequestDataJobFuzzerHarness* GetInstance() {
40 return base::Singleton<URLRequestDataJobFuzzerHarness>::get(); 44 return base::Singleton<URLRequestDataJobFuzzerHarness>::get();
41 } 45 }
42 46
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 if (bytes_read > 0) { 152 if (bytes_read > 0) {
149 ReadFromRequest(request); 153 ReadFromRequest(request);
150 } else { 154 } else {
151 QuitLoop(); 155 QuitLoop();
152 } 156 }
153 } 157 }
154 158
155 private: 159 private:
156 friend struct base::DefaultSingletonTraits<URLRequestDataJobFuzzerHarness>; 160 friend struct base::DefaultSingletonTraits<URLRequestDataJobFuzzerHarness>;
157 161
162 base::test::ScopedTaskScheduler scoped_task_scheduler_;
163 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
164
158 net::TestURLRequestContext context_; 165 net::TestURLRequestContext context_;
159 net::URLRequestJobFactoryImpl job_factory_; 166 net::URLRequestJobFactoryImpl job_factory_;
160 std::vector<size_t> read_lengths_; 167 std::vector<size_t> read_lengths_;
161 scoped_refptr<net::IOBuffer> buf_; 168 scoped_refptr<net::IOBuffer> buf_;
162 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
163 base::RunLoop* read_loop_; 169 base::RunLoop* read_loop_;
164 170
165 DISALLOW_COPY_AND_ASSIGN(URLRequestDataJobFuzzerHarness); 171 DISALLOW_COPY_AND_ASSIGN(URLRequestDataJobFuzzerHarness);
166 }; 172 };
167 173
168 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 174 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
169 // Using a static singleton test harness lets the test run ~3-4x faster. 175 // Using a static singleton test harness lets the test run ~3-4x faster.
170 return URLRequestDataJobFuzzerHarness::GetInstance() 176 return URLRequestDataJobFuzzerHarness::GetInstance()
171 ->CreateAndReadFromDataURLRequest(data, size); 177 ->CreateAndReadFromDataURLRequest(data, size);
172 } 178 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698