Changes to be committed:
	modified:   uitest/core/frontend_api_defines.h
	modified:   uitest/core/frontend_api_handler.cpp
	modified:   uitest/core/ui_action.h
This commit is contained in:
肖帅
2022-06-17 21:05:36 +08:00
parent 0f967fa035
commit 21d2f2ddc0
3 changed files with 52 additions and 0 deletions
+1
View File
@@ -139,6 +139,7 @@ namespace OHOS::uitest {
{"UiDriver.assertComponentExist", "(By):void", false, false},
{"UiDriver.pressBack", "():void", false, false},
{"UiDriver.triggerKey", "(int):void", false, false},
{"UiDriver.triggerCombineKeys", "(int,int,int?):void", false, false},
{"UiDriver.click", "(int,int):void", false, false},
{"UiDriver.longClick", "(int,int):void", false, false},
{"UiDriver.doubleClick", "(int,int):void", false, false},
+12
View File
@@ -15,6 +15,7 @@
#include <sstream>
#include "ui_driver.h"
#include "ui_action.h"
#include "frontend_api_handler.h"
namespace OHOS::uitest {
@@ -390,6 +391,17 @@ namespace OHOS::uitest {
driver.TriggerKey(key, uiOpArgs, out.exception_);
};
server.AddHandler("UiDriver.triggerKey", triggerKey);
auto triggerCombineKeys = [](const ApiCallInfo &in, ApiReplyInfo &out) {
auto &driver = GetBackendObject<UiDriver>(in.callerObjRef_);
UiOpArgs uiOpArgs;
auto key0 = ReadCallArg<int32_t>(in, INDEX_ZERO);
auto key1 = ReadCallArg<int32_t>(in, INDEX_ONE);
auto key2 = ReadCallArg<int32_t>(in, INDEX_TWO, KEYCODE_NONE);
auto keyAction = CombinedKeys(key0, key1, key2);
driver.TriggerKey(keyAction, uiOpArgs, out.exception_);
};
server.AddHandler("UiDriver.triggerCombineKeys", triggerCombineKeys);
}
static void RegisterUiDriverTocuchOperators()
+39
View File
@@ -176,6 +176,45 @@ namespace OHOS::uitest {
const int32_t code_;
};
/**Generic Combinedkeys actions.*/
class CombinedKeys final : public KeyAction {
public:
CombinedKeys(int32_t code_zero, int32_t code_one, int32_t code_two)
: code_zero_(code_zero), code_one_(code_one), code_two_(code_two) {};
void ComputeEvents(std::vector<KeyEvent> &recv, const UiOpArgs &opt) const override
{
recv.push_back(KeyEvent {ActionStage::DOWN, code_zero_, 0});
recv.push_back(KeyEvent {ActionStage::DOWN, code_one_, 0});
if (code_two_ != KEYCODE_NONE) {
recv.push_back(KeyEvent {ActionStage::DOWN, code_two_, opt.keyHoldMs_});
} else {
recv.at(INDEX_ONE).holdMs_ = opt.keyHoldMs_;
}
if (code_two_ != KEYCODE_NONE) {
recv.push_back(KeyEvent {ActionStage::UP, code_two_, 0});
}
recv.push_back(KeyEvent {ActionStage::UP, code_one_, 0});
recv.push_back(KeyEvent {ActionStage::UP, code_zero_, 0});
}
std::string Describe() const override
{
std::string desc0 = std::string("key_") + std::to_string(code_zero_);
std::string desc1 = std::string("key_") + std::to_string(code_one_);
if (code_two_ != KEYCODE_NONE) {
std::string desc2 = std::string("key_") + std::to_string(code_two_);
return desc0 + desc1 + desc2;
}
return desc0 + desc1;
}
private:
const int32_t code_zero_;
const int32_t code_one_;
const int32_t code_two_;
};
using Back = NamedPlainKey<KEYNAME_BACK, KEYCODE_BACK>;
using Paste = NamedPlainKey<KEYNAME_PASTE, KEYCODE_V, KEYCODE_CTRL>;
}