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