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 "thermal_mgr_dialog_test.h"
17 #include "action_popup.h"
18 
19 using namespace testing::ext;
20 using namespace OHOS::PowerMgr;
21 using namespace OHOS;
22 using namespace std;
23 using namespace Security::AccessToken;
24 using Security::AccessToken::AccessTokenID;
25 
26 const char *g_perms[] = { "ohos.permission.START_INVISIBLE_ABILITY" };
27 uint64_t g_token;
28 AccessTokenID ThermalMgrDialogTest::tokenID_ = 0;
29 
30 NativeTokenInfoParams infoInstance = {
31     .dcapsNum = 0,
32     .permsNum = 1,
33     .aclsNum = 0,
34     .dcaps = nullptr,
35     .perms = g_perms,
36     .acls = nullptr,
37     .processName = "ThermalMgrDialogTest",
38     .aplStr = "system_basic",
39 };
40 
SetUpTestCase()41 void ThermalMgrDialogTest::SetUpTestCase()
42 {
43     g_token = GetSelfTokenID();
44     tokenID_ = GetAccessTokenId(&infoInstance);
45     ASSERT_NE(0, tokenID_);
46     ASSERT_EQ(0, SetSelfTokenID(tokenID_));
47     AccessTokenKit::ReloadNativeTokenInfo();
48 }
49 
TearDownTestCase()50 void ThermalMgrDialogTest::TearDownTestCase()
51 {
52     AccessTokenKit::DeleteToken(tokenID_);
53     SetSelfTokenID(g_token);
54 }
55 
SetUp()56 void ThermalMgrDialogTest::SetUp() {}
57 
TearDown()58 void ThermalMgrDialogTest::TearDown() {}
59 
60 namespace {
61 /**
62  * @tc.name: ThermalMgrDialogTest001
63  * @tc.desc: test pull up HighThermalDialog in StartPowerDialog
64  * @tc.type: FUNC
65  * @tc.require: issueissueI5I9BF
66  */
67 HWTEST_F(ThermalMgrDialogTest, ThermalMgrDialogTest001, TestSize.Level0)
68 {
69     auto popup = std::make_unique<ActionPopup>("Start HighThermal Dialog");
70     EXPECT_TRUE(popup->ShowThermalDialog(ActionPopup::TempStatus::HIGHER_TEMP));
71 }
72 
73 /**
74  * @tc.name: ThermalMgrDialogTest002
75  * @tc.desc: test pull up LowThermalDialog in StartPowerDialog
76  * @tc.type: FUNC
77  * @tc.require: issueissueI5I9BF
78  */
79 HWTEST_F(ThermalMgrDialogTest, ThermalMgrDialogTest002, TestSize.Level0)
80 {
81     auto popup = std::make_unique<ActionPopup>("Start LowThermal Dialog");
82     EXPECT_TRUE(popup->ShowThermalDialog(ActionPopup::TempStatus::LOWER_TEMP));
83 }
84 } // namespace