• 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 // gtest
17 #include <gtest/gtest.h>
18 
19 #include "future.h"
20 #include "window_manager.h"
21 #include "wm_common.h"
22 #include "scene_board_judgement.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 }
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 {
65 }
66 
SetUp()67 void GestureNavigationEnabledTest::SetUp()
68 {
69 }
70 
TearDown()71 void GestureNavigationEnabledTest::TearDown()
72 {
73 }
74 
75 namespace {
76 /**
77  * @tc.name: SetGestureNavigationEnabled
78  * @tc.desc: Check gesture navigation enabled
79  * @tc.type: FUNC
80  */
81 HWTEST_F(GestureNavigationEnabledTest, SetGestureNavigationEnabled, Function | MediumTest | Level1)
82 {
83     ASSERT_NE(lisenter_, nullptr);
84 
85     auto& windowManager =  WindowManager::GetInstance();
86     windowManager.SetGestureNavigationEnabled(false);
87     sleep(WAIT_SLEEP_TIME);
88 
89     windowManager.RegisterGestureNavigationEnabledChangedListener(lisenter_);
90     sleep(WAIT_SLEEP_TIME);
91     windowManager.SetGestureNavigationEnabled(true);
92     auto result = lisenter_->future_.GetResult(WAIT_FUTURE_RESULT);
93 
94     if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
95         ASSERT_EQ(result, true);
96     }
97 
98     lisenter_->future_.Reset(true);
99     windowManager.SetGestureNavigationEnabled(false);
100     result = lisenter_->future_.GetResult(WAIT_FUTURE_RESULT);
101     if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
102         ASSERT_EQ(result, false);
103     }
104 
105     lisenter_->future_.Reset(false);
106     windowManager.UnregisterGestureNavigationEnabledChangedListener(lisenter_);
107     sleep(WAIT_SLEEP_TIME);
108 }
109 }
110 } // namespace Rosen
111 } // namespace OHOS
112 
113