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

Side by Side Diff: content/browser/android/url_request_content_job_unittest.cc

Issue 2506303002: Revert of Add a NetworkQualityEstimator to TestURLRequestContext. (Closed)
Patch Set: Created 4 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/android/url_request_content_job.h" 5 #include "content/browser/android/url_request_content_job.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 13 #include "base/run_loop.h"
15 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
16 #include "base/test/test_file_util.h" 15 #include "base/test/test_file_util.h"
17 #include "base/threading/thread_task_runner_handle.h"
18 #include "net/url_request/url_request.h" 16 #include "net/url_request/url_request.h"
19 #include "net/url_request/url_request_test_util.h" 17 #include "net/url_request/url_request_test_util.h"
20 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
21 19
22 20
23 namespace content { 21 namespace content {
24 22
25 namespace { 23 namespace {
26 24
27 // A URLRequestJobFactory that will return URLRequestContentJobWithCallbacks 25 // A URLRequestJobFactory that will return URLRequestContentJobWithCallbacks
28 // instances for content:// scheme URLs. 26 // instances for content:// scheme URLs.
29 class CallbacksJobFactory : public net::URLRequestJobFactory { 27 class CallbacksJobFactory : public net::URLRequestJobFactory {
30 public: 28 public:
31 class JobObserver { 29 class JobObserver {
32 public: 30 public:
33 virtual ~JobObserver() {} 31 virtual ~JobObserver() {}
34 virtual void OnJobCreated() = 0; 32 virtual void OnJobCreated() = 0;
35 }; 33 };
36 34
37 CallbacksJobFactory(const base::FilePath& path, JobObserver* observer) 35 CallbacksJobFactory(const base::FilePath& path, JobObserver* observer)
38 : path_(path), observer_(observer) { 36 : path_(path), observer_(observer) {
39 } 37 }
40 38
41 ~CallbacksJobFactory() override {} 39 ~CallbacksJobFactory() override {}
42 40
43 net::URLRequestJob* MaybeCreateJobWithProtocolHandler( 41 net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
44 const std::string& scheme, 42 const std::string& scheme,
45 net::URLRequest* request, 43 net::URLRequest* request,
46 net::NetworkDelegate* network_delegate) const override { 44 net::NetworkDelegate* network_delegate) const override {
47 URLRequestContentJob* job = new URLRequestContentJob( 45 URLRequestContentJob* job =
48 request, network_delegate, path_, base::ThreadTaskRunnerHandle::Get()); 46 new URLRequestContentJob(
47 request,
48 network_delegate,
49 path_,
50 const_cast<base::MessageLoop*>(&message_loop_)->task_runner());
49 observer_->OnJobCreated(); 51 observer_->OnJobCreated();
50 return job; 52 return job;
51 } 53 }
52 54
53 net::URLRequestJob* MaybeInterceptRedirect( 55 net::URLRequestJob* MaybeInterceptRedirect(
54 net::URLRequest* request, 56 net::URLRequest* request,
55 net::NetworkDelegate* network_delegate, 57 net::NetworkDelegate* network_delegate,
56 const GURL& location) const override { 58 const GURL& location) const override {
57 return nullptr; 59 return nullptr;
58 } 60 }
(...skipping 10 matching lines...) Expand all
69 71
70 bool IsHandledURL(const GURL& url) const override { 72 bool IsHandledURL(const GURL& url) const override {
71 return IsHandledProtocol(url.scheme()); 73 return IsHandledProtocol(url.scheme());
72 } 74 }
73 75
74 bool IsSafeRedirectTarget(const GURL& location) const override { 76 bool IsSafeRedirectTarget(const GURL& location) const override {
75 return false; 77 return false;
76 } 78 }
77 79
78 private: 80 private:
81 base::MessageLoop message_loop_;
79 base::FilePath path_; 82 base::FilePath path_;
80 JobObserver* observer_; 83 JobObserver* observer_;
81 }; 84 };
82 85
83 class JobObserverImpl : public CallbacksJobFactory::JobObserver { 86 class JobObserverImpl : public CallbacksJobFactory::JobObserver {
84 public: 87 public:
85 JobObserverImpl() : num_jobs_created_(0) {} 88 JobObserverImpl() : num_jobs_created_(0) {}
86 ~JobObserverImpl() override {} 89 ~JobObserverImpl() override {}
87 90
88 void OnJobCreated() override { ++num_jobs_created_; } 91 void OnJobCreated() override { ++num_jobs_created_; }
(...skipping 22 matching lines...) Expand all
111 URLRequestContentJobTest(); 114 URLRequestContentJobTest();
112 115
113 protected: 116 protected:
114 // This inserts an image file into the android MediaStore and retrieves the 117 // This inserts an image file into the android MediaStore and retrieves the
115 // content URI. Then creates and runs a URLRequestContentJob to get the 118 // content URI. Then creates and runs a URLRequestContentJob to get the
116 // contents out of it. If a Range is provided, this function will add the 119 // contents out of it. If a Range is provided, this function will add the
117 // appropriate Range http header to the request and verify the bytes 120 // appropriate Range http header to the request and verify the bytes
118 // retrieved. 121 // retrieved.
119 void RunRequest(const Range* range); 122 void RunRequest(const Range* range);
120 123
121 base::MessageLoop message_loop_;
122 JobObserverImpl observer_; 124 JobObserverImpl observer_;
123 net::TestURLRequestContext context_; 125 net::TestURLRequestContext context_;
124 net::TestDelegate delegate_; 126 net::TestDelegate delegate_;
125 }; 127 };
126 128
127 URLRequestContentJobTest::URLRequestContentJobTest() {} 129 URLRequestContentJobTest::URLRequestContentJobTest() {}
128 130
129 void URLRequestContentJobTest::RunRequest(const Range* range) { 131 void URLRequestContentJobTest::RunRequest(const Range* range) {
130 base::FilePath test_dir; 132 base::FilePath test_dir;
131 PathService::Get(base::DIR_SOURCE_ROOT, &test_dir); 133 PathService::Get(base::DIR_SOURCE_ROOT, &test_dir);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 192 }
191 193
192 TEST_F(URLRequestContentJobTest, ContentURIWithZeroRange) { 194 TEST_F(URLRequestContentJobTest, ContentURIWithZeroRange) {
193 Range range(0, 0); 195 Range range(0, 0);
194 RunRequest(&range); 196 RunRequest(&range);
195 } 197 }
196 198
197 } // namespace 199 } // namespace
198 200
199 } // namespace content 201 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/ssl/chrome_expect_ct_reporter_unittest.cc ('k') | net/http/http_transaction_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698