• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 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 UIAbility from '@ohos.app.ability.UIAbility';
17import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
18import hilog from '@ohos.hilog';
19import { Hypium } from '@ohos/hypium';
20import testsuite from '../test/List.test';
21import window from '@ohos.window';
22import Want from '@ohos.app.ability.Want';
23import AbilityConstant from '@ohos.app.ability.AbilityConstant';
24import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
25
26export default class TestAbility extends UIAbility {
27  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
28    hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
29    hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
30    hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
31    let abilityDelegator: AbilityDelegatorRegistry.AbilityDelegator;
32    abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
33    let abilityDelegatorArguments: AbilityDelegatorRegistry.AbilityDelegatorArgs;
34    abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments();
35    hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
36    Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite);
37  }
38
39  onDestroy() {
40    hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
41  }
42
43  onWindowStageCreate(windowStage: window.WindowStage) {
44    hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
45    windowStage.loadContent('testability/pages/Index', (err, data) => {
46      if (err.code) {
47        hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
48        return;
49      }
50      hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
51        JSON.stringify(data) ?? '');
52    });
53    let atManager = abilityAccessCtrl.createAtManager();
54      console.info('-------------------------------------requestPermissionsFromUser get location permission start!!!!--------------------------------------');
55      atManager.requestPermissionsFromUser(this.context, ['ohos.permission.LOCATION','ohos.permission.APPROXIMATELY_LOCATION']).then((data) => {
56          console.info('requestPermissionsFromUser data:' + JSON.stringify(data));
57          console.info('requestPermissionsFromUser data permissions:' + data.permissions);
58          console.info('requestPermissionsFromUser data authResults:' + data.authResults);
59          console.info('-------------------------------------requestPermissionsFromUser get location permission end!!!!--------------------------------------');
60      }).catch((err) => {
61        console.info('-------------------------------------requestPermissionsFromUser get location permission error!!!!--------------------------------------');
62        console.info('requestPermissionsFromUser err:' + JSON.stringify(err));
63      })
64  }
65
66  onWindowStageDestroy() {
67    hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
68  }
69
70  onForeground() {
71    hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
72  }
73
74  onBackground() {
75    hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
76  }
77}