quick_pair_service_unittest.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #include "ash/services/quick_pair/quick_pair_service.h"
  5. #include "ash/services/quick_pair/public/mojom/fast_pair_data_parser.mojom.h"
  6. #include "base/bind.h"
  7. #include "base/test/task_environment.h"
  8. #include "base/threading/sequenced_task_runner_handle.h"
  9. #include "mojo/public/cpp/bindings/pending_receiver.h"
  10. #include "mojo/public/cpp/bindings/pending_remote.h"
  11. #include "mojo/public/cpp/bindings/remote.h"
  12. #include "mojo/public/cpp/bindings/shared_remote.h"
  13. #include "testing/gtest/include/gtest/gtest.h"
  14. namespace ash {
  15. namespace quick_pair {
  16. class QuickPairServiceTest : public testing::Test {
  17. public:
  18. void SetUp() override {
  19. receiver_ = service_.BindNewPipeAndPassReceiver();
  20. mojo::PendingRemote<mojom::FastPairDataParser> fast_pair_data_parser;
  21. mojo::PendingReceiver<mojom::FastPairDataParser>
  22. fast_pair_data_parser_receiver =
  23. fast_pair_data_parser.InitWithNewPipeAndPassReceiver();
  24. fast_pair_data_parser_.Bind(std::move(fast_pair_data_parser),
  25. /*bind_task_runner=*/nullptr);
  26. quick_pair_service_ =
  27. std::make_unique<QuickPairService>(std::move(receiver_));
  28. quick_pair_service_->Connect(std::move(fast_pair_data_parser_receiver));
  29. }
  30. void TearDown() override { quick_pair_service_.reset(); }
  31. protected:
  32. mojo::PendingReceiver<mojom::QuickPairService> receiver_;
  33. mojo::SharedRemote<mojom::FastPairDataParser> data_parser_remote_;
  34. mojo::SharedRemote<mojom::FastPairDataParser> fast_pair_data_parser_;
  35. mojo::Remote<mojom::QuickPairService> service_;
  36. base::test::SingleThreadTaskEnvironment task_environment;
  37. std::unique_ptr<QuickPairService> quick_pair_service_;
  38. };
  39. TEST_F(QuickPairServiceTest, ConnectSuccess) {
  40. EXPECT_TRUE(quick_pair_service_->fast_pair_data_parser());
  41. }
  42. } // namespace quick_pair
  43. } // namespace ash