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

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: Ready for review. 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
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) {
Łukasz Anforowicz 2016/01/21 00:27:08 Copy&pasted from components/test_runner/web_test_p
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) {
Łukasz Anforowicz 2016/01/21 00:27:08 Copy&pasted from components/test_runner/web_test_p
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) {
Łukasz Anforowicz 2016/01/21 00:27:08 DumpLayout is a rough equivalent of WebTestProxyBa
55 DCHECK(frame);
56 std::string result;
57
58 if (flags.dump_as_text) {
59 DCHECK(!flags.dump_as_markup);
60 DCHECK(!flags.dump_scroll_positions);
61
62 result = DumpFrameHeaderIfNeeded(frame);
63 if (flags.dump_as_printed && frame->document().isHTMLDocument()) {
64 result += frame->layoutTreeAsText(WebFrame::LayoutAsTextPrinting).utf8();
65 } else {
66 result += frame->document().contentAsTextForTesting().utf8();
67 }
68 result += "\n";
69 } else if (flags.dump_as_markup) {
70 DCHECK(!flags.dump_as_text);
71 DCHECK(!flags.dump_scroll_positions);
72 DCHECK(!flags.dump_as_printed);
73
74 result = DumpFrameHeaderIfNeeded(frame);
75 result += frame->contentAsMarkup().utf8();
76 result += "\n";
77 } else if (flags.dump_scroll_positions) {
78 DCHECK(!flags.dump_as_text);
79 DCHECK(!flags.dump_as_markup);
80
81 if (frame->parent() == nullptr) {
82 WebFrame::LayoutAsTextControls layout_text_behavior =
83 WebFrame::LayoutAsTextNormal;
84 if (flags.dump_as_printed)
85 layout_text_behavior |= WebFrame::LayoutAsTextPrinting;
86 if (flags.debug_render_tree)
87 layout_text_behavior |= WebFrame::LayoutAsTextDebug;
88 if (flags.dump_line_box_trees)
89 layout_text_behavior |= WebFrame::LayoutAsTextWithLineTrees;
90 result = frame->layoutTreeAsText(layout_text_behavior).utf8();
91 }
92
93 result += DumpFrameScrollPosition(frame);
94 }
95
96 return result;
97 }
98
99 } // namespace test_runner
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698