1 /* 2 * Copyright (c) 2020-2021 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 UI_TEST_EVENT_INJECTOR_H 17 #define UI_TEST_EVENT_INJECTOR_H 18 19 #include "graphic_config.h" 20 21 #if ENABLE_DEBUG 22 #include "components/root_view.h" 23 #include "components/ui_label.h" 24 #include "components/ui_label_button.h" 25 #include "components/ui_scroll_view.h" 26 #include "dock/input_device.h" 27 #include "ui_test.h" 28 #include "layout/grid_layout.h" 29 30 namespace OHOS { 31 class TestEventInjectorView; 32 33 constexpr char* UI_TEST_UP_TO_DOWN = "up_to_down"; 34 constexpr char* UI_TEST_DOWN_TO_UP = "down_to_up"; 35 constexpr char* UI_TEST_LEFT_TO_RIGHT = "left_to_right"; 36 constexpr char* UI_TEST_RIGHT_TO_LEFT = "right_to_left"; 37 constexpr char* UI_TEST_ULEFT_TO_LRIGHT = "uleft_to_lright"; 38 constexpr char* UI_TEST_LRIGHT_TO_ULEFT = "lright_to_uleft"; 39 constexpr char* UI_TEST_INCREASE_DRAG_TIME = "increase_drag_time"; 40 constexpr char* UI_TEST_DECREASE_DRAG_TIME = "decrease_drag_time"; 41 constexpr char* UI_TEST_SET_DRAGE_TIME = "set_drage_time"; 42 43 class UITestEventInjector : public UITest, public UIView::OnClickListener { 44 public: UITestEventInjector()45 UITestEventInjector() {} ~UITestEventInjector()46 ~UITestEventInjector() {} 47 void SetUp() override; 48 void TearDown() override; 49 const UIView* GetTestView() override; 50 bool OnClick(UIView& view, const ClickEvent& event) override; 51 52 void UIKitEventInjectorClickEvent001(); 53 void UIKitEventInjectorDragEvent002(); 54 void UIKitEventInjectorLongPressEvent003(); 55 void UIKitEventInjectorKeyEvent004(); 56 void UIKitEventInjectorUptoDown005(); 57 void UIKitEventInjectorDowntoUp006(); 58 void UIKitEventInjectorLefttoRight007(); 59 void UIKitEventInjectorRighttoLeft008(); 60 void UIKitEventInjectorULefttoLRight009(); 61 void UIKitEventInjectorLRighttoULeft010(); 62 63 private: 64 UIScrollView* container_ = nullptr; 65 GridLayout* layout_ = nullptr; 66 UILabelButton* clickBtn_ = nullptr; 67 UILabelButton* dragBtn_ = nullptr; 68 UILabelButton* longPressBtn_ = nullptr; 69 UILabelButton* keyBtn_ = nullptr; 70 UILabelButton* upToDownBtn_ = nullptr; 71 UILabelButton* downToUpBtn_ = nullptr; 72 UILabelButton* leftToRightBtn_ = nullptr; 73 UILabelButton* rightToLeftBtn_ = nullptr; 74 UILabelButton* uLeftTolRightBtn_ = nullptr; 75 UILabelButton* lRightTouLeftBtn_ = nullptr; 76 UILabelButton* increaseDragTimeBtn_ = nullptr; 77 UILabelButton* decreaseDragTimeBtn_ = nullptr; 78 UILabelButton* DragTimeDisplayBtn_ = nullptr; 79 TestEventInjectorView* clickTestView_ = nullptr; 80 TestEventInjectorView* dragTestView_ = nullptr; 81 TestEventInjectorView* longPressTestView_ = nullptr; 82 TestEventInjectorView* KeyEventTestView_ = nullptr; 83 UIScrollView* scrollTestView_ = nullptr; 84 85 int16_t lastX_ = 0; 86 int16_t lastY_ = 0; 87 uint16_t dragTime_ = 100; // 100: 100ms 88 89 void InnerTest(const char* title, bool touchable, bool draggable, bool dragParent, 90 const char* btnTitle, UILabelButton* btn, TestEventInjectorView*& testView); 91 void SetLastPos(UIView* view); 92 void SetUpButton(UILabelButton* btn, const char* title, const char* id); 93 void SetUpScrollView(); 94 void IncreaseDragTime(); 95 void DecreaseDragTime(); 96 void DragTimeDisplay(); 97 void SetDragTimeDisplay(uint16_t dragTime); 98 }; 99 } // namespace OHOS 100 #endif // UI_TEST_EVENT_INJECTOR_H 101 #endif // ENABLE_DEBUG 102