| 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/accessibility_controller.h" |
| 23 #include "components/test_runner/event_sender.h" | 23 #include "components/test_runner/event_sender.h" |
| 24 #include "components/test_runner/layout_dump.h" |
| 24 #include "components/test_runner/mock_color_chooser.h" | 25 #include "components/test_runner/mock_color_chooser.h" |
| 25 #include "components/test_runner/mock_credential_manager_client.h" | 26 #include "components/test_runner/mock_credential_manager_client.h" |
| 26 #include "components/test_runner/mock_screen_orientation_client.h" | 27 #include "components/test_runner/mock_screen_orientation_client.h" |
| 27 #include "components/test_runner/mock_web_speech_recognizer.h" | 28 #include "components/test_runner/mock_web_speech_recognizer.h" |
| 28 #include "components/test_runner/mock_web_user_media_client.h" | 29 #include "components/test_runner/mock_web_user_media_client.h" |
| 29 #include "components/test_runner/spell_check_client.h" | 30 #include "components/test_runner/spell_check_client.h" |
| 30 #include "components/test_runner/test_interfaces.h" | 31 #include "components/test_runner/test_interfaces.h" |
| 31 #include "components/test_runner/test_plugin.h" | 32 #include "components/test_runner/test_plugin.h" |
| 32 #include "components/test_runner/test_runner.h" | 33 #include "components/test_runner/test_runner.h" |
| 33 #include "components/test_runner/web_test_delegate.h" | 34 #include "components/test_runner/web_test_delegate.h" |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 return kPolicyNewForegroundTab; | 283 return kPolicyNewForegroundTab; |
| 283 case blink::WebNavigationPolicyNewWindow: | 284 case blink::WebNavigationPolicyNewWindow: |
| 284 return kPolicyNewWindow; | 285 return kPolicyNewWindow; |
| 285 case blink::WebNavigationPolicyNewPopup: | 286 case blink::WebNavigationPolicyNewPopup: |
| 286 return kPolicyNewPopup; | 287 return kPolicyNewPopup; |
| 287 default: | 288 default: |
| 288 return kIllegalString; | 289 return kIllegalString; |
| 289 } | 290 } |
| 290 } | 291 } |
| 291 | 292 |
| 292 std::string DumpFrameHeaderIfNeeded(blink::WebFrame* frame) { | 293 std::string DumpDeepLayout(blink::WebFrame* frame, |
| 293 std::string result; | 294 LayoutDumpFlags flags, |
| 294 | 295 bool recursive) { |
| 295 // Add header for all but the main frame. Skip empty frames. | 296 std::string result = DumpLayout(frame->toWebLocalFrame(), flags); |
| 296 if (frame->parent() && !frame->document().documentElement().isNull()) { | |
| 297 result.append("\n--------\nFrame: '"); | |
| 298 result.append(frame->uniqueName().utf8().data()); | |
| 299 result.append("'\n--------\n"); | |
| 300 } | |
| 301 | |
| 302 return result; | |
| 303 } | |
| 304 | |
| 305 std::string DumpFramesAsMarkup(blink::WebFrame* frame, bool recursive) { | |
| 306 std::string result = DumpFrameHeaderIfNeeded(frame); | |
| 307 result.append(frame->contentAsMarkup().utf8()); | |
| 308 result.append("\n"); | |
| 309 | 297 |
| 310 if (recursive) { | 298 if (recursive) { |
| 311 for (blink::WebFrame* child = frame->firstChild(); child; | 299 for (blink::WebFrame* child = frame->firstChild(); child; |
| 312 child = child->nextSibling()) | 300 child = child->nextSibling()) |
| 313 result.append(DumpFramesAsMarkup(child, recursive)); | 301 result.append(DumpDeepLayout(child, flags, recursive)); |
| 314 } | 302 } |
| 315 | 303 |
| 316 return result; | 304 return result; |
| 317 } | 305 } |
| 318 | 306 |
| 319 std::string DumpDocumentText(blink::WebFrame* frame) { | |
| 320 return frame->document().contentAsTextForTesting().utf8(); | |
| 321 } | |
| 322 | |
| 323 std::string DumpFramesAsText(blink::WebFrame* frame, bool recursive) { | |
| 324 std::string result = DumpFrameHeaderIfNeeded(frame); | |
| 325 result.append(DumpDocumentText(frame)); | |
| 326 result.append("\n"); | |
| 327 | |
| 328 if (recursive) { | |
| 329 for (blink::WebFrame* child = frame->firstChild(); child; | |
| 330 child = child->nextSibling()) | |
| 331 result.append(DumpFramesAsText(child, recursive)); | |
| 332 } | |
| 333 | |
| 334 return result; | |
| 335 } | |
| 336 | |
| 337 std::string DumpFramesAsPrintedText(blink::WebFrame* frame, bool recursive) { | |
| 338 // Cannot do printed format for anything other than HTML | |
| 339 if (!frame->document().isHTMLDocument()) | |
| 340 return std::string(); | |
| 341 | |
| 342 std::string result = DumpFrameHeaderIfNeeded(frame); | |
| 343 result.append( | |
| 344 frame->layoutTreeAsText(blink::WebFrame::LayoutAsTextPrinting).utf8()); | |
| 345 result.append("\n"); | |
| 346 | |
| 347 if (recursive) { | |
| 348 for (blink::WebFrame* child = frame->firstChild(); child; | |
| 349 child = child->nextSibling()) | |
| 350 result.append(DumpFramesAsPrintedText(child, recursive)); | |
| 351 } | |
| 352 | |
| 353 return result; | |
| 354 } | |
| 355 | |
| 356 std::string DumpFrameScrollPosition(blink::WebFrame* frame, bool recursive) { | |
| 357 std::string result; | |
| 358 blink::WebSize offset = frame->scrollOffset(); | |
| 359 if (offset.width > 0 || offset.height > 0) { | |
| 360 if (frame->parent()) { | |
| 361 result = | |
| 362 std::string("frame '") + frame->uniqueName().utf8().data() + "' "; | |
| 363 } | |
| 364 base::StringAppendF( | |
| 365 &result, "scrolled to %d,%d\n", offset.width, offset.height); | |
| 366 } | |
| 367 | |
| 368 if (!recursive) | |
| 369 return result; | |
| 370 for (blink::WebFrame* child = frame->firstChild(); child; | |
| 371 child = child->nextSibling()) | |
| 372 result += DumpFrameScrollPosition(child, recursive); | |
| 373 return result; | |
| 374 } | |
| 375 | |
| 376 std::string DumpAllBackForwardLists(TestInterfaces* interfaces, | 307 std::string DumpAllBackForwardLists(TestInterfaces* interfaces, |
| 377 WebTestDelegate* delegate) { | 308 WebTestDelegate* delegate) { |
| 378 std::string result; | 309 std::string result; |
| 379 const std::vector<WebTestProxyBase*>& window_list = | 310 const std::vector<WebTestProxyBase*>& window_list = |
| 380 interfaces->GetWindowList(); | 311 interfaces->GetWindowList(); |
| 381 for (size_t i = 0; i < window_list.size(); ++i) | 312 for (size_t i = 0; i < window_list.size(); ++i) |
| 382 result.append(delegate->DumpHistoryForWindow(window_list.at(i))); | 313 result.append(delegate->DumpHistoryForWindow(window_list.at(i))); |
| 383 return result; | 314 return result; |
| 384 } | 315 } |
| 385 } | 316 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 } | 412 } |
| 482 delegate_->PrintMessage("ValidationMessageClient: main-message=" + | 413 delegate_->PrintMessage("ValidationMessageClient: main-message=" + |
| 483 base::UTF16ToUTF8(wrapped_main_text) + | 414 base::UTF16ToUTF8(wrapped_main_text) + |
| 484 " sub-message=" + | 415 " sub-message=" + |
| 485 base::UTF16ToUTF8(wrapped_sub_text) + "\n"); | 416 base::UTF16ToUTF8(wrapped_sub_text) + "\n"); |
| 486 } | 417 } |
| 487 | 418 |
| 488 std::string WebTestProxyBase::CaptureTree( | 419 std::string WebTestProxyBase::CaptureTree( |
| 489 bool debug_render_tree, | 420 bool debug_render_tree, |
| 490 bool dump_line_box_trees) { | 421 bool dump_line_box_trees) { |
| 491 bool should_dump_custom_text = | 422 TestRunner* test_runner = test_interfaces_->GetTestRunner(); |
| 492 test_interfaces_->GetTestRunner()->shouldDumpAsCustomText(); | |
| 493 bool should_dump_as_text = | |
| 494 test_interfaces_->GetTestRunner()->shouldDumpAsText(); | |
| 495 bool should_dump_as_markup = | |
| 496 test_interfaces_->GetTestRunner()->shouldDumpAsMarkup(); | |
| 497 bool should_dump_as_printed = test_interfaces_->GetTestRunner()->isPrinting(); | |
| 498 blink::WebFrame* frame = GetWebView()->mainFrame(); | 423 blink::WebFrame* frame = GetWebView()->mainFrame(); |
| 499 std::string data_utf8; | 424 std::string data_utf8; |
| 500 if (should_dump_custom_text) { | 425 if (test_runner->shouldDumpAsCustomText()) { |
| 501 // Append a newline for the test driver. | 426 // Append a newline for the test driver. |
| 502 data_utf8 = test_interfaces_->GetTestRunner()->customDumpText() + "\n"; | 427 data_utf8 = test_interfaces_->GetTestRunner()->customDumpText() + "\n"; |
| 503 } else if (should_dump_as_text) { | |
| 504 bool recursive = | |
| 505 test_interfaces_->GetTestRunner()->shouldDumpChildFramesAsText(); | |
| 506 data_utf8 = should_dump_as_printed ? | |
| 507 DumpFramesAsPrintedText(frame, recursive) : | |
| 508 DumpFramesAsText(frame, recursive); | |
| 509 } else if (should_dump_as_markup) { | |
| 510 bool recursive = | |
| 511 test_interfaces_->GetTestRunner()->shouldDumpChildFramesAsMarkup(); | |
| 512 // Append a newline for the test driver. | |
| 513 data_utf8 = DumpFramesAsMarkup(frame, recursive); | |
| 514 } else { | 428 } else { |
| 515 bool recursive = test_interfaces_->GetTestRunner() | 429 LayoutDumpFlags flags = test_runner->GetLayoutDumpFlags(); |
| 516 ->shouldDumpChildFrameScrollPositions(); | 430 data_utf8 = DumpDeepLayout(frame, flags, flags.dump_child_frames); |
| 517 blink::WebFrame::LayoutAsTextControls layout_text_behavior = | |
| 518 blink::WebFrame::LayoutAsTextNormal; | |
| 519 if (should_dump_as_printed) | |
| 520 layout_text_behavior |= blink::WebFrame::LayoutAsTextPrinting; | |
| 521 if (debug_render_tree) | |
| 522 layout_text_behavior |= blink::WebFrame::LayoutAsTextDebug; | |
| 523 if (dump_line_box_trees) | |
| 524 layout_text_behavior |= blink::WebFrame::LayoutAsTextWithLineTrees; | |
| 525 data_utf8 = frame->layoutTreeAsText(layout_text_behavior).utf8(); | |
| 526 data_utf8 += DumpFrameScrollPosition(frame, recursive); | |
| 527 } | 431 } |
| 528 | 432 |
| 529 if (test_interfaces_->GetTestRunner()->ShouldDumpBackForwardList()) | 433 if (test_interfaces_->GetTestRunner()->ShouldDumpBackForwardList()) |
| 530 data_utf8 += DumpAllBackForwardLists(test_interfaces_, delegate_); | 434 data_utf8 += DumpBackForwardLists(); |
| 531 | 435 |
| 532 return data_utf8; | 436 return data_utf8; |
| 533 } | 437 } |
| 534 | 438 |
| 439 std::string WebTestProxyBase::DumpBackForwardLists() { |
| 440 return DumpAllBackForwardLists(test_interfaces_, delegate_); |
| 441 } |
| 442 |
| 535 void WebTestProxyBase::DrawSelectionRect(SkCanvas* canvas) { | 443 void WebTestProxyBase::DrawSelectionRect(SkCanvas* canvas) { |
| 536 // See if we need to draw the selection bounds rect. Selection bounds | 444 // See if we need to draw the selection bounds rect. Selection bounds |
| 537 // rect is the rect enclosing the (possibly transformed) selection. | 445 // rect is the rect enclosing the (possibly transformed) selection. |
| 538 // The rect should be drawn after everything is laid out and painted. | 446 // The rect should be drawn after everything is laid out and painted. |
| 539 if (!test_interfaces_->GetTestRunner()->shouldDumpSelectionRect()) | 447 if (!test_interfaces_->GetTestRunner()->shouldDumpSelectionRect()) |
| 540 return; | 448 return; |
| 541 // If there is a selection rect - draw a red 1px border enclosing rect | 449 // If there is a selection rect - draw a red 1px border enclosing rect |
| 542 blink::WebRect wr = GetWebView()->mainFrame()->selectionBoundsRect(); | 450 blink::WebRect wr = GetWebView()->mainFrame()->selectionBoundsRect(); |
| 543 if (wr.isEmpty()) | 451 if (wr.isEmpty()) |
| 544 return; | 452 return; |
| (...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 callback->onError(blink::WebSetSinkIdError::NotAuthorized); | 1333 callback->onError(blink::WebSetSinkIdError::NotAuthorized); |
| 1426 else | 1334 else |
| 1427 callback->onError(blink::WebSetSinkIdError::NotFound); | 1335 callback->onError(blink::WebSetSinkIdError::NotFound); |
| 1428 } | 1336 } |
| 1429 | 1337 |
| 1430 blink::WebString WebTestProxyBase::acceptLanguages() { | 1338 blink::WebString WebTestProxyBase::acceptLanguages() { |
| 1431 return blink::WebString::fromUTF8(accept_languages_); | 1339 return blink::WebString::fromUTF8(accept_languages_); |
| 1432 } | 1340 } |
| 1433 | 1341 |
| 1434 } // namespace test_runner | 1342 } // namespace test_runner |
| OLD | NEW |