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/weburl_loader_mock_factory_impl.h" | 5 #include "platform/testing/weburl_loader_mock_factory_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 url_to_error_info_.clear(); | 77 url_to_error_info_.clear(); |
78 } | 78 } |
79 | 79 |
80 void WebURLLoaderMockFactoryImpl::serveAsynchronousRequests() { | 80 void WebURLLoaderMockFactoryImpl::serveAsynchronousRequests() { |
81 // Serving a request might trigger more requests, so we cannot iterate on | 81 // Serving a request might trigger more requests, so we cannot iterate on |
82 // pending_loaders_ as it might get modified. | 82 // pending_loaders_ as it might get modified. |
83 while (!pending_loaders_.isEmpty()) { | 83 while (!pending_loaders_.isEmpty()) { |
84 LoaderToRequestMap::iterator iter = pending_loaders_.begin(); | 84 LoaderToRequestMap::iterator iter = pending_loaders_.begin(); |
85 WeakPtr<WebURLLoaderMock> loader(iter->key->GetWeakPtr()); | 85 WeakPtr<WebURLLoaderMock> loader(iter->key->GetWeakPtr()); |
86 const WebURLRequest request = iter->value; | 86 const WebURLRequest request = iter->value; |
87 pending_loaders_.remove(loader.get()); | 87 pending_loaders_.erase(loader.get()); |
88 | 88 |
89 WebURLResponse response; | 89 WebURLResponse response; |
90 WebURLError error; | 90 WebURLError error; |
91 WebData data; | 91 WebData data; |
92 LoadRequest(request, &response, &error, &data); | 92 LoadRequest(request, &response, &error, &data); |
93 // Follow any redirects while the loader is still active. | 93 // Follow any redirects while the loader is still active. |
94 while (response.httpStatusCode() >= 300 && | 94 while (response.httpStatusCode() >= 300 && |
95 response.httpStatusCode() < 400) { | 95 response.httpStatusCode() < 400) { |
96 WebURLRequest newRequest = loader->ServeRedirect(request, response); | 96 WebURLRequest newRequest = loader->ServeRedirect(request, response); |
97 RunUntilIdle(); | 97 RunUntilIdle(); |
98 if (!loader || loader->is_cancelled() || loader->is_deferred()) | 98 if (!loader || loader->is_cancelled() || loader->is_deferred()) |
99 break; | 99 break; |
100 LoadRequest(newRequest, &response, &error, &data); | 100 LoadRequest(newRequest, &response, &error, &data); |
101 } | 101 } |
102 // Serve the request if the loader is still active. | 102 // Serve the request if the loader is still active. |
103 if (loader && !loader->is_cancelled() && !loader->is_deferred()) { | 103 if (loader && !loader->is_cancelled() && !loader->is_deferred()) { |
104 loader->ServeAsynchronousRequest(delegate_, response, data, error); | 104 loader->ServeAsynchronousRequest(delegate_, response, data, error); |
105 RunUntilIdle(); | 105 RunUntilIdle(); |
106 } | 106 } |
107 } | 107 } |
108 RunUntilIdle(); | 108 RunUntilIdle(); |
109 } | 109 } |
110 | 110 |
111 bool WebURLLoaderMockFactoryImpl::IsMockedURL(const blink::WebURL& url) { | 111 bool WebURLLoaderMockFactoryImpl::IsMockedURL(const blink::WebURL& url) { |
112 return url_to_response_info_.find(url) != url_to_response_info_.end(); | 112 return url_to_response_info_.find(url) != url_to_response_info_.end(); |
113 } | 113 } |
114 | 114 |
115 void WebURLLoaderMockFactoryImpl::CancelLoad(WebURLLoaderMock* loader) { | 115 void WebURLLoaderMockFactoryImpl::CancelLoad(WebURLLoaderMock* loader) { |
116 pending_loaders_.remove(loader); | 116 pending_loaders_.erase(loader); |
117 } | 117 } |
118 | 118 |
119 void WebURLLoaderMockFactoryImpl::LoadSynchronously( | 119 void WebURLLoaderMockFactoryImpl::LoadSynchronously( |
120 const WebURLRequest& request, | 120 const WebURLRequest& request, |
121 WebURLResponse* response, | 121 WebURLResponse* response, |
122 WebURLError* error, | 122 WebURLError* error, |
123 WebData* data, | 123 WebData* data, |
124 int64_t* encoded_data_length) { | 124 int64_t* encoded_data_length) { |
125 LoadRequest(request, response, error, data); | 125 LoadRequest(request, response, error, data); |
126 *encoded_data_length = data->size(); | 126 *encoded_data_length = data->size(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 175 |
176 std::string buffer; | 176 std::string buffer; |
177 if (!base::ReadFileToString(file_path, &buffer)) | 177 if (!base::ReadFileToString(file_path, &buffer)) |
178 return false; | 178 return false; |
179 | 179 |
180 data->assign(buffer.data(), buffer.size()); | 180 data->assign(buffer.data(), buffer.size()); |
181 return true; | 181 return true; |
182 } | 182 } |
183 | 183 |
184 } // namespace blink | 184 } // namespace blink |
OLD | NEW |