Fix text autosizer behavior when printing

Cherry-picked from:

https://chromium-review.googlesource.com/920001

BUG=799014
TBR=skobes@chromium.org

Change-Id: Ia07e20f5aeaaa8d7d1d4d37fbb78c29a2b761d38
Reviewed-on: https://chromium-review.googlesource.com/929583
Reviewed-by: Stefan Zager <szager@chromium.org>
Cr-Commit-Position: refs/branch-heads/3325@{#538}
Cr-Branched-From: bc084a8b5afa3744a74927344e304c02ae54189f-refs/heads/master@{#530369}
diff --git a/third_party/WebKit/Source/core/frame/LocalFrame.cpp b/third_party/WebKit/Source/core/frame/LocalFrame.cpp
index b76797e..198244a 100644
--- a/third_party/WebKit/Source/core/frame/LocalFrame.cpp
+++ b/third_party/WebKit/Source/core/frame/LocalFrame.cpp
@@ -67,6 +67,7 @@
 #include "core/layout/HitTestResult.h"
 #include "core/layout/LayoutEmbeddedContent.h"
 #include "core/layout/LayoutView.h"
+#include "core/layout/TextAutosizer.h"
 #include "core/loader/DocumentLoader.h"
 #include "core/loader/FrameLoadRequest.h"
 #include "core/loader/IdlenessDetector.h"
@@ -534,6 +535,9 @@
                                       : Document::kFinishingPrinting);
   View()->AdjustMediaTypeForPrinting(printing);
 
+  if (TextAutosizer* text_autosizer = GetDocument()->GetTextAutosizer())
+    text_autosizer->UpdatePageInfo();
+
   if (ShouldUsePrintingLayout()) {
     View()->ForceLayoutForPagination(page_size, original_page_size,
                                      maximum_shrink_ratio);
diff --git a/third_party/WebKit/Source/core/layout/TextAutosizerTest.cpp b/third_party/WebKit/Source/core/layout/TextAutosizerTest.cpp
index ffc8c6c..39a0bd5 100644
--- a/third_party/WebKit/Source/core/layout/TextAutosizerTest.cpp
+++ b/third_party/WebKit/Source/core/layout/TextAutosizerTest.cpp
@@ -1032,4 +1032,31 @@
   EXPECT_FLOAT_EQ(20.0f * device_scale,
                   target->GetLayoutObject()->Style()->ComputedFontSize());
 }
+
+TEST_F(TextAutosizerTest, AfterPrint) {
+  const float device_scale = 3;
+  FloatSize print_size(160, 240);
+  set_device_scale_factor(device_scale);
+  SetBodyInnerHTML(R"HTML(
+    <style>
+      html { font-size: 8px; }
+    </style>
+    <body>
+      <div id='target'>
+        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
+        do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+        Ut enim ad minim veniam, quis nostrud exercitation ullamco
+        laboris nisi ut aliquip ex ea commodo consequat.
+      </div>
+    </body>
+  )HTML");
+  Element* target = GetDocument().getElementById("target");
+  EXPECT_FLOAT_EQ(20.0f * device_scale,
+                  target->GetLayoutObject()->Style()->ComputedFontSize());
+  GetDocument().GetFrame()->SetPrinting(true, print_size, print_size, 1.0);
+  EXPECT_FLOAT_EQ(8.0f, target->GetLayoutObject()->Style()->ComputedFontSize());
+  GetDocument().GetFrame()->SetPrinting(false, print_size, print_size, 1.0);
+  EXPECT_FLOAT_EQ(20.0f * device_scale,
+                  target->GetLayoutObject()->Style()->ComputedFontSize());
+}
 }  // namespace blink