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

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

Issue 2851483002: Network traffic annotation added to url_request_data_job_fuzzer. (Closed)
Patch Set: Annotation changed to test flag. Created 3 years, 7 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/message_loop/message_loop.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/test/fuzzed_data_provider.h" 12 #include "base/test/fuzzed_data_provider.h"
13 #include "base/test/scoped_task_scheduler.h" 13 #include "base/test/scoped_task_scheduler.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "net/http/http_request_headers.h" 15 #include "net/http/http_request_headers.h"
16 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
16 #include "net/url_request/data_protocol_handler.h" 17 #include "net/url_request/data_protocol_handler.h"
17 #include "net/url_request/url_request.h" 18 #include "net/url_request/url_request.h"
18 #include "net/url_request/url_request_job_factory_impl.h" 19 #include "net/url_request/url_request_job_factory_impl.h"
19 #include "net/url_request/url_request_test_util.h" 20 #include "net/url_request/url_request_test_util.h"
20 21
21 namespace { 22 namespace {
22 23
23 const size_t kMaxLengthForFuzzedRange = 32; 24 const size_t kMaxLengthForFuzzedRange = 32;
24 25
25 } // namespace 26 } // namespace
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // ensure that if it's a URL, it's a data URL. If the URL is invalid just 74 // ensure that if it's a URL, it's a data URL. If the URL is invalid just
74 // use a test variant, so the fuzzer has a chance to execute something. 75 // use a test variant, so the fuzzer has a chance to execute something.
75 std::string data_url_string = 76 std::string data_url_string =
76 std::string("data:") + provider.ConsumeRemainingBytes(); 77 std::string("data:") + provider.ConsumeRemainingBytes();
77 GURL data_url(data_url_string); 78 GURL data_url(data_url_string);
78 if (!data_url.is_valid()) 79 if (!data_url.is_valid())
79 data_url = GURL("data:text/html;charset=utf-8,<p>test</p>"); 80 data_url = GURL("data:text/html;charset=utf-8,<p>test</p>");
80 81
81 // Create a URLRequest with the given data URL and start reading 82 // Create a URLRequest with the given data URL and start reading
82 // from it. 83 // from it.
83 std::unique_ptr<net::URLRequest> request = 84 std::unique_ptr<net::URLRequest> request = context_.CreateRequest(
84 context_.CreateRequest(data_url, net::DEFAULT_PRIORITY, this); 85 data_url, net::DEFAULT_PRIORITY, this, TRAFFIC_ANNOTATION_FOR_TESTS);
85 if (use_range) { 86 if (use_range) {
86 if (!net::HttpUtil::IsValidHeaderValue(range)) 87 if (!net::HttpUtil::IsValidHeaderValue(range))
87 range = "bytes=3-"; 88 range = "bytes=3-";
88 request->SetExtraRequestHeaderByName("Range", range, true); 89 request->SetExtraRequestHeaderByName("Range", range, true);
89 } 90 }
90 91
91 // Block the thread while the request is read. 92 // Block the thread while the request is read.
92 base::RunLoop read_loop; 93 base::RunLoop read_loop;
93 read_loop_ = &read_loop; 94 read_loop_ = &read_loop;
94 request->Start(); 95 request->Start();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 base::RunLoop* read_loop_; 170 base::RunLoop* read_loop_;
170 171
171 DISALLOW_COPY_AND_ASSIGN(URLRequestDataJobFuzzerHarness); 172 DISALLOW_COPY_AND_ASSIGN(URLRequestDataJobFuzzerHarness);
172 }; 173 };
173 174
174 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 175 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
175 // Using a static singleton test harness lets the test run ~3-4x faster. 176 // Using a static singleton test harness lets the test run ~3-4x faster.
176 return URLRequestDataJobFuzzerHarness::GetInstance() 177 return URLRequestDataJobFuzzerHarness::GetInstance()
177 ->CreateAndReadFromDataURLRequest(data, size); 178 ->CreateAndReadFromDataURLRequest(data, size);
178 } 179 }
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