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 // gtest
17 #include <gtest/gtest.h>
18
19 #include "future.h"
20 #include "scene_board_judgement.h"
21 #include "window_manager.h"
22 #include "wm_common.h"
23
24 using namespace testing;
25 using namespace testing::ext;
26
27 namespace OHOS {
28 namespace Rosen {
29 namespace {
30 constexpr int WAIT_FUTURE_RESULT = 20000; // 20s
31 constexpr int WAIT_SLEEP_TIME = 1; // 1s
32 } // namespace
33
34 class TestGestureNavigationEnabledChangedListener : public IGestureNavigationEnabledChangedListener {
35 public:
36 void OnGestureNavigationEnabledUpdate(bool enable) override;
37
38 RunnableFuture<bool> future_;
39 };
40
OnGestureNavigationEnabledUpdate(bool enable)41 void TestGestureNavigationEnabledChangedListener::OnGestureNavigationEnabledUpdate(bool enable)
42 {
43 future_.SetValue(enable);
44 }
45
46 class GestureNavigationEnabledTest : public testing::Test {
47 public:
48 static void SetUpTestCase();
49 static void TearDownTestCase();
50 void SetUp() override;
51 void TearDown() override;
52
53 static sptr<TestGestureNavigationEnabledChangedListener> lisenter_;
54 };
55
56 sptr<TestGestureNavigationEnabledChangedListener> GestureNavigationEnabledTest::lisenter_ = nullptr;
SetUpTestCase()57 void GestureNavigationEnabledTest::SetUpTestCase()
58 {
59 lisenter_ = new (std::nothrow) TestGestureNavigationEnabledChangedListener();
60 ASSERT_NE(lisenter_, nullptr);
61 }
62
TearDownTestCase()63 void GestureNavigationEnabledTest::TearDownTestCase() {}
64
SetUp()65 void GestureNavigationEnabledTest::SetUp() {}
66
TearDown()67 void GestureNavigationEnabledTest::TearDown() {}
68
69 namespace {
70 /**
71 * @tc.name: SetGestureNavigationEnabled
72 * @tc.desc: Check gesture navigation enabled
73 * @tc.type: FUNC
74 */
75 HWTEST_F(GestureNavigationEnabledTest, SetGestureNavigationEnabled, TestSize.Level1)
76 {
77 ASSERT_NE(lisenter_, nullptr);
78
79 auto& windowManager = WindowManager::GetInstance();
80 windowManager.SetGestureNavigationEnabled(false);
81 sleep(WAIT_SLEEP_TIME);
82
83 windowManager.RegisterGestureNavigationEnabledChangedListener(lisenter_);
84 sleep(WAIT_SLEEP_TIME);
85 windowManager.SetGestureNavigationEnabled(true);
86 auto result = lisenter_->future_.GetResult(WAIT_FUTURE_RESULT);
87
88 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
89 ASSERT_EQ(result, true);
90 }
91
92 lisenter_->future_.Reset(true);
93 windowManager.SetGestureNavigationEnabled(false);
94 result = lisenter_->future_.GetResult(WAIT_FUTURE_RESULT);
95 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
96 ASSERT_EQ(result, false);
97 }
98
99 lisenter_->future_.Reset(false);
100 windowManager.UnregisterGestureNavigationEnabledChangedListener(lisenter_);
101 sleep(WAIT_SLEEP_TIME);
102 }
103 } // namespace
104 } // namespace Rosen
105 } // namespace OHOS
106