| 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" | |
| 23 #include "components/test_runner/event_sender.h" | 22 #include "components/test_runner/event_sender.h" |
| 24 #include "components/test_runner/layout_dump.h" | |
| 25 #include "components/test_runner/mock_color_chooser.h" | |
| 26 #include "components/test_runner/mock_credential_manager_client.h" | 23 #include "components/test_runner/mock_credential_manager_client.h" |
| 27 #include "components/test_runner/mock_screen_orientation_client.h" | 24 #include "components/test_runner/mock_screen_orientation_client.h" |
| 28 #include "components/test_runner/mock_web_speech_recognizer.h" | 25 #include "components/test_runner/mock_web_speech_recognizer.h" |
| 29 #include "components/test_runner/mock_web_user_media_client.h" | |
| 30 #include "components/test_runner/spell_check_client.h" | 26 #include "components/test_runner/spell_check_client.h" |
| 27 #include "components/test_runner/test_common.h" |
| 31 #include "components/test_runner/test_interfaces.h" | 28 #include "components/test_runner/test_interfaces.h" |
| 32 #include "components/test_runner/test_plugin.h" | 29 #include "components/test_runner/test_plugin.h" |
| 33 #include "components/test_runner/test_runner.h" | 30 #include "components/test_runner/test_runner.h" |
| 34 #include "components/test_runner/web_test_delegate.h" | 31 #include "components/test_runner/web_test_delegate.h" |
| 35 #include "components/test_runner/web_test_interfaces.h" | 32 #include "components/test_runner/web_test_interfaces.h" |
| 36 #include "components/test_runner/web_test_runner.h" | 33 #include "components/test_runner/web_test_runner.h" |
| 37 // FIXME: Including platform_canvas.h here is a layering violation. | 34 // FIXME: Including platform_canvas.h here is a layering violation. |
| 38 #include "skia/ext/platform_canvas.h" | 35 #include "skia/ext/platform_canvas.h" |
| 39 #include "third_party/WebKit/public/platform/Platform.h" | 36 #include "third_party/WebKit/public/platform/Platform.h" |
| 40 #include "third_party/WebKit/public/platform/WebClipboard.h" | 37 #include "third_party/WebKit/public/platform/WebClipboard.h" |
| 41 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac
k.h" | 38 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac
k.h" |
| 42 #include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h" | 39 #include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h" |
| 43 #include "third_party/WebKit/public/platform/WebURLError.h" | 40 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 44 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 41 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 45 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 42 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 46 #include "third_party/WebKit/public/web/WebAXEnums.h" | 43 #include "third_party/WebKit/public/web/WebAXEnums.h" |
| 47 #include "third_party/WebKit/public/web/WebAXObject.h" | 44 #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" | |
| 50 #include "third_party/WebKit/public/web/WebDocument.h" | 45 #include "third_party/WebKit/public/web/WebDocument.h" |
| 51 #include "third_party/WebKit/public/web/WebElement.h" | 46 #include "third_party/WebKit/public/web/WebElement.h" |
| 52 #include "third_party/WebKit/public/web/WebHistoryItem.h" | 47 #include "third_party/WebKit/public/web/WebHistoryItem.h" |
| 53 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 48 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 54 #include "third_party/WebKit/public/web/WebNode.h" | 49 #include "third_party/WebKit/public/web/WebNode.h" |
| 55 #include "third_party/WebKit/public/web/WebPagePopup.h" | 50 #include "third_party/WebKit/public/web/WebPagePopup.h" |
| 56 #include "third_party/WebKit/public/web/WebPluginParams.h" | 51 #include "third_party/WebKit/public/web/WebPluginParams.h" |
| 57 #include "third_party/WebKit/public/web/WebPrintParams.h" | 52 #include "third_party/WebKit/public/web/WebPrintParams.h" |
| 58 #include "third_party/WebKit/public/web/WebRange.h" | 53 #include "third_party/WebKit/public/web/WebRange.h" |
| 59 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 54 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 typedef void (WebTestProxyBase::*CallbackMethodType)(); | 102 typedef void (WebTestProxyBase::*CallbackMethodType)(); |
| 108 HostMethodTask(WebTestProxyBase* object, CallbackMethodType callback) | 103 HostMethodTask(WebTestProxyBase* object, CallbackMethodType callback) |
| 109 : WebMethodTask<WebTestProxyBase>(object), callback_(callback) {} | 104 : WebMethodTask<WebTestProxyBase>(object), callback_(callback) {} |
| 110 | 105 |
| 111 void RunIfValid() override { (object_->*callback_)(); } | 106 void RunIfValid() override { (object_->*callback_)(); } |
| 112 | 107 |
| 113 private: | 108 private: |
| 114 CallbackMethodType callback_; | 109 CallbackMethodType callback_; |
| 115 }; | 110 }; |
| 116 | 111 |
| 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 | |
| 292 std::string DumpAllBackForwardLists(TestInterfaces* interfaces, | 112 std::string DumpAllBackForwardLists(TestInterfaces* interfaces, |
| 293 WebTestDelegate* delegate) { | 113 WebTestDelegate* delegate) { |
| 294 std::string result; | 114 std::string result; |
| 295 const std::vector<WebTestProxyBase*>& window_list = | 115 const std::vector<WebTestProxyBase*>& window_list = |
| 296 interfaces->GetWindowList(); | 116 interfaces->GetWindowList(); |
| 297 for (size_t i = 0; i < window_list.size(); ++i) | 117 for (size_t i = 0; i < window_list.size(); ++i) |
| 298 result.append(delegate->DumpHistoryForWindow(window_list.at(i))); | 118 result.append(delegate->DumpHistoryForWindow(window_list.at(i))); |
| 299 return result; | 119 return result; |
| 300 } | 120 } |
| 301 } | 121 } |
| 302 | 122 |
| 303 WebTestProxyBase::WebTestProxyBase() | 123 WebTestProxyBase::WebTestProxyBase() |
| 304 : test_interfaces_(NULL), | 124 : test_interfaces_(NULL), |
| 305 delegate_(NULL), | 125 delegate_(NULL), |
| 306 web_widget_(NULL), | 126 web_widget_(NULL), |
| 307 spellcheck_(new SpellCheckClient(this)), | 127 spellcheck_(new SpellCheckClient(this)) { |
| 308 chooser_count_(0) { | |
| 309 Reset(); | 128 Reset(); |
| 310 } | 129 } |
| 311 | 130 |
| 312 WebTestProxyBase::~WebTestProxyBase() { | 131 WebTestProxyBase::~WebTestProxyBase() { |
| 313 test_interfaces_->WindowClosed(this); | 132 test_interfaces_->WindowClosed(this); |
| 314 } | 133 } |
| 315 | 134 |
| 316 void WebTestProxyBase::SetInterfaces(WebTestInterfaces* interfaces) { | 135 void WebTestProxyBase::SetInterfaces(WebTestInterfaces* interfaces) { |
| 317 test_interfaces_ = interfaces->GetTestInterfaces(); | 136 test_interfaces_ = interfaces->GetTestInterfaces(); |
| 318 test_interfaces_->WindowOpened(this); | 137 test_interfaces_->WindowOpened(this); |
| 319 } | 138 } |
| 320 | 139 |
| 321 void WebTestProxyBase::SetDelegate(WebTestDelegate* delegate) { | 140 void WebTestProxyBase::SetDelegate(WebTestDelegate* delegate) { |
| 322 delegate_ = delegate; | 141 delegate_ = delegate; |
| 323 spellcheck_->SetDelegate(delegate); | 142 spellcheck_->SetDelegate(delegate); |
| 324 if (speech_recognizer_.get()) | 143 if (speech_recognizer_.get()) |
| 325 speech_recognizer_->SetDelegate(delegate); | 144 speech_recognizer_->SetDelegate(delegate); |
| 326 } | 145 } |
| 327 | 146 |
| 328 blink::WebView* WebTestProxyBase::GetWebView() const { | 147 blink::WebView* WebTestProxyBase::GetWebView() const { |
| 329 DCHECK(web_widget_); | 148 DCHECK(web_widget_); |
| 330 // TestRunner does not support popup widgets. So |web_widget|_ is always a | 149 // TestRunner does not support popup widgets. So |web_widget|_ is always a |
| 331 // WebView. | 150 // WebView. |
| 332 return static_cast<blink::WebView*>(web_widget_); | 151 return static_cast<blink::WebView*>(web_widget_); |
| 333 } | 152 } |
| 334 | 153 |
| 335 void WebTestProxyBase::Reset() { | 154 void WebTestProxyBase::Reset() { |
| 336 drag_image_.reset(); | 155 drag_image_.reset(); |
| 337 animate_scheduled_ = false; | 156 animate_scheduled_ = false; |
| 338 resource_identifier_map_.clear(); | |
| 339 log_console_output_ = true; | |
| 340 accept_languages_ = ""; | 157 accept_languages_ = ""; |
| 341 } | 158 } |
| 342 | 159 |
| 343 blink::WebSpellCheckClient* WebTestProxyBase::GetSpellCheckClient() const { | 160 blink::WebSpellCheckClient* WebTestProxyBase::GetSpellCheckClient() const { |
| 344 return spellcheck_.get(); | 161 return spellcheck_.get(); |
| 345 } | 162 } |
| 346 | 163 |
| 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 | |
| 355 bool WebTestProxyBase::RunFileChooser( | 164 bool WebTestProxyBase::RunFileChooser( |
| 356 const blink::WebFileChooserParams& params, | 165 const blink::WebFileChooserParams& params, |
| 357 blink::WebFileChooserCompletion* completion) { | 166 blink::WebFileChooserCompletion* completion) { |
| 358 delegate_->PrintMessage("Mock: Opening a file chooser.\n"); | 167 delegate_->PrintMessage("Mock: Opening a file chooser.\n"); |
| 359 // FIXME: Add ability to set file names to a file upload control. | 168 // FIXME: Add ability to set file names to a file upload control. |
| 360 return false; | 169 return false; |
| 361 } | 170 } |
| 362 | 171 |
| 363 void WebTestProxyBase::ShowValidationMessage( | 172 void WebTestProxyBase::ShowValidationMessage( |
| 364 const blink::WebString& main_message, | 173 const blink::WebString& main_message, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 383 } else if (sub_message_hint == blink::WebTextDirectionRightToLeft) { | 192 } else if (sub_message_hint == blink::WebTextDirectionRightToLeft) { |
| 384 base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text); | 193 base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text); |
| 385 } | 194 } |
| 386 } | 195 } |
| 387 delegate_->PrintMessage("ValidationMessageClient: main-message=" + | 196 delegate_->PrintMessage("ValidationMessageClient: main-message=" + |
| 388 base::UTF16ToUTF8(wrapped_main_text) + | 197 base::UTF16ToUTF8(wrapped_main_text) + |
| 389 " sub-message=" + | 198 " sub-message=" + |
| 390 base::UTF16ToUTF8(wrapped_sub_text) + "\n"); | 199 base::UTF16ToUTF8(wrapped_sub_text) + "\n"); |
| 391 } | 200 } |
| 392 | 201 |
| 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 | |
| 420 std::string WebTestProxyBase::DumpBackForwardLists() { | 202 std::string WebTestProxyBase::DumpBackForwardLists() { |
| 421 return DumpAllBackForwardLists(test_interfaces_, delegate_); | 203 return DumpAllBackForwardLists(test_interfaces_, delegate_); |
| 422 } | 204 } |
| 423 | 205 |
| 424 void WebTestProxyBase::DrawSelectionRect(SkCanvas* canvas) { | 206 void WebTestProxyBase::DrawSelectionRect(SkCanvas* canvas) { |
| 425 // See if we need to draw the selection bounds rect. Selection bounds | 207 // See if we need to draw the selection bounds rect. Selection bounds |
| 426 // rect is the rect enclosing the (possibly transformed) selection. | 208 // rect is the rect enclosing the (possibly transformed) selection. |
| 427 // The rect should be drawn after everything is laid out and painted. | 209 // The rect should be drawn after everything is laid out and painted. |
| 428 if (!test_interfaces_->GetTestRunner()->shouldDumpSelectionRect()) | 210 if (!test_interfaces_->GetTestRunner()->shouldDumpSelectionRect()) |
| 429 return; | 211 return; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 | 352 |
| 571 void WebTestProxyBase::DidCapturePixelsAsync( | 353 void WebTestProxyBase::DidCapturePixelsAsync( |
| 572 const base::Callback<void(const SkBitmap&)>& callback, | 354 const base::Callback<void(const SkBitmap&)>& callback, |
| 573 const SkBitmap& bitmap) { | 355 const SkBitmap& bitmap) { |
| 574 SkCanvas canvas(bitmap); | 356 SkCanvas canvas(bitmap); |
| 575 DrawSelectionRect(&canvas); | 357 DrawSelectionRect(&canvas); |
| 576 if (!callback.is_null()) | 358 if (!callback.is_null()) |
| 577 callback.Run(bitmap); | 359 callback.Run(bitmap); |
| 578 } | 360 } |
| 579 | 361 |
| 580 void WebTestProxyBase::SetLogConsoleOutput(bool enabled) { | |
| 581 log_console_output_ = enabled; | |
| 582 } | |
| 583 | |
| 584 void LayoutAndPaintCallback::didLayoutAndPaint() { | 362 void LayoutAndPaintCallback::didLayoutAndPaint() { |
| 585 TRACE_EVENT0("shell", "LayoutAndPaintCallback::didLayoutAndPaint"); | 363 TRACE_EVENT0("shell", "LayoutAndPaintCallback::didLayoutAndPaint"); |
| 586 if (wait_for_popup_) { | 364 if (wait_for_popup_) { |
| 587 wait_for_popup_ = false; | 365 wait_for_popup_ = false; |
| 588 return; | 366 return; |
| 589 } | 367 } |
| 590 | 368 |
| 591 if (!callback_.is_null()) | 369 if (!callback_.is_null()) |
| 592 callback_.Run(); | 370 callback_.Run(); |
| 593 delete this; | 371 delete this; |
| 594 } | 372 } |
| 595 | 373 |
| 596 void WebTestProxyBase::LayoutAndPaintAsyncThen(const base::Closure& callback) { | 374 void WebTestProxyBase::LayoutAndPaintAsyncThen(const base::Closure& callback) { |
| 597 TRACE_EVENT0("shell", "WebTestProxyBase::LayoutAndPaintAsyncThen"); | 375 TRACE_EVENT0("shell", "WebTestProxyBase::LayoutAndPaintAsyncThen"); |
| 598 | 376 |
| 599 LayoutAndPaintCallback* layout_and_paint_callback = | 377 LayoutAndPaintCallback* layout_and_paint_callback = |
| 600 new LayoutAndPaintCallback(callback); | 378 new LayoutAndPaintCallback(callback); |
| 601 web_widget_->layoutAndPaintAsync(layout_and_paint_callback); | 379 web_widget_->layoutAndPaintAsync(layout_and_paint_callback); |
| 602 if (blink::WebPagePopup* popup = web_widget_->pagePopup()) { | 380 if (blink::WebPagePopup* popup = web_widget_->pagePopup()) { |
| 603 layout_and_paint_callback->set_wait_for_popup(true); | 381 layout_and_paint_callback->set_wait_for_popup(true); |
| 604 popup->layoutAndPaintAsync(layout_and_paint_callback); | 382 popup->layoutAndPaintAsync(layout_and_paint_callback); |
| 605 } | 383 } |
| 606 } | 384 } |
| 607 | 385 |
| 608 void WebTestProxyBase::GetScreenOrientationForTesting( | 386 void WebTestProxyBase::GetScreenOrientationForTesting( |
| 609 blink::WebScreenInfo& screen_info) { | 387 blink::WebScreenInfo& screen_info) { |
| 610 MockScreenOrientationClient* mock_client = GetScreenOrientationClientMock(); | 388 MockScreenOrientationClient* mock_client = |
| 389 test_interfaces_->GetTestRunner()->getMockScreenOrientationClient(); |
| 611 if (mock_client->IsDisabled()) | 390 if (mock_client->IsDisabled()) |
| 612 return; | 391 return; |
| 613 // Override screen orientation information with mock data. | 392 // Override screen orientation information with mock data. |
| 614 screen_info.orientationType = mock_client->CurrentOrientationType(); | 393 screen_info.orientationType = mock_client->CurrentOrientationType(); |
| 615 screen_info.orientationAngle = mock_client->CurrentOrientationAngle(); | 394 screen_info.orientationAngle = mock_client->CurrentOrientationAngle(); |
| 616 } | 395 } |
| 617 | 396 |
| 618 MockScreenOrientationClient* | |
| 619 WebTestProxyBase::GetScreenOrientationClientMock() { | |
| 620 return test_interfaces_->GetTestRunner()->getMockScreenOrientationClient(); | |
| 621 } | |
| 622 | |
| 623 MockWebSpeechRecognizer* WebTestProxyBase::GetSpeechRecognizerMock() { | 397 MockWebSpeechRecognizer* WebTestProxyBase::GetSpeechRecognizerMock() { |
| 624 if (!speech_recognizer_.get()) { | 398 if (!speech_recognizer_.get()) { |
| 625 speech_recognizer_.reset(new MockWebSpeechRecognizer()); | 399 speech_recognizer_.reset(new MockWebSpeechRecognizer()); |
| 626 speech_recognizer_->SetDelegate(delegate_); | 400 speech_recognizer_->SetDelegate(delegate_); |
| 627 } | 401 } |
| 628 return speech_recognizer_.get(); | 402 return speech_recognizer_.get(); |
| 629 } | 403 } |
| 630 | 404 |
| 631 MockCredentialManagerClient* | 405 MockCredentialManagerClient* |
| 632 WebTestProxyBase::GetCredentialManagerClientMock() { | 406 WebTestProxyBase::GetCredentialManagerClientMock() { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 652 animate_scheduled_ = false; | 426 animate_scheduled_ = false; |
| 653 web_widget_->beginFrame(animate_time.InSecondsF()); | 427 web_widget_->beginFrame(animate_time.InSecondsF()); |
| 654 web_widget_->updateAllLifecyclePhases(); | 428 web_widget_->updateAllLifecyclePhases(); |
| 655 if (blink::WebPagePopup* popup = web_widget_->pagePopup()) { | 429 if (blink::WebPagePopup* popup = web_widget_->pagePopup()) { |
| 656 popup->beginFrame(animate_time.InSecondsF()); | 430 popup->beginFrame(animate_time.InSecondsF()); |
| 657 popup->updateAllLifecyclePhases(); | 431 popup->updateAllLifecyclePhases(); |
| 658 } | 432 } |
| 659 } | 433 } |
| 660 } | 434 } |
| 661 | 435 |
| 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 | |
| 797 void WebTestProxyBase::StartDragging(blink::WebLocalFrame* frame, | 436 void WebTestProxyBase::StartDragging(blink::WebLocalFrame* frame, |
| 798 const blink::WebDragData& data, | 437 const blink::WebDragData& data, |
| 799 blink::WebDragOperationsMask mask, | 438 blink::WebDragOperationsMask mask, |
| 800 const blink::WebImage& image, | 439 const blink::WebImage& image, |
| 801 const blink::WebPoint& point) { | 440 const blink::WebPoint& point) { |
| 802 if (test_interfaces_->GetTestRunner()->shouldDumpDragImage()) { | 441 if (test_interfaces_->GetTestRunner()->shouldDumpDragImage()) { |
| 803 if (drag_image_.isNull()) | 442 if (drag_image_.isNull()) |
| 804 drag_image_ = image; | 443 drag_image_ = image; |
| 805 } | 444 } |
| 806 // When running a test, we need to fake a drag drop operation otherwise | 445 // When running a test, we need to fake a drag drop operation otherwise |
| 807 // Windows waits for real mouse events to know when the drag is over. | 446 // Windows waits for real mouse events to know when the drag is over. |
| 808 test_interfaces_->GetEventSender()->DoDragDrop(data, mask); | 447 test_interfaces_->GetEventSender()->DoDragDrop(data, mask); |
| 809 } | 448 } |
| 810 | 449 |
| 811 // The output from these methods in layout test mode should match that | 450 // The output from these methods in layout test mode should match that |
| 812 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree. | 451 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree. |
| 813 | 452 |
| 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 | |
| 821 void WebTestProxyBase::DidChangeContents() { | 453 void WebTestProxyBase::DidChangeContents() { |
| 822 if (test_interfaces_->GetTestRunner()->shouldDumpEditingCallbacks()) | 454 if (test_interfaces_->GetTestRunner()->shouldDumpEditingCallbacks()) |
| 823 delegate_->PrintMessage( | 455 delegate_->PrintMessage( |
| 824 "EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n"); | 456 "EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n"); |
| 825 } | 457 } |
| 826 | 458 |
| 827 bool WebTestProxyBase::CreateView(blink::WebLocalFrame* frame, | 459 bool WebTestProxyBase::CreateView(blink::WebLocalFrame* frame, |
| 828 const blink::WebURLRequest& request, | 460 const blink::WebURLRequest& request, |
| 829 const blink::WebWindowFeatures& features, | 461 const blink::WebWindowFeatures& features, |
| 830 const blink::WebString& frame_name, | 462 const blink::WebString& frame_name, |
| 831 blink::WebNavigationPolicy policy, | 463 blink::WebNavigationPolicy policy, |
| 832 bool suppress_opener) { | 464 bool suppress_opener) { |
| 833 if (test_interfaces_->GetTestRunner()->shouldDumpNavigationPolicy()) { | 465 if (test_interfaces_->GetTestRunner()->shouldDumpNavigationPolicy()) { |
| 834 delegate_->PrintMessage("Default policy for createView for '" + | 466 delegate_->PrintMessage("Default policy for createView for '" + |
| 835 URLDescription(request.url()) + "' is '" + | 467 URLDescription(request.url()) + "' is '" + |
| 836 WebNavigationPolicyToString(policy) + "'\n"); | 468 WebNavigationPolicyToString(policy) + "'\n"); |
| 837 } | 469 } |
| 838 | 470 |
| 839 if (!test_interfaces_->GetTestRunner()->canOpenWindows()) | 471 if (!test_interfaces_->GetTestRunner()->canOpenWindows()) |
| 840 return false; | 472 return false; |
| 841 if (test_interfaces_->GetTestRunner()->shouldDumpCreateView()) | 473 if (test_interfaces_->GetTestRunner()->shouldDumpCreateView()) |
| 842 delegate_->PrintMessage(std::string("createView(") + | 474 delegate_->PrintMessage(std::string("createView(") + |
| 843 URLDescription(request.url()) + ")\n"); | 475 URLDescription(request.url()) + ")\n"); |
| 844 return true; | 476 return true; |
| 845 } | 477 } |
| 846 | 478 |
| 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 | |
| 855 void WebTestProxyBase::SetStatusText(const blink::WebString& text) { | 479 void WebTestProxyBase::SetStatusText(const blink::WebString& text) { |
| 856 if (!test_interfaces_->GetTestRunner()->shouldDumpStatusCallbacks()) | 480 if (!test_interfaces_->GetTestRunner()->shouldDumpStatusCallbacks()) |
| 857 return; | 481 return; |
| 858 delegate_->PrintMessage( | 482 delegate_->PrintMessage( |
| 859 std::string("UI DELEGATE STATUS CALLBACK: setStatusText:") + | 483 std::string("UI DELEGATE STATUS CALLBACK: setStatusText:") + |
| 860 text.utf8().data() + "\n"); | 484 text.utf8().data() + "\n"); |
| 861 } | 485 } |
| 862 | 486 |
| 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 | |
| 874 // Simulate a print by going into print mode and then exit straight away. | 487 // Simulate a print by going into print mode and then exit straight away. |
| 875 void WebTestProxyBase::PrintPage(blink::WebLocalFrame* frame) { | 488 void WebTestProxyBase::PrintPage(blink::WebLocalFrame* frame) { |
| 876 blink::WebSize page_size_in_pixels = web_widget_->size(); | 489 blink::WebSize page_size_in_pixels = web_widget_->size(); |
| 877 if (page_size_in_pixels.isEmpty()) | 490 if (page_size_in_pixels.isEmpty()) |
| 878 return; | 491 return; |
| 879 blink::WebPrintParams printParams(page_size_in_pixels); | 492 blink::WebPrintParams printParams(page_size_in_pixels); |
| 880 frame->printBegin(printParams); | 493 frame->printBegin(printParams); |
| 881 frame->printEnd(); | 494 frame->printEnd(); |
| 882 } | 495 } |
| 883 | 496 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 899 | 512 |
| 900 void WebTestProxyBase::DidFocus() { | 513 void WebTestProxyBase::DidFocus() { |
| 901 delegate_->SetFocus(this, true); | 514 delegate_->SetFocus(this, true); |
| 902 } | 515 } |
| 903 | 516 |
| 904 void WebTestProxyBase::SetToolTipText(const blink::WebString& text, | 517 void WebTestProxyBase::SetToolTipText(const blink::WebString& text, |
| 905 blink::WebTextDirection direction) { | 518 blink::WebTextDirection direction) { |
| 906 test_interfaces_->GetTestRunner()->setToolTipText(text); | 519 test_interfaces_->GetTestRunner()->setToolTipText(text); |
| 907 } | 520 } |
| 908 | 521 |
| 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 | |
| 1283 void WebTestProxyBase::PostSpellCheckEvent(const blink::WebString& event_name) { | 522 void WebTestProxyBase::PostSpellCheckEvent(const blink::WebString& event_name) { |
| 1284 if (test_interfaces_->GetTestRunner()->shouldDumpSpellCheckCallbacks()) { | 523 if (test_interfaces_->GetTestRunner()->shouldDumpSpellCheckCallbacks()) { |
| 1285 delegate_->PrintMessage(std::string("SpellCheckEvent: ") + | 524 delegate_->PrintMessage(std::string("SpellCheckEvent: ") + |
| 1286 event_name.utf8().data() + "\n"); | 525 event_name.utf8().data() + "\n"); |
| 1287 } | 526 } |
| 1288 } | 527 } |
| 1289 | 528 |
| 1290 void WebTestProxyBase::ResetInputMethod() { | 529 void WebTestProxyBase::ResetInputMethod() { |
| 1291 // If a composition text exists, then we need to let the browser process | 530 // If a composition text exists, then we need to let the browser process |
| 1292 // to cancel the input method's ongoing composition session. | 531 // to cancel the input method's ongoing composition session. |
| 1293 if (web_widget_) | 532 if (web_widget_) |
| 1294 web_widget_->confirmComposition(); | 533 web_widget_->confirmComposition(); |
| 1295 } | 534 } |
| 1296 | 535 |
| 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 | |
| 1311 blink::WebString WebTestProxyBase::acceptLanguages() { | 536 blink::WebString WebTestProxyBase::acceptLanguages() { |
| 1312 return blink::WebString::fromUTF8(accept_languages_); | 537 return blink::WebString::fromUTF8(accept_languages_); |
| 1313 } | 538 } |
| 1314 | 539 |
| 1315 } // namespace test_runner | 540 } // namespace test_runner |
| OLD | NEW |