| 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 "components/test_runner/web_test_proxy.h" | 5 #include "components/test_runner/web_test_proxy.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <cctype> | 10 #include <cctype> |
| 11 | 11 |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
| 22 #include "components/test_runner/accessibility_controller.h" |
| 22 #include "components/test_runner/event_sender.h" | 23 #include "components/test_runner/event_sender.h" |
| 24 #include "components/test_runner/layout_dump.h" |
| 25 #include "components/test_runner/mock_color_chooser.h" |
| 23 #include "components/test_runner/mock_credential_manager_client.h" | 26 #include "components/test_runner/mock_credential_manager_client.h" |
| 24 #include "components/test_runner/mock_screen_orientation_client.h" | 27 #include "components/test_runner/mock_screen_orientation_client.h" |
| 25 #include "components/test_runner/mock_web_speech_recognizer.h" | 28 #include "components/test_runner/mock_web_speech_recognizer.h" |
| 29 #include "components/test_runner/mock_web_user_media_client.h" |
| 26 #include "components/test_runner/spell_check_client.h" | 30 #include "components/test_runner/spell_check_client.h" |
| 27 #include "components/test_runner/test_common.h" | |
| 28 #include "components/test_runner/test_interfaces.h" | 31 #include "components/test_runner/test_interfaces.h" |
| 29 #include "components/test_runner/test_plugin.h" | 32 #include "components/test_runner/test_plugin.h" |
| 30 #include "components/test_runner/test_runner.h" | 33 #include "components/test_runner/test_runner.h" |
| 31 #include "components/test_runner/web_test_delegate.h" | 34 #include "components/test_runner/web_test_delegate.h" |
| 32 #include "components/test_runner/web_test_interfaces.h" | 35 #include "components/test_runner/web_test_interfaces.h" |
| 33 #include "components/test_runner/web_test_runner.h" | 36 #include "components/test_runner/web_test_runner.h" |
| 34 // FIXME: Including platform_canvas.h here is a layering violation. | 37 // FIXME: Including platform_canvas.h here is a layering violation. |
| 35 #include "skia/ext/platform_canvas.h" | 38 #include "skia/ext/platform_canvas.h" |
| 36 #include "third_party/WebKit/public/platform/Platform.h" | 39 #include "third_party/WebKit/public/platform/Platform.h" |
| 37 #include "third_party/WebKit/public/platform/WebClipboard.h" | 40 #include "third_party/WebKit/public/platform/WebClipboard.h" |
| 38 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac
k.h" | 41 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac
k.h" |
| 39 #include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h" | 42 #include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h" |
| 40 #include "third_party/WebKit/public/platform/WebURLError.h" | 43 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 41 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 44 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 42 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 45 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 43 #include "third_party/WebKit/public/web/WebAXEnums.h" | 46 #include "third_party/WebKit/public/web/WebAXEnums.h" |
| 44 #include "third_party/WebKit/public/web/WebAXObject.h" | 47 #include "third_party/WebKit/public/web/WebAXObject.h" |
| 48 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
| 49 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 45 #include "third_party/WebKit/public/web/WebDocument.h" | 50 #include "third_party/WebKit/public/web/WebDocument.h" |
| 46 #include "third_party/WebKit/public/web/WebElement.h" | 51 #include "third_party/WebKit/public/web/WebElement.h" |
| 47 #include "third_party/WebKit/public/web/WebHistoryItem.h" | 52 #include "third_party/WebKit/public/web/WebHistoryItem.h" |
| 48 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 53 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 49 #include "third_party/WebKit/public/web/WebNode.h" | 54 #include "third_party/WebKit/public/web/WebNode.h" |
| 50 #include "third_party/WebKit/public/web/WebPagePopup.h" | 55 #include "third_party/WebKit/public/web/WebPagePopup.h" |
| 51 #include "third_party/WebKit/public/web/WebPluginParams.h" | 56 #include "third_party/WebKit/public/web/WebPluginParams.h" |
| 52 #include "third_party/WebKit/public/web/WebPrintParams.h" | 57 #include "third_party/WebKit/public/web/WebPrintParams.h" |
| 53 #include "third_party/WebKit/public/web/WebRange.h" | 58 #include "third_party/WebKit/public/web/WebRange.h" |
| 54 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 59 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 typedef void (WebTestProxyBase::*CallbackMethodType)(); | 107 typedef void (WebTestProxyBase::*CallbackMethodType)(); |
| 103 HostMethodTask(WebTestProxyBase* object, CallbackMethodType callback) | 108 HostMethodTask(WebTestProxyBase* object, CallbackMethodType callback) |
| 104 : WebMethodTask<WebTestProxyBase>(object), callback_(callback) {} | 109 : WebMethodTask<WebTestProxyBase>(object), callback_(callback) {} |
| 105 | 110 |
| 106 void RunIfValid() override { (object_->*callback_)(); } | 111 void RunIfValid() override { (object_->*callback_)(); } |
| 107 | 112 |
| 108 private: | 113 private: |
| 109 CallbackMethodType callback_; | 114 CallbackMethodType callback_; |
| 110 }; | 115 }; |
| 111 | 116 |
| 117 void PrintFrameDescription(WebTestDelegate* delegate, blink::WebFrame* frame) { |
| 118 std::string name8 = frame->uniqueName().utf8(); |
| 119 if (frame == frame->view()->mainFrame()) { |
| 120 if (!name8.length()) { |
| 121 delegate->PrintMessage("main frame"); |
| 122 return; |
| 123 } |
| 124 delegate->PrintMessage(std::string("main frame \"") + name8 + "\""); |
| 125 return; |
| 126 } |
| 127 if (!name8.length()) { |
| 128 delegate->PrintMessage("frame (anonymous)"); |
| 129 return; |
| 130 } |
| 131 delegate->PrintMessage(std::string("frame \"") + name8 + "\""); |
| 132 } |
| 133 |
| 134 void PrintFrameuserGestureStatus(WebTestDelegate* delegate, |
| 135 blink::WebFrame* frame, |
| 136 const char* msg) { |
| 137 bool is_user_gesture = |
| 138 blink::WebUserGestureIndicator::isProcessingUserGesture(); |
| 139 delegate->PrintMessage(std::string("Frame with user gesture \"") + |
| 140 (is_user_gesture ? "true" : "false") + "\"" + msg); |
| 141 } |
| 142 |
| 143 // Used to write a platform neutral file:/// URL by taking the |
| 144 // filename and its directory. (e.g., converts |
| 145 // "file:///tmp/foo/bar.txt" to just "bar.txt"). |
| 146 std::string DescriptionSuitableForTestResult(const std::string& url) { |
| 147 if (url.empty() || std::string::npos == url.find("file://")) |
| 148 return url; |
| 149 |
| 150 size_t pos = url.rfind('/'); |
| 151 if (pos == std::string::npos || !pos) |
| 152 return "ERROR:" + url; |
| 153 pos = url.rfind('/', pos - 1); |
| 154 if (pos == std::string::npos) |
| 155 return "ERROR:" + url; |
| 156 |
| 157 return url.substr(pos + 1); |
| 158 } |
| 159 |
| 160 void PrintResponseDescription(WebTestDelegate* delegate, |
| 161 const blink::WebURLResponse& response) { |
| 162 if (response.isNull()) { |
| 163 delegate->PrintMessage("(null)"); |
| 164 return; |
| 165 } |
| 166 delegate->PrintMessage(base::StringPrintf( |
| 167 "<NSURLResponse %s, http status code %d>", |
| 168 DescriptionSuitableForTestResult(response.url().string().utf8()).c_str(), |
| 169 response.httpStatusCode())); |
| 170 } |
| 171 |
| 172 std::string URLDescription(const GURL& url) { |
| 173 if (url.SchemeIs(url::kFileScheme)) |
| 174 return url.ExtractFileName(); |
| 175 return url.possibly_invalid_spec(); |
| 176 } |
| 177 |
| 178 std::string PriorityDescription( |
| 179 const blink::WebURLRequest::Priority& priority) { |
| 180 switch (priority) { |
| 181 case blink::WebURLRequest::PriorityVeryLow: |
| 182 return "VeryLow"; |
| 183 case blink::WebURLRequest::PriorityLow: |
| 184 return "Low"; |
| 185 case blink::WebURLRequest::PriorityMedium: |
| 186 return "Medium"; |
| 187 case blink::WebURLRequest::PriorityHigh: |
| 188 return "High"; |
| 189 case blink::WebURLRequest::PriorityVeryHigh: |
| 190 return "VeryHigh"; |
| 191 case blink::WebURLRequest::PriorityUnresolved: |
| 192 default: |
| 193 return "Unresolved"; |
| 194 } |
| 195 } |
| 196 |
| 197 void BlockRequest(blink::WebURLRequest& request) { |
| 198 request.setURL(GURL("255.255.255.255")); |
| 199 } |
| 200 |
| 201 bool IsLocalHost(const std::string& host) { |
| 202 return host == "127.0.0.1" || host == "localhost"; |
| 203 } |
| 204 |
| 205 bool IsTestHost(const std::string& host) { |
| 206 return base::EndsWith(host, ".test", base::CompareCase::INSENSITIVE_ASCII); |
| 207 } |
| 208 |
| 209 bool HostIsUsedBySomeTestsToGenerateError(const std::string& host) { |
| 210 return host == "255.255.255.255"; |
| 211 } |
| 212 |
| 213 // Used to write a platform neutral file:/// URL by only taking the filename |
| 214 // (e.g., converts "file:///tmp/foo.txt" to just "foo.txt"). |
| 215 std::string URLSuitableForTestResult(const std::string& url) { |
| 216 if (url.empty() || std::string::npos == url.find("file://")) |
| 217 return url; |
| 218 |
| 219 size_t pos = url.rfind('/'); |
| 220 if (pos == std::string::npos) { |
| 221 #ifdef WIN32 |
| 222 pos = url.rfind('\\'); |
| 223 if (pos == std::string::npos) |
| 224 pos = 0; |
| 225 #else |
| 226 pos = 0; |
| 227 #endif |
| 228 } |
| 229 std::string filename = url.substr(pos + 1); |
| 230 if (filename.empty()) |
| 231 return "file:"; // A WebKit test has this in its expected output. |
| 232 return filename; |
| 233 } |
| 234 |
| 235 // WebNavigationType debugging strings taken from PolicyDelegate.mm. |
| 236 const char* kLinkClickedString = "link clicked"; |
| 237 const char* kFormSubmittedString = "form submitted"; |
| 238 const char* kBackForwardString = "back/forward"; |
| 239 const char* kReloadString = "reload"; |
| 240 const char* kFormResubmittedString = "form resubmitted"; |
| 241 const char* kOtherString = "other"; |
| 242 const char* kIllegalString = "illegal value"; |
| 243 |
| 244 // Get a debugging string from a WebNavigationType. |
| 245 const char* WebNavigationTypeToString(blink::WebNavigationType type) { |
| 246 switch (type) { |
| 247 case blink::WebNavigationTypeLinkClicked: |
| 248 return kLinkClickedString; |
| 249 case blink::WebNavigationTypeFormSubmitted: |
| 250 return kFormSubmittedString; |
| 251 case blink::WebNavigationTypeBackForward: |
| 252 return kBackForwardString; |
| 253 case blink::WebNavigationTypeReload: |
| 254 return kReloadString; |
| 255 case blink::WebNavigationTypeFormResubmitted: |
| 256 return kFormResubmittedString; |
| 257 case blink::WebNavigationTypeOther: |
| 258 return kOtherString; |
| 259 } |
| 260 return kIllegalString; |
| 261 } |
| 262 |
| 263 const char* kPolicyIgnore = "Ignore"; |
| 264 const char* kPolicyDownload = "download"; |
| 265 const char* kPolicyCurrentTab = "current tab"; |
| 266 const char* kPolicyNewBackgroundTab = "new background tab"; |
| 267 const char* kPolicyNewForegroundTab = "new foreground tab"; |
| 268 const char* kPolicyNewWindow = "new window"; |
| 269 const char* kPolicyNewPopup = "new popup"; |
| 270 |
| 271 const char* WebNavigationPolicyToString(blink::WebNavigationPolicy policy) { |
| 272 switch (policy) { |
| 273 case blink::WebNavigationPolicyIgnore: |
| 274 return kPolicyIgnore; |
| 275 case blink::WebNavigationPolicyDownload: |
| 276 return kPolicyDownload; |
| 277 case blink::WebNavigationPolicyCurrentTab: |
| 278 return kPolicyCurrentTab; |
| 279 case blink::WebNavigationPolicyNewBackgroundTab: |
| 280 return kPolicyNewBackgroundTab; |
| 281 case blink::WebNavigationPolicyNewForegroundTab: |
| 282 return kPolicyNewForegroundTab; |
| 283 case blink::WebNavigationPolicyNewWindow: |
| 284 return kPolicyNewWindow; |
| 285 case blink::WebNavigationPolicyNewPopup: |
| 286 return kPolicyNewPopup; |
| 287 default: |
| 288 return kIllegalString; |
| 289 } |
| 290 } |
| 291 |
| 112 std::string DumpAllBackForwardLists(TestInterfaces* interfaces, | 292 std::string DumpAllBackForwardLists(TestInterfaces* interfaces, |
| 113 WebTestDelegate* delegate) { | 293 WebTestDelegate* delegate) { |
| 114 std::string result; | 294 std::string result; |
| 115 const std::vector<WebTestProxyBase*>& window_list = | 295 const std::vector<WebTestProxyBase*>& window_list = |
| 116 interfaces->GetWindowList(); | 296 interfaces->GetWindowList(); |
| 117 for (size_t i = 0; i < window_list.size(); ++i) | 297 for (size_t i = 0; i < window_list.size(); ++i) |
| 118 result.append(delegate->DumpHistoryForWindow(window_list.at(i))); | 298 result.append(delegate->DumpHistoryForWindow(window_list.at(i))); |
| 119 return result; | 299 return result; |
| 120 } | 300 } |
| 121 } | 301 } |
| 122 | 302 |
| 123 WebTestProxyBase::WebTestProxyBase() | 303 WebTestProxyBase::WebTestProxyBase() |
| 124 : test_interfaces_(NULL), | 304 : test_interfaces_(NULL), |
| 125 delegate_(NULL), | 305 delegate_(NULL), |
| 126 web_widget_(NULL), | 306 web_widget_(NULL), |
| 127 spellcheck_(new SpellCheckClient(this)) { | 307 spellcheck_(new SpellCheckClient(this)), |
| 308 chooser_count_(0) { |
| 128 Reset(); | 309 Reset(); |
| 129 } | 310 } |
| 130 | 311 |
| 131 WebTestProxyBase::~WebTestProxyBase() { | 312 WebTestProxyBase::~WebTestProxyBase() { |
| 132 test_interfaces_->WindowClosed(this); | 313 test_interfaces_->WindowClosed(this); |
| 133 } | 314 } |
| 134 | 315 |
| 135 void WebTestProxyBase::SetInterfaces(WebTestInterfaces* interfaces) { | 316 void WebTestProxyBase::SetInterfaces(WebTestInterfaces* interfaces) { |
| 136 test_interfaces_ = interfaces->GetTestInterfaces(); | 317 test_interfaces_ = interfaces->GetTestInterfaces(); |
| 137 test_interfaces_->WindowOpened(this); | 318 test_interfaces_->WindowOpened(this); |
| 138 } | 319 } |
| 139 | 320 |
| 140 void WebTestProxyBase::SetDelegate(WebTestDelegate* delegate) { | 321 void WebTestProxyBase::SetDelegate(WebTestDelegate* delegate) { |
| 141 delegate_ = delegate; | 322 delegate_ = delegate; |
| 142 spellcheck_->SetDelegate(delegate); | 323 spellcheck_->SetDelegate(delegate); |
| 143 if (speech_recognizer_.get()) | 324 if (speech_recognizer_.get()) |
| 144 speech_recognizer_->SetDelegate(delegate); | 325 speech_recognizer_->SetDelegate(delegate); |
| 145 } | 326 } |
| 146 | 327 |
| 147 blink::WebView* WebTestProxyBase::GetWebView() const { | 328 blink::WebView* WebTestProxyBase::GetWebView() const { |
| 148 DCHECK(web_widget_); | 329 DCHECK(web_widget_); |
| 149 // TestRunner does not support popup widgets. So |web_widget|_ is always a | 330 // TestRunner does not support popup widgets. So |web_widget|_ is always a |
| 150 // WebView. | 331 // WebView. |
| 151 return static_cast<blink::WebView*>(web_widget_); | 332 return static_cast<blink::WebView*>(web_widget_); |
| 152 } | 333 } |
| 153 | 334 |
| 154 void WebTestProxyBase::Reset() { | 335 void WebTestProxyBase::Reset() { |
| 155 drag_image_.reset(); | 336 drag_image_.reset(); |
| 156 animate_scheduled_ = false; | 337 animate_scheduled_ = false; |
| 338 resource_identifier_map_.clear(); |
| 339 log_console_output_ = true; |
| 157 accept_languages_ = ""; | 340 accept_languages_ = ""; |
| 158 } | 341 } |
| 159 | 342 |
| 160 blink::WebSpellCheckClient* WebTestProxyBase::GetSpellCheckClient() const { | 343 blink::WebSpellCheckClient* WebTestProxyBase::GetSpellCheckClient() const { |
| 161 return spellcheck_.get(); | 344 return spellcheck_.get(); |
| 162 } | 345 } |
| 163 | 346 |
| 347 blink::WebColorChooser* WebTestProxyBase::CreateColorChooser( |
| 348 blink::WebColorChooserClient* client, |
| 349 const blink::WebColor& color, |
| 350 const blink::WebVector<blink::WebColorSuggestion>& suggestions) { |
| 351 // This instance is deleted by WebCore::ColorInputType |
| 352 return new MockColorChooser(client, delegate_, this); |
| 353 } |
| 354 |
| 164 bool WebTestProxyBase::RunFileChooser( | 355 bool WebTestProxyBase::RunFileChooser( |
| 165 const blink::WebFileChooserParams& params, | 356 const blink::WebFileChooserParams& params, |
| 166 blink::WebFileChooserCompletion* completion) { | 357 blink::WebFileChooserCompletion* completion) { |
| 167 delegate_->PrintMessage("Mock: Opening a file chooser.\n"); | 358 delegate_->PrintMessage("Mock: Opening a file chooser.\n"); |
| 168 // FIXME: Add ability to set file names to a file upload control. | 359 // FIXME: Add ability to set file names to a file upload control. |
| 169 return false; | 360 return false; |
| 170 } | 361 } |
| 171 | 362 |
| 172 void WebTestProxyBase::ShowValidationMessage( | 363 void WebTestProxyBase::ShowValidationMessage( |
| 173 const blink::WebString& main_message, | 364 const blink::WebString& main_message, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 192 } else if (sub_message_hint == blink::WebTextDirectionRightToLeft) { | 383 } else if (sub_message_hint == blink::WebTextDirectionRightToLeft) { |
| 193 base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text); | 384 base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text); |
| 194 } | 385 } |
| 195 } | 386 } |
| 196 delegate_->PrintMessage("ValidationMessageClient: main-message=" + | 387 delegate_->PrintMessage("ValidationMessageClient: main-message=" + |
| 197 base::UTF16ToUTF8(wrapped_main_text) + | 388 base::UTF16ToUTF8(wrapped_main_text) + |
| 198 " sub-message=" + | 389 " sub-message=" + |
| 199 base::UTF16ToUTF8(wrapped_sub_text) + "\n"); | 390 base::UTF16ToUTF8(wrapped_sub_text) + "\n"); |
| 200 } | 391 } |
| 201 | 392 |
| 393 void WebTestProxyBase::RunModalAlertDialog(const blink::WebString& message) { |
| 394 delegate_->PrintMessage(std::string("ALERT: ") + message.utf8().data() + |
| 395 "\n"); |
| 396 } |
| 397 |
| 398 bool WebTestProxyBase::RunModalConfirmDialog(const blink::WebString& message) { |
| 399 delegate_->PrintMessage(std::string("CONFIRM: ") + message.utf8().data() + |
| 400 "\n"); |
| 401 return true; |
| 402 } |
| 403 |
| 404 bool WebTestProxyBase::RunModalPromptDialog( |
| 405 const blink::WebString& message, |
| 406 const blink::WebString& default_value, |
| 407 blink::WebString* actual_value) { |
| 408 delegate_->PrintMessage(std::string("PROMPT: ") + message.utf8().data() + |
| 409 ", default text: " + default_value.utf8().data() + |
| 410 "\n"); |
| 411 return true; |
| 412 } |
| 413 |
| 414 bool WebTestProxyBase::RunModalBeforeUnloadDialog(bool is_reload) { |
| 415 delegate_->PrintMessage(std::string("CONFIRM NAVIGATION\n")); |
| 416 return !test_interfaces_->GetTestRunner() |
| 417 ->shouldStayOnPageAfterHandlingBeforeUnload(); |
| 418 } |
| 419 |
| 202 std::string WebTestProxyBase::DumpBackForwardLists() { | 420 std::string WebTestProxyBase::DumpBackForwardLists() { |
| 203 return DumpAllBackForwardLists(test_interfaces_, delegate_); | 421 return DumpAllBackForwardLists(test_interfaces_, delegate_); |
| 204 } | 422 } |
| 205 | 423 |
| 206 void WebTestProxyBase::DrawSelectionRect(SkCanvas* canvas) { | 424 void WebTestProxyBase::DrawSelectionRect(SkCanvas* canvas) { |
| 207 // See if we need to draw the selection bounds rect. Selection bounds | 425 // See if we need to draw the selection bounds rect. Selection bounds |
| 208 // rect is the rect enclosing the (possibly transformed) selection. | 426 // rect is the rect enclosing the (possibly transformed) selection. |
| 209 // The rect should be drawn after everything is laid out and painted. | 427 // The rect should be drawn after everything is laid out and painted. |
| 210 if (!test_interfaces_->GetTestRunner()->shouldDumpSelectionRect()) | 428 if (!test_interfaces_->GetTestRunner()->shouldDumpSelectionRect()) |
| 211 return; | 429 return; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 | 570 |
| 353 void WebTestProxyBase::DidCapturePixelsAsync( | 571 void WebTestProxyBase::DidCapturePixelsAsync( |
| 354 const base::Callback<void(const SkBitmap&)>& callback, | 572 const base::Callback<void(const SkBitmap&)>& callback, |
| 355 const SkBitmap& bitmap) { | 573 const SkBitmap& bitmap) { |
| 356 SkCanvas canvas(bitmap); | 574 SkCanvas canvas(bitmap); |
| 357 DrawSelectionRect(&canvas); | 575 DrawSelectionRect(&canvas); |
| 358 if (!callback.is_null()) | 576 if (!callback.is_null()) |
| 359 callback.Run(bitmap); | 577 callback.Run(bitmap); |
| 360 } | 578 } |
| 361 | 579 |
| 580 void WebTestProxyBase::SetLogConsoleOutput(bool enabled) { |
| 581 log_console_output_ = enabled; |
| 582 } |
| 583 |
| 362 void LayoutAndPaintCallback::didLayoutAndPaint() { | 584 void LayoutAndPaintCallback::didLayoutAndPaint() { |
| 363 TRACE_EVENT0("shell", "LayoutAndPaintCallback::didLayoutAndPaint"); | 585 TRACE_EVENT0("shell", "LayoutAndPaintCallback::didLayoutAndPaint"); |
| 364 if (wait_for_popup_) { | 586 if (wait_for_popup_) { |
| 365 wait_for_popup_ = false; | 587 wait_for_popup_ = false; |
| 366 return; | 588 return; |
| 367 } | 589 } |
| 368 | 590 |
| 369 if (!callback_.is_null()) | 591 if (!callback_.is_null()) |
| 370 callback_.Run(); | 592 callback_.Run(); |
| 371 delete this; | 593 delete this; |
| 372 } | 594 } |
| 373 | 595 |
| 374 void WebTestProxyBase::LayoutAndPaintAsyncThen(const base::Closure& callback) { | 596 void WebTestProxyBase::LayoutAndPaintAsyncThen(const base::Closure& callback) { |
| 375 TRACE_EVENT0("shell", "WebTestProxyBase::LayoutAndPaintAsyncThen"); | 597 TRACE_EVENT0("shell", "WebTestProxyBase::LayoutAndPaintAsyncThen"); |
| 376 | 598 |
| 377 LayoutAndPaintCallback* layout_and_paint_callback = | 599 LayoutAndPaintCallback* layout_and_paint_callback = |
| 378 new LayoutAndPaintCallback(callback); | 600 new LayoutAndPaintCallback(callback); |
| 379 web_widget_->layoutAndPaintAsync(layout_and_paint_callback); | 601 web_widget_->layoutAndPaintAsync(layout_and_paint_callback); |
| 380 if (blink::WebPagePopup* popup = web_widget_->pagePopup()) { | 602 if (blink::WebPagePopup* popup = web_widget_->pagePopup()) { |
| 381 layout_and_paint_callback->set_wait_for_popup(true); | 603 layout_and_paint_callback->set_wait_for_popup(true); |
| 382 popup->layoutAndPaintAsync(layout_and_paint_callback); | 604 popup->layoutAndPaintAsync(layout_and_paint_callback); |
| 383 } | 605 } |
| 384 } | 606 } |
| 385 | 607 |
| 386 void WebTestProxyBase::GetScreenOrientationForTesting( | 608 void WebTestProxyBase::GetScreenOrientationForTesting( |
| 387 blink::WebScreenInfo& screen_info) { | 609 blink::WebScreenInfo& screen_info) { |
| 388 MockScreenOrientationClient* mock_client = | 610 MockScreenOrientationClient* mock_client = GetScreenOrientationClientMock(); |
| 389 test_interfaces_->GetTestRunner()->getMockScreenOrientationClient(); | |
| 390 if (mock_client->IsDisabled()) | 611 if (mock_client->IsDisabled()) |
| 391 return; | 612 return; |
| 392 // Override screen orientation information with mock data. | 613 // Override screen orientation information with mock data. |
| 393 screen_info.orientationType = mock_client->CurrentOrientationType(); | 614 screen_info.orientationType = mock_client->CurrentOrientationType(); |
| 394 screen_info.orientationAngle = mock_client->CurrentOrientationAngle(); | 615 screen_info.orientationAngle = mock_client->CurrentOrientationAngle(); |
| 395 } | 616 } |
| 396 | 617 |
| 618 MockScreenOrientationClient* |
| 619 WebTestProxyBase::GetScreenOrientationClientMock() { |
| 620 return test_interfaces_->GetTestRunner()->getMockScreenOrientationClient(); |
| 621 } |
| 622 |
| 397 MockWebSpeechRecognizer* WebTestProxyBase::GetSpeechRecognizerMock() { | 623 MockWebSpeechRecognizer* WebTestProxyBase::GetSpeechRecognizerMock() { |
| 398 if (!speech_recognizer_.get()) { | 624 if (!speech_recognizer_.get()) { |
| 399 speech_recognizer_.reset(new MockWebSpeechRecognizer()); | 625 speech_recognizer_.reset(new MockWebSpeechRecognizer()); |
| 400 speech_recognizer_->SetDelegate(delegate_); | 626 speech_recognizer_->SetDelegate(delegate_); |
| 401 } | 627 } |
| 402 return speech_recognizer_.get(); | 628 return speech_recognizer_.get(); |
| 403 } | 629 } |
| 404 | 630 |
| 405 MockCredentialManagerClient* | 631 MockCredentialManagerClient* |
| 406 WebTestProxyBase::GetCredentialManagerClientMock() { | 632 WebTestProxyBase::GetCredentialManagerClientMock() { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 426 animate_scheduled_ = false; | 652 animate_scheduled_ = false; |
| 427 web_widget_->beginFrame(animate_time.InSecondsF()); | 653 web_widget_->beginFrame(animate_time.InSecondsF()); |
| 428 web_widget_->updateAllLifecyclePhases(); | 654 web_widget_->updateAllLifecyclePhases(); |
| 429 if (blink::WebPagePopup* popup = web_widget_->pagePopup()) { | 655 if (blink::WebPagePopup* popup = web_widget_->pagePopup()) { |
| 430 popup->beginFrame(animate_time.InSecondsF()); | 656 popup->beginFrame(animate_time.InSecondsF()); |
| 431 popup->updateAllLifecyclePhases(); | 657 popup->updateAllLifecyclePhases(); |
| 432 } | 658 } |
| 433 } | 659 } |
| 434 } | 660 } |
| 435 | 661 |
| 662 void WebTestProxyBase::PostAccessibilityEvent(const blink::WebAXObject& obj, |
| 663 blink::WebAXEvent event) { |
| 664 // Only hook the accessibility events occured during the test run. |
| 665 // This check prevents false positives in WebLeakDetector. |
| 666 // The pending tasks in browser/renderer message queue may trigger |
| 667 // accessibility events, |
| 668 // and AccessibilityController will hold on to their target nodes if we don't |
| 669 // ignore them here. |
| 670 if (!test_interfaces_->GetTestRunner()->TestIsRunning()) |
| 671 return; |
| 672 |
| 673 const char* event_name = NULL; |
| 674 switch (event) { |
| 675 case blink::WebAXEventActiveDescendantChanged: |
| 676 event_name = "ActiveDescendantChanged"; |
| 677 break; |
| 678 case blink::WebAXEventAlert: |
| 679 event_name = "Alert"; |
| 680 break; |
| 681 case blink::WebAXEventAriaAttributeChanged: |
| 682 event_name = "AriaAttributeChanged"; |
| 683 break; |
| 684 case blink::WebAXEventAutocorrectionOccured: |
| 685 event_name = "AutocorrectionOccured"; |
| 686 break; |
| 687 case blink::WebAXEventBlur: |
| 688 event_name = "Blur"; |
| 689 break; |
| 690 case blink::WebAXEventCheckedStateChanged: |
| 691 event_name = "CheckedStateChanged"; |
| 692 break; |
| 693 case blink::WebAXEventChildrenChanged: |
| 694 event_name = "ChildrenChanged"; |
| 695 break; |
| 696 case blink::WebAXEventClicked: |
| 697 event_name = "Clicked"; |
| 698 break; |
| 699 case blink::WebAXEventDocumentSelectionChanged: |
| 700 event_name = "DocumentSelectionChanged"; |
| 701 break; |
| 702 case blink::WebAXEventFocus: |
| 703 event_name = "Focus"; |
| 704 break; |
| 705 case blink::WebAXEventHide: |
| 706 event_name = "Hide"; |
| 707 break; |
| 708 case blink::WebAXEventHover: |
| 709 event_name = "Hover"; |
| 710 break; |
| 711 case blink::WebAXEventInvalidStatusChanged: |
| 712 event_name = "InvalidStatusChanged"; |
| 713 break; |
| 714 case blink::WebAXEventLayoutComplete: |
| 715 event_name = "LayoutComplete"; |
| 716 break; |
| 717 case blink::WebAXEventLiveRegionChanged: |
| 718 event_name = "LiveRegionChanged"; |
| 719 break; |
| 720 case blink::WebAXEventLoadComplete: |
| 721 event_name = "LoadComplete"; |
| 722 break; |
| 723 case blink::WebAXEventLocationChanged: |
| 724 event_name = "LocationChanged"; |
| 725 break; |
| 726 case blink::WebAXEventMenuListItemSelected: |
| 727 event_name = "MenuListItemSelected"; |
| 728 break; |
| 729 case blink::WebAXEventMenuListItemUnselected: |
| 730 event_name = "MenuListItemUnselected"; |
| 731 break; |
| 732 case blink::WebAXEventMenuListValueChanged: |
| 733 event_name = "MenuListValueChanged"; |
| 734 break; |
| 735 case blink::WebAXEventRowCollapsed: |
| 736 event_name = "RowCollapsed"; |
| 737 break; |
| 738 case blink::WebAXEventRowCountChanged: |
| 739 event_name = "RowCountChanged"; |
| 740 break; |
| 741 case blink::WebAXEventRowExpanded: |
| 742 event_name = "RowExpanded"; |
| 743 break; |
| 744 case blink::WebAXEventScrollPositionChanged: |
| 745 event_name = "ScrollPositionChanged"; |
| 746 break; |
| 747 case blink::WebAXEventScrolledToAnchor: |
| 748 event_name = "ScrolledToAnchor"; |
| 749 break; |
| 750 case blink::WebAXEventSelectedChildrenChanged: |
| 751 event_name = "SelectedChildrenChanged"; |
| 752 break; |
| 753 case blink::WebAXEventSelectedTextChanged: |
| 754 event_name = "SelectedTextChanged"; |
| 755 break; |
| 756 case blink::WebAXEventShow: |
| 757 event_name = "Show"; |
| 758 break; |
| 759 case blink::WebAXEventTextChanged: |
| 760 event_name = "TextChanged"; |
| 761 break; |
| 762 case blink::WebAXEventTextInserted: |
| 763 event_name = "TextInserted"; |
| 764 break; |
| 765 case blink::WebAXEventTextRemoved: |
| 766 event_name = "TextRemoved"; |
| 767 break; |
| 768 case blink::WebAXEventValueChanged: |
| 769 event_name = "ValueChanged"; |
| 770 break; |
| 771 default: |
| 772 event_name = "Unknown"; |
| 773 break; |
| 774 } |
| 775 |
| 776 test_interfaces_->GetAccessibilityController()->NotificationReceived( |
| 777 obj, event_name); |
| 778 |
| 779 if (test_interfaces_->GetAccessibilityController() |
| 780 ->ShouldLogAccessibilityEvents()) { |
| 781 std::string message("AccessibilityNotification - "); |
| 782 message += event_name; |
| 783 |
| 784 blink::WebNode node = obj.node(); |
| 785 if (!node.isNull() && node.isElementNode()) { |
| 786 blink::WebElement element = node.to<blink::WebElement>(); |
| 787 if (element.hasAttribute("id")) { |
| 788 message += " - id:"; |
| 789 message += element.getAttribute("id").utf8().data(); |
| 790 } |
| 791 } |
| 792 |
| 793 delegate_->PrintMessage(message + "\n"); |
| 794 } |
| 795 } |
| 796 |
| 436 void WebTestProxyBase::StartDragging(blink::WebLocalFrame* frame, | 797 void WebTestProxyBase::StartDragging(blink::WebLocalFrame* frame, |
| 437 const blink::WebDragData& data, | 798 const blink::WebDragData& data, |
| 438 blink::WebDragOperationsMask mask, | 799 blink::WebDragOperationsMask mask, |
| 439 const blink::WebImage& image, | 800 const blink::WebImage& image, |
| 440 const blink::WebPoint& point) { | 801 const blink::WebPoint& point) { |
| 441 if (test_interfaces_->GetTestRunner()->shouldDumpDragImage()) { | 802 if (test_interfaces_->GetTestRunner()->shouldDumpDragImage()) { |
| 442 if (drag_image_.isNull()) | 803 if (drag_image_.isNull()) |
| 443 drag_image_ = image; | 804 drag_image_ = image; |
| 444 } | 805 } |
| 445 // When running a test, we need to fake a drag drop operation otherwise | 806 // When running a test, we need to fake a drag drop operation otherwise |
| 446 // Windows waits for real mouse events to know when the drag is over. | 807 // Windows waits for real mouse events to know when the drag is over. |
| 447 test_interfaces_->GetEventSender()->DoDragDrop(data, mask); | 808 test_interfaces_->GetEventSender()->DoDragDrop(data, mask); |
| 448 } | 809 } |
| 449 | 810 |
| 450 // The output from these methods in layout test mode should match that | 811 // The output from these methods in layout test mode should match that |
| 451 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree. | 812 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree. |
| 452 | 813 |
| 814 void WebTestProxyBase::DidChangeSelection(bool is_empty_callback) { |
| 815 if (test_interfaces_->GetTestRunner()->shouldDumpEditingCallbacks()) |
| 816 delegate_->PrintMessage( |
| 817 "EDITING DELEGATE: " |
| 818 "webViewDidChangeSelection:WebViewDidChangeSelectionNotification\n"); |
| 819 } |
| 820 |
| 453 void WebTestProxyBase::DidChangeContents() { | 821 void WebTestProxyBase::DidChangeContents() { |
| 454 if (test_interfaces_->GetTestRunner()->shouldDumpEditingCallbacks()) | 822 if (test_interfaces_->GetTestRunner()->shouldDumpEditingCallbacks()) |
| 455 delegate_->PrintMessage( | 823 delegate_->PrintMessage( |
| 456 "EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n"); | 824 "EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n"); |
| 457 } | 825 } |
| 458 | 826 |
| 459 bool WebTestProxyBase::CreateView(blink::WebLocalFrame* frame, | 827 bool WebTestProxyBase::CreateView(blink::WebLocalFrame* frame, |
| 460 const blink::WebURLRequest& request, | 828 const blink::WebURLRequest& request, |
| 461 const blink::WebWindowFeatures& features, | 829 const blink::WebWindowFeatures& features, |
| 462 const blink::WebString& frame_name, | 830 const blink::WebString& frame_name, |
| 463 blink::WebNavigationPolicy policy, | 831 blink::WebNavigationPolicy policy, |
| 464 bool suppress_opener) { | 832 bool suppress_opener) { |
| 465 if (test_interfaces_->GetTestRunner()->shouldDumpNavigationPolicy()) { | 833 if (test_interfaces_->GetTestRunner()->shouldDumpNavigationPolicy()) { |
| 466 delegate_->PrintMessage("Default policy for createView for '" + | 834 delegate_->PrintMessage("Default policy for createView for '" + |
| 467 URLDescription(request.url()) + "' is '" + | 835 URLDescription(request.url()) + "' is '" + |
| 468 WebNavigationPolicyToString(policy) + "'\n"); | 836 WebNavigationPolicyToString(policy) + "'\n"); |
| 469 } | 837 } |
| 470 | 838 |
| 471 if (!test_interfaces_->GetTestRunner()->canOpenWindows()) | 839 if (!test_interfaces_->GetTestRunner()->canOpenWindows()) |
| 472 return false; | 840 return false; |
| 473 if (test_interfaces_->GetTestRunner()->shouldDumpCreateView()) | 841 if (test_interfaces_->GetTestRunner()->shouldDumpCreateView()) |
| 474 delegate_->PrintMessage(std::string("createView(") + | 842 delegate_->PrintMessage(std::string("createView(") + |
| 475 URLDescription(request.url()) + ")\n"); | 843 URLDescription(request.url()) + ")\n"); |
| 476 return true; | 844 return true; |
| 477 } | 845 } |
| 478 | 846 |
| 847 blink::WebPlugin* WebTestProxyBase::CreatePlugin( |
| 848 blink::WebLocalFrame* frame, |
| 849 const blink::WebPluginParams& params) { |
| 850 if (TestPlugin::IsSupportedMimeType(params.mimeType)) |
| 851 return TestPlugin::create(frame, params, delegate_); |
| 852 return delegate_->CreatePluginPlaceholder(frame, params); |
| 853 } |
| 854 |
| 479 void WebTestProxyBase::SetStatusText(const blink::WebString& text) { | 855 void WebTestProxyBase::SetStatusText(const blink::WebString& text) { |
| 480 if (!test_interfaces_->GetTestRunner()->shouldDumpStatusCallbacks()) | 856 if (!test_interfaces_->GetTestRunner()->shouldDumpStatusCallbacks()) |
| 481 return; | 857 return; |
| 482 delegate_->PrintMessage( | 858 delegate_->PrintMessage( |
| 483 std::string("UI DELEGATE STATUS CALLBACK: setStatusText:") + | 859 std::string("UI DELEGATE STATUS CALLBACK: setStatusText:") + |
| 484 text.utf8().data() + "\n"); | 860 text.utf8().data() + "\n"); |
| 485 } | 861 } |
| 486 | 862 |
| 863 void WebTestProxyBase::ShowContextMenu( |
| 864 const blink::WebContextMenuData& context_menu_data) { |
| 865 test_interfaces_->GetEventSender()->SetContextMenuData(context_menu_data); |
| 866 } |
| 867 |
| 868 blink::WebUserMediaClient* WebTestProxyBase::GetUserMediaClient() { |
| 869 if (!user_media_client_.get()) |
| 870 user_media_client_.reset(new MockWebUserMediaClient(delegate_)); |
| 871 return user_media_client_.get(); |
| 872 } |
| 873 |
| 487 // Simulate a print by going into print mode and then exit straight away. | 874 // Simulate a print by going into print mode and then exit straight away. |
| 488 void WebTestProxyBase::PrintPage(blink::WebLocalFrame* frame) { | 875 void WebTestProxyBase::PrintPage(blink::WebLocalFrame* frame) { |
| 489 blink::WebSize page_size_in_pixels = web_widget_->size(); | 876 blink::WebSize page_size_in_pixels = web_widget_->size(); |
| 490 if (page_size_in_pixels.isEmpty()) | 877 if (page_size_in_pixels.isEmpty()) |
| 491 return; | 878 return; |
| 492 blink::WebPrintParams printParams(page_size_in_pixels); | 879 blink::WebPrintParams printParams(page_size_in_pixels); |
| 493 frame->printBegin(printParams); | 880 frame->printBegin(printParams); |
| 494 frame->printEnd(); | 881 frame->printEnd(); |
| 495 } | 882 } |
| 496 | 883 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 512 | 899 |
| 513 void WebTestProxyBase::DidFocus() { | 900 void WebTestProxyBase::DidFocus() { |
| 514 delegate_->SetFocus(this, true); | 901 delegate_->SetFocus(this, true); |
| 515 } | 902 } |
| 516 | 903 |
| 517 void WebTestProxyBase::SetToolTipText(const blink::WebString& text, | 904 void WebTestProxyBase::SetToolTipText(const blink::WebString& text, |
| 518 blink::WebTextDirection direction) { | 905 blink::WebTextDirection direction) { |
| 519 test_interfaces_->GetTestRunner()->setToolTipText(text); | 906 test_interfaces_->GetTestRunner()->setToolTipText(text); |
| 520 } | 907 } |
| 521 | 908 |
| 909 void WebTestProxyBase::DidOpenChooser() { |
| 910 chooser_count_++; |
| 911 } |
| 912 |
| 913 void WebTestProxyBase::DidCloseChooser() { |
| 914 chooser_count_--; |
| 915 } |
| 916 |
| 917 bool WebTestProxyBase::IsChooserShown() { |
| 918 return 0 < chooser_count_; |
| 919 } |
| 920 |
| 921 void WebTestProxyBase::LoadURLExternally(const blink::WebURLRequest& request, |
| 922 blink::WebNavigationPolicy policy, |
| 923 const blink::WebString& suggested_name, |
| 924 bool replaces_current_history_item) { |
| 925 if (test_interfaces_->GetTestRunner()->shouldWaitUntilExternalURLLoad()) { |
| 926 if (policy == blink::WebNavigationPolicyDownload) { |
| 927 delegate_->PrintMessage( |
| 928 std::string("Downloading URL with suggested filename \"") + |
| 929 suggested_name.utf8() + "\"\n"); |
| 930 } else { |
| 931 delegate_->PrintMessage(std::string("Loading URL externally - \"") + |
| 932 URLDescription(request.url()) + "\"\n"); |
| 933 } |
| 934 delegate_->TestFinished(); |
| 935 } |
| 936 } |
| 937 |
| 938 void WebTestProxyBase::DidStartProvisionalLoad(blink::WebLocalFrame* frame) { |
| 939 if (!test_interfaces_->GetTestRunner()->topLoadingFrame()) |
| 940 test_interfaces_->GetTestRunner()->setTopLoadingFrame(frame, false); |
| 941 |
| 942 if (test_interfaces_->GetTestRunner()->shouldDumpFrameLoadCallbacks()) { |
| 943 PrintFrameDescription(delegate_, frame); |
| 944 delegate_->PrintMessage(" - didStartProvisionalLoadForFrame\n"); |
| 945 } |
| 946 |
| 947 if (test_interfaces_->GetTestRunner() |
| 948 ->shouldDumpUserGestureInFrameLoadCallbacks()) { |
| 949 PrintFrameuserGestureStatus( |
| 950 delegate_, frame, " - in didStartProvisionalLoadForFrame\n"); |
| 951 } |
| 952 } |
| 953 |
| 954 void WebTestProxyBase::DidReceiveServerRedirectForProvisionalLoad( |
| 955 blink::WebLocalFrame* frame) { |
| 956 if (test_interfaces_->GetTestRunner()->shouldDumpFrameLoadCallbacks()) { |
| 957 PrintFrameDescription(delegate_, frame); |
| 958 delegate_->PrintMessage( |
| 959 " - didReceiveServerRedirectForProvisionalLoadForFrame\n"); |
| 960 } |
| 961 } |
| 962 |
| 963 bool WebTestProxyBase::DidFailProvisionalLoad( |
| 964 blink::WebLocalFrame* frame, |
| 965 const blink::WebURLError& error, |
| 966 blink::WebHistoryCommitType commit_type) { |
| 967 DCHECK(frame->provisionalDataSource()); |
| 968 if (test_interfaces_->GetTestRunner()->shouldDumpFrameLoadCallbacks()) { |
| 969 PrintFrameDescription(delegate_, frame); |
| 970 delegate_->PrintMessage(" - didFailProvisionalLoadWithError\n"); |
| 971 } |
| 972 CheckDone(frame, MainResourceLoadFailed); |
| 973 return !frame->provisionalDataSource(); |
| 974 } |
| 975 |
| 976 void WebTestProxyBase::DidCommitProvisionalLoad( |
| 977 blink::WebLocalFrame* frame, |
| 978 const blink::WebHistoryItem& history_item, |
| 979 blink::WebHistoryCommitType history_type) { |
| 980 if (test_interfaces_->GetTestRunner()->shouldDumpFrameLoadCallbacks()) { |
| 981 PrintFrameDescription(delegate_, frame); |
| 982 delegate_->PrintMessage(" - didCommitLoadForFrame\n"); |
| 983 } |
| 984 } |
| 985 |
| 986 void WebTestProxyBase::DidReceiveTitle(blink::WebLocalFrame* frame, |
| 987 const blink::WebString& title, |
| 988 blink::WebTextDirection direction) { |
| 989 if (test_interfaces_->GetTestRunner()->shouldDumpFrameLoadCallbacks()) { |
| 990 PrintFrameDescription(delegate_, frame); |
| 991 delegate_->PrintMessage(std::string(" - didReceiveTitle: ") + title.utf8() + |
| 992 "\n"); |
| 993 } |
| 994 |
| 995 if (test_interfaces_->GetTestRunner()->shouldDumpTitleChanges()) |
| 996 delegate_->PrintMessage(std::string("TITLE CHANGED: '") + title.utf8() + |
| 997 "'\n"); |
| 998 } |
| 999 |
| 1000 void WebTestProxyBase::DidChangeIcon(blink::WebLocalFrame* frame, |
| 1001 blink::WebIconURL::Type icon_type) { |
| 1002 if (test_interfaces_->GetTestRunner()->shouldDumpIconChanges()) { |
| 1003 PrintFrameDescription(delegate_, frame); |
| 1004 delegate_->PrintMessage(std::string(" - didChangeIcons\n")); |
| 1005 } |
| 1006 } |
| 1007 |
| 1008 void WebTestProxyBase::DidFinishDocumentLoad(blink::WebLocalFrame* frame) { |
| 1009 if (test_interfaces_->GetTestRunner()->shouldDumpFrameLoadCallbacks()) { |
| 1010 PrintFrameDescription(delegate_, frame); |
| 1011 delegate_->PrintMessage(" - didFinishDocumentLoadForFrame\n"); |
| 1012 } |
| 1013 } |
| 1014 |
| 1015 void WebTestProxyBase::DidHandleOnloadEvents(blink::WebLocalFrame* frame) { |
| 1016 if (test_interfaces_->GetTestRunner()->shouldDumpFrameLoadCallbacks()) { |
| 1017 PrintFrameDescription(delegate_, frame); |
| 1018 delegate_->PrintMessage(" - didHandleOnloadEventsForFrame\n"); |
| 1019 } |
| 1020 } |
| 1021 |
| 1022 void WebTestProxyBase::DidFailLoad(blink::WebLocalFrame* frame, |
| 1023 const blink::WebURLError& error, |
| 1024 blink::WebHistoryCommitType commit_type) { |
| 1025 if (test_interfaces_->GetTestRunner()->shouldDumpFrameLoadCallbacks()) { |
| 1026 PrintFrameDescription(delegate_, frame); |
| 1027 delegate_->PrintMessage(" - didFailLoadWithError\n"); |
| 1028 } |
| 1029 CheckDone(frame, MainResourceLoadFailed); |
| 1030 } |
| 1031 |
| 1032 void WebTestProxyBase::DidFinishLoad(blink::WebLocalFrame* frame) { |
| 1033 if (test_interfaces_->GetTestRunner()->shouldDumpFrameLoadCallbacks()) { |
| 1034 PrintFrameDescription(delegate_, frame); |
| 1035 delegate_->PrintMessage(" - didFinishLoadForFrame\n"); |
| 1036 } |
| 1037 CheckDone(frame, LoadFinished); |
| 1038 } |
| 1039 |
| 1040 void WebTestProxyBase::DidDetectXSS(const blink::WebURL& insecure_url, |
| 1041 bool did_block_entire_page) { |
| 1042 if (test_interfaces_->GetTestRunner()->shouldDumpFrameLoadCallbacks()) |
| 1043 delegate_->PrintMessage("didDetectXSS\n"); |
| 1044 } |
| 1045 |
| 1046 void WebTestProxyBase::DidDispatchPingLoader(const blink::WebURL& url) { |
| 1047 if (test_interfaces_->GetTestRunner()->shouldDumpPingLoaderCallbacks()) |
| 1048 delegate_->PrintMessage(std::string("PingLoader dispatched to '") + |
| 1049 URLDescription(url).c_str() + "'.\n"); |
| 1050 } |
| 1051 |
| 1052 void WebTestProxyBase::WillSendRequest( |
| 1053 blink::WebLocalFrame* frame, |
| 1054 unsigned identifier, |
| 1055 blink::WebURLRequest& request, |
| 1056 const blink::WebURLResponse& redirect_response) { |
| 1057 // Need to use GURL for host() and SchemeIs() |
| 1058 GURL url = request.url(); |
| 1059 std::string request_url = url.possibly_invalid_spec(); |
| 1060 |
| 1061 GURL main_document_url = request.firstPartyForCookies(); |
| 1062 |
| 1063 if (redirect_response.isNull() && |
| 1064 (test_interfaces_->GetTestRunner()->shouldDumpResourceLoadCallbacks() || |
| 1065 test_interfaces_->GetTestRunner()->shouldDumpResourcePriorities())) { |
| 1066 DCHECK(resource_identifier_map_.find(identifier) == |
| 1067 resource_identifier_map_.end()); |
| 1068 resource_identifier_map_[identifier] = |
| 1069 DescriptionSuitableForTestResult(request_url); |
| 1070 } |
| 1071 |
| 1072 if (test_interfaces_->GetTestRunner()->shouldDumpResourceLoadCallbacks()) { |
| 1073 if (resource_identifier_map_.find(identifier) == |
| 1074 resource_identifier_map_.end()) |
| 1075 delegate_->PrintMessage("<unknown>"); |
| 1076 else |
| 1077 delegate_->PrintMessage(resource_identifier_map_[identifier]); |
| 1078 delegate_->PrintMessage(" - willSendRequest <NSURLRequest URL "); |
| 1079 delegate_->PrintMessage( |
| 1080 DescriptionSuitableForTestResult(request_url).c_str()); |
| 1081 delegate_->PrintMessage(", main document URL "); |
| 1082 delegate_->PrintMessage(URLDescription(main_document_url).c_str()); |
| 1083 delegate_->PrintMessage(", http method "); |
| 1084 delegate_->PrintMessage(request.httpMethod().utf8().data()); |
| 1085 delegate_->PrintMessage("> redirectResponse "); |
| 1086 PrintResponseDescription(delegate_, redirect_response); |
| 1087 delegate_->PrintMessage("\n"); |
| 1088 } |
| 1089 |
| 1090 if (test_interfaces_->GetTestRunner()->shouldDumpResourcePriorities()) { |
| 1091 delegate_->PrintMessage( |
| 1092 DescriptionSuitableForTestResult(request_url).c_str()); |
| 1093 delegate_->PrintMessage(" has priority "); |
| 1094 delegate_->PrintMessage(PriorityDescription(request.getPriority())); |
| 1095 delegate_->PrintMessage("\n"); |
| 1096 } |
| 1097 |
| 1098 if (test_interfaces_->GetTestRunner()->httpHeadersToClear()) { |
| 1099 const std::set<std::string>* clearHeaders = |
| 1100 test_interfaces_->GetTestRunner()->httpHeadersToClear(); |
| 1101 for (std::set<std::string>::const_iterator header = clearHeaders->begin(); |
| 1102 header != clearHeaders->end(); |
| 1103 ++header) |
| 1104 request.clearHTTPHeaderField(blink::WebString::fromUTF8(*header)); |
| 1105 } |
| 1106 |
| 1107 std::string host = url.host(); |
| 1108 if (!host.empty() && |
| 1109 (url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme))) { |
| 1110 if (!IsLocalHost(host) && !IsTestHost(host) && |
| 1111 !HostIsUsedBySomeTestsToGenerateError(host) && |
| 1112 ((!main_document_url.SchemeIs(url::kHttpScheme) && |
| 1113 !main_document_url.SchemeIs(url::kHttpsScheme)) || |
| 1114 IsLocalHost(main_document_url.host())) && |
| 1115 !delegate_->AllowExternalPages()) { |
| 1116 delegate_->PrintMessage(std::string("Blocked access to external URL ") + |
| 1117 request_url + "\n"); |
| 1118 BlockRequest(request); |
| 1119 return; |
| 1120 } |
| 1121 } |
| 1122 |
| 1123 // Set the new substituted URL. |
| 1124 request.setURL( |
| 1125 delegate_->RewriteLayoutTestsURL(request.url().string().utf8())); |
| 1126 } |
| 1127 |
| 1128 void WebTestProxyBase::DidReceiveResponse( |
| 1129 unsigned identifier, |
| 1130 const blink::WebURLResponse& response) { |
| 1131 if (test_interfaces_->GetTestRunner()->shouldDumpResourceLoadCallbacks()) { |
| 1132 if (resource_identifier_map_.find(identifier) == |
| 1133 resource_identifier_map_.end()) |
| 1134 delegate_->PrintMessage("<unknown>"); |
| 1135 else |
| 1136 delegate_->PrintMessage(resource_identifier_map_[identifier]); |
| 1137 delegate_->PrintMessage(" - didReceiveResponse "); |
| 1138 PrintResponseDescription(delegate_, response); |
| 1139 delegate_->PrintMessage("\n"); |
| 1140 } |
| 1141 if (test_interfaces_->GetTestRunner() |
| 1142 ->shouldDumpResourceResponseMIMETypes()) { |
| 1143 GURL url = response.url(); |
| 1144 blink::WebString mime_type = response.mimeType(); |
| 1145 delegate_->PrintMessage(url.ExtractFileName()); |
| 1146 delegate_->PrintMessage(" has MIME type "); |
| 1147 // Simulate NSURLResponse's mapping of empty/unknown MIME types to |
| 1148 // application/octet-stream |
| 1149 delegate_->PrintMessage(mime_type.isEmpty() ? "application/octet-stream" |
| 1150 : mime_type.utf8().data()); |
| 1151 delegate_->PrintMessage("\n"); |
| 1152 } |
| 1153 } |
| 1154 |
| 1155 void WebTestProxyBase::DidChangeResourcePriority( |
| 1156 unsigned identifier, |
| 1157 const blink::WebURLRequest::Priority& priority, |
| 1158 int intra_priority_value) { |
| 1159 if (test_interfaces_->GetTestRunner()->shouldDumpResourcePriorities()) { |
| 1160 if (resource_identifier_map_.find(identifier) == |
| 1161 resource_identifier_map_.end()) |
| 1162 delegate_->PrintMessage("<unknown>"); |
| 1163 else |
| 1164 delegate_->PrintMessage(resource_identifier_map_[identifier]); |
| 1165 delegate_->PrintMessage( |
| 1166 base::StringPrintf(" changed priority to %s, intra_priority %d\n", |
| 1167 PriorityDescription(priority).c_str(), |
| 1168 intra_priority_value)); |
| 1169 } |
| 1170 } |
| 1171 |
| 1172 void WebTestProxyBase::DidFinishResourceLoad(blink::WebLocalFrame* frame, |
| 1173 unsigned identifier) { |
| 1174 if (test_interfaces_->GetTestRunner()->shouldDumpResourceLoadCallbacks()) { |
| 1175 if (resource_identifier_map_.find(identifier) == |
| 1176 resource_identifier_map_.end()) |
| 1177 delegate_->PrintMessage("<unknown>"); |
| 1178 else |
| 1179 delegate_->PrintMessage(resource_identifier_map_[identifier]); |
| 1180 delegate_->PrintMessage(" - didFinishLoading\n"); |
| 1181 } |
| 1182 resource_identifier_map_.erase(identifier); |
| 1183 CheckDone(frame, ResourceLoadCompleted); |
| 1184 } |
| 1185 |
| 1186 void WebTestProxyBase::DidAddMessageToConsole( |
| 1187 const blink::WebConsoleMessage& message, |
| 1188 const blink::WebString& source_name, |
| 1189 unsigned source_line) { |
| 1190 // This matches win DumpRenderTree's UIDelegate.cpp. |
| 1191 if (!log_console_output_) |
| 1192 return; |
| 1193 std::string level; |
| 1194 switch (message.level) { |
| 1195 case blink::WebConsoleMessage::LevelDebug: |
| 1196 level = "DEBUG"; |
| 1197 break; |
| 1198 case blink::WebConsoleMessage::LevelLog: |
| 1199 level = "MESSAGE"; |
| 1200 break; |
| 1201 case blink::WebConsoleMessage::LevelInfo: |
| 1202 level = "INFO"; |
| 1203 break; |
| 1204 case blink::WebConsoleMessage::LevelWarning: |
| 1205 level = "WARNING"; |
| 1206 break; |
| 1207 case blink::WebConsoleMessage::LevelError: |
| 1208 level = "ERROR"; |
| 1209 break; |
| 1210 default: |
| 1211 level = "MESSAGE"; |
| 1212 } |
| 1213 delegate_->PrintMessage(std::string("CONSOLE ") + level + ": "); |
| 1214 if (source_line) { |
| 1215 delegate_->PrintMessage(base::StringPrintf("line %d: ", source_line)); |
| 1216 } |
| 1217 if (!message.text.isEmpty()) { |
| 1218 std::string new_message; |
| 1219 new_message = message.text.utf8(); |
| 1220 size_t file_protocol = new_message.find("file://"); |
| 1221 if (file_protocol != std::string::npos) { |
| 1222 new_message = new_message.substr(0, file_protocol) + |
| 1223 URLSuitableForTestResult(new_message.substr(file_protocol)); |
| 1224 } |
| 1225 delegate_->PrintMessage(new_message); |
| 1226 } |
| 1227 delegate_->PrintMessage(std::string("\n")); |
| 1228 } |
| 1229 |
| 1230 void WebTestProxyBase::CheckDone(blink::WebLocalFrame* frame, |
| 1231 CheckDoneReason reason) { |
| 1232 if (frame != test_interfaces_->GetTestRunner()->topLoadingFrame()) |
| 1233 return; |
| 1234 if (reason != MainResourceLoadFailed && |
| 1235 (frame->isResourceLoadInProgress() || frame->isLoading())) |
| 1236 return; |
| 1237 test_interfaces_->GetTestRunner()->setTopLoadingFrame(frame, true); |
| 1238 } |
| 1239 |
| 1240 blink::WebNavigationPolicy WebTestProxyBase::DecidePolicyForNavigation( |
| 1241 const blink::WebFrameClient::NavigationPolicyInfo& info) { |
| 1242 if (test_interfaces_->GetTestRunner()->shouldDumpNavigationPolicy()) { |
| 1243 delegate_->PrintMessage("Default policy for navigation to '" + |
| 1244 URLDescription(info.urlRequest.url()) + "' is '" + |
| 1245 WebNavigationPolicyToString(info.defaultPolicy) + |
| 1246 "'\n"); |
| 1247 } |
| 1248 |
| 1249 blink::WebNavigationPolicy result; |
| 1250 if (!test_interfaces_->GetTestRunner()->policyDelegateEnabled()) |
| 1251 return info.defaultPolicy; |
| 1252 |
| 1253 delegate_->PrintMessage( |
| 1254 std::string("Policy delegate: attempt to load ") + |
| 1255 URLDescription(info.urlRequest.url()) + " with navigation type '" + |
| 1256 WebNavigationTypeToString(info.navigationType) + "'\n"); |
| 1257 if (test_interfaces_->GetTestRunner()->policyDelegateIsPermissive()) |
| 1258 result = blink::WebNavigationPolicyCurrentTab; |
| 1259 else |
| 1260 result = blink::WebNavigationPolicyIgnore; |
| 1261 |
| 1262 if (test_interfaces_->GetTestRunner()->policyDelegateShouldNotifyDone()) { |
| 1263 test_interfaces_->GetTestRunner()->policyDelegateDone(); |
| 1264 result = blink::WebNavigationPolicyIgnore; |
| 1265 } |
| 1266 |
| 1267 return result; |
| 1268 } |
| 1269 |
| 1270 bool WebTestProxyBase::WillCheckAndDispatchMessageEvent( |
| 1271 blink::WebLocalFrame* source_frame, |
| 1272 blink::WebFrame* target_frame, |
| 1273 blink::WebSecurityOrigin target, |
| 1274 blink::WebDOMMessageEvent event) { |
| 1275 if (test_interfaces_->GetTestRunner()->shouldInterceptPostMessage()) { |
| 1276 delegate_->PrintMessage("intercepted postMessage\n"); |
| 1277 return true; |
| 1278 } |
| 1279 |
| 1280 return false; |
| 1281 } |
| 1282 |
| 522 void WebTestProxyBase::PostSpellCheckEvent(const blink::WebString& event_name) { | 1283 void WebTestProxyBase::PostSpellCheckEvent(const blink::WebString& event_name) { |
| 523 if (test_interfaces_->GetTestRunner()->shouldDumpSpellCheckCallbacks()) { | 1284 if (test_interfaces_->GetTestRunner()->shouldDumpSpellCheckCallbacks()) { |
| 524 delegate_->PrintMessage(std::string("SpellCheckEvent: ") + | 1285 delegate_->PrintMessage(std::string("SpellCheckEvent: ") + |
| 525 event_name.utf8().data() + "\n"); | 1286 event_name.utf8().data() + "\n"); |
| 526 } | 1287 } |
| 527 } | 1288 } |
| 528 | 1289 |
| 529 void WebTestProxyBase::ResetInputMethod() { | 1290 void WebTestProxyBase::ResetInputMethod() { |
| 530 // If a composition text exists, then we need to let the browser process | 1291 // If a composition text exists, then we need to let the browser process |
| 531 // to cancel the input method's ongoing composition session. | 1292 // to cancel the input method's ongoing composition session. |
| 532 if (web_widget_) | 1293 if (web_widget_) |
| 533 web_widget_->confirmComposition(); | 1294 web_widget_->confirmComposition(); |
| 534 } | 1295 } |
| 535 | 1296 |
| 1297 void WebTestProxyBase::CheckIfAudioSinkExistsAndIsAuthorized( |
| 1298 const blink::WebString& sink_id, |
| 1299 const blink::WebSecurityOrigin& security_origin, |
| 1300 blink::WebSetSinkIdCallbacks* web_callbacks) { |
| 1301 scoped_ptr<blink::WebSetSinkIdCallbacks> callback(web_callbacks); |
| 1302 std::string device_id = sink_id.utf8(); |
| 1303 if (device_id == "valid" || device_id.empty()) |
| 1304 callback->onSuccess(); |
| 1305 else if (device_id == "unauthorized") |
| 1306 callback->onError(blink::WebSetSinkIdError::NotAuthorized); |
| 1307 else |
| 1308 callback->onError(blink::WebSetSinkIdError::NotFound); |
| 1309 } |
| 1310 |
| 536 blink::WebString WebTestProxyBase::acceptLanguages() { | 1311 blink::WebString WebTestProxyBase::acceptLanguages() { |
| 537 return blink::WebString::fromUTF8(accept_languages_); | 1312 return blink::WebString::fromUTF8(accept_languages_); |
| 538 } | 1313 } |
| 539 | 1314 |
| 540 } // namespace test_runner | 1315 } // namespace test_runner |
| OLD | NEW |