提交 6e5879ca 编写于 作者: C caochuan

getPermission

get permission by requestPermissionsFromUser
Signed-off-by: Ncaochuan <caochuan@huawei.com>
Change-Id: Ibd3b01236c5bd1dfdae7620183dafffb51fccd24
上级 ca41e2a9
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import mediaLibrary from '@ohos.multimedia.mediaLibrary'; import mediaLibrary from "@ohos.multimedia.mediaLibrary";
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; import abilityAccessCtrl from "@ohos.abilityAccessCtrl";
import bundle from '@ohos.bundle'; import bundle from "@ohos.bundle";
import uitest from "@ohos.uitest";
const presetsCount = { const presetsCount = {
ActsMediaLibraryAlbumTest: { albumsCount: 15, assetsCount: 27 }, ActsMediaLibraryAlbumTest: { albumsCount: 15, assetsCount: 27 },
ActsMediaLibraryBaseTest: { albumsCount: 11, assetsCount: 14 }, ActsMediaLibraryBaseTest: { albumsCount: 11, assetsCount: 14 },
...@@ -27,7 +27,7 @@ const presetsCount = { ...@@ -27,7 +27,7 @@ const presetsCount = {
ActsMediaLibraryGetThumbnailTest: { albumsCount: 3, assetsCount: 3 }, ActsMediaLibraryGetThumbnailTest: { albumsCount: 3, assetsCount: 3 },
ActsMediaLibraryMediafetchoptionsTest: { albumsCount: 3, assetsCount: 8 }, ActsMediaLibraryMediafetchoptionsTest: { albumsCount: 3, assetsCount: 8 },
ActsMediaLibraryTrashJsTest: { albumsCount: 6, assetsCount: 24 }, ActsMediaLibraryTrashJsTest: { albumsCount: 6, assetsCount: 24 },
} };
const IMAGE_TYPE = mediaLibrary.MediaType.IMAGE; const IMAGE_TYPE = mediaLibrary.MediaType.IMAGE;
const VIDEO_TYPE = mediaLibrary.MediaType.VIDEO; const VIDEO_TYPE = mediaLibrary.MediaType.VIDEO;
...@@ -35,7 +35,7 @@ const AUDIO_TYPE = mediaLibrary.MediaType.AUDIO; ...@@ -35,7 +35,7 @@ const AUDIO_TYPE = mediaLibrary.MediaType.AUDIO;
const FILE_TYPE = mediaLibrary.MediaType.FILE; const FILE_TYPE = mediaLibrary.MediaType.FILE;
const FILEKEY = mediaLibrary.FileKey; 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) { const sleep = async function sleep(times) {
if (!times) { if (!times) {
...@@ -49,41 +49,41 @@ const allFetchOp = function (others) { ...@@ -49,41 +49,41 @@ const allFetchOp = function (others) {
others = {}; others = {};
} }
return { return {
selections: '', selections: "",
selectionArgs: [], selectionArgs: [],
...others ...others,
}; };
} };
const fetchOps = function (testNum, path, type, others) { const fetchOps = function (testNum, path, type, others) {
if (!others) { if (!others) {
others = {}; others = {};
} }
let ops = { let ops = {
selections: FILEKEY.RELATIVE_PATH + '= ? AND ' + FILEKEY.MEDIA_TYPE + '=?', selections: FILEKEY.RELATIVE_PATH + "= ? AND " + FILEKEY.MEDIA_TYPE + "=?",
selectionArgs: [path, type.toString()], selectionArgs: [path, type.toString()],
...others ...others,
}; };
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`) console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`);
return ops return ops;
} };
const nameFetchOps = function (testNum, path, display_name, type) { const nameFetchOps = function (testNum, path, display_name, type) {
let ops = { 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()], selectionArgs: [path, display_name, type.toString()],
}; };
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`) console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`);
return ops return ops;
} };
const idFetchOps = function (testNum, albumId) { const idFetchOps = function (testNum, albumId) {
let ops = { let ops = {
selections: FILEKEY.ALBUM_ID + '= ?', selections: FILEKEY.ALBUM_ID + "= ?",
selectionArgs: [albumId + ''], selectionArgs: [albumId + ""],
}; };
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`) console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`);
return ops return ops;
} };
const fileIdFetchOps = function (testNum, id) { const fileIdFetchOps = function (testNum, id) {
let ops = { let ops = {
...@@ -96,16 +96,16 @@ const fileIdFetchOps = function (testNum, id) { ...@@ -96,16 +96,16 @@ const fileIdFetchOps = function (testNum, id) {
const albumFetchOps = function (testNum, path, albumName, type, others) { const albumFetchOps = function (testNum, path, albumName, type, others) {
if (!others) { if (!others) {
others = { order: FILEKEY.DATE_ADDED + " DESC", }; others = { order: FILEKEY.DATE_ADDED + " DESC" };
} }
let ops = { 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()], selectionArgs: [path, albumName, type.toString()],
...others ...others,
}; };
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`) console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`);
return ops return ops;
} };
// albums of two resource types // albums of two resource types
const albumTwoTypesFetchOps = function (testNum, paths, albumName, types, others) { const albumTwoTypesFetchOps = function (testNum, paths, albumName, types, others) {
...@@ -114,20 +114,27 @@ const albumTwoTypesFetchOps = function (testNum, paths, albumName, types, others ...@@ -114,20 +114,27 @@ const albumTwoTypesFetchOps = function (testNum, paths, albumName, types, others
} }
try { try {
let ops = { let ops = {
selections: '(' + RELATIVE_PATH + '= ? or ' + selections:
RELATIVE_PATH + '= ? ) AND ' + "(" +
ALBUM_NAME + '= ? AND (' + RELATIVE_PATH +
MEDIA_TYPE + '= ? or ' + "= ? or " +
MEDIA_TYPE + '= ?)', RELATIVE_PATH +
"= ? ) AND " +
ALBUM_NAME +
"= ? AND (" +
MEDIA_TYPE +
"= ? or " +
MEDIA_TYPE +
"= ?)",
selectionArgs: [paths[0], paths[1], albumName, types[0].toString(), types[1].toString()], selectionArgs: [paths[0], paths[1], albumName, types[0].toString(), types[1].toString()],
...others ...others,
}; };
console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`) console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`);
return ops return ops;
} catch (error) { } catch (error) {
console.info(`albumTwoTypesFetchOps :: error: ${error}`); console.info(`albumTwoTypesFetchOps :: error: ${error}`);
} }
} };
// albums of three resource types // albums of three resource types
const albumThreeTypesFetchOps = function (testNum, paths, albumName, types, others) { const albumThreeTypesFetchOps = function (testNum, paths, albumName, types, others) {
...@@ -136,47 +143,63 @@ const albumThreeTypesFetchOps = function (testNum, paths, albumName, types, othe ...@@ -136,47 +143,63 @@ const albumThreeTypesFetchOps = function (testNum, paths, albumName, types, othe
} }
try { try {
let ops = { let ops = {
selections: '(' + RELATIVE_PATH + '= ? or ' + selections:
RELATIVE_PATH + '= ? or ' + "(" +
RELATIVE_PATH + '= ? ) AND ' + RELATIVE_PATH +
ALBUM_NAME + '= ? AND (' + "= ? or " +
MEDIA_TYPE + '= ? or ' + RELATIVE_PATH +
MEDIA_TYPE + '= ? or ' + "= ? or " +
MEDIA_TYPE + '= ?)', RELATIVE_PATH +
selectionArgs: [paths[0], paths[1], paths[2], albumName, "= ? ) AND " +
types[0].toString(), types[1].toString(), types[2].toString()], ALBUM_NAME +
...others "= ? 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)}`) console.info(`${testNum}: fetchOps${JSON.stringify(ops)}`);
return ops return ops;
} catch (error) { } catch (error) {
console.info(`albumThreeTypesFetchOps :: error: ${error}`); console.info(`albumThreeTypesFetchOps :: error: ${error}`);
} }
} };
const checkPresetsAssets = async function (media, hapName) { const checkPresetsAssets = async function (media, hapName) {
console.info('checkPresetsAssets start') console.info("checkPresetsAssets start");
let albumList = await media.getAlbums(allFetchOp()); let albumList = await media.getAlbums(allFetchOp());
let albumsCount = albumList.length; let albumsCount = albumList.length;
let fetchFileResult = await media.getFileAssets(allFetchOp()); let fetchFileResult = await media.getFileAssets(allFetchOp());
let assetsCount = await fetchFileResult.getCount(); let assetsCount = await fetchFileResult.getCount();
let presetsassetsCount = presetsCount[hapName].assetsCount; let presetsassetsCount = presetsCount[hapName].assetsCount;
let presetsalbumsCount = presetsCount[hapName].albumsCount; 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; console.info(`${hapName} checkPresetsAssets failed;
assetsCount : presetsassetsCount = ${assetsCount} : ${presetsassetsCount} assetsCount : presetsassetsCount = ${assetsCount} : ${presetsassetsCount}
albumsCount : presetsalbumsCount = ${albumsCount} : ${presetsalbumsCount}`) albumsCount : presetsalbumsCount = ${albumsCount} : ${presetsalbumsCount}`);
} else { } else {
console.info(`${hapName} checkPresetsAssets passed`) console.info(`${hapName} checkPresetsAssets passed`);
} }
} };
const checkAssetsCount = async function (done, testNum, fetchFileResult, expectCount) { const checkAssetsCount = async function (done, testNum, fetchFileResult, expectCount) {
if (!fetchFileResult) { if (!fetchFileResult) {
console.info(`${testNum}:: fetchFileResult error:`); console.info(`${testNum}:: fetchFileResult error:`);
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
return false return false;
} }
let count = await fetchFileResult.getCount(); let count = await fetchFileResult.getCount();
if (count != expectCount) { if (count != expectCount) {
...@@ -185,14 +208,14 @@ const checkAssetsCount = async function (done, testNum, fetchFileResult, expectC ...@@ -185,14 +208,14 @@ const checkAssetsCount = async function (done, testNum, fetchFileResult, expectC
done(); done();
} }
return count == expectCount; return count == expectCount;
} };
const checkAlbumsCount = function (done, testNum, albumList, expectCount) { const checkAlbumsCount = function (done, testNum, albumList, expectCount) {
if (!Array.isArray(albumList)) { if (!Array.isArray(albumList)) {
console.info(`${testNum}:: albumList error:`); console.info(`${testNum}:: albumList error:`);
expect(false).assertTrue(); expect(false).assertTrue();
done(); done();
return false return false;
} }
let albumsCount = albumList.length; let albumsCount = albumList.length;
if (albumsCount != expectCount) { if (albumsCount != expectCount) {
...@@ -201,45 +224,43 @@ const checkAlbumsCount = function (done, testNum, albumList, expectCount) { ...@@ -201,45 +224,43 @@ const checkAlbumsCount = function (done, testNum, albumList, expectCount) {
done(); done();
} }
return albumsCount == expectCount; return albumsCount == expectCount;
} };
const getPermission = async function (name) { const getPermission = async function (name, context) {
if (!name) { if (!name) {
name = "ohos.acts.multimedia.mediaLibrary"; 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 appInfo = await bundle.getApplicationInfo(name, 0, 100);
let tokenID = appInfo.accessTokenId; let tokenID = appInfo.accessTokenId;
let atManager = abilityAccessCtrl.createAtManager(); 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 isGranted1 = await atManager.verifyAccessToken(tokenID, "ohos.permission.MEDIA_LOCATION");
let isGranted2 = await atManager.verifyAccessToken(tokenID, "ohos.permission.READ_MEDIA"); let isGranted2 = await atManager.verifyAccessToken(tokenID, "ohos.permission.READ_MEDIA");
let isGranted3 = await atManager.verifyAccessToken(tokenID, "ohos.permission.WRITE_MEDIA"); let isGranted3 = await atManager.verifyAccessToken(tokenID, "ohos.permission.WRITE_MEDIA");
if (!(isGranted1 == 0 && isGranted2 == 0 && isGranted3 == 0)) { 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) { const isNum = function (value) {
return typeof value === 'number' && !isNaN(value); return typeof value === "number" && !isNaN(value);
} };
export { export {
getPermission, getPermission,
IMAGE_TYPE, IMAGE_TYPE,
......
{ {
"app":{ "app": {
"bundleName":"ohos.acts.multimedia.mediaLibrary", "bundleName": "ohos.acts.multimedia.mediaLibrary",
"vendor":"huawei", "vendor": "huawei",
"versionCode":1000000, "versionCode": 1000000,
"versionName":"1.0.0", "versionName": "1.0.0",
"debug":false, "debug": false,
"icon":"$media:icon", "icon": "$media:icon",
"label":"$string:entry_MainAbility", "label": "$string:app_name",
"description":"$string:mainability_description", "description": "$string:description_application",
"distributedNotificationEnabled":true, "distributedNotificationEnabled": true,
"keepAlive":true, "keepAlive": true,
"singleUser":true, "singleUser": true,
"minAPIVersion":8, "minAPIVersion": 9,
"targetAPIVersion":8, "targetAPIVersion": 9,
"car":{ "car": {
"apiCompatibleVersion":8, "apiCompatibleVersion": 9,
"singleUser":false "singleUser": false
} }
} }
} }
\ No newline at end of file
{ {
"string": [ "string":[
{ {
"name": "entry_MainAbility", "name":"app_name",
"value": "MediaLibraryJSTestMain" "value":"ohosProject"
},
{
"name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability"
} }
] ]
} }
\ No newline at end of file
...@@ -15,6 +15,7 @@ import("//test/xts/tools/build/suite.gni") ...@@ -15,6 +15,7 @@ import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("mediaLibrary_album_hap") { ohos_js_hap_suite("mediaLibrary_album_hap") {
hap_profile = "entry/src/main/module.json" hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [ deps = [
":mediaLibrary_js_assets", ":mediaLibrary_js_assets",
":mediaLibrary_resources", ":mediaLibrary_resources",
......
{ {
"description": "Configuration for mediaLibrary Tests", "description": "Configuration for mediaLibrary Tests",
"driver": { "driver": {
"type": "JSUnitTest", "type": "OHJSUnitTest",
"test-timeout": "300000", "test-timeout": "180000",
"package": "ohos.acts.multimedia.mediaLibrary", "bundle-name": "ohos.acts.multimedia.mediaLibrary",
"shell-timeout": "600000" "module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
}, },
"kits": [ "kits": [
{ {
"type": "ShellKit", "type": "ShellKit",
"pre-push": [ "pre-push": [],
],
"run-command": [ "run-command": [
"rm -rf /storage/media/100/local/files/*", "rm -rf /storage/media/100/local/files/*",
"rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*", "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*",
"mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios}", "mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios}",
"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"
] ]
}, },
{ {
"type": "PushKit", "type": "PushKit",
"pre-push": [ "pre-push": [],
],
"push": [ "push": [
"./resource/medialibrary/01.jpg ->/storage/media/100/local/temp", "./resource/medialibrary/01.jpg ->/storage/media/100/local/temp",
"./resource/medialibrary/01.mp3 ->/storage/media/100/local/temp", "./resource/medialibrary/01.mp3 ->/storage/media/100/local/temp",
...@@ -36,13 +39,10 @@ ...@@ -36,13 +39,10 @@
"mkdir -pv /storage/media/100/local/files/Audios/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/DynamicPro$$i; done;",
"for i in $$(seq 6); do mkdir -pv /storage/media/100/local/files/Pictures/DynamicCb$$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.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.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 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;", "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 /storage/media/100/local/files/*",
"chmod -R 777 /data/service/el2/100/hmdfs/account/files/*", "chmod -R 777 /data/service/el2/100/hmdfs/account/files/*",
"hilog -Q pidoff", "hilog -Q pidoff",
...@@ -52,8 +52,9 @@ ...@@ -52,8 +52,9 @@
"scanner", "scanner",
"sleep 10" "sleep 10"
], ],
"teardown-command":[ "teardown-command": [
"hilog -b X -D 0xD002B70" "hilog -b X -D 0xD002B70",
"power-shell setmode 600"
] ]
}, },
{ {
......
import Ability from '@ohos.app.ability.UIAbility' import Ability from '@ohos.app.ability.UIAbility'
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
onCreate(want,launchParam){ onCreate(want, launchParam) {
// Ability is creating, initialize resources for this ability // Ability is creating, initialize resources for this ability
console.log("[Demo] MainAbility onCreate") console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want; globalThis.abilityWant = want;
...@@ -12,11 +12,11 @@ export default class MainAbility extends Ability { ...@@ -12,11 +12,11 @@ export default class MainAbility extends Ability {
console.log("[Demo] MainAbility onDestroy") 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 windowStage=" + windowStage)
console.log("[Demo] MainAbility onWindowStageCreate") globalThis.windowStage = windowStage
globalThis.abilityContext = this.context globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null) windowStage.setUIContent(this.context, "MainAbility/pages/index/index", null)
} }
onWindowStageDestroy() { onWindowStageDestroy() {
......
...@@ -12,10 +12,11 @@ ...@@ -12,10 +12,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 @Entry
@Component @Component
...@@ -23,24 +24,12 @@ struct Index { ...@@ -23,24 +24,12 @@ struct Index {
aboutToAppear(){ aboutToAppear(){
console.info("start run testcase!!!!") console.info("start run testcase!!!!")
const core = Core.getInstance() var abilityDelegator: any
const expectExtend = new ExpectExtend({ abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
'id': 'extend' var abilityDelegatorArguments: any
}) abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
core.addService('expect', expectExtend) console.info('start run testcase!!!')
const reportExtend = new ReportExtend(file) Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
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() { 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. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -12,20 +12,23 @@ ...@@ -12,20 +12,23 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import router from '@system.router'; import router from '@ohos.router';
@Entry @Entry
@Component @Component
struct Second { struct Index {
private content: string = "Second Page" aboutToAppear() {
console.info('TestAbility index aboutToAppear')
}
@State message: string = 'Hello World'
build() { build() {
Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Row() {
Text(`${this.content}`) Column() {
Text(this.message)
.fontSize(50) .fontSize(50)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button() { Button() {
Text('back to index') Text('next page')
.fontSize(20) .fontSize(20)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) }.type(ButtonType.Capsule)
...@@ -33,11 +36,13 @@ struct Second { ...@@ -33,11 +36,13 @@ struct Second {
top: 20 top: 20
}) })
.backgroundColor('#0D9FFB') .backgroundColor('#0D9FFB')
.onClick(() => { .width('35%')
router.back() .height('5%')
.onClick(()=>{
}) })
} }
.width('100%') .width('100%')
}
.height('100%') .height('100%')
} }
} }
\ No newline at end of file \ 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. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -16,9 +16,9 @@ import albumGetFileAssetsCallbackTest from './albumGetFileAssetsCallback.test.et ...@@ -16,9 +16,9 @@ import albumGetFileAssetsCallbackTest from './albumGetFileAssetsCallback.test.et
import albumGetFileAssetsPromiseTest from './albumGetFileAssetsPromise.test.ets' import albumGetFileAssetsPromiseTest from './albumGetFileAssetsPromise.test.ets'
import albumTestCallBackTest from './albumTestCallBack.test.ets' import albumTestCallBackTest from './albumTestCallBack.test.ets'
import albumTestPromiseTest from './albumTestPromise.test.ets' import albumTestPromiseTest from './albumTestPromise.test.ets'
export default function testsuite(abilityContext) { export default function testsuite() {
albumGetFileAssetsCallbackTest(abilityContext) albumGetFileAssetsCallbackTest(globalThis.abilityContext)
albumGetFileAssetsPromiseTest(abilityContext) albumGetFileAssetsPromiseTest(globalThis.abilityContext)
albumTestPromiseTest(abilityContext) albumTestPromiseTest(globalThis.abilityContext)
albumTestCallBackTest(abilityContext) albumTestCallBackTest(globalThis.abilityContext)
} }
...@@ -35,7 +35,7 @@ export default function albumGetFileAssetsCallbackTest(abilityContext) { ...@@ -35,7 +35,7 @@ export default function albumGetFileAssetsCallbackTest(abilityContext) {
const media = mediaLibrary.getMediaLibrary(abilityContext); const media = mediaLibrary.getMediaLibrary(abilityContext);
beforeAll(async function () { beforeAll(async function () {
console.info('beforeAll case'); console.info('beforeAll case');
await getPermission(); await getPermission(null, abilityContext);
await checkPresetsAssets(media, 'ActsMediaLibraryAlbumTest'); await checkPresetsAssets(media, 'ActsMediaLibraryAlbumTest');
}); });
beforeEach(function () { beforeEach(function () {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"name": "phone", "name": "phone",
"type": "entry", "type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts", "srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:mainability_description", "description": "$string:phone_entry_dsc",
"mainElement": "MainAbility", "mainElement": "MainAbility",
"deviceTypes": [ "deviceTypes": [
"tablet", "tablet",
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
"pages": "$profile:main_pages", "pages": "$profile:main_pages",
"abilities": [ "abilities": [
{ {
"name": "ohos.acts.multimedia.mediaLibrary.MainAbility", "name": "com.example.myapplication.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts", "srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:mainability_description", "description": "$string:phone_entry_main",
"icon": "$media:icon", "icon": "$media:icon",
"label": "$string:entry_MainAbility", "label": "$string:entry_label",
"visible": true, "visible": true,
"orientation": "portrait", "orientation": "portrait",
"skills": [ "skills": [
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
"actions": [ "actions": [
"action.system.home" "action.system.home"
], ],
"entities":[ "entities": [
"entity.system.home" "entity.system.home"
] ]
} }
...@@ -42,27 +42,27 @@ ...@@ -42,27 +42,27 @@
}, },
{ {
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
"reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" "reason": "use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
}, },
{ {
"name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" "reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
}, },
{ {
"name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", "name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS",
"reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" "reason": "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
}, },
{ {
"name": "ohos.permission.MEDIA_LOCATION", "name": "ohos.permission.MEDIA_LOCATION",
"reason":"use ohos.permission.MEDIA_LOCATION" "reason": "use ohos.permission.MEDIA_LOCATION"
}, },
{ {
"name": "ohos.permission.READ_MEDIA", "name": "ohos.permission.READ_MEDIA",
"reason":"use ohos.permission.READ_MEDIA" "reason": "use ohos.permission.READ_MEDIA"
}, },
{ {
"name": "ohos.permission.WRITE_MEDIA", "name": "ohos.permission.WRITE_MEDIA",
"reason":"use ohos.permission.WRITE_MEDIA" "reason": "use ohos.permission.WRITE_MEDIA"
} }
] ]
} }
......
{ {
"string": [ "string": [
{ {
"name": "entry_MainAbility", "name": "phone_entry_dsc",
"value": "MediaLibraryJSTestMain" "value": "i am an entry for phone"
}, },
{ {
"name": "mainability_description", "name": "phone_entry_main",
"value": "MediaLibraryJSTestMain Ability" "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 \ No newline at end of file
{ {
"src": [ "src": [
"pages/index/index", "MainAbility/pages/index/index"
"pages/second/second"
] ]
} }
\ No newline at end of file
{ {
"app":{ "app": {
"bundleName":"ohos.acts.multimedia.mediaLibrary", "bundleName": "ohos.acts.multimedia.mediaLibrary",
"vendor":"huawei", "vendor": "huawei",
"versionCode":1000000, "versionCode": 1000000,
"versionName":"1.0.0", "versionName": "1.0.0",
"debug":false, "debug": false,
"icon":"$media:icon", "icon": "$media:icon",
"label":"$string:entry_MainAbility", "label": "$string:app_name",
"description":"$string:mainability_description", "description": "$string:description_application",
"distributedNotificationEnabled":true, "distributedNotificationEnabled": true,
"keepAlive":true, "keepAlive": true,
"singleUser":true, "singleUser": true,
"minAPIVersion":8, "minAPIVersion": 9,
"targetAPIVersion":8, "targetAPIVersion": 9,
"car":{ "car": {
"apiCompatibleVersion":8, "apiCompatibleVersion": 9,
"singleUser":false "singleUser": false
} }
} }
} }
\ No newline at end of file
{ {
"string": [ "string":[
{ {
"name": "entry_MainAbility", "name":"app_name",
"value": "MediaLibraryJSTestMain" "value":"ohosProject"
},
{
"name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability"
} }
] ]
} }
\ No newline at end of file
...@@ -15,6 +15,7 @@ import("//test/xts/tools/build/suite.gni") ...@@ -15,6 +15,7 @@ import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("mediaLibrary_base_hap") { ohos_js_hap_suite("mediaLibrary_base_hap") {
hap_profile = "entry/src/main/module.json" hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [ deps = [
":mediaLibrary_js_assets", ":mediaLibrary_js_assets",
":mediaLibrary_resources", ":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 @@ ...@@ -12,10 +12,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 @Entry
@Component @Component
...@@ -23,24 +24,12 @@ struct Index { ...@@ -23,24 +24,12 @@ struct Index {
aboutToAppear(){ aboutToAppear(){
console.info("start run testcase!!!!") console.info("start run testcase!!!!")
const core = Core.getInstance() var abilityDelegator: any
const expectExtend = new ExpectExtend({ abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
'id': 'extend' var abilityDelegatorArguments: any
}) abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
core.addService('expect', expectExtend) console.info('start run testcase!!!')
const reportExtend = new ReportExtend(file) Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
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() { build() {
......
{ {
"description": "Configuration for mediaLibrary Tests", "description": "Configuration for mediaLibrary Tests",
"driver": { "driver": {
"type": "JSUnitTest", "type": "OHJSUnitTest",
"test-timeout": "300000", "test-timeout": "180000",
"package": "ohos.acts.multimedia.mediaLibrary", "bundle-name": "ohos.acts.multimedia.mediaLibrary",
"shell-timeout": "600000" "module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
}, },
"kits": [ "kits": [
{ {
...@@ -14,7 +16,10 @@ ...@@ -14,7 +16,10 @@
"rm -rf /storage/media/100/local/files/*", "rm -rf /storage/media/100/local/files/*",
"rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*", "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*",
"mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}", "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 @@ ...@@ -47,8 +52,9 @@
"scanner", "scanner",
"sleep 10" "sleep 10"
], ],
"teardown-command":[ "teardown-command": [
"hilog -b X -D 0xD002B70" "hilog -b X -D 0xD002B70",
"power-shell setmode 600"
] ]
}, },
{ {
......
import Ability from '@ohos.app.ability.UIAbility' 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 { export default class MainAbility extends Ability {
onCreate(want,launchParam){ onCreate(want, launchParam) {
// Ability is creating, initialize resources for this ability // Ability is creating, initialize resources for this ability
console.log("[Demo] MainAbility onCreate") console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want; globalThis.abilityWant = want;
...@@ -12,11 +25,47 @@ export default class MainAbility extends Ability { ...@@ -12,11 +25,47 @@ export default class MainAbility extends Ability {
console.log("[Demo] MainAbility onDestroy") console.log("[Demo] MainAbility onDestroy")
} }
onWindowStageCreate(windowStage) { async onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability // 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 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() { onWindowStageDestroy() {
......
...@@ -12,10 +12,11 @@ ...@@ -12,10 +12,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 @Entry
@Component @Component
...@@ -23,24 +24,14 @@ struct Index { ...@@ -23,24 +24,14 @@ struct Index {
aboutToAppear(){ aboutToAppear(){
console.info("start run testcase!!!!") console.info("start run testcase!!!!")
const core = Core.getInstance() console.info("getPermission 5");
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
const reportExtend = new ReportExtend(file)
core.addService('report', reportExtend) var abilityDelegator: any
core.init() abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
core.subscribeEvent('task', reportExtend) var abilityDelegatorArguments: any
const configService = core.getDefaultService('config') abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) console.info('start run testcase!!!')
globalThis.abilityWant.parameters.timeout = 70000; Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
configService.setConfig(globalThis.abilityWant.parameters)
console.info('testsuite()---->')
testsuite(globalThis.abilityContext)
core.execute()
console.info('core.execute()---->')
} }
build() { 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. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -12,20 +12,23 @@ ...@@ -12,20 +12,23 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import router from '@system.router'; import router from '@ohos.router';
@Entry @Entry
@Component @Component
struct Second { struct Index {
private content: string = "Second Page" aboutToAppear() {
console.info('TestAbility index aboutToAppear')
}
@State message: string = 'Hello World'
build() { build() {
Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Row() {
Text(`${this.content}`) Column() {
Text(this.message)
.fontSize(50) .fontSize(50)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button() { Button() {
Text('back to index') Text('next page')
.fontSize(20) .fontSize(20)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) }.type(ButtonType.Capsule)
...@@ -33,11 +36,13 @@ struct Second { ...@@ -33,11 +36,13 @@ struct Second {
top: 20 top: 20
}) })
.backgroundColor('#0D9FFB') .backgroundColor('#0D9FFB')
.onClick(() => { .width('35%')
router.back() .height('5%')
.onClick(()=>{
}) })
} }
.width('100%') .width('100%')
}
.height('100%') .height('100%')
} }
} }
\ No newline at end of file \ 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
...@@ -17,8 +17,8 @@ import mediaLibraryTestCallback from './mediaLibraryTestCallback.test.ets' ...@@ -17,8 +17,8 @@ import mediaLibraryTestCallback from './mediaLibraryTestCallback.test.ets'
import mediaLibraryTestPromise from './mediaLibraryTestPromise.test.ets' import mediaLibraryTestPromise from './mediaLibraryTestPromise.test.ets'
import mediaLibraryTestPromiseOnOffTest from './mediaLibraryTestPromiseOnOff.test.ets' import mediaLibraryTestPromiseOnOffTest from './mediaLibraryTestPromiseOnOff.test.ets'
export default function testsuite(abilityContext) { export default function testsuite() {
mediaLibraryTestCallback(abilityContext) mediaLibraryTestCallback(globalThis.abilityContext)
mediaLibraryTestPromise(abilityContext) mediaLibraryTestPromise(globalThis.abilityContext)
mediaLibraryTestPromiseOnOffTest(abilityContext) mediaLibraryTestPromiseOnOffTest(globalThis.abilityContext)
} }
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"name": "phone", "name": "phone",
"type": "entry", "type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts", "srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:mainability_description", "description": "$string:phone_entry_dsc",
"mainElement": "MainAbility", "mainElement": "MainAbility",
"deviceTypes": [ "deviceTypes": [
"tablet", "tablet",
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
"pages": "$profile:main_pages", "pages": "$profile:main_pages",
"abilities": [ "abilities": [
{ {
"name": "ohos.acts.multimedia.mediaLibrary.MainAbility", "name": "com.example.myapplication.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts", "srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:mainability_description", "description": "$string:phone_entry_main",
"icon": "$media:icon", "icon": "$media:icon",
"label": "$string:entry_MainAbility", "label": "$string:entry_label",
"visible": true, "visible": true,
"orientation": "portrait", "orientation": "portrait",
"skills": [ "skills": [
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
"actions": [ "actions": [
"action.system.home" "action.system.home"
], ],
"entities":[ "entities": [
"entity.system.home" "entity.system.home"
] ]
} }
...@@ -42,27 +42,27 @@ ...@@ -42,27 +42,27 @@
}, },
{ {
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
"reason":"use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" "reason": "use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
}, },
{ {
"name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" "reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
}, },
{ {
"name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", "name": "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS",
"reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" "reason": "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
}, },
{ {
"name": "ohos.permission.MEDIA_LOCATION", "name": "ohos.permission.MEDIA_LOCATION",
"reason":"use ohos.permission.MEDIA_LOCATION" "reason": "use ohos.permission.MEDIA_LOCATION"
}, },
{ {
"name": "ohos.permission.READ_MEDIA", "name": "ohos.permission.READ_MEDIA",
"reason":"use ohos.permission.READ_MEDIA" "reason": "use ohos.permission.READ_MEDIA"
}, },
{ {
"name": "ohos.permission.WRITE_MEDIA", "name": "ohos.permission.WRITE_MEDIA",
"reason":"use ohos.permission.WRITE_MEDIA" "reason": "use ohos.permission.WRITE_MEDIA"
} }
] ]
} }
......
{ {
"string": [ "string": [
{ {
"name": "entry_MainAbility", "name": "phone_entry_dsc",
"value": "MediaLibraryJSTestMain" "value": "i am an entry for phone"
}, },
{ {
"name": "mainability_description", "name": "phone_entry_main",
"value": "MediaLibraryJSTestMain Ability" "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 \ No newline at end of file
{ {
"src": [ "src": [
"pages/index/index", "MainAbility/pages/index/index"
"pages/second/second"
] ]
} }
\ No newline at end of file
{ {
"app":{ "app": {
"bundleName":"ohos.acts.multimedia.mediaLibrary", "bundleName": "ohos.acts.multimedia.mediaLibrary",
"vendor":"huawei", "vendor": "huawei",
"versionCode":1000000, "versionCode": 1000000,
"versionName":"1.0.0", "versionName": "1.0.0",
"debug":false, "debug": false,
"icon":"$media:icon", "icon": "$media:icon",
"label":"$string:entry_MainAbility", "label": "$string:app_name",
"description":"$string:mainability_description", "description": "$string:description_application",
"distributedNotificationEnabled":true, "distributedNotificationEnabled": true,
"keepAlive":true, "keepAlive": true,
"singleUser":true, "singleUser": true,
"minAPIVersion":8, "minAPIVersion": 9,
"targetAPIVersion":8, "targetAPIVersion": 9,
"car":{ "car": {
"apiCompatibleVersion":8, "apiCompatibleVersion": 9,
"singleUser":false "singleUser": false
} }
} }
} }
\ No newline at end of file
{ {
"string": [ "string":[
{ {
"name": "entry_MainAbility", "name":"app_name",
"value": "MediaLibraryJSTestMain" "value":"ohosProject"
},
{
"name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability"
} }
] ]
} }
\ No newline at end of file
...@@ -15,6 +15,7 @@ import("//test/xts/tools/build/suite.gni") ...@@ -15,6 +15,7 @@ import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("mediaLibrary_favorite_hap") { ohos_js_hap_suite("mediaLibrary_favorite_hap") {
hap_profile = "entry/src/main/module.json" hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [ deps = [
":mediaLibrary_js_assets", ":mediaLibrary_js_assets",
":mediaLibrary_resources", ":mediaLibrary_resources",
......
{ {
"description": "Configuration for mediaLibrary Tests", "description": "Configuration for mediaLibrary Tests",
"driver": { "driver": {
"type": "JSUnitTest", "type": "OHJSUnitTest",
"test-timeout": "300000", "test-timeout": "180000",
"package": "ohos.acts.multimedia.mediaLibrary", "bundle-name": "ohos.acts.multimedia.mediaLibrary",
"shell-timeout": "600000" "module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
}, },
"kits": [ "kits": [
{ {
...@@ -14,7 +16,10 @@ ...@@ -14,7 +16,10 @@
"rm -rf /storage/media/100/local/files/*", "rm -rf /storage/media/100/local/files/*",
"rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*", "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/*",
"mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}", "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 @@ ...@@ -47,8 +52,9 @@
"scanner", "scanner",
"sleep 10" "sleep 10"
], ],
"teardown-command":[ "teardown-command": [
"hilog -b X -D 0xD002B70" "hilog -b X -D 0xD002B70",
"power-shell setmode 600"
] ]
}, },
{ {
......
import Ability from '@ohos.app.ability.UIAbility' import Ability from '@ohos.app.ability.UIAbility'
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
onCreate(want,launchParam){ onCreate(want, launchParam) {
// Ability is creating, initialize resources for this ability // Ability is creating, initialize resources for this ability
console.log("[Demo] MainAbility onCreate") console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want; globalThis.abilityWant = want;
...@@ -12,11 +12,11 @@ export default class MainAbility extends Ability { ...@@ -12,11 +12,11 @@ export default class MainAbility extends Ability {
console.log("[Demo] MainAbility onDestroy") 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 windowStage=" + windowStage)
console.log("[Demo] MainAbility onWindowStageCreate") globalThis.windowStage = windowStage
globalThis.abilityContext = this.context globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null) windowStage.setUIContent(this.context, "MainAbility/pages/index/index", null)
} }
onWindowStageDestroy() { onWindowStageDestroy() {
......
...@@ -12,36 +12,24 @@ ...@@ -12,36 +12,24 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 @Entry
@Component @Component
struct Index { struct Index {
aboutToAppear(){ aboutToAppear(){
console.info("start run testcase!!!!") console.info("start run testcase!!!!")
const core = Core.getInstance() var abilityDelegator: any
const expectExtend = new ExpectExtend({ abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
'id': 'extend' var abilityDelegatorArguments: any
}) abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
core.addService('expect', expectExtend) console.info('start run testcase!!!')
const reportExtend = new ReportExtend(file) Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
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() { 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. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -12,20 +12,23 @@ ...@@ -12,20 +12,23 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import router from '@system.router'; import router from '@ohos.router';
@Entry @Entry
@Component @Component
struct Second { struct Index {
private content: string = "Second Page" aboutToAppear() {
console.info('TestAbility index aboutToAppear')
}
@State message: string = 'Hello World'
build() { build() {
Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Row() {
Text(`${this.content}`) Column() {
Text(this.message)
.fontSize(50) .fontSize(50)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button() { Button() {
Text('back to index') Text('next page')
.fontSize(20) .fontSize(20)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) }.type(ButtonType.Capsule)
...@@ -33,11 +36,13 @@ struct Second { ...@@ -33,11 +36,13 @@ struct Second {
top: 20 top: 20
}) })
.backgroundColor('#0D9FFB') .backgroundColor('#0D9FFB')
.onClick(() => { .width('35%')
router.back() .height('5%')
.onClick(()=>{
}) })
} }
.width('100%') .width('100%')
}
.height('100%') .height('100%')
} }
} }
\ No newline at end of file \ 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
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册