diff --git a/xplat/FlipperTestLib/FlipperPluginMock.h b/xplat/FlipperTestLib/FlipperPluginMock.h index 20a27b64f..02becf427 100644 --- a/xplat/FlipperTestLib/FlipperPluginMock.h +++ b/xplat/FlipperTestLib/FlipperPluginMock.h @@ -1,11 +1,10 @@ /* - * Copyright (c) 2018-present, Facebook, Inc. + * Copyright (c) Facebook, Inc. * * This source code is licensed under the MIT license found in the LICENSE * file in the root directory of this source tree. * */ - #pragma once #include @@ -35,6 +34,16 @@ class FlipperPluginMock : public FlipperPlugin { connectionCallback_(connectionCallback), disconnectionCallback_(disconnectionCallback) {} + FlipperPluginMock( + const std::string& identifier, + const ConnectionCallback& connectionCallback, + const DisconnectionCallback& disconnectionCallback, + bool runInBackground) + : identifier_(identifier), + runInBackground_(runInBackground), + connectionCallback_(connectionCallback), + disconnectionCallback_(disconnectionCallback) {} + std::string identifier() const override { return identifier_; } @@ -51,8 +60,13 @@ class FlipperPluginMock : public FlipperPlugin { } } + bool runInBackground() override { + return runInBackground_; + } + private: std::string identifier_; + bool runInBackground_ = false; ConnectionCallback connectionCallback_; DisconnectionCallback disconnectionCallback_; }; diff --git a/xplat/FlipperTests/FlipperClientTests.cpp b/xplat/FlipperTests/FlipperClientTests.cpp index 853f1eca9..1eb08eb91 100644 --- a/xplat/FlipperTests/FlipperClientTests.cpp +++ b/xplat/FlipperTests/FlipperClientTests.cpp @@ -1,11 +1,10 @@ /* - * Copyright (c) 2018-present, Facebook, Inc. + * Copyright (c) Facebook, Inc. * * This source code is licensed under the MIT license found in the LICENSE * file in the root directory of this source tree. * */ - #include #include #include @@ -289,6 +288,46 @@ TEST(FlipperClientTests, testExceptionUnknownApi) { "connection Unknown not found for method execute"); } +TEST(FlipperClientTests, testBackgroundPluginActivated) { + auto socket = new FlipperConnectionManagerMock; + FlipperClient client( + std::unique_ptr{socket}, state); + + bool pluginConnected = false; + const auto connectionCallback = [&](std::shared_ptr conn) { + pluginConnected = true; + }; + const auto disconnectionCallback = [&]() { pluginConnected = false; }; + auto plugin = std::make_shared( + "Test", connectionCallback, disconnectionCallback, true); + + client.addPlugin(plugin); + client.start(); + EXPECT_TRUE(pluginConnected); + client.stop(); + EXPECT_FALSE(pluginConnected); +} + +TEST(FlipperClientTests, testNonBackgroundPluginNotActivated) { + auto socket = new FlipperConnectionManagerMock; + FlipperClient client( + std::unique_ptr{socket}, state); + + bool pluginConnected = false; + const auto connectionCallback = [&](std::shared_ptr conn) { + pluginConnected = true; + }; + const auto disconnectionCallback = [&]() { pluginConnected = false; }; + auto plugin = std::make_shared( + "Test", connectionCallback, disconnectionCallback, false); + + client.addPlugin(plugin); + client.start(); + EXPECT_FALSE(pluginConnected); + client.stop(); + EXPECT_FALSE(pluginConnected); +} + } // namespace test } // namespace flipper } // namespace facebook