From 0b23e56e9341275e1c8bc072afc31029a14613f4 Mon Sep 17 00:00:00 2001 From: qlxie Date: Mon, 30 Jun 2025 19:28:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E9=94=AE=E4=BA=8B=E4=BB=B6TDD?= =?UTF-8?q?=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qlxie Change-Id: Ic50b76a6f598f4d891cbbcaa7f60e1b54ca4037c --- .../unittest/core/base/short_cuts_test_ng.cpp | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/test/unittest/core/base/short_cuts_test_ng.cpp b/test/unittest/core/base/short_cuts_test_ng.cpp index faa9f5067ac..69077ed5656 100644 --- a/test/unittest/core/base/short_cuts_test_ng.cpp +++ b/test/unittest/core/base/short_cuts_test_ng.cpp @@ -42,6 +42,8 @@ const std::string VALUE_Z = "Z"; const std::string VALUE_Y = "Y"; const std::string VALUE_X = "X"; const std::string VALUE_TAB = "TAB"; +const std::string VALUE_F4 = "KEY_F4"; +const std::string VALUE_ESC = "ESCAPE"; const std::string VALUE_DPAD_UP = "DPAD_UP"; const std::string VALUE_DPAD_DOWN = "DPAD_DOWN"; const std::string VALUE_DPAD_LEFT = "DPAD_LEFT"; @@ -1420,4 +1422,105 @@ HWTEST_F(ShortCutsTestNg, ShortCutsTest040, TestSize.Level1) EXPECT_EQ(eventManager->keyboardShortcutNode_.size(), 1); keys.clear(); } + +/** + * @tc.name: ShortCutsTest041 + * @tc.desc: Test the prohibit the binding of system shortcuts. + * @tc.type: FUNC + */ +HWTEST_F(ShortCutsTestNg, ShortCutsTest041, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create a FrameNode and get eventManager. + */ + const RefPtr targetNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr(), true); + ViewStackProcessor::GetInstance()->Push(targetNode); + auto eventManager = PipelineContext::GetCurrentContext()->GetEventManager(); + eventManager->keyboardShortcutNode_.clear(); + /** + * @tc.steps: step2. Key combination ALT + F4. + * @tc.expected: The callback was not executed. + */ + std::vector keyone{ModifierKey::ALT}; + bool res = false; + auto callback = [&res](){res = true;}; + ViewAbstract::SetKeyboardShortcut(VALUE_F4, std::move(keyone), callback); + KeyEvent event; + event.code = KeyCode::KEY_F4; + event.action = KeyAction::DOWN; + event.pressedCodes = {KeyCode::KEY_ALT_LEFT}; + eventManager->DispatchKeyboardShortcut(event); + EXPECT_EQ(res, false); + eventManager->keyboardShortcutNode_.clear(); + + /** + * @tc.steps: step3. Key combination ALT + SHIFT + F4. + * @tc.expected: The callback was not executed. + */ + std::vector keytwo{ModifierKey::ALT, ModifierKey::SHIFT}; + ViewAbstract::SetKeyboardShortcut(VALUE_F4, std::move(keytwo), callback); + event.code = KeyCode::KEY_F4; + event.action = KeyAction::DOWN; + event.pressedCodes = {KeyCode::KEY_ALT_LEFT, KeyCode::KEY_SHIFT_LEFT}; + eventManager->DispatchKeyboardShortcut(event); + EXPECT_EQ(res, false); + eventManager->keyboardShortcutNode_.clear(); + + /** + * @tc.steps: step4. Key combination ALT + TAB. + * @tc.expected: The callback was not executed. + */ + std::vector keythree{ModifierKey::ALT}; + ViewAbstract::SetKeyboardShortcut(VALUE_TAB, std::move(keythree), callback); + event.code = KeyCode::KEY_TAB; + event.action = KeyAction::DOWN; + event.pressedCodes = {KeyCode::KEY_ALT_LEFT}; + eventManager->DispatchKeyboardShortcut(event); + EXPECT_EQ(res, false); +} + +/** + * @tc.name: ShortCutsTest042 + * @tc.desc: Test the prohibit the binding of system shortcuts. + * @tc.type: FUNC + */ +HWTEST_F(ShortCutsTestNg, ShortCutsTest042, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create a FrameNode and get eventManager. + */ + const RefPtr targetNode = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr(), true); + ViewStackProcessor::GetInstance()->Push(targetNode); + auto eventManager = PipelineContext::GetCurrentContext()->GetEventManager(); + eventManager->keyboardShortcutNode_.clear(); + + /** + * @tc.steps: step2. Key combination ALT + SHIFT + TAB. + * @tc.expected: The callback was not executed. + */ + bool res = false; + auto callback = [&res](){res = true;}; + std::vector keyfour{ModifierKey::ALT, ModifierKey::SHIFT}; + ViewAbstract::SetKeyboardShortcut(VALUE_TAB, std::move(keyfour), callback); + KeyEvent event; + event.code = KeyCode::KEY_TAB; + event.action = KeyAction::DOWN; + event.pressedCodes = {KeyCode::KEY_ALT_LEFT, KeyCode::KEY_SHIFT_LEFT}; + eventManager->DispatchKeyboardShortcut(event); + EXPECT_EQ(res, false); + eventManager->keyboardShortcutNode_.clear(); + + /** + * @tc.steps: step3. Key combination CTRL + SHIFT + ESC. + * @tc.expected: The callback was not executed. + */ + res = false; + std::vector keyfive{ModifierKey::CTRL, ModifierKey::SHIFT}; + ViewAbstract::SetKeyboardShortcut(VALUE_ESC, std::move(keyfive), callback); + event.code = KeyCode::KEY_ESCAPE; + event.action = KeyAction::DOWN; + event.pressedCodes = {KeyCode::KEY_CTRL_LEFT, KeyCode::KEY_SHIFT_LEFT}; + eventManager->DispatchKeyboardShortcut(event); + EXPECT_EQ(res, false); +} } // namespace OHOS::Ace::NG \ No newline at end of file -- Gitee