• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <limits>
18 #include <test_header.h>
19 
20 #include "hgm_core.h"
21 #include "hgm_frame_rate_manager.h"
22 #include "hgm_app_page_url_strategy.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace {
30     constexpr int32_t DEF_PID = 1000;
31     constexpr int32_t MIN_FPS = 60;
32     constexpr int32_t MAX_FPS = 90;
33     const std::string STRATEGY = "5";
34     const std::string PKG_NAME = "com.pkg.other";
35     const std::string PAGE_NAME = "other";
36 }
37 
38 class HgmAppPageUrlStrategyTest : public testing::Test {
39 public:
SetUpTestCase()40     static void SetUpTestCase() {}
TearDownTestCase()41     static void TearDownTestCase() {}
42     void SetUp();
TearDown()43     void TearDown() {}
44     HgmErrCode GetPageUrlVoteInfo(uint32_t pid);
45 
46     std::shared_ptr<HgmAppPageUrlStrategy> appPageUrlStrategy_;
47     PolicyConfigData::ScreenSetting screenSetting_;
48 };
49 
SetUp()50 void HgmAppPageUrlStrategyTest::SetUp()
51 {
52     appPageUrlStrategy_ = std::make_shared<HgmAppPageUrlStrategy>();
53     PolicyConfigData::PageUrlConfig pageUrlConfig;
54     pageUrlConfig[PAGE_NAME] = STRATEGY;
55     screenSetting_.pageUrlConfig[PKG_NAME] = pageUrlConfig;
56 }
57 
GetPageUrlVoteInfo(uint32_t pid)58 HgmErrCode HgmAppPageUrlStrategyTest::GetPageUrlVoteInfo(uint32_t pid)
59 {
60     for (auto& pageUrlVoter : appPageUrlStrategy_->pageUrlVoterInfo_) {
61         auto voterPid = pageUrlVoter.first;
62         auto voterInfo = pageUrlVoter.second;
63         if (voterPid == pid && voterInfo.hasVoter) {
64             return EXEC_SUCCESS;
65         }
66     }
67     return HGM_ERROR;
68 }
69 
70 /**
71  * @tc.name: NotifyPageName001
72  * @tc.desc: Verify the result of NotifyPageName001 function
73  * @tc.type: FUNC
74  * @tc.require:
75  */
76 HWTEST_F(HgmAppPageUrlStrategyTest, NotifyPageName001, Function | SmallTest | Level1)
77 {
78     PolicyConfigData::ScreenSetting screenSetting;
79     appPageUrlStrategy_->SetPageUrlConfig(screenSetting.pageUrlConfig);
80     appPageUrlStrategy_->NotifyPageName(DEF_PID, PKG_NAME, PAGE_NAME, true);
81     ASSERT_EQ(GetPageUrlVoteInfo(DEF_PID), HGM_ERROR);
82     appPageUrlStrategy_->NotifyPageName(DEF_PID, PKG_NAME, PAGE_NAME, false);
83     ASSERT_EQ(GetPageUrlVoteInfo(DEF_PID), HGM_ERROR);
84 }
85 
86 /**
87  * @tc.name: NotifyPageName002
88  * @tc.desc: Verify the result of NotifyPageName002 function
89  * @tc.type: FUNC
90  * @tc.require:
91  */
92 HWTEST_F(HgmAppPageUrlStrategyTest, NotifyPageName002, Function | SmallTest | Level1)
93 {
94     appPageUrlStrategy_->SetPageUrlConfig(screenSetting_.pageUrlConfig);
95     appPageUrlStrategy_->NotifyPageName(DEF_PID, PKG_NAME, PAGE_NAME, true);
96     ASSERT_EQ(GetPageUrlVoteInfo(DEF_PID), EXEC_SUCCESS);
97     appPageUrlStrategy_->NotifyPageName(DEF_PID, PKG_NAME, PAGE_NAME, false);
98     ASSERT_EQ(GetPageUrlVoteInfo(DEF_PID), HGM_ERROR);
99 }
100 
101 /**
102  * @tc.name: NotifyScreenSettingChange001
103  * @tc.desc: Verify the result of NotifyScreenSettingChange001 function
104  * @tc.type: FUNC
105  * @tc.require:
106  */
107 HWTEST_F(HgmAppPageUrlStrategyTest, NotifyScreenSettingChange001, Function | SmallTest | Level1)
108 {
109     PolicyConfigData::ScreenSetting screenSetting;
110 
111     appPageUrlStrategy_->SetPageUrlConfig(screenSetting.pageUrlConfig);
112     appPageUrlStrategy_->NotifyPageName(DEF_PID, PKG_NAME, PAGE_NAME, true);
113     ASSERT_EQ(GetPageUrlVoteInfo(DEF_PID), HGM_ERROR);
114 
115     appPageUrlStrategy_->SetPageUrlConfig(screenSetting_.pageUrlConfig);
116     appPageUrlStrategy_->NotifyScreenSettingChange();
117     ASSERT_EQ(GetPageUrlVoteInfo(DEF_PID), EXEC_SUCCESS);
118     appPageUrlStrategy_->NotifyPageName(DEF_PID, PKG_NAME, PAGE_NAME, false);
119     ASSERT_EQ(GetPageUrlVoteInfo(DEF_PID), HGM_ERROR);
120 }
121 
122 /**
123  * @tc.name: NotifyScreenSettingChange002
124  * @tc.desc: Verify the result of NotifyScreenSettingChange002 function
125  * @tc.type: FUNC
126  * @tc.require:
127  */
128 HWTEST_F(HgmAppPageUrlStrategyTest, NotifyScreenSettingChange002, Function | SmallTest | Level1)
129 {
130     PolicyConfigData::ScreenSetting screenSetting;
131 
132     appPageUrlStrategy_->SetPageUrlConfig(screenSetting_.pageUrlConfig);
133     appPageUrlStrategy_->NotifyPageName(DEF_PID, PKG_NAME, PAGE_NAME, true);
134     ASSERT_EQ(GetPageUrlVoteInfo(DEF_PID), EXEC_SUCCESS);
135 
136     appPageUrlStrategy_->SetPageUrlConfig(screenSetting.pageUrlConfig);
137     appPageUrlStrategy_->NotifyScreenSettingChange();
138     ASSERT_EQ(GetPageUrlVoteInfo(DEF_PID), HGM_ERROR);
139     appPageUrlStrategy_->NotifyPageName(DEF_PID, PKG_NAME, PAGE_NAME, false);
140     ASSERT_EQ(GetPageUrlVoteInfo(DEF_PID), HGM_ERROR);
141 }
142 } // namespace Rosen
143 } // namespace OHOS