| 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 "components/test_runner/web_frame_test_client.h" | 5 #include "components/test_runner/web_frame_test_client.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 if (response.isNull()) { | 89 if (response.isNull()) { |
| 90 delegate->PrintMessage("(null)"); | 90 delegate->PrintMessage("(null)"); |
| 91 return; | 91 return; |
| 92 } | 92 } |
| 93 delegate->PrintMessage(base::StringPrintf( | 93 delegate->PrintMessage(base::StringPrintf( |
| 94 "<NSURLResponse %s, http status code %d>", | 94 "<NSURLResponse %s, http status code %d>", |
| 95 DescriptionSuitableForTestResult(response.url().string().utf8()).c_str(), | 95 DescriptionSuitableForTestResult(response.url().string().utf8()).c_str(), |
| 96 response.httpStatusCode())); | 96 response.httpStatusCode())); |
| 97 } | 97 } |
| 98 | 98 |
| 99 std::string PriorityDescription( | |
| 100 const blink::WebURLRequest::Priority& priority) { | |
| 101 switch (priority) { | |
| 102 case blink::WebURLRequest::PriorityVeryLow: | |
| 103 return "VeryLow"; | |
| 104 case blink::WebURLRequest::PriorityLow: | |
| 105 return "Low"; | |
| 106 case blink::WebURLRequest::PriorityMedium: | |
| 107 return "Medium"; | |
| 108 case blink::WebURLRequest::PriorityHigh: | |
| 109 return "High"; | |
| 110 case blink::WebURLRequest::PriorityVeryHigh: | |
| 111 return "VeryHigh"; | |
| 112 case blink::WebURLRequest::PriorityUnresolved: | |
| 113 default: | |
| 114 return "Unresolved"; | |
| 115 } | |
| 116 } | |
| 117 | |
| 118 void BlockRequest(blink::WebURLRequest& request) { | 99 void BlockRequest(blink::WebURLRequest& request) { |
| 119 request.setURL(GURL("255.255.255.255")); | 100 request.setURL(GURL("255.255.255.255")); |
| 120 } | 101 } |
| 121 | 102 |
| 122 bool IsLocalHost(const std::string& host) { | 103 bool IsLocalHost(const std::string& host) { |
| 123 return host == "127.0.0.1" || host == "localhost" || host == "[::1]"; | 104 return host == "127.0.0.1" || host == "localhost" || host == "[::1]"; |
| 124 } | 105 } |
| 125 | 106 |
| 126 bool IsTestHost(const std::string& host) { | 107 bool IsTestHost(const std::string& host) { |
| 127 return base::EndsWith(host, ".test", base::CompareCase::INSENSITIVE_ASCII); | 108 return base::EndsWith(host, ".test", base::CompareCase::INSENSITIVE_ASCII); |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 if (test_runner_->shouldDumpFrameLoadCallbacks()) | 515 if (test_runner_->shouldDumpFrameLoadCallbacks()) |
| 535 delegate_->PrintMessage("didDetectXSS\n"); | 516 delegate_->PrintMessage("didDetectXSS\n"); |
| 536 } | 517 } |
| 537 | 518 |
| 538 void WebFrameTestClient::didDispatchPingLoader(const blink::WebURL& url) { | 519 void WebFrameTestClient::didDispatchPingLoader(const blink::WebURL& url) { |
| 539 if (test_runner_->shouldDumpPingLoaderCallbacks()) | 520 if (test_runner_->shouldDumpPingLoaderCallbacks()) |
| 540 delegate_->PrintMessage(std::string("PingLoader dispatched to '") + | 521 delegate_->PrintMessage(std::string("PingLoader dispatched to '") + |
| 541 URLDescription(url).c_str() + "'.\n"); | 522 URLDescription(url).c_str() + "'.\n"); |
| 542 } | 523 } |
| 543 | 524 |
| 544 void WebFrameTestClient::willSendRequest( | 525 void WebFrameTestClient::willSendRequest(blink::WebLocalFrame* frame, |
| 545 blink::WebLocalFrame* frame, | 526 blink::WebURLRequest& request) { |
| 546 unsigned identifier, | |
| 547 blink::WebURLRequest& request, | |
| 548 const blink::WebURLResponse& redirect_response) { | |
| 549 // Need to use GURL for host() and SchemeIs() | 527 // Need to use GURL for host() and SchemeIs() |
| 550 GURL url = request.url(); | 528 GURL url = request.url(); |
| 551 std::string request_url = url.possibly_invalid_spec(); | 529 std::string request_url = url.possibly_invalid_spec(); |
| 552 | 530 |
| 553 GURL main_document_url = request.firstPartyForCookies(); | 531 GURL main_document_url = request.firstPartyForCookies(); |
| 554 | 532 |
| 555 if (redirect_response.isNull() && | |
| 556 (test_runner_->shouldDumpResourceLoadCallbacks() || | |
| 557 test_runner_->shouldDumpResourcePriorities())) { | |
| 558 DCHECK(resource_identifier_map_.find(identifier) == | |
| 559 resource_identifier_map_.end()); | |
| 560 resource_identifier_map_[identifier] = | |
| 561 DescriptionSuitableForTestResult(request_url); | |
| 562 } | |
| 563 | |
| 564 if (test_runner_->shouldDumpResourceLoadCallbacks()) { | 533 if (test_runner_->shouldDumpResourceLoadCallbacks()) { |
| 565 if (resource_identifier_map_.find(identifier) == | 534 delegate_->PrintMessage(DescriptionSuitableForTestResult(request_url)); |
| 566 resource_identifier_map_.end()) | |
| 567 delegate_->PrintMessage("<unknown>"); | |
| 568 else | |
| 569 delegate_->PrintMessage(resource_identifier_map_[identifier]); | |
| 570 delegate_->PrintMessage(" - willSendRequest <NSURLRequest URL "); | 535 delegate_->PrintMessage(" - willSendRequest <NSURLRequest URL "); |
| 571 delegate_->PrintMessage( | 536 delegate_->PrintMessage( |
| 572 DescriptionSuitableForTestResult(request_url).c_str()); | 537 DescriptionSuitableForTestResult(request_url).c_str()); |
| 573 delegate_->PrintMessage(", main document URL "); | 538 delegate_->PrintMessage(", main document URL "); |
| 574 delegate_->PrintMessage(URLDescription(main_document_url).c_str()); | 539 delegate_->PrintMessage(URLDescription(main_document_url).c_str()); |
| 575 delegate_->PrintMessage(", http method "); | 540 delegate_->PrintMessage(", http method "); |
| 576 delegate_->PrintMessage(request.httpMethod().utf8().data()); | 541 delegate_->PrintMessage(request.httpMethod().utf8().data()); |
| 577 delegate_->PrintMessage("> redirectResponse "); | 542 delegate_->PrintMessage(">\n"); |
| 578 PrintResponseDescription(delegate_, redirect_response); | |
| 579 delegate_->PrintMessage("\n"); | |
| 580 } | |
| 581 | |
| 582 if (test_runner_->shouldDumpResourcePriorities()) { | |
| 583 delegate_->PrintMessage( | |
| 584 DescriptionSuitableForTestResult(request_url).c_str()); | |
| 585 delegate_->PrintMessage(" has priority "); | |
| 586 delegate_->PrintMessage(PriorityDescription(request.getPriority())); | |
| 587 delegate_->PrintMessage("\n"); | |
| 588 } | 543 } |
| 589 | 544 |
| 590 if (test_runner_->httpHeadersToClear()) { | 545 if (test_runner_->httpHeadersToClear()) { |
| 591 const std::set<std::string>* clearHeaders = | 546 const std::set<std::string>* clearHeaders = |
| 592 test_runner_->httpHeadersToClear(); | 547 test_runner_->httpHeadersToClear(); |
| 593 for (std::set<std::string>::const_iterator header = clearHeaders->begin(); | 548 for (std::set<std::string>::const_iterator header = clearHeaders->begin(); |
| 594 header != clearHeaders->end(); ++header) | 549 header != clearHeaders->end(); ++header) |
| 595 request.clearHTTPHeaderField(blink::WebString::fromUTF8(*header)); | 550 request.clearHTTPHeaderField(blink::WebString::fromUTF8(*header)); |
| 596 } | 551 } |
| 597 | 552 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 611 } | 566 } |
| 612 } | 567 } |
| 613 | 568 |
| 614 // Set the new substituted URL. | 569 // Set the new substituted URL. |
| 615 request.setURL(delegate_->RewriteLayoutTestsURL( | 570 request.setURL(delegate_->RewriteLayoutTestsURL( |
| 616 request.url().string().utf8(), | 571 request.url().string().utf8(), |
| 617 test_runner_->is_web_platform_tests_mode())); | 572 test_runner_->is_web_platform_tests_mode())); |
| 618 } | 573 } |
| 619 | 574 |
| 620 void WebFrameTestClient::didReceiveResponse( | 575 void WebFrameTestClient::didReceiveResponse( |
| 621 unsigned identifier, | |
| 622 const blink::WebURLResponse& response) { | 576 const blink::WebURLResponse& response) { |
| 623 if (test_runner_->shouldDumpResourceLoadCallbacks()) { | 577 if (test_runner_->shouldDumpResourceLoadCallbacks()) { |
| 624 if (resource_identifier_map_.find(identifier) == | 578 delegate_->PrintMessage(DescriptionSuitableForTestResult( |
| 625 resource_identifier_map_.end()) | 579 GURL(response.url()).possibly_invalid_spec())); |
| 626 delegate_->PrintMessage("<unknown>"); | |
| 627 else | |
| 628 delegate_->PrintMessage(resource_identifier_map_[identifier]); | |
| 629 delegate_->PrintMessage(" - didReceiveResponse "); | 580 delegate_->PrintMessage(" - didReceiveResponse "); |
| 630 PrintResponseDescription(delegate_, response); | 581 PrintResponseDescription(delegate_, response); |
| 631 delegate_->PrintMessage("\n"); | 582 delegate_->PrintMessage("\n"); |
| 632 } | 583 } |
| 633 if (test_runner_->shouldDumpResourceResponseMIMETypes()) { | 584 if (test_runner_->shouldDumpResourceResponseMIMETypes()) { |
| 634 GURL url = response.url(); | 585 GURL url = response.url(); |
| 635 blink::WebString mime_type = response.mimeType(); | 586 blink::WebString mime_type = response.mimeType(); |
| 636 delegate_->PrintMessage(url.ExtractFileName()); | 587 delegate_->PrintMessage(url.ExtractFileName()); |
| 637 delegate_->PrintMessage(" has MIME type "); | 588 delegate_->PrintMessage(" has MIME type "); |
| 638 // Simulate NSURLResponse's mapping of empty/unknown MIME types to | 589 // Simulate NSURLResponse's mapping of empty/unknown MIME types to |
| 639 // application/octet-stream | 590 // application/octet-stream |
| 640 delegate_->PrintMessage(mime_type.isEmpty() ? "application/octet-stream" | 591 delegate_->PrintMessage(mime_type.isEmpty() ? "application/octet-stream" |
| 641 : mime_type.utf8().data()); | 592 : mime_type.utf8().data()); |
| 642 delegate_->PrintMessage("\n"); | 593 delegate_->PrintMessage("\n"); |
| 643 } | 594 } |
| 644 } | 595 } |
| 645 | 596 |
| 646 void WebFrameTestClient::didChangeResourcePriority( | |
| 647 unsigned identifier, | |
| 648 const blink::WebURLRequest::Priority& priority, | |
| 649 int intra_priority_value) { | |
| 650 if (test_runner_->shouldDumpResourcePriorities()) { | |
| 651 if (resource_identifier_map_.find(identifier) == | |
| 652 resource_identifier_map_.end()) | |
| 653 delegate_->PrintMessage("<unknown>"); | |
| 654 else | |
| 655 delegate_->PrintMessage(resource_identifier_map_[identifier]); | |
| 656 delegate_->PrintMessage(base::StringPrintf( | |
| 657 " changed priority to %s, intra_priority %d\n", | |
| 658 PriorityDescription(priority).c_str(), intra_priority_value)); | |
| 659 } | |
| 660 } | |
| 661 | |
| 662 void WebFrameTestClient::didFinishResourceLoad(blink::WebLocalFrame* frame, | |
| 663 unsigned identifier) { | |
| 664 if (test_runner_->shouldDumpResourceLoadCallbacks()) { | |
| 665 if (resource_identifier_map_.find(identifier) == | |
| 666 resource_identifier_map_.end()) | |
| 667 delegate_->PrintMessage("<unknown>"); | |
| 668 else | |
| 669 delegate_->PrintMessage(resource_identifier_map_[identifier]); | |
| 670 delegate_->PrintMessage(" - didFinishLoading\n"); | |
| 671 } | |
| 672 resource_identifier_map_.erase(identifier); | |
| 673 } | |
| 674 | |
| 675 void WebFrameTestClient::didAddMessageToConsole( | 597 void WebFrameTestClient::didAddMessageToConsole( |
| 676 const blink::WebConsoleMessage& message, | 598 const blink::WebConsoleMessage& message, |
| 677 const blink::WebString& source_name, | 599 const blink::WebString& source_name, |
| 678 unsigned source_line, | 600 unsigned source_line, |
| 679 const blink::WebString& stack_trace) { | 601 const blink::WebString& stack_trace) { |
| 680 if (!test_runner_->ShouldDumpConsoleMessages()) | 602 if (!test_runner_->ShouldDumpConsoleMessages()) |
| 681 return; | 603 return; |
| 682 std::string level; | 604 std::string level; |
| 683 switch (message.level) { | 605 switch (message.level) { |
| 684 case blink::WebConsoleMessage::LevelDebug: | 606 case blink::WebConsoleMessage::LevelDebug: |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 | 689 |
| 768 bool WebFrameTestClient::runFileChooser( | 690 bool WebFrameTestClient::runFileChooser( |
| 769 const blink::WebFileChooserParams& params, | 691 const blink::WebFileChooserParams& params, |
| 770 blink::WebFileChooserCompletion* completion) { | 692 blink::WebFileChooserCompletion* completion) { |
| 771 delegate_->PrintMessage("Mock: Opening a file chooser.\n"); | 693 delegate_->PrintMessage("Mock: Opening a file chooser.\n"); |
| 772 // FIXME: Add ability to set file names to a file upload control. | 694 // FIXME: Add ability to set file names to a file upload control. |
| 773 return false; | 695 return false; |
| 774 } | 696 } |
| 775 | 697 |
| 776 } // namespace test_runner | 698 } // namespace test_runner |
| OLD | NEW |