| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/shell/renderer/test_runner/web_test_proxy.h" | 5 #include "content/shell/renderer/test_runner/web_test_proxy.h" |
| 6 | 6 |
| 7 #include <cctype> | 7 #include <cctype> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/stringprintf.h" |
| 12 #include "content/shell/renderer/test_runner/MockWebSpeechRecognizer.h" | 13 #include "content/shell/renderer/test_runner/MockWebSpeechRecognizer.h" |
| 13 #include "content/shell/renderer/test_runner/SpellCheckClient.h" | 14 #include "content/shell/renderer/test_runner/SpellCheckClient.h" |
| 14 #include "content/shell/renderer/test_runner/TestCommon.h" | 15 #include "content/shell/renderer/test_runner/TestCommon.h" |
| 15 #include "content/shell/renderer/test_runner/TestInterfaces.h" | 16 #include "content/shell/renderer/test_runner/TestInterfaces.h" |
| 16 #include "content/shell/renderer/test_runner/TestPlugin.h" | 17 #include "content/shell/renderer/test_runner/TestPlugin.h" |
| 17 #include "content/shell/renderer/test_runner/WebTestDelegate.h" | 18 #include "content/shell/renderer/test_runner/WebTestDelegate.h" |
| 18 #include "content/shell/renderer/test_runner/WebTestInterfaces.h" | 19 #include "content/shell/renderer/test_runner/WebTestInterfaces.h" |
| 19 #include "content/shell/renderer/test_runner/accessibility_controller.h" | 20 #include "content/shell/renderer/test_runner/accessibility_controller.h" |
| 20 #include "content/shell/renderer/test_runner/event_sender.h" | 21 #include "content/shell/renderer/test_runner/event_sender.h" |
| 21 #include "content/shell/renderer/test_runner/mock_color_chooser.h" | 22 #include "content/shell/renderer/test_runner/mock_color_chooser.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 108 |
| 108 return url.substr(pos + 1); | 109 return url.substr(pos + 1); |
| 109 } | 110 } |
| 110 | 111 |
| 111 void PrintResponseDescription(WebTestDelegate* delegate, | 112 void PrintResponseDescription(WebTestDelegate* delegate, |
| 112 const blink::WebURLResponse& response) { | 113 const blink::WebURLResponse& response) { |
| 113 if (response.isNull()) { | 114 if (response.isNull()) { |
| 114 delegate->printMessage("(null)"); | 115 delegate->printMessage("(null)"); |
| 115 return; | 116 return; |
| 116 } | 117 } |
| 117 std::string url = response.url().spec(); | 118 delegate->printMessage(base::StringPrintf( |
| 118 char data[100]; | 119 "<NSURLResponse %s, http status code %d>", |
| 119 snprintf(data, sizeof(data), "%d", response.httpStatusCode()); | 120 DescriptionSuitableForTestResult(response.url().spec()).c_str(), |
| 120 delegate->printMessage(std::string("<NSURLResponse ") + | 121 response.httpStatusCode())); |
| 121 DescriptionSuitableForTestResult(url) + | |
| 122 ", http status code " + data + ">"); | |
| 123 } | 122 } |
| 124 | 123 |
| 125 std::string URLDescription(const GURL& url) { | 124 std::string URLDescription(const GURL& url) { |
| 126 if (url.SchemeIs("file")) | 125 if (url.SchemeIs("file")) |
| 127 return url.ExtractFileName(); | 126 return url.ExtractFileName(); |
| 128 return url.possibly_invalid_spec(); | 127 return url.possibly_invalid_spec(); |
| 129 } | 128 } |
| 130 | 129 |
| 131 std::string PriorityDescription( | 130 std::string PriorityDescription( |
| 132 const blink::WebURLRequest::Priority& priority) { | 131 const blink::WebURLRequest::Priority& priority) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 } | 278 } |
| 280 | 279 |
| 281 std::string DumpFrameScrollPosition(blink::WebFrame* frame, bool recursive) { | 280 std::string DumpFrameScrollPosition(blink::WebFrame* frame, bool recursive) { |
| 282 std::string result; | 281 std::string result; |
| 283 blink::WebSize offset = frame->scrollOffset(); | 282 blink::WebSize offset = frame->scrollOffset(); |
| 284 if (offset.width > 0 || offset.height > 0) { | 283 if (offset.width > 0 || offset.height > 0) { |
| 285 if (frame->parent()) { | 284 if (frame->parent()) { |
| 286 result = | 285 result = |
| 287 std::string("frame '") + frame->uniqueName().utf8().data() + "' "; | 286 std::string("frame '") + frame->uniqueName().utf8().data() + "' "; |
| 288 } | 287 } |
| 289 char data[100]; | 288 base::StringAppendF( |
| 290 snprintf( | 289 &result, "scrolled to %d,%d\n", offset.width, offset.height); |
| 291 data, sizeof(data), "scrolled to %d,%d\n", offset.width, offset.height); | |
| 292 result += data; | |
| 293 } | 290 } |
| 294 | 291 |
| 295 if (!recursive) | 292 if (!recursive) |
| 296 return result; | 293 return result; |
| 297 for (blink::WebFrame* child = frame->firstChild(); child; | 294 for (blink::WebFrame* child = frame->firstChild(); child; |
| 298 child = child->nextSibling()) | 295 child = child->nextSibling()) |
| 299 result += DumpFrameScrollPosition(child, recursive); | 296 result += DumpFrameScrollPosition(child, recursive); |
| 300 return result; | 297 return result; |
| 301 } | 298 } |
| 302 | 299 |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 } | 954 } |
| 958 | 955 |
| 959 void WebTestProxyBase::DidFinishDocumentLoad(blink::WebLocalFrame* frame) { | 956 void WebTestProxyBase::DidFinishDocumentLoad(blink::WebLocalFrame* frame) { |
| 960 if (test_interfaces_->testRunner()->shouldDumpFrameLoadCallbacks()) { | 957 if (test_interfaces_->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 961 PrintFrameDescription(delegate_, frame); | 958 PrintFrameDescription(delegate_, frame); |
| 962 delegate_->printMessage(" - didFinishDocumentLoadForFrame\n"); | 959 delegate_->printMessage(" - didFinishDocumentLoadForFrame\n"); |
| 963 } else { | 960 } else { |
| 964 unsigned pendingUnloadEvents = frame->unloadListenerCount(); | 961 unsigned pendingUnloadEvents = frame->unloadListenerCount(); |
| 965 if (pendingUnloadEvents) { | 962 if (pendingUnloadEvents) { |
| 966 PrintFrameDescription(delegate_, frame); | 963 PrintFrameDescription(delegate_, frame); |
| 967 char buffer[100]; | 964 delegate_->printMessage(base::StringPrintf( |
| 968 snprintf(buffer, | 965 " - has %u onunload handler(s)\n", pendingUnloadEvents)); |
| 969 sizeof(buffer), | |
| 970 " - has %u onunload handler(s)\n", | |
| 971 pendingUnloadEvents); | |
| 972 delegate_->printMessage(buffer); | |
| 973 } | 966 } |
| 974 } | 967 } |
| 975 } | 968 } |
| 976 | 969 |
| 977 void WebTestProxyBase::DidHandleOnloadEvents(blink::WebLocalFrame* frame) { | 970 void WebTestProxyBase::DidHandleOnloadEvents(blink::WebLocalFrame* frame) { |
| 978 if (test_interfaces_->testRunner()->shouldDumpFrameLoadCallbacks()) { | 971 if (test_interfaces_->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 979 PrintFrameDescription(delegate_, frame); | 972 PrintFrameDescription(delegate_, frame); |
| 980 delegate_->printMessage(" - didHandleOnloadEventsForFrame\n"); | 973 delegate_->printMessage(" - didHandleOnloadEventsForFrame\n"); |
| 981 } | 974 } |
| 982 } | 975 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 blink::WebLocalFrame* frame, | 1122 blink::WebLocalFrame* frame, |
| 1130 unsigned identifier, | 1123 unsigned identifier, |
| 1131 const blink::WebURLRequest::Priority& priority, | 1124 const blink::WebURLRequest::Priority& priority, |
| 1132 int intra_priority_value) { | 1125 int intra_priority_value) { |
| 1133 if (test_interfaces_->testRunner()->shouldDumpResourcePriorities()) { | 1126 if (test_interfaces_->testRunner()->shouldDumpResourcePriorities()) { |
| 1134 if (resource_identifier_map_.find(identifier) == | 1127 if (resource_identifier_map_.find(identifier) == |
| 1135 resource_identifier_map_.end()) | 1128 resource_identifier_map_.end()) |
| 1136 delegate_->printMessage("<unknown>"); | 1129 delegate_->printMessage("<unknown>"); |
| 1137 else | 1130 else |
| 1138 delegate_->printMessage(resource_identifier_map_[identifier]); | 1131 delegate_->printMessage(resource_identifier_map_[identifier]); |
| 1139 delegate_->printMessage(" changed priority to "); | 1132 delegate_->printMessage( |
| 1140 delegate_->printMessage(PriorityDescription(priority)); | 1133 base::StringPrintf(" changed priority to %s, intra_priority %d\n", |
| 1141 char buffer[64]; | 1134 PriorityDescription(priority).c_str(), |
| 1142 snprintf( | 1135 intra_priority_value)); |
| 1143 buffer, sizeof(buffer), ", intra_priority %d", intra_priority_value); | |
| 1144 delegate_->printMessage(buffer); | |
| 1145 delegate_->printMessage("\n"); | |
| 1146 } | 1136 } |
| 1147 } | 1137 } |
| 1148 | 1138 |
| 1149 void WebTestProxyBase::DidFinishResourceLoad(blink::WebLocalFrame* frame, | 1139 void WebTestProxyBase::DidFinishResourceLoad(blink::WebLocalFrame* frame, |
| 1150 unsigned identifier) { | 1140 unsigned identifier) { |
| 1151 if (test_interfaces_->testRunner()->shouldDumpResourceLoadCallbacks()) { | 1141 if (test_interfaces_->testRunner()->shouldDumpResourceLoadCallbacks()) { |
| 1152 if (resource_identifier_map_.find(identifier) == | 1142 if (resource_identifier_map_.find(identifier) == |
| 1153 resource_identifier_map_.end()) | 1143 resource_identifier_map_.end()) |
| 1154 delegate_->printMessage("<unknown>"); | 1144 delegate_->printMessage("<unknown>"); |
| 1155 else | 1145 else |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1179 break; | 1169 break; |
| 1180 case blink::WebConsoleMessage::LevelWarning: | 1170 case blink::WebConsoleMessage::LevelWarning: |
| 1181 level = "WARNING"; | 1171 level = "WARNING"; |
| 1182 break; | 1172 break; |
| 1183 case blink::WebConsoleMessage::LevelError: | 1173 case blink::WebConsoleMessage::LevelError: |
| 1184 level = "ERROR"; | 1174 level = "ERROR"; |
| 1185 break; | 1175 break; |
| 1186 } | 1176 } |
| 1187 delegate_->printMessage(std::string("CONSOLE ") + level + ": "); | 1177 delegate_->printMessage(std::string("CONSOLE ") + level + ": "); |
| 1188 if (source_line) { | 1178 if (source_line) { |
| 1189 char buffer[40]; | 1179 delegate_->printMessage(base::StringPrintf("line %d: ", source_line)); |
| 1190 snprintf(buffer, sizeof(buffer), "line %d: ", source_line); | |
| 1191 delegate_->printMessage(buffer); | |
| 1192 } | 1180 } |
| 1193 if (!message.text.isEmpty()) { | 1181 if (!message.text.isEmpty()) { |
| 1194 std::string new_message; | 1182 std::string new_message; |
| 1195 new_message = message.text.utf8(); | 1183 new_message = message.text.utf8(); |
| 1196 size_t file_protocol = new_message.find("file://"); | 1184 size_t file_protocol = new_message.find("file://"); |
| 1197 if (file_protocol != std::string::npos) { | 1185 if (file_protocol != std::string::npos) { |
| 1198 new_message = new_message.substr(0, file_protocol) + | 1186 new_message = new_message.substr(0, file_protocol) + |
| 1199 URLSuitableForTestResult(new_message.substr(file_protocol)); | 1187 URLSuitableForTestResult(new_message.substr(file_protocol)); |
| 1200 } | 1188 } |
| 1201 delegate_->printMessage(new_message); | 1189 delegate_->printMessage(new_message); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1269 if (!push_client_.get()) | 1257 if (!push_client_.get()) |
| 1270 push_client_.reset(new MockWebPushClient); | 1258 push_client_.reset(new MockWebPushClient); |
| 1271 return push_client_.get(); | 1259 return push_client_.get(); |
| 1272 } | 1260 } |
| 1273 | 1261 |
| 1274 blink::WebPushClient* WebTestProxyBase::GetWebPushClient() { | 1262 blink::WebPushClient* WebTestProxyBase::GetWebPushClient() { |
| 1275 return GetPushClientMock(); | 1263 return GetPushClientMock(); |
| 1276 } | 1264 } |
| 1277 | 1265 |
| 1278 } // namespace content | 1266 } // namespace content |
| OLD | NEW |