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 16import { AsyncCallback } from '../basic'; 17import UIAbility from '../@ohos.app.ability.UIAbility'; 18import AbilityStage from '../@ohos.app.ability.AbilityStage'; 19import { AbilityMonitor } from './AbilityMonitor'; 20import { AbilityStageMonitor } from './AbilityStageMonitor'; 21import Context from './Context'; 22import Want from "../@ohos.app.ability.Want"; 23import { ShellCmdResult } from './shellCmdResult'; 24 25/** 26 * A global test utility interface used for adding AbilityMonitor objects and control lifecycle states of abilities. 27 * @interface 28 * @syscap SystemCapability.Ability.AbilityRuntime.Core 29 * @since 9 30 */ 31export interface AbilityDelegator { 32 /** 33 * Add an AbilityMonitor object for monitoring the lifecycle state changes of the specified ability in this process. 34 * @param { AbilityMonitor } monitor - AbilityMonitor object 35 * @param { AsyncCallback<void> } callback - The callback of addAbilityMonitor. 36 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 37 * @syscap SystemCapability.Ability.AbilityRuntime.Core 38 * @since 9 39 */ 40 addAbilityMonitor(monitor: AbilityMonitor, callback: AsyncCallback<void>): void; 41 42 /** 43 * Add an AbilityMonitor object for monitoring the lifecycle state changes of the specified ability in this process. 44 * @param { AbilityMonitor } monitor - AbilityMonitor object 45 * @returns { Promise<void> } The promise returned by the function. 46 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 47 * @syscap SystemCapability.Ability.AbilityRuntime.Core 48 * @since 9 49 */ 50 addAbilityMonitor(monitor: AbilityMonitor): Promise<void>; 51 52 /** 53 * Add an AbilityStageMonitor object for monitoring the lifecycle state changes of the specified abilityStage in this process. 54 * @param { AbilityStageMonitor } monitor - AbilityStageMonitor object. 55 * @param { AsyncCallback<void> } callback - The callback of addAbilityStageMonitor. 56 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 57 * @syscap SystemCapability.Ability.AbilityRuntime.Core 58 * @since 9 59 */ 60 addAbilityStageMonitor(monitor: AbilityStageMonitor, callback: AsyncCallback<void>): void; 61 62 /** 63 * Add an AbilityStageMonitor object for monitoring the lifecycle state changes of the specified abilityStage in this process. 64 * @param { AbilityStageMonitor } monitor - AbilityStageMonitor object. 65 * @returns { Promise<void> } The promise returned by the function. 66 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 67 * @syscap SystemCapability.Ability.AbilityRuntime.Core 68 * @since 9 69 */ 70 addAbilityStageMonitor(monitor: AbilityStageMonitor): Promise<void>; 71 72 /** 73 * Remove a specified AbilityMonitor object from the application memory. 74 * @param { AbilityMonitor } monitor - AbilityMonitor object. 75 * @param { AsyncCallback<void> } callback - The callback of removeAbilityMonitor. 76 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 77 * @syscap SystemCapability.Ability.AbilityRuntime.Core 78 * @since 9 79 */ 80 removeAbilityMonitor(monitor: AbilityMonitor, callback: AsyncCallback<void>): void; 81 82 /** 83 * Remove a specified AbilityMonitor object from the application memory. 84 * @param { AbilityMonitor } monitor - AbilityMonitor object. 85 * @returns { Promise<void> } The promise returned by the function. 86 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 87 * @syscap SystemCapability.Ability.AbilityRuntime.Core 88 * @since 9 89 */ 90 removeAbilityMonitor(monitor: AbilityMonitor): Promise<void>; 91 92 /** 93 * Remove a specified AbilityStageMonitor object from the application memory. 94 * @param { AbilityStageMonitor } monitor - AbilityStageMonitor object. 95 * @param { AsyncCallback<void> } callback - The callback of removeAbilityStageMonitor. 96 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 97 * @syscap SystemCapability.Ability.AbilityRuntime.Core 98 * @since 9 99 */ 100 removeAbilityStageMonitor(monitor: AbilityStageMonitor, callback: AsyncCallback<void>): void; 101 102 /** 103 * Remove a specified AbilityStageMonitor object from the application memory. 104 * @param { AbilityStageMonitor } monitor - AbilityStageMonitor object. 105 * @returns { Promise<void> } The promise returned by the function. 106 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 107 * @syscap SystemCapability.Ability.AbilityRuntime.Core 108 * @since 9 109 */ 110 removeAbilityStageMonitor(monitor: AbilityStageMonitor): Promise<void>; 111 112 /** 113 * Wait for and returns the Ability object that matches the conditions set in the given AbilityMonitor. 114 * @param { AbilityMonitor } monitor - AbilityMonitor object. 115 * @param { AsyncCallback<UIAbility> } callback - The callback is used to return the Ability object. 116 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 117 * @syscap SystemCapability.Ability.AbilityRuntime.Core 118 * @since 9 119 */ 120 waitAbilityMonitor(monitor: AbilityMonitor, callback: AsyncCallback<UIAbility>): void; 121 122 /** 123 * Wait for and returns the Ability object that matches the conditions set in the given AbilityMonitor. 124 * @param { AbilityMonitor } monitor - AbilityMonitor object. 125 * @param { number } timeout - Maximum wait time, in milliseconds. 126 * @param { AsyncCallback<UIAbility> } callback - The callback is used to return the Ability object. 127 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 128 * @syscap SystemCapability.Ability.AbilityRuntime.Core 129 * @since 9 130 */ 131 waitAbilityMonitor(monitor: AbilityMonitor, timeout: number, callback: AsyncCallback<UIAbility>): void; 132 133 /** 134 * Wait for and returns the Ability object that matches the conditions set in the given AbilityMonitor. 135 * @param { AbilityMonitor } monitor - AbilityMonitor object. 136 * @param { number } timeout - Maximum wait time, in milliseconds. 137 * @returns { Promise<UIAbility> } Returns the Ability object. 138 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 139 * @syscap SystemCapability.Ability.AbilityRuntime.Core 140 * @since 9 141 */ 142 waitAbilityMonitor(monitor: AbilityMonitor, timeout?: number): Promise<UIAbility>; 143 144 /** 145 * Wait for and returns the AbilityStage object that matches the conditions set in the given AbilityStageMonitor. 146 * @param { AbilityStageMonitor } monitor - AbilityStageMonitor object. 147 * @param { AsyncCallback<AbilityStage> } callback - The callback is used to return the AbilityStage object. 148 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 149 * @syscap SystemCapability.Ability.AbilityRuntime.Core 150 * @since 9 151 */ 152 waitAbilityStageMonitor(monitor: AbilityStageMonitor, callback: AsyncCallback<AbilityStage>): void; 153 154 /** 155 * Wait for and returns the AbilityStage object that matches the conditions set in the given AbilityStageMonitor. 156 * @param { AbilityStageMonitor } monitor - AbilityStageMonitor object. 157 * @param { number } timeout - Maximum wait time, in milliseconds. 158 * @param { AsyncCallback<AbilityStage> } callback - The callback is used to return the AbilityStage object. 159 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 160 * @syscap SystemCapability.Ability.AbilityRuntime.Core 161 * @since 9 162 */ 163 waitAbilityStageMonitor(monitor: AbilityStageMonitor, timeout: number, callback: AsyncCallback<AbilityStage>): void; 164 165 /** 166 * Wait for and returns the AbilityStage object that matches the conditions set in the given AbilityStageMonitor. 167 * @param { AbilityStageMonitor } monitor - AbilityStageMonitor object. 168 * @param { number } timeout - Maximum wait time, in milliseconds. 169 * @returns { Promise<AbilityStage> } Returns the AbilityStage object. 170 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 171 * @syscap SystemCapability.Ability.AbilityRuntime.Core 172 * @since 9 173 */ 174 waitAbilityStageMonitor(monitor: AbilityStageMonitor, timeout?: number): Promise<AbilityStage>; 175 176 /** 177 * Obtain the application context. 178 * @returns { Context } Returns the app Context. 179 * @syscap SystemCapability.Ability.AbilityRuntime.Core 180 * @since 9 181 */ 182 getAppContext(): Context; 183 184 /** 185 * Obtain the lifecycle state of a specified ability. 186 * @param { UIAbility } ability - The Ability object. 187 * @returns { number } Returns the state of the Ability object. 188 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 189 * @syscap SystemCapability.Ability.AbilityRuntime.Core 190 * @since 9 191 */ 192 getAbilityState(ability: UIAbility): number; 193 194 /** 195 * Obtain the ability that is currently being displayed in this process. 196 * @param { AsyncCallback<UIAbility> } callback - The callback is used to return the Ability object. 197 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 198 * @syscap SystemCapability.Ability.AbilityRuntime.Core 199 * @since 9 200 */ 201 getCurrentTopAbility(callback: AsyncCallback<UIAbility>): void; 202 203 /** 204 * Obtain the ability that is currently being displayed in this process. 205 * @returns { Promise<UIAbility> } Returns the Ability object. 206 * @syscap SystemCapability.Ability.AbilityRuntime.Core 207 * @since 9 208 */ 209 getCurrentTopAbility(): Promise<UIAbility> 210 211 /** 212 * Start a new ability. 213 * @param { Want } want - Indicates the ability to start 214 * @param { AsyncCallback<void> } callback - The callback of startAbility. 215 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 216 * @syscap SystemCapability.Ability.AbilityRuntime.Core 217 * @since 9 218 */ 219 startAbility(want: Want, callback: AsyncCallback<void>): void; 220 221 /** 222 * Start a new ability. 223 * @param { Want } want - Indicates the ability to start 224 * @returns { Promise<void> } The promise returned by the function. 225 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 226 * @syscap SystemCapability.Ability.AbilityRuntime.Core 227 * @since 9 228 */ 229 startAbility(want: Want): Promise<void>; 230 231 /** 232 * Invoke the Ability.onForeground() callback of a specified ability without changing its lifecycle state. 233 * @param { UIAbility } ability - The ability object. 234 * @param { AsyncCallback<void> } callback - The callback of doAbilityForeground. 235 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 236 * @syscap SystemCapability.Ability.AbilityRuntime.Core 237 * @since 9 238 */ 239 doAbilityForeground(ability: UIAbility, callback: AsyncCallback<void>): void; 240 241 /** 242 * Invoke the Ability.onForeground() callback of a specified ability without changing its lifecycle state. 243 * @param { UIAbility } ability - The ability object. 244 * @returns { Promise<void> } The promise returned by the function. 245 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 246 * @syscap SystemCapability.Ability.AbilityRuntime.Core 247 * @since 9 248 */ 249 doAbilityForeground(ability: UIAbility): Promise<void>; 250 251 /** 252 * Invoke the Ability.onBackground() callback of a specified ability without changing its lifecycle state. 253 * @param { UIAbility } ability - The ability object. 254 * @param { AsyncCallback<void> } callback - The callback of doAbilityBackground. 255 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 256 * @syscap SystemCapability.Ability.AbilityRuntime.Core 257 * @since 9 258 */ 259 doAbilityBackground(ability: UIAbility, callback: AsyncCallback<void>): void; 260 261 /** 262 * Invoke the Ability.onBackground() callback of a specified ability without changing its lifecycle state. 263 * @param { UIAbility } ability - The ability object. 264 * @returns { Promise<void> } The promise returned by the function. 265 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 266 * @syscap SystemCapability.Ability.AbilityRuntime.Core 267 * @since 9 268 */ 269 doAbilityBackground(ability: UIAbility): Promise<void>; 270 271 /** 272 * Prints log information to the unit testing console. 273 * The total length of the log information to be printed cannot exceed 1000 characters. 274 * 275 * @since 8 276 * @syscap SystemCapability.Ability.AbilityRuntime.Core 277 * @param msg Log information 278 */ 279 print(msg: string, callback: AsyncCallback<void>): void; 280 print(msg: string): Promise<void>; 281 282 /** 283 * Prints log information to the unit testing console. 284 * The total length of the log information to be printed cannot exceed 1000 characters. 285 * @param { string } msg - Log information. 286 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 287 * @syscap SystemCapability.Ability.AbilityRuntime.Core 288 * @since 9 289 */ 290 printSync(msg: string): void; 291 292 /** 293 * Execute the given command in the aa tools side. 294 * 295 * @since 8 296 * @syscap SystemCapability.Ability.AbilityRuntime.Core 297 * @param cmd Shell command 298 * @param timeoutSecs Timeout, in seconds 299 * @returns ShellCmdResult object 300 */ 301 executeShellCommand(cmd: string, callback: AsyncCallback<ShellCmdResult>): void; 302 executeShellCommand(cmd: string, timeoutSecs: number, callback: AsyncCallback<ShellCmdResult>): void; 303 executeShellCommand(cmd: string, timeoutSecs?: number): Promise<ShellCmdResult>; 304 305 /** 306 * Finish the test and print log information to the unit testing console. 307 * The total length of the log information to be printed cannot exceed 1000 characters. 308 * @param { string } msg - Log information. 309 * @param { number } code - Result code. 310 * @param { AsyncCallback<void> } callback - The callback of finishTest. 311 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 312 * @syscap SystemCapability.Ability.AbilityRuntime.Core 313 * @since 9 314 */ 315 finishTest(msg: string, code: number, callback: AsyncCallback<void>): void; 316 317 /** 318 * Finish the test and print log information to the unit testing console. 319 * The total length of the log information to be printed cannot exceed 1000 characters. 320 * @param { string } msg - Log information. 321 * @param { number } code - Result code. 322 * @returns { Promise<void> } The promise returned by the function. 323 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 324 * @syscap SystemCapability.Ability.AbilityRuntime.Core 325 * @since 9 326 */ 327 finishTest(msg: string, code: number): Promise<void>; 328} 329 330export default AbilityDelegator; 331