[web_runner_tests]  Port to use libsys

DX-387 #comment

TEST=CQ

Change-Id: Ifd169df228028e3e16891df6edd083c3ffd55a14
diff --git a/tests/web_runner_tests/BUILD.gn b/tests/web_runner_tests/BUILD.gn
index c355e68..5b35689 100644
--- a/tests/web_runner_tests/BUILD.gn
+++ b/tests/web_runner_tests/BUILD.gn
@@ -21,7 +21,7 @@
   ]
 
   public_deps = [
-    "//garnet/public/lib/component/cpp",
+    "//sdk/lib/sys/cpp",
     "//topaz/runtime/chromium:chromium.web",
   ]
 }
@@ -50,10 +50,10 @@
   deps = [
     ":chromium_context",
     ":test_server",
-    "//garnet/public/lib/component/cpp/testing",
-    "//src/lib/fxl",
     "//garnet/public/lib/gtest",
     "//sdk/fidl/fuchsia.sys",
+    "//sdk/lib/sys/cpp/testing:unit",
+    "//src/lib/fxl",
     "//third_party/googletest:gtest_main",
     "//zircon/public/lib/fit",
   ]
@@ -69,7 +69,6 @@
   deps = [
     ":chromium_context",
     ":test_server",
-    "//garnet/public/lib/component/cpp",
     "//garnet/public/lib/fsl",
     "//garnet/public/lib/gtest",
     "//sdk/fidl/fuchsia.sys",
@@ -77,6 +76,7 @@
     "//sdk/fidl/fuchsia.ui.policy",
     "//sdk/fidl/fuchsia.ui.scenic",
     "//sdk/fidl/fuchsia.ui.views",
+    "//sdk/lib/sys/cpp",
     "//sdk/lib/ui/scenic/cpp",
     "//third_party/googletest:gtest_main",
     "//zircon/public/lib/fit",
@@ -94,6 +94,7 @@
   tests = [
     {
       name = "web_runner_integration_tests"
+
       # FLK-148
       # environments = basic_envs
       # This does not seem to flake on NUCs.
diff --git a/tests/web_runner_tests/chromium_context.cc b/tests/web_runner_tests/chromium_context.cc
index 762a179..f0a638d 100644
--- a/tests/web_runner_tests/chromium_context.cc
+++ b/tests/web_runner_tests/chromium_context.cc
@@ -9,23 +9,20 @@
 #include <src/lib/fxl/logging.h>
 #include <zircon/status.h>
 
-ChromiumContext::ChromiumContext(component::StartupContext* startup_context) {
+ChromiumContext::ChromiumContext(sys::ComponentContext* component_context) {
   auto chromium_context_provider =
-      startup_context
-          ->ConnectToEnvironmentService<chromium::web::ContextProvider>();
+      component_context->svc()->Connect<chromium::web::ContextProvider>();
   chromium_context_provider.set_error_handler([](zx_status_t status) {
     FAIL() << "chromium_context_provider: " << zx_status_get_string(status);
   });
 
-  zx_handle_t incoming_service_clone = fdio_service_clone(
-      startup_context->incoming_services()->directory().get());
-  FXL_CHECK(incoming_service_clone != ZX_HANDLE_INVALID);
+  auto incoming_service_clone = component_context->svc()->CloneChannel();
+  FXL_CHECK(incoming_service_clone.is_valid());
   chromium::web::CreateContextParams params;
-  params.set_service_directory(fidl::InterfaceHandle<fuchsia::io::Directory>(
-      zx::channel(incoming_service_clone)));
+  params.set_service_directory(std::move(incoming_service_clone));
 
   chromium_context_provider->Create(std::move(params),
-                                     chromium_context_.NewRequest());
+                                    chromium_context_.NewRequest());
   chromium_context_.set_error_handler([](zx_status_t status) {
     FAIL() << "chromium_context_: " << zx_status_get_string(status);
   });
diff --git a/tests/web_runner_tests/chromium_context.h b/tests/web_runner_tests/chromium_context.h
index 653c82d..3a8f476 100644
--- a/tests/web_runner_tests/chromium_context.h
+++ b/tests/web_runner_tests/chromium_context.h
@@ -6,7 +6,7 @@
 #define TOPAZ_TESTS_WEB_RUNNER_TESTS_CHROMIUM_CONTEXT_H_
 
 #include <chromium/web/cpp/fidl.h>
-#include <lib/component/cpp/startup_context.h>
+#include <lib/sys/cpp/component_context.h>
 
 // This sub-fixture uses chromium.web FIDL services to interact with Chromium.
 //
@@ -14,7 +14,7 @@
 // https://chromium.googlesource.com/chromium/src/+/master/fuchsia/engine/test/webrunner_browser_test.h
 class ChromiumContext {
  public:
-  ChromiumContext(component::StartupContext* startup_context);
+  ChromiumContext(sys::ComponentContext* component_context);
   void Navigate(const std::string& url);
 
   chromium::web::Frame* frame() { return chromium_frame_.get(); }
diff --git a/tests/web_runner_tests/web_runner_integration_tests.cc b/tests/web_runner_tests/web_runner_integration_tests.cc
index 8a3007c..bbfe95c 100644
--- a/tests/web_runner_tests/web_runner_integration_tests.cc
+++ b/tests/web_runner_tests/web_runner_integration_tests.cc
@@ -4,13 +4,13 @@
 
 #include <fuchsia/sys/cpp/fidl.h>
 #include <gtest/gtest.h>
-#include <lib/component/cpp/environment_services_helper.h>
 #include <lib/fit/function.h>
+#include <lib/gtest/real_loop_fixture.h>
 #include <src/lib/fxl/logging.h>
 #include <src/lib/fxl/strings/string_printf.h>
-#include <lib/gtest/real_loop_fixture.h>
 #include <zircon/status.h>
 
+#include "lib/sys/cpp/service_directory.h"
 #include "topaz/tests/web_runner_tests/chromium_context.h"
 #include "topaz/tests/web_runner_tests/test_server.h"
 
@@ -38,7 +38,7 @@
       fxl::StringPrintf("http://localhost:%d/foo.html", server.port());
 
   fuchsia::sys::LauncherSyncPtr launcher;
-  component::GetEnvironmentServices()->ConnectToService(launcher.NewRequest());
+  sys::ServiceDirectory::CreateFromNamespace()->Connect(launcher.NewRequest());
 
   fuchsia::sys::ComponentControllerSyncPtr controller;
   launcher->CreateComponent(std::move(launch_info), controller.NewRequest());
@@ -88,8 +88,7 @@
 
 class ChromiumAppTest : public gtest::RealLoopFixture {
  protected:
-  ChromiumAppTest()
-      : chromium_(component::StartupContext::CreateFromStartupInfo().get()) {}
+  ChromiumAppTest() : chromium_(sys::ComponentContext::Create().get()) {}
 
   ChromiumContext* chromium() { return &chromium_; }
 
diff --git a/tests/web_runner_tests/web_runner_pixel_tests.cc b/tests/web_runner_tests/web_runner_pixel_tests.cc
index 740b91d..6285c76 100644
--- a/tests/web_runner_tests/web_runner_pixel_tests.cc
+++ b/tests/web_runner_tests/web_runner_pixel_tests.cc
@@ -2,29 +2,30 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include <iomanip>
-#include <map>
-#include <string>
-#include <vector>
-
 #include <fuchsia/sys/cpp/fidl.h>
 #include <fuchsia/ui/app/cpp/fidl.h>
 #include <fuchsia/ui/policy/cpp/fidl.h>
 #include <fuchsia/ui/scenic/cpp/fidl.h>
 #include <fuchsia/ui/views/cpp/fidl.h>
 #include <gtest/gtest.h>
-#include <lib/component/cpp/startup_context.h>
 #include <lib/fdio/spawn.h>
 #include <lib/fit/function.h>
 #include <lib/fsl/vmo/vector.h>
-#include <src/lib/fxl/logging.h>
-#include <src/lib/fxl/strings/string_printf.h>
 #include <lib/gtest/real_loop_fixture.h>
+#include <lib/sys/cpp/component_context.h>
+#include <lib/sys/cpp/service_directory.h>
 #include <lib/ui/scenic/cpp/view_token_pair.h>
 #include <lib/zx/time.h>
 #include <src/lib/files/file.h>
+#include <src/lib/fxl/logging.h>
+#include <src/lib/fxl/strings/string_printf.h>
 #include <zircon/status.h>
 
+#include <iomanip>
+#include <map>
+#include <string>
+#include <vector>
+
 #include "topaz/tests/web_runner_tests/chromium_context.h"
 #include "topaz/tests/web_runner_tests/test_server.h"
 
@@ -104,9 +105,8 @@
 // screenshot utilities.
 class PixelTest : public gtest::RealLoopFixture {
  protected:
-  PixelTest() : context_(component::StartupContext::CreateFromStartupInfo()) {
-    scenic_ =
-        context_->ConnectToEnvironmentService<fuchsia::ui::scenic::Scenic>();
+  PixelTest() : context_(sys::ComponentContext::Create()) {
+    scenic_ = context_->svc()->Connect<fuchsia::ui::scenic::Scenic>();
     scenic_.set_error_handler([](zx_status_t status) {
       FAIL() << "Lost connection to Scenic: " << zx_status_get_string(status);
     });
@@ -122,15 +122,14 @@
     FXL_CHECK(WaitForBlank());
   }
 
-  component::StartupContext* context() { return context_.get(); }
+  sys::ComponentContext* context() { return context_.get(); }
 
   // Gets a view token for presentation by |RootPresenter|. See also
   // garnet/examples/ui/hello_base_view
   fuchsia::ui::views::ViewToken CreatePresentationViewToken() {
     auto [view_token, view_holder_token] = scenic::NewViewTokenPair();
 
-    auto presenter =
-        context_->ConnectToEnvironmentService<fuchsia::ui::policy::Presenter>();
+    auto presenter = context_->svc()->Connect<fuchsia::ui::policy::Presenter>();
     presenter.set_error_handler([](zx_status_t status) {
       FAIL() << "presenter: " << zx_status_get_string(status);
     });
@@ -214,7 +213,7 @@
   }
 
  private:
-  std::unique_ptr<component::StartupContext> context_;
+  std::unique_ptr<sys::ComponentContext> context_;
   fuchsia::sys::ComponentControllerPtr runner_ctrl_;
   fuchsia::ui::scenic::ScenicPtr scenic_;
 };
@@ -238,17 +237,20 @@
     }
   });
 
-  component::Services services;
   fuchsia::sys::ComponentControllerPtr controller;
+  fuchsia::sys::LauncherPtr launcher;
+  context()->svc()->Connect(launcher.NewRequest());
 
-  context()->launcher()->CreateComponent(
+  zx::channel request;
+  auto services = sys::ServiceDirectory::CreateWithRequest(&request);
+  launcher->CreateComponent(
       {.url =
            fxl::StringPrintf("http://localhost:%d/static.html", server.port()),
-       .directory_request = services.NewRequest()},
+       .directory_request = std::move(request)},
       controller.NewRequest());
 
   // Present the view.
-  services.ConnectToService<fuchsia::ui::app::ViewProvider>()->CreateView(
+  services->Connect<fuchsia::ui::app::ViewProvider>()->CreateView(
       CreatePresentationViewToken().value, nullptr, nullptr);
 
   ExpectSolidColor(kTargetColor);