pending_connection_manager_unittest.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2019 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 "chromeos/components/mojo_bootstrap/pending_connection_manager.h"
  5. #include "base/test/bind.h"
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. namespace mojo_bootstrap {
  8. class PendingConnectionManagerTest : public testing::Test {
  9. protected:
  10. PendingConnectionManager connection_manager_;
  11. };
  12. namespace {
  13. TEST_F(PendingConnectionManagerTest, Basic) {
  14. auto token = base::UnguessableToken::Create();
  15. int callback_calls = 0;
  16. connection_manager_.ExpectOpenIpcChannel(
  17. token,
  18. base::BindLambdaForTesting([&](base::ScopedFD fd) { callback_calls++; }));
  19. EXPECT_TRUE(connection_manager_.OpenIpcChannel(token.ToString(), {}));
  20. EXPECT_FALSE(connection_manager_.OpenIpcChannel(token.ToString(), {}));
  21. EXPECT_EQ(1, callback_calls);
  22. }
  23. TEST_F(PendingConnectionManagerTest, Cancel) {
  24. auto token = base::UnguessableToken::Create();
  25. connection_manager_.ExpectOpenIpcChannel(
  26. token, base::BindLambdaForTesting(
  27. [&](base::ScopedFD fd) { FAIL() << "Unexpected call"; }));
  28. connection_manager_.CancelExpectedOpenIpcChannel(token);
  29. EXPECT_FALSE(connection_manager_.OpenIpcChannel(token.ToString(), {}));
  30. }
  31. TEST_F(PendingConnectionManagerTest, UnexpectedConnection) {
  32. EXPECT_FALSE(connection_manager_.OpenIpcChannel("invalid", {}));
  33. }
  34. } // namespace
  35. } // namespace mojo_bootstrap