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

Side by Side Diff: third_party/WebKit/Source/platform/testing/weburl_loader_mock.cc

Issue 2657793002: Make WebURLLoaderMockFactoryImpl::createURLLoader accept nullptr (Closed)
Patch Set: cl format 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
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 "platform/testing/weburl_loader_mock.h" 5 #include "platform/testing/weburl_loader_mock.h"
6 6
7 #include "platform/testing/weburl_loader_mock_factory_impl.h" 7 #include "platform/testing/weburl_loader_mock_factory_impl.h"
8 #include "public/platform/URLConversion.h" 8 #include "public/platform/URLConversion.h"
9 #include "public/platform/WebData.h" 9 #include "public/platform/WebData.h"
10 #include "public/platform/WebURLError.h" 10 #include "public/platform/WebURLError.h"
11 #include "public/platform/WebURLLoaderClient.h" 11 #include "public/platform/WebURLLoaderClient.h"
12 12
13 namespace blink { 13 namespace blink {
14 14
15 namespace {
16
17 void assertFallbackLoaderAvailability(const WebURL& url,
18 const WebURLLoader* default_loader) {
19 DCHECK(KURL(url).protocolIsData()) << "shouldn't be falling back: "
20 << url.string().utf8();
21 DCHECK(default_loader) << "default_loader wasn't set: "
22 << url.string().utf8();
23 }
24
25 } // namespace
26
15 WebURLLoaderMock::WebURLLoaderMock(WebURLLoaderMockFactoryImpl* factory, 27 WebURLLoaderMock::WebURLLoaderMock(WebURLLoaderMockFactoryImpl* factory,
16 WebURLLoader* default_loader) 28 WebURLLoader* default_loader)
17 : factory_(factory), 29 : factory_(factory),
18 default_loader_(WTF::wrapUnique(default_loader)), 30 default_loader_(WTF::wrapUnique(default_loader)),
19 weak_factory_(this) {} 31 weak_factory_(this) {}
20 32
21 WebURLLoaderMock::~WebURLLoaderMock() { 33 WebURLLoaderMock::~WebURLLoaderMock() {
22 cancel(); 34 cancel();
23 } 35 }
24 36
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 WebURLResponse& response, 109 WebURLResponse& response,
98 WebURLError& error, 110 WebURLError& error,
99 WebData& data, 111 WebData& data,
100 int64_t& encoded_data_length, 112 int64_t& encoded_data_length,
101 int64_t& encoded_body_length) { 113 int64_t& encoded_body_length) {
102 if (factory_->IsMockedURL(request.url())) { 114 if (factory_->IsMockedURL(request.url())) {
103 factory_->LoadSynchronously(request, &response, &error, &data, 115 factory_->LoadSynchronously(request, &response, &error, &data,
104 &encoded_data_length); 116 &encoded_data_length);
105 return; 117 return;
106 } 118 }
107 DCHECK(KURL(request.url()).protocolIsData()) 119 assertFallbackLoaderAvailability(request.url(), default_loader_.get());
108 << "loadSynchronously shouldn't be falling back: "
109 << request.url().string().utf8();
110 using_default_loader_ = true; 120 using_default_loader_ = true;
111 default_loader_->loadSynchronously(request, response, error, data, 121 default_loader_->loadSynchronously(request, response, error, data,
112 encoded_data_length, encoded_body_length); 122 encoded_data_length, encoded_body_length);
113 } 123 }
114 124
115 void WebURLLoaderMock::loadAsynchronously(const WebURLRequest& request, 125 void WebURLLoaderMock::loadAsynchronously(const WebURLRequest& request,
116 WebURLLoaderClient* client) { 126 WebURLLoaderClient* client) {
117 DCHECK(client); 127 DCHECK(client);
118 if (factory_->IsMockedURL(request.url())) { 128 if (factory_->IsMockedURL(request.url())) {
119 client_ = client; 129 client_ = client;
120 factory_->LoadAsynchronouly(request, this); 130 factory_->LoadAsynchronouly(request, this);
121 return; 131 return;
122 } 132 }
123 DCHECK(KURL(request.url()).protocolIsData()) 133 assertFallbackLoaderAvailability(request.url(), default_loader_.get());
124 << "loadAsynchronously shouldn't be falling back: "
125 << request.url().string().utf8();
126 using_default_loader_ = true; 134 using_default_loader_ = true;
127 default_loader_->loadAsynchronously(request, client); 135 default_loader_->loadAsynchronously(request, client);
128 } 136 }
129 137
130 void WebURLLoaderMock::cancel() { 138 void WebURLLoaderMock::cancel() {
131 if (using_default_loader_) { 139 if (using_default_loader_) {
132 default_loader_->cancel(); 140 default_loader_->cancel();
133 return; 141 return;
134 } 142 }
135 client_ = nullptr; 143 client_ = nullptr;
(...skipping 20 matching lines...) Expand all
156 // In principle this is NOTIMPLEMENTED(), but if we put that here it floods 164 // In principle this is NOTIMPLEMENTED(), but if we put that here it floods
157 // the console during webkit unit tests, so we leave the function empty. 165 // the console during webkit unit tests, so we leave the function empty.
158 DCHECK(runner); 166 DCHECK(runner);
159 } 167 }
160 168
161 WeakPtr<WebURLLoaderMock> WebURLLoaderMock::GetWeakPtr() { 169 WeakPtr<WebURLLoaderMock> WebURLLoaderMock::GetWeakPtr() {
162 return weak_factory_.createWeakPtr(); 170 return weak_factory_.createWeakPtr();
163 } 171 }
164 172
165 } // namespace blink 173 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698