无障碍新增DT用例

Signed-off-by: qianchuang <qianchuang1@huawei.com>
This commit is contained in:
qianchuang 2024-09-27 15:07:02 +08:00
parent d7e326b1db
commit eb697e386b
4 changed files with 1392 additions and 0 deletions

View File

@ -0,0 +1,249 @@
/*
* Copyright (C) 2022 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 <unistd.h>
#include "accessibility_account_data.h"
#include "accessibility_common_helper.h"
#include "accessibility_input_interceptor.h"
#include "accessibility_mt_helper.h"
#include "accessible_ability_channel.h"
#include "accessible_ability_connection.h"
#include "accessible_ability_manager_service.h"
#include "iservice_registry.h"
#include "mock_input_manager.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Accessibility {
namespace {
constexpr uint8_t TEST_NUM_2 = 2;
constexpr uint8_t TEST_NUM_3 = 3;
constexpr uint16_t TEST_NUM_THOUSAND = 1000;
} // namespace
static void WaitUntilTaskFinished()
{
const uint32_t maxRetryNum = TEST_NUM_THOUSAND;
const uint32_t sleepTime = TEST_NUM_THOUSAND;
uint32_t count = 0;
auto handler = Singleton<AccessibleAbilityManagerService>::GetInstance().GetMainHandler();
std::atomic<bool> taskCalled(false);
auto func = [&taskCalled]() { taskCalled.store(true); };
if (handler->PostTask(func)) {
while (!taskCalled.load()) {
count++;
if (count >= maxRetryNum) {
break;
}
usleep(sleepTime);
}
}
}
class MockAamsKeyEventFilterTest : public testing::Test {
public:
MockAamsKeyEventFilterTest()
{}
~MockAamsKeyEventFilterTest()
{}
std::shared_ptr<MMI::IInputEventConsumer> interceptorId_ = nullptr;
sptr<AccessibleAbilityChannel> aastub_ = nullptr;
sptr<AccessibleAbilityChannel> aacs_ = nullptr;
int32_t tempData_ = 0;
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void AddConnection();
void TearDown();
void WritefileAll(const char* fname, const char* data) const;
std::shared_ptr<MMI::KeyEvent> CreateOnKeyEvent(int32_t keycode) const;
};
void MockAamsKeyEventFilterTest::SetUpTestCase(void)
{
Singleton<AccessibleAbilityManagerService>::GetInstance().OnStart();
AccessibilityCommonHelper::GetInstance().WaitForServicePublish();
Singleton<AccessibleAbilityManagerService>::GetInstance().SwitchedUser(AccessibilityHelper::accountId_);
GTEST_LOG_(INFO) << "AccessibleAbilityManagerService is published";
}
void MockAamsKeyEventFilterTest::TearDownTestCase(void)
{
Singleton<AccessibleAbilityManagerService>::GetInstance().OnStop();
}
void MockAamsKeyEventFilterTest::SetUp()
{
GTEST_LOG_(INFO) << "MockAamsKeyEventFilterTest ModuleTest SetUp";
// Add an ability connection client
AccessibilityAbilityInitParams initParams;
std::shared_ptr<AccessibilityAbilityInfo> abilityInfo = std::make_shared<AccessibilityAbilityInfo>(initParams);
abilityInfo->SetCapabilityValues(CAPABILITY_KEY_EVENT_OBSERVER);
AppExecFwk::ElementName elementName("deviceId", "bundleName", "name");
auto accountData = Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
accountData->AddInstalledAbility(*abilityInfo);
sleep(TEST_NUM_2);
sptr<AccessibleAbilityConnection> connection =
new AccessibleAbilityConnection(accountData->GetAccountId(), 0, *abilityInfo);
aastub_ = new AccessibleAbilityChannel(accountData->GetAccountId(), abilityInfo->GetId());
connection->OnAbilityConnectDoneSync(elementName, aastub_);
interceptorId_ = std::make_shared<AccessibilityInputEventConsumer>();
MMI::InputManager::GetInstance()->AddInterceptor(interceptorId_);
}
void MockAamsKeyEventFilterTest::TearDown()
{
GTEST_LOG_(INFO) << "MockAamsKeyEventFilterTest ModuleTest TearDown";
interceptorId_ = nullptr;
aastub_ = nullptr;
}
void MockAamsKeyEventFilterTest::WritefileAll(const char* fname, const char* data) const
{
FILE* fp = nullptr;
if (!(fp = fopen(fname, "w"))) {
printf("open file %s fail \n", fname);
return;
}
(void)fprintf(fp, "%s", data);
(void)fclose(fp);
}
std::shared_ptr<MMI::KeyEvent> MockAamsKeyEventFilterTest::CreateOnKeyEvent(int32_t keycode) const
{
std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
MMI::KeyEvent::KeyItem item = {};
item.SetPressed(true);
keyEvent->AddKeyItem(item);
keyEvent->SetKeyCode(keycode);
return keyEvent;
}
/**
* @tc.number: OnKeyEvent001
* @tc.name: OnKeyEvent
* @tc.desc: AccessibleAbility responds the keyevent within 500 ms.(handled is true)
*/
HWTEST_F(MockAamsKeyEventFilterTest, MockAamsKeyEventFilterTest_Moduletest_OnKeyEvent001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "MockAamsKeyEventFilterTest_Moduletest_OnKeyEvent001 start";
std::shared_ptr<MMI::KeyEvent> keyEvent = CreateOnKeyEvent(MMI::KeyEvent::KEYCODE_VOLUME_UP);
sleep(TEST_NUM_3 + TEST_NUM_2);
auto accountData = Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
std::map<std::string, sptr<AccessibleAbilityConnection>> connectionMaps = accountData->GetConnectedA11yAbilities();
EXPECT_EQ(connectionMaps.size(), 1);
auto inputEventConsumer = MMI::MockInputManager::GetInputEventConsumer();
if (inputEventConsumer != nullptr) {
inputEventConsumer->OnInputEvent(keyEvent);
}
bool handled = true;
int32_t sequence = 1;
auto iter = connectionMaps.begin();
sptr<AccessibleAbilityConnection> ptr_connect = iter->second;
ASSERT_TRUE(ptr_connect);
aacs_ = new AccessibleAbilityChannel(accountData->GetAccountId(),
ptr_connect->GetAbilityInfo().GetId());
aacs_->SetOnKeyPressEventResult(handled, sequence);
WaitUntilTaskFinished();
EXPECT_EQ(AccessibilityHelper::GetInstance().GetTestKeyPressEvent(), 1);
aacs_ = nullptr;
GTEST_LOG_(INFO) << "MockAamsKeyEventFilterTest_Moduletest_OnKeyEvent001 end";
}
/**
* @tc.number: OnKeyEvent002
* @tc.name: OnKeyEvent
* @tc.desc: AccessibleAbility responds the keyevent within 500 ms.(handled is false)
*/
HWTEST_F(MockAamsKeyEventFilterTest, MockAamsKeyEventFilterTest_Moduletest_OnKeyEvent002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "MockAamsKeyEventFilterTest_Moduletest_OnKeyEvent002 start";
std::shared_ptr<MMI::KeyEvent> keyEvent = CreateOnKeyEvent(MMI::KeyEvent::KEYCODE_VOLUME_UP);
sleep(TEST_NUM_3);
auto accountData = Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
std::map<std::string, sptr<AccessibleAbilityConnection>> connectionMaps = accountData->GetConnectedA11yAbilities();
EXPECT_EQ(connectionMaps.size(), 1);
auto inputEventConsumer = MMI::MockInputManager::GetInputEventConsumer();
if (inputEventConsumer != nullptr) {
inputEventConsumer->OnInputEvent(keyEvent);
}
bool handled = false;
int32_t sequence = TEST_NUM_2;
auto iter = connectionMaps.begin();
sptr<AccessibleAbilityConnection> ptr_connect = iter->second;
ASSERT_TRUE(ptr_connect);
aacs_ = new AccessibleAbilityChannel(accountData->GetAccountId(),
ptr_connect->GetAbilityInfo().GetId());
aacs_->SetOnKeyPressEventResult(handled, sequence);
sleep(1);
WaitUntilTaskFinished();
EXPECT_EQ(AccessibilityHelper::GetInstance().GetTestKeyPressEvent(), TEST_NUM_2);
EXPECT_EQ(MMI::MockInputManager::GetKeyCode(), MMI::KeyEvent::KEYCODE_VOLUME_UP);
aacs_ = nullptr;
GTEST_LOG_(INFO) << "MockAamsKeyEventFilterTest_Moduletest_OnKeyEvent002 end";
}
/**
* @tc.number: OnKeyEvent003
* @tc.name: OnKeyEvent
* @tc.desc: AccessibleAbility doesn't respond the keyevent within 500 ms.
*/
HWTEST_F(MockAamsKeyEventFilterTest, MockAamsKeyEventFilterTest_Moduletest_OnKeyEvent003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "MockAamsKeyEventFilterTest_Moduletest_OnKeyEvent003 start";
std::shared_ptr<MMI::KeyEvent> keyEvent = CreateOnKeyEvent(MMI::KeyEvent::KEYCODE_VOLUME_UP);
sleep(TEST_NUM_3);
std::map<std::string, sptr<AccessibleAbilityConnection>> connectionMaps =
Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData()
->GetConnectedA11yAbilities();
EXPECT_EQ(connectionMaps.size(), 1);
auto inputEventConsumer = MMI::MockInputManager::GetInputEventConsumer();
if (inputEventConsumer != nullptr) {
inputEventConsumer->OnInputEvent(keyEvent);
}
sleep(1);
WaitUntilTaskFinished();
EXPECT_EQ(AccessibilityHelper::GetInstance().GetTestKeyPressEvent(), TEST_NUM_3);
EXPECT_EQ(MMI::MockInputManager::GetKeyCode(), MMI::KeyEvent::KEYCODE_VOLUME_UP);
GTEST_LOG_(INFO) << "MockAamsKeyEventFilterTest_Moduletest_OnKeyEvent003 end";
}
} // namespace Accessibility
} // namespace OHOS

View File

@ -0,0 +1,686 @@
/*
* Copyright (C) 2022 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 "accessibility_common_helper.h"
#include "accessibility_display_manager.h"
#include "accessibility_element_operator_stub.h"
#include "accessibility_mt_helper.h"
#include "accessible_ability_channel.h"
#include "accessible_ability_manager_service.h"
#include "display_manager.h"
#include "iservice_registry.h"
#include "mock_accessibility_element_operator_callback.h"
#include "mock_accessibility_element_operator_impl.h"
#include "mock_accessibility_element_operator_proxy.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Accessibility {
class MockAamsAccessibleAbilityChannelTest : public testing::Test {
public:
MockAamsAccessibleAbilityChannelTest()
{}
~MockAamsAccessibleAbilityChannelTest()
{}
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
void WritefileAll(const char* fname, const char* data);
void AddAccessibleAbilityConnection(bool isNoCapability = false);
void AddAccessibilityWindowConnection();
sptr<AccessibilityAccountData> accountData_ = nullptr;
sptr<AccessibleAbilityChannel> aastub_ = nullptr;
sptr<AppExecFwk::ElementName> elementName_ = nullptr;
sptr<AccessibleAbilityConnection> AAConnection_ = nullptr;
sptr<MockAccessibilityElementOperatorProxy> proxy_ = nullptr;
};
void MockAamsAccessibleAbilityChannelTest::SetUpTestCase()
{
GTEST_LOG_(INFO) << "MockAamsAccessibleAbilityChannelTest SetUpTestCase";
// Start AAMS
Singleton<AccessibleAbilityManagerService>::GetInstance().OnStart();
AccessibilityCommonHelper::GetInstance().WaitForServicePublish();
Singleton<AccessibleAbilityManagerService>::GetInstance().SwitchedUser(AccessibilityHelper::accountId_);
GTEST_LOG_(INFO) << "AccessibleAbilityManagerService is published";
}
void MockAamsAccessibleAbilityChannelTest::TearDownTestCase()
{
GTEST_LOG_(INFO) << "MockAamsAccessibleAbilityChannelTest TearDownTestCase";
// Stop AAMS
Singleton<AccessibleAbilityManagerService>::GetInstance().OnStop();
}
void MockAamsAccessibleAbilityChannelTest::SetUp()
{
GTEST_LOG_(INFO) << "MockAamsAccessibleAbilityChannelTest SetUp";
}
void MockAamsAccessibleAbilityChannelTest::TearDown()
{
GTEST_LOG_(INFO) << "MockAamsAccessibleAbilityChannelTest TearDown";
Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData()->OnAccountSwitched();
// Deregister ElementOperator
Singleton<AccessibleAbilityManagerService>::GetInstance().DeregisterElementOperator(0);
bool ret = AccessibilityCommonHelper::GetInstance().WaitForLoop(std::bind([=]() -> bool {
auto &aams = Singleton<AccessibleAbilityManagerService>::GetInstance();
if (aams.GetMainRunner()->GetEventQueue()->IsIdle()) {
return true;
} else {
return false;
}
}), 1);
if (!ret) {
GTEST_LOG_(INFO) << "MockAamsAccessibleAbilityChannelTest TearDown EventQueue is not empty";
}
accountData_ = nullptr;
aastub_ = nullptr;
elementName_ = nullptr;
AAConnection_ = nullptr;
proxy_ = nullptr;
}
void MockAamsAccessibleAbilityChannelTest::WritefileAll(const char* fname, const char* data)
{
FILE* fp = nullptr;
if (!(fp = fopen(fname, "w"))) {
printf("open file %s fail \n", fname);
return;
}
(void)fprintf(fp, "%s", data);
(void)fclose(fp);
}
void MockAamsAccessibleAbilityChannelTest::AddAccessibleAbilityConnection(bool isNoCapability)
{
GTEST_LOG_(INFO) << "MockAamsAccessibleAbilityChannelTest AddAccessibleAbilityConnection";
AAFwk::Want want;
AppExecFwk::ElementName name;
std::string deviceId;
name.SetAbilityName("com.example.aalisttest.MainAbility");
name.SetBundleName("com.example.aalisttest");
want.SetElement(name);
AccessibilityAbilityInitParams initParams;
std::shared_ptr<AccessibilityAbilityInfo> abilityInfo = std::make_shared<AccessibilityAbilityInfo>(initParams);
abilityInfo->SetAccessibilityAbilityType(AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_ALL);
uint32_t capabilities = 0;
if (!isNoCapability) {
capabilities = Capability::CAPABILITY_RETRIEVE | Capability::CAPABILITY_TOUCH_GUIDE |
Capability::CAPABILITY_GESTURE | Capability::CAPABILITY_KEY_EVENT_OBSERVER;
}
abilityInfo->SetCapabilityValues(capabilities);
accountData_ = Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
accountData_->Init();
AAConnection_ = new AccessibleAbilityConnection(accountData_->GetAccountId(), 0, *abilityInfo);
elementName_ = new AppExecFwk::ElementName(deviceId, initParams.bundleName, initParams.name);
aastub_ = new AccessibleAbilityChannel(accountData_->GetAccountId(), abilityInfo->GetId());
AAConnection_->OnAbilityConnectDoneSync(*elementName_, aastub_);
accountData_->AddInstalledAbility(*abilityInfo);
sleep(1);
}
void MockAamsAccessibleAbilityChannelTest::AddAccessibilityWindowConnection()
{
GTEST_LOG_(INFO) << "MockAamsAccessibleAbilityChannelTest AddAccessibilityWindowConnection";
// accessibility interaction connection
int32_t windowId = 0;
std::shared_ptr<MockAccessibilityElementOperatorCallback> mockCallback =
std::make_shared<MockAccessibilityElementOperatorCallback>();
sptr<AccessibilityElementOperatorStub> stub =
new MockAccessibilityElementOperatorImpl(windowId, nullptr, *mockCallback);
sptr<MockAccessibilityElementOperatorProxy> proxy = new MockAccessibilityElementOperatorProxy(stub);
proxy_ = proxy;
Singleton<AccessibleAbilityManagerService>::GetInstance().RegisterElementOperator(windowId, proxy, true);
bool ret = AccessibilityCommonHelper::GetInstance().WaitForLoop(std::bind([=]() -> bool {
auto &aams = Singleton<AccessibleAbilityManagerService>::GetInstance();
if (aams.GetMainRunner()->GetEventQueue()->IsIdle()) {
return true;
} else {
return false;
}
}), 1);
if (!ret) {
GTEST_LOG_(INFO) << "MockAamsAccessibleAbilityChannelTest EventQueue is not empty";
}
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_SearchElementInfoByAccessibilityId_001
* @tc.name: SearchElementInfoByAccessibilityId
* @tc.desc: AccessibilityWindowId is accessibility interaction connection windowId,
* check SearchElementInfoByAccessibilityId.
*/
HWTEST_F(MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_SearchElementInfoByAccessibilityId_001,
TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfoByAccessibilityId_001 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection();
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
ElementBasicInfo info = {};
RetError result =
AccessibilityHelper::GetInstance().GetTestStub()->SearchElementInfoByAccessibilityId(info, 0, nullptr, 0, true);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_EQ(-1, proxy_->testChannelElementId_);
EXPECT_EQ(-1, proxy_->testChannelRequestId_);
EXPECT_EQ(-1, proxy_->testChannelMode_);
EXPECT_EQ(result, RET_ERR_NULLPTR);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfoByAccessibilityId_001 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_SearchElementInfoByAccessibilityId_002
* @tc.name: SearchElementInfoByAccessibilityId
* @tc.desc: AccessibilityWindowId not accessibility interaction connection windowId,
* check SearchElementInfoByAccessibilityId.
*/
HWTEST_F(MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_SearchElementInfoByAccessibilityId_002,
TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfoByAccessibilityId_002 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection();
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
ElementBasicInfo info = {};
RetError result = AccessibilityHelper::GetInstance().GetTestStub()->SearchElementInfoByAccessibilityId(
info, 0, nullptr, 0, true);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_EQ(-1, proxy_->testChannelElementId_);
EXPECT_EQ(-1, proxy_->testChannelRequestId_);
EXPECT_EQ(-1, proxy_->testChannelMode_);
EXPECT_EQ(result, RET_ERR_NULLPTR);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfoByAccessibilityId_002 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_SearchElementInfosByText_001
* @tc.name: SearchElementInfosByText
* @tc.desc: AccessibilityWindowId is accessibility interaction connection windowId, check SearchElementInfosByText.
*/
HWTEST_F(
MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_SearchElementInfosByText_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfosByText_001 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection();
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
string text = "text";
RetError result =
AccessibilityHelper::GetInstance().GetTestStub()->SearchElementInfosByText(0, 0, text, 0, nullptr);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_EQ(-1, proxy_->testChannelElementId_);
EXPECT_EQ(-1, proxy_->testChannelRequestId_);
EXPECT_EQ("", proxy_->testText_);
EXPECT_EQ(result, RET_ERR_NULLPTR);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfosByText_001 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_SearchElementInfosByText_002
* @tc.name: SearchElementInfosByText
* @tc.desc: AccessibilityWindowId not accessibility interaction connection windowId, check SearchElementInfosByText.
*/
HWTEST_F(
MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_SearchElementInfosByText_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfosByText_002 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection();
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
string text = "text";
RetError result = AccessibilityHelper::GetInstance().GetTestStub()->SearchElementInfosByText(
ACTIVE_WINDOW_ID, 0, text, 0, nullptr);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_EQ(-1, proxy_->testChannelElementId_);
EXPECT_EQ(-1, proxy_->testChannelRequestId_);
EXPECT_NE(text, proxy_->testText_);
EXPECT_EQ(result, RET_ERR_NULLPTR);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfosByText_002 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_001
* @tc.name: FindFocusedElementInfo
* @tc.desc: AccessibilityWindowId is accessibility interaction connection windowId, check FindFocusedElementInfo.
*/
HWTEST_F(
MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_001 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection();
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
int32_t focusType = OHOS::Accessibility::FOCUS_TYPE_INPUT;
RetError result =
AccessibilityHelper::GetInstance().GetTestStub()->FindFocusedElementInfo(0, 0, focusType, 0, nullptr);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_EQ(-1, proxy_->testChannelElementId_);
EXPECT_EQ(-1, proxy_->testChannelRequestId_);
EXPECT_EQ(0, proxy_->testFocusType_);
EXPECT_EQ(result, RET_ERR_NULLPTR);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_001 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_002
* @tc.name: FindFocusedElementInfo
* @tc.desc: AccessibilityWindowId not accessibility interaction connection windowId, check FindFocusedElementInfo.
*/
HWTEST_F(
MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_002 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection();
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
int32_t focusType = OHOS::Accessibility::FOCUS_TYPE_INPUT;
RetError result = AccessibilityHelper::GetInstance().GetTestStub()->FindFocusedElementInfo(
ACTIVE_WINDOW_ID, 0, focusType, 0, nullptr);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_EQ(-1, proxy_->testChannelElementId_);
EXPECT_EQ(-1, proxy_->testChannelRequestId_);
EXPECT_NE(focusType, proxy_->testFocusType_);
EXPECT_EQ(result, RET_ERR_NULLPTR);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_002 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_003
* @tc.name: FindFocusedElementInfo
* @tc.desc: FocusType is FOCUS_TYPE_ACCESSIBILITY, check FindFocusedElementInfo.
*/
HWTEST_F(
MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_003 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection();
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
int32_t focusType = OHOS::Accessibility::FOCUS_TYPE_ACCESSIBILITY;
RetError result =
AccessibilityHelper::GetInstance().GetTestStub()->FindFocusedElementInfo(0, 0, focusType, 1, nullptr);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_EQ(-1, proxy_->testChannelElementId_);
EXPECT_EQ(-1, proxy_->testChannelRequestId_);
EXPECT_EQ(0, proxy_->testFocusType_);
EXPECT_EQ(result, RET_ERR_NULLPTR);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_003 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_FocusMoveSearch_001
* @tc.name: FocusMoveSearch
* @tc.desc: AccessibilityWindowId is accessibility interaction connection windowId, check FocusMoveSearch.
*/
HWTEST_F(MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_FocusMoveSearch_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FocusMoveSearch_001 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection();
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
int32_t direction = FocusMoveDirection::UP;
RetError result = AccessibilityHelper::GetInstance().GetTestStub()->FocusMoveSearch(0, 0, direction, 0, nullptr);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_EQ(-1, proxy_->testChannelElementId_);
EXPECT_EQ(-1, proxy_->testChannelRequestId_);
EXPECT_EQ(0, proxy_->testDirection_);
EXPECT_EQ(result, RET_ERR_NULLPTR);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FocusMoveSearch_001 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_FocusMoveSearch_002
* @tc.name: FocusMoveSearch
* @tc.desc: AccessibilityWindowId not accessibility interaction connection windowId, check FocusMoveSearch.
*/
HWTEST_F(MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_FocusMoveSearch_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FocusMoveSearch_002 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection();
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
int32_t direction = FocusMoveDirection::UP;
RetError result =
AccessibilityHelper::GetInstance().GetTestStub()->FocusMoveSearch(ACTIVE_WINDOW_ID, 0, direction, 0, nullptr);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_EQ(-1, proxy_->testChannelElementId_);
EXPECT_EQ(-1, proxy_->testChannelRequestId_);
EXPECT_NE(direction, proxy_->testDirection_);
EXPECT_EQ(result, RET_ERR_NULLPTR);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FocusMoveSearch_002 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_ExecuteAction_001
* @tc.name: ExecuteAction
* @tc.desc: AccessibilityWindowId is accessibility interaction connection windowId, check ExecuteAction.
*/
HWTEST_F(MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_ExecuteAction_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_ExecuteAction_001 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection();
std::map<std::string, std::string> actionArguments;
actionArguments.insert(std::make_pair("invalid", "invalid"));
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
RetError result =
AccessibilityHelper::GetInstance().GetTestStub()->ExecuteAction(0, 4, 3, actionArguments, 0, nullptr);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_EQ(-1, proxy_->testChannelElementId_);
EXPECT_EQ(-1, proxy_->testChannelRequestId_);
EXPECT_EQ(0, proxy_->testAction_);
EXPECT_TRUE(proxy_->testActionArguments_.empty());
EXPECT_EQ(result, RET_ERR_NULLPTR);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_ExecuteAction_001 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_ExecuteAction_002
* @tc.name: ExecuteAction
* @tc.desc: AccessibilityWindowId not accessibility interaction connection windowId, check ExecuteAction.
*/
HWTEST_F(MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_ExecuteAction_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_ExecuteAction_002 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection();
std::map<std::string, std::string> actionArguments;
actionArguments.insert(std::make_pair("invalid", "invalid"));
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
RetError result = AccessibilityHelper::GetInstance().GetTestStub()->ExecuteAction(
ACTIVE_WINDOW_ID, 4, 3, actionArguments, 0, nullptr);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_EQ(-1, proxy_->testChannelElementId_);
EXPECT_EQ(-1, proxy_->testChannelRequestId_);
EXPECT_EQ(0, proxy_->testAction_);
EXPECT_EQ(result, RET_ERR_NULLPTR);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_ExecuteAction_002 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_GetWindows_002
* @tc.name: GetWindows
* @tc.desc: Not add interaction connection check get windows.
*/
HWTEST_F(MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_GetWindows_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_GetWindows_002 start";
// Not add interaction connection,add accessibleAbility connection
AddAccessibleAbilityConnection();
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
uint64_t displayId = Rosen::DisplayManager::GetInstance().GetDefaultDisplayId();
std::vector<AccessibilityWindowInfo> windows;
AccessibilityHelper::GetInstance().GetTestStub()->GetWindowsByDisplayId(displayId, windows);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_GE(windows.size(), 0);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_GetWindows_002 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_SendSimulateGesture_001
* @tc.name: SendSimulateGesture
* @tc.desc: Add connection check send simulate gesture.
*/
HWTEST_F(MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_SendSimulateGesture_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SendSimulateGesture_001 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection();
AccessibilityGesturePosition point {10.0f, 10.0f};
std::shared_ptr<AccessibilityGestureInjectPath> gesturePath = std::make_shared<AccessibilityGestureInjectPath>();
gesturePath->AddPosition(point);
gesturePath->SetDurationTime(100);
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
RetError result = AccessibilityHelper::GetInstance().GetTestStub()->SendSimulateGesture(gesturePath);
EXPECT_EQ(result, RET_OK);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SendSimulateGesture_001 end";
}
/***********************************************************************************************************/
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_SearchElementInfoByAccessibilityId_NoCapability_001
* @tc.name: SearchElementInfoByAccessibilityId
* @tc.desc: No retrieve capability, check SearchElementInfoByAccessibilityId.
*/
HWTEST_F(MockAamsAccessibleAbilityChannelTest,
AccessibleAbilityChannel_ModuleTest_SearchElementInfoByAccessibilityId_NoCapability_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfoByAccessibilityId_NoCapability_001 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection(true);
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
ElementBasicInfo info = {};
RetError result =
AccessibilityHelper::GetInstance().GetTestStub()->SearchElementInfoByAccessibilityId(info, 0, nullptr, 0, true);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_EQ(-1, proxy_->testChannelElementId_);
EXPECT_EQ(-1, proxy_->testChannelRequestId_);
EXPECT_EQ(-1, proxy_->testChannelMode_);
EXPECT_EQ(result, RET_ERR_NULLPTR);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfoByAccessibilityId_NoCapability_001 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_SearchElementInfosByText_NoCapability_001
* @tc.name: SearchElementInfosByText
* @tc.desc: No retrieve capability, check SearchElementInfosByText.
*/
HWTEST_F(MockAamsAccessibleAbilityChannelTest,
AccessibleAbilityChannel_ModuleTest_SearchElementInfosByText_NoCapability_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfosByText_NoCapability_001 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection(true);
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
string text = "text";
RetError result =
AccessibilityHelper::GetInstance().GetTestStub()->SearchElementInfosByText(0, 0, text, 0, nullptr);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_EQ(-1, proxy_->testChannelElementId_);
EXPECT_EQ(-1, proxy_->testChannelRequestId_);
EXPECT_NE(text, proxy_->testText_);
EXPECT_EQ(result, RET_ERR_NULLPTR);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfosByText_NoCapability_001 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_NoCapability_001
* @tc.name: FindFocusedElementInfo
* @tc.desc: No retrieve capability, check FindFocusedElementInfo.
*/
HWTEST_F(MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_NoCapability_001,
TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_NoCapability_001 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection(true);
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
int32_t focusType = OHOS::Accessibility::FOCUS_TYPE_INPUT;
RetError result =
AccessibilityHelper::GetInstance().GetTestStub()->FindFocusedElementInfo(0, 0, focusType, 0, nullptr);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_EQ(-1, proxy_->testChannelElementId_);
EXPECT_EQ(-1, proxy_->testChannelRequestId_);
EXPECT_NE(focusType, proxy_->testFocusType_);
EXPECT_EQ(result, RET_ERR_NULLPTR);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_NoCapability_001 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_FocusMoveSearch_NoCapability_001
* @tc.name: FocusMoveSearch
* @tc.desc: No retrieve capability, check FocusMoveSearch.
*/
HWTEST_F(MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_FocusMoveSearch_NoCapability_001,
TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FocusMoveSearch_NoCapability_001 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection(true);
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
int32_t direction = FocusMoveDirection::UP;
RetError result = AccessibilityHelper::GetInstance().GetTestStub()->FocusMoveSearch(0, 0, direction, 0, nullptr);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_EQ(-1, proxy_->testChannelElementId_);
EXPECT_EQ(-1, proxy_->testChannelRequestId_);
EXPECT_NE(direction, proxy_->testDirection_);
EXPECT_EQ(result, RET_ERR_NULLPTR);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FocusMoveSearch_NoCapability_001 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_ExecuteAction_NoCapability_001
* @tc.name: ExecuteAction
* @tc.desc: No retrieve capability, check ExecuteAction.
*/
HWTEST_F(MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_ExecuteAction_NoCapability_001,
TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_ExecuteAction_NoCapability_001 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection(true);
std::map<std::string, std::string> actionArguments;
actionArguments.insert(std::make_pair("invalid", "invalid"));
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
RetError result =
AccessibilityHelper::GetInstance().GetTestStub()->ExecuteAction(0, 4, 3, actionArguments, 0, nullptr);
sleep(2);
GTEST_LOG_(INFO) << "Test result";
EXPECT_EQ(-1, proxy_->testChannelElementId_);
EXPECT_EQ(-1, proxy_->testChannelRequestId_);
EXPECT_EQ(0, proxy_->testAction_);
EXPECT_NE(actionArguments, proxy_->testActionArguments_);
EXPECT_EQ(result, RET_ERR_NULLPTR);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_ExecuteAction_NoCapability_001 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_GetWindows_NoCapability_001
* @tc.name: GetWindows
* @tc.desc: No retrieve capability, check get windows.
*/
HWTEST_F(
MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_GetWindows_NoCapability_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_GetWindows_NoCapability_001 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection();
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
uint64_t displayId = Rosen::DisplayManager::GetInstance().GetDefaultDisplayId();
std::vector<AccessibilityWindowInfo> windows;
AccessibilityHelper::GetInstance().GetTestStub()->GetWindowsByDisplayId(displayId, windows);
GTEST_LOG_(INFO) << "Test result";
EXPECT_GE(windows.size(), 0);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_GetWindows_NoCapability_001 end";
}
/**
* @tc.number: AccessibleAbilityChannel_ModuleTest_SendSimulateGesture_NoCapability_001
* @tc.name: SendSimulateGesture
* @tc.desc: No gesture capability, check send simulate gesture.
*/
HWTEST_F(MockAamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_SendSimulateGesture_NoCapability_001,
TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SendSimulateGesture_NoCapability_001 start";
// Add connection
AddAccessibilityWindowConnection();
AddAccessibleAbilityConnection(true);
AccessibilityGesturePosition point {10.0f, 10.0f};
std::shared_ptr<AccessibilityGestureInjectPath> gesturePath = std::make_shared<AccessibilityGestureInjectPath>();
gesturePath->AddPosition(point);
gesturePath->SetDurationTime(100);
ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub());
RetError result = AccessibilityHelper::GetInstance().GetTestStub()->SendSimulateGesture(gesturePath);
EXPECT_EQ(result, RET_ERR_NO_CAPABILITY);
GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SendSimulateGesture_NoCapability_001 end";
}
} // namespace Accessibility
} // namespace OHOS

View File

@ -0,0 +1,121 @@
/*
* Copyright (C) 2022 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 "accessibility_common_helper.h"
#include "accessibility_mt_helper.h"
#include "accessible_ability_channel.h"
#include "accessible_ability_connection.h"
#include "accessible_ability_manager_service.h"
#include "common_event_manager.h"
#include "iservice_registry.h"
using namespace testing;
using namespace testing::ext;
using namespace OHOS::EventFwk;
namespace OHOS {
namespace Accessibility {
class MockAccessibilityCommonEventRegistryTest : public ::testing::Test {
public:
MockAccessibilityCommonEventRegistryTest()
{}
~MockAccessibilityCommonEventRegistryTest()
{}
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
void AddAccessibleAbilityConnection();
sptr<AccessibilityAccountData> accountData_ = nullptr;
sptr<AccessibleAbilityChannel> aastub_ = nullptr;
sptr<AppExecFwk::ElementName> elementName_ = nullptr;
sptr<AccessibleAbilityConnection> AAConnection_ = nullptr;
};
void MockAccessibilityCommonEventRegistryTest::SetUpTestCase()
{
GTEST_LOG_(INFO) << "MockAccessibilityCommonEventRegistryTest SetUpTestCase";
// Start AAMS
Singleton<AccessibleAbilityManagerService>::GetInstance().OnStart();
AccessibilityCommonHelper::GetInstance().WaitForServicePublish();
Singleton<AccessibleAbilityManagerService>::GetInstance().SwitchedUser(AccessibilityHelper::accountId_);
GTEST_LOG_(INFO) << "AccessibleAbilityManagerService is published";
}
void MockAccessibilityCommonEventRegistryTest::TearDownTestCase()
{
GTEST_LOG_(INFO) << "MockAccessibilityCommonEventRegistryTest TearDownTestCase";
Singleton<AccessibleAbilityManagerService>::GetInstance().OnStop();
}
void MockAccessibilityCommonEventRegistryTest::SetUp()
{
GTEST_LOG_(INFO) << "SetUp";
}
void MockAccessibilityCommonEventRegistryTest::TearDown()
{
GTEST_LOG_(INFO) << "TearDown";
accountData_ = nullptr;
aastub_ = nullptr;
elementName_ = nullptr;
AAConnection_ = nullptr;
}
void MockAccessibilityCommonEventRegistryTest::AddAccessibleAbilityConnection()
{
GTEST_LOG_(INFO) << "MockAccessibilityCommonEventRegistryTest AddAccessibleAbilityConnection";
AAFwk::Want want;
AppExecFwk::ElementName name;
name.SetAbilityName("com.example.aalisttest.MainAbility");
name.SetBundleName("com.example.aalisttest");
want.SetElement(name);
AccessibilityAbilityInitParams initParams;
std::shared_ptr<AccessibilityAbilityInfo> abilityInfo = std::make_shared<AccessibilityAbilityInfo>(initParams);
accountData_ = Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
AAConnection_ = new AccessibleAbilityConnection(accountData_->GetAccountId(), 0, *abilityInfo);
elementName_ = new AppExecFwk::ElementName("name", "bundleName", "id");
aastub_ = new AccessibleAbilityChannel(accountData_->GetAccountId(), abilityInfo->GetId());
AAConnection_->OnAbilityConnectDoneSync(*elementName_, aastub_);
accountData_->AddInstalledAbility(*abilityInfo);
sleep(1);
}
/**
* @tc.number: AccessibilityCommonEventRegistry_ModuleTest_PackageChanged_001
* @tc.name: PackageChanged
* @tc.desc: There is a connected ability. The package has changed. Empty all install ability.
*/
HWTEST_F(MockAccessibilityCommonEventRegistryTest, AccessibilityCommonEvent_ModuleTest_PackageChanged_001,
TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibilityCommonEvent_ModuleTest_PackageChanged_001 start";
AddAccessibleAbilityConnection();
EXPECT_EQ(1, int(accountData_->GetInstalledAbilities().size()));
// PackageChanged
std::string bundleName = "bundleName";
Singleton<AccessibleAbilityManagerService>::GetInstance().PackageChanged(bundleName);
EXPECT_EQ(1, int(accountData_->GetInstalledAbilities().size()));
AAConnection_->OnAbilityDisconnectDoneSync(*elementName_);
GTEST_LOG_(INFO) << "AccessibilityCommonEvent_ModuleTest_PackageChanged_001 end";
}
} // namespace Accessibility
} // namespace OHOS

View File

@ -0,0 +1,336 @@
/*
* Copyright (C) 2022 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 "accessibility_common_helper.h"
#include "accessibility_display_manager.h"
#include "accessibility_element_operator_proxy.h"
#include "accessibility_element_operator_stub.h"
#include "accessibility_mt_helper.h"
#include "accessible_ability_manager_service.h"
#include "accessible_ability_manager_state_observer_proxy.h"
#include "accessible_ability_manager_state_observer_stub.h"
#include "iservice_registry.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Accessibility {
class MockAAMSServerTest : public testing::Test {
public:
AAMSServerTest()
{}
~AAMSServerTest()
{}
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
void AddAccessibleAbilityConnection();
void WritefileAll(const char* fname, const char* data);
sptr<AccessibilityAccountData> accountData_ = nullptr;
sptr<AccessibleAbilityChannel> aastub_ = nullptr;
sptr<AppExecFwk::ElementName> elementName_ = nullptr;
sptr<AccessibleAbilityConnection> AAConnection_ = nullptr;
};
void AAMSServerTest::SetUpTestCase()
{
GTEST_LOG_(INFO) << "AAMSServerTest SetUpTestCase";
}
void AAMSServerTest::TearDownTestCase()
{
GTEST_LOG_(INFO) << "AAMSServerTest TearDownTestCase";
}
void AAMSServerTest::SetUp()
{
GTEST_LOG_(INFO) << "AAMSServerTest SetUp";
// Start AAMS
Singleton<AccessibleAbilityManagerService>::GetInstance().OnStart();
AccessibilityCommonHelper::GetInstance().WaitForServicePublish();
Singleton<AccessibleAbilityManagerService>::GetInstance().SwitchedUser(AccessibilityHelper::accountId_);
sleep(1);
GTEST_LOG_(INFO) << "AccessibleAbilityManagerService is published";
}
void AAMSServerTest::TearDown()
{
GTEST_LOG_(INFO) << "AAMSServerTest TearDown";
AccessibilityHelper::GetInstance().SetTestStub(nullptr);
AccessibilityHelper::GetInstance().SetTestStateType(-1);
AccessibilityHelper::GetInstance().SetTestEventType(-1);
AccessibilityHelper::GetInstance().SetTestWindowChangeTypes(-1);
AccessibilityHelper::GetInstance().SetTestWindowId(-1);
Singleton<AccessibleAbilityManagerService>::GetInstance().OnStop();
accountData_ = nullptr;
aastub_ = nullptr;
elementName_ = nullptr;
AAConnection_ = nullptr;
}
void AAMSServerTest::WritefileAll(const char* fname, const char* data)
{
FILE* fp = nullptr;
if (!(fp = fopen(fname, "w"))) {
printf("open file %s fail \n", fname);
return;
}
(void)fprintf(fp, "%s", data);
(void)fclose(fp);
}
void AAMSServerTest::AddAccessibleAbilityConnection()
{
GTEST_LOG_(INFO) << "AAMSServerTest AddAccessibleAbilityConnection";
// accessibleAbility connection
AAFwk::Want want;
AppExecFwk::ElementName name;
std::string deviceId;
name.SetAbilityName("com.example.aalisttest.MainAbility");
name.SetBundleName("com.example.aalisttest");
want.SetElement(name);
AccessibilityAbilityInitParams initParams;
std::shared_ptr<AccessibilityAbilityInfo> abilityInfo = std::make_shared<AccessibilityAbilityInfo>(initParams);
abilityInfo->SetAccessibilityAbilityType(AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_ALL);
accountData_ = Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
AAConnection_ = new AccessibleAbilityConnection(accountData_->GetAccountId(), 0, *abilityInfo);
elementName_ = new AppExecFwk::ElementName(deviceId, initParams.bundleName, initParams.name);
aastub_ = new AccessibleAbilityChannel(accountData_->GetAccountId(), abilityInfo->GetId());
AAConnection_->OnAbilityConnectDoneSync(*elementName_, aastub_);
accountData_->AddInstalledAbility(*abilityInfo);
sleep(1);
}
/**
* @tc.number: AAMS_moduletest_SendEvent_001
* @tc.name: SendEvent
* @tc.desc: Test function SendEvent aams send event to accessibility,and check the parm of event.
*
*/
HWTEST_F(AAMSServerTest, SendEvent_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AAMSServerTest SendEvent_001 start";
// register AA
AddAccessibleAbilityConnection();
// make an event
AccessibilityEventInfo eventInfo;
eventInfo.SetEventType(EventType::TYPE_WINDOW_UPDATE);
// aams send event
Singleton<AccessibleAbilityManagerService>::GetInstance().SendEvent(eventInfo);
sleep(1);
// check aa proxy
EXPECT_EQ(AccessibilityHelper::GetInstance().GetTestEventType(), int(EventType::TYPE_WINDOW_UPDATE));
AAConnection_->OnAbilityDisconnectDoneSync(*elementName_);
accountData_->ClearInstalledAbility();
GTEST_LOG_(INFO) << "AAMSServerTest SendEvent_001 end";
}
/**
* @tc.number: AAMS_moduletest_GetAbilityList_001
* @tc.name: GetAbilityList
* @tc.desc: Test function GetAbilityList
* The func with Illegal parameter 1
*/
HWTEST_F(AAMSServerTest, GetAbilityList_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_001 start";
std::vector<OHOS::Accessibility::AccessibilityAbilityInfo> infos;
auto &aams = Singleton<AccessibleAbilityManagerService>::GetInstance();
auto ret = aams.GetAbilityList(0, AbilityStateType::ABILITY_STATE_ENABLE, infos);
EXPECT_EQ(RET_OK, ret);
EXPECT_EQ(infos.size(), 0);
GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_001 end";
}
/**
* @tc.number: AAMS_moduletest_GetAbilityList_002
* @tc.name: GetAbilityList
* @tc.desc: Test function GetAbilityList
* Get Enable Ability list.
*/
HWTEST_F(AAMSServerTest, GetAbilityList_002, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_002 start";
sleep(1);
AddAccessibleAbilityConnection();
std::vector<OHOS::Accessibility::AccessibilityAbilityInfo> infos;
Singleton<AccessibleAbilityManagerService>::GetInstance().GetAbilityList(
AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_SPOKEN, AbilityStateType::ABILITY_STATE_ENABLE, infos);
EXPECT_EQ(infos.size(), 1);
AAConnection_->OnAbilityDisconnectDoneSync(*elementName_);
accountData_->ClearInstalledAbility();
GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_002 end";
}
/**
* @tc.number: AAMS_moduletest_GetAbilityList_003
* @tc.name: GetAbilityList
* @tc.desc: Test function GetAbilityList
* Get Disable Ability list with 2 installed ability accessibility and a connected accessibility ability.
*/
HWTEST_F(AAMSServerTest, GetAbilityList_003, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_003 start";
sleep(1);
AddAccessibleAbilityConnection();
AccessibilityAbilityInitParams initParams;
std::shared_ptr<AccessibilityAbilityInfo> installAbilityInfo =
std::make_shared<AccessibilityAbilityInfo>(initParams);
installAbilityInfo->SetAccessibilityAbilityType(AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_ALL);
installAbilityInfo->SetPackageName("123");
auto accountData = Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
// add install ability dummy
EXPECT_EQ(1, (int)accountData->GetInstalledAbilities().size());
accountData->AddInstalledAbility(*installAbilityInfo);
EXPECT_EQ(2, (int)accountData->GetInstalledAbilities().size());
// ABILITY_STATE_DISABLE
int32_t stateType = AbilityStateType::ABILITY_STATE_DISABLE;
std::vector<OHOS::Accessibility::AccessibilityAbilityInfo> infos;
Singleton<AccessibleAbilityManagerService>::GetInstance().GetAbilityList(
AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_SPOKEN, stateType, infos);
EXPECT_EQ(infos.size(), 1);
AAConnection_->OnAbilityDisconnectDoneSync(*elementName_);
accountData_->ClearInstalledAbility();
GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_003 end";
}
/**
* @tc.number: AAMS_moduletest_GetAbilityList_004
* @tc.name: GetAbilityList
* @tc.desc: Test function GetAbilityList
* Get Disabled Ability list.
*/
HWTEST_F(AAMSServerTest, GetAbilityList_004, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_004 start";
sleep(1);
AddAccessibleAbilityConnection();
int32_t stateType = AbilityStateType::ABILITY_STATE_DISABLE;
std::vector<OHOS::Accessibility::AccessibilityAbilityInfo> infos;
Singleton<AccessibleAbilityManagerService>::GetInstance().GetAbilityList(
AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_SPOKEN, stateType, infos);
EXPECT_EQ(infos.size(), 0);
AAConnection_->OnAbilityDisconnectDoneSync(*elementName_);
accountData_->ClearInstalledAbility();
GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_004 end";
}
/**
* @tc.number: AAMS_moduletest_GetAbilityList_005
* @tc.name: GetAbilityList
* @tc.desc: Test function GetAbilityList
* Get Installed ability
*/
HWTEST_F(AAMSServerTest, GetAbilityList_005, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_005 start";
AddAccessibleAbilityConnection();
std::vector<OHOS::Accessibility::AccessibilityAbilityInfo> infos;
Singleton<AccessibleAbilityManagerService>::GetInstance().GetAbilityList(
AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_SPOKEN,
AbilityStateType::ABILITY_STATE_INSTALLED, infos);
EXPECT_EQ(infos.size(), 1);
AAConnection_->OnAbilityDisconnectDoneSync(*elementName_);
accountData_->ClearInstalledAbility();
GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_005 end";
}
/**
* @tc.number: AAMS_moduletest_RegisterElementOperator_001
* @tc.name: RegisterElementOperator
* @tc.desc: Test function RegisterElementOperator
* Register a ElementOperator and check account data and event detail.
*/
HWTEST_F(AAMSServerTest, RegisterElementOperator_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AAMSServerTest RegisterElementOperator_001 start";
AddAccessibleAbilityConnection();
auto &aams = Singleton<AccessibleAbilityManagerService>::GetInstance();
auto accountData = aams.GetCurrentAccountData();
auto map = accountData->GetAsacConnections();
EXPECT_EQ(int(map.size()), 0);
EXPECT_EQ(RET_OK, aams.RegisterElementOperator(0, nullptr, true));
sleep(1);
GTEST_LOG_(INFO) << "RegisterElementOperator OK";
map = accountData->GetAsacConnections();
EXPECT_EQ(int(map.size()), 1);
aams.DeregisterElementOperator(0);
sleep(1);
AAConnection_->OnAbilityDisconnectDoneSync(*elementName_);
accountData_->ClearInstalledAbility();
GTEST_LOG_(INFO) << "AAMSServerTest RegisterElementOperator_001 end";
}
/**
* @tc.number: AAMS_moduletest_DeregisterElementOperator_001
* @tc.name: DeregisterElementOperator
* @tc.desc: Test function DeregisterElementOperator
* Deregister a ElementOperator and check account data and event detail.
*/
HWTEST_F(AAMSServerTest, DeregisterElementOperator_001, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AAMSServerTest DeregisterElementOperator_001 start";
auto &aams = Singleton<AccessibleAbilityManagerService>::GetInstance();
auto accountData = aams.GetCurrentAccountData();
auto map = accountData->GetAsacConnections();
EXPECT_EQ(int(map.size()), 0);
AddAccessibleAbilityConnection();
sleep(1);
aams.RegisterElementOperator(0, nullptr, true);
sleep(1);
map = accountData->GetAsacConnections();
EXPECT_EQ(int(map.size()), 1);
// wrong windowId
aams.DeregisterElementOperator(1);
sleep(1);
map = accountData->GetAsacConnections();
EXPECT_EQ(int(map.size()), 1);
// true windowId
aams.DeregisterElementOperator(0);
sleep(1);
map = accountData->GetAsacConnections();
EXPECT_EQ(int(map.size()), 0);
AAConnection_->OnAbilityDisconnectDoneSync(*elementName_);
accountData_->ClearInstalledAbility();
GTEST_LOG_(INFO) << "AAMSServerTest DeregisterElementOperator_001 end";
}
} // namespace Accessibility
} // namespace OHOS