| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/test_runner/layout_dump.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/strings/stringprintf.h" | |
| 9 #include "third_party/WebKit/public/platform/WebSize.h" | |
| 10 #include "third_party/WebKit/public/platform/WebString.h" | |
| 11 #include "third_party/WebKit/public/web/WebDocument.h" | |
| 12 #include "third_party/WebKit/public/web/WebElement.h" | |
| 13 #include "third_party/WebKit/public/web/WebFrame.h" | |
| 14 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" | |
| 15 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
| 16 | |
| 17 namespace test_runner { | |
| 18 | |
| 19 using blink::WebFrame; | |
| 20 using blink::WebFrameContentDumper; | |
| 21 using blink::WebLocalFrame; | |
| 22 using blink::WebSize; | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 std::string DumpFrameHeaderIfNeeded(WebFrame* frame) { | |
| 27 std::string result; | |
| 28 | |
| 29 // Add header for all but the main frame. Skip empty frames. | |
| 30 if (frame->parent() && !frame->document().documentElement().isNull()) { | |
| 31 result.append("\n--------\nFrame: '"); | |
| 32 result.append(frame->uniqueName().utf8()); | |
| 33 result.append("'\n--------\n"); | |
| 34 } | |
| 35 | |
| 36 return result; | |
| 37 } | |
| 38 | |
| 39 std::string DumpFrameScrollPosition(WebFrame* frame) { | |
| 40 std::string result; | |
| 41 WebSize offset = frame->getScrollOffset(); | |
| 42 if (offset.width > 0 || offset.height > 0) { | |
| 43 if (frame->parent()) { | |
| 44 result = | |
| 45 std::string("frame '") + frame->uniqueName().utf8().data() + "' "; | |
| 46 } | |
| 47 base::StringAppendF(&result, "scrolled to %d,%d\n", offset.width, | |
| 48 offset.height); | |
| 49 } | |
| 50 | |
| 51 return result; | |
| 52 } | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 56 std::string DumpLayout(WebLocalFrame* frame, | |
| 57 const LayoutTestRuntimeFlags& flags) { | |
| 58 DCHECK(frame); | |
| 59 std::string result; | |
| 60 | |
| 61 if (flags.dump_as_text()) { | |
| 62 result = DumpFrameHeaderIfNeeded(frame); | |
| 63 if (flags.is_printing() && frame->document().isHTMLDocument()) { | |
| 64 result += WebFrameContentDumper::dumpLayoutTreeAsText( | |
| 65 frame, WebFrameContentDumper::LayoutAsTextPrinting) | |
| 66 .utf8(); | |
| 67 } else { | |
| 68 result += frame->document().contentAsTextForTesting().utf8(); | |
| 69 } | |
| 70 result += "\n"; | |
| 71 } else if (flags.dump_as_markup()) { | |
| 72 DCHECK(!flags.is_printing()); | |
| 73 result = DumpFrameHeaderIfNeeded(frame); | |
| 74 result += WebFrameContentDumper::dumpAsMarkup(frame).utf8(); | |
| 75 result += "\n"; | |
| 76 } else { | |
| 77 if (frame->parent() == nullptr) { | |
| 78 WebFrameContentDumper::LayoutAsTextControls layout_text_behavior = | |
| 79 WebFrameContentDumper::LayoutAsTextNormal; | |
| 80 if (flags.is_printing()) | |
| 81 layout_text_behavior |= WebFrameContentDumper::LayoutAsTextPrinting; | |
| 82 result = WebFrameContentDumper::dumpLayoutTreeAsText(frame, | |
| 83 layout_text_behavior) | |
| 84 .utf8(); | |
| 85 } | |
| 86 result += DumpFrameScrollPosition(frame); | |
| 87 } | |
| 88 | |
| 89 return result; | |
| 90 } | |
| 91 | |
| 92 } // namespace test_runner | |
| OLD | NEW |