Android OOP-D: Fix layout test issues due to size mismatch

With Viz/SurfaceSync, the browser/renderer may synchronize sizes
at a number of points.

Layout tests directly set a size on the renderer, but do not notify
the browser of this size. This can lead to the renderer's size being
unexpectedly reset.

This isn't an issue on other platforms, as the native view seems to
determine its size automatically.

We should move Android to match this more automatic behavior, but
until then this workaround ensures that we have the correct sizing.

Bug: 923029
Change-Id: Ie3a07cd167ab2f557e687e53b6f71b8129df7535
Reviewed-on: https://chromium-review.googlesource.com/c/1461553
Commit-Queue: Eric Karl <ericrk@chromium.org>
Auto-Submit: Eric Karl <ericrk@chromium.org>
Reviewed-by: Mason Freed <masonfreed@chromium.org>
Reviewed-by: Antoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#631474}
diff --git a/content/shell/BUILD.gn b/content/shell/BUILD.gn
index 6aa0176..1d731bd 100644
--- a/content/shell/BUILD.gn
+++ b/content/shell/BUILD.gn
@@ -398,6 +398,7 @@
       "//components/embedder_support/android:view",
       "//content/shell/android:content_shell_jni_headers",
       "//mojo/public/java/system:test_support",
+      "//ui/android",
     ]
   }
 
diff --git a/content/shell/browser/web_test/blink_test_controller.cc b/content/shell/browser/web_test/blink_test_controller.cc
index 718be489..3df9828d 100644
--- a/content/shell/browser/web_test/blink_test_controller.cc
+++ b/content/shell/browser/web_test/blink_test_controller.cc
@@ -84,6 +84,10 @@
 #include "base/mac/foundation_util.h"
 #endif
 
+#if defined(OS_ANDROID)
+#include "ui/android/view_android.h"
+#endif
+
 namespace content {
 
 namespace {
@@ -970,6 +974,17 @@
       !base::ContainsKey(main_window_render_process_hosts_, process_host)) {
     main_window_render_process_hosts_.insert(process_host);
 
+#if defined(OS_ANDROID)
+    // On Android the native view doesn't automatically know its size. This
+    // causes problems with Viz, where the view/renderer synchronize sizes
+    // frequently. Make sure the view hosting the renderer has the same size
+    // that we're about to send.
+    main_window_->web_contents()->GetNativeView()->OnSizeChanged(
+        initial_size_.width(), initial_size_.height());
+    main_window_->web_contents()->GetNativeView()->OnPhysicalBackingSizeChanged(
+        initial_size_);
+#endif
+
     // Make sure the new renderer process_host has a test configuration shared
     // with other renderers.
     mojom::ShellTestConfigurationPtr params =
diff --git a/third_party/blink/web_tests/TestExpectations b/third_party/blink/web_tests/TestExpectations
index e0126ed..b194d0f 100644
--- a/third_party/blink/web_tests/TestExpectations
+++ b/third_party/blink/web_tests/TestExpectations
@@ -6087,3 +6087,10 @@
 # Sheriff 2019-02-12
 crbug.com/931349 [ Mac ] fast/events/popup-blocking-timers5.html [ Failure Timeout Pass ]
 crbug.com/931349 [ Mac ] media/video-played-ranges-1.html [ Failure Timeout Pass ]
+
+# Viz on Android causes issues due to synchronization of view / renderer sizes.
+crbug.com/930934 [ Android ] compositing/rendering-contexts.html [ Failure ]
+crbug.com/930934 [ Android ] paint/invalidation/compositing/should-not-repaint-composited-opacity.html [ Failure ]
+crbug.com/930934 [ Android ] paint/invalidation/svg/animated-svg-as-image-transformed-offscreen.html [ Failure ]
+crbug.com/930934 [ Android ] paint/selection/selection-drag-image-in-iframe.html [ Failure ]
+crbug.com/930934 [ Android ] virtual/gpu-rasterization/images/drag-image-descendant-painting-sibling.html [ Failure ]