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

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

Issue 2130493002: Implement THROTTLED priority semantics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@NetworkStreamThrottler
Patch Set: Fix use of message_loop_ in Android tests. 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/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/test/test_file_util.h" 15 #include "base/test/test_file_util.h"
16 #include "base/threading/thread_task_runner_handle.h"
16 #include "net/url_request/url_request.h" 17 #include "net/url_request/url_request.h"
17 #include "net/url_request/url_request_test_util.h" 18 #include "net/url_request/url_request_test_util.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20
21 namespace content { 21 namespace content {
22 22
23 namespace { 23 namespace {
24 24
25 // A URLRequestJobFactory that will return URLRequestContentJobWithCallbacks 25 // A URLRequestJobFactory that will return URLRequestContentJobWithCallbacks
26 // instances for content:// scheme URLs. 26 // instances for content:// scheme URLs.
27 class CallbacksJobFactory : public net::URLRequestJobFactory { 27 class CallbacksJobFactory : public net::URLRequestJobFactory {
28 public: 28 public:
29 class JobObserver { 29 class JobObserver {
30 public: 30 public:
31 virtual ~JobObserver() {} 31 virtual ~JobObserver() {}
32 virtual void OnJobCreated() = 0; 32 virtual void OnJobCreated() = 0;
33 }; 33 };
34 34
35 CallbacksJobFactory(const base::FilePath& path, JobObserver* observer) 35 CallbacksJobFactory(const base::FilePath& path, JobObserver* observer)
36 : path_(path), observer_(observer) { 36 : path_(path), observer_(observer) {
37 } 37 }
38 38
39 ~CallbacksJobFactory() override {} 39 ~CallbacksJobFactory() override {}
40 40
41 net::URLRequestJob* MaybeCreateJobWithProtocolHandler( 41 net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
42 const std::string& scheme, 42 const std::string& scheme,
43 net::URLRequest* request, 43 net::URLRequest* request,
44 net::NetworkDelegate* network_delegate) const override { 44 net::NetworkDelegate* network_delegate) const override {
45 URLRequestContentJob* job = 45 URLRequestContentJob* job =
46 new URLRequestContentJob( 46 new URLRequestContentJob(
47 request, 47 request,
48 network_delegate, 48 network_delegate,
49 path_, 49 path_,
50 const_cast<base::MessageLoop*>(&message_loop_)->task_runner()); 50 base::ThreadTaskRunnerHandle::Get());
51 observer_->OnJobCreated(); 51 observer_->OnJobCreated();
52 return job; 52 return job;
53 } 53 }
54 54
55 net::URLRequestJob* MaybeInterceptRedirect( 55 net::URLRequestJob* MaybeInterceptRedirect(
56 net::URLRequest* request, 56 net::URLRequest* request,
57 net::NetworkDelegate* network_delegate, 57 net::NetworkDelegate* network_delegate,
58 const GURL& location) const override { 58 const GURL& location) const override {
59 return nullptr; 59 return nullptr;
60 } 60 }
(...skipping 10 matching lines...) Expand all
71 71
72 bool IsHandledURL(const GURL& url) const override { 72 bool IsHandledURL(const GURL& url) const override {
73 return IsHandledProtocol(url.scheme()); 73 return IsHandledProtocol(url.scheme());
74 } 74 }
75 75
76 bool IsSafeRedirectTarget(const GURL& location) const override { 76 bool IsSafeRedirectTarget(const GURL& location) const override {
77 return false; 77 return false;
78 } 78 }
79 79
80 private: 80 private:
81 base::MessageLoop message_loop_;
82 base::FilePath path_; 81 base::FilePath path_;
83 JobObserver* observer_; 82 JobObserver* observer_;
84 }; 83 };
85 84
86 class JobObserverImpl : public CallbacksJobFactory::JobObserver { 85 class JobObserverImpl : public CallbacksJobFactory::JobObserver {
87 public: 86 public:
88 JobObserverImpl() : num_jobs_created_(0) {} 87 JobObserverImpl() : num_jobs_created_(0) {}
89 ~JobObserverImpl() override {} 88 ~JobObserverImpl() override {}
90 89
91 void OnJobCreated() override { ++num_jobs_created_; } 90 void OnJobCreated() override { ++num_jobs_created_; }
(...skipping 22 matching lines...) Expand all
114 URLRequestContentJobTest(); 113 URLRequestContentJobTest();
115 114
116 protected: 115 protected:
117 // This inserts an image file into the android MediaStore and retrieves the 116 // This inserts an image file into the android MediaStore and retrieves the
118 // content URI. Then creates and runs a URLRequestContentJob to get the 117 // content URI. Then creates and runs a URLRequestContentJob to get the
119 // contents out of it. If a Range is provided, this function will add the 118 // contents out of it. If a Range is provided, this function will add the
120 // appropriate Range http header to the request and verify the bytes 119 // appropriate Range http header to the request and verify the bytes
121 // retrieved. 120 // retrieved.
122 void RunRequest(const Range* range); 121 void RunRequest(const Range* range);
123 122
123 base::MessageLoop message_loop_;
124 JobObserverImpl observer_; 124 JobObserverImpl observer_;
125 net::TestURLRequestContext context_; 125 net::TestURLRequestContext context_;
126 net::TestDelegate delegate_; 126 net::TestDelegate delegate_;
127 }; 127 };
128 128
129 URLRequestContentJobTest::URLRequestContentJobTest() {} 129 URLRequestContentJobTest::URLRequestContentJobTest() {}
130 130
131 void URLRequestContentJobTest::RunRequest(const Range* range) { 131 void URLRequestContentJobTest::RunRequest(const Range* range) {
132 base::FilePath test_dir; 132 base::FilePath test_dir;
133 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
192 } 192 }
193 193
194 TEST_F(URLRequestContentJobTest, ContentURIWithZeroRange) { 194 TEST_F(URLRequestContentJobTest, ContentURIWithZeroRange) {
195 Range range(0, 0); 195 Range range(0, 0);
196 RunRequest(&range); 196 RunRequest(&range);
197 } 197 }
198 198
199 } // namespace 199 } // namespace
200 200
201 } // namespace content 201 } // namespace content
OLDNEW
« no previous file with comments | « components/cronet/url_request_context_config_unittest.cc ('k') | net/base/network_throttle_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698