Remove duplication between TestRunner's fields and LayoutDumpFlags struct.

The current CL paves the way for 1) moving more test flags from
TestRunner's fields into LayoutDumpFlags and 2) replicating the
test flags when transferring to another renderer process (in addition
to using LayoutDumpFlags during a textual layout dump).

In a way, the current CL backpedals on some aspects of an earlier CL
(crrev.com/1589643003) which has introduced LayoutDumpFlags struct that
holds layout dump flags for the purpose of passing them to the browser
process (which can coordinate dumping across all frames).  The
backpedaling is necessary because:

- Having LayoutDumpFlags is good for passing the flags to the browser
  process (when having to do a layout dump spanning multiple renderers /
  OOPIFs), but LayoutDumpFlags is also bad, because the same flags are
  represented (in a slightly different way) in 2 places: in
  LayoutDumpFlags struct and in TestRunner fields.  This CL fixes this
  by moving relevant fields of TestRunner into LayoutDumpFlags struct.

- The previous CL tried to be (unnecessarily :-/) smart and for example:
  - consolidated |dump_child_frames_as_text|,
    |dump_child_frames_as_markup| and |dump_child_frame_scroll_positions|
    into |dump_child_frames| field.
  - consolidated |dump_as_text|, |dump_as_markup| into a |main_dump_mode|
    field with 3 possible states - text / markup / scroll positions.
  The current CL backpedals on this and simply copies TestRunner's fields
  into LayoutDumpFlags, because otherwise preserving all existing test
  behavior is prooving to be really difficult.

BUG=587175

Review URL: https://codereview.chromium.org/1689283003

Cr-Commit-Position: refs/heads/master@{#377712}
diff --git a/components/test_runner/layout_dump.cc b/components/test_runner/layout_dump.cc
index ac5b5d4..02a90ee 100644
--- a/components/test_runner/layout_dump.cc
+++ b/components/test_runner/layout_dump.cc
@@ -57,45 +57,37 @@
   DCHECK(frame);
   std::string result;
 
-  switch (flags.main_dump_mode) {
-    case LayoutDumpMode::DUMP_AS_TEXT:
-      result = DumpFrameHeaderIfNeeded(frame);
-      if (flags.dump_as_printed && frame->document().isHTMLDocument()) {
-        result += WebFrameContentDumper::dumpLayoutTreeAsText(
-                      frame, WebFrameContentDumper::LayoutAsTextPrinting)
-                      .utf8();
-      } else {
-        result += frame->document().contentAsTextForTesting().utf8();
-      }
-      result += "\n";
-      break;
-    case LayoutDumpMode::DUMP_AS_MARKUP:
-      DCHECK(!flags.dump_as_printed);
-      result = DumpFrameHeaderIfNeeded(frame);
-      result += WebFrameContentDumper::dumpAsMarkup(frame).utf8();
-      result += "\n";
-      break;
-    case LayoutDumpMode::DUMP_SCROLL_POSITIONS:
-      if (frame->parent() == nullptr) {
-        WebFrameContentDumper::LayoutAsTextControls layout_text_behavior =
-            WebFrameContentDumper::LayoutAsTextNormal;
-        if (flags.dump_as_printed)
-          layout_text_behavior |= WebFrameContentDumper::LayoutAsTextPrinting;
-        if (flags.debug_render_tree)
-          layout_text_behavior |= WebFrameContentDumper::LayoutAsTextDebug;
-        if (flags.dump_line_box_trees)
-          layout_text_behavior |=
-              WebFrameContentDumper::LayoutAsTextWithLineTrees;
-        result = WebFrameContentDumper::dumpLayoutTreeAsText(
-                     frame, layout_text_behavior)
-                     .utf8();
-      }
-      result += DumpFrameScrollPosition(frame);
-      break;
-    default:
-      DCHECK(false) << static_cast<int>(flags.main_dump_mode);
-      result = "";
-      break;
+  if (flags.dump_as_text) {
+    result = DumpFrameHeaderIfNeeded(frame);
+    if (flags.is_printing && frame->document().isHTMLDocument()) {
+      result += WebFrameContentDumper::dumpLayoutTreeAsText(
+                    frame, WebFrameContentDumper::LayoutAsTextPrinting)
+                    .utf8();
+    } else {
+      result += frame->document().contentAsTextForTesting().utf8();
+    }
+    result += "\n";
+  } else if (flags.dump_as_markup) {
+    DCHECK(!flags.is_printing);
+    result = DumpFrameHeaderIfNeeded(frame);
+    result += WebFrameContentDumper::dumpAsMarkup(frame).utf8();
+    result += "\n";
+  } else {
+    if (frame->parent() == nullptr) {
+      WebFrameContentDumper::LayoutAsTextControls layout_text_behavior =
+          WebFrameContentDumper::LayoutAsTextNormal;
+      if (flags.is_printing)
+        layout_text_behavior |= WebFrameContentDumper::LayoutAsTextPrinting;
+      if (flags.debug_render_tree)
+        layout_text_behavior |= WebFrameContentDumper::LayoutAsTextDebug;
+      if (flags.dump_line_box_trees)
+        layout_text_behavior |=
+            WebFrameContentDumper::LayoutAsTextWithLineTrees;
+      result = WebFrameContentDumper::dumpLayoutTreeAsText(frame,
+                                                           layout_text_behavior)
+                   .utf8();
+    }
+    result += DumpFrameScrollPosition(frame);
   }
 
   return result;
diff --git a/components/test_runner/layout_dump_flags.h b/components/test_runner/layout_dump_flags.h
index 5253e15..188c1be3 100644
--- a/components/test_runner/layout_dump_flags.h
+++ b/components/test_runner/layout_dump_flags.h
@@ -7,17 +7,65 @@
 
 namespace test_runner {
 
-enum class LayoutDumpMode {
-  DUMP_AS_TEXT,
-  DUMP_AS_MARKUP,
-  DUMP_SCROLL_POSITIONS
-};
-
 struct LayoutDumpFlags {
-  LayoutDumpMode main_dump_mode;
+  LayoutDumpFlags(bool dump_as_text,
+                  bool dump_child_frames_as_text,
+                  bool dump_as_markup,
+                  bool dump_child_frames_as_markup,
+                  bool dump_child_frame_scroll_positions,
+                  bool is_printing,
+                  bool dump_line_box_trees,
+                  bool debug_render_tree)
+      : dump_as_text(dump_as_text),
+        dump_child_frames_as_text(dump_child_frames_as_text),
+        dump_as_markup(dump_as_text),
+        dump_child_frames_as_markup(dump_child_frames_as_markup),
+        dump_child_frame_scroll_positions(dump_child_frame_scroll_positions),
+        is_printing(is_printing),
+        dump_line_box_trees(dump_line_box_trees),
+        debug_render_tree(debug_render_tree) {}
 
-  bool dump_as_printed;
-  bool dump_child_frames;
+  // Default constructor needed for IPC.
+  //
+  // Default constructor is |= default| to make sure LayoutDumpFlags is a POD
+  // (required until we can remove content/shell/browser dependency on it).
+  LayoutDumpFlags() = default;
+
+  // If true, the test_shell will produce a plain text dump rather than a
+  // text representation of the renderer.
+  bool dump_as_text;
+
+  // If true and if dump_as_text_ is true, the test_shell will recursively
+  // dump all frames as plain text.
+  bool dump_child_frames_as_text;
+
+  // If true, the test_shell will produce a dump of the DOM rather than a text
+  // representation of the layout objects.
+  bool dump_as_markup;
+
+  // If true and if dump_as_markup_ is true, the test_shell will recursively
+  // produce a dump of the DOM rather than a text representation of the
+  // layout objects.
+  bool dump_child_frames_as_markup;
+
+  // If true, the test_shell will print out the child frame scroll offsets as
+  // well.
+  bool dump_child_frame_scroll_positions;
+
+  // Reports whether recursing over child frames is necessary.
+  bool dump_child_frames() const {
+    if (dump_as_text)
+      return dump_child_frames_as_text;
+    else if (dump_as_markup)
+      return dump_child_frames_as_markup;
+    else
+      return dump_child_frame_scroll_positions;
+  }
+
+  // If true, layout is to target printed pages.
+  bool is_printing;
+
+  // Extra flags for debugging layout tests.
   bool dump_line_box_trees;
   bool debug_render_tree;
 };
diff --git a/components/test_runner/test_runner.cc b/components/test_runner/test_runner.cc
index b55b4982..ccf57951 100644
--- a/components/test_runner/test_runner.cc
+++ b/components/test_runner/test_runner.cc
@@ -1651,6 +1651,15 @@
       disable_notify_done_(false),
       web_history_item_count_(0),
       intercept_post_message_(false),
+      layout_dump_flags_(
+          false,  // dump_as_text
+          false,  // dump_child_frames_as_text
+          false,  // dump_as_markup
+          false,  // dump_child_frames_as_markup
+          false,  // dump_child_frame_scroll_positions
+          false,  // is_printing
+          false,  // dump_line_box_trees
+          false),  // debug_render_tree
       test_interfaces_(interfaces),
       delegate_(nullptr),
       web_view_(nullptr),
@@ -1720,12 +1729,12 @@
   }
 
   dump_editting_callbacks_ = false;
-  dump_as_text_ = false;
-  dump_as_markup_ = false;
+  layout_dump_flags_.dump_as_text = false;
+  layout_dump_flags_.dump_as_markup = false;
   generate_pixel_results_ = true;
-  dump_child_frame_scroll_positions_ = false;
-  dump_child_frames_as_markup_ = false;
-  dump_child_frames_as_text_ = false;
+  layout_dump_flags_.dump_child_frame_scroll_positions = false;
+  layout_dump_flags_.dump_child_frames_as_text = false;
+  layout_dump_flags_.dump_child_frames_as_markup = false;
   dump_icon_changes_ = false;
   dump_as_audio_ = false;
   dump_frame_load_callbacks_ = false;
@@ -1745,7 +1754,7 @@
   dump_navigation_policy_ = false;
   test_repaint_ = false;
   sweep_horizontally_ = false;
-  is_printing_ = false;
+  layout_dump_flags_.is_printing = false;
   midi_accessor_result_ = true;
   should_stay_on_page_after_handling_before_unload_ = false;
   should_dump_resource_priorities_ = false;
@@ -1788,21 +1797,12 @@
   return dump_editting_callbacks_;
 }
 
-bool TestRunner::shouldDumpAsText() {
-  CheckResponseMimeType();
-  return dump_as_text_;
-}
-
 void TestRunner::setShouldDumpAsText(bool value) {
-  dump_as_text_ = value;
-}
-
-bool TestRunner::shouldDumpAsMarkup() {
-  return dump_as_markup_;
+  layout_dump_flags_.dump_as_text = value;
 }
 
 void TestRunner::setShouldDumpAsMarkup(bool value) {
-  dump_as_markup_ = value;
+  layout_dump_flags_.dump_as_markup = value;
 }
 
 bool TestRunner::shouldDumpAsCustomText() const {
@@ -1832,18 +1832,6 @@
   generate_pixel_results_ = value;
 }
 
-bool TestRunner::shouldDumpChildFrameScrollPositions() const {
-  return dump_child_frame_scroll_positions_;
-}
-
-bool TestRunner::shouldDumpChildFramesAsMarkup() const {
-  return dump_child_frames_as_markup_;
-}
-
-bool TestRunner::shouldDumpChildFramesAsText() const {
-  return dump_child_frames_as_text_;
-}
-
 bool TestRunner::ShouldDumpAsAudio() const {
   return dump_as_audio_;
 }
@@ -1852,25 +1840,9 @@
   *buffer_view = audio_data_;
 }
 
-LayoutDumpFlags TestRunner::GetLayoutDumpFlags() {
-  LayoutDumpFlags result;
-
-  if (shouldDumpAsText()) {
-    result.main_dump_mode = LayoutDumpMode::DUMP_AS_TEXT;
-    result.dump_child_frames = shouldDumpChildFramesAsText();
-  } else if (shouldDumpAsMarkup()) {
-    result.main_dump_mode = LayoutDumpMode::DUMP_AS_MARKUP;
-    result.dump_child_frames = shouldDumpChildFramesAsMarkup();
-  } else {
-    result.main_dump_mode = LayoutDumpMode::DUMP_SCROLL_POSITIONS;
-    result.dump_child_frames = shouldDumpChildFrameScrollPositions();
-  }
-
-  result.dump_as_printed = isPrinting();
-
-  result.dump_line_box_trees = result.debug_render_tree = false;
-
-  return result;
+const LayoutDumpFlags& TestRunner::GetLayoutDumpFlags() {
+  CheckResponseMimeType();
+  return layout_dump_flags_;
 }
 
 bool TestRunner::HasCustomTextDump(std::string* custom_text_dump) const {
@@ -1955,7 +1927,7 @@
 }
 
 bool TestRunner::isPrinting() const {
-  return is_printing_;
+  return layout_dump_flags_.is_printing;
 }
 
 bool TestRunner::shouldWaitUntilExternalURLLoad() const {
@@ -2661,30 +2633,30 @@
 }
 
 void TestRunner::DumpAsMarkup() {
-  dump_as_markup_ = true;
+  layout_dump_flags_.dump_as_markup = true;
   generate_pixel_results_ = false;
 }
 
 void TestRunner::DumpAsText() {
-  dump_as_text_ = true;
+  layout_dump_flags_.dump_as_text = true;
   generate_pixel_results_ = false;
 }
 
 void TestRunner::DumpAsTextWithPixelResults() {
-  dump_as_text_ = true;
+  layout_dump_flags_.dump_as_text = true;
   generate_pixel_results_ = true;
 }
 
 void TestRunner::DumpChildFrameScrollPositions() {
-  dump_child_frame_scroll_positions_ = true;
+  layout_dump_flags_.dump_child_frame_scroll_positions = true;
 }
 
 void TestRunner::DumpChildFramesAsMarkup() {
-  dump_child_frames_as_markup_ = true;
+  layout_dump_flags_.dump_child_frames_as_markup = true;
 }
 
 void TestRunner::DumpChildFramesAsText() {
-  dump_child_frames_as_text_ = true;
+  layout_dump_flags_.dump_child_frames_as_text = true;
 }
 
 void TestRunner::DumpIconChanges() {
@@ -2783,11 +2755,11 @@
 }
 
 void TestRunner::SetPrinting() {
-  is_printing_ = true;
+  layout_dump_flags_.is_printing = true;
 }
 
 void TestRunner::ClearPrinting() {
-  is_printing_ = false;
+  layout_dump_flags_.is_printing = false;
 }
 
 void TestRunner::SetShouldStayOnPageAfterHandlingBeforeUnload(bool value) {
@@ -3165,11 +3137,11 @@
 void TestRunner::CheckResponseMimeType() {
   // Text output: the test page can request different types of output which we
   // handle here.
-  if (!dump_as_text_) {
+  if (!layout_dump_flags_.dump_as_text) {
     std::string mimeType =
         web_view_->mainFrame()->dataSource()->response().mimeType().utf8();
     if (mimeType == "text/plain") {
-      dump_as_text_ = true;
+      layout_dump_flags_.dump_as_text = true;
       generate_pixel_results_ = false;
     }
   }
diff --git a/components/test_runner/test_runner.h b/components/test_runner/test_runner.h
index cd9e9ae..00b7488f 100644
--- a/components/test_runner/test_runner.h
+++ b/components/test_runner/test_runner.h
@@ -15,6 +15,7 @@
 #include "base/macros.h"
 #include "base/memory/scoped_ptr.h"
 #include "base/memory/weak_ptr.h"
+#include "components/test_runner/layout_dump_flags.h"
 #include "components/test_runner/test_runner_export.h"
 #include "components/test_runner/web_task.h"
 #include "components/test_runner/web_test_runner.h"
@@ -72,7 +73,7 @@
   bool ShouldStayOnPageAfterHandlingBeforeUnload() const override;
   bool ShouldDumpAsAudio() const override;
   void GetAudioData(std::vector<unsigned char>* buffer_view) const override;
-  LayoutDumpFlags GetLayoutDumpFlags() override;
+  const LayoutDumpFlags& GetLayoutDumpFlags() override;
   bool HasCustomTextDump(std::string* custom_text_dump) const override;
   bool ShouldDumpBackForwardList() const override;
   blink::WebContentSettingsClient* GetWebContentSettings() const override;
@@ -80,14 +81,9 @@
   // Methods used by WebTestProxyBase.
   bool shouldDumpSelectionRect() const;
   bool isPrinting() const;
-  bool shouldDumpAsText();
   bool shouldDumpAsTextWithPixelResults();
   bool shouldDumpAsCustomText() const;
   std:: string customDumpText() const;
-  bool shouldDumpAsMarkup();
-  bool shouldDumpChildFrameScrollPositions() const;
-  bool shouldDumpChildFramesAsMarkup() const;
-  bool shouldDumpChildFramesAsText() const;
   void ShowDevTools(const std::string& settings,
                     const std::string& frontend_url);
   void ClearDevToolsLocalStorage();
@@ -709,26 +705,8 @@
   // If true, the test_shell will generate pixel results in DumpAsText mode
   bool generate_pixel_results_;
 
-  // If true, the test_shell will produce a plain text dump rather than a
-  // text representation of the renderer.
-  bool dump_as_text_;
-
-  // If true and if dump_as_text_ is true, the test_shell will recursively
-  // dump all frames as plain text.
-  bool dump_child_frames_as_text_;
-
-  // If true, the test_shell will produce a dump of the DOM rather than a text
-  // representation of the renderer.
-  bool dump_as_markup_;
-
-  // If true and if dump_as_markup_ is true, the test_shell will recursively
-  // produce a dump of the DOM rather than a text representation of the
-  // renderer.
-  bool dump_child_frames_as_markup_;
-
-  // If true, the test_shell will print out the child frame scroll offsets as
-  // well.
-  bool dump_child_frame_scroll_positions_;
+  // Flags controlling what content gets dumped as a layout text result.
+  LayoutDumpFlags layout_dump_flags_;
 
   // If true, the test_shell will print out the icon change notifications.
   bool dump_icon_changes_;
@@ -802,9 +780,6 @@
   // a series of 1px-wide, view-tall paints across the width of the view.
   bool sweep_horizontally_;
 
-  // If true, layout is to target printed pages.
-  bool is_printing_;
-
   // If false, MockWebMIDIAccessor fails on startSession() for testing.
   bool midi_accessor_result_;
 
diff --git a/components/test_runner/web_test_runner.h b/components/test_runner/web_test_runner.h
index b5040df..612baf75 100644
--- a/components/test_runner/web_test_runner.h
+++ b/components/test_runner/web_test_runner.h
@@ -8,14 +8,14 @@
 #include <string>
 #include <vector>
 
-#include "components/test_runner/layout_dump_flags.h"
-
 namespace blink {
 class WebContentSettingsClient;
 }
 
 namespace test_runner {
 
+struct LayoutDumpFlags;
+
 class WebTestRunner {
  public:
   // Returns a mock WebContentSettings that is used for layout tests. An
@@ -33,7 +33,7 @@
 
   // Gets layout dump flags (i.e. dump-as-text or dump-as-markup) requested
   // by the test (i.e. via testRunner.dumpAsText() called from javascript).
-  virtual LayoutDumpFlags GetLayoutDumpFlags() = 0;
+  virtual const LayoutDumpFlags& GetLayoutDumpFlags() = 0;
 
   // If custom text dump is present (i.e. if testRunner.setCustomTextOutput has
   // been called from javascript), then returns |true| and populates the