1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FRONTEND_API_DEFINES_H 17 #define FRONTEND_API_DEFINES_H 18 19 #include <initializer_list> 20 #include <string_view> 21 #include <map> 22 #include "nlohmann/json.hpp" 23 24 namespace OHOS::uitest { 25 enum ErrCode : uint32_t { 26 /**Old ErrorCode*/ 27 NO_ERROR = 0, 28 /**Internal error, not expected to happen.*/ 29 INTERNAL_ERROR = 1, 30 /**Widget that is expected to be exist lost.*/ 31 WIDGET_LOST = 2, 32 /**Window that is expected to be exist lost.*/ 33 WINDOW_LOST = 3, 34 /**The user assertion failure.*/ 35 ASSERTION_FAILURE = 4, 36 USAGE_ERROR = 5, 37 /**New ErrorCode*/ 38 /**Initialize failed.*/ 39 ERR_INITIALIZE_FAILED = 17000001, 40 /**API does not allow calling concurrently.*/ 41 ERR_API_USAGE = 17000002, 42 /**Component existence assertion failed.*/ 43 ERR_ASSERTION_FAILED = 17000003, 44 /**Component lost/UiWindow lost.*/ 45 ERR_COMPONENT_LOST = 17000004, 46 /**This operation is not supported.*/ 47 ERR_OPERATION_UNSUPPORTED = 17000005, 48 /**Internal error.*/ 49 ERR_INTERNAL = 17000006, 50 /**Invalid input parameter.*/ 51 ERR_INVALID_INPUT = 401, 52 /**The specified SystemCapability name was not found.*/ 53 ERR_NO_SYSTEM_CAPABILITY = 801, 54 /**Invalid input parameter.*/ 55 ERR_INVALID_PARAM = 17000007, 56 }; 57 58 const std::map<ErrCode, std::string> ErrDescMap = { 59 /**Correspondence between error codes and descriptions*/ 60 {NO_ERROR, "No Error"}, 61 {ERR_INITIALIZE_FAILED, "Initialization failed."}, 62 {ERR_API_USAGE, "The async function is not called with await."}, 63 {ERR_ASSERTION_FAILED, "Assertion failed."}, 64 {ERR_COMPONENT_LOST, "The window or component is invisible or destroyed."}, 65 {ERR_OPERATION_UNSUPPORTED, "This operation is not supported."}, 66 {ERR_INTERNAL, "Internal error."}, 67 {ERR_NO_SYSTEM_CAPABILITY, "The specified SystemCapability name was not found."}, 68 {ERR_INVALID_INPUT, "Invalid input parameter."}, 69 }; 70 71 /**API invocation error detail wrapper.*/ 72 struct ApiCallErr { 73 public: 74 ErrCode code_; 75 std::string message_ = ""; 76 77 ApiCallErr() = delete; 78 ApiCallErrApiCallErr79 explicit ApiCallErr(ErrCode ec) 80 { 81 code_ = ec; 82 message_ = ErrDescMap.find(ec)->second; 83 } 84 ApiCallErrApiCallErr85 ApiCallErr(ErrCode ec, std::string_view msg) 86 { 87 code_ = ec; 88 message_ = std::string(msg); 89 } 90 }; 91 92 /**Structure wraps the api-call data.*/ 93 struct ApiCallInfo { 94 std::string apiId_; 95 std::string callerObjRef_; 96 nlohmann::json paramList_ = nlohmann::json::array(); 97 int32_t fdParamIndex_ = -1; // support fd as param 98 bool convertError_ = false; 99 }; 100 101 /**Structure wraps the api-call reply.*/ 102 struct ApiReplyInfo { 103 nlohmann::json resultValue_ = nullptr; 104 ApiCallErr exception_ = ApiCallErr(NO_ERROR); 105 bool convertError_ = false; 106 }; 107 108 /** Specifications of a frontend enumerator value.*/ 109 struct FrontendEnumValueDef { 110 std::string_view name_; 111 std::string_view valueJson_; 112 }; 113 114 /** Specifications of a frontend enumerator.*/ 115 struct FrontendEnumeratorDef { 116 std::string_view name_; 117 const FrontendEnumValueDef *values_; 118 size_t valueCount_; 119 }; 120 121 /** Specifications of a frontend json data property.*/ 122 struct FrontEndJsonPropDef { 123 std::string_view name_; 124 std::string_view type_; 125 bool required_; 126 }; 127 /** Specifications of a frontend json object.*/ 128 struct FrontEndJsonDef { 129 std::string_view name_; 130 const FrontEndJsonPropDef *props_; 131 size_t propCount_; 132 }; 133 134 /** Specifications of a frontend class method.*/ 135 struct FrontendMethodDef { 136 std::string_view name_; 137 std::string_view signature_; 138 bool static_; 139 bool fast_; 140 bool convertError_ = false; 141 }; 142 143 /** Specifications of a frontend class.*/ 144 struct FrontEndClassDef { 145 std::string_view name_; 146 const FrontendMethodDef *methods_; 147 size_t methodCount_; 148 bool bindUiDriver_; 149 }; 150 151 /** MatchPattern enumerator definition.*/ 152 constexpr FrontendEnumValueDef PATTERN_VALUES[] = { 153 {"EQUALS", "0"}, 154 {"CONTAINS", "1"}, 155 {"STARTS_WITH", "2"}, 156 {"ENDS_WITH", "3"}, 157 {"REG_EXP", "4"}, 158 {"REG_EXP_ICASE", "5"}, 159 }; 160 constexpr FrontendEnumeratorDef MATCH_PATTERN_DEF = { 161 "MatchPattern", 162 PATTERN_VALUES, 163 sizeof(PATTERN_VALUES) / sizeof(FrontendEnumValueDef), 164 }; 165 166 /** Window ResizeDirection enumerator definition.*/ 167 constexpr FrontendEnumValueDef RESIZE_DIRECTION_VALUES[] = { 168 {"LEFT", "0"}, {"RIGHT", "1"}, {"UP", "2"}, {"DOWN", "3"}, 169 {"LEFT_UP", "4"}, {"LEFT_DOWN", "5"}, {"RIGHT_UP", "6"}, {"RIGHT_DOWN", "7"}, 170 }; 171 constexpr FrontendEnumeratorDef RESIZE_DIRECTION_DEF = { 172 "ResizeDirection", 173 RESIZE_DIRECTION_VALUES, 174 sizeof(RESIZE_DIRECTION_VALUES) / sizeof(FrontendEnumValueDef), 175 }; 176 177 /** WindowMode enumerator definition.*/ 178 constexpr FrontendEnumValueDef WINDOW_MODE_VALUES[] = { 179 {"FULLSCREEN", "0"}, 180 {"PRIMARY", "1"}, 181 {"SECONDARY", "2"}, 182 {"FLOATING", "3"}, 183 }; 184 constexpr FrontendEnumeratorDef WINDOW_MODE_DEF = { 185 "WindowMode", 186 WINDOW_MODE_VALUES, 187 sizeof(WINDOW_MODE_VALUES) / sizeof(FrontendEnumValueDef), 188 }; 189 190 /** Describes the rotation of the device display.*/ 191 constexpr FrontendEnumValueDef DISPLAY_ROTATION_VALUES[] = { 192 {"ROTATION_0", "0"}, 193 {"ROTATION_90", "1"}, 194 {"ROTATION_180", "2"}, 195 {"ROTATION_270", "3"}, 196 }; 197 constexpr FrontendEnumeratorDef DISPLAY_ROTATION_DEF = { 198 "DisplayRotation", 199 DISPLAY_ROTATION_VALUES, 200 sizeof(DISPLAY_ROTATION_VALUES) / sizeof(FrontendEnumValueDef), 201 }; 202 203 /** Describes the Button of the mouse.*/ 204 constexpr FrontendEnumValueDef MOUSE_BUTTON_VALUES[] = { 205 {"MOUSE_BUTTON_LEFT", "0"}, 206 {"MOUSE_BUTTON_RIGHT", "1"}, 207 {"MOUSE_BUTTON_MIDDLE", "2"}, 208 }; 209 constexpr FrontendEnumeratorDef MOUSE_BUTTON_DEF = { 210 "MouseButton", 211 MOUSE_BUTTON_VALUES, 212 sizeof(MOUSE_BUTTON_VALUES) / sizeof(FrontendEnumValueDef), 213 }; 214 215 /** Describes the direction of the UI operation.*/ 216 constexpr FrontendEnumValueDef UI_DIRECTION_VALUES[] = { 217 {"LEFT", "0"}, 218 {"RIGHT", "1"}, 219 {"UP", "2"}, 220 {"DOWN", "3"}, 221 }; 222 constexpr FrontendEnumeratorDef UI_DIRECTION_DEF = { 223 "UiDirection", 224 UI_DIRECTION_VALUES, 225 sizeof(UI_DIRECTION_VALUES) / sizeof(FrontendEnumValueDef), 226 }; 227 228 /** Rect jsonObject definition.*/ 229 constexpr FrontEndJsonPropDef RECT_PROPERTIES[] = { 230 {"left", "int", true}, 231 {"top", "int", true}, 232 {"right", "int", true}, 233 {"bottom", "int", true}, 234 {"displayId", "int", false}, 235 }; 236 constexpr FrontEndJsonDef RECT_DEF = { 237 "Rect", 238 RECT_PROPERTIES, 239 sizeof(RECT_PROPERTIES) / sizeof(FrontEndJsonPropDef), 240 }; 241 242 /** Point jsonObject definition.*/ 243 constexpr FrontEndJsonPropDef POINT_PROPERTIES[] = { 244 {"x", "int", true}, 245 {"y", "int", true}, 246 {"displayId", "int", false}, 247 }; 248 constexpr FrontEndJsonDef POINT_DEF = { 249 "Point", 250 POINT_PROPERTIES, 251 sizeof(POINT_PROPERTIES) / sizeof(FrontEndJsonPropDef), 252 }; 253 254 /** WindowFilter jsonObject definition.*/ 255 constexpr FrontEndJsonPropDef WINDOW_FILTER_PROPERTIES[] = { 256 {"bundleName", "string", false}, 257 {"title", "string", false}, 258 {"focused", "bool", false}, 259 {"actived", "bool", false}, // Deprecated from API 11 260 {"active", "bool", false}, 261 {"displayId", "int", false}, 262 }; 263 constexpr FrontEndJsonDef WINDOW_FILTER_DEF = { 264 "WindowFilter", 265 WINDOW_FILTER_PROPERTIES, 266 sizeof(WINDOW_FILTER_PROPERTIES) / sizeof(FrontEndJsonPropDef), 267 }; 268 269 /** InputTextMode jsonObject definition.*/ 270 constexpr FrontEndJsonPropDef INPUTTEXT_MODE_PROPERTIES[] = { 271 {"paste", "bool", false}, 272 {"addition", "bool", false}, 273 }; 274 constexpr FrontEndJsonDef INPUTTEXT_MODE_DEF = { 275 "InputTextMode", 276 INPUTTEXT_MODE_PROPERTIES, 277 sizeof(INPUTTEXT_MODE_PROPERTIES) / sizeof(FrontEndJsonPropDef), 278 }; 279 280 /** UIElementInfo jsonObject definition.*/ 281 constexpr FrontEndJsonPropDef UI_ELEMENT_INFO_PROPERTIES[] = { 282 {"bundleName", "string", false}, 283 {"text", "string", false}, 284 {"type", "string", false}, 285 }; 286 constexpr FrontEndJsonDef UI_ELEMENT_INFO_DEF = { 287 "UIElementInfo", 288 UI_ELEMENT_INFO_PROPERTIES, 289 sizeof(UI_ELEMENT_INFO_PROPERTIES) / sizeof(FrontEndJsonPropDef), 290 }; 291 292 /** TouchPadSwipeOptions definition.*/ 293 constexpr FrontEndJsonPropDef TOUCH_PAD_SWIPE_OPTIONS[] = { 294 {"stay", "bool", false}, 295 {"speed", "int", false}, 296 }; 297 constexpr FrontEndJsonDef TOUCH_PAD_SWIPE_OPTIONS_DEF = { 298 "TouchPadSwipeOptions", 299 TOUCH_PAD_SWIPE_OPTIONS, 300 sizeof(TOUCH_PAD_SWIPE_OPTIONS) / sizeof(FrontEndJsonPropDef), 301 }; 302 303 /** By class definition. deprecated since api 9*/ 304 constexpr FrontendMethodDef BY_METHODS[] = { 305 {"By.id", "(int):By", false, true}, 306 {"By.text", "(string,int?):By", false, true}, // MatchPattern enum as int value 307 {"By.key", "(string):By", false, true}, 308 {"By.type", "(string):By", false, true}, 309 {"By.enabled", "(bool?):By", false, true}, // default bool arg: true 310 {"By.focused", "(bool?):By", false, true}, 311 {"By.selected", "(bool?):By", false, true}, 312 {"By.clickable", "(bool?):By", false, true}, 313 {"By.scrollable", "(bool?):By", false, true}, 314 {"By.isBefore", "(By):By", false, true}, 315 {"By.isAfter", "(By):By", false, true}, 316 }; 317 constexpr std::string_view REF_SEED_BY = "On#seed"; 318 constexpr FrontEndClassDef BY_DEF = { 319 "By", 320 BY_METHODS, 321 sizeof(BY_METHODS) / sizeof(FrontendMethodDef), 322 }; 323 324 /** UiDriver class definition.*/ 325 constexpr FrontendMethodDef UI_DRIVER_METHODS[] = { 326 {"UiDriver.create", "():UiDriver", true, true}, 327 {"UiDriver.delayMs", "(int):void", false, false}, 328 {"UiDriver.findComponent", "(By):UiComponent", false, false}, 329 {"UiDriver.findComponents", "(By):[UiComponent]", false, false}, 330 {"UiDriver.screenCap", "(int):bool", false, false}, // fliePath as fileDescription. 331 {"UiDriver.assertComponentExist", "(By):void", false, false}, 332 {"UiDriver.pressBack", "():void", false, false}, 333 {"UiDriver.triggerKey", "(int):void", false, false}, 334 {"UiDriver.swipe", "(int,int,int,int,int?):void", false, false}, 335 {"UiDriver.click", "(int,int):void", false, false}, 336 {"UiDriver.longClick", "(int,int):void", false, false}, 337 {"UiDriver.doubleClick", "(int,int):void", false, false}, 338 }; 339 constexpr FrontEndClassDef UI_DRIVER_DEF = { 340 "UiDriver", 341 UI_DRIVER_METHODS, 342 sizeof(UI_DRIVER_METHODS) / sizeof(FrontendMethodDef), 343 }; 344 345 /** UiComponent class definition.*/ 346 constexpr FrontendMethodDef UI_COMPONENT_METHODS[] = { 347 {"UiComponent.getId", "():int", false, false}, 348 {"UiComponent.getText", "():string", false, false}, 349 {"UiComponent.getKey", "():string", false, false}, 350 {"UiComponent.getType", "():string", false, false}, 351 {"UiComponent.isEnabled", "():bool", false, false}, 352 {"UiComponent.isFocused", "():bool", false, false}, 353 {"UiComponent.isSelected", "():bool", false, false}, 354 {"UiComponent.isClickable", "():bool", false, false}, 355 {"UiComponent.isScrollable", "():bool", false, false}, 356 {"UiComponent.click", "():void", false, false}, 357 {"UiComponent.longClick", "():void", false, false}, 358 {"UiComponent.doubleClick", "():void", false, false}, 359 {"UiComponent.inputText", "(string):void", false, false}, 360 {"UiComponent.scrollSearch", "(By):UiComponent", false, false}, 361 }; 362 constexpr FrontEndClassDef UI_COMPONENT_DEF = { 363 "UiComponent", 364 UI_COMPONENT_METHODS, 365 sizeof(UI_COMPONENT_METHODS) / sizeof(FrontendMethodDef), 366 }; 367 368 /** On class definition(since api 9, outdates By class).*/ 369 constexpr FrontendMethodDef ON_METHODS[] = { 370 {"On.text", "(string,int?):On", false, true}, // MatchPattern enum as int value 371 {"On.id", "(string,int?):On", false, true}, 372 {"On.type", "(string,int?):On", false, true}, 373 {"On.description", "(string,int?):On", false, true}, 374 {"On.hint", "(string,int?):On", false, true}, 375 {"On.enabled", "(bool?):On", false, true}, // default bool arg: true 376 {"On.focused", "(bool?):On", false, true}, 377 {"On.selected", "(bool?):On", false, true}, 378 {"On.clickable", "(bool?):On", false, true}, 379 {"On.longClickable", "(bool?):On", false, true}, 380 {"On.scrollable", "(bool?):On", false, true}, 381 {"On.checkable", "(bool?):On", false, true}, 382 {"On.checked", "(bool?):On", false, true}, 383 {"On.isBefore", "(On):On", false, true}, 384 {"On.isAfter", "(On):On", false, true}, 385 {"On.within", "(On):On", false, true}, 386 {"On.inWindow", "(string):On", false, true}, 387 {"On.inDisplay", "(int):On", false, true}, 388 {"On.belongingDisplay", "(int):On", false, true, true}, 389 {"On.originalText", "(string,int?):On", false, true, true}, // MatchPattern enum as int value 390 }; 391 392 constexpr std::string_view REF_SEED_ON = "On#seed"; 393 constexpr FrontEndClassDef ON_DEF = { 394 "On", 395 ON_METHODS, 396 sizeof(ON_METHODS) / sizeof(FrontendMethodDef), 397 }; 398 399 /** Driver class definition. (since api 9, outdates UiDriver)*/ 400 constexpr FrontendMethodDef DRIVER_METHODS[] = { 401 {"Driver.create", "():Driver", true, true}, 402 {"Driver.delayMs", "(int):void", false, false}, 403 {"Driver.findComponent", "(On):Component", false, false}, 404 {"Driver.findWindow", "(WindowFilter):UiWindow", false, false}, 405 {"Driver.findComponents", "(On):[Component]", false, false}, 406 {"Driver.waitForComponent", "(On,int):Component", false, false}, 407 {"Driver.screenCap", "(int,int?):bool", false, false}, // fliePath as fileDescription. 408 {"Driver.screenCapture", "(int, Rect?):bool", false, false}, // fliePath as fileDescription. 409 {"Driver.assertComponentExist", "(On):void", false, false}, 410 {"Driver.pressBack", "(int?):void", false, false, true}, 411 {"Driver.triggerKey", "(int,int?):void", false, false}, 412 {"Driver.triggerCombineKeys", "(int,int,int?,int?):void", false, false}, 413 {"Driver.click", "(int,int):void", false, false}, 414 {"Driver.click", "(Point):void", false, false}, 415 {"Driver.clickAt", "(Point):void", false, false, true}, 416 {"Driver.longClick", "(int,int):void", false, false}, 417 {"Driver.longClick", "(Point):void", false, false}, 418 {"Driver.longClickAt", "(Point, int?):void", false, false, true}, 419 {"Driver.doubleClick", "(int,int):void", false, false}, 420 {"Driver.doubleClick", "(Point):void", false, false}, 421 {"Driver.doubleClickAt", "(Point):void", false, false, true}, 422 {"Driver.swipe", "(int,int,int,int,int?):void", false, false}, 423 {"Driver.swipe", "(Point,Point,int?):void", false, false}, 424 {"Driver.swipeBetween", "(Point,Point,int?):void", false, false, true}, 425 {"Driver.drag", "(int,int,int,int,int?):void", false, false}, 426 {"Driver.drag", "(Point,Point,int?):void", false, false}, 427 {"Driver.dragBetween", "(Point,Point,int?,int?):void", false, false, true}, 428 {"Driver.setDisplayRotation", "(int):void", false, false}, // DisplayRotation enum as int value 429 {"Driver.getDisplayRotation", "(int?):int", false, false, true}, // DisplayRotation enum as int value 430 {"Driver.setDisplayRotationEnabled", "(bool):void", false, false}, 431 {"Driver.getDisplaySize", "(int?):Point", false, false, true}, 432 {"Driver.getDisplayDensity", "(int?):Point", false, false, true}, 433 {"Driver.wakeUpDisplay", "():void", false, false}, 434 {"Driver.pressHome", "(int?):void", false, false, true}, 435 {"Driver.waitForIdle", "(int,int):bool", false, false}, 436 {"Driver.fling", "(Point,Point,int,int):void", false, false}, 437 {"Driver.fling", "(int,int,int?):void", false, false}, 438 {"Driver.injectMultiPointerAction", "(PointerMatrix, int?):bool", false, false}, 439 {"Driver.mouseClick", "(Point,int,int?,int?):void", false, false}, 440 {"Driver.mouseDoubleClick", "(Point,int,int?,int?):void", false, false}, 441 {"Driver.mouseLongClick", "(Point,int,int?,int?,int?):void", false, false}, 442 {"Driver.mouseMoveTo", "(Point):void", false, false}, 443 {"Driver.mouseMoveWithTrack", "(Point,Point,int?):void", false, false}, 444 {"Driver.mouseDrag", "(Point,Point,int?,int?):void", false, false}, 445 {"Driver.mouseScroll", "(Point,bool,int,int?,int?,int?):void", false, false}, 446 {"Driver.createUIEventObserver", "():UIEventObserver", false, true}, 447 {"Driver.inputText", "(Point,string,InputTextMode?):void", false, false}, 448 {"Driver.touchPadMultiFingerSwipe", "(int,int,TouchPadSwipeOptions?):void", false, false}, 449 {"Driver.penClick", "(Point):void", false, false}, 450 {"Driver.penLongClick", "(Point,float?):void", false, false}, 451 {"Driver.penDoubleClick", "(Point):void", false, false}, 452 {"Driver.penSwipe", "(Point,Point,int?,float?):void", false, false}, 453 {"Driver.injectPenPointerAction", "(PointerMatrix,int?,float?):void", false, false}, 454 {"Driver.crownRotate", "(signedInt,int?):void", false, false, true}, 455 }; 456 constexpr FrontEndClassDef DRIVER_DEF = { 457 "Driver", 458 DRIVER_METHODS, 459 sizeof(DRIVER_METHODS) / sizeof(FrontendMethodDef), 460 }; 461 462 /** Component class definition.(since api 9, outdates UiComponent)*/ 463 constexpr FrontendMethodDef COMPONENT_METHODS[] = { 464 {"Component.getText", "():string", false, false}, 465 {"Component.getId", "():string", false, false}, 466 {"Component.getType", "():string", false, false}, 467 {"Component.getDescription", "():string", false, false}, 468 {"Component.getHint", "():string", false, false}, 469 {"Component.getDisplayId", "():int", false, false}, 470 {"Component.isEnabled", "():bool", false, false}, 471 {"Component.isFocused", "():bool", false, false}, 472 {"Component.isSelected", "():bool", false, false}, 473 {"Component.isClickable", "():bool", false, false}, 474 {"Component.isLongClickable", "():bool", false, false}, 475 {"Component.isScrollable", "():bool", false, false}, 476 {"Component.isCheckable", "():bool", false, false}, 477 {"Component.isChecked", "():bool", false, false}, 478 {"Component.getBounds", "():Rect", false, false}, 479 {"Component.getBoundsCenter", "():Point", false, false}, 480 {"Component.click", "():void", false, false}, 481 {"Component.longClick", "():void", false, false}, 482 {"Component.doubleClick", "():void", false, false}, 483 {"Component.scrollToTop", "(int?):void", false, false}, 484 {"Component.scrollToBottom", "(int?):void", false, false}, 485 {"Component.inputText", "(string,InputTextMode?):void", false, false}, 486 {"Component.clearText", "():void", false, false}, 487 {"Component.scrollSearch", "(On, bool?, int?):Component", false, false}, 488 {"Component.dragTo", "(Component):void", false, false}, 489 {"Component.pinchOut", "(float):void", false, false}, 490 {"Component.pinchIn", "(float):void", false, false}, 491 {"Component.getOriginalText", "():string", false, false, true}, 492 }; 493 constexpr FrontEndClassDef COMPONENT_DEF = { 494 "Component", 495 COMPONENT_METHODS, 496 sizeof(COMPONENT_METHODS) / sizeof(FrontendMethodDef), 497 }; 498 499 /** UiWindow class definition.*/ 500 constexpr FrontendMethodDef UI_WINDOW_METHODS[] = { 501 {"UiWindow.getBundleName", "():string", false, false}, 502 {"UiWindow.getBounds", "():Rect", false, false}, 503 {"UiWindow.getTitle", "():string", false, false}, 504 {"UiWindow.getWindowMode", "():int", false, false}, // WindowMode enum as int value 505 {"UiWindow.getDisplayId", "():int", false, false}, 506 {"UiWindow.isFocused", "():bool", false, false}, 507 {"UiWindow.isActived", "():bool", false, false}, // Deprecated from API 11 508 {"UiWindow.isActive", "():bool", false, false}, 509 {"UiWindow.focus", "():void", false, false}, 510 {"UiWindow.moveTo", "(int,int):void", false, false}, 511 {"UiWindow.resize", "(int,int,int):void", false, false}, // ResizeDirection enum as int value 512 {"UiWindow.split", "():void", false, false}, 513 {"UiWindow.maximize", "():void", false, false}, 514 {"UiWindow.resume", "():void", false, false}, 515 {"UiWindow.minimize", "():void", false, false}, 516 {"UiWindow.close", "():void", false, false}, 517 }; 518 constexpr FrontEndClassDef UI_WINDOW_DEF = { 519 "UiWindow", 520 UI_WINDOW_METHODS, 521 sizeof(UI_WINDOW_METHODS) / sizeof(FrontendMethodDef), 522 }; 523 524 /** PointerMatrix class definition.*/ 525 constexpr FrontendMethodDef POINTER_MATRIX_METHODS[] = { 526 {"PointerMatrix.create", "(int,int):PointerMatrix", true, true}, 527 {"PointerMatrix.setPoint", "(int,int,Point):void", false, true}, 528 }; 529 constexpr FrontEndClassDef POINTER_MATRIX_DEF = { 530 "PointerMatrix", 531 POINTER_MATRIX_METHODS, 532 sizeof(POINTER_MATRIX_METHODS) / sizeof(FrontendMethodDef), 533 }; 534 535 /** UIEventObserver class definition.*/ 536 constexpr FrontendMethodDef UI_EVENT_OBSERVER_METHODS[] = { 537 // callback<UIElementInfo> saved in js, works as callbackRef in c++. 538 {"UIEventObserver.once", "(string, string):void", false, true}, 539 }; 540 constexpr FrontEndClassDef UI_EVENT_OBSERVER_DEF = { 541 "UIEventObserver", 542 UI_EVENT_OBSERVER_METHODS, 543 sizeof(UI_EVENT_OBSERVER_METHODS) / sizeof(FrontendMethodDef), 544 }; 545 546 /** List all the frontend data-type definitions.*/ 547 const auto FRONTEND_CLASS_DEFS = {&BY_DEF, &UI_DRIVER_DEF, &UI_COMPONENT_DEF, &ON_DEF, 548 &DRIVER_DEF, &COMPONENT_DEF, &UI_WINDOW_DEF, &POINTER_MATRIX_DEF, 549 &UI_EVENT_OBSERVER_DEF}; 550 const auto FRONTEND_ENUMERATOR_DEFS = {&MATCH_PATTERN_DEF, &WINDOW_MODE_DEF, &RESIZE_DIRECTION_DEF, 551 &DISPLAY_ROTATION_DEF, &MOUSE_BUTTON_DEF, &UI_DIRECTION_DEF}; 552 const auto FRONTEND_JSON_DEFS = {&RECT_DEF, &POINT_DEF, &WINDOW_FILTER_DEF, &UI_ELEMENT_INFO_DEF, 553 &TOUCH_PAD_SWIPE_OPTIONS_DEF, &INPUTTEXT_MODE_DEF}; 554 /** The allowed in/out data type scope of frontend apis.*/ 555 const std::initializer_list<std::string_view> DATA_TYPE_SCOPE = { 556 "int", 557 "signedInt", 558 "float", 559 "bool", 560 "string", 561 RECT_DEF.name_, 562 POINT_DEF.name_, 563 WINDOW_FILTER_DEF.name_, 564 BY_DEF.name_, 565 UI_DRIVER_DEF.name_, 566 UI_COMPONENT_DEF.name_, 567 ON_DEF.name_, 568 DRIVER_DEF.name_, 569 COMPONENT_DEF.name_, 570 UI_WINDOW_DEF.name_, 571 POINTER_MATRIX_DEF.name_, 572 UI_EVENT_OBSERVER_DEF.name_, 573 TOUCH_PAD_SWIPE_OPTIONS_DEF.name_, 574 INPUTTEXT_MODE_DEF.name_, 575 }; 576 } // namespace OHOS::uitest 577 578 #endif