Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: components/test_runner/layout_dump.cc

Issue 1589643003: OOPIF support for testRunner.dumpAsText and similar layout dumps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing... Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/test_runner/layout_dump.h ('k') | components/test_runner/layout_dump_flags.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/WebLocalFrame.h"
15
16 namespace test_runner {
17
18 using blink::WebFrame;
19 using blink::WebLocalFrame;
20 using blink::WebSize;
21
22 namespace {
23
24 std::string DumpFrameHeaderIfNeeded(WebFrame* frame) {
25 std::string result;
26
27 // Add header for all but the main frame. Skip empty frames.
28 if (frame->parent() && !frame->document().documentElement().isNull()) {
29 result.append("\n--------\nFrame: '");
30 result.append(frame->uniqueName().utf8());
31 result.append("'\n--------\n");
32 }
33
34 return result;
35 }
36
37 std::string DumpFrameScrollPosition(WebFrame* frame) {
38 std::string result;
39 WebSize offset = frame->scrollOffset();
40 if (offset.width > 0 || offset.height > 0) {
41 if (frame->parent()) {
42 result =
43 std::string("frame '") + frame->uniqueName().utf8().data() + "' ";
44 }
45 base::StringAppendF(&result, "scrolled to %d,%d\n", offset.width,
46 offset.height);
47 }
48
49 return result;
50 }
51
52 } // namespace
53
54 std::string DumpLayout(WebLocalFrame* frame, const LayoutDumpFlags& flags) {
55 DCHECK(frame);
56 std::string result;
57
58 switch (flags.main_dump_mode) {
59 case LayoutDumpMode::DUMP_AS_TEXT:
60 result = DumpFrameHeaderIfNeeded(frame);
61 if (flags.dump_as_printed && frame->document().isHTMLDocument()) {
62 result +=
63 frame->layoutTreeAsText(WebFrame::LayoutAsTextPrinting).utf8();
64 } else {
65 result += frame->document().contentAsTextForTesting().utf8();
66 }
67 result += "\n";
68 break;
69 case LayoutDumpMode::DUMP_AS_MARKUP:
70 DCHECK(!flags.dump_as_printed);
71 result = DumpFrameHeaderIfNeeded(frame);
72 result += frame->contentAsMarkup().utf8();
73 result += "\n";
74 break;
75 case LayoutDumpMode::DUMP_SCROLL_POSITIONS:
76 if (frame->parent() == nullptr) {
77 WebFrame::LayoutAsTextControls layout_text_behavior =
78 WebFrame::LayoutAsTextNormal;
79 if (flags.dump_as_printed)
80 layout_text_behavior |= WebFrame::LayoutAsTextPrinting;
81 if (flags.debug_render_tree)
82 layout_text_behavior |= WebFrame::LayoutAsTextDebug;
83 if (flags.dump_line_box_trees)
84 layout_text_behavior |= WebFrame::LayoutAsTextWithLineTrees;
85 result = frame->layoutTreeAsText(layout_text_behavior).utf8();
86 }
87 result += DumpFrameScrollPosition(frame);
88 break;
89 default:
90 DCHECK(false) << static_cast<int>(flags.main_dump_mode);
91 result = "";
92 break;
93 }
94
95 return result;
96 }
97
98 } // namespace test_runner
OLDNEW
« no previous file with comments | « components/test_runner/layout_dump.h ('k') | components/test_runner/layout_dump_flags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698