未验证 提交 59852bb8 编写于 作者: O openharmony_ci 提交者: Gitee

!6908 mediaLibrary 修改获取权限方式 -monthly

Merge pull request !6908 from caochuan/monthly_getPermission
......@@ -12,10 +12,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import bundle from '@ohos.bundle';
import mediaLibrary from "@ohos.multimedia.mediaLibrary";
import abilityAccessCtrl from "@ohos.abilityAccessCtrl";
import bundle from "@ohos.bundle";
import uitest from "@ohos.uitest";
const presetsCount = {
ActsMediaLibraryAlbumTest: { albumsCount: 15, assetsCount: 27 },
ActsMediaLibraryBaseTest: { albumsCount: 11, assetsCount: 14 },
......@@ -27,7 +27,7 @@ const presetsCount = {
ActsMediaLibraryGetThumbnailTest: { albumsCount: 3, assetsCount: 3 },
ActsMediaLibraryMediafetchoptionsTest: { albumsCount: 3, assetsCount: 8 },
ActsMediaLibraryTrashJsTest: { albumsCount: 6, assetsCount: 24 },
}
};
const IMAGE_TYPE = mediaLibrary.MediaType.IMAGE;
const VIDEO_TYPE = mediaLibrary.MediaType.VIDEO;
......@@ -35,7 +35,7 @@ const AUDIO_TYPE = mediaLibrary.MediaType.AUDIO;
const FILE_TYPE = mediaLibrary.MediaType.FILE;
const FILEKEY = mediaLibrary.FileKey;
const { RELATIVE_PATH, ALBUM_NAME, MEDIA_TYPE } = FILEKEY
const { RELATIVE_PATH, ALBUM_NAME, MEDIA_TYPE } = FILEKEY;
const sleep = async function sleep(times) {
if (!times) {
......@@ -49,41 +49,41 @@ const allFetchOp = function (others) {
others = {};
}
return {
selections: '',
selections: "",
selectionArgs: [],
...others
...others,
};
}
};
const fetchOps = function (testNum, path, type, others) {
if (!others) {
others = {};
}
let ops = {
selections: FILEKEY.RELATIVE_PATH + '= ? AND ' + FILEKEY.MEDIA_TYPE + '=?',
selections: FILEKEY.RELATIVE_PATH + "= ? AND " + FILEKEY.MEDIA_TYPE + "=?",
selectionArgs: [path, type.toString()],
...others
...others,
};
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`)
return ops
}
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`);
return ops;
};
const nameFetchOps = function (testNum, path, display_name, type) {
let ops = {
selections: FILEKEY.RELATIVE_PATH + '= ? AND ' + FILEKEY.DISPLAY_NAME + '= ? AND ' + FILEKEY.MEDIA_TYPE + '=?',
selections: FILEKEY.RELATIVE_PATH + "= ? AND " + FILEKEY.DISPLAY_NAME + "= ? AND " + FILEKEY.MEDIA_TYPE + "=?",
selectionArgs: [path, display_name, type.toString()],
};
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`)
return ops
}
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`);
return ops;
};
const idFetchOps = function (testNum, albumId) {
let ops = {
selections: FILEKEY.ALBUM_ID + '= ?',
selectionArgs: [albumId + ''],
selections: FILEKEY.ALBUM_ID + "= ?",
selectionArgs: [albumId + ""],
};
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`)
return ops
}
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`);
return ops;
};
const fileIdFetchOps = function (testNum, id) {
let ops = {
......@@ -96,16 +96,16 @@ const fileIdFetchOps = function (testNum, id) {
const albumFetchOps = function (testNum, path, albumName, type, others) {
if (!others) {
others = { order: FILEKEY.DATE_ADDED + " DESC", };
others = { order: FILEKEY.DATE_ADDED + " DESC" };
}
let ops = {
selections: RELATIVE_PATH + '= ? AND ' + ALBUM_NAME + '= ? AND ' + MEDIA_TYPE + '= ?',
selections: RELATIVE_PATH + "= ? AND " + ALBUM_NAME + "= ? AND " + MEDIA_TYPE + "= ?",
selectionArgs: [path, albumName, type.toString()],
...others
...others,
};
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`)
return ops
}
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`);
return ops;
};
// albums of two resource types
const albumTwoTypesFetchOps = function (testNum, paths, albumName, types, others) {
......@@ -114,20 +114,27 @@ const albumTwoTypesFetchOps = function (testNum, paths, albumName, types, others
}
try {
let ops = {
selections: '(' + RELATIVE_PATH + '= ? or ' +
RELATIVE_PATH + '= ? ) AND ' +
ALBUM_NAME + '= ? AND (' +
MEDIA_TYPE + '= ? or ' +
MEDIA_TYPE + '= ?)',
selections:
"(" +
RELATIVE_PATH +
"= ? or " +
RELATIVE_PATH +
"= ? ) AND " +
ALBUM_NAME +
"= ? AND (" +
MEDIA_TYPE +
"= ? or " +
MEDIA_TYPE +
"= ?)",
selectionArgs: [paths[0], paths[1], albumName, types[0].toString(), types[1].toString()],
...others
...others,
};
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`)
return ops
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`);
return ops;
} catch (error) {
console.info(`albumTwoTypesFetchOps :: error: ${error}`);
}
}
};
// albums of three resource types
const albumThreeTypesFetchOps = function (testNum, paths, albumName, types, others) {
......@@ -136,47 +143,63 @@ const albumThreeTypesFetchOps = function (testNum, paths, albumName, types, othe
}
try {
let ops = {
selections: '(' + RELATIVE_PATH + '= ? or ' +
RELATIVE_PATH + '= ? or ' +
RELATIVE_PATH + '= ? ) AND ' +
ALBUM_NAME + '= ? AND (' +
MEDIA_TYPE + '= ? or ' +
MEDIA_TYPE + '= ? or ' +
MEDIA_TYPE + '= ?)',
selectionArgs: [paths[0], paths[1], paths[2], albumName,
types[0].toString(), types[1].toString(), types[2].toString()],
...others
selections:
"(" +
RELATIVE_PATH +
"= ? or " +
RELATIVE_PATH +
"= ? or " +
RELATIVE_PATH +
"= ? ) AND " +
ALBUM_NAME +
"= ? AND (" +
MEDIA_TYPE +
"= ? or " +
MEDIA_TYPE +
"= ? or " +
MEDIA_TYPE +
"= ?)",
selectionArgs: [
paths[0],
paths[1],
paths[2],
albumName,
types[0].toString(),
types[1].toString(),
types[2].toString(),
],
...others,
};
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`)
return ops
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`);
return ops;
} catch (error) {
console.info(`albumThreeTypesFetchOps :: error: ${error}`);
}
}
};
const checkPresetsAssets = async function (media, hapName) {
console.info('checkPresetsAssets start')
console.info("checkPresetsAssets start");
let albumList = await media.getAlbums(allFetchOp());
let albumsCount = albumList.length;
let fetchFileResult = await media.getFileAssets(allFetchOp());
let assetsCount = await fetchFileResult.getCount();
let presetsassetsCount = presetsCount[hapName].assetsCount;
let presetsalbumsCount = presetsCount[hapName].albumsCount;
if (assetsCount != presetsCount[hapName].assetsCount || albumsCount !=presetsCount[hapName].albumsCount) {
if (assetsCount != presetsCount[hapName].assetsCount || albumsCount != presetsCount[hapName].albumsCount) {
console.info(`${hapName} checkPresetsAssets failed;
assetsCount : presetsassetsCount = ${assetsCount} : ${presetsassetsCount}
albumsCount : presetsalbumsCount = ${albumsCount} : ${presetsalbumsCount}`)
albumsCount : presetsalbumsCount = ${albumsCount} : ${presetsalbumsCount}`);
} else {
console.info(`${hapName} checkPresetsAssets passed`)
console.info(`${hapName} checkPresetsAssets passed`);
}
}
};
const checkAssetsCount = async function (done, testNum, fetchFileResult, expectCount) {
if (!fetchFileResult) {
console.info(`${testNum}:: fetchFileResult error:`);
expect(false).assertTrue();
done();
return false
return false;
}
let count = await fetchFileResult.getCount();
if (count != expectCount) {
......@@ -185,14 +208,14 @@ const checkAssetsCount = async function (done, testNum, fetchFileResult, expectC
done();
}
return count == expectCount;
}
};
const checkAlbumsCount = function (done, testNum, albumList, expectCount) {
if (!Array.isArray(albumList)) {
console.info(`${testNum}:: albumList error:`);
expect(false).assertTrue();
done();
return false
return false;
}
let albumsCount = albumList.length;
if (albumsCount != expectCount) {
......@@ -201,45 +224,43 @@ const checkAlbumsCount = function (done, testNum, albumList, expectCount) {
done();
}
return albumsCount == expectCount;
}
};
const getPermission = async function (name) {
const getPermission = async function (name, context) {
if (!name) {
name = "ohos.acts.multimedia.mediaLibrary";
}
console.info('getPermission start', name)
console.info("getPermission start", name);
let permissions = ["ohos.permission.MEDIA_LOCATION", "ohos.permission.READ_MEDIA", "ohos.permission.WRITE_MEDIA"];
context.requestPermissionsFromUser(permissions, (data) => {
console.info(`getPermission requestPermissionsFromUser ${JSON.stringify(data)}`);
});
await sleep(200);
let driver = uitest.Driver.create();
await sleep(200);
let button = await driver.findComponent(uitest.ON.text("允许"));
await button.click();
let appInfo = await bundle.getApplicationInfo(name, 0, 100);
let tokenID = appInfo.accessTokenId;
let atManager = abilityAccessCtrl.createAtManager();
try {
await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.MEDIA_LOCATION", 1);
} catch (error) {
console.info('getPermission MEDIA_LOCATION failed')
}
try {
await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.READ_MEDIA", 1);
} catch (error) {
console.info('getPermission READ_MEDIA failed')
}
try {
await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.WRITE_MEDIA", 1);
} catch (error) {
console.info('getPermission WRITE_MEDIA failed')
}
let isGranted1 = await atManager.verifyAccessToken(tokenID, "ohos.permission.MEDIA_LOCATION");
let isGranted2 = await atManager.verifyAccessToken(tokenID, "ohos.permission.READ_MEDIA");
let isGranted3 = await atManager.verifyAccessToken(tokenID, "ohos.permission.WRITE_MEDIA");
if (!(isGranted1 == 0 && isGranted2 == 0 && isGranted3 == 0)) {
console.info('getPermission failed')
console.info("getPermission failed");
}
console.info('getPermission end')
}
console.info("getPermission end");
};
const MODIFY_ERROR_CODE_01 = '-1000';
const MODIFY_ERROR_CODE_01 = "-1000";
const isNum = function (value) {
return typeof value === 'number' && !isNaN(value);
}
return typeof value === "number" && !isNaN(value);
};
export {
getPermission,
IMAGE_TYPE,
......
{
"app":{
"bundleName":"ohos.acts.multimedia.mediaLibrary",
"vendor":"huawei",
"versionCode":1000000,
"versionName":"1.0.0",
"debug":false,
"icon":"$media:icon",
"label":"$string:entry_MainAbility",
"description":"$string:mainability_description",
"distributedNotificationEnabled":true,
"keepAlive":true,
"singleUser":true,
"minAPIVersion":8,
"targetAPIVersion":8,
"car":{
"apiCompatibleVersion":8,
"singleUser":false
}
}
}
{
"app": {
"bundleName": "ohos.acts.multimedia.mediaLibrary",
"vendor": "huawei",
"versionCode": 1000000,
"versionName": "1.0.0",
"debug": false,
"icon": "$media:icon",
"label": "$string:app_name",
"description": "$string:description_application",
"distributedNotificationEnabled": true,
"keepAlive": true,
"singleUser": true,
"minAPIVersion": 9,
"targetAPIVersion": 9,
"car": {
"apiCompatibleVersion": 9,
"singleUser": false
}
}
}
\ No newline at end of file
{
"string": [
{
"name": "entry_MainAbility",
"value": "MediaLibraryJSTestMain"
},
{
"name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability"
}
]
}
\ No newline at end of file
{
"string":[
{
"name":"app_name",
"value":"ohosProject"
}
]
}
\ No newline at end of file
......@@ -15,6 +15,7 @@ import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("mediaLibrary_album_hap") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":mediaLibrary_js_assets",
":mediaLibrary_resources",
......
{
"description": "Configuration for mediaLibrary Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "300000",
"package": "ohos.acts.multimedia.mediaLibrary",
"shell-timeout": "600000"
},
"kits": [
{
"type": "ShellKit",
"pre-push": [
],
"run-command": [
"rm -rf /storage/media/100/local/files/*",
"rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*",
"mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios}",
"mkdir -p /storage/media/100/local/temp"
]
},
{
"type": "PushKit",
"pre-push": [
],
"push": [
"./resource/medialibrary/01.jpg ->/storage/media/100/local/temp",
"./resource/medialibrary/01.mp3 ->/storage/media/100/local/temp",
"./resource/medialibrary/01.mp4 ->/storage/media/100/local/temp"
]
},
{
"type": "ShellKit",
"run-command": [
"mkdir -pv /storage/media/100/local/files/Pictures/Static",
"mkdir -pv /storage/media/100/local/files/Videos/Static",
"mkdir -pv /storage/media/100/local/files/Audios/Static",
"for i in $$(seq 6); do mkdir -pv /storage/media/100/local/files/Pictures/DynamicPro$$i; done;",
"for i in $$(seq 6); do mkdir -pv /storage/media/100/local/files/Pictures/DynamicCb$$i; done;",
"for d in Static; do for i in $$(seq 5); do cp /storage/media/100/local/temp/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in Static; do for i in $$(seq 5); do cp /storage/media/100/local/temp/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in Static; do for i in $$(seq 5); do cp /storage/media/100/local/temp/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"for d in DynamicPro1 DynamicPro2 DynamicPro3 DynamicPro4 DynamicPro5 DynamicPro6 DynamicCb1 DynamicCb2 DynamicCb3 DynamicCb4 DynamicCb5 DynamicCb6; do cp /storage/media/100/local/temp/01.jpg /storage/media/100/local/files/Pictures/$$d ;done;",
"chmod -R 777 /storage/media/100/local/files/*",
"chmod -R 777 /data/service/el2/100/hmdfs/account/files/*",
"hilog -Q pidoff",
"hilog -p off",
"hilog -b I",
"hilog -b D -D 0xD002B70",
"scanner",
"sleep 10"
],
"teardown-command":[
"hilog -b X -D 0xD002B70"
]
},
{
"test-file-name": [
"ActsMediaLibraryAlbumTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
{
"description": "Configuration for mediaLibrary Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "180000",
"bundle-name": "ohos.acts.multimedia.mediaLibrary",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
},
"kits": [
{
"type": "ShellKit",
"pre-push": [],
"run-command": [
"rm -rf /storage/media/100/local/files/*",
"rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*",
"mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios}",
"mkdir -p /storage/media/100/local/temp",
"power-shell wakeup",
"uinput -T -d 300 600 -m 300 600 300 100 -u 300 100",
"power-shell setmode 602"
]
},
{
"type": "PushKit",
"pre-push": [],
"push": [
"./resource/medialibrary/01.jpg ->/storage/media/100/local/temp",
"./resource/medialibrary/01.mp3 ->/storage/media/100/local/temp",
"./resource/medialibrary/01.mp4 ->/storage/media/100/local/temp"
]
},
{
"type": "ShellKit",
"run-command": [
"mkdir -pv /storage/media/100/local/files/Pictures/Static",
"mkdir -pv /storage/media/100/local/files/Videos/Static",
"mkdir -pv /storage/media/100/local/files/Audios/Static",
"for i in $$(seq 6); do mkdir -pv /storage/media/100/local/files/Pictures/DynamicPro$$i; done;",
"for i in $$(seq 6); do mkdir -pv /storage/media/100/local/files/Pictures/DynamicCb$$i; done;",
"for d in Static; do for i in $$(seq 5); do cp /storage/media/100/local/temp/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in Static; do for i in $$(seq 5); do cp /storage/media/100/local/temp/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in Static; do for i in $$(seq 5); do cp /storage/media/100/local/temp/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"for d in DynamicPro1 DynamicPro2 DynamicPro3 DynamicPro4 DynamicPro5 DynamicPro6 DynamicCb1 DynamicCb2 DynamicCb3 DynamicCb4 DynamicCb5 DynamicCb6; do cp /storage/media/100/local/temp/01.jpg /storage/media/100/local/files/Pictures/$$d ;done;",
"chmod -R 777 /storage/media/100/local/files/*",
"chmod -R 777 /data/service/el2/100/hmdfs/account/files/*",
"hilog -Q pidoff",
"hilog -p off",
"hilog -b I",
"hilog -b D -D 0xD002B70",
"scanner",
"sleep 10"
],
"teardown-command": [
"hilog -b X -D 0xD002B70",
"power-shell setmode 600"
]
},
{
"test-file-name": [
"ActsMediaLibraryAlbumTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
import AbilityStage from "@ohos.application.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
globalThis.stageOnCreateRun = 1;
globalThis.stageContext = this.context;
}
}
import AbilityStage from "@ohos.app.ability.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
globalThis.stageOnCreateRun = 1;
globalThis.stageContext = this.context;
}
}
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
onCreate(want,launchParam){
// Ability is creating, initialize resources for this ability
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.log("[Demo] MainAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageCreate")
globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null)
}
onWindowStageDestroy() {
//Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility onBackground")
}
import Ability from '@ohos.app.ability.UIAbility'
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
// Ability is creating, initialize resources for this ability
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.log("[Demo] MainAbility onDestroy")
}
async onWindowStageCreate(windowStage) {
console.log("[Demo] MainAbility onWindowStageCreate windowStage=" + windowStage)
globalThis.windowStage = windowStage
globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "MainAbility/pages/index/index", null)
}
onWindowStageDestroy() {
//Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility onBackground")
}
};
\ No newline at end of file
......@@ -12,10 +12,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import file from '@system.file';
import router from '@ohos.router';
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../../../test/List.test'
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index"
import testsuite from "../../test/List.test.ets"
@Entry
@Component
......@@ -23,24 +24,12 @@ struct Index {
aboutToAppear(){
console.info("start run testcase!!!!")
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
const reportExtend = new ReportExtend(file)
core.addService('report', reportExtend)
core.init()
core.subscribeEvent('task', reportExtend)
const configService = core.getDefaultService('config')
console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters))
globalThis.abilityWant.parameters.timeout = 70000;
configService.setConfig(globalThis.abilityWant.parameters)
console.info('testsuite()---->')
testsuite(globalThis.abilityContext)
core.execute()
console.info('core.execute()---->')
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
build() {
......
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Ability from '@ohos.app.ability.UIAbility'
export default class TestAbility extends Ability {
onCreate(want, launchParam) {
console.log('TestAbility onCreate')
}
onDestroy() {
console.log('TestAbility onDestroy')
}
onWindowStageCreate(windowStage) {
console.log('TestAbility onWindowStageCreate')
windowStage.loadContent("TestAbility/pages/index", (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
});
globalThis.abilityContext = this.context;
}
onWindowStageDestroy() {
console.log('TestAbility onWindowStageDestroy')
}
onForeground() {
console.log('TestAbility onForeground')
}
onBackground() {
console.log('TestAbility onBackground')
}
};
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import router from '@system.router';
@Entry
@Component
struct Second {
private content: string = "Second Page"
build() {
Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('back to index')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
router.back()
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import router from '@ohos.router';
@Entry
@Component
struct Index {
aboutToAppear() {
console.info('TestAbility index aboutToAppear')
}
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(()=>{
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import TestRunner from '@ohos.application.testRunner'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s it',
'-s level', '-s testType', '-s size', '-s timeout',
'-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams = `${targetParams} ${key} ${parameters[key]}`
}
}
return targetParams.trim()
}
async function onAbilityCreateCallback() {
console.log("onAbilityCreateCallback");
}
async function addAbilityMonitorCallback(err: any) {
console.info("addAbilityMonitorCallback : " + JSON.stringify(err))
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
console.info("OpenHarmonyTestRunner OnPrepare ")
}
async onRun() {
console.log('OpenHarmonyTestRunner onRun run')
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a com.example.myapplication.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters["-D"]
if (debug == 'true')
{
cmd += ' -D'
}
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + d.stdResult);
console.info('executeShellCommand : data : ' + d.exitCode);
})
console.info('OpenHarmonyTestRunner onRun end')
}
};
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import file from '@system.file';
import { Core, ExpectExtend, InstrumentLog, ReportExtend } from "deccjsunit/index"
import testsuite from "../../test/List.test.ets"
@Entry
@Component
struct Index {
aboutToAppear(){
console.info("start run testcase!!!!")
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
const reportExtend = new ReportExtend(file)
core.addService('report', reportExtend)
core.init()
core.subscribeEvent('task', reportExtend)
const configService = core.getDefaultService('config')
console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters))
globalThis.abilityWant.parameters.timeout = 70000;
configService.setConfig(globalThis.abilityWant.parameters)
console.info('testsuite()---->')
testsuite(globalThis.abilityContext)
core.execute()
console.info('core.execute()---->')
}
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import albumGetFileAssetsCallbackTest from './albumGetFileAssetsCallback.test.ets'
import albumGetFileAssetsPromiseTest from './albumGetFileAssetsPromise.test.ets'
import albumTestCallBackTest from './albumTestCallBack.test.ets'
import albumTestPromiseTest from './albumTestPromise.test.ets'
export default function testsuite(abilityContext) {
albumGetFileAssetsCallbackTest(abilityContext)
albumGetFileAssetsPromiseTest(abilityContext)
albumTestPromiseTest(abilityContext)
albumTestCallBackTest(abilityContext)
}
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import albumGetFileAssetsCallbackTest from './albumGetFileAssetsCallback.test.ets'
import albumGetFileAssetsPromiseTest from './albumGetFileAssetsPromise.test.ets'
import albumTestCallBackTest from './albumTestCallBack.test.ets'
import albumTestPromiseTest from './albumTestPromise.test.ets'
export default function testsuite() {
albumGetFileAssetsCallbackTest(globalThis.abilityContext)
albumGetFileAssetsPromiseTest(globalThis.abilityContext)
albumTestPromiseTest(globalThis.abilityContext)
albumTestCallBackTest(globalThis.abilityContext)
}
......@@ -35,7 +35,7 @@ export default function albumGetFileAssetsCallbackTest(abilityContext) {
const media = mediaLibrary.getMediaLibrary(abilityContext);
beforeAll(async function () {
console.info('beforeAll case');
await getPermission();
await getPermission(null, abilityContext);
await checkPresetsAssets(media, 'ActsMediaLibraryAlbumTest');
});
beforeEach(function () {
......
{
"module": {
"name": "phone",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:mainability_description",
"mainElement": "MainAbility",
"deviceTypes": [
"tablet",
"default",
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"uiSyntax": "ets",
"pages": "$profile:main_pages",
"abilities": [
{
"name": "ohos.acts.multimedia.mediaLibrary.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:mainability_description",
"icon": "$media:icon",
"label": "$string:entry_MainAbility",
"visible": true,
"orientation": "portrait",
"skills": [
{
"actions": [
"action.system.home"
],
"entities":[
"entity.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name": "ohos.permission.GET_BUNDLE_INFO",
"reason": "use ohos.permission.GET_BUNDLE_INFO"
},
{
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
"reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
},
{
"name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS",
"reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
},
{
"name": "ohos.permission.MEDIA_LOCATION",
"reason":"use ohos.permission.MEDIA_LOCATION"
},
{
"name": "ohos.permission.READ_MEDIA",
"reason":"use ohos.permission.READ_MEDIA"
},
{
"name": "ohos.permission.WRITE_MEDIA",
"reason":"use ohos.permission.WRITE_MEDIA"
}
]
}
}
{
"module": {
"name": "phone",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:phone_entry_dsc",
"mainElement": "MainAbility",
"deviceTypes": [
"tablet",
"default",
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"uiSyntax": "ets",
"pages": "$profile:main_pages",
"abilities": [
{
"name": "com.example.myapplication.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:phone_entry_main",
"icon": "$media:icon",
"label": "$string:entry_label",
"visible": true,
"orientation": "portrait",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name": "ohos.permission.GET_BUNDLE_INFO",
"reason": "use ohos.permission.GET_BUNDLE_INFO"
},
{
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
"reason": "use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
},
{
"name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS",
"reason": "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
},
{
"name": "ohos.permission.MEDIA_LOCATION",
"reason": "use ohos.permission.MEDIA_LOCATION"
},
{
"name": "ohos.permission.READ_MEDIA",
"reason": "use ohos.permission.READ_MEDIA"
},
{
"name": "ohos.permission.WRITE_MEDIA",
"reason": "use ohos.permission.WRITE_MEDIA"
}
]
}
}
\ No newline at end of file
{
"string": [
{
"name": "entry_MainAbility",
"value": "MediaLibraryJSTestMain"
},
{
"name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "phone_entry_dsc",
"value": "i am an entry for phone"
},
{
"name": "phone_entry_main",
"value": "the phone entry ability"
},
{
"name": "entry_label",
"value": "ActsMediaLibraryTest"
},
{
"name": "form_description",
"value": "mediaLibrary"
},
{
"name": "serviceability_description",
"value": "mediaLibrary"
},
{
"name": "description_application",
"value": "mediaLibrary test"
},
{
"name": "app_name",
"value": "ActsMediaLibraryTest"
}
]
}
\ No newline at end of file
{
"src": [
"pages/index/index",
"pages/second/second"
]
{
"src": [
"MainAbility/pages/index/index"
]
}
\ No newline at end of file
{
"app":{
"bundleName":"ohos.acts.multimedia.mediaLibrary",
"vendor":"huawei",
"versionCode":1000000,
"versionName":"1.0.0",
"debug":false,
"icon":"$media:icon",
"label":"$string:entry_MainAbility",
"description":"$string:mainability_description",
"distributedNotificationEnabled":true,
"keepAlive":true,
"singleUser":true,
"minAPIVersion":8,
"targetAPIVersion":8,
"car":{
"apiCompatibleVersion":8,
"singleUser":false
"app": {
"bundleName": "ohos.acts.multimedia.mediaLibrary",
"vendor": "huawei",
"versionCode": 1000000,
"versionName": "1.0.0",
"debug": false,
"icon": "$media:icon",
"label": "$string:app_name",
"description": "$string:description_application",
"distributedNotificationEnabled": true,
"keepAlive": true,
"singleUser": true,
"minAPIVersion": 9,
"targetAPIVersion": 9,
"car": {
"apiCompatibleVersion": 9,
"singleUser": false
}
}
}
}
\ No newline at end of file
{
"string": [
"string":[
{
"name": "entry_MainAbility",
"value": "MediaLibraryJSTestMain"
},
{
"name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability"
"name":"app_name",
"value":"ohosProject"
}
]
}
\ No newline at end of file
}
\ No newline at end of file
......@@ -15,6 +15,7 @@ import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("mediaLibrary_base_hap") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":mediaLibrary_js_assets",
":mediaLibrary_resources",
......
import Ability from '@ohos.app.ability.UIAbility'
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
// Ability is creating, initialize resources for this ability
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.log("[Demo] MainAbility onDestroy")
}
async onWindowStageCreate(windowStage) {
console.log("[Demo] MainAbility onWindowStageCreate windowStage=" + windowStage)
globalThis.windowStage = windowStage
globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "MainAbility/pages/index/index", null)
}
onWindowStageDestroy() {
//Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[Demo] MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("[Demo] MainAbility onBackground")
}
};
\ No newline at end of file
......@@ -12,10 +12,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import file from '@system.file';
import router from '@ohos.router';
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../../../test/List.test'
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index"
import testsuite from "../../test/List.test.ets"
@Entry
@Component
......@@ -23,24 +24,12 @@ struct Index {
aboutToAppear(){
console.info("start run testcase!!!!")
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
const reportExtend = new ReportExtend(file)
core.addService('report', reportExtend)
core.init()
core.subscribeEvent('task', reportExtend)
const configService = core.getDefaultService('config')
console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters))
globalThis.abilityWant.parameters.timeout = 70000;
configService.setConfig(globalThis.abilityWant.parameters)
console.info('testsuite()---->')
testsuite(globalThis.abilityContext)
core.execute()
console.info('core.execute()---->')
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
build() {
......
{
"description": "Configuration for mediaLibrary Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "300000",
"package": "ohos.acts.multimedia.mediaLibrary",
"shell-timeout": "600000"
"type": "OHJSUnitTest",
"test-timeout": "180000",
"bundle-name": "ohos.acts.multimedia.mediaLibrary",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
},
"kits": [
{
......@@ -14,7 +16,10 @@
"rm -rf /storage/media/100/local/files/*",
"rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*",
"mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}",
"mkdir -p /storage/media/100/local/temp"
"mkdir -p /storage/media/100/local/temp",
"power-shell wakeup",
"uinput -T -d 300 600 -m 300 600 300 100 -u 300 100",
"power-shell setmode 602"
]
},
{
......@@ -47,8 +52,9 @@
"scanner",
"sleep 10"
],
"teardown-command":[
"hilog -b X -D 0xD002B70"
"teardown-command": [
"hilog -b X -D 0xD002B70",
"power-shell setmode 600"
]
},
{
......
......@@ -3,7 +3,7 @@ import AbilityStage from "@ohos.application.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
globalThis.stageOnCreateRun = 1;
globalThis.stageContext = this.context;
globalThis.stageOnCreateRun = 1;
globalThis.stageContext = this.context;
}
}
import Ability from '@ohos.application.Ability'
import Ability from '@ohos.app.ability.UIAbility'
import {
UiComponent,
UiDriver,
Component,
Driver,
UiWindow,
ON,
BY,
MatchPattern,
DisplayRotation,
ResizeDirection,
WindowMode,
PointerMatrix,
} from "@ohos.uitest";
export default class MainAbility extends Ability {
onCreate(want,launchParam){
onCreate(want, launchParam) {
// Ability is creating, initialize resources for this ability
console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want;
......@@ -12,11 +25,47 @@ export default class MainAbility extends Ability {
console.log("[Demo] MainAbility onDestroy")
}
onWindowStageCreate(windowStage) {
async onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageCreate")
// var context = this.context
// let array: Array<string> = ["ohos.permission.MEDIA_LOCATION", "ohos.permission.READ_MEDIA", "ohos.permission.WRITE_MEDIA"];
// //requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗
// context.requestPermissionsFromUser(array).then(async function (data) {
// console.log("data type:" + JSON.stringify(data));
// console.log("data:" + data);
// console.log("data permissions:" + data.permissions);
// console.log("data result:" + data.authResults);
// }, (err) => {
// console.error('Failed to start ability', err.code);
// });
// console.info("getPermission 1");
// await new Promise((res) => setTimeout(res, 200));
// let driver = Driver.create();
// console.info("getPermission 2");
// console.info(`driver is ${JSON.stringify(driver)}`);
// await new Promise((res) => setTimeout(res, 200));
// let button = await driver.findComponent(ON.text("允许"));
// while (button) {
// console.info(`button is ${JSON.stringify(button)}`);
// await new Promise((res) => setTimeout(res, 200));
// await button.click();
// button = await driver.findComponent(ON.text("允许"));
// }
// console.info("getPermission 3");
console.log("[Demo] MainAbility onWindowStageCreate windowStage=" + windowStage)
globalThis.windowStage = windowStage
globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null)
windowStage.setUIContent(this.context, "MainAbility/pages/index/index", null)
console.info("getPermission 4");
}
onWindowStageDestroy() {
......
......@@ -12,10 +12,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import file from '@system.file';
import router from '@ohos.router';
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../../../test/List.test'
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index"
import testsuite from "../../test/List.test.ets"
@Entry
@Component
......@@ -23,24 +24,14 @@ struct Index {
aboutToAppear(){
console.info("start run testcase!!!!")
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
const reportExtend = new ReportExtend(file)
console.info("getPermission 5");
core.addService('report', reportExtend)
core.init()
core.subscribeEvent('task', reportExtend)
const configService = core.getDefaultService('config')
console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters))
globalThis.abilityWant.parameters.timeout = 70000;
configService.setConfig(globalThis.abilityWant.parameters)
console.info('testsuite()---->')
testsuite(globalThis.abilityContext)
core.execute()
console.info('core.execute()---->')
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
build() {
......
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Ability from '@ohos.app.ability.UIAbility'
export default class TestAbility extends Ability {
onCreate(want, launchParam) {
console.log('TestAbility onCreate')
}
onDestroy() {
console.log('TestAbility onDestroy')
}
onWindowStageCreate(windowStage) {
console.log('TestAbility onWindowStageCreate')
windowStage.loadContent("TestAbility/pages/index", (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
});
globalThis.abilityContext = this.context;
}
onWindowStageDestroy() {
console.log('TestAbility onWindowStageDestroy')
}
onForeground() {
console.log('TestAbility onForeground')
}
onBackground() {
console.log('TestAbility onBackground')
}
};
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import router from '@system.router';
@Entry
@Component
struct Second {
private content: string = "Second Page"
build() {
Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('back to index')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
router.back()
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import router from '@ohos.router';
@Entry
@Component
struct Index {
aboutToAppear() {
console.info('TestAbility index aboutToAppear')
}
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(()=>{
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import TestRunner from '@ohos.application.testRunner'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s it',
'-s level', '-s testType', '-s size', '-s timeout',
'-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams = `${targetParams} ${key} ${parameters[key]}`
}
}
return targetParams.trim()
}
async function onAbilityCreateCallback() {
console.log("onAbilityCreateCallback");
}
async function addAbilityMonitorCallback(err: any) {
console.info("addAbilityMonitorCallback : " + JSON.stringify(err))
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
console.info("OpenHarmonyTestRunner OnPrepare ")
}
async onRun() {
console.log('OpenHarmonyTestRunner onRun run')
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a com.example.myapplication.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters["-D"]
if (debug == 'true')
{
cmd += ' -D'
}
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + d.stdResult);
console.info('executeShellCommand : data : ' + d.exitCode);
})
console.info('OpenHarmonyTestRunner onRun end')
}
};
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index"
import testsuite from "../../test/List.test.ets"
@Entry
@Component
struct Index {
aboutToAppear(){
console.info("start run testcase!!!!")
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
const reportExtend = new ReportExtend(file)
core.addService('report', reportExtend)
core.init()
core.subscribeEvent('task', reportExtend)
const configService = core.getDefaultService('config')
console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters))
globalThis.abilityWant.parameters.timeout = 70000;
configService.setConfig(globalThis.abilityWant.parameters)
console.info('testsuite()---->')
testsuite(globalThis.abilityContext)
core.execute()
console.info('core.execute()---->')
}
build() {
Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibraryTestCallback from './mediaLibraryTestCallback.test.ets'
import mediaLibraryTestPromise from './mediaLibraryTestPromise.test.ets'
import mediaLibraryTestPromiseOnOffTest from './mediaLibraryTestPromiseOnOff.test.ets'
export default function testsuite(abilityContext) {
mediaLibraryTestCallback(abilityContext)
mediaLibraryTestPromise(abilityContext)
mediaLibraryTestPromiseOnOffTest(abilityContext)
}
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibraryTestCallback from './mediaLibraryTestCallback.test.ets'
import mediaLibraryTestPromise from './mediaLibraryTestPromise.test.ets'
import mediaLibraryTestPromiseOnOffTest from './mediaLibraryTestPromiseOnOff.test.ets'
export default function testsuite() {
mediaLibraryTestCallback(globalThis.abilityContext)
mediaLibraryTestPromise(globalThis.abilityContext)
mediaLibraryTestPromiseOnOffTest(globalThis.abilityContext)
}
{
"src": [
"pages/index/index",
"pages/second/second"
"MainAbility/pages/index/index"
]
}
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册