!429 merge cherry-pick-mr-412-1783483912326-auto into master

fix window translate problem

Created-by: panyongchaox
Commit-by: baoyang
Merged-by: openharmony_ci
Description: ### 关联的issue:
https://gitcode.com/openharmony/security_security_component_manager/issues/408

### 修改描述:

### 测试用例(附上截图):
TDD:
![image.png](https://raw.gitcode.com/user-images/assets/4378957/0bfb31e7-f3ef-4766-b5fe-69b381f13f5c/image.png 'image.png')
XTS:
![image.png](https://raw.gitcode.com/user-images/assets/4378957/3c9a44c8-c20f-480d-bacd-6179702192d3/image.png 'image.png')
手工用例:

### 兼容性上库自检:
- [x] 不涉及组件视觉效果发生变化
- [x] 不涉及组件布局调整
- [x] 不涉及组件交互体验发生变化
- [x] 不涉及组件动效发生变化
- [x] 不涉及组件无障碍、适老化、全球化规格变化
- [x] 不涉及API功能发生变化
- [x] 不涉及改变回调函数或生命周期的触发时机或时序,或删除生命周期和回调函数
- [x] 不涉及参数的规格发生了变化,例如取值范围缩小等
- [x] 不涉及对外接口新增权限校验
- [x] 不涉及接口的使用约束规格收紧,例如权限开放范围变化
- [x] 不涉及系统可创建的实例数量收紧
- [x] 不涉及修改了接口返回的数据
- [x] 未新增错误抛出,包括新增错误码、对已有的场景从不会抛错误码变成会抛出错误
- [x] 未修改已有的错误码,对于相同的输入原本抛出A错误码变成了抛出B错误码
- [x] 接口性能未出现明显劣化

### 日志规范自检:
- [x] 【规则】高频代码的正常流程中禁止打印日志
- [x] 【规则】在基本不可能发生的点必须要打印日志
- [x] 【规则】事件记录的日志使用who do what 主谓宾的形式打印
- [x] 【规则】状态变化的日志打印使用state_name:s1->s2, reason:msg的形式打印
- [x] 【规则】参数值的日志打印使用name1=value1, name2=value2…的形式打印
- [x] 【规则】代码运行成功的日志使用xxx successful的形式打印
- [x] 【规则】代码运行失败的日志使用xxx failed, please xxx的形式打印

### 安全编码自检:
- [x] 裸指针避免通过隐式转换构造为sptr
- [x] json对象在取值之前必须先判断类型,避免类型不匹配
- [x] 序列化时必须对传入的数组大小进行校验,避免出现超大数组
- [x] 避免使用未明确位宽的整型,选择使用int8_t、uint8_t等类型
- [x] 外部传入的路径要做规范化校验,对路径中的.、..、../等特殊字符严格校验
- [x] 指针变量、表示资源描述符的变量、bool变量必须赋初值
- [x] readParcelable获取的对象使用前需要判空
- [x] 分配和释放内存的函数需要成对出现
- [x] 申请内存后异常退出前需要及时进行内存释放
- [x] 内存申请前必须对内存大小进行合法性校验
- [x] 内存分配后必须判断是否成功
- [x] 禁止使用realloc、alloc函数
- [x] 禁止打印文件路径、口令等敏感信息,如有需要,使用private修饰
- [x] 禁止打印内存地址
- [x] 整数之间运算时必须严格检查,确保不会出现溢出、反转、除0
- [x] 禁止对有符号整数进行位操作符运算
- [x] 禁止对指针进行逻辑或位运算
- [x] 循环次数如果收外部数据控制,需要检验其合法性
- [x] 禁止使用内存操作类危险函数,需要使用安全函数
- [x] 谨慎使用不可重入函数
- [x] 必须检查安全函数的返回值,并进行正确处理
- [x] 禁止仅通过TokenType类型判断绕过权限校验


See merge request: openharmony/security_security_component_manager!429
This commit is contained in:
openharmony_ci
2026-07-10 17:10:54 +08:00
12 changed files with 274 additions and 31 deletions
@@ -60,6 +60,31 @@ HWTEST_F(LocationButtonTest, ToJsonStr001, TestSize.Level1)
EXPECT_EQ(jsonComponent.dump(), button.ToJsonStr());
}
/**
* @tc.name: ToJsonStr002
* @tc.desc: Test ToJsonStr with isSmartEdgeState
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LocationButtonTest, ToJsonStr002, TestSize.Level1)
{
nlohmann::json jsonComponent;
LocationButton button;
std::string message;
bool isClicked = true;
TestCommon::BuildLocationComponentInfo(jsonComponent);
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = true;
EXPECT_TRUE(button.FromJson(jsonComponent, message, isClicked));
EXPECT_TRUE(button.isSmartEdgeState_);
EXPECT_EQ(jsonComponent.dump(), button.ToJsonStr());
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = false;
EXPECT_TRUE(button.FromJson(jsonComponent, message, isClicked));
EXPECT_FALSE(button.isSmartEdgeState_);
EXPECT_EQ(jsonComponent.dump(), button.ToJsonStr());
}
/**
* @tc.name: CompareComponentBasicInfo001
* @tc.desc: Test CompareComponentBasicInfo other is null
@@ -26,6 +26,7 @@ using namespace OHOS::Security::SecurityComponent;
namespace {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "PasteButtonTest"};
static const std::string WRONG_TYPE = "wrongType";
}
void PasteButtonTest::SetUpTestCase()
@@ -187,3 +188,30 @@ HWTEST_F(PasteButtonTest, IsCorrespondenceType001, TestSize.Level1)
button.type_ = LOCATION_COMPONENT;
EXPECT_FALSE(button.IsCorrespondenceType());
}
/**
* @tc.name: FromJson001
* @tc.desc: Test paste button from wrong isSmartEdgeState json
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(PasteButtonTest, FromJson001, TestSize.Level1)
{
nlohmann::json jsonComponent;
PasteButton comp;
std::string message;
bool isClicked = true;
TestCommon::BuildPasteComponentInfo(jsonComponent);
EXPECT_TRUE(comp.FromJson(jsonComponent, message, isClicked));
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = WRONG_TYPE;
EXPECT_FALSE(comp.FromJson(jsonComponent, message, isClicked));
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = true;
EXPECT_TRUE(comp.FromJson(jsonComponent, message, isClicked));
EXPECT_TRUE(comp.isSmartEdgeState_);
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = false;
EXPECT_TRUE(comp.FromJson(jsonComponent, message, isClicked));
EXPECT_FALSE(comp.isSmartEdgeState_);
}
@@ -775,7 +775,34 @@ HWTEST_F(SaveButtonTest, FromJson020, TestSize.Level1)
jsonComponent[JsonTagConstants::JSON_IS_OVERLAY_TEXT_SET_TAG] = true;
jsonComponent[JsonTagConstants::JSON_IS_OVERLAY_NODE_SET_TAG] = WRONG_TYPE;
EXPECT_FALSE(comp.FromJson(jsonComponent, message, isClicked));
jsonComponent[JsonTagConstants::JSON_IS_ARKUI_COMPONENT] = WRONG_TYPE;
EXPECT_FALSE(comp.FromJson(jsonComponent, message, isClicked));
}
/**
* @tc.name: FromJson021
* @tc.desc: Test save button from wrong isSmartEdgeState json
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SaveButtonTest, FromJson021, TestSize.Level1)
{
nlohmann::json jsonComponent;
SaveButton comp;
std::string message;
bool isClicked = true;
TestCommon::BuildSaveComponentInfo(jsonComponent);
EXPECT_TRUE(comp.FromJson(jsonComponent, message, isClicked));
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = WRONG_TYPE;
EXPECT_FALSE(comp.FromJson(jsonComponent, message, isClicked));
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = true;
EXPECT_TRUE(comp.FromJson(jsonComponent, message, isClicked));
EXPECT_TRUE(comp.isSmartEdgeState_);
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = false;
EXPECT_TRUE(comp.FromJson(jsonComponent, message, isClicked));
EXPECT_FALSE(comp.isSmartEdgeState_);
}
@@ -97,6 +97,7 @@ void TestCommon::BuildLocationComponentInfo(nlohmann::json& jsonComponent)
jsonComponent[JsonTagConstants::JSON_IS_CUSTOMIZABLE] = false;
jsonComponent[JsonTagConstants::JSON_TIP_POSITION] = TipPosition::ABOVE_BOTTOM;
jsonComponent[JsonTagConstants::JSON_IS_ARKUI_COMPONENT] = false;
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = false;
}
void TestCommon::BuildSaveComponentInfo(nlohmann::json& jsonComponent)
@@ -129,6 +130,7 @@ void TestCommon::BuildSaveComponentInfo(nlohmann::json& jsonComponent)
jsonComponent[JsonTagConstants::JSON_IS_CUSTOMIZABLE] = false;
jsonComponent[JsonTagConstants::JSON_TIP_POSITION] = TipPosition::ABOVE_BOTTOM;
jsonComponent[JsonTagConstants::JSON_IS_ARKUI_COMPONENT] = false;
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = false;
}
void TestCommon::BuildPasteComponentInfo(nlohmann::json& jsonComponent)
@@ -161,6 +163,7 @@ void TestCommon::BuildPasteComponentInfo(nlohmann::json& jsonComponent)
jsonComponent[JsonTagConstants::JSON_IS_CUSTOMIZABLE] = false;
jsonComponent[JsonTagConstants::JSON_TIP_POSITION] = TipPosition::ABOVE_BOTTOM;
jsonComponent[JsonTagConstants::JSON_IS_ARKUI_COMPONENT] = false;
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = false;
}
} // namespace SecurityComponent
} // namespace Security
@@ -80,6 +80,7 @@ const std::string JsonTagConstants::JSON_IS_OVERLAY_NODE_SET_TAG = "isOverlayNod
const std::string JsonTagConstants::JSON_TIP_POSITION = "tipPosition";
const std::string JsonTagConstants::JSON_IS_CUSTOMIZABLE = "isCustomizable";
const std::string JsonTagConstants::JSON_IS_ARKUI_COMPONENT = "isArkuiComponent";
const std::string JsonTagConstants::JSON_IS_SMART_EDGE_STATE = "isSmartEdgeState";
bool SecCompBase::ParseNonCompatibleChange(const nlohmann::json& json)
{
@@ -428,6 +429,9 @@ bool SecCompBase::ParseComponentInfo(const nlohmann::json& json, std::string& me
if (!ParseBool(json, JsonTagConstants::JSON_IS_ARKUI_COMPONENT, isArkuiComponent_)) {
return false;
}
if (!ParseBool(json, JsonTagConstants::JSON_IS_SMART_EDGE_STATE, isSmartEdgeState_)) {
return false;
}
return true;
}
@@ -585,6 +589,7 @@ void SecCompBase::ToJson(nlohmann::json& jsonRes) const
jsonRes[JsonTagConstants::JSON_IS_CUSTOMIZABLE] = isCustomizable_;
jsonRes[JsonTagConstants::JSON_TIP_POSITION] = tipPosition_;
jsonRes[JsonTagConstants::JSON_IS_ARKUI_COMPONENT] = isArkuiComponent_;
jsonRes[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = isSmartEdgeState_;
}
std::string SecCompBase::ToJsonStr() const
@@ -97,6 +97,7 @@ public:
static const std::string JSON_IS_CUSTOMIZABLE;
static const std::string JSON_TIP_POSITION;
static const std::string JSON_IS_ARKUI_COMPONENT;
static const std::string JSON_IS_SMART_EDGE_STATE;
};
class __attribute__((visibility("default"))) SecCompBase {
@@ -168,6 +169,7 @@ public:
bool isClickEvent_ = false;
bool isArkuiComponent_ = false;
bool isCompatScaleMode_ = false;
bool isSmartEdgeState_ = false;
protected:
virtual bool IsTextIconTypeValid(std::string& message, bool isClicked) = 0;
virtual bool IsCorrespondenceType() = 0;
@@ -387,7 +387,7 @@ bool SecCompInfoHelper::CheckComponentValid(SecCompBase* comp, std::string& mess
if ((!IsEqual(scales.floatingScale, WindowInfoHelper::FULL_SCREEN_SCALE) && !IsEqual(scales.floatingScale, 0.0)) ||
(!IsEqual(scales.scaleX, WindowInfoHelper::FULL_SCREEN_SCALE) && !IsEqual(scales.scaleX, 0.0)) ||
(!IsEqual(scales.scaleY, WindowInfoHelper::FULL_SCREEN_SCALE) && !IsEqual(scales.scaleY, 0.0)) ||
isCompatScaleMode) {
isCompatScaleMode || comp->isSmartEdgeState_) {
AdjustSecCompRect(comp, scales, isCompatScaleMode, scaleRect);
}
@@ -39,7 +39,7 @@ bool WindowInfoHelper::TryGetWindowInfo(int32_t windowId, sptr<Rosen::Accessibil
}
auto iter = std::find_if(infos.begin(), infos.end(),
[windowId](const sptr<Rosen::AccessibilityWindowInfo>& info) {
return (info != nullptr) && (windowId == info->wid_);
return (info != nullptr) && (windowId == info->wid_ || (info->wid_ == 1 && windowId == info->innerWid_));
});
if (iter == infos.end()) {
return false;
@@ -726,6 +726,42 @@ HWTEST_F(SecCompInfoHelperTest, AdjustSecCompRect002, TestSize.Level0)
EXPECT_TRUE(IsEqual(comp->rect_.y_, 3));
}
/**
* @tc.name: AdjustSecCompRect003
* @tc.desc: Test AdjustSecCompRect with isSmartEdgeState
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SecCompInfoHelperTest, AdjustSecCompRect003, TestSize.Level0)
{
nlohmann::json jsonComponent;
ServiceTestCommon::BuildLocationComponentJson(jsonComponent);
std::string message;
SecCompRect scaleRect;
SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message);
Scales scales;
scales.floatingScale = 0.8f;
scales.scaleX = 0.9f;
scales.scaleY = 0.8f;
comp->rect_.x_ = 10.0f;
comp->rect_.y_ = 5.0f;
comp->rect_.width_ = 20.0f;
comp->rect_.height_ = 10.0f;
comp->windowRect_.x_ = 0.0f;
comp->windowRect_.y_ = 0.0f;
comp->windowRect_.width_ = 200.0f;
comp->windowRect_.height_ = 100.0f;
comp->isSmartEdgeState_ = true;
SecCompInfoHelper::AdjustSecCompRect(comp, scales, false, scaleRect);
EXPECT_TRUE(IsEqual(comp->rect_.width_, 18));
EXPECT_TRUE(IsEqual(comp->rect_.height_, 8));
EXPECT_TRUE(IsEqual(comp->rect_.x_, 9));
EXPECT_TRUE(IsEqual(comp->rect_.y_, 4));
EXPECT_TRUE(IsEqual(comp->scale_, 0.9f));
}
/**
* @tc.name: CheckComponentValid001
* @tc.desc: Test CheckComponentValid with invalid color
@@ -859,7 +895,11 @@ HWTEST_F(SecCompInfoHelperTest, CheckComponentValid006, TestSize.Level0)
comp->isArkuiComponent_ = false;
comp->bgColor_.value = 0x0C000000;
ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp, message));
comp->isSmartEdgeState_ = true;
ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp, message));
comp->isSmartEdgeState_ = false;
comp->bgColor_.value = 0x00000000;
ASSERT_FALSE(SecCompInfoHelper::CheckComponentValid(comp, message));
}
@@ -93,6 +93,7 @@ void ServiceTestCommon::BuildLocationComponentJson(nlohmann::json& jsonComponent
jsonComponent[JsonTagConstants::JSON_IS_CUSTOMIZABLE] = false;
jsonComponent[JsonTagConstants::JSON_TIP_POSITION] = TipPosition::ABOVE_BOTTOM;
jsonComponent[JsonTagConstants::JSON_IS_ARKUI_COMPONENT] = false;
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = false;
}
void ServiceTestCommon::BuildSaveComponentJson(nlohmann::json& jsonComponent)
@@ -170,6 +171,7 @@ void ServiceTestCommon::BuildSaveComponentJson(nlohmann::json& jsonComponent)
jsonComponent[JsonTagConstants::JSON_IS_CUSTOMIZABLE] = false;
jsonComponent[JsonTagConstants::JSON_TIP_POSITION] = TipPosition::ABOVE_BOTTOM;
jsonComponent[JsonTagConstants::JSON_IS_ARKUI_COMPONENT] = false;
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = false;
}
void ServiceTestCommon::BuildPasteComponentJson(nlohmann::json& jsonComponent)
@@ -247,6 +249,7 @@ void ServiceTestCommon::BuildPasteComponentJson(nlohmann::json& jsonComponent)
jsonComponent[JsonTagConstants::JSON_IS_CUSTOMIZABLE] = false;
jsonComponent[JsonTagConstants::JSON_TIP_POSITION] = TipPosition::ABOVE_BOTTOM;
jsonComponent[JsonTagConstants::JSON_IS_ARKUI_COMPONENT] = false;
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = false;
}
} // namespace SecurityComponent
} // namespace Security
@@ -51,33 +51,6 @@ public:
} // namespace Security
} // namespace OHOS
/**
* @tc.name: TryGetWindowInfo001
* @tc.desc: Test null window info is skipped
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(WindowInfoHelperTest, TryGetWindowInfo001, TestSize.Level0)
{
auto oldResult = WindowManager::GetInstance().result_;
auto oldList = WindowManager::GetInstance().list_;
WindowManager::GetInstance().result_ = WMError::WM_OK;
std::vector<sptr<AccessibilityWindowInfo>> list;
list.emplace_back(nullptr);
sptr<AccessibilityWindowInfo> compWin = new AccessibilityWindowInfo();
compWin->wid_ = 1;
list.emplace_back(compWin);
WindowManager::GetInstance().list_ = list;
sptr<AccessibilityWindowInfo> windowInfo = nullptr;
EXPECT_TRUE(WindowInfoHelper::TryGetWindowInfo(1, windowInfo));
EXPECT_NE(nullptr, windowInfo);
if (windowInfo != nullptr) {
EXPECT_EQ(1, windowInfo->wid_);
}
WindowManager::GetInstance().list_ = oldList;
WindowManager::GetInstance().result_ = oldResult;
}
/**
* @tc.name: CheckOtherWindowCoverComp001
@@ -314,3 +287,137 @@ HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp007, TestSize.Level0)
std::string message;
ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect, message));
}
/**
* @tc.name: TryGetWindowInfo001
* @tc.desc: Test TryGetWindowInfo with normal windowId match
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(WindowInfoHelperTest, TryGetWindowInfo001, TestSize.Level0)
{
WindowManager::GetInstance().result_ = WMError::WM_OK;
std::vector<sptr<AccessibilityWindowInfo>> list;
sptr<AccessibilityWindowInfo> win1 = new AccessibilityWindowInfo();
win1->wid_ = 0;
list.emplace_back(win1);
sptr<AccessibilityWindowInfo> win2 = new AccessibilityWindowInfo();
win2->wid_ = 1;
list.emplace_back(win2);
WindowManager::GetInstance().list_ = list;
sptr<AccessibilityWindowInfo> windowInfo;
ASSERT_TRUE(WindowInfoHelper::TryGetWindowInfo(0, windowInfo));
ASSERT_NE(nullptr, windowInfo);
EXPECT_EQ(0, windowInfo->wid_);
ASSERT_TRUE(WindowInfoHelper::TryGetWindowInfo(1, windowInfo));
ASSERT_NE(nullptr, windowInfo);
EXPECT_EQ(1, windowInfo->wid_);
}
/**
* @tc.name: TryGetWindowInfo002
* @tc.desc: Test TryGetWindowInfo with smart edge windowId match (wid_ == 1 && windowId == innerWid_)
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(WindowInfoHelperTest, TryGetWindowInfo002, TestSize.Level0)
{
WindowManager::GetInstance().result_ = WMError::WM_OK;
std::vector<sptr<AccessibilityWindowInfo>> list;
sptr<AccessibilityWindowInfo> smartEdgeWin = new AccessibilityWindowInfo();
smartEdgeWin->wid_ = 1;
smartEdgeWin->innerWid_ = 100;
list.emplace_back(smartEdgeWin);
WindowManager::GetInstance().list_ = list;
sptr<AccessibilityWindowInfo> windowInfo;
ASSERT_TRUE(WindowInfoHelper::TryGetWindowInfo(100, windowInfo));
ASSERT_NE(nullptr, windowInfo);
EXPECT_EQ(1, windowInfo->wid_);
EXPECT_EQ(100, windowInfo->innerWid_);
}
/**
* @tc.name: TryGetWindowInfo003
* @tc.desc: Test TryGetWindowInfo with smart edge windowId not match
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(WindowInfoHelperTest, TryGetWindowInfo003, TestSize.Level0)
{
WindowManager::GetInstance().result_ = WMError::WM_OK;
std::vector<sptr<AccessibilityWindowInfo>> list;
sptr<AccessibilityWindowInfo> smartEdgeWin = new AccessibilityWindowInfo();
smartEdgeWin->wid_ = 1;
smartEdgeWin->innerWid_ = 100;
list.emplace_back(smartEdgeWin);
WindowManager::GetInstance().list_ = list;
sptr<AccessibilityWindowInfo> windowInfo;
ASSERT_FALSE(WindowInfoHelper::TryGetWindowInfo(101, windowInfo));
ASSERT_EQ(nullptr, windowInfo);
}
/**
* @tc.name: TryGetWindowInfo004
* @tc.desc: Test TryGetWindowInfo with mixed windows (normal and smart edge)
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(WindowInfoHelperTest, TryGetWindowInfo004, TestSize.Level0)
{
WindowManager::GetInstance().result_ = WMError::WM_OK;
std::vector<sptr<AccessibilityWindowInfo>> list;
sptr<AccessibilityWindowInfo> normalWin = new AccessibilityWindowInfo();
normalWin->wid_ = 0;
list.emplace_back(normalWin);
sptr<AccessibilityWindowInfo> smartEdgeWin = new AccessibilityWindowInfo();
smartEdgeWin->wid_ = 1;
smartEdgeWin->innerWid_ = 100;
list.emplace_back(smartEdgeWin);
WindowManager::GetInstance().list_ = list;
sptr<AccessibilityWindowInfo> windowInfo;
ASSERT_TRUE(WindowInfoHelper::TryGetWindowInfo(0, windowInfo));
ASSERT_NE(nullptr, windowInfo);
EXPECT_EQ(0, windowInfo->wid_);
ASSERT_TRUE(WindowInfoHelper::TryGetWindowInfo(100, windowInfo));
ASSERT_NE(nullptr, windowInfo);
EXPECT_EQ(1, windowInfo->wid_);
EXPECT_EQ(100, windowInfo->innerWid_);
ASSERT_FALSE(WindowInfoHelper::TryGetWindowInfo(999, windowInfo));
}
/**
* @tc.name: TryGetWindowInfo005
* @tc.desc: Test null window info is skipped
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(WindowInfoHelperTest, TryGetWindowInfo005, TestSize.Level0)
{
auto oldResult = WindowManager::GetInstance().result_;
auto oldList = WindowManager::GetInstance().list_;
WindowManager::GetInstance().result_ = WMError::WM_OK;
std::vector<sptr<AccessibilityWindowInfo>> list;
list.emplace_back(nullptr);
sptr<AccessibilityWindowInfo> compWin = new AccessibilityWindowInfo();
compWin->wid_ = 1;
list.emplace_back(compWin);
WindowManager::GetInstance().list_ = list;
sptr<AccessibilityWindowInfo> windowInfo = nullptr;
EXPECT_TRUE(WindowInfoHelper::TryGetWindowInfo(1, windowInfo));
EXPECT_NE(nullptr, windowInfo);
if (windowInfo != nullptr) {
EXPECT_EQ(1, windowInfo->wid_);
}
WindowManager::GetInstance().list_ = oldList;
WindowManager::GetInstance().result_ = oldResult;
}
@@ -119,6 +119,7 @@ std::string CompoRandomGenerator::ConstructLocationJson()
jsonComponent[JsonTagConstants::JSON_IS_CUSTOMIZABLE] = false;
jsonComponent[JsonTagConstants::JSON_TIP_POSITION] = TipPosition::ABOVE_BOTTOM;
jsonComponent[JsonTagConstants::JSON_IS_ARKUI_COMPONENT] = false;
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = false;
compoJson_ = jsonComponent;
return compoJson_.dump();
}
@@ -175,6 +176,7 @@ std::string CompoRandomGenerator::ConstructSaveJson()
jsonComponent[JsonTagConstants::JSON_IS_CUSTOMIZABLE] = false;
jsonComponent[JsonTagConstants::JSON_TIP_POSITION] = TipPosition::ABOVE_BOTTOM;
jsonComponent[JsonTagConstants::JSON_IS_ARKUI_COMPONENT] = false;
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = false;
compoJson_ = jsonComponent;
return compoJson_.dump();
}
@@ -231,6 +233,7 @@ std::string CompoRandomGenerator::ConstructPasteJson()
jsonComponent[JsonTagConstants::JSON_IS_CUSTOMIZABLE] = false;
jsonComponent[JsonTagConstants::JSON_TIP_POSITION] = TipPosition::ABOVE_BOTTOM;
jsonComponent[JsonTagConstants::JSON_IS_ARKUI_COMPONENT] = false;
jsonComponent[JsonTagConstants::JSON_IS_SMART_EDGE_STATE] = false;
compoJson_ = jsonComponent;
return compoJson_.dump();
}