diff --git a/shell/platform/tizen/BUILD.gn b/shell/platform/tizen/BUILD.gn index bc2b01a32e52b..e210a6c2a2777 100644 --- a/shell/platform/tizen/BUILD.gn +++ b/shell/platform/tizen/BUILD.gn @@ -268,6 +268,7 @@ executable("flutter_tizen_unittests") { testonly = true sources = [ + "channels/lifecycle_channel_unittests.cc", "channels/settings_channel_unittests.cc", "flutter_project_bundle_unittests.cc", "flutter_tizen_engine_unittest.cc", diff --git a/shell/platform/tizen/channels/lifecycle_channel_unittests.cc b/shell/platform/tizen/channels/lifecycle_channel_unittests.cc new file mode 100644 index 0000000000000..9d687c0abf36f --- /dev/null +++ b/shell/platform/tizen/channels/lifecycle_channel_unittests.cc @@ -0,0 +1,86 @@ +// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/shell/platform/tizen/channels/lifecycle_channel.h" +#include "flutter/shell/platform/tizen/channels/string_codec.h" +#include "flutter/shell/platform/tizen/testing/test_binary_messenger.h" +#include "gtest/gtest.h" + +namespace { + +constexpr char kChannelName[] = "flutter/lifecycle"; + +constexpr char kInactive[] = "AppLifecycleState.inactive"; +constexpr char kResumed[] = "AppLifecycleState.resumed"; +constexpr char kPaused[] = "AppLifecycleState.paused"; +constexpr char kDetached[] = "AppLifecycleState.detached"; +} // namespace + +namespace flutter { +namespace testing { + +std::unique_ptr CreateMessenger( + std::string& decoded_message) { + return std::make_unique( + [&decoded_message](const std::string& channel, const uint8_t* message, + size_t message_size, BinaryReply reply) { + if (channel == kChannelName) { + std::unique_ptr value = + StringCodec::GetInstance().DecodeMessage(message, message_size); + if (auto pval = std::get_if(value.get())) { + decoded_message = *pval; + } + } else { + // Should not be reached. + EXPECT_TRUE(false); + } + }); +} + +TEST(LifecycleChannel, AppIsInactive) { + std::string decoded_message; + std::unique_ptr messenger = + CreateMessenger(decoded_message); + LifecycleChannel lifecycle_channel(messenger.get()); + + lifecycle_channel.AppIsInactive(); + + EXPECT_TRUE(decoded_message == kInactive); +} + +TEST(LifecycleChannel, AppIsResumed) { + std::string decoded_message; + std::unique_ptr messenger = + CreateMessenger(decoded_message); + LifecycleChannel lifecycle_channel(messenger.get()); + + lifecycle_channel.AppIsResumed(); + + EXPECT_TRUE(decoded_message == kResumed); +} + +TEST(LifecycleChannel, AppIsPaused) { + std::string decoded_message; + std::unique_ptr messenger = + CreateMessenger(decoded_message); + LifecycleChannel lifecycle_channel(messenger.get()); + + lifecycle_channel.AppIsPaused(); + + EXPECT_TRUE(decoded_message == kPaused); +} + +TEST(LifecycleChannel, AppIsDetached) { + std::string decoded_message; + std::unique_ptr messenger = + CreateMessenger(decoded_message); + LifecycleChannel lifecycle_channel(messenger.get()); + + lifecycle_channel.AppIsDetached(); + + EXPECT_TRUE(decoded_message == kDetached); +} + +} // namespace testing +} // namespace flutter