1 /* 2 * Copyright (c) 2023 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 INPUTMETHOD_UNITTEST_UTIL_H 17 #define INPUTMETHOD_UNITTEST_UTIL_H 18 19 #include <string> 20 21 #include "block_data.h" 22 #include "bundle_mgr_interface.h" 23 #include "window.h" 24 #include "window_manager.h" 25 #include "window_option.h" 26 #include "wm_common.h" 27 28 namespace OHOS { 29 namespace MiscServices { 30 class FocusChangedListenerTestImpl : public Rosen::IFocusChangedListener { 31 public: 32 FocusChangedListenerTestImpl() = default; 33 ~FocusChangedListenerTestImpl() = default; 34 void OnFocused(const sptr<Rosen::FocusChangeInfo> &focusChangeInfo) override; 35 void OnUnfocused(const sptr<Rosen::FocusChangeInfo> &focusChangeInfo) override; 36 bool getFocus_ = false; 37 static std::shared_ptr<BlockData<bool>> isFocused_; 38 static std::shared_ptr<BlockData<bool>> unFocused_; 39 }; 40 class TddUtil { 41 public: 42 static constexpr int32_t WAIT_APP_START_COMPLETE = 5; 43 static constexpr int32_t WAIT_TASK_EMPTY_TIMES = 100; 44 static constexpr int32_t WAIT_TASK_EMPTY_INTERVAL = 20; 45 static int32_t GetCurrentUserId(); 46 static void StorageSelfTokenID(); 47 static uint64_t AllocTestTokenID( 48 bool isSystemApp, const std::string &bundleName, const std::vector<std::string> &premission = {}); 49 static uint64_t GetTestTokenID(const std::string &bundleName); 50 static void DeleteTestTokenID(uint64_t tokenId); 51 static void SetTestTokenID(uint64_t tokenId); 52 static void RestoreSelfTokenID(); 53 static uint64_t GetCurrentTokenID(); 54 static int32_t GetUid(const std::string &bundleName); 55 static void SetSelfUid(int32_t uid); 56 static bool ExecuteCmd(const std::string &cmd, std::string &result); 57 static pid_t GetImsaPid(); 58 static bool KillImsaProcess(); 59 static void PushEnableImeValue(const std::string &key, const std::string &value); 60 static void GrantNativePermission(); 61 static void DeleteGlobalTable(const std::string &key); 62 static void DeleteUserTable(int32_t userId, const std::string &key); 63 static void SetGlobalTable(const std::string &key, const std::string &content); 64 static void SetUserTable(int32_t userId, const std::string &key, const std::string &content); 65 static std::string GetGlobalTable(const std::string &key); 66 static std::string GetUserTable(int32_t userId, const std::string &key); 67 static int32_t GetEnableData(std::string &value); 68 static void InitWindow(bool isShow); 69 static void DestroyWindow(); 70 static bool GetFocused(); 71 static bool GetUnfocused(); 72 static void InitCurrentImePermissionInfo(); 73 static void EnabledAllIme(); 74 static void DisabledAllIme(); 75 static void StartApp(const std::string &bundleName); 76 static void StopApp(const std::string &bundleName); 77 static void ClickApp(const std::string &cmd); 78 static bool WaitTaskEmpty(); 79 static std::string currentBundleNameMock_; 80 class WindowManager { 81 public: 82 static void CreateWindow(); 83 static void ShowWindow(); 84 static void HideWindow(); 85 static void DestroyWindow(); 86 static void RegisterFocusChangeListener(); 87 static int32_t currentWindowId_; 88 89 private: 90 static sptr<Rosen::Window> window_; 91 static uint64_t windowTokenId_; 92 }; 93 94 private: 95 static sptr<OHOS::AppExecFwk::IBundleMgr> GetBundleMgr(); 96 static int GetUserIdByBundleName(const std::string &bundleName, const int currentUserId); 97 static void DeleteTable(const std::string &key, const std::string &uriProxy); 98 static void SetTable(const std::string &key, const std::string &uriProxy, const std::string &content); 99 static std::string GetTable(const std::string &key, const std::string &uriProxy); 100 static uint64_t selfTokenID_; 101 static uint64_t testTokenID_; 102 static int32_t userID_; 103 }; 104 } // namespace MiscServices 105 } // namespace OHOS 106 #endif // INPUTMETHOD_UNITTEST_UTIL_H