!1401 快捷键DT用例补齐

Merge pull request !1401 from 小发发/accessibility_240904
This commit is contained in:
openharmony_ci 2024-09-06 06:14:50 +00:00 committed by Gitee
commit a37c2c5d91
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 328 additions and 0 deletions

View File

@ -1421,6 +1421,86 @@ ohos_unittest("accessibility_short_key_test") {
]
}
################################################################################
ohos_unittest("accessibility_short_key_dialog_test") {
module_out_path = module_output_path
sources = [
"../../test/mock/mock_common_event_data.cpp",
"../../test/mock/mock_common_event_manager.cpp",
"../../test/mock/mock_common_event_subscribe_info.cpp",
"../../test/mock/mock_common_event_subscriber.cpp",
"../../test/mock/mock_matching_skill.cpp",
"../src/accessibility_account_data.cpp",
"../src/accessibility_datashare_helper.cpp",
"../src/accessibility_display_manager.cpp",
"../src/accessibility_dumper.cpp",
"../src/accessibility_power_manager.cpp",
"../src/accessibility_setting_observer.cpp",
"../src/accessibility_setting_provider.cpp",
"../src/accessibility_settings.cpp",
"../src/accessibility_settings_config.cpp",
"../src/accessibility_short_key.cpp",
"../src/accessibility_short_key_dialog.cpp",
"../src/accessibility_window_connection.cpp",
"../src/accessibility_window_manager.cpp",
"../src/accessible_ability_channel.cpp",
"../src/accessible_ability_connection.cpp",
"../src/accessible_ability_manager_service_event_handler.cpp",
"../src/utils.cpp",
"mock/src/mock_accessibility_common_event.cpp",
"mock/src/mock_accessibility_event_transmission.cpp",
"mock/src/mock_accessible_ability_client_stub_impl.cpp",
"mock/src/mock_accessible_ability_manager_service.cpp",
"mock/src/mock_system_ability.cpp",
"unittest/accessibility_short_key_dialog_test.cpp",
]
sources += aams_mock_distributeddatamgr_src
configs = [
":module_private_config",
"../../../resources/config/build:coverage_flags",
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"ability_runtime:abilitykit_native",
"ability_runtime:dataobs_manager",
"ability_runtime:extension_manager",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"data_share:datashare_consumer",
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbegetutil",
"input:libmmi-client",
"ipc:ipc_single",
"os_account:os_account_innerkits",
"power_manager:powermgr_client",
"preferences:native_preferences",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
"window_manager:libdm",
"window_manager:libwm",
]
}
################################################################################
ohos_unittest("accessibility_settings_config_test") {
module_out_path = module_output_path

View File

@ -0,0 +1,93 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <map>
#include <memory>
#include "accessibility_short_key_dialog.h"
#include "accessibility_ut_helper.h"
#include "accessible_ability_manager_service.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Accessibility {
class AccessibilityShortKeyDialogUnitTest : public ::testing::Test {
public:
AccessibilityShortKeyDialogUnitTest()
{}
~AccessibilityShortKeyDialogUnitTest()
{}
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
std::shared_ptr<AccessibilityShortKeyDialog> shortKeyDialog_ = nullptr;
};
void AccessibilityShortKeyDialogUnitTest::SetUpTestCase()
{
GTEST_LOG_(INFO) << "###################### AccessibilityShortKeyDialogUnitTest Start ######################";
Singleton<AccessibleAbilityManagerService>::GetInstance().OnStart();
}
void AccessibilityShortKeyDialogUnitTest::TearDownTestCase()
{
GTEST_LOG_(INFO) << "###################### AccessibilityShortKeyDialogUnitTest End ######################";
Singleton<AccessibleAbilityManagerService>::GetInstance().OnStop();
}
void AccessibilityShortKeyDialogUnitTest::SetUp()
{
GTEST_LOG_(INFO) << "SetUp";
shortKeyDialog_ = std::make_shared<AccessibilityShortKeyDialog>();
}
void AccessibilityShortKeyDialogUnitTest::TearDown()
{
GTEST_LOG_(INFO) << "TearDown";
shortKeyDialog_ = nullptr;
}
/**
* @tc.number: AccessibilityshortKeyDialog_Unittest_ConnectDialog_001
* @tc.name: ConnectDialog
* @tc.desc: Test function ConnectDialog
* @tc.require: issueI5NTXH
*/
HWTEST_F(AccessibilityShortKeyDialogUnitTest, AccessibilityshortKeyDialog_Unittest_ConnectDialog_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibilityshortKeyDialog_Unittest_ConnectDialog_001 start";
EXPECT_TRUE(shortKeyDialog_->ConnectDialog(ShortKeyDialogType::FUNCTION_SELECT));
GTEST_LOG_(INFO) << "AccessibilityshortKeyDialog_Unittest_ConnectDialog_001 end";
}
/**
* @tc.number: AccessibilityshortKeyDialog_Unittest_ConnectDialog_002
* @tc.name: ConnectDialog
* @tc.desc: Test function ConnectDialog
* @tc.require: issueI5NTXH
*/
HWTEST_F(AccessibilityShortKeyDialogUnitTest, AccessibilityshortKeyDialog_Unittest_ConnectDialog_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibilityshortKeyDialog_Unittest_ConnectDialog_002 start";
EXPECT_TRUE(shortKeyDialog_->ConnectDialog(ShortKeyDialogType::RECONFIRM));
GTEST_LOG_(INFO) << "AccessibilityshortKeyDialog_Unittest_ConnectDialog_002 end";
}
} // namespace Accessibility
} // namespace OHOS

View File

@ -43,6 +43,8 @@ namespace {
constexpr float BRIGHTNESS_DISCOUNT_VALUE = 0.1f;
constexpr float AUDIO_BALANCE_VALUE = 0.1f;
constexpr int32_t ACTIVE_WINDOW_VALUE = 2;
constexpr int32_t SHORT_KEY_TIMEOUT_BEFORE_USE = 3000; // ms
const std::string DEVICE_PROVISIONED = "device_provisioned";
} // namespace
class AccessibleAbilityManagerServiceUnitTest : public ::testing::Test {
@ -1473,10 +1475,163 @@ HWTEST_F(AccessibleAbilityManagerServiceUnitTest, GetShortkeyMultiTarget_001, Te
HWTEST_F(AccessibleAbilityManagerServiceUnitTest, OnShortKeyProcess_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_001 start";
Singleton<AccessibleAbilityManagerService>::GetInstance().SwitchedUser(-1);
sleep(SLEEP_TIME_1);
Singleton<AccessibleAbilityManagerService>::GetInstance().OnShortKeyProcess();
EXPECT_TRUE(Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData() == nullptr);
GTEST_LOG_(INFO) << "AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_001 end";
}
/**OnShortKeyProcess
* @tc.number: AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_002
* @tc.name: OnShortKeyProcess
* @tc.desc: Test function OnShortKeyProcess
*/
HWTEST_F(AccessibleAbilityManagerServiceUnitTest, OnShortKeyProcess_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_001 start";
std::shared_ptr<AccessibilitySettingProvider> service =
AccessibilitySettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID);
if (service == nullptr) {
GTEST_LOG_(INFO) << "service is nullptr";
return;
}
service->PutBoolValue(DEVICE_PROVISIONED, false, true);
auto accountData = Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
if (accountData == nullptr) {
GTEST_LOG_(INFO) << "accountData is nullptr";
return;
}
Singleton<AccessibleAbilityManagerService>::GetInstance().OnShortKeyProcess();
EXPECT_EQ(accountData->GetConfig()->GetShortKeyTimeout(), SHORT_KEY_TIMEOUT_BEFORE_USE);
GTEST_LOG_(INFO) << "AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_002 end";
}
/**OnShortKeyProcess
* @tc.number: AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_003
* @tc.name: OnShortKeyProcess
* @tc.desc: Test function OnShortKeyProcess
*/
HWTEST_F(AccessibleAbilityManagerServiceUnitTest, OnShortKeyProcess_003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_003 start";
std::shared_ptr<AccessibilitySettingProvider> service =
AccessibilitySettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID);
if (service == nullptr) {
GTEST_LOG_(INFO) << "service is nullptr";
return;
}
service->PutBoolValue(DEVICE_PROVISIONED, true, true);
auto accountData = Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
if (accountData == nullptr) {
GTEST_LOG_(INFO) << "accountData is nullptr";
return;
}
Singleton<AccessibleAbilityManagerService>::GetInstance().OnShortKeyProcess();
EXPECT_EQ(accountData->GetConfig()->GetShortKeyTimeout(), SHORT_KEY_TIMEOUT_BEFORE_USE);
GTEST_LOG_(INFO) << "AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_003 end";
}
/**OnShortKeyProcess
* @tc.number: AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_004
* @tc.name: OnShortKeyProcess
* @tc.desc: Test function OnShortKeyProcess
*/
HWTEST_F(AccessibleAbilityManagerServiceUnitTest, OnShortKeyProcess_004, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_004 start";
std::shared_ptr<AccessibilitySettingProvider> service =
AccessibilitySettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID);
if (service == nullptr) {
GTEST_LOG_(INFO) << "service is nullptr";
return;
}
service->PutBoolValue(DEVICE_PROVISIONED, true, true);
auto accountData = Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
if (accountData == nullptr) {
GTEST_LOG_(INFO) << "accountData is nullptr";
return;
}
std::vector<std::string> name;
Singleton<AccessibleAbilityManagerService>::GetInstance().SetShortkeyMultiTarget(name);
EXPECT_EQ(accountData->GetConfig()->GetShortkeyMultiTarget().size(), 0);
Singleton<AccessibleAbilityManagerService>::GetInstance().OnShortKeyProcess();
EXPECT_EQ(accountData->GetConfig()->GetEnabledAccessibilityServices().size(), 0);
GTEST_LOG_(INFO) << "AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_004 end";
}
/**OnShortKeyProcess
* @tc.number: AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_005
* @tc.name: OnShortKeyProcess
* @tc.desc: Test function OnShortKeyProcess
*/
HWTEST_F(AccessibleAbilityManagerServiceUnitTest, OnShortKeyProcess_005, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_005 start";
std::shared_ptr<AccessibilitySettingProvider> service =
AccessibilitySettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID);
if (service == nullptr) {
GTEST_LOG_(INFO) << "service is nullptr";
return;
}
service->PutBoolValue(DEVICE_PROVISIONED, true, true);
auto accountData = Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
if (accountData == nullptr) {
GTEST_LOG_(INFO) << "accountData is nullptr";
return;
}
std::vector<std::string> name;
name.push_back("test1");
Singleton<AccessibleAbilityManagerService>::GetInstance().SetShortkeyMultiTarget(name);
EXPECT_EQ(accountData->GetConfig()->GetShortkeyMultiTarget().size(), 1);
Singleton<AccessibleAbilityManagerService>::GetInstance().OnShortKeyProcess();
EXPECT_EQ(accountData->GetConfig()->GetEnabledAccessibilityServices().size(), 0);
GTEST_LOG_(INFO) << "AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_005 end";
}
/**OnShortKeyProcess
* @tc.number: AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_006
* @tc.name: OnShortKeyProcess
* @tc.desc: Test function OnShortKeyProcess
*/
HWTEST_F(AccessibleAbilityManagerServiceUnitTest, OnShortKeyProcess_006, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_006 start";
std::shared_ptr<AccessibilitySettingProvider> service =
AccessibilitySettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID);
if (service == nullptr) {
GTEST_LOG_(INFO) << "service is nullptr";
return;
}
service->PutBoolValue(DEVICE_PROVISIONED, true, true);
auto accountData = Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
if (accountData == nullptr) {
GTEST_LOG_(INFO) << "accountData is nullptr";
return;
}
std::vector<std::string> name;
name.push_back("test1");
name.push_back("test2");
Singleton<AccessibleAbilityManagerService>::GetInstance().SetShortkeyMultiTarget(name);
EXPECT_EQ(accountData->GetConfig()->GetShortkeyMultiTarget().size(), 1);
Singleton<AccessibleAbilityManagerService>::GetInstance().OnShortKeyProcess();
EXPECT_EQ(accountData->GetConfig()->GetEnabledAccessibilityServices().size(), 0);
GTEST_LOG_(INFO) << "AccessibleAbility_ManagerService_UnitTest_OnShortKeyProcess_006 end";
}
/**
* @tc.number: AccessibleAbilityManagerServiceUnitTest_SetMouseAutoClick_002
* @tc.name: SetMouseAutoClick