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

Side by Side Diff: webkit/support/weburl_loader_mock_factory.cc

Issue 11940002: Support WebCore's memory cache reusing main resources in unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/support/weburl_loader_mock_factory.h" 5 #include "webkit/support/weburl_loader_mock_factory.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLError.h" 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLError.h"
11 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h"
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLResponse.h" 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLResponse.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h"
14 #include "webkit/support/webkit_support.h"
13 #include "webkit/support/weburl_loader_mock.h" 15 #include "webkit/support/weburl_loader_mock.h"
14 16
17 using WebKit::WebCache;
15 using WebKit::WebData; 18 using WebKit::WebData;
16 using WebKit::WebString; 19 using WebKit::WebString;
17 using WebKit::WebURL; 20 using WebKit::WebURL;
18 using WebKit::WebURLError; 21 using WebKit::WebURLError;
19 using WebKit::WebURLLoader; 22 using WebKit::WebURLLoader;
20 using WebKit::WebURLRequest; 23 using WebKit::WebURLRequest;
21 using WebKit::WebURLResponse; 24 using WebKit::WebURLResponse;
22 25
23 struct WebURLLoaderMockFactory::ResponseInfo { 26 struct WebURLLoaderMockFactory::ResponseInfo {
24 WebKit::WebURLResponse response; 27 WebKit::WebURLResponse response;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 url_to_reponse_info_.erase(iter); 69 url_to_reponse_info_.erase(iter);
67 70
68 URLToErrorMap::iterator error_iter = url_to_error_info_.find(url); 71 URLToErrorMap::iterator error_iter = url_to_error_info_.find(url);
69 if (error_iter != url_to_error_info_.end()) 72 if (error_iter != url_to_error_info_.end())
70 url_to_error_info_.erase(error_iter); 73 url_to_error_info_.erase(error_iter);
71 } 74 }
72 75
73 void WebURLLoaderMockFactory::UnregisterAllURLs() { 76 void WebURLLoaderMockFactory::UnregisterAllURLs() {
74 url_to_reponse_info_.clear(); 77 url_to_reponse_info_.clear();
75 url_to_error_info_.clear(); 78 url_to_error_info_.clear();
79 WebCache::clear();
76 } 80 }
77 81
78 void WebURLLoaderMockFactory::ServeAsynchronousRequests() { 82 void WebURLLoaderMockFactory::ServeAsynchronousRequests() {
79 last_handled_asynchronous_request_.reset(); 83 last_handled_asynchronous_request_.reset();
80 // Serving a request might trigger more requests, so we cannot iterate on 84 // Serving a request might trigger more requests, so we cannot iterate on
81 // pending_loaders_ as it might get modified. 85 // pending_loaders_ as it might get modified.
82 while (!pending_loaders_.empty()) { 86 while (!pending_loaders_.empty()) {
83 LoaderToRequestMap::iterator iter = pending_loaders_.begin(); 87 LoaderToRequestMap::iterator iter = pending_loaders_.begin();
84 WebURLLoaderMock* loader = iter->first; 88 WebURLLoaderMock* loader = iter->first;
85 const WebURLRequest& request = iter->second; 89 const WebURLRequest& request = iter->second;
(...skipping 10 matching lines...) Expand all
96 break; 100 break;
97 last_handled_asynchronous_request_ = newRequest; 101 last_handled_asynchronous_request_ = newRequest;
98 LoadRequest(newRequest, &response, &error, &data); 102 LoadRequest(newRequest, &response, &error, &data);
99 } 103 }
100 // Serve the request if the loader is still active. 104 // Serve the request if the loader is still active.
101 if (IsPending(loader) && !loader->isDeferred()) 105 if (IsPending(loader) && !loader->isDeferred())
102 loader->ServeAsynchronousRequest(response, data, error); 106 loader->ServeAsynchronousRequest(response, data, error);
103 // The loader might have already been removed. 107 // The loader might have already been removed.
104 pending_loaders_.erase(loader); 108 pending_loaders_.erase(loader);
105 } 109 }
110 webkit_support::RunAllPendingMessages();
106 } 111 }
107 112
108 WebKit::WebURLRequest 113 WebKit::WebURLRequest
109 WebURLLoaderMockFactory::GetLastHandledAsynchronousRequest() { 114 WebURLLoaderMockFactory::GetLastHandledAsynchronousRequest() {
110 return last_handled_asynchronous_request_; 115 return last_handled_asynchronous_request_;
111 } 116 }
112 117
113 bool WebURLLoaderMockFactory::IsMockedURL(const WebKit::WebURL& url) { 118 bool WebURLLoaderMockFactory::IsMockedURL(const WebKit::WebURL& url) {
114 return url_to_reponse_info_.find(url) != url_to_reponse_info_.end(); 119 return url_to_reponse_info_.find(url) != url_to_reponse_info_.end();
115 } 120 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 scoped_array<char> buffer(new char[size]); 186 scoped_array<char> buffer(new char[size]);
182 data->reset(); 187 data->reset();
183 int read_count = file_util::ReadFile(file_path, buffer.get(), size); 188 int read_count = file_util::ReadFile(file_path, buffer.get(), size);
184 if (read_count == -1) 189 if (read_count == -1)
185 return false; 190 return false;
186 DCHECK(read_count == size); 191 DCHECK(read_count == size);
187 data->assign(buffer.get(), size); 192 data->assign(buffer.get(), size);
188 193
189 return true; 194 return true;
190 } 195 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698