mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-12-11 18:05:04 +00:00
Add preventDefault tests
Signed-off-by: yangziyong <nsyangziyong@huawei.com>
This commit is contained in:
parent
a2e05b326f
commit
41cb664a07
@ -17,26 +17,27 @@
|
||||
#include <optional>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#define protected public
|
||||
#define private public
|
||||
|
||||
#include "test/mock/core/common/mock_theme_manager.h"
|
||||
#include "test/mock/core/pipeline/mock_pipeline_context.h"
|
||||
|
||||
#include "base/memory/ace_type.h"
|
||||
#include "base/memory/referenced.h"
|
||||
#include "core/components_ng/event/focus_hub.h"
|
||||
#include "core/pipeline/base/element_register.h"
|
||||
#include "core/pipeline_ng/ui_task_scheduler.h"
|
||||
|
||||
#define protected public
|
||||
#define private public
|
||||
#include "core/components/button/button_theme.h"
|
||||
#include "core/components/toggle/toggle_theme.h"
|
||||
#include "core/components_ng/base/view_stack_processor.h"
|
||||
#include "core/components_ng/event/focus_hub.h"
|
||||
#include "core/components_ng/pattern/button/button_pattern.h"
|
||||
#include "core/components_ng/pattern/button/toggle_button_model_ng.h"
|
||||
#include "core/components_ng/pattern/button/toggle_button_paint_property.h"
|
||||
#include "core/components_ng/pattern/button/toggle_button_pattern.h"
|
||||
#include "core/components_ng/pattern/text/text_pattern.h"
|
||||
#include "test/mock/core/common/mock_theme_manager.h"
|
||||
#include "core/components_v2/inspector/inspector_constants.h"
|
||||
#include "test/mock/core/pipeline/mock_pipeline_context.h"
|
||||
#include "core/event/touch_event.h"
|
||||
#include "core/pipeline/base/element_register.h"
|
||||
#include "core/pipeline_ng/ui_task_scheduler.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
@ -469,4 +470,98 @@ HWTEST_F(ToggleButtonTestNg, ToggleButtonPatternTest011, TestSize.Level1)
|
||||
pattern->UpdateSelectStatus(isSelected);
|
||||
EXPECT_TRUE(accessibilityProperty->ActActionClearSelection());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PreventDefault001
|
||||
* @tc.desc: test InitTouchEvent and InitClickEvent
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ToggleButtonTestNg, PreventDefault001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Create toggleButtonModelNG.
|
||||
*/
|
||||
ToggleButtonModelNG toggleButtonModelNG;
|
||||
toggleButtonModelNG.Create(TOGGLE_ETS_TAG);
|
||||
toggleButtonModelNG.SetIsOn(true);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
auto pattern = frameNode->GetPattern<ToggleButtonPattern>();
|
||||
ASSERT_NE(pattern, nullptr);
|
||||
auto gestureHub = frameNode->GetOrCreateGestureEventHub();
|
||||
ASSERT_NE(gestureHub, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Mock TouchEventInfo info and set preventDefault to true
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitTouchEvent();
|
||||
TouchEventInfo touchInfo("onTouch");
|
||||
TouchLocationInfo touchDownInfo(1);
|
||||
touchDownInfo.SetTouchType(TouchType::DOWN);
|
||||
touchInfo.SetPreventDefault(true);
|
||||
touchInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
touchInfo.AddTouchLocationInfo(std::move(touchDownInfo));
|
||||
pattern->touchListener_->callback_(touchInfo);
|
||||
EXPECT_TRUE(pattern->isTouchPreventDefault_);
|
||||
EXPECT_TRUE(pattern->isPress_);
|
||||
/**
|
||||
* @tc.steps: step3.Mock GestureEvent info and set preventDefault to true
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitClickEvent();
|
||||
GestureEvent clickInfo;
|
||||
clickInfo.SetPreventDefault(true);
|
||||
clickInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
pattern->clickListener_->operator()(clickInfo);
|
||||
EXPECT_FALSE(pattern->isTouchPreventDefault_);
|
||||
EXPECT_FALSE(pattern->isOn_);
|
||||
EXPECT_FALSE(pattern->isFocus_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PreventDefault002
|
||||
* @tc.desc: test InitTouchEvent and InitClickEvent
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ToggleButtonTestNg, PreventDefault002, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Create toggleButtonModelNG.
|
||||
*/
|
||||
ToggleButtonModelNG toggleButtonModelNG;
|
||||
toggleButtonModelNG.Create(TOGGLE_ETS_TAG);
|
||||
toggleButtonModelNG.SetIsOn(true);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
auto pattern = frameNode->GetPattern<ToggleButtonPattern>();
|
||||
ASSERT_NE(pattern, nullptr);
|
||||
auto gestureHub = frameNode->GetOrCreateGestureEventHub();
|
||||
ASSERT_NE(gestureHub, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Mock TouchEvent info and set preventDefault to false
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitTouchEvent();
|
||||
TouchEventInfo touchInfo("onTouch");
|
||||
TouchLocationInfo touchDownInfo(1);
|
||||
touchDownInfo.SetTouchType(TouchType::DOWN);
|
||||
touchInfo.SetPreventDefault(false);
|
||||
touchInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
touchInfo.AddTouchLocationInfo(std::move(touchDownInfo));
|
||||
pattern->touchListener_->callback_(touchInfo);
|
||||
EXPECT_EQ(touchInfo.IsPreventDefault(), pattern->isTouchPreventDefault_);
|
||||
/**
|
||||
* @tc.steps: step3. Mock GestureEvent info and set preventDefault to false
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitClickEvent();
|
||||
GestureEvent clickInfo;
|
||||
clickInfo.SetPreventDefault(false);
|
||||
clickInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
pattern->clickListener_->operator()(clickInfo);
|
||||
EXPECT_FALSE(pattern->isTouchPreventDefault_);
|
||||
EXPECT_TRUE(pattern->isOn_);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -722,4 +722,93 @@ HWTEST_F(CheckBoxPatternSubTestNG, CheckBoxPatternTest063, TestSize.Level1)
|
||||
eventHub->getInnerFocusRectFunc_(paintRect);
|
||||
EXPECT_EQ(paintRect.GetRect().ToString(), "RectT (-100.00, -100.00) - [400.00 x 400.00]");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PreventDefault001
|
||||
* @tc.desc: test InitTouchEvent and InitClickEvent
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(CheckBoxPatternSubTestNG, PreventDefault001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Init CheckBox node
|
||||
*/
|
||||
CheckBoxModelNG checkBoxModelNG;
|
||||
checkBoxModelNG.Create(NAME, GROUP_NAME, TAG);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
auto pattern = frameNode->GetPattern<CheckBoxPattern>();
|
||||
ASSERT_NE(pattern, nullptr);
|
||||
auto gestureHub = frameNode->GetOrCreateGestureEventHub();
|
||||
ASSERT_NE(gestureHub, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Mock TouchEventInfo info and set preventDefault to true
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitTouchEvent();
|
||||
TouchEventInfo touchInfo("onTouch");
|
||||
TouchLocationInfo touchDownInfo(1);
|
||||
touchDownInfo.SetTouchType(TouchType::DOWN);
|
||||
touchInfo.SetPreventDefault(true);
|
||||
touchInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
touchInfo.AddTouchLocationInfo(std::move(touchDownInfo));
|
||||
pattern->touchListener_->callback_(touchInfo);
|
||||
EXPECT_TRUE(pattern->isTouchPreventDefault_);
|
||||
EXPECT_EQ(pattern->touchHoverType_, TouchHoverAnimationType::PRESS);
|
||||
/**
|
||||
* @tc.steps: step3.Mock GestureEvent info and set preventDefault to true
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitClickEvent();
|
||||
GestureEvent clickInfo;
|
||||
clickInfo.SetPreventDefault(true);
|
||||
clickInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
pattern->clickListener_->operator()(clickInfo);
|
||||
EXPECT_FALSE(pattern->isTouchPreventDefault_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PreventDefault002
|
||||
* @tc.desc: test InitTouchEvent and InitClickEvent
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(CheckBoxPatternSubTestNG, PreventDefault002, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Init CheckBox node
|
||||
*/
|
||||
CheckBoxModelNG checkBoxModelNG;
|
||||
checkBoxModelNG.Create(NAME, GROUP_NAME, TAG);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
auto pattern = frameNode->GetPattern<CheckBoxPattern>();
|
||||
ASSERT_NE(pattern, nullptr);
|
||||
auto gestureHub = frameNode->GetOrCreateGestureEventHub();
|
||||
ASSERT_NE(gestureHub, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Mock TouchEvent info and set preventDefault to false
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitTouchEvent();
|
||||
TouchEventInfo touchInfo("onTouch");
|
||||
TouchLocationInfo touchDownInfo(1);
|
||||
touchDownInfo.SetTouchType(TouchType::DOWN);
|
||||
touchInfo.SetPreventDefault(false);
|
||||
touchInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
touchInfo.AddTouchLocationInfo(std::move(touchDownInfo));
|
||||
pattern->touchListener_->callback_(touchInfo);
|
||||
EXPECT_FALSE(pattern->isTouchPreventDefault_);
|
||||
/**
|
||||
* @tc.steps: step3. Mock GestureEvent info and set preventDefault to false
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitClickEvent();
|
||||
GestureEvent clickInfo;
|
||||
clickInfo.SetPreventDefault(false);
|
||||
clickInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
pattern->clickListener_->operator()(clickInfo);
|
||||
EXPECT_FALSE(pattern->isTouchPreventDefault_);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -466,4 +466,93 @@ HWTEST_F(CheckBoxGroupPatternTestNG, CheckBoxGroupPatternTest008, TestSize.Level
|
||||
pattern->GetInnerFocusPaintRect(paintRect);
|
||||
AceApplicationInfo::GetInstance().SetApiTargetVersion(backupApiVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PreventDefault001
|
||||
* @tc.desc: test InitTouchEvent and InitClickEvent
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(CheckBoxGroupPatternTestNG, PreventDefault001, TestSize.Level1)
|
||||
{
|
||||
/*
|
||||
* @tc.steps: step1. Create CheckBoxGroup model.
|
||||
*/
|
||||
CheckBoxGroupModelNG checkBoxModelNG;
|
||||
checkBoxModelNG.Create(CHECKBOXGROUP_NAME);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
auto pattern = frameNode->GetPattern<CheckBoxGroupPattern>();
|
||||
ASSERT_NE(pattern, nullptr);
|
||||
auto gestureHub = frameNode->GetOrCreateGestureEventHub();
|
||||
ASSERT_NE(gestureHub, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Mock TouchEventInfo info and set preventDefault to true
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitTouchEvent();
|
||||
TouchEventInfo touchInfo("onTouch");
|
||||
TouchLocationInfo touchDownInfo(1);
|
||||
touchDownInfo.SetTouchType(TouchType::DOWN);
|
||||
touchInfo.SetPreventDefault(true);
|
||||
touchInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
touchInfo.AddTouchLocationInfo(std::move(touchDownInfo));
|
||||
pattern->touchListener_->callback_(touchInfo);
|
||||
EXPECT_TRUE(pattern->isTouchPreventDefault_);
|
||||
EXPECT_EQ(pattern->touchHoverType_, TouchHoverAnimationType::PRESS);
|
||||
/**
|
||||
* @tc.steps: step3.Mock GestureEvent info and set preventDefault to true
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitClickEvent();
|
||||
GestureEvent clickInfo;
|
||||
clickInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
clickInfo.SetPreventDefault(true);
|
||||
pattern->clickListener_->operator()(clickInfo);
|
||||
EXPECT_FALSE(pattern->isTouchPreventDefault_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PreventDefault002
|
||||
* @tc.desc: test InitTouchEvent and InitClickEvent
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(CheckBoxGroupPatternTestNG, PreventDefault002, TestSize.Level1)
|
||||
{
|
||||
/*
|
||||
* @tc.steps: step1. Create CheckBoxGroup model.
|
||||
*/
|
||||
CheckBoxGroupModelNG checkBoxModelNG;
|
||||
checkBoxModelNG.Create(CHECKBOXGROUP_NAME);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
auto pattern = frameNode->GetPattern<CheckBoxGroupPattern>();
|
||||
ASSERT_NE(pattern, nullptr);
|
||||
auto gestureHub = frameNode->GetOrCreateGestureEventHub();
|
||||
ASSERT_NE(gestureHub, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Mock TouchEvent info and set preventDefault to false
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitTouchEvent();
|
||||
TouchEventInfo touchInfo("onTouch");
|
||||
TouchLocationInfo touchDownInfo(1);
|
||||
touchDownInfo.SetTouchType(TouchType::DOWN);
|
||||
touchInfo.SetPreventDefault(false);
|
||||
touchInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
touchInfo.AddTouchLocationInfo(std::move(touchDownInfo));
|
||||
pattern->touchListener_->callback_(touchInfo);
|
||||
EXPECT_EQ(touchInfo.IsPreventDefault(), pattern->isTouchPreventDefault_);
|
||||
/**
|
||||
* @tc.steps: step3. Mock GestureEvent info and set preventDefault to false
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitClickEvent();
|
||||
GestureEvent clickInfo;
|
||||
clickInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
clickInfo.SetPreventDefault(false);
|
||||
pattern->clickListener_->operator()(clickInfo);
|
||||
EXPECT_FALSE(pattern->isTouchPreventDefault_);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "core/components_ng/pattern/stage/stage_manager.h"
|
||||
#include "core/components_ng/pattern/stage/stage_pattern.h"
|
||||
#include "core/components_v2/inspector/inspector_constants.h"
|
||||
|
||||
#include "core/event/touch_event.h"
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
using RadioBuilderFunc = std::function<void()>;
|
||||
@ -342,7 +342,7 @@ HWTEST_F(RadioNodeTestNg, RadioNodeTest006, TestSize.Level1)
|
||||
AceType::MakeRefPtr<FrameNode>("", CHILD_NODE_ID, AceType::MakeRefPtr<Pattern>());
|
||||
return child;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Set parameters to pattern builderFunc
|
||||
*/
|
||||
@ -1005,4 +1005,94 @@ HWTEST_F(RadioNodeTestNg, RadioNodeTest017, TestSize.Level1)
|
||||
*/
|
||||
EXPECT_EQ(isChecked, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PreventDefault001
|
||||
* @tc.desc: test InitTouchEvent and InitClickEvent
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RadioNodeTestNg, PreventDefault001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Init Radio node
|
||||
*/
|
||||
RadioModelNG radioModelNG;
|
||||
radioModelNG.Create(NAME, GROUP_NAME, INDICATOR_TYPE_TICK);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
auto pattern = frameNode->GetPattern<RadioPattern>();
|
||||
ASSERT_NE(pattern, nullptr);
|
||||
auto gestureHub = frameNode->GetOrCreateGestureEventHub();
|
||||
ASSERT_NE(gestureHub, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Mock TouchEventInfo info and set preventDefault to true
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitTouchEvent();
|
||||
TouchEventInfo touchInfo("onTouch");
|
||||
TouchLocationInfo touchDownInfo(1);
|
||||
touchDownInfo.SetTouchType(TouchType::DOWN);
|
||||
touchInfo.SetPreventDefault(true);
|
||||
touchInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
touchInfo.AddTouchLocationInfo(std::move(touchDownInfo));
|
||||
pattern->touchListener_->callback_(touchInfo);
|
||||
EXPECT_TRUE(pattern->isTouchPreventDefault_);
|
||||
EXPECT_EQ(pattern->touchHoverType_, TouchHoverAnimationType::PRESS);
|
||||
/**
|
||||
* @tc.steps: step3.Mock GestureEvent info and set preventDefault to true
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitClickEvent();
|
||||
GestureEvent clickInfo;
|
||||
clickInfo.SetPreventDefault(true);
|
||||
clickInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
pattern->clickListener_->operator()(clickInfo);
|
||||
EXPECT_FALSE(pattern->isTouchPreventDefault_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PreventDefault002
|
||||
* @tc.desc: test InitTouchEvent and InitClickEvent
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RadioNodeTestNg, PreventDefault002, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Init Radio node
|
||||
*/
|
||||
RadioModelNG radioModelNG;
|
||||
radioModelNG.Create(NAME, GROUP_NAME, INDICATOR_TYPE_TICK);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
auto pattern = frameNode->GetPattern<RadioPattern>();
|
||||
ASSERT_NE(pattern, nullptr);
|
||||
auto gestureHub = frameNode->GetOrCreateGestureEventHub();
|
||||
ASSERT_NE(gestureHub, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Mock TouchEvent info and set preventDefault to false
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitTouchEvent();
|
||||
TouchEventInfo touchInfo("onTouch");
|
||||
TouchLocationInfo touchDownInfo(1);
|
||||
touchDownInfo.SetTouchType(TouchType::DOWN);
|
||||
touchInfo.SetPreventDefault(false);
|
||||
touchInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
touchInfo.AddTouchLocationInfo(std::move(touchDownInfo));
|
||||
pattern->touchListener_->callback_(touchInfo);
|
||||
EXPECT_FALSE(pattern->isTouchPreventDefault_);
|
||||
EXPECT_EQ(pattern->touchHoverType_, TouchHoverAnimationType::PRESS);
|
||||
/**
|
||||
* @tc.steps: step3. Mock GestureEvent info and set preventDefault to false
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitClickEvent();
|
||||
GestureEvent clickInfo;
|
||||
clickInfo.SetPreventDefault(false);
|
||||
clickInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
pattern->clickListener_->operator()(clickInfo);
|
||||
EXPECT_FALSE(pattern->isTouchPreventDefault_);
|
||||
}
|
||||
}
|
@ -1663,4 +1663,98 @@ HWTEST_F(RatingTestNg, RatingPatternTest071, TestSize.Level1)
|
||||
ratingPattern->SetBuilderFunc(node);
|
||||
ratingPattern->BuildContentModifierNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PreventDefault001
|
||||
* @tc.desc: test InitTouchEvent and InitClickEvent
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RatingTestNg, PreventDefault001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Create RatingModelNG.
|
||||
*/
|
||||
RatingModelNG rating;
|
||||
rating.Create();
|
||||
rating.SetIndicator(RATING_INDICATOR);
|
||||
rating.SetStepSize(RATING_STEP_SIZE_1);
|
||||
rating.SetStars(DEFAULT_STAR_NUM);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
auto pattern = frameNode->GetPattern<RatingPattern>();
|
||||
ASSERT_NE(pattern, nullptr);
|
||||
auto gestureHub = frameNode->GetOrCreateGestureEventHub();
|
||||
ASSERT_NE(gestureHub, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Mock TouchEventInfo info and set preventDefault to true
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitTouchEvent(gestureHub);
|
||||
TouchEventInfo touchInfo("onTouch");
|
||||
TouchLocationInfo touchDownInfo(1);
|
||||
touchDownInfo.SetTouchType(TouchType::DOWN);
|
||||
touchInfo.SetPreventDefault(true);
|
||||
touchInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
touchInfo.AddTouchLocationInfo(std::move(touchDownInfo));
|
||||
pattern->touchEvent_->callback_(touchInfo);
|
||||
EXPECT_TRUE(pattern->isTouchPreventDefault_);
|
||||
/**
|
||||
* @tc.steps: step3.Mock GestureEvent info and set preventDefault to true
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitClickEvent(gestureHub);
|
||||
GestureEvent clickInfo;
|
||||
clickInfo.SetPreventDefault(true);
|
||||
clickInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
pattern->clickEvent_->operator()(clickInfo);
|
||||
EXPECT_FALSE(pattern->isTouchPreventDefault_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PreventDefault002
|
||||
* @tc.desc: test InitTouchEvent and InitClickEvent
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RatingTestNg, PreventDefault002, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Create RatingModelNG.
|
||||
*/
|
||||
RatingModelNG rating;
|
||||
rating.Create();
|
||||
rating.SetIndicator(RATING_INDICATOR);
|
||||
rating.SetStepSize(RATING_STEP_SIZE_1);
|
||||
rating.SetStars(DEFAULT_STAR_NUM);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
auto pattern = frameNode->GetPattern<RatingPattern>();
|
||||
ASSERT_NE(pattern, nullptr);
|
||||
auto gestureHub = frameNode->GetOrCreateGestureEventHub();
|
||||
ASSERT_NE(gestureHub, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Mock TouchEvent info and set preventDefault to false
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitTouchEvent(gestureHub);
|
||||
TouchEventInfo touchInfo("onTouch");
|
||||
TouchLocationInfo touchDownInfo(1);
|
||||
touchDownInfo.SetTouchType(TouchType::DOWN);
|
||||
touchInfo.SetPreventDefault(false);
|
||||
touchInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
touchInfo.AddTouchLocationInfo(std::move(touchDownInfo));
|
||||
pattern->touchEvent_->callback_(touchInfo);
|
||||
EXPECT_EQ(touchInfo.IsPreventDefault(), pattern->isTouchPreventDefault_);
|
||||
/**
|
||||
* @tc.steps: step3. Mock GestureEvent info and set preventDefault to false
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
pattern->InitClickEvent(gestureHub);
|
||||
GestureEvent clickInfo;
|
||||
clickInfo.SetPreventDefault(false);
|
||||
clickInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
pattern->clickEvent_->operator()(clickInfo);
|
||||
EXPECT_FALSE(pattern->isTouchPreventDefault_);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -1526,4 +1526,97 @@ HWTEST_F(ToggleSwitchTestNg, ToggleSwitchPatternTest006, TestSize.Level1)
|
||||
|
||||
MockContainer::Current()->SetApiTargetVersion(rollbackApiVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PreventDefault001
|
||||
* @tc.desc: test InitTouchEvent and InitClickEvent
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ToggleSwitchTestNg, PreventDefault001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Create toggleModelNG.
|
||||
*/
|
||||
ToggleModelNG toggleModelNG;
|
||||
toggleModelNG.Create(ToggleType::SWITCH, IS_ON);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
auto switchPattern = frameNode->GetPattern<SwitchPattern>();
|
||||
ASSERT_NE(switchPattern, nullptr);
|
||||
auto gestureHub = frameNode->GetOrCreateGestureEventHub();
|
||||
ASSERT_NE(gestureHub, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Mock TouchEventInfo info and set preventDefault to true
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
switchPattern->InitTouchEvent();
|
||||
TouchEventInfo touchInfo("onTouch");
|
||||
TouchLocationInfo touchDownInfo(1);
|
||||
touchDownInfo.SetTouchType(TouchType::DOWN);
|
||||
touchInfo.SetPreventDefault(true);
|
||||
touchInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
touchInfo.AddTouchLocationInfo(std::move(touchDownInfo));
|
||||
switchPattern->touchListener_->callback_(touchInfo);
|
||||
EXPECT_TRUE(switchPattern->isTouchPreventDefault_);
|
||||
EXPECT_EQ(switchPattern->touchHoverType_, TouchHoverAnimationType::PRESS);
|
||||
/**
|
||||
* @tc.steps: step3.Mock GestureEvent info and set preventDefault to true
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
switchPattern->InitClickEvent();
|
||||
GestureEvent clickInfo;
|
||||
clickInfo.SetPreventDefault(true);
|
||||
clickInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
switchPattern->clickListener_->operator()(clickInfo);
|
||||
EXPECT_FALSE(switchPattern->isTouchPreventDefault_);
|
||||
EXPECT_FALSE(switchPattern->isOn_);
|
||||
EXPECT_FALSE(switchPattern->isFocus_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PreventDefault002
|
||||
* @tc.desc: test InitTouchEvent and InitClickEvent
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ToggleSwitchTestNg, PreventDefault002, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Create toggleModelNG.
|
||||
*/
|
||||
ToggleModelNG toggleModelNG;
|
||||
toggleModelNG.Create(ToggleType::SWITCH, IS_ON);
|
||||
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
auto switchPattern = frameNode->GetPattern<SwitchPattern>();
|
||||
ASSERT_NE(switchPattern, nullptr);
|
||||
auto gestureHub = frameNode->GetOrCreateGestureEventHub();
|
||||
ASSERT_NE(gestureHub, nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Mock TouchEvent info and set preventDefault to false
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
switchPattern->InitTouchEvent();
|
||||
TouchEventInfo touchInfo("onTouch");
|
||||
TouchLocationInfo touchDownInfo(1);
|
||||
touchDownInfo.SetTouchType(TouchType::DOWN);
|
||||
touchInfo.SetPreventDefault(false);
|
||||
touchInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
touchInfo.AddTouchLocationInfo(std::move(touchDownInfo));
|
||||
switchPattern->touchListener_->callback_(touchInfo);
|
||||
EXPECT_EQ(touchInfo.IsPreventDefault(), switchPattern->isTouchPreventDefault_);
|
||||
EXPECT_EQ(switchPattern->touchHoverType_, TouchHoverAnimationType::PRESS);
|
||||
/**
|
||||
* @tc.steps: step3. Mock GestureEvent info and set preventDefault to false
|
||||
* @tc.expected: Check the param value
|
||||
*/
|
||||
switchPattern->InitClickEvent();
|
||||
GestureEvent clickInfo;
|
||||
clickInfo.SetPreventDefault(false);
|
||||
clickInfo.SetSourceDevice(SourceType::TOUCH);
|
||||
switchPattern->clickListener_->operator()(clickInfo);
|
||||
EXPECT_FALSE(switchPattern->isTouchPreventDefault_);
|
||||
EXPECT_TRUE(switchPattern->isOn_);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
Loading…
Reference in New Issue
Block a user