• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
15import hilog from '@ohos.hilog';
16import Window from '@ohos.window';
17import { Hypium } from '@ohos/hypium';
18import testsuite from '../test/List.test';
19import Ability from '@ohos.app.ability.UIAbility';
20import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
21
22export default class MainAbility extends Ability {
23    onCreate(want, launchParam) {
24        hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
25        hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
26        hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
27        hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
28
29        var abilityDelegator: any;
30        abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
31        var abilityDelegatorArguments: any;
32        abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments();
33        hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
34        if (abilityDelegator != undefined && abilityDelegatorArguments != undefined) {
35            hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
36            Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite);
37        } else {
38            hilog.info(0x0000, 'testTag', '%{public}s', 'abilityDelegator or abilityDelegatorArguments is undefined!!!');
39        }
40    }
41
42    onDestroy() {
43        hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
44        hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
45    }
46
47    onWindowStageCreate(windowStage: Window.WindowStage) {
48        // Main window is created, set main page for this ability
49        hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
50        hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
51
52        globalThis.abilityContext = this.context;
53
54        windowStage.loadContent('pages/index', (err, data) => {
55            if (err.code) {
56                hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
57                hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
58                return;
59            }
60            hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
61            hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
62        });
63    }
64
65    onWindowStageDestroy() {
66        // Main window is destroyed, release UI related resources
67        hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
68        hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
69    }
70
71    onForeground() {
72        // Ability has brought to foreground
73        hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
74        hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
75    }
76
77    onBackground() {
78        // Ability has back to background
79        hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
80        hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
81    }
82}
83