• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "wm_common.h"
18 #include "common_test_utils.h"
19 #include "freeze_controller.h"
20 #include "display_manager.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 namespace OHOS {
25 namespace Rosen {
26 class WindowFreezeControllerTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp() override;
31     void TearDown() override;
32     sptr<FreezeController> controller_;
33 
34     void SetAceessTokenPermission(const std::string processName);
35 };
36 
SetUpTestCase()37 void WindowFreezeControllerTest::SetUpTestCase()
38 {
39     const char** perms = new const char *[1];
40     perms[0] = "ohos.permission.CAPTURE_SCREEN";
41     std::string processName = "WindowFreezeControllerTest";
42     CommonTestUtils::SetAceessTokenPermission(processName, perms, 1);
43 }
44 
TearDownTestCase()45 void WindowFreezeControllerTest::TearDownTestCase()
46 {
47 }
48 
SetUp()49 void WindowFreezeControllerTest::SetUp()
50 {
51     controller_ = new FreezeController();
52 }
53 
TearDown()54 void WindowFreezeControllerTest::TearDown()
55 {
56 }
57 
58 namespace {
59 /**
60  * @tc.name: FreezeDisplay01
61  * @tc.desc: test FreezeDisplay/UnFreezeDisplay
62  * @tc.type: FUNC
63  */
64 HWTEST_F(WindowFreezeControllerTest, FreezeDisplay01, Function | SmallTest | Level2)
65 {
66     DisplayId displayId = DISPLAY_ID_INVALID;
67     bool res = true;
68 
69     res = controller_->UnfreezeDisplay(displayId);
70     ASSERT_EQ(res, false);
71     res = controller_->FreezeDisplay(displayId);
72     ASSERT_EQ(res, false);
73     res = controller_->FreezeDisplay(displayId);
74     ASSERT_EQ(res, false);
75     res = controller_->UnfreezeDisplay(displayId);
76     ASSERT_EQ(res, true);
77 
78     displayId = DisplayManager::GetInstance().GetDefaultDisplayId();
79 
80     res = controller_->FreezeDisplay(displayId);
81     ASSERT_EQ(res, false);
82     res = controller_->UnfreezeDisplay(displayId);
83     ASSERT_EQ(res, true);
84 }
85 }
86 }
87 }
88