• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include "floating_ball_manager.h"
18 #include "wm_common.h"
19 #include "parameters.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 class FloatingBallManagerTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp() override;
31     void TearDown() override;
32 };
33 
34 class MockWindow : public Window {
35 public:
MockWindow()36     MockWindow() {};
~MockWindow()37     ~MockWindow() {};
38 };
39 
SetUpTestCase()40 void FloatingBallManagerTest::SetUpTestCase()
41 {
42 }
43 
TearDownTestCase()44 void FloatingBallManagerTest::TearDownTestCase()
45 {
46 }
47 
SetUp()48 void FloatingBallManagerTest::SetUp()
49 {
50 }
51 
TearDown()52 void FloatingBallManagerTest::TearDown()
53 {
54 }
55 
56 namespace {
57 
58 /**
59  * @tc.name: activeController
60  * @tc.desc: activeController
61  * @tc.type: FUNC
62  */
63 HWTEST_F(FloatingBallManagerTest, activeController, TestSize.Level1)
64 {
65     auto mw = sptr<MockWindow>::MakeSptr();
66     ASSERT_NE(nullptr, mw);
67     auto option = sptr<FbOption>::MakeSptr();
68     ASSERT_NE(nullptr, option);
69     auto fbController = sptr<FloatingBallController>::MakeSptr(mw, 101, nullptr);
70     // null fbController
71     EXPECT_EQ(false, FloatingBallManager::IsActiveController(fbController));
72     EXPECT_EQ(false, FloatingBallManager::HasActiveController());
73     std::string clickAction = "click";
74     std::string closeAction = "close";
75     FloatingBallManager::DoFbActionEvent("on");
76     FloatingBallManager::DoFbActionEvent(clickAction);
77     FloatingBallManager::DoFbActionEvent(closeAction);
78     FloatingBallManager::DoDestroy();
79 
80     // has fbController
81     FloatingBallManager::SetActiveController(fbController);
82     EXPECT_EQ(true, FloatingBallManager::IsActiveController(fbController));
83     EXPECT_EQ(true, FloatingBallManager::HasActiveController());
84     FloatingBallManager::DoFbActionEvent(clickAction);
85     FloatingBallManager::DoFbActionEvent(closeAction);
86     FloatingBallManager::DoDestroy();
87     auto fbController1 = sptr<FloatingBallController>::MakeSptr(mw, 102, nullptr);
88     FloatingBallManager::RemoveActiveController(fbController1);
89     FloatingBallManager::RemoveActiveController(fbController);
90 }
91 
92 /**
93  * @tc.name: IsSupportFloatingBall01
94  * @tc.desc: IsSupportFloatingBall01
95  * @tc.type: FUNC
96  */
97 HWTEST_F(FloatingBallManagerTest, IsSupportFloatingBall01, TestSize.Level1)
98 {
99     const std::string multiWindowUIType = system::GetParameter("const.window.multiWindowUIType", "");
100     bool isDeviceSupported = (multiWindowUIType == "HandsetSmartWindow"  || multiWindowUIType == "TabletSmartWindow");
101     bool isSupportFloatingBall = FloatingBallManager::IsSupportFloatingBall();
102     ASSERT_EQ(isDeviceSupported, isSupportFloatingBall);
103 }
104 
105 }
106 }
107 }