test_component_controller.cc 962 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2021 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. #include "base/fuchsia/test_component_controller.h"
  5. #include "base/fuchsia/fuchsia_logging.h"
  6. #include "base/run_loop.h"
  7. namespace base {
  8. TestComponentController::TestComponentController() = default;
  9. TestComponentController::TestComponentController(TestComponentController&&) =
  10. default;
  11. TestComponentController& TestComponentController::operator=(
  12. TestComponentController&&) = default;
  13. TestComponentController::~TestComponentController() {
  14. KillAndRunUntilDisconnect();
  15. }
  16. void TestComponentController::KillAndRunUntilDisconnect() {
  17. if (!ptr_)
  18. return;
  19. base::RunLoop loop;
  20. ptr_.set_error_handler([&loop](zx_status_t status) {
  21. loop.Quit();
  22. ZX_CHECK(status == ZX_ERR_PEER_CLOSED, status);
  23. });
  24. ptr_->Kill();
  25. loop.Run();
  26. CHECK(!ptr_);
  27. }
  28. } // namespace base