OLD | NEW |
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 // This file contains the implementation of TestWebViewDelegate, which serves | 5 // This file contains the implementation of TestWebViewDelegate, which serves |
6 // as the WebViewDelegate for the TestShellWebHost. The host is expected to | 6 // as the WebViewDelegate for the TestShellWebHost. The host is expected to |
7 // have initialized a MessageLoop before these methods are called. | 7 // have initialized a MessageLoop before these methods are called. |
8 | 8 |
9 #include "webkit/tools/test_shell/test_webview_delegate.h" | 9 #include "webkit/tools/test_shell/test_webview_delegate.h" |
10 | 10 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 const char* kReloadString = "reload"; | 143 const char* kReloadString = "reload"; |
144 const char* kFormResubmittedString = "form resubmitted"; | 144 const char* kFormResubmittedString = "form resubmitted"; |
145 const char* kOtherString = "other"; | 145 const char* kOtherString = "other"; |
146 const char* kIllegalString = "illegal value"; | 146 const char* kIllegalString = "illegal value"; |
147 | 147 |
148 int next_page_id_ = 1; | 148 int next_page_id_ = 1; |
149 | 149 |
150 // Used to write a platform neutral file:/// URL by taking the | 150 // Used to write a platform neutral file:/// URL by taking the |
151 // filename and its directory. (e.g., converts | 151 // filename and its directory. (e.g., converts |
152 // "file:///tmp/foo/bar.txt" to just "bar.txt"). | 152 // "file:///tmp/foo/bar.txt" to just "bar.txt"). |
153 std::string DescriptionSuitableForTestResult(const std::string& url) { | |
154 if (url.empty() || std::string::npos == url.find("file://")) | |
155 return url; | |
156 | |
157 size_t pos = url.rfind('/'); | |
158 if (pos == std::string::npos || pos == 0) | |
159 return "ERROR:" + url; | |
160 pos = url.rfind('/', pos - 1); | |
161 if (pos == std::string::npos) | |
162 return "ERROR:" + url; | |
163 | |
164 return url.substr(pos + 1); | |
165 } | |
166 | |
167 // Adds a file called "DRTFakeFile" to |data_object|. Use to fake dragging a | |
168 // file. | |
169 void AddDRTFakeFileToDataObject(WebDragData* drag_data) { | |
170 WebDragData::Item item; | |
171 item.storageType = WebDragData::Item::StorageTypeFilename; | |
172 item.filenameData = WebString::fromUTF8("DRTFakeFile"); | |
173 drag_data->addItem(item); | |
174 } | |
175 | |
176 // Get a debugging string from a WebNavigationType. | 153 // Get a debugging string from a WebNavigationType. |
177 const char* WebNavigationTypeToString(WebNavigationType type) { | 154 const char* WebNavigationTypeToString(WebNavigationType type) { |
178 switch (type) { | 155 switch (type) { |
179 case WebKit::WebNavigationTypeLinkClicked: | 156 case WebKit::WebNavigationTypeLinkClicked: |
180 return kLinkClickedString; | 157 return kLinkClickedString; |
181 case WebKit::WebNavigationTypeFormSubmitted: | 158 case WebKit::WebNavigationTypeFormSubmitted: |
182 return kFormSubmittedString; | 159 return kFormSubmittedString; |
183 case WebKit::WebNavigationTypeBackForward: | 160 case WebKit::WebNavigationTypeBackForward: |
184 return kBackForwardString; | 161 return kBackForwardString; |
185 case WebKit::WebNavigationTypeReload: | 162 case WebKit::WebNavigationTypeReload: |
186 return kReloadString; | 163 return kReloadString; |
187 case WebKit::WebNavigationTypeFormResubmitted: | 164 case WebKit::WebNavigationTypeFormResubmitted: |
188 return kFormResubmittedString; | 165 return kFormResubmittedString; |
189 case WebKit::WebNavigationTypeOther: | 166 case WebKit::WebNavigationTypeOther: |
190 return kOtherString; | 167 return kOtherString; |
191 } | 168 } |
192 return kIllegalString; | 169 return kIllegalString; |
193 } | 170 } |
194 | 171 |
195 std::string GetURLDescription(const GURL& url) { | 172 std::string GetURLDescription(const GURL& url) { |
196 if (url.SchemeIs("file")) | 173 if (url.SchemeIs("file")) |
197 return url.ExtractFileName(); | 174 return url.ExtractFileName(); |
198 | 175 |
199 return url.possibly_invalid_spec(); | 176 return url.possibly_invalid_spec(); |
200 } | 177 } |
201 | 178 |
202 std::string GetResponseDescription(const WebURLResponse& response) { | |
203 if (response.isNull()) | |
204 return "(null)"; | |
205 | |
206 const std::string url = GURL(response.url()).possibly_invalid_spec(); | |
207 return base::StringPrintf("<NSURLResponse %s, http status code %d>", | |
208 DescriptionSuitableForTestResult(url).c_str(), | |
209 response.httpStatusCode()); | |
210 } | |
211 | |
212 std::string GetErrorDescription(const WebURLError& error) { | |
213 std::string domain = UTF16ToASCII(error.domain); | |
214 int code = error.reason; | |
215 | |
216 if (domain == net::kErrorDomain) { | |
217 domain = "NSURLErrorDomain"; | |
218 switch (error.reason) { | |
219 case net::ERR_ABORTED: | |
220 code = -999; // NSURLErrorCancelled | |
221 break; | |
222 case net::ERR_UNSAFE_PORT: | |
223 // Our unsafe port checking happens at the network stack level, but we | |
224 // make this translation here to match the behavior of stock WebKit. | |
225 domain = "WebKitErrorDomain"; | |
226 code = 103; | |
227 break; | |
228 case net::ERR_ADDRESS_INVALID: | |
229 case net::ERR_ADDRESS_UNREACHABLE: | |
230 case net::ERR_NETWORK_ACCESS_DENIED: | |
231 code = -1004; // NSURLErrorCannotConnectToHost | |
232 break; | |
233 } | |
234 } else { | |
235 DLOG(WARNING) << "Unknown error domain"; | |
236 } | |
237 | |
238 return base::StringPrintf("<NSError domain %s, code %d, failing URL \"%s\">", | |
239 domain.c_str(), code, error.unreachableURL.spec().data()); | |
240 } | |
241 | |
242 std::string GetNodeDescription(const WebNode& node, int exception) { | 179 std::string GetNodeDescription(const WebNode& node, int exception) { |
243 if (exception) | 180 if (exception) |
244 return "ERROR"; | 181 return "ERROR"; |
245 if (node.isNull()) | 182 if (node.isNull()) |
246 return "(null)"; | 183 return "(null)"; |
247 std::string str = node.nodeName().utf8(); | 184 std::string str = node.nodeName().utf8(); |
248 const WebNode& parent = node.parentNode(); | 185 const WebNode& parent = node.parentNode(); |
249 if (!parent.isNull()) { | 186 if (!parent.isNull()) { |
250 str.append(" > "); | 187 str.append(" > "); |
251 str.append(GetNodeDescription(parent, 0)); | 188 str.append(GetNodeDescription(parent, 0)); |
252 } | 189 } |
253 return str; | 190 return str; |
254 } | 191 } |
255 | 192 |
256 std::string GetRangeDescription(const WebRange& range) { | |
257 if (range.isNull()) | |
258 return "(null)"; | |
259 int exception = 0; | |
260 std::string str = "range from "; | |
261 int offset = range.startOffset(); | |
262 str.append(base::IntToString(offset)); | |
263 str.append(" of "); | |
264 WebNode container = range.startContainer(exception); | |
265 str.append(GetNodeDescription(container, exception)); | |
266 str.append(" to "); | |
267 offset = range.endOffset(); | |
268 str.append(base::IntToString(offset)); | |
269 str.append(" of "); | |
270 container = range.endContainer(exception); | |
271 str.append(GetNodeDescription(container, exception)); | |
272 return str; | |
273 } | |
274 | |
275 std::string GetEditingActionDescription(WebEditingAction action) { | |
276 switch (action) { | |
277 case WebKit::WebEditingActionTyped: | |
278 return "WebViewInsertActionTyped"; | |
279 case WebKit::WebEditingActionPasted: | |
280 return "WebViewInsertActionPasted"; | |
281 case WebKit::WebEditingActionDropped: | |
282 return "WebViewInsertActionDropped"; | |
283 } | |
284 return "(UNKNOWN ACTION)"; | |
285 } | |
286 | |
287 std::string GetTextAffinityDescription(WebTextAffinity affinity) { | |
288 switch (affinity) { | |
289 case WebKit::WebTextAffinityUpstream: | |
290 return "NSSelectionAffinityUpstream"; | |
291 case WebKit::WebTextAffinityDownstream: | |
292 return "NSSelectionAffinityDownstream"; | |
293 } | |
294 return "(UNKNOWN AFFINITY)"; | |
295 } | |
296 | |
297 } // namespace | 193 } // namespace |
298 | 194 |
299 // WebViewDelegate ----------------------------------------------------------- | 195 // WebViewDelegate ----------------------------------------------------------- |
300 | 196 |
301 std::string TestWebViewDelegate::GetResourceDescription(uint32 identifier) { | 197 std::string TestWebViewDelegate::GetResourceDescription(uint32 identifier) { |
302 ResourceMap::iterator it = resource_identifier_map_.find(identifier); | 198 ResourceMap::iterator it = resource_identifier_map_.find(identifier); |
303 return it != resource_identifier_map_.end() ? it->second : "<unknown>"; | 199 return it != resource_identifier_map_.end() ? it->second : "<unknown>"; |
304 } | 200 } |
305 | 201 |
306 void TestWebViewDelegate::SetUserStyleSheetEnabled(bool is_enabled) { | 202 void TestWebViewDelegate::SetUserStyleSheetEnabled(bool is_enabled) { |
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 } | 1034 } |
1139 | 1035 |
1140 void TestWebViewDelegate::set_fake_window_rect(const WebRect& rect) { | 1036 void TestWebViewDelegate::set_fake_window_rect(const WebRect& rect) { |
1141 fake_rect_ = rect; | 1037 fake_rect_ = rect; |
1142 using_fake_rect_ = true; | 1038 using_fake_rect_ = true; |
1143 } | 1039 } |
1144 | 1040 |
1145 WebRect TestWebViewDelegate::fake_window_rect() { | 1041 WebRect TestWebViewDelegate::fake_window_rect() { |
1146 return fake_rect_; | 1042 return fake_rect_; |
1147 } | 1043 } |
OLD | NEW |