Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/WebURLLoaderMock.h" | 5 #include "platform/testing/WebURLLoaderMock.h" |
| 6 | 6 |
| 7 #include "platform/testing/WebURLLoaderMockFactoryImpl.h" | 7 #include "platform/testing/WebURLLoaderMockFactoryImpl.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 IsFallbackLoaderAvailable(const WebURL& url, | |
|
kinuko
2017/01/25 12:42:13
I'd name this 'assertFallbackLoaderAvailability()'
Takashi Toyoshima
2017/01/26 11:54:24
Done.
| |
| 18 const WebURLLoader* defaultLoader) { | |
| 19 DCHECK(KURL(url).protocolIsData()) << "shouldn't be falling back: " | |
| 20 << url.string().utf8(); | |
| 21 DCHECK(defaultLoader) << "defaultLoader wasn't set: " << url.string().utf8(); | |
| 22 } | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 15 WebURLLoaderMock::WebURLLoaderMock(WebURLLoaderMockFactoryImpl* factory, | 26 WebURLLoaderMock::WebURLLoaderMock(WebURLLoaderMockFactoryImpl* factory, |
| 16 WebURLLoader* defaultLoader) | 27 WebURLLoader* defaultLoader) |
| 17 : m_factory(factory), | 28 : m_factory(factory), |
| 18 m_defaultLoader(WTF::wrapUnique(defaultLoader)), | 29 m_defaultLoader(WTF::wrapUnique(defaultLoader)), |
| 19 m_weakFactory(this) {} | 30 m_weakFactory(this) {} |
| 20 | 31 |
| 21 WebURLLoaderMock::~WebURLLoaderMock() { | 32 WebURLLoaderMock::~WebURLLoaderMock() { |
| 22 cancel(); | 33 cancel(); |
| 23 } | 34 } |
| 24 | 35 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 WebURLResponse& response, | 108 WebURLResponse& response, |
| 98 WebURLError& error, | 109 WebURLError& error, |
| 99 WebData& data, | 110 WebData& data, |
| 100 int64_t& encodedDataLength, | 111 int64_t& encodedDataLength, |
| 101 int64_t& encodedBodyLength) { | 112 int64_t& encodedBodyLength) { |
| 102 if (m_factory->IsMockedURL(request.url())) { | 113 if (m_factory->IsMockedURL(request.url())) { |
| 103 m_factory->LoadSynchronously(request, &response, &error, &data, | 114 m_factory->LoadSynchronously(request, &response, &error, &data, |
| 104 &encodedDataLength); | 115 &encodedDataLength); |
| 105 return; | 116 return; |
| 106 } | 117 } |
| 107 DCHECK(KURL(request.url()).protocolIsData()) | 118 IsFallbackLoaderAvailable(request.url(), m_defaultLoader.get()); |
| 108 << "loadSynchronously shouldn't be falling back: " | |
| 109 << request.url().string().utf8(); | |
| 110 m_usingDefaultLoader = true; | 119 m_usingDefaultLoader = true; |
| 111 m_defaultLoader->loadSynchronously(request, response, error, data, | 120 m_defaultLoader->loadSynchronously(request, response, error, data, |
| 112 encodedDataLength, encodedBodyLength); | 121 encodedDataLength, encodedBodyLength); |
| 113 } | 122 } |
| 114 | 123 |
| 115 void WebURLLoaderMock::loadAsynchronously(const WebURLRequest& request, | 124 void WebURLLoaderMock::loadAsynchronously(const WebURLRequest& request, |
| 116 WebURLLoaderClient* client) { | 125 WebURLLoaderClient* client) { |
| 117 DCHECK(client); | 126 DCHECK(client); |
| 118 if (m_factory->IsMockedURL(request.url())) { | 127 if (m_factory->IsMockedURL(request.url())) { |
| 119 m_client = client; | 128 m_client = client; |
| 120 m_factory->LoadAsynchronouly(request, this); | 129 m_factory->LoadAsynchronouly(request, this); |
| 121 return; | 130 return; |
| 122 } | 131 } |
| 123 DCHECK(KURL(request.url()).protocolIsData()) | 132 IsFallbackLoaderAvailable(request.url(), m_defaultLoader.get()); |
| 124 << "loadAsynchronously shouldn't be falling back: " | |
| 125 << request.url().string().utf8(); | |
| 126 m_usingDefaultLoader = true; | 133 m_usingDefaultLoader = true; |
| 127 m_defaultLoader->loadAsynchronously(request, client); | 134 m_defaultLoader->loadAsynchronously(request, client); |
| 128 } | 135 } |
| 129 | 136 |
| 130 void WebURLLoaderMock::cancel() { | 137 void WebURLLoaderMock::cancel() { |
| 131 if (m_usingDefaultLoader) { | 138 if (m_usingDefaultLoader) { |
| 132 m_defaultLoader->cancel(); | 139 m_defaultLoader->cancel(); |
| 133 return; | 140 return; |
| 134 } | 141 } |
| 135 m_client = nullptr; | 142 m_client = nullptr; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 156 // In principle this is NOTIMPLEMENTED(), but if we put that here it floods | 163 // 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. | 164 // the console during webkit unit tests, so we leave the function empty. |
| 158 DCHECK(runner); | 165 DCHECK(runner); |
| 159 } | 166 } |
| 160 | 167 |
| 161 WeakPtr<WebURLLoaderMock> WebURLLoaderMock::GetWeakPtr() { | 168 WeakPtr<WebURLLoaderMock> WebURLLoaderMock::GetWeakPtr() { |
| 162 return m_weakFactory.createWeakPtr(); | 169 return m_weakFactory.createWeakPtr(); |
| 163 } | 170 } |
| 164 | 171 |
| 165 } // namespace blink | 172 } // namespace blink |
| OLD | NEW |