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