Don't update style for focusability when render-blocking.

WebNode::IsFocusable() updated style and layout tree, without ignoring
pending stylesheets, which meant generating a display:none placeholder
style for the root node. Instead, early return from IsFocusable() when
we are blocking rendering.

Bug: 521692

Change-Id: Idd6cfcf800e4173cfc1bdcb916728c7a0186edf9
Reviewed-on: https://chromium-review.googlesource.com/c/1245787
Reviewed-by: Stefan Zager <szager@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599181}
diff --git a/third_party/blink/renderer/core/exported/web_node.cc b/third_party/blink/renderer/core/exported/web_node.cc
index 06ba400..55843e7 100644
--- a/third_party/blink/renderer/core/exported/web_node.cc
+++ b/third_party/blink/renderer/core/exported/web_node.cc
@@ -133,6 +133,8 @@
 bool WebNode::IsFocusable() const {
   if (!private_->IsElementNode())
     return false;
+  if (!private_->GetDocument().IsRenderingReady())
+    return false;
   private_->GetDocument().UpdateStyleAndLayoutTreeForNode(private_.Get());
   return ToElement(private_.Get())->IsFocusable();
 }
diff --git a/third_party/blink/renderer/core/exported/web_node_test.cc b/third_party/blink/renderer/core/exported/web_node_test.cc
index bb1d34dc..d16be0d 100644
--- a/third_party/blink/renderer/core/exported/web_node_test.cc
+++ b/third_party/blink/renderer/core/exported/web_node_test.cc
@@ -67,7 +67,8 @@
   LoadURL("https://example.com/test.html");
   WebView().Resize(WebSize(800, 600));
 
-  main_resource.Complete(R"HTML(
+  main_resource.Start();
+  main_resource.Write(R"HTML(
     <!DOCTYPE html>
     <link rel=stylesheet href=style.css>
     <input id=focusable>
@@ -79,7 +80,9 @@
 
   WebNode input_node(GetDocument().getElementById("focusable"));
   EXPECT_FALSE(input_node.IsFocusable());
+  EXPECT_FALSE(GetDocument().HasNodesWithPlaceholderStyle());
 
+  main_resource.Finish();
   css_resource.Complete("dummy {}");
   EXPECT_TRUE(input_node.IsFocusable());
 }