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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 if (test_runner_->shouldDumpFrameLoadCallbacks()) | 503 if (test_runner_->shouldDumpFrameLoadCallbacks()) |
523 delegate_->PrintMessage("didDetectXSS\n"); | 504 delegate_->PrintMessage("didDetectXSS\n"); |
524 } | 505 } |
525 | 506 |
526 void WebFrameTestClient::didDispatchPingLoader(const blink::WebURL& url) { | 507 void WebFrameTestClient::didDispatchPingLoader(const blink::WebURL& url) { |
527 if (test_runner_->shouldDumpPingLoaderCallbacks()) | 508 if (test_runner_->shouldDumpPingLoaderCallbacks()) |
528 delegate_->PrintMessage(std::string("PingLoader dispatched to '") + | 509 delegate_->PrintMessage(std::string("PingLoader dispatched to '") + |
529 URLDescription(url).c_str() + "'.\n"); | 510 URLDescription(url).c_str() + "'.\n"); |
530 } | 511 } |
531 | 512 |
532 void WebFrameTestClient::willSendRequest( | 513 void WebFrameTestClient::willSendRequest(blink::WebLocalFrame* frame, |
533 blink::WebLocalFrame* frame, | 514 blink::WebURLRequest& request) { |
534 unsigned identifier, | |
535 blink::WebURLRequest& request, | |
536 const blink::WebURLResponse& redirect_response) { | |
537 // Need to use GURL for host() and SchemeIs() | 515 // Need to use GURL for host() and SchemeIs() |
538 GURL url = request.url(); | 516 GURL url = request.url(); |
539 std::string request_url = url.possibly_invalid_spec(); | 517 std::string request_url = url.possibly_invalid_spec(); |
540 | 518 |
541 GURL main_document_url = request.firstPartyForCookies(); | 519 GURL main_document_url = request.firstPartyForCookies(); |
542 | 520 |
543 if (redirect_response.isNull() && | |
544 (test_runner_->shouldDumpResourceLoadCallbacks() || | |
545 test_runner_->shouldDumpResourcePriorities())) { | |
546 DCHECK(resource_identifier_map_.find(identifier) == | |
547 resource_identifier_map_.end()); | |
548 resource_identifier_map_[identifier] = | |
549 DescriptionSuitableForTestResult(request_url); | |
550 } | |
551 | |
552 if (test_runner_->shouldDumpResourceLoadCallbacks()) { | 521 if (test_runner_->shouldDumpResourceLoadCallbacks()) { |
553 if (resource_identifier_map_.find(identifier) == | 522 delegate_->PrintMessage(DescriptionSuitableForTestResult(request_url)); |
554 resource_identifier_map_.end()) | |
555 delegate_->PrintMessage("<unknown>"); | |
556 else | |
557 delegate_->PrintMessage(resource_identifier_map_[identifier]); | |
558 delegate_->PrintMessage(" - willSendRequest <NSURLRequest URL "); | 523 delegate_->PrintMessage(" - willSendRequest <NSURLRequest URL "); |
559 delegate_->PrintMessage( | 524 delegate_->PrintMessage( |
560 DescriptionSuitableForTestResult(request_url).c_str()); | 525 DescriptionSuitableForTestResult(request_url).c_str()); |
561 delegate_->PrintMessage(", main document URL "); | 526 delegate_->PrintMessage(", main document URL "); |
562 delegate_->PrintMessage(URLDescription(main_document_url).c_str()); | 527 delegate_->PrintMessage(URLDescription(main_document_url).c_str()); |
563 delegate_->PrintMessage(", http method "); | 528 delegate_->PrintMessage(", http method "); |
564 delegate_->PrintMessage(request.httpMethod().utf8().data()); | 529 delegate_->PrintMessage(request.httpMethod().utf8().data()); |
565 delegate_->PrintMessage("> redirectResponse "); | 530 delegate_->PrintMessage(">\n"); |
566 PrintResponseDescription(delegate_, redirect_response); | |
567 delegate_->PrintMessage("\n"); | |
568 } | |
569 | |
570 if (test_runner_->shouldDumpResourcePriorities()) { | |
571 delegate_->PrintMessage( | |
572 DescriptionSuitableForTestResult(request_url).c_str()); | |
573 delegate_->PrintMessage(" has priority "); | |
574 delegate_->PrintMessage(PriorityDescription(request.getPriority())); | |
575 delegate_->PrintMessage("\n"); | |
576 } | 531 } |
577 | 532 |
578 if (test_runner_->httpHeadersToClear()) { | 533 if (test_runner_->httpHeadersToClear()) { |
579 const std::set<std::string>* clearHeaders = | 534 const std::set<std::string>* clearHeaders = |
580 test_runner_->httpHeadersToClear(); | 535 test_runner_->httpHeadersToClear(); |
581 for (std::set<std::string>::const_iterator header = clearHeaders->begin(); | 536 for (std::set<std::string>::const_iterator header = clearHeaders->begin(); |
582 header != clearHeaders->end(); ++header) | 537 header != clearHeaders->end(); ++header) |
583 request.clearHTTPHeaderField(blink::WebString::fromUTF8(*header)); | 538 request.clearHTTPHeaderField(blink::WebString::fromUTF8(*header)); |
584 } | 539 } |
585 | 540 |
(...skipping 13 matching lines...) Expand all Loading... |
599 } | 554 } |
600 } | 555 } |
601 | 556 |
602 // Set the new substituted URL. | 557 // Set the new substituted URL. |
603 request.setURL(delegate_->RewriteLayoutTestsURL( | 558 request.setURL(delegate_->RewriteLayoutTestsURL( |
604 request.url().string().utf8(), | 559 request.url().string().utf8(), |
605 test_runner_->is_web_platform_tests_mode())); | 560 test_runner_->is_web_platform_tests_mode())); |
606 } | 561 } |
607 | 562 |
608 void WebFrameTestClient::didReceiveResponse( | 563 void WebFrameTestClient::didReceiveResponse( |
609 unsigned identifier, | |
610 const blink::WebURLResponse& response) { | 564 const blink::WebURLResponse& response) { |
611 if (test_runner_->shouldDumpResourceLoadCallbacks()) { | 565 if (test_runner_->shouldDumpResourceLoadCallbacks()) { |
612 if (resource_identifier_map_.find(identifier) == | 566 delegate_->PrintMessage(DescriptionSuitableForTestResult( |
613 resource_identifier_map_.end()) | 567 GURL(response.url()).possibly_invalid_spec())); |
614 delegate_->PrintMessage("<unknown>"); | |
615 else | |
616 delegate_->PrintMessage(resource_identifier_map_[identifier]); | |
617 delegate_->PrintMessage(" - didReceiveResponse "); | 568 delegate_->PrintMessage(" - didReceiveResponse "); |
618 PrintResponseDescription(delegate_, response); | 569 PrintResponseDescription(delegate_, response); |
619 delegate_->PrintMessage("\n"); | 570 delegate_->PrintMessage("\n"); |
620 } | 571 } |
621 if (test_runner_->shouldDumpResourceResponseMIMETypes()) { | 572 if (test_runner_->shouldDumpResourceResponseMIMETypes()) { |
622 GURL url = response.url(); | 573 GURL url = response.url(); |
623 blink::WebString mime_type = response.mimeType(); | 574 blink::WebString mime_type = response.mimeType(); |
624 delegate_->PrintMessage(url.ExtractFileName()); | 575 delegate_->PrintMessage(url.ExtractFileName()); |
625 delegate_->PrintMessage(" has MIME type "); | 576 delegate_->PrintMessage(" has MIME type "); |
626 // Simulate NSURLResponse's mapping of empty/unknown MIME types to | 577 // Simulate NSURLResponse's mapping of empty/unknown MIME types to |
627 // application/octet-stream | 578 // application/octet-stream |
628 delegate_->PrintMessage(mime_type.isEmpty() ? "application/octet-stream" | 579 delegate_->PrintMessage(mime_type.isEmpty() ? "application/octet-stream" |
629 : mime_type.utf8().data()); | 580 : mime_type.utf8().data()); |
630 delegate_->PrintMessage("\n"); | 581 delegate_->PrintMessage("\n"); |
631 } | 582 } |
632 } | 583 } |
633 | 584 |
634 void WebFrameTestClient::didChangeResourcePriority( | |
635 unsigned identifier, | |
636 const blink::WebURLRequest::Priority& priority, | |
637 int intra_priority_value) { | |
638 if (test_runner_->shouldDumpResourcePriorities()) { | |
639 if (resource_identifier_map_.find(identifier) == | |
640 resource_identifier_map_.end()) | |
641 delegate_->PrintMessage("<unknown>"); | |
642 else | |
643 delegate_->PrintMessage(resource_identifier_map_[identifier]); | |
644 delegate_->PrintMessage(base::StringPrintf( | |
645 " changed priority to %s, intra_priority %d\n", | |
646 PriorityDescription(priority).c_str(), intra_priority_value)); | |
647 } | |
648 } | |
649 | |
650 void WebFrameTestClient::didFinishResourceLoad(blink::WebLocalFrame* frame, | |
651 unsigned identifier) { | |
652 if (test_runner_->shouldDumpResourceLoadCallbacks()) { | |
653 if (resource_identifier_map_.find(identifier) == | |
654 resource_identifier_map_.end()) | |
655 delegate_->PrintMessage("<unknown>"); | |
656 else | |
657 delegate_->PrintMessage(resource_identifier_map_[identifier]); | |
658 delegate_->PrintMessage(" - didFinishLoading\n"); | |
659 } | |
660 resource_identifier_map_.erase(identifier); | |
661 } | |
662 | |
663 void WebFrameTestClient::didAddMessageToConsole( | 585 void WebFrameTestClient::didAddMessageToConsole( |
664 const blink::WebConsoleMessage& message, | 586 const blink::WebConsoleMessage& message, |
665 const blink::WebString& source_name, | 587 const blink::WebString& source_name, |
666 unsigned source_line, | 588 unsigned source_line, |
667 const blink::WebString& stack_trace) { | 589 const blink::WebString& stack_trace) { |
668 if (!test_runner_->ShouldDumpConsoleMessages()) | 590 if (!test_runner_->ShouldDumpConsoleMessages()) |
669 return; | 591 return; |
670 std::string level; | 592 std::string level; |
671 switch (message.level) { | 593 switch (message.level) { |
672 case blink::WebConsoleMessage::LevelDebug: | 594 case blink::WebConsoleMessage::LevelDebug: |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 | 677 |
756 bool WebFrameTestClient::runFileChooser( | 678 bool WebFrameTestClient::runFileChooser( |
757 const blink::WebFileChooserParams& params, | 679 const blink::WebFileChooserParams& params, |
758 blink::WebFileChooserCompletion* completion) { | 680 blink::WebFileChooserCompletion* completion) { |
759 delegate_->PrintMessage("Mock: Opening a file chooser.\n"); | 681 delegate_->PrintMessage("Mock: Opening a file chooser.\n"); |
760 // FIXME: Add ability to set file names to a file upload control. | 682 // FIXME: Add ability to set file names to a file upload control. |
761 return false; | 683 return false; |
762 } | 684 } |
763 | 685 |
764 } // namespace test_runner | 686 } // namespace test_runner |
OLD | NEW |