cast_runner_integration_test_base.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef FUCHSIA_WEB_RUNNERS_CAST_CAST_RUNNER_INTEGRATION_TEST_BASE_H_
  5. #define FUCHSIA_WEB_RUNNERS_CAST_CAST_RUNNER_INTEGRATION_TEST_BASE_H_
  6. #include <fuchsia/sys/cpp/fidl.h>
  7. #include <lib/fidl/cpp/interface_request.h>
  8. #include <lib/sys/cpp/outgoing_directory.h>
  9. #include <lib/sys/cpp/service_directory.h>
  10. #include <stdint.h>
  11. #include <memory>
  12. #include "base/fuchsia/test_component_controller.h"
  13. #include "base/location.h"
  14. #include "base/test/scoped_run_loop_timeout.h"
  15. #include "base/test/task_environment.h"
  16. #include "base/test/test_timeouts.h"
  17. #include "fuchsia_web/runners/cast/test/cast_runner_features.h"
  18. #include "net/test/embedded_test_server/embedded_test_server.h"
  19. #include "testing/gtest/include/gtest/gtest.h"
  20. #if defined(USE_CFV1_LAUNCHER)
  21. #include "fuchsia_web/runners/cast/test/cast_runner_launcher_v1.h" // nogncheck
  22. #else
  23. #include "fuchsia_web/runners/cast/test/cast_runner_launcher_v2.h" // nogncheck
  24. #endif
  25. // The base class for cast runner integration tests; templated on the type of
  26. // launcher used to start the component. This allows the same tests to be used
  27. // under both component framework v1 (using fuchsia.sys.Launcher) and v2
  28. // (using component_testing::RealmBuilder).
  29. class CastRunnerIntegrationTest : public testing::Test {
  30. public:
  31. #if defined(USE_CFV1_LAUNCHER)
  32. using Launcher = test::CastRunnerLauncherV1;
  33. #else
  34. using Launcher = test::CastRunnerLauncherV2;
  35. #endif
  36. CastRunnerIntegrationTest(const CastRunnerIntegrationTest&) = delete;
  37. CastRunnerIntegrationTest& operator=(const CastRunnerIntegrationTest&) =
  38. delete;
  39. protected:
  40. // Convenience constructor with `runner_features` == kCastRunnerFeaturesNone.
  41. CastRunnerIntegrationTest();
  42. explicit CastRunnerIntegrationTest(test::CastRunnerFeatures runner_features);
  43. ~CastRunnerIntegrationTest() override;
  44. // testing::Test:
  45. void SetUp() override;
  46. void TearDown() override;
  47. Launcher& cast_runner_launcher() { return cast_runner_launcher_; }
  48. net::EmbeddedTestServer& test_server() { return test_server_; }
  49. fuchsia::sys::RunnerPtr& cast_runner() { return cast_runner_; }
  50. const sys::ServiceDirectory& cast_runner_services() const {
  51. return *cast_runner_services_;
  52. }
  53. private:
  54. base::test::SingleThreadTaskEnvironment task_environment_{
  55. base::test::SingleThreadTaskEnvironment::MainThreadType::IO};
  56. net::EmbeddedTestServer test_server_;
  57. // TODO(https://crbug.com/1168538): Override the RunLoop timeout set by
  58. // |task_environment_| to allow for the very high variability in web.Context
  59. // launch times.
  60. const base::test::ScopedRunLoopTimeout scoped_timeout_{
  61. FROM_HERE, TestTimeouts::action_max_timeout()};
  62. Launcher cast_runner_launcher_;
  63. fuchsia::sys::RunnerPtr cast_runner_;
  64. std::unique_ptr<sys::ServiceDirectory> cast_runner_services_;
  65. };
  66. #endif // FUCHSIA_WEB_RUNNERS_CAST_CAST_RUNNER_INTEGRATION_TEST_BASE_H_