| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/test_runner/web_frame_test_client.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/strings/string_piece.h" | |
| 11 #include "base/strings/string_util.h" | |
| 12 #include "base/strings/stringprintf.h" | |
| 13 #include "components/test_runner/accessibility_controller.h" | |
| 14 #include "components/test_runner/event_sender.h" | |
| 15 #include "components/test_runner/mock_color_chooser.h" | |
| 16 #include "components/test_runner/mock_screen_orientation_client.h" | |
| 17 #include "components/test_runner/mock_web_user_media_client.h" | |
| 18 #include "components/test_runner/test_common.h" | |
| 19 #include "components/test_runner/test_interfaces.h" | |
| 20 #include "components/test_runner/test_plugin.h" | |
| 21 #include "components/test_runner/test_runner.h" | |
| 22 #include "components/test_runner/web_frame_test_proxy.h" | |
| 23 #include "components/test_runner/web_test_delegate.h" | |
| 24 #include "components/test_runner/web_view_test_proxy.h" | |
| 25 #include "components/test_runner/web_widget_test_proxy.h" | |
| 26 #include "net/base/net_errors.h" | |
| 27 #include "third_party/WebKit/public/platform/WebString.h" | |
| 28 #include "third_party/WebKit/public/platform/WebURL.h" | |
| 29 #include "third_party/WebKit/public/platform/WebURLRequest.h" | |
| 30 #include "third_party/WebKit/public/platform/WebURLResponse.h" | |
| 31 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | |
| 32 #include "third_party/WebKit/public/web/WebDataSource.h" | |
| 33 #include "third_party/WebKit/public/web/WebElement.h" | |
| 34 #include "third_party/WebKit/public/web/WebFrame.h" | |
| 35 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
| 36 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" | |
| 37 #include "third_party/WebKit/public/web/WebPluginParams.h" | |
| 38 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | |
| 39 #include "third_party/WebKit/public/web/WebView.h" | |
| 40 #include "url/gurl.h" | |
| 41 #include "url/url_constants.h" | |
| 42 | |
| 43 namespace test_runner { | |
| 44 | |
| 45 namespace { | |
| 46 | |
| 47 void PrintFrameDescription(WebTestDelegate* delegate, blink::WebFrame* frame) { | |
| 48 std::string name8 = frame->uniqueName().utf8(); | |
| 49 if (frame == frame->view()->mainFrame()) { | |
| 50 if (!name8.length()) { | |
| 51 delegate->PrintMessage("main frame"); | |
| 52 return; | |
| 53 } | |
| 54 delegate->PrintMessage(std::string("main frame \"") + name8 + "\""); | |
| 55 return; | |
| 56 } | |
| 57 if (!name8.length()) { | |
| 58 delegate->PrintMessage("frame (anonymous)"); | |
| 59 return; | |
| 60 } | |
| 61 delegate->PrintMessage(std::string("frame \"") + name8 + "\""); | |
| 62 } | |
| 63 | |
| 64 void PrintFrameuserGestureStatus(WebTestDelegate* delegate, | |
| 65 blink::WebFrame* frame, | |
| 66 const char* msg) { | |
| 67 bool is_user_gesture = | |
| 68 blink::WebUserGestureIndicator::isProcessingUserGesture(); | |
| 69 delegate->PrintMessage(std::string("Frame with user gesture \"") + | |
| 70 (is_user_gesture ? "true" : "false") + "\"" + msg); | |
| 71 } | |
| 72 | |
| 73 // Used to write a platform neutral file:/// URL by taking the | |
| 74 // filename and its directory. (e.g., converts | |
| 75 // "file:///tmp/foo/bar.txt" to just "bar.txt"). | |
| 76 std::string DescriptionSuitableForTestResult(const std::string& url) { | |
| 77 if (url.empty() || std::string::npos == url.find("file://")) | |
| 78 return url; | |
| 79 | |
| 80 size_t pos = url.rfind('/'); | |
| 81 if (pos == std::string::npos || !pos) | |
| 82 return "ERROR:" + url; | |
| 83 pos = url.rfind('/', pos - 1); | |
| 84 if (pos == std::string::npos) | |
| 85 return "ERROR:" + url; | |
| 86 | |
| 87 return url.substr(pos + 1); | |
| 88 } | |
| 89 | |
| 90 void PrintResponseDescription(WebTestDelegate* delegate, | |
| 91 const blink::WebURLResponse& response) { | |
| 92 if (response.isNull()) { | |
| 93 delegate->PrintMessage("(null)"); | |
| 94 return; | |
| 95 } | |
| 96 delegate->PrintMessage(base::StringPrintf( | |
| 97 "<NSURLResponse %s, http status code %d>", | |
| 98 DescriptionSuitableForTestResult(response.url().string().utf8()).c_str(), | |
| 99 response.httpStatusCode())); | |
| 100 } | |
| 101 | |
| 102 void BlockRequest(blink::WebURLRequest& request) { | |
| 103 request.setURL(GURL("255.255.255.255")); | |
| 104 } | |
| 105 | |
| 106 bool IsLocalHost(const std::string& host) { | |
| 107 return host == "127.0.0.1" || host == "localhost" || host == "[::1]"; | |
| 108 } | |
| 109 | |
| 110 bool IsTestHost(const std::string& host) { | |
| 111 return base::EndsWith(host, ".test", base::CompareCase::INSENSITIVE_ASCII); | |
| 112 } | |
| 113 | |
| 114 bool HostIsUsedBySomeTestsToGenerateError(const std::string& host) { | |
| 115 return host == "255.255.255.255"; | |
| 116 } | |
| 117 | |
| 118 // Used to write a platform neutral file:/// URL by only taking the filename | |
| 119 // (e.g., converts "file:///tmp/foo.txt" to just "foo.txt"). | |
| 120 std::string URLSuitableForTestResult(const std::string& url) { | |
| 121 if (url.empty() || std::string::npos == url.find("file://")) | |
| 122 return url; | |
| 123 | |
| 124 size_t pos = url.rfind('/'); | |
| 125 if (pos == std::string::npos) { | |
| 126 #ifdef WIN32 | |
| 127 pos = url.rfind('\\'); | |
| 128 if (pos == std::string::npos) | |
| 129 pos = 0; | |
| 130 #else | |
| 131 pos = 0; | |
| 132 #endif | |
| 133 } | |
| 134 std::string filename = url.substr(pos + 1); | |
| 135 if (filename.empty()) | |
| 136 return "file:"; // A WebKit test has this in its expected output. | |
| 137 return filename; | |
| 138 } | |
| 139 | |
| 140 // WebNavigationType debugging strings taken from PolicyDelegate.mm. | |
| 141 const char* kLinkClickedString = "link clicked"; | |
| 142 const char* kFormSubmittedString = "form submitted"; | |
| 143 const char* kBackForwardString = "back/forward"; | |
| 144 const char* kReloadString = "reload"; | |
| 145 const char* kFormResubmittedString = "form resubmitted"; | |
| 146 const char* kOtherString = "other"; | |
| 147 const char* kIllegalString = "illegal value"; | |
| 148 | |
| 149 // Get a debugging string from a WebNavigationType. | |
| 150 const char* WebNavigationTypeToString(blink::WebNavigationType type) { | |
| 151 switch (type) { | |
| 152 case blink::WebNavigationTypeLinkClicked: | |
| 153 return kLinkClickedString; | |
| 154 case blink::WebNavigationTypeFormSubmitted: | |
| 155 return kFormSubmittedString; | |
| 156 case blink::WebNavigationTypeBackForward: | |
| 157 return kBackForwardString; | |
| 158 case blink::WebNavigationTypeReload: | |
| 159 return kReloadString; | |
| 160 case blink::WebNavigationTypeFormResubmitted: | |
| 161 return kFormResubmittedString; | |
| 162 case blink::WebNavigationTypeOther: | |
| 163 return kOtherString; | |
| 164 } | |
| 165 return kIllegalString; | |
| 166 } | |
| 167 | |
| 168 } // namespace | |
| 169 | |
| 170 WebFrameTestClient::WebFrameTestClient( | |
| 171 WebTestDelegate* delegate, | |
| 172 WebViewTestProxyBase* web_view_test_proxy_base, | |
| 173 WebFrameTestProxyBase* web_frame_test_proxy_base) | |
| 174 : delegate_(delegate), | |
| 175 web_view_test_proxy_base_(web_view_test_proxy_base), | |
| 176 web_frame_test_proxy_base_(web_frame_test_proxy_base) { | |
| 177 DCHECK(delegate_); | |
| 178 DCHECK(web_frame_test_proxy_base_); | |
| 179 DCHECK(web_view_test_proxy_base_); | |
| 180 } | |
| 181 | |
| 182 WebFrameTestClient::~WebFrameTestClient() {} | |
| 183 | |
| 184 blink::WebColorChooser* WebFrameTestClient::createColorChooser( | |
| 185 blink::WebColorChooserClient* client, | |
| 186 const blink::WebColor& color, | |
| 187 const blink::WebVector<blink::WebColorSuggestion>& suggestions) { | |
| 188 // This instance is deleted by WebCore::ColorInputType | |
| 189 return new MockColorChooser(client, delegate_, test_runner()); | |
| 190 } | |
| 191 | |
| 192 void WebFrameTestClient::runModalAlertDialog(const blink::WebString& message) { | |
| 193 if (!test_runner()->ShouldDumpJavaScriptDialogs()) | |
| 194 return; | |
| 195 delegate_->PrintMessage(std::string("ALERT: ") + message.utf8().data() + | |
| 196 "\n"); | |
| 197 } | |
| 198 | |
| 199 bool WebFrameTestClient::runModalConfirmDialog( | |
| 200 const blink::WebString& message) { | |
| 201 if (!test_runner()->ShouldDumpJavaScriptDialogs()) | |
| 202 return true; | |
| 203 delegate_->PrintMessage(std::string("CONFIRM: ") + message.utf8().data() + | |
| 204 "\n"); | |
| 205 return true; | |
| 206 } | |
| 207 | |
| 208 bool WebFrameTestClient::runModalPromptDialog( | |
| 209 const blink::WebString& message, | |
| 210 const blink::WebString& default_value, | |
| 211 blink::WebString* actual_value) { | |
| 212 if (!test_runner()->ShouldDumpJavaScriptDialogs()) | |
| 213 return true; | |
| 214 delegate_->PrintMessage(std::string("PROMPT: ") + message.utf8().data() + | |
| 215 ", default text: " + default_value.utf8().data() + | |
| 216 "\n"); | |
| 217 return true; | |
| 218 } | |
| 219 | |
| 220 bool WebFrameTestClient::runModalBeforeUnloadDialog(bool is_reload) { | |
| 221 if (test_runner()->ShouldDumpJavaScriptDialogs()) | |
| 222 delegate_->PrintMessage(std::string("CONFIRM NAVIGATION\n")); | |
| 223 return !test_runner()->shouldStayOnPageAfterHandlingBeforeUnload(); | |
| 224 } | |
| 225 | |
| 226 blink::WebScreenOrientationClient* | |
| 227 WebFrameTestClient::webScreenOrientationClient() { | |
| 228 return test_runner()->getMockScreenOrientationClient(); | |
| 229 } | |
| 230 | |
| 231 void WebFrameTestClient::postAccessibilityEvent(const blink::WebAXObject& obj, | |
| 232 blink::WebAXEvent event) { | |
| 233 // Only hook the accessibility events occured during the test run. | |
| 234 // This check prevents false positives in WebLeakDetector. | |
| 235 // The pending tasks in browser/renderer message queue may trigger | |
| 236 // accessibility events, | |
| 237 // and AccessibilityController will hold on to their target nodes if we don't | |
| 238 // ignore them here. | |
| 239 if (!test_runner()->TestIsRunning()) | |
| 240 return; | |
| 241 | |
| 242 const char* event_name = NULL; | |
| 243 switch (event) { | |
| 244 case blink::WebAXEventActiveDescendantChanged: | |
| 245 event_name = "ActiveDescendantChanged"; | |
| 246 break; | |
| 247 case blink::WebAXEventAlert: | |
| 248 event_name = "Alert"; | |
| 249 break; | |
| 250 case blink::WebAXEventAriaAttributeChanged: | |
| 251 event_name = "AriaAttributeChanged"; | |
| 252 break; | |
| 253 case blink::WebAXEventAutocorrectionOccured: | |
| 254 event_name = "AutocorrectionOccured"; | |
| 255 break; | |
| 256 case blink::WebAXEventBlur: | |
| 257 event_name = "Blur"; | |
| 258 break; | |
| 259 case blink::WebAXEventCheckedStateChanged: | |
| 260 event_name = "CheckedStateChanged"; | |
| 261 break; | |
| 262 case blink::WebAXEventChildrenChanged: | |
| 263 event_name = "ChildrenChanged"; | |
| 264 break; | |
| 265 case blink::WebAXEventClicked: | |
| 266 event_name = "Clicked"; | |
| 267 break; | |
| 268 case blink::WebAXEventDocumentSelectionChanged: | |
| 269 event_name = "DocumentSelectionChanged"; | |
| 270 break; | |
| 271 case blink::WebAXEventFocus: | |
| 272 event_name = "Focus"; | |
| 273 break; | |
| 274 case blink::WebAXEventHide: | |
| 275 event_name = "Hide"; | |
| 276 break; | |
| 277 case blink::WebAXEventHover: | |
| 278 event_name = "Hover"; | |
| 279 break; | |
| 280 case blink::WebAXEventInvalidStatusChanged: | |
| 281 event_name = "InvalidStatusChanged"; | |
| 282 break; | |
| 283 case blink::WebAXEventLayoutComplete: | |
| 284 event_name = "LayoutComplete"; | |
| 285 break; | |
| 286 case blink::WebAXEventLiveRegionChanged: | |
| 287 event_name = "LiveRegionChanged"; | |
| 288 break; | |
| 289 case blink::WebAXEventLoadComplete: | |
| 290 event_name = "LoadComplete"; | |
| 291 break; | |
| 292 case blink::WebAXEventLocationChanged: | |
| 293 event_name = "LocationChanged"; | |
| 294 break; | |
| 295 case blink::WebAXEventMenuListItemSelected: | |
| 296 event_name = "MenuListItemSelected"; | |
| 297 break; | |
| 298 case blink::WebAXEventMenuListItemUnselected: | |
| 299 event_name = "MenuListItemUnselected"; | |
| 300 break; | |
| 301 case blink::WebAXEventMenuListValueChanged: | |
| 302 event_name = "MenuListValueChanged"; | |
| 303 break; | |
| 304 case blink::WebAXEventRowCollapsed: | |
| 305 event_name = "RowCollapsed"; | |
| 306 break; | |
| 307 case blink::WebAXEventRowCountChanged: | |
| 308 event_name = "RowCountChanged"; | |
| 309 break; | |
| 310 case blink::WebAXEventRowExpanded: | |
| 311 event_name = "RowExpanded"; | |
| 312 break; | |
| 313 case blink::WebAXEventScrollPositionChanged: | |
| 314 event_name = "ScrollPositionChanged"; | |
| 315 break; | |
| 316 case blink::WebAXEventScrolledToAnchor: | |
| 317 event_name = "ScrolledToAnchor"; | |
| 318 break; | |
| 319 case blink::WebAXEventSelectedChildrenChanged: | |
| 320 event_name = "SelectedChildrenChanged"; | |
| 321 break; | |
| 322 case blink::WebAXEventSelectedTextChanged: | |
| 323 event_name = "SelectedTextChanged"; | |
| 324 break; | |
| 325 case blink::WebAXEventShow: | |
| 326 event_name = "Show"; | |
| 327 break; | |
| 328 case blink::WebAXEventTextChanged: | |
| 329 event_name = "TextChanged"; | |
| 330 break; | |
| 331 case blink::WebAXEventTextInserted: | |
| 332 event_name = "TextInserted"; | |
| 333 break; | |
| 334 case blink::WebAXEventTextRemoved: | |
| 335 event_name = "TextRemoved"; | |
| 336 break; | |
| 337 case blink::WebAXEventValueChanged: | |
| 338 event_name = "ValueChanged"; | |
| 339 break; | |
| 340 default: | |
| 341 event_name = "Unknown"; | |
| 342 break; | |
| 343 } | |
| 344 | |
| 345 AccessibilityController* accessibility_controller = | |
| 346 web_view_test_proxy_base_->accessibility_controller(); | |
| 347 accessibility_controller->NotificationReceived(obj, event_name); | |
| 348 if (accessibility_controller->ShouldLogAccessibilityEvents()) { | |
| 349 std::string message("AccessibilityNotification - "); | |
| 350 message += event_name; | |
| 351 | |
| 352 blink::WebNode node = obj.node(); | |
| 353 if (!node.isNull() && node.isElementNode()) { | |
| 354 blink::WebElement element = node.to<blink::WebElement>(); | |
| 355 if (element.hasAttribute("id")) { | |
| 356 message += " - id:"; | |
| 357 message += element.getAttribute("id").utf8().data(); | |
| 358 } | |
| 359 } | |
| 360 | |
| 361 delegate_->PrintMessage(message + "\n"); | |
| 362 } | |
| 363 } | |
| 364 | |
| 365 void WebFrameTestClient::didChangeSelection(bool is_empty_callback) { | |
| 366 if (test_runner()->shouldDumpEditingCallbacks()) | |
| 367 delegate_->PrintMessage( | |
| 368 "EDITING DELEGATE: " | |
| 369 "webViewDidChangeSelection:WebViewDidChangeSelectionNotification\n"); | |
| 370 } | |
| 371 | |
| 372 blink::WebPlugin* WebFrameTestClient::createPlugin( | |
| 373 blink::WebLocalFrame* frame, | |
| 374 const blink::WebPluginParams& params) { | |
| 375 if (TestPlugin::IsSupportedMimeType(params.mimeType)) | |
| 376 return TestPlugin::create(frame, params, delegate_); | |
| 377 return delegate_->CreatePluginPlaceholder(frame, params); | |
| 378 } | |
| 379 | |
| 380 void WebFrameTestClient::showContextMenu( | |
| 381 const blink::WebContextMenuData& context_menu_data) { | |
| 382 delegate_->GetWebWidgetTestProxyBase(web_frame_test_proxy_base_->web_frame()) | |
| 383 ->event_sender() | |
| 384 ->SetContextMenuData(context_menu_data); | |
| 385 } | |
| 386 | |
| 387 blink::WebUserMediaClient* WebFrameTestClient::userMediaClient() { | |
| 388 return test_runner()->getMockWebUserMediaClient(); | |
| 389 } | |
| 390 | |
| 391 void WebFrameTestClient::loadURLExternally( | |
| 392 const blink::WebURLRequest& request, | |
| 393 blink::WebNavigationPolicy policy, | |
| 394 const blink::WebString& suggested_name, | |
| 395 bool replaces_current_history_item) { | |
| 396 if (test_runner()->shouldWaitUntilExternalURLLoad()) { | |
| 397 if (policy == blink::WebNavigationPolicyDownload) { | |
| 398 delegate_->PrintMessage( | |
| 399 std::string("Downloading URL with suggested filename \"") + | |
| 400 suggested_name.utf8() + "\"\n"); | |
| 401 } else { | |
| 402 delegate_->PrintMessage(std::string("Loading URL externally - \"") + | |
| 403 URLDescription(request.url()) + "\"\n"); | |
| 404 } | |
| 405 delegate_->TestFinished(); | |
| 406 } | |
| 407 } | |
| 408 | |
| 409 void WebFrameTestClient::loadErrorPage(int reason) { | |
| 410 if (test_runner()->shouldDumpFrameLoadCallbacks()) { | |
| 411 delegate_->PrintMessage(base::StringPrintf( | |
| 412 "- loadErrorPage: %s\n", net::ErrorToString(reason).c_str())); | |
| 413 } | |
| 414 } | |
| 415 | |
| 416 void WebFrameTestClient::didStartProvisionalLoad( | |
| 417 blink::WebDataSource* data_source) { | |
| 418 // PlzNavigate | |
| 419 // A provisional load notification is received when a frame navigation is | |
| 420 // sent to the browser. We don't want to log it again during commit. | |
| 421 if (delegate_->IsNavigationInitiatedByRenderer(data_source->getRequest())) | |
| 422 return; | |
| 423 | |
| 424 test_runner()->tryToSetTopLoadingFrame( | |
| 425 web_frame_test_proxy_base_->web_frame()); | |
| 426 | |
| 427 if (test_runner()->shouldDumpFrameLoadCallbacks()) { | |
| 428 PrintFrameDescription(delegate_, web_frame_test_proxy_base_->web_frame()); | |
| 429 delegate_->PrintMessage(" - didStartProvisionalLoadForFrame\n"); | |
| 430 } | |
| 431 | |
| 432 if (test_runner()->shouldDumpUserGestureInFrameLoadCallbacks()) { | |
| 433 PrintFrameuserGestureStatus(delegate_, | |
| 434 web_frame_test_proxy_base_->web_frame(), | |
| 435 " - in didStartProvisionalLoadForFrame\n"); | |
| 436 } | |
| 437 } | |
| 438 | |
| 439 void WebFrameTestClient::didReceiveServerRedirectForProvisionalLoad( | |
| 440 blink::WebLocalFrame* frame) { | |
| 441 if (test_runner()->shouldDumpFrameLoadCallbacks()) { | |
| 442 PrintFrameDescription(delegate_, frame); | |
| 443 delegate_->PrintMessage( | |
| 444 " - didReceiveServerRedirectForProvisionalLoadForFrame\n"); | |
| 445 } | |
| 446 } | |
| 447 | |
| 448 void WebFrameTestClient::didFailProvisionalLoad( | |
| 449 blink::WebLocalFrame* frame, | |
| 450 const blink::WebURLError& error, | |
| 451 blink::WebHistoryCommitType commit_type) { | |
| 452 if (test_runner()->shouldDumpFrameLoadCallbacks()) { | |
| 453 PrintFrameDescription(delegate_, frame); | |
| 454 delegate_->PrintMessage(" - didFailProvisionalLoadWithError\n"); | |
| 455 } | |
| 456 } | |
| 457 | |
| 458 void WebFrameTestClient::didCommitProvisionalLoad( | |
| 459 blink::WebLocalFrame* frame, | |
| 460 const blink::WebHistoryItem& history_item, | |
| 461 blink::WebHistoryCommitType history_type) { | |
| 462 if (test_runner()->shouldDumpFrameLoadCallbacks()) { | |
| 463 PrintFrameDescription(delegate_, frame); | |
| 464 delegate_->PrintMessage(" - didCommitLoadForFrame\n"); | |
| 465 } | |
| 466 } | |
| 467 | |
| 468 void WebFrameTestClient::didReceiveTitle(blink::WebLocalFrame* frame, | |
| 469 const blink::WebString& title, | |
| 470 blink::WebTextDirection direction) { | |
| 471 if (test_runner()->shouldDumpFrameLoadCallbacks()) { | |
| 472 PrintFrameDescription(delegate_, frame); | |
| 473 delegate_->PrintMessage(std::string(" - didReceiveTitle: ") + title.utf8() + | |
| 474 "\n"); | |
| 475 } | |
| 476 | |
| 477 if (test_runner()->shouldDumpTitleChanges()) | |
| 478 delegate_->PrintMessage(std::string("TITLE CHANGED: '") + title.utf8() + | |
| 479 "'\n"); | |
| 480 } | |
| 481 | |
| 482 void WebFrameTestClient::didChangeIcon(blink::WebLocalFrame* frame, | |
| 483 blink::WebIconURL::Type icon_type) { | |
| 484 if (test_runner()->shouldDumpIconChanges()) { | |
| 485 PrintFrameDescription(delegate_, frame); | |
| 486 delegate_->PrintMessage(std::string(" - didChangeIcons\n")); | |
| 487 } | |
| 488 } | |
| 489 | |
| 490 void WebFrameTestClient::didFinishDocumentLoad(blink::WebLocalFrame* frame) { | |
| 491 if (test_runner()->shouldDumpFrameLoadCallbacks()) { | |
| 492 PrintFrameDescription(delegate_, frame); | |
| 493 delegate_->PrintMessage(" - didFinishDocumentLoadForFrame\n"); | |
| 494 } | |
| 495 } | |
| 496 | |
| 497 void WebFrameTestClient::didHandleOnloadEvents(blink::WebLocalFrame* frame) { | |
| 498 if (test_runner()->shouldDumpFrameLoadCallbacks()) { | |
| 499 PrintFrameDescription(delegate_, frame); | |
| 500 delegate_->PrintMessage(" - didHandleOnloadEventsForFrame\n"); | |
| 501 } | |
| 502 } | |
| 503 | |
| 504 void WebFrameTestClient::didFailLoad(blink::WebLocalFrame* frame, | |
| 505 const blink::WebURLError& error, | |
| 506 blink::WebHistoryCommitType commit_type) { | |
| 507 if (test_runner()->shouldDumpFrameLoadCallbacks()) { | |
| 508 PrintFrameDescription(delegate_, frame); | |
| 509 delegate_->PrintMessage(" - didFailLoadWithError\n"); | |
| 510 } | |
| 511 } | |
| 512 | |
| 513 void WebFrameTestClient::didFinishLoad(blink::WebLocalFrame* frame) { | |
| 514 if (test_runner()->shouldDumpFrameLoadCallbacks()) { | |
| 515 PrintFrameDescription(delegate_, frame); | |
| 516 delegate_->PrintMessage(" - didFinishLoadForFrame\n"); | |
| 517 } | |
| 518 } | |
| 519 | |
| 520 void WebFrameTestClient::didNavigateWithinPage( | |
| 521 blink::WebLocalFrame* frame, | |
| 522 const blink::WebHistoryItem& history_item, | |
| 523 blink::WebHistoryCommitType commit_type, | |
| 524 bool contentInitiated) { | |
| 525 test_runner()->OnNavigationEnd(); | |
| 526 } | |
| 527 | |
| 528 void WebFrameTestClient::didStartLoading(bool to_different_document) { | |
| 529 test_runner()->OnNavigationBegin(web_frame_test_proxy_base_->web_frame()); | |
| 530 } | |
| 531 | |
| 532 void WebFrameTestClient::didStopLoading() { | |
| 533 test_runner()->tryToClearTopLoadingFrame( | |
| 534 web_frame_test_proxy_base_->web_frame()); | |
| 535 } | |
| 536 | |
| 537 void WebFrameTestClient::didDetectXSS(const blink::WebURL& insecure_url, | |
| 538 bool did_block_entire_page) { | |
| 539 if (test_runner()->shouldDumpFrameLoadCallbacks()) | |
| 540 delegate_->PrintMessage("didDetectXSS\n"); | |
| 541 } | |
| 542 | |
| 543 void WebFrameTestClient::didDispatchPingLoader(const blink::WebURL& url) { | |
| 544 if (test_runner()->shouldDumpPingLoaderCallbacks()) | |
| 545 delegate_->PrintMessage(std::string("PingLoader dispatched to '") + | |
| 546 URLDescription(url).c_str() + "'.\n"); | |
| 547 } | |
| 548 | |
| 549 void WebFrameTestClient::willSendRequest(blink::WebLocalFrame* frame, | |
| 550 blink::WebURLRequest& request) { | |
| 551 // PlzNavigate | |
| 552 // Navigation requests initiated by the renderer will have been logged when | |
| 553 // the navigation was sent to the browser. Please see | |
| 554 // the RenderFrameImpl::BeginNavigation() function. | |
| 555 if (delegate_->IsNavigationInitiatedByRenderer(request)) | |
| 556 return; | |
| 557 // Need to use GURL for host() and SchemeIs() | |
| 558 GURL url = request.url(); | |
| 559 std::string request_url = url.possibly_invalid_spec(); | |
| 560 | |
| 561 GURL main_document_url = request.firstPartyForCookies(); | |
| 562 | |
| 563 if (test_runner()->shouldDumpResourceLoadCallbacks()) { | |
| 564 delegate_->PrintMessage(DescriptionSuitableForTestResult(request_url)); | |
| 565 delegate_->PrintMessage(" - willSendRequest <NSURLRequest URL "); | |
| 566 delegate_->PrintMessage( | |
| 567 DescriptionSuitableForTestResult(request_url).c_str()); | |
| 568 delegate_->PrintMessage(", main document URL "); | |
| 569 delegate_->PrintMessage(URLDescription(main_document_url).c_str()); | |
| 570 delegate_->PrintMessage(", http method "); | |
| 571 delegate_->PrintMessage(request.httpMethod().utf8().data()); | |
| 572 delegate_->PrintMessage(">\n"); | |
| 573 } | |
| 574 | |
| 575 if (test_runner()->httpHeadersToClear()) { | |
| 576 const std::set<std::string>* clearHeaders = | |
| 577 test_runner()->httpHeadersToClear(); | |
| 578 for (std::set<std::string>::const_iterator header = clearHeaders->begin(); | |
| 579 header != clearHeaders->end(); ++header) | |
| 580 request.clearHTTPHeaderField(blink::WebString::fromUTF8(*header)); | |
| 581 } | |
| 582 | |
| 583 std::string host = url.host(); | |
| 584 if (!host.empty() && | |
| 585 (url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme))) { | |
| 586 if (!IsLocalHost(host) && !IsTestHost(host) && | |
| 587 !HostIsUsedBySomeTestsToGenerateError(host) && | |
| 588 ((!main_document_url.SchemeIs(url::kHttpScheme) && | |
| 589 !main_document_url.SchemeIs(url::kHttpsScheme)) || | |
| 590 IsLocalHost(main_document_url.host())) && | |
| 591 !delegate_->AllowExternalPages()) { | |
| 592 delegate_->PrintMessage(std::string("Blocked access to external URL ") + | |
| 593 request_url + "\n"); | |
| 594 BlockRequest(request); | |
| 595 return; | |
| 596 } | |
| 597 } | |
| 598 | |
| 599 // Set the new substituted URL. | |
| 600 request.setURL(delegate_->RewriteLayoutTestsURL( | |
| 601 request.url().string().utf8(), | |
| 602 test_runner()->is_web_platform_tests_mode())); | |
| 603 } | |
| 604 | |
| 605 void WebFrameTestClient::didReceiveResponse( | |
| 606 const blink::WebURLResponse& response) { | |
| 607 if (test_runner()->shouldDumpResourceLoadCallbacks()) { | |
| 608 delegate_->PrintMessage(DescriptionSuitableForTestResult( | |
| 609 GURL(response.url()).possibly_invalid_spec())); | |
| 610 delegate_->PrintMessage(" - didReceiveResponse "); | |
| 611 PrintResponseDescription(delegate_, response); | |
| 612 delegate_->PrintMessage("\n"); | |
| 613 } | |
| 614 if (test_runner()->shouldDumpResourceResponseMIMETypes()) { | |
| 615 GURL url = response.url(); | |
| 616 blink::WebString mime_type = response.mimeType(); | |
| 617 delegate_->PrintMessage(url.ExtractFileName()); | |
| 618 delegate_->PrintMessage(" has MIME type "); | |
| 619 // Simulate NSURLResponse's mapping of empty/unknown MIME types to | |
| 620 // application/octet-stream | |
| 621 delegate_->PrintMessage(mime_type.isEmpty() ? "application/octet-stream" | |
| 622 : mime_type.utf8().data()); | |
| 623 delegate_->PrintMessage("\n"); | |
| 624 } | |
| 625 } | |
| 626 | |
| 627 void WebFrameTestClient::didAddMessageToConsole( | |
| 628 const blink::WebConsoleMessage& message, | |
| 629 const blink::WebString& source_name, | |
| 630 unsigned source_line, | |
| 631 const blink::WebString& stack_trace) { | |
| 632 if (!test_runner()->ShouldDumpConsoleMessages()) | |
| 633 return; | |
| 634 std::string level; | |
| 635 switch (message.level) { | |
| 636 case blink::WebConsoleMessage::LevelVerbose: | |
| 637 level = "DEBUG"; | |
| 638 break; | |
| 639 case blink::WebConsoleMessage::LevelInfo: | |
| 640 level = "MESSAGE"; | |
| 641 break; | |
| 642 case blink::WebConsoleMessage::LevelWarning: | |
| 643 level = "WARNING"; | |
| 644 break; | |
| 645 case blink::WebConsoleMessage::LevelError: | |
| 646 level = "ERROR"; | |
| 647 break; | |
| 648 default: | |
| 649 level = "MESSAGE"; | |
| 650 } | |
| 651 delegate_->PrintMessage(std::string("CONSOLE ") + level + ": "); | |
| 652 if (source_line) { | |
| 653 delegate_->PrintMessage(base::StringPrintf("line %d: ", source_line)); | |
| 654 } | |
| 655 if (!message.text.isEmpty()) { | |
| 656 std::string new_message; | |
| 657 new_message = message.text.utf8(); | |
| 658 size_t file_protocol = new_message.find("file://"); | |
| 659 if (file_protocol != std::string::npos) { | |
| 660 new_message = new_message.substr(0, file_protocol) + | |
| 661 URLSuitableForTestResult(new_message.substr(file_protocol)); | |
| 662 } | |
| 663 delegate_->PrintMessage(new_message); | |
| 664 } | |
| 665 delegate_->PrintMessage(std::string("\n")); | |
| 666 } | |
| 667 | |
| 668 blink::WebNavigationPolicy WebFrameTestClient::decidePolicyForNavigation( | |
| 669 const blink::WebFrameClient::NavigationPolicyInfo& info) { | |
| 670 // PlzNavigate | |
| 671 // Navigation requests initiated by the renderer have checked navigation | |
| 672 // policy when the navigation was sent to the browser. Some layout tests | |
| 673 // expect that navigation policy is only checked once. | |
| 674 if (delegate_->IsNavigationInitiatedByRenderer(info.urlRequest)) | |
| 675 return info.defaultPolicy; | |
| 676 | |
| 677 if (test_runner()->shouldDumpNavigationPolicy()) { | |
| 678 delegate_->PrintMessage("Default policy for navigation to '" + | |
| 679 URLDescription(info.urlRequest.url()) + "' is '" + | |
| 680 WebNavigationPolicyToString(info.defaultPolicy) + | |
| 681 "'\n"); | |
| 682 } | |
| 683 | |
| 684 blink::WebNavigationPolicy result; | |
| 685 if (!test_runner()->policyDelegateEnabled()) | |
| 686 return info.defaultPolicy; | |
| 687 | |
| 688 delegate_->PrintMessage( | |
| 689 std::string("Policy delegate: attempt to load ") + | |
| 690 URLDescription(info.urlRequest.url()) + " with navigation type '" + | |
| 691 WebNavigationTypeToString(info.navigationType) + "'\n"); | |
| 692 if (test_runner()->policyDelegateIsPermissive()) | |
| 693 result = blink::WebNavigationPolicyCurrentTab; | |
| 694 else | |
| 695 result = blink::WebNavigationPolicyIgnore; | |
| 696 | |
| 697 if (test_runner()->policyDelegateShouldNotifyDone()) { | |
| 698 test_runner()->policyDelegateDone(); | |
| 699 result = blink::WebNavigationPolicyIgnore; | |
| 700 } | |
| 701 | |
| 702 return result; | |
| 703 } | |
| 704 | |
| 705 void WebFrameTestClient::checkIfAudioSinkExistsAndIsAuthorized( | |
| 706 const blink::WebString& sink_id, | |
| 707 const blink::WebSecurityOrigin& security_origin, | |
| 708 blink::WebSetSinkIdCallbacks* web_callbacks) { | |
| 709 std::unique_ptr<blink::WebSetSinkIdCallbacks> callback(web_callbacks); | |
| 710 std::string device_id = sink_id.utf8(); | |
| 711 if (device_id == "valid" || device_id.empty()) | |
| 712 callback->onSuccess(); | |
| 713 else if (device_id == "unauthorized") | |
| 714 callback->onError(blink::WebSetSinkIdError::NotAuthorized); | |
| 715 else | |
| 716 callback->onError(blink::WebSetSinkIdError::NotFound); | |
| 717 } | |
| 718 | |
| 719 void WebFrameTestClient::didClearWindowObject(blink::WebLocalFrame* frame) { | |
| 720 web_view_test_proxy_base_->test_interfaces()->BindTo(frame); | |
| 721 web_view_test_proxy_base_->BindTo(frame); | |
| 722 delegate_->GetWebWidgetTestProxyBase(frame)->BindTo(frame); | |
| 723 } | |
| 724 | |
| 725 bool WebFrameTestClient::runFileChooser( | |
| 726 const blink::WebFileChooserParams& params, | |
| 727 blink::WebFileChooserCompletion* completion) { | |
| 728 delegate_->PrintMessage("Mock: Opening a file chooser.\n"); | |
| 729 // FIXME: Add ability to set file names to a file upload control. | |
| 730 return false; | |
| 731 } | |
| 732 | |
| 733 blink::WebEffectiveConnectionType | |
| 734 WebFrameTestClient::getEffectiveConnectionType() { | |
| 735 return test_runner()->effective_connection_type(); | |
| 736 } | |
| 737 | |
| 738 TestRunner* WebFrameTestClient::test_runner() { | |
| 739 return web_view_test_proxy_base_->test_interfaces()->GetTestRunner(); | |
| 740 } | |
| 741 | |
| 742 } // namespace test_runner | |
| OLD | NEW |