!1136 Add Tdd for interface called GetDragAction

Merge pull request !1136 from Science/shz
This commit is contained in:
openharmony_ci 2023-11-21 11:40:46 +00:00 committed by Gitee
commit f5bf5ab307
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 271 additions and 59 deletions

View File

@ -45,6 +45,7 @@ constexpr int32_t TIME_WAIT_FOR_OP_MS { 20 };
constexpr int32_t TIME_WAIT_FOR_INJECT_MS { 80 };
constexpr int32_t TIME_WAIT_FOR_TOUCH_DOWN_MS { 1000 };
constexpr int32_t PROMISE_WAIT_SPAN_MS { 2000 };
constexpr int32_t TIME_WAIT_FOR_NOTIFY_LINSTER { 100 };
constexpr int32_t TEST_PIXEL_MAP_WIDTH { 200 };
constexpr int32_t TEST_PIXEL_MAP_HEIGHT { 200 };
constexpr int32_t MAX_PIXEL_MAP_WIDTH { 600 };
@ -74,6 +75,7 @@ constexpr int32_t RADIUS_IN { 42 };
constexpr int32_t RADIUS_OUT { 42 };
constexpr int32_t ALPHA_IN { 51 };
constexpr int32_t ALPHA_OUT { 0 };
constexpr int64_t DOWN_TIME { 1 };
const std::string UD_KEY { "Unified data key" };
const std::string EXTRA_INFO { "{ \"drag_allow_distributed\" : false }" };
const std::string SYSTEM_CORE { "system_core" };
@ -85,6 +87,7 @@ int32_t g_screenHeight { 1280 };
uint64_t g_tokenID { 0 };
const char *g_cores[] = { "ohos.permission.INPUT_MONITORING" };
const char *g_basics[] = { "ohos.permission.COOPERATE_MANAGER" };
std::shared_ptr<MMI::KeyEvent> g_keyEvent = MMI::KeyEvent::Create();
} // namespace
class InteractionManagerTest : public testing::Test {
@ -102,15 +105,22 @@ public:
int32_t deviceId, const std::pair<int32_t, int32_t> &displayLocation, bool isPressed);
static std::shared_ptr<MMI::PointerEvent> SetupPointerEvent(const std::pair<int32_t, int32_t> &displayLocation,
int32_t action, int32_t sourceType, int32_t pointerId, bool isPressed);
static void SimulateDownEvent(const std::pair<int32_t, int32_t> &location, int32_t sourceType, int32_t pointerId);
static void SimulateUpEvent(const std::pair<int32_t, int32_t> &location, int32_t sourceType, int32_t pointerId);
static void SimulateMoveEvent(const std::pair<int32_t, int32_t> &srcLocation, const std::pair<int32_t, int32_t>
&dstLocation, int32_t sourceType, int32_t pointerId, bool isPressed);
static void SimulateDownPointerEvent(
const std::pair<int32_t, int32_t> &location, int32_t sourceType, int32_t pointerId);
static void SimulateUpPointerEvent(
const std::pair<int32_t, int32_t> &location, int32_t sourceType, int32_t pointerId);
static void SimulateMovePointerEvent(const std::pair<int32_t, int32_t> &srcLocation,
const std::pair<int32_t, int32_t> &dstLocation, int32_t sourceType, int32_t pointerId, bool isPressed);
static int32_t TestAddMonitor(std::shared_ptr<MMI::IInputEventConsumer> consumer);
static void TestRemoveMonitor(int32_t monitorId);
static void PrintDragData(const DragData &dragData);
static void SetPermission(const std::string &level, const char** perms, size_t permAmount);
static void RemovePermission();
static void SetupKeyEvent(int32_t action, int32_t key, bool isPressed);
static void ClearUpKeyEvent();
static void SimulateDownKeyEvent(int32_t key);
static void SimulateUpKeyEvent(int32_t key);
static void PrintDragAction(DragAction dragAction);
};
void InteractionManagerTest::SetPermission(const std::string &level, const char** perms, size_t permAmount)
@ -149,7 +159,7 @@ void InteractionManagerTest::RemovePermission()
class DragListenerTest : public IDragListener {
public:
DragListenerTest() {}
explicit DragListenerTest(std::string name) : moduleName_(name) {}
explicit DragListenerTest(const std::string& name) : moduleName_(name) {}
void OnDragMessage(DragState state) override
{
if (moduleName_.empty()) {
@ -180,9 +190,15 @@ private:
class SubscriptListenerTest : public ISubscriptListener {
public:
SubscriptListenerTest() {}
explicit SubscriptListenerTest(std::string name) : moduleName_(name) {}
explicit SubscriptListenerTest(const std::string& name) : moduleName_(name)
{
futureFlag_ = promiseFlag_.get_future();
}
void OnMessage(DragCursorStyle style) override
{
if (style != dragStyle_) {
promiseFlag_.set_value(true);
}
SetDragSyle(style);
if (moduleName_.empty()) {
moduleName_ = std::string("SubscriptListenerTest");
@ -218,6 +234,10 @@ private:
return type;
}
public:
std::promise<bool> promiseFlag_;
std::future<bool> futureFlag_;
private:
DragCursorStyle dragStyle_ { DragCursorStyle::DEFAULT };
std::string moduleName_;
@ -370,7 +390,7 @@ std::shared_ptr<MMI::PointerEvent> InteractionManagerTest::SetupPointerEvent(con
return pointerEvent;
}
void InteractionManagerTest::SimulateDownEvent(const std::pair<int32_t, int32_t> &location, int32_t sourceType,
void InteractionManagerTest::SimulateDownPointerEvent(const std::pair<int32_t, int32_t> &location, int32_t sourceType,
int32_t pointerId)
{
CALL_DEBUG_ENTER;
@ -382,7 +402,7 @@ void InteractionManagerTest::SimulateDownEvent(const std::pair<int32_t, int32_t>
MMI::InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
}
void InteractionManagerTest::SimulateUpEvent(const std::pair<int32_t, int32_t> &location, int32_t sourceType,
void InteractionManagerTest::SimulateUpPointerEvent(const std::pair<int32_t, int32_t> &location, int32_t sourceType,
int32_t pointerId)
{
CALL_DEBUG_ENTER;
@ -394,7 +414,7 @@ void InteractionManagerTest::SimulateUpEvent(const std::pair<int32_t, int32_t> &
MMI::InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
}
void InteractionManagerTest::SimulateMoveEvent(const std::pair<int32_t, int32_t> &srcLocation,
void InteractionManagerTest::SimulateMovePointerEvent(const std::pair<int32_t, int32_t> &srcLocation,
const std::pair<int32_t, int32_t> &dstLocation, int32_t sourceType, int32_t pointerId, bool isPressed)
{
CALL_DEBUG_ENTER;
@ -458,6 +478,69 @@ void InteractionManagerTest::PrintDragData(const DragData &dragData)
dragData.udKey.substr(0, SUBSTR_UDKEY_LEN).c_str());
}
void InteractionManagerTest::SetupKeyEvent(
int32_t action, int32_t key, bool isPressed)
{
CALL_DEBUG_ENTER;
CHKPV(g_keyEvent);
MMI::KeyEvent::KeyItem keyItem;
keyItem.SetKeyCode(key);
keyItem.SetDeviceId(1);
keyItem.SetDownTime(DOWN_TIME);
g_keyEvent->SetKeyAction(action);
g_keyEvent->SetKeyCode(key);
if (action == MMI::KeyEvent::KEY_ACTION_DOWN) {
keyItem.SetPressed(isPressed);
} else if (action == MMI::KeyEvent::KEY_ACTION_UP) {
g_keyEvent->RemoveReleasedKeyItems(keyItem);
}
g_keyEvent->AddPressedKeyItems(keyItem);
}
void InteractionManagerTest::ClearUpKeyEvent()
{
CALL_DEBUG_ENTER;
CHKPV(g_keyEvent);
for (const auto& iter : g_keyEvent->GetKeyItems()) {
if (!iter.IsPressed()) {
FI_HILOGD("TEST:Clean keyItem, keyCode:%{public}d", iter.GetKeyCode());
g_keyEvent->RemoveReleasedKeyItems(iter);
return;
}
}
}
void InteractionManagerTest::SimulateDownKeyEvent(int32_t key)
{
CALL_DEBUG_ENTER;
SetupKeyEvent(MMI::KeyEvent::KEY_ACTION_DOWN, key, true);
FI_HILOGD("TEST:keyCode:%{public}d, keyAction: KEY_ACTION_DOWN", key);
MMI::InputManager::GetInstance()->SimulateInputEvent(g_keyEvent);
}
void InteractionManagerTest::SimulateUpKeyEvent(int32_t key)
{
CALL_DEBUG_ENTER;
SetupKeyEvent(MMI::KeyEvent::KEY_ACTION_UP, key, false);
FI_HILOGD("TEST:keyCode:%{public}d, keyAction: KEY_ACTION_UP", key);
MMI::InputManager::GetInstance()->SimulateInputEvent(g_keyEvent);
}
void InteractionManagerTest::PrintDragAction(DragAction dragAction)
{
switch (dragAction) {
case DragAction::MOVE:
FI_HILOGD("drag action: MOVE");
break;
case DragAction::COPY:
FI_HILOGD("drag action: COPY");
break;
default:
FI_HILOGD("drag action: UNKNOWN");
break;
}
}
class InputEventCallbackTest : public MMI::IInputEventConsumer {
public:
InputEventCallbackTest() {}
@ -744,7 +827,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_Draglistener_Mouse, Test
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
@ -752,7 +836,7 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_Draglistener_Mouse, Test
ASSERT_EQ(ret, RET_OK);
ret = InteractionManager::GetInstance()->SetDragWindowVisible(true);
EXPECT_EQ(ret, RET_OK);
SimulateMoveEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, true);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
InteractionManager::GetInstance()->StopDrag(dropResult);
@ -785,13 +869,14 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_Draglistener_Touch, Test
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.targetPid, notifyMessage.result);
promiseFlag.set_value(true);
};
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ MAX_PIXEL_MAP_WIDTH, MAX_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback);
ASSERT_EQ(ret, RET_OK);
SimulateMoveEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
InteractionManager::GetInstance()->StopDrag(dropResult);
@ -825,7 +910,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_Draglistener, TestSize.L
dragListeners.push_back(listener);
}
}
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ MAX_PIXEL_MAP_WIDTH, MAX_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
@ -838,7 +924,7 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_Draglistener, TestSize.L
};
ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback);
ASSERT_EQ(ret, RET_OK);
SimulateMoveEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
InteractionManager::GetInstance()->StopDrag(dropResult);
@ -879,16 +965,18 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_SubscriptListener_001, T
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ MAX_PIXEL_MAP_WIDTH, MAX_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback);
ASSERT_EQ(ret, RET_OK);
SimulateMoveEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
SimulateUpEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
SimulateUpPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
InteractionManager::GetInstance()->StopDrag(dropResult);
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
std::future_status::timeout);
@ -925,7 +1013,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_SubscriptListener_002, T
std::optional<DragData> dragData = CreateDragData({ MAX_PIXEL_MAP_WIDTH, MAX_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback);
ASSERT_EQ(ret, RET_OK);
ret = InteractionManager::GetInstance()->SetDragWindowVisible(true);
@ -933,18 +1022,19 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_SubscriptListener_002, T
DragCursorStyle style = DragCursorStyle::DEFAULT;
ret = InteractionManager::GetInstance()->UpdateDragStyle(style);
ASSERT_EQ(ret, RET_OK);
SimulateMoveEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
SimulateUpEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
InteractionManager::GetInstance()->StopDrag(dropResult);
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
EXPECT_TRUE(listener->futureFlag_.wait_for(std::chrono::milliseconds(TIME_WAIT_FOR_NOTIFY_LINSTER)) !=
std::future_status::timeout);
DragCursorStyle recvStyle = listener->GetDragStyle();
FI_HILOGD("Recived style:%{public}d, expected style:%{public}d", static_cast<int32_t>(recvStyle),
static_cast<int32_t>(style));
ASSERT_EQ(recvStyle, style);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
SimulateUpPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
InteractionManager::GetInstance()->StopDrag(dropResult);
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
std::future_status::timeout);
ret = InteractionManager::GetInstance()->RemoveSubscriptListener(listener);
ASSERT_EQ(ret, RET_OK);
}
@ -969,7 +1059,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_Mouse, TestSiz
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
@ -977,7 +1068,7 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_Mouse, TestSiz
ASSERT_EQ(ret, RET_OK);
ret = InteractionManager::GetInstance()->SetDragWindowVisible(true);
EXPECT_EQ(ret, RET_OK);
SimulateMoveEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, true);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
InteractionManager::GetInstance()->StopDrag(dropResult);
@ -1000,7 +1091,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_Failed_Mouse,
} else {
std::promise<bool> promiseFlag;
std::future<bool> futureFlag = promiseFlag.get_future();
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
@ -1038,7 +1130,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_StopDrag_Mouse, TestSize
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.targetPid, notifyMessage.result);
promiseFlag.set_value(true);
};
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
@ -1063,7 +1156,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_StopDrag_Failed_Mouse, T
if (g_deviceMouseId < 0) {
ASSERT_TRUE(g_deviceMouseId < 0);
} else {
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
@ -1087,7 +1181,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_Touch, TestSiz
if (g_deviceTouchId < 0) {
ASSERT_TRUE(g_deviceTouchId < 0);
} else {
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_TOUCH_DOWN_MS));
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
@ -1103,7 +1198,7 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_Touch, TestSiz
ASSERT_EQ(ret, RET_OK);
ret = InteractionManager::GetInstance()->SetDragWindowVisible(true);
EXPECT_EQ(ret, RET_OK);
SimulateMoveEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
InteractionManager::GetInstance()->StopDrag(dropResult);
@ -1131,7 +1226,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_StopDrag_Touch, TestSize
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_TOUCH_DOWN_MS));
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
@ -1164,7 +1260,8 @@ HWTEST_F(InteractionManagerTest, GetDragTargetPid_Mouse, TestSize.Level1)
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseStopFlag.set_value(true);
};
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
@ -1203,7 +1300,8 @@ HWTEST_F(InteractionManagerTest, GetDragTargetPid_Touch, TestSize.Level1)
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseStopFlag.set_value(true);
};
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_TOUCH_DOWN_MS));
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
@ -1241,7 +1339,8 @@ HWTEST_F(InteractionManagerTest, TouchEventDispatch, TestSize.Level1)
FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
};
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_TOUCH_DOWN_MS));
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
@ -1253,7 +1352,7 @@ HWTEST_F(InteractionManagerTest, TouchEventDispatch, TestSize.Level1)
auto callbackPtr = std::make_shared<InputEventCallbackTest>(
[&promiseEventFlag]{promiseEventFlag.set_value(true);});
int32_t monitorId = TestAddMonitor(callbackPtr);
SimulateMoveEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
ASSERT_TRUE(futureEventFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
std::future_status::timeout);
@ -1282,7 +1381,8 @@ HWTEST_F(InteractionManagerTest, MouseEventDispatch, TestSize.Level1)
FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
};
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, 0);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, 0);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, 0, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
@ -1293,7 +1393,7 @@ HWTEST_F(InteractionManagerTest, MouseEventDispatch, TestSize.Level1)
auto callbackPtr = std::make_shared<InputEventCallbackTest>(
[&promiseEventFlag]{promiseEventFlag.set_value(true);});
int32_t monitorId = TestAddMonitor(callbackPtr);
SimulateMoveEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, TOUCH_POINTER_ID, true);
ASSERT_TRUE(futureEventFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
std::future_status::timeout);
@ -1342,7 +1442,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_GetShadowOffset, TestSiz
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_TOUCH_DOWN_MS));
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
@ -1371,7 +1472,8 @@ HWTEST_F(InteractionManagerTest, GetUdKey_Mouse, TestSize.Level1)
if (g_deviceMouseId < 0) {
ASSERT_TRUE(g_deviceMouseId < 0);
} else {
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
@ -1415,7 +1517,8 @@ HWTEST_F(InteractionManagerTest, GetUdKey_Touch, TestSize.Level1)
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.targetPid, notifyMessage.result);
promiseFlag.set_value(true);
};
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_TOUCH_DOWN_MS));
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
@ -1453,7 +1556,8 @@ HWTEST_F(InteractionManagerTest, GetDragData_Success, TestSize.Level1)
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
@ -1477,7 +1581,8 @@ HWTEST_F(InteractionManagerTest, GetDragData_Success, TestSize.Level1)
ASSERT_EQ(dragData->displayId, replyDragData.displayId);
ASSERT_EQ(dragData->hasCanceledAnimation, replyDragData.hasCanceledAnimation);
PrintDragData(replyDragData);
SimulateUpEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
SimulateUpPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
InteractionManager::GetInstance()->StopDrag(dropResult);
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
@ -1497,11 +1602,13 @@ HWTEST_F(InteractionManagerTest, GetDragData_Failed, TestSize.Level1)
if (g_deviceTouchId < 0) {
ASSERT_TRUE(g_deviceTouchId < 0);
} else {
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_TOUCH_DOWN_MS));
DragData dragData;
int32_t ret = InteractionManager::GetInstance()->GetDragData(dragData);
SimulateUpEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
SimulateUpPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
ASSERT_EQ(ret, RET_ERR);
}
}
@ -1522,7 +1629,8 @@ HWTEST_F(InteractionManagerTest, GetDragState, TestSize.Level1)
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
@ -1535,7 +1643,8 @@ HWTEST_F(InteractionManagerTest, GetDragState, TestSize.Level1)
EXPECT_EQ(ret, RET_OK);
EXPECT_EQ(dragState, DragState::START);
SimulateUpEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
SimulateUpPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
ret = InteractionManager::GetInstance()->StopDrag(dropResult);
ASSERT_EQ(ret, RET_OK);
@ -1628,14 +1737,14 @@ HWTEST_F(InteractionManagerTest, AddHotAreaListener_002, TestSize.Level1)
#else
ASSERT_EQ(ret, ERROR_UNSUPPORT);
#endif // OHOS_BUILD_ENABLE_COORDINATION
SimulateMoveEvent({ HOT_AREA_STEP, HOT_AREA_COOR }, { HOT_AREA_STEP - HOT_AREA_SPAN, HOT_AREA_COOR },
SimulateMovePointerEvent({ HOT_AREA_STEP, HOT_AREA_COOR }, { HOT_AREA_STEP - HOT_AREA_SPAN, HOT_AREA_COOR },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, true);
SimulateMoveEvent({ HOT_AREA_COOR, HOT_AREA_STEP }, { HOT_AREA_COOR, HOT_AREA_STEP - HOT_AREA_SPAN },
SimulateMovePointerEvent({ HOT_AREA_COOR, HOT_AREA_STEP }, { HOT_AREA_COOR, HOT_AREA_STEP - HOT_AREA_SPAN },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, true);
SimulateMoveEvent({ g_screenWidth - HOT_AREA_STEP, HOT_AREA_COOR },
SimulateMovePointerEvent({ g_screenWidth - HOT_AREA_STEP, HOT_AREA_COOR },
{ g_screenWidth - HOT_AREA_SPAN, HOT_AREA_COOR },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, true);
SimulateMoveEvent({ HOT_AREA_COOR, g_screenHeight - HOT_AREA_STEP },
SimulateMovePointerEvent({ HOT_AREA_COOR, g_screenHeight - HOT_AREA_STEP },
{ HOT_AREA_COOR, g_screenHeight - HOT_AREA_SPAN },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, true);
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_TOUCH_DOWN_MS));
@ -1699,7 +1808,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_UpdateDragItemStyle, Tes
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
@ -1709,15 +1819,15 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_UpdateDragItemStyle, Tes
EXPECT_EQ(ret, RET_OK);
std::pair<int32_t, int32_t> enterPos { 500, 50 };
std::pair<int32_t, int32_t> leavePos { 500, 200 };
SimulateMoveEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { enterPos.first, enterPos.second },
SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { enterPos.first, enterPos.second },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
ret = InteractionManager::GetInstance()->UpdateDragItemStyle({ FOREGROUND_COLOR_IN, RADIUS_IN, ALPHA_IN });
EXPECT_EQ(ret, RET_OK);
SimulateMoveEvent({ enterPos.first, enterPos.second }, { leavePos.first, leavePos.second },
SimulateMovePointerEvent({ enterPos.first, enterPos.second }, { leavePos.first, leavePos.second },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
ret = InteractionManager::GetInstance()->UpdateDragItemStyle({ FOREGROUND_COLOR_OUT, RADIUS_OUT, ALPHA_OUT });
EXPECT_EQ(ret, RET_OK);
SimulateMoveEvent({ leavePos.first, leavePos.second }, { DRAG_DST_X, DRAG_DST_Y },
SimulateMovePointerEvent({ leavePos.first, leavePos.second }, { DRAG_DST_X, DRAG_DST_Y },
MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
InteractionManager::GetInstance()->StopDrag(dropResult);
@ -1752,7 +1862,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_GetExtraInfo, TestSize.L
{
CALL_TEST_DEBUG;
if (g_deviceMouseId >= 0) {
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
@ -1777,6 +1888,100 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_GetExtraInfo, TestSize.L
std::future_status::timeout);
}
}
/**
* @tc.name: InteractionManagerTest_GetDragAction_001
* @tc.desc: Get drag action with no keyboard events of keys in dragging
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InteractionManagerTest, GetDragAction_001, TestSize.Level1)
{
CALL_TEST_DEBUG;
std::promise<bool> promiseFlag;
std::future<bool> futureFlag = promiseFlag.get_future();
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback);
ASSERT_EQ(ret, RET_OK);
DragAction dragAction { DragAction::INVALID };
ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
EXPECT_EQ(ret, RET_OK);
EXPECT_EQ(dragAction, DragAction::MOVE);
PrintDragAction(dragAction);
SimulateUpPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
InteractionManager::GetInstance()->StopDrag(dropResult);
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
std::future_status::timeout);
ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
EXPECT_EQ(ret, RET_ERR);
}
/**
* @tc.name: InteractionManagerTest_GetDragAction_002
* @tc.desc: Get drag action with simple press and release keyboard events of keys in dragging
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InteractionManagerTest, GetDragAction_002, TestSize.Level1)
{
CALL_TEST_DEBUG;
std::promise<bool> promiseFlag;
std::future<bool> futureFlag = promiseFlag.get_future();
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback);
ASSERT_EQ(ret, RET_OK);
SimulateDownKeyEvent(MMI::KeyEvent::KEYCODE_CTRL_LEFT);
DragAction dragAction { DragAction::INVALID };
ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
EXPECT_EQ(ret, RET_OK);
EXPECT_EQ(dragAction, DragAction::COPY);
PrintDragAction(dragAction);
SimulateUpKeyEvent(MMI::KeyEvent::KEYCODE_CTRL_LEFT);
ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
EXPECT_EQ(ret, RET_OK);
EXPECT_EQ(dragAction, DragAction::MOVE);
PrintDragAction(dragAction);
ClearUpKeyEvent();
SimulateDownKeyEvent(MMI::KeyEvent::KEYCODE_A);
ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
EXPECT_EQ(ret, RET_OK);
EXPECT_EQ(dragAction, DragAction::MOVE);
PrintDragAction(dragAction);
SimulateUpKeyEvent(MMI::KeyEvent::KEYCODE_A);
ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
EXPECT_EQ(ret, RET_OK);
EXPECT_EQ(dragAction, DragAction::MOVE);
PrintDragAction(dragAction);
ClearUpKeyEvent();
SimulateUpPointerEvent(
{ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
InteractionManager::GetInstance()->StopDrag(dropResult);
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
std::future_status::timeout);
ret = InteractionManager::GetInstance()->GetDragAction(dragAction);
EXPECT_EQ(ret, RET_ERR);
}
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS

View File

@ -109,8 +109,15 @@ int32_t DragDataManager::GetShadowOffset(int32_t& offsetX, int32_t& offsetY, int
void DragDataManager::ResetDragData()
{
CALL_DEBUG_ENTER;
dragData_ = { };
ShadowInfo shadowInfo;
std::vector<uint8_t> buffer;
dragData_ = { shadowInfo, buffer, "", "", "", -1, -1, -1, -1, -1, -1, false };
dragItemStyle_ = { };
dragStyle_ = DragCursorStyle::DEFAULT;
visible_ = false;
targetTid_ = -1;
targetPid_ = -1;
isMotionDrag_ = false;
}
void DragDataManager::SetMotionDrag(bool isMotionDrag)