[fuchsia] Wait for ContextProvider instances to start.

Launching WebEngine processes can be extremely costly if the main binary
blob is not already loaded into blobfs' in-memory cache. If instances of
the ContextProvider used by tests are allowed to load asynchronously
then the slow launch time may cause the test default RunLoop timeout to
expire.

Wait until newly-launched ContextProvider instances have completed
loading before returning from StartWebEngineForTest() and related helper
functions, to avoid this.

Bug: 1168538
Change-Id: Ic30457cadaac70a149bd3b12289e5baefd500544
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2678947
Reviewed-by: David Dorwin <[email protected]>
Commit-Queue: Wez <[email protected]>
Auto-Submit: Wez <[email protected]>
Cr-Commit-Position: refs/heads/master@{#851927}
diff --git a/fuchsia/base/context_provider_test_connector.cc b/fuchsia/base/context_provider_test_connector.cc
index d06cd9a3..292dfeb 100644
--- a/fuchsia/base/context_provider_test_connector.cc
+++ b/fuchsia/base/context_provider_test_connector.cc
@@ -49,7 +49,7 @@
     launch_info.arguments->push_back("--enable-logging=stderr");
   }
 
-  fidl::InterfaceHandle<fuchsia::io::Directory> web_engine_services_dir;
+  fuchsia::io::DirectorySyncPtr web_engine_services_dir;
   launch_info.directory_request =
       web_engine_services_dir.NewRequest().TakeChannel();
 
@@ -58,7 +58,15 @@
   launcher->CreateComponent(std::move(launch_info),
                             std::move(component_controller_request));
 
-  return web_engine_services_dir;
+  // The WebEngine binary can take sufficiently long for blobfs to resolve that
+  // tests using it may timeout as a result. Wait for the ContextProvider to
+  // be responsive, by making a synchronous request to its service directory.
+  fuchsia::io::NodeAttributes attributes{};
+  zx_status_t stat{};
+  zx_status_t status = web_engine_services_dir->GetAttr(&stat, &attributes);
+  ZX_CHECK(status == ZX_OK, status);
+
+  return web_engine_services_dir.Unbind();
 }
 
 }  // namespace