提交 2665dd5e 编写于 作者: C caochuan

add trash test

Signed-off-by: Ncaochuan <caochuan@huawei.com>
上级 b510db8c
...@@ -51,6 +51,7 @@ group("multimedia") { ...@@ -51,6 +51,7 @@ group("multimedia") {
"medialibrary/mediaLibrary_fileResult:mediaLibrary_fileResult_hap", "medialibrary/mediaLibrary_fileResult:mediaLibrary_fileResult_hap",
"medialibrary/mediaLibrary_getThumbnail:mediaLibrary_getThumbnail_hap", "medialibrary/mediaLibrary_getThumbnail:mediaLibrary_getThumbnail_hap",
"medialibrary/mediaLibrary_mediafetchoptions:mediaLibrary_mediafetchoptions_hap", "medialibrary/mediaLibrary_mediafetchoptions:mediaLibrary_mediafetchoptions_hap",
"medialibrary/mediaLibrary_trash:mediaLibrary_trash_js_hap",
] ]
} else { } else {
deps = [ deps = [
......
/*
* 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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import featureAbility from '@ohos.ability.featureAbility';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
} from '../../../../../../common';
describe('file.callback.test.js', function () {
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT');
beforeAll(function () {
console.info('File Callback MediaLibraryTest: beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.');
});
beforeEach(function () {
console.info('File Callback MediaLibraryTest: beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.');
});
afterEach(async function () { await sleep(200)});
afterAll(function () {
console.info('File Callback MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed');
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_01
* @tc.name : favorite
* @tc.desc : favorite by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_01', 0, async function (done) {
const asset = await media.createAsset(mediaType, 'image01.jpg', path);
asset.favorite(true, (err) => {
if (err == undefined) {
console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_01 success');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_01 fail, message = ' + err);
expect(false).assertTrue();
done();
}
});
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_02
* @tc.name : favorite
* @tc.desc : favorite by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_02', 0, async function (done) {
const asset = await media.createAsset(mediaType, 'image02.jpg', path);
asset.favorite(false, (err) => {
if (err == undefined) {
console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_02 success');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_02 fail, message = ' + err);
expect(false).assertTrue();
done();
}
});
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_03
* @tc.name : favorite
* @tc.desc : favorite by 666
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_03', 0, async function (done) {
const asset = await media.createAsset(mediaType, 'image03.jpg', path);
asset.favorite(666, (err) => {
if (err == undefined) {
console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_03 success');
expect(false).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_03 fail, message = ' + err);
expect(true).assertTrue();
done();
}
});
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_04
* @tc.name : favorite
* @tc.desc : favorite by '666'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_04', 0, async function (done) {
const asset = await media.createAsset(mediaType, 'image04.jpg', path);
asset.favorite('666', (err) => {
if (err == undefined) {
console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_04 success');
expect(false).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_04 fail, message = ' + err);
expect(true).assertTrue();
done();
}
});
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_05
* @tc.name : favorite
* @tc.desc : favorite by 0.666
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_05', 0, async function (done) {
const asset = await media.createAsset(mediaType, 'image05.jpg', path);
asset.favorite(0.666, (err) => {
if (err == undefined) {
console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_05 success');
expect(false).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_05 fail, message = ' + err);
expect(true).assertTrue();
done();
}
});
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_06
* @tc.name : favorite
* @tc.desc : favorite by null
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_CALLBACK_007_06', 0, async function (done) {
const asset = await media.createAsset(mediaType, 'image06.jpg', path);
asset.favorite(null, (err) => {
if (err == undefined) {
console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_06 success');
expect(false).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_CALLBACK favorite 007_06 fail, message = ' + err);
expect(true).assertTrue();
done();
}
});
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_CALLBACK_008_01
* @tc.name : isFavorite
* @tc.desc : Is Favourite true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_CALLBACK_008_01', 0, async function (done) {
const asset = await media.createAsset(mediaType, 'image07.jpg', path);
await asset.favorite(true);
asset.isFavorite((err, isFavorite) => {
if (err == undefined && isFavorite == true) {
console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite 008_01 isFavorite = ' + isFavorite);
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite 008_01 fail, message = ' + err);
expect(false).assertTrue();
done();
}
});
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_CALLBACK_008_02
* @tc.name : isFavorite
* @tc.desc : Is Favourite true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_CALLBACK_008_02', 0, async function (done) {
const asset = await media.createAsset(mediaType, 'image0702.jpg', path);
await asset.favorite(false);
asset.isFavorite((err, isFavorite) => {
if (err == undefined && isFavorite == false) {
console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite 008_02 isFavorite = ' + isFavorite);
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_CALLBACK isFavorite 008_02 fail, message = ' + err);
expect(false).assertTrue();
done();
}
});
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_01
* @tc.name : trash
* @tc.desc : Trash by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_01', 0, async function (done) {
const asset = await media.createAsset(mediaType, 'image08.jpg', path);
asset.trash(true, (err) => {
if (err == undefined) {
console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_01');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_01 fail ,message = ', err);
expect(false).assertTrue();
done();
}
});
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_02
* @tc.name : trash
* @tc.desc : Trash by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_02', 0, async function (done) {
const asset = await media.createAsset(mediaType, 'image09.jpg', path);
asset.trash(false, (err) => {
if (err == undefined) {
console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_02');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_02 fail ,message = ', err);
expect(false).assertTrue();
done();
}
});
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_03
* @tc.name : trash
* @tc.desc : Trash by 666
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_03', 0, async function (done) {
const asset = await media.createAsset(mediaType, 'image10.jpg', path);
asset.trash(666, (err) => {
if (err == undefined) {
console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_03');
expect(false).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_03 fail ,message = ', err);
expect(true).assertTrue();
done();
}
});
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_04
* @tc.name : trash
* @tc.desc : Trash by '666'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_04', 0, async function (done) {
const asset = await media.createAsset(mediaType, 'image11.jpg', path);
asset.trash('666', (err) => {
if (err == undefined) {
console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_04');
expect(false).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_04 fail ,message = ', err);
expect(true).assertTrue();
done();
}
});
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_05
* @tc.name : trash
* @tc.desc : Trash by 0.666
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_05', 0, async function (done) {
const asset = await media.createAsset(mediaType, 'image12.jpg', path);
asset.trash(0.666, (err) => {
if (err == undefined) {
console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_05');
expect(false).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_05 fail ,message = ', err);
expect(true).assertTrue();
done();
}
});
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_06
* @tc.name : trash
* @tc.desc : Trash by null
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_CALLBACK_009_06', 0, async function (done) {
const asset = await media.createAsset(mediaType, 'image13.jpg', path);
asset.trash(null, (err) => {
if (err == undefined) {
console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_06');
expect(false).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_CALLBACK trash 009_06 fail ,message = ', err);
expect(true).assertTrue();
done();
}
});
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_CALLBACK_0010_01
* @tc.name : isTrash
* @tc.desc : isTrash true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_CALLBACK_0010_01', 0, async function (done) {
const asset = await media.createAsset(mediaType, 'image14.jpg', path);
await asset.trash(true);
asset.isTrash((err, isTrash) => {
if (err == undefined && isTrash == true) {
console.info('MediaLibraryTest : ASSET_CALLBACK trash 0010_01');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_CALLBACK trash 0010_01 fail ,message = ', err);
expect(false).assertTrue();
done();
}
});
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_CALLBACK_0010_02
* @tc.name : isTrash
* @tc.desc : isTrash false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_CALLBACK_0010_02', 0, async function (done) {
const asset = await media.createAsset(mediaType, 'image15.jpg', path);
await asset.trash(false);
asset.isTrash((err, isTrash) => {
if (err == undefined && isTrash == false) {
console.info('MediaLibraryTest : ASSET_CALLBACK trash 0010_02');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_CALLBACK trash 0010_02 fail ,message = ', err);
expect(false).assertTrue();
done();
}
});
});
});
/*
* 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 mediaLibrary from '@ohos.multimedia.mediaLibrary';
import featureAbility from '@ohos.ability.featureAbility';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
import {
sleep,
} from '../../../../../../common';
describe('file.promise.test.js', function () {
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT');
beforeAll(function () {
console.info('File Promise MediaLibraryTest: beforeAll : Prerequisites at the test suite level, which are executed before the test suite is executed.');
});
beforeEach(function () {
console.info('File Promise MediaLibraryTest: beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.');
});
afterEach(async function () { await sleep(200)});
afterAll(function () {
console.info('File Promise MediaLibraryTest: afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed');
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_01
* @tc.name : favorite
* @tc.desc : favorite by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_01', 0, async function (done) {
try {
const asset = await media.createAsset(mediaType, 'image01.jpg', path);
await asset.favorite(true);
console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_01 success');
expect(true).assertTrue();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE close 007_01 fail, message = ' + error);
expect(false).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_02
* @tc.name : favorite
* @tc.desc : favorite by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_02', 0, async function (done) {
try {
const asset = await media.createAsset(mediaType, 'image02.jpg', path);
await asset.favorite(false);
console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_02 success');
expect(true).assertTrue();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE close 007_02 fail, message = ' + error);
expect(false).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_03
* @tc.name : favorite
* @tc.desc : favorite by 666
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_03', 0, async function (done) {
try {
const asset = await media.createAsset(mediaType, 'image03.jpg', path);
await asset.favorite(666);
console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_03 success');
expect(false).assertTrue();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE close 007_03 fail, message = ' + error);
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_04
* @tc.name : favorite
* @tc.desc : favorite by '666'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_04', 0, async function (done) {
try {
const asset = await media.createAsset(mediaType, 'image04.jpg', path);
await asset.favorite('666');
console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_04 success');
expect(false).assertTrue();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE close 007_04 fail, message = ' + error);
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_05
* @tc.name : favorite
* @tc.desc : favorite by 0.666
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_05', 0, async function (done) {
try {
const asset = await media.createAsset(mediaType, 'image05.jpg', path);
await asset.favorite(0.666);
console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_05 success');
expect(false).assertTrue();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE close 007_05 fail, message = ' + error);
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_06
* @tc.name : favorite
* @tc.desc : favorite by null
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_FAV_ASSET_PROMISE_007_06', 0, async function (done) {
try {
const asset = await media.createAsset(mediaType, 'image06.jpg', path);
await asset.favorite();
console.info('MediaLibraryTest : ASSET_PROMISE favorite 007_06 success');
expect(false).assertTrue();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE close 007_06 fail, message = ' + error);
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_01
* @tc.name : isFavorite
* @tc.desc : Is Favourite
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_01', 0, async function (done) {
try {
const asset = await media.createAsset(mediaType, 'image07.jpg', path);
await asset.favorite(true);
let isFavorite = await asset.isFavorite();
if (isFavorite == true) {
console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite);
expect(true).assertTrue();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite);
expect(true).assertTrue();
}
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE isFavorite fail, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_02
* @tc.name : isFavorite
* @tc.desc : Is Favourite
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ISFAV_ASSET_PROMISE_008_02', 0, async function (done) {
try {
const asset = await media.createAsset(mediaType, 'image0702.jpg', path);
await asset.favorite(false);
let isFavorite = await asset.isFavorite();
if (isFavorite == false) {
console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite);
expect(true).assertTrue();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE isFavorite = ' + isFavorite);
expect(true).assertTrue();
}
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE isFavorite fail, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_01
* @tc.name : trash
* @tc.desc : Trash by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_01', 0, async function (done) {
try {
const asset = await media.createAsset(mediaType, 'image08.jpg', path);
await asset.trash(true);
console.info('MediaLibraryTest : ASSET_PROMISE trash 009_01');
expect(true).assertTrue();
done();
} catch (trashError) {
console.info('MediaLibraryTest : ASSET_PROMISE trash 009_01 fail ,message = ', trashError);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_02
* @tc.name : trash
* @tc.desc : Trash by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_02', 0, async function (done) {
try {
const asset = await media.createAsset(mediaType, 'image09.jpg', path);
await asset.trash(false);
console.info('MediaLibraryTest : ASSET_PROMISE trash 009_02');
expect(true).assertTrue();
done();
} catch (trashError) {
console.info('MediaLibraryTest : ASSET_PROMISE trash 009_02 fail ,message = ', trashError);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_03
* @tc.name : trash
* @tc.desc : Trash by 666
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_03', 0, async function (done) {
try {
const asset = await media.createAsset(mediaType, 'image10.jpg', path);
await asset.trash(666);
console.info('MediaLibraryTest : ASSET_PROMISE trash 009_03');
expect(false).assertTrue();
done();
} catch (trashError) {
console.info('MediaLibraryTest : ASSET_PROMISE trash 009_03 fail ,message = ' + trashError);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_04
* @tc.name : trash
* @tc.desc : Trash by '666'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_04', 0, async function (done) {
try {
const asset = await media.createAsset(mediaType, 'image11.jpg', path);
await asset.trash('666');
console.info('MediaLibraryTest : ASSET_PROMISE trash 009_04');
expect(false).assertTrue();
done();
} catch (trashError) {
console.info('MediaLibraryTest : ASSET_PROMISE trash 009_04 fail ,message = ' + trashError);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_05
* @tc.name : trash
* @tc.desc : Trash by 0.666
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_05', 0, async function (done) {
try {
const asset = await media.createAsset(mediaType, 'image12.jpg', path);
await asset.trash(0.666);
console.info('MediaLibraryTest : ASSET_PROMISE trash 009_05');
expect(false).assertTrue();
done();
} catch (trashError) {
console.info('MediaLibraryTest : ASSET_PROMISE trash 009_05 fail ,message = ' + trashError);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_06
* @tc.name : trash
* @tc.desc : Trash by null
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_TRA_ASSET_PROMISE_009_06', 0, async function (done) {
try {
const asset = await media.createAsset(mediaType, 'image13.jpg', path);
await asset.trash();
console.info('MediaLibraryTest : ASSET_PROMISE trash 009_06');
expect(false).assertTrue();
done();
} catch (trashError) {
console.info('MediaLibraryTest : ASSET_PROMISE trash 009_06 fail ,message = ' + trashError);
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010_01
* @tc.name : isTrash
* @tc.desc : isTrash true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010_01', 0, async function (done) {
try {
const asset = await media.createAsset(mediaType, 'image14.jpg', path);
await asset.trash(true);
let isTrash = await asset.isTrash();
console.info('MediaLibraryTest : ASSET_PROMISE Trash 0010_01 = ' + isTrash);
if (isTrash) {
expect(true).assertTrue();
} else {
expect(false).assertTrue();
}
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE isTrash 0010_01 fail, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010_02
* @tc.name : isTrash
* @tc.desc : isTrash false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ISTRASH_ASSET_PROMISE_0010_02', 0, async function (done) {
try {
const asset = await media.createAsset(mediaType, 'image15.jpg', path);
await asset.trash(false);
let isTrash = await asset.isTrash();
console.info('MediaLibraryTest : ASSET_PROMISE Trash 0010_02 = ' + isTrash);
if (!isTrash) {
expect(true).assertTrue();
} else {
expect(false).assertTrue();
}
done();
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE isTrash 0010_02 fail, message = ' + error);
expect(false).assertTrue();
done();
}
});
});
/*
* 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 { describe, beforeAll,afterAll, it, expect } from 'deccjsunit/index';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import bundle from '@ohos.bundle';
export default function getPermissionTest() {
describe("get_permission", function () {
/**
* @tc.number SUB_DF_GRANT_USER_GRANTED_PERMISSION_0000
* @tc.name grant_user_granted_permission_async_000
* @tc.desc Test grantUserGrantedPermission() interfaces, grant permission.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it("grant_user_granted_permission_async_000", 0, async function (done) {
let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.mediaLibrary', 0, 100);
let tokenID = appInfo.accessTokenId;
let atManager = abilityAccessCtrl.createAtManager();
let result1 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.MEDIA_LOCATION", 1);
let result2 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.READ_MEDIA", 1);
let result3 = await atManager.grantUserGrantedPermission(tokenID, "ohos.permission.WRITE_MEDIA", 1);
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");
expect(result1 == 0 && result2 == 0 && result3 == 0).assertTrue();
expect(isGranted1 == 0 && isGranted2 == 0 && isGranted3 == 0).assertTrue();
done();
});
});
}
\ No newline at end of file
...@@ -30,8 +30,8 @@ import { ...@@ -30,8 +30,8 @@ import {
getPermission, getPermission,
} from '../../../../../../common'; } from '../../../../../../common';
export default function filekeyTestCallbackTest(abilityContext) { export default function mediafetchoptionsCallback(abilityContext) {
describe('filekeyTestCallbackTest', function () { describe('mediafetchoptionsCallback', function () {
const media = mediaLibrary.getMediaLibrary(abilityContext); const media = mediaLibrary.getMediaLibrary(abilityContext);
beforeAll(async function () { beforeAll(async function () {
console.info('beforeAll case'); console.info('beforeAll case');
......
...@@ -30,8 +30,8 @@ import { ...@@ -30,8 +30,8 @@ import {
getPermission, getPermission,
} from '../../../../../../common'; } from '../../../../../../common';
export default function filekeyTestPromiseTest(abilityContext) { export default function mediafetchoptionsPromise(abilityContext) {
describe('filekeyTestPromiseTest', function () { describe('mediafetchoptionsPromise', function () {
const media = mediaLibrary.getMediaLibrary(abilityContext); const media = mediaLibrary.getMediaLibrary(abilityContext);
beforeAll(async function () { beforeAll(async function () {
console.info('beforeAll case'); console.info('beforeAll case');
......
{ {
"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:entry_MainAbility",
"description":"$string:mainability_description", "description":"$string:mainability_description",
"distributedNotificationEnabled":true, "distributedNotificationEnabled":true,
"keepAlive":true, "keepAlive":true,
"singleUser":true, "singleUser":true,
"minAPIVersion":8, "minAPIVersion":8,
"targetAPIVersion":8, "targetAPIVersion":8,
"car":{ "car":{
"apiCompatibleVersion":8, "apiCompatibleVersion":8,
"singleUser":false "singleUser":false
} }
} }
} }
{ {
"string": [ "string": [
{ {
"name": "entry_MainAbility", "name": "entry_MainAbility",
"value": "MediaLibraryJSTestMain" "value": "MediaLibraryJSTestMain"
}, },
{ {
"name": "mainability_description", "name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability" "value": "MediaLibraryJSTestMain Ability"
} }
] ]
} }
\ No newline at end of file
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# 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("//test/xts/tools/build/suite.gni") import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("mediaLibrary_js_hap") { ohos_js_hap_suite("mediaLibrary_trash_js_hap") {
hap_profile = "entry/src/main/module.json" hap_profile = "entry/src/main/module.json"
deps = [ deps = [
":mediaLibrary_js_assets", ":mediaLibrary_js_assets",
...@@ -21,7 +21,7 @@ ohos_js_hap_suite("mediaLibrary_js_hap") { ...@@ -21,7 +21,7 @@ ohos_js_hap_suite("mediaLibrary_js_hap") {
] ]
ets2abc = true ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b" certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsMediaLibraryJsTest" hap_name = "ActsMediaLibraryTrashJsTest"
} }
ohos_app_scope("medialibrary_app_profile") { ohos_app_scope("medialibrary_app_profile") {
......
{ {
"description": "Configuration for mediaLibrary Tests", "description": "Configuration for mediaLibrary Tests",
"driver": { "driver": {
"type": "JSUnitTest", "type": "JSUnitTest",
"test-timeout": "600000", "test-timeout": "300000",
"package": "ohos.acts.multimedia.mediaLibrary", "package": "ohos.acts.multimedia.mediaLibrary",
"shell-timeout": "600000" "shell-timeout": "600000"
}, },
"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/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/*", "rm -rf /data/app/el2/100/database/com.ohos.medialibrary.MediaLibraryDataA/*",
"mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}", "mkdir -pv /storage/media/100/local/files/{Pictures,Videos,Audios,Documents}",
"mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" "mkdir -p /data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA"
] ]
}, },
{ {
"type": "PushKit", "type": "PushKit",
"pre-push": [ "pre-push": [
], ],
"push": [ "push": [
"./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", "./resource/medialibrary/01.jpg ->/data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA",
"./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", "./resource/medialibrary/01.mp3 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA",
"./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata", "./resource/medialibrary/01.mp4 ->/data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA",
"./resource/medialibrary/01.dat ->/data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata" "./resource/medialibrary/01.dat ->/data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA"
] ]
}, },
{ {
"type": "ShellKit", "type": "ShellKit",
"run-command": [ "run-command": [
"mkdir -pv /storage/media/100/local/files/Pictures/{Static,Static01,Album/Static,Dynamic,Dynamic01,Dynamic022,DeleteCb01,AblumInfo,DeletePro01,Dynamic03,Temp}", "mkdir -pv /storage/media/100/local/files/Pictures/{trash,trashCb}",
"mkdir -pv /storage/media/100/local/files/Videos/{Static,Static01,Album/Static,Dynamic,Dynamic01,Dynamic02,DeleteCb01,AblumInfo,DeletePro01,Dynamic03}", "mkdir -pv /storage/media/100/local/files/Videos/{trash,trashCb}",
"mkdir -pv /storage/media/100/local/files/Audios/{Static,Static01,Album/Static,Dynamic,Dynamic01,Dynamic02,DeleteCb01,AblumInfo,DeletePro01,Dynamic03}", "mkdir -pv /storage/media/100/local/files/Audios/{trash,trashCb}",
"mkdir -pv /storage/media/100/local/files/Documents/{Static,Static01,Album/Static,Dynamic,Dynamic01,Dynamic02,DeleteCb01,AblumInfo,DeletePro01}", "mkdir -pv /storage/media/100/local/files/Documents/{trash,trashCb}",
"for d in Static Album/Static Dynamic Dynamic01 Dynamic022 AblumInfo; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in Static Album/Static Dynamic Dynamic01 Dynamic02 AblumInfo; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;", "for d in trash trashCb; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA/01.jpg /storage/media/100/local/files/Pictures/$$d/0$$i.jpg; done;done;",
"for d in Static Album/Static Dynamic Dynamic01 Dynamic02 AblumInfo; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;", "for d in trash trashCb; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA/01.mp3 /storage/media/100/local/files/Audios/$$d/0$$i.mp3; done;done;",
"for d in Static Album/Static Dynamic Dynamic01 Dynamic02 AblumInfo; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.dat /storage/media/100/local/files/Documents/$$d/0$$i.dat; done;done;", "for d in trash trashCb; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA/01.mp4 /storage/media/100/local/files/Videos/$$d/0$$i.mp4; done;done;",
"for d in trash trashCb; do for i in $$(seq 3); do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.MediaLibraryDataA/01.dat /storage/media/100/local/files/Documents/$$d/0$$i.dat; done;done;",
"for d in DeleteCb01 DeletePro01 Static01; do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.jpg /storage/media/100/local/files/Pictures/$$d ;done;",
"for d in DeleteCb01 DeletePro01 Static01; do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp3 /storage/media/100/local/files/Audios/$$d ;done;", "chmod -R 777 /storage/media/100/local/files/*",
"for d in DeleteCb01 DeletePro01 Static01; do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.mp4 /storage/media/100/local/files/Videos/$$d ;done;", "chmod -R 777 /data/service/el2/100/hmdfs/account/files/*",
"for d in DeleteCb01 DeletePro01 Static01; do cp /data/accounts/account_0/appdata/com.ohos.medialibrary.medialibrarydata/01.dat /storage/media/100/local/files/Documents/$$d ;done;", "hilog -Q pidoff",
"hilog -p off",
"chmod -R 777 /storage/media/100/local/files/*", "hilog -b I",
"chmod -R 777 /data/service/el2/100/hmdfs/account/files/*", "hilog -b D -D 0xD002B70",
"hilog -Q pidoff", "scanner_demo",
"hilog -b D -D 0xD002B70", "sleep 10"
"aa start -a com.ohos.photos.MainAbility -b com.ohos.photos", ],
"sleep 10", "teardown-command":[
"cem publish -e usual.event.SCREEN_OFF", "rm -rf /storage/media/100/local/files/*"
"sleep 10" ]
] },
}, {
{ "test-file-name": [
"test-file-name": [ "ActsMediaLibraryTrashJsTest.hap"
"ActsMediaLibraryJsTest.hap" ],
], "type": "AppInstallKit",
"type": "AppInstallKit", "cleanup-apps": true
"cleanup-apps": true }
} ]
] }
}
\ No newline at end of file
import AbilityStage from "@ohos.application.AbilityStage" import AbilityStage from "@ohos.application.AbilityStage"
export default class MyAbilityStage extends AbilityStage { export default class MyAbilityStage extends AbilityStage {
onCreate() { onCreate() {
console.log("[Demo] MyAbilityStage onCreate") console.log("[Demo] MyAbilityStage onCreate")
globalThis.stageOnCreateRun = 1; globalThis.stageOnCreateRun = 1;
globalThis.stageContext = this.context; globalThis.stageContext = this.context;
} }
} }
import Ability from '@ohos.application.Ability' import Ability from '@ohos.application.Ability'
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;
} }
onDestroy() { onDestroy() {
// Ability is destroying, release resources for this ability // Ability is destroying, release resources for this ability
console.log("[Demo] MainAbility onDestroy") console.log("[Demo] MainAbility onDestroy")
} }
onWindowStageCreate(windowStage) { 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") console.log("[Demo] MainAbility onWindowStageCreate")
globalThis.abilityContext = this.context globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null) windowStage.setUIContent(this.context, "pages/index/index", null)
} }
onWindowStageDestroy() { onWindowStageDestroy() {
//Main window is destroyed, release UI related resources //Main window is destroyed, release UI related resources
console.log("[Demo] MainAbility onWindowStageDestroy") console.log("[Demo] MainAbility onWindowStageDestroy")
} }
onForeground() { onForeground() {
// Ability has brought to foreground // Ability has brought to foreground
console.log("[Demo] MainAbility onForeground") console.log("[Demo] MainAbility onForeground")
} }
onBackground() { onBackground() {
// Ability has back to background // Ability has back to background
console.log("[Demo] MainAbility onBackground") console.log("[Demo] MainAbility onBackground")
} }
}; };
\ No newline at end of file
/* /*
* Copyright (c) 2021 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
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* 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 file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index"
import testsuite from "../../test/List.test.ets" 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() const core = Core.getInstance()
const expectExtend = new ExpectExtend({ const expectExtend = new ExpectExtend({
'id': 'extend' 'id': 'extend'
}) })
core.addService('expect', expectExtend) core.addService('expect', expectExtend)
const reportExtend = new ReportExtend(file) const reportExtend = new ReportExtend(file)
core.addService('report', reportExtend) core.addService('report', reportExtend)
core.init() core.init()
core.subscribeEvent('task', reportExtend) core.subscribeEvent('task', reportExtend)
const configService = core.getDefaultService('config') const configService = core.getDefaultService('config')
console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters))
globalThis.abilityWant.parameters.timeout = 70000; globalThis.abilityWant.parameters.timeout = 70000;
configService.setConfig(globalThis.abilityWant.parameters) configService.setConfig(globalThis.abilityWant.parameters)
console.info('testsuite()---->') console.info('testsuite()---->')
testsuite(globalThis.abilityContext) testsuite(globalThis.abilityContext)
core.execute() core.execute()
console.info('core.execute()---->') console.info('core.execute()---->')
} }
build() { build() {
Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World') Text('Hello World')
.fontSize(50) .fontSize(50)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button() { Button() {
Text('next page') Text('next page')
.fontSize(25) .fontSize(25)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) }.type(ButtonType.Capsule)
.margin({ .margin({
top: 20 top: 20
}) })
.backgroundColor('#0D9FFB') .backgroundColor('#0D9FFB')
.onClick(() => { .onClick(() => {
}) })
} }
.width('100%') .width('100%')
.height('100%') .height('100%')
} }
} }
\ No newline at end of file
/* /*
* Copyright (c) 2021 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
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* 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 '@system.router';
@Entry @Entry
@Component @Component
struct Second { struct Second {
private content: string = "Second Page" private content: string = "Second Page"
build() { build() {
Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`) Text(`${this.content}`)
.fontSize(50) .fontSize(50)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button() { Button() {
Text('back to index') Text('back to index')
.fontSize(20) .fontSize(20)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) }.type(ButtonType.Capsule)
.margin({ .margin({
top: 20 top: 20
}) })
.backgroundColor('#0D9FFB') .backgroundColor('#0D9FFB')
.onClick(() => { .onClick(() => {
router.back() router.back()
}) })
} }
.width('100%') .width('100%')
.height('100%') .height('100%')
} }
} }
\ No newline at end of file
/* /*
* Copyright (c) 2021 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
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* 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 getPermissionTest from './getPermission.test.ets' import trashPromise from './trashPromise.test.ets'
import trashCallback from './trashCallback.test.ets'
export default function testsuite(abilityContext) { export default function testsuite(abilityContext) {
getPermissionTest() trashCallback(abilityContext)
} trashPromise(abilityContext)
}
\ 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 mediaLibrary from "@ohos.multimedia.mediaLibrary";
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "deccjsunit/index";
import {
sleep,
IMAGE_TYPE,
AUDIO_TYPE,
VIDEO_TYPE,
FILE_TYPE,
fetchOps,
getPermission,
albumFetchOps,
fileIdFetchOps,
} from "../../../../../../common";
export default function trashCallback(abilityContext) {
describe("trashCallback", function () {
beforeAll(async function () {
await getPermission();
console.info("beforeAll case");
});
beforeEach(function () {
console.info("beforeEach case");
});
afterEach(async function () {
console.info("afterEach case");
await sleep;
});
afterAll(async function () {
console.info("afterAll case");
});
const media = mediaLibrary.getMediaLibrary(abilityContext);
async function setTrash(done, testNum, databasefFetchOps, ablumFetchOps, noAlbum) {
try {
// database info
let databaseFetchFileResult = await media.getFileAssets(databasefFetchOps);
let count = databaseFetchFileResult.getCount();
//album info
if (!noAlbum) {
let albumList = await media.getAlbums(ablumFetchOps);
let album = albumList[0];
let albumFetchFileResult = await album.getFileAssets();
let albumFilesCount = albumFetchFileResult.getCount();
expect(albumFilesCount).assertEqual(count);
}
// file info
let asset = await databaseFetchFileResult.getFirstObject();
let id = asset.id;
let istrash = await asset.isTrash();
expect(istrash).assertFalse();
// trash operation
asset.trash(true, async (err) => {
if (err) {
console.info(`${testNum} err: ${err}`);
expect(false).assertTrue();
done();
return;
}
asset.isTrash(async (err, trashState) => {
if (err) {
console.info(`${testNum} err: ${err}`);
expect(false).assertTrue();
done();
return;
}
expect(trashState).assertTrue();
try {
// after trash database info
databaseFetchFileResult = await media.getFileAssets(databasefFetchOps);
let databaseCount = databaseFetchFileResult.getCount();
expect(databaseCount).assertEqual(count - 1);
//album info
if (!noAlbum) {
let albumList = await media.getAlbums(ablumFetchOps);
let album = albumList[0];
let albumFetchFileResult = await album.getFileAssets();
let albumFilesCount = albumFetchFileResult.getCount();
expect(albumFilesCount).assertEqual(count - 1);
}
let assetOpts = fileIdFetchOps(id);
let trashAssetResult = await media.getFileAssets(assetOpts);
let afterTrashAssetConut = trashAssetResult.getCount();
expect(afterTrashAssetConut).assertEqual(0);
await asset.trash(false);
done();
} catch (error) {
console.info(`${testNum} error: ${error}`);
expect(false).assertTrue();
done();
}
});
});
} catch (error) {
console.info(`${testNum} error: ${error}`);
expect(false).assertTrue();
done();
}
}
async function recovery(done, testNum, databasefFetchOps, ablumFetchOps, noAlbum) {
try {
let databaseFetchFileResult = await media.getFileAssets(databasefFetchOps);
let count = databaseFetchFileResult.getCount();
let asset = await databaseFetchFileResult.getFirstObject();
let id = asset.id;
await asset.trash(true);
let istrash = await asset.isTrash();
if (!istrash) {
console.info(`${testNum} istrash failed: ${istrash}`);
expect(istrash).assertFalse();
return;
}
asset.trash(false, async (err) => {
if (err) {
console.info(`${testNum} err: ${err}`);
expect(false).assertTrue();
done();
return;
}
asset.isTrash(async (err, trashState) => {
if (err) {
console.info(`${testNum} err: ${err}`);
expect(false).assertTrue();
done();
return;
}
expect(trashState).assertFalse();
try {
databaseFetchFileResult = await media.getFileAssets(databasefFetchOps);
let databaseCount = databaseFetchFileResult.getCount();
expect(databaseCount).assertEqual(count);
//album info
if (!noAlbum) {
let albumList = await media.getAlbums(ablumFetchOps);
let album = albumList[0];
let albumFetchFileResult = await album.getFileAssets();
let albumFilesCount = albumFetchFileResult.getCount();
expect(albumFilesCount).assertEqual(count);
}
// asset after trash Conut
let assetOpts = fileIdFetchOps(testNum, id);
let recoveryAssetResult = await media.getFileAssets(assetOpts);
let afterRecoveryAssetConut = recoveryAssetResult.getCount();
expect(afterRecoveryAssetConut).assertEqual(1);
let recoveryAsset = await recoveryAssetResult.getFirstObject();
let recoveryAssetState = await recoveryAsset.isTrash();
expect(recoveryAssetState).assertFalse();
done();
} catch (error) {
console.info(`${testNum} error: ${error}`);
expect(false).assertTrue();
done();
}
});
});
} catch (error) {
console.info(`${testNum} error: ${error}`);
expect(false).assertTrue();
done();
}
}
async function trashError(done, testNum, databasefFetchOps, value) {
try {
let databaseFetchFileResult = await media.getFileAssets(databasefFetchOps);
let asset = await databaseFetchFileResult.getFirstObject();
let count = databaseFetchFileResult.getCount();
console.info(`${testNum}count:${count}`);
try {
asset.trash(value, async (err) => {
if (err) {
console.info(`${testNum} err: ${err}`);
expect(false).assertTrue();
done();
return;
}
expect(false).assertTrue();
done();
});
} catch (error) {
console.info(`${testNum} error: ${error}`);
let databaseFetchFileResult = await media.getFileAssets(databasefFetchOps);
let count2 = databaseFetchFileResult.getCount();
expect(count).assertEqual(count2);
done();
}
} catch (error) {
console.info(`${testNum} error: ${error}`);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_CALLBACK_01_001
* @tc.name : trash
* @tc.desc : image asset Trash by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_CALLBACK_01_001", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_CALLBACK_01_001";
let rOps = fetchOps(testNum, "Pictures/trashCb/", IMAGE_TYPE);
let aOps = albumFetchOps(testNum, "Pictures/", "trashCb", IMAGE_TYPE);
let noAlbum = false;
await setTrash(done, testNum, rOps, aOps, noAlbum);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_CALLBACK_01_002
* @tc.name : trash
* @tc.desc : video asset Trash by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_CALLBACK_01_002", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_CALLBACK_01_002";
let rOps = fetchOps(testNum, "Videos/trashCb/", VIDEO_TYPE);
let aOps = albumFetchOps(testNum, "Videos/", "trashCb", VIDEO_TYPE);
let noAlbum = false;
await setTrash(done, testNum, rOps, aOps, noAlbum);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_CALLBACK_01_003
* @tc.name : trash
* @tc.desc : audio asset Trash by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_CALLBACK_01_003", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_CALLBACK_01_003";
let rOps = fetchOps(testNum, "Audios/trashCb/", AUDIO_TYPE);
let aOps = albumFetchOps(testNum, "Audios/", "trashCb", AUDIO_TYPE);
let noAlbum = false;
await setTrash(done, testNum, rOps, aOps, noAlbum);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_CALLBACK_01_004
* @tc.name : trash
* @tc.desc : file asset Trash by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_CALLBACK_01_004", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_CALLBACK_01_004";
let rOps = fetchOps(testNum, "Documents/trashCb/", FILE_TYPE);
let aOps = albumFetchOps(testNum, "Documents/", "trashCb", FILE_TYPE);
let noAlbum = true;
await setTrash(done, testNum, rOps, aOps, noAlbum);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_CALLBACK_02_001
* @tc.name : trash
* @tc.desc : image asset Trash by 1
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 3
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_CALLBACK_02_001", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_CALLBACK_02_001";
let rOps = fetchOps(testNum, "Pictures/trashCb/", IMAGE_TYPE);
let value = 1;
await trashError(done, testNum, rOps, value);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_CALLBACK_02_002
* @tc.name : trash
* @tc.desc : image asset Trash by 'abc'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 3
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_CALLBACK_02_002", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_CALLBACK_02_002";
let rOps = fetchOps(testNum, "Pictures/trashCb/", IMAGE_TYPE);
let value = "abc";
await trashError(done, testNum, rOps, value);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_CALLBACK_02_003
* @tc.name : trash
* @tc.desc : image asset Trash by {a:10}
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 3
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_CALLBACK_02_003", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_CALLBACK_02_003";
let rOps = fetchOps(testNum, "Pictures/trashCb/", IMAGE_TYPE);
let value = { a: 10 };
await trashError(done, testNum, rOps, value);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_CALLBACK_02_004
* @tc.name : trash
* @tc.desc : image asset Trash by undefined
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 3
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_CALLBACK_02_004", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_CALLBACK_02_004";
let rOps = fetchOps(testNum, "Pictures/trashCb/", IMAGE_TYPE);
let value = undefined;
await trashError(done, testNum, rOps, value);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_CALLBACK_02_005
* @tc.name : trash
* @tc.desc : image asset Trash by null
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 3
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_CALLBACK_02_005", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_CALLBACK_02_005";
let rOps = fetchOps(testNum, "Pictures/trashCb/", IMAGE_TYPE);
let value = null;
await trashError(done, testNum, rOps, value);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_CALLBACK_03_001
* @tc.name : trash
* @tc.desc : image asset Trash by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_CALLBACK_03_001", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_CALLBACK_03_001";
let rOps = fetchOps(testNum, "Pictures/trash/", IMAGE_TYPE);
let aOps = albumFetchOps(testNum, "Pictures/", "trash", IMAGE_TYPE);
let noAlbum = false;
await recovery(done, testNum, rOps, aOps, noAlbum);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_CALLBACK_03_002
* @tc.name : trash
* @tc.desc : video asset Trash by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_CALLBACK_03_002", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_CALLBACK_03_002";
let rOps = fetchOps(testNum, "Videos/trash/", VIDEO_TYPE);
let aOps = albumFetchOps(testNum, "Videos/", "trash", VIDEO_TYPE);
let noAlbum = false;
await recovery(done, testNum, rOps, aOps, noAlbum);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_CALLBACK_03_003
* @tc.name : trash
* @tc.desc : audio asset Trash by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_CALLBACK_03_003", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_CALLBACK_03_003";
let rOps = fetchOps(testNum, "Audios/trash/", AUDIO_TYPE);
let aOps = albumFetchOps(testNum, "Audios/", "trash", AUDIO_TYPE);
let noAlbum = false;
await recovery(done, testNum, rOps, aOps, noAlbum);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_CALLBACK_03_004
* @tc.name : trash
* @tc.desc : file asset Trash by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_CALLBACK_03_004", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_CALLBACK_03_004";
let rOps = fetchOps(testNum, "Documents/trash/", FILE_TYPE);
let aOps = albumFetchOps(testNum, "Documents/", "trash", FILE_TYPE);
let noAlbum = true;
await recovery(done, testNum, rOps, aOps, noAlbum);
});
});
}
/*
* 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 mediaLibrary from "@ohos.multimedia.mediaLibrary";
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "deccjsunit/index";
import {
sleep,
IMAGE_TYPE,
AUDIO_TYPE,
VIDEO_TYPE,
FILE_TYPE,
fetchOps,
fileIdFetchOps,
albumFetchOps,
} from "../../../../../../common";
export default function trashPromise(abilityContext) {
describe("trashPromise", function () {
beforeAll(async function () {
console.info("beforeAll case");
});
beforeEach(function () {
console.info("beforeEach case");
});
afterEach(async function () {
console.info("afterEach case");
await sleep();
});
afterAll(async function () {
console.info("afterAll case");
});
const media = mediaLibrary.getMediaLibrary(abilityContext);
async function setTrash(done, testNum, databasefFetchOps, ablumFetchOps, noAlbum = false) {
try {
// database info
let databaseFetchFileResult = await media.getFileAssets(databasefFetchOps);
let count = databaseFetchFileResult.getCount();
//album info
if (!noAlbum) {
var albumList = await media.getAlbums(ablumFetchOps);
var album = albumList[0];
var albumFetchFileResult = await album.getFileAssets();
var albumFilesCount = albumFetchFileResult.getCount();
expect(albumFilesCount).assertEqual(count);
}
// file info
let asset = await databaseFetchFileResult.getFirstObject();
let id = asset.id;
let istrash = await asset.isTrash();
expect(istrash).assertFalse();
// trash operation
await asset.trash(true);
istrash = await asset.isTrash();
console.info(`${testNum} istrash: ${istrash}`);
databaseFetchFileResult = await media.getFileAssets(databasefFetchOps);
let databaseCount = databaseFetchFileResult.getCount();
expect(databaseCount).assertEqual(count - 1);
//album info
if (!noAlbum) {
var albumList = await media.getAlbums(ablumFetchOps);
var album = albumList[0];
var albumFetchFileResult = await album.getFileAssets();
var albumFilesCount = albumFetchFileResult.getCount();
expect(databaseCount).assertEqual(count - 1);
}
// asset after trash Conut
let assetOpts = fileIdFetchOps(id);
let trashAssetResult = await media.getFileAssets(assetOpts);
let afterTrashAssetConut = trashAssetResult.getCount();
expect(afterTrashAssetConut).assertEqual(0);
await asset.trash(false);
done();
} catch (error) {
console.info(`${testNum} error: ${error}`);
expect(false).assertTrue();
done();
}
}
async function trashError(done, testNum, databasefFetchOps, value) {
try {
let databaseFetchFileResult = await media.getFileAssets(databasefFetchOps);
let asset = await databaseFetchFileResult.getFirstObject();
let count = databaseFetchFileResult.getCount();
try {
await asset.trash(value);
expect(false).assertTrue();
done();
} catch (error) {
console.info(`${testNum} error: ${error}`);
let databaseFetchFileResult = await media.getFileAssets(databasefFetchOps);
let count2 = databaseFetchFileResult.getCount();
expect(count).assertEqual(count2);
done();
}
} catch (error) {
console.info(`${testNum} error: ${error}`);
expect(false).assertTrue();
done();
}
}
async function recovery(done, testNum, databasefFetchOps, ablumFetchOps, noAlbum) {
try {
let databaseFetchFileResult = await media.getFileAssets(databasefFetchOps);
let count = databaseFetchFileResult.getCount();
let asset = await databaseFetchFileResult.getFirstObject();
let id = asset.id;
await asset.trash(true);
let istrash = await asset.isTrash();
if (!istrash) {
console.info(`${testNum} istrash failed: ${istrash}`);
expect(istrash).assertFalse();
return;
}
await asset.trash(false);
databaseFetchFileResult = await media.getFileAssets(databasefFetchOps);
let databaseCount = databaseFetchFileResult.getCount();
expect(databaseCount).assertEqual(count);
//album info
if (!noAlbum) {
let albumList = await media.getAlbums(ablumFetchOps);
let album = albumList[0];
let albumFetchFileResult = await album.getFileAssets();
let albumFilesCount = albumFetchFileResult.getCount();
expect(albumFilesCount).assertEqual(count);
}
// asset after trash Conut
let assetOpts = fileIdFetchOps(testNum, id);
let recoveryAssetResult = await media.getFileAssets(assetOpts);
let afterRecoveryAssetConut = recoveryAssetResult.getCount();
expect(afterRecoveryAssetConut).assertEqual(1);
let recoveryAsset = await recoveryAssetResult.getFirstObject();
let recoveryAssetState = await recoveryAsset.isTrash();
expect(recoveryAssetState).assertFalse();
done();
} catch (error) {
console.info(`${testNum} error: ${error}`);
expect(false).assertTrue();
done();
}
}
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_PROMISE_01_001
* @tc.name : trash
* @tc.desc : image asset Trash by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_PROMISE_01_001", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_PROMISE_01_001";
let rOps = fetchOps(testNum, "Pictures/trash/", IMAGE_TYPE);
let aOps = albumFetchOps(testNum, "Pictures/", "trash", IMAGE_TYPE);
let noAlbum = false;
await setTrash(done, testNum, rOps, aOps, noAlbum);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_PROMISE_01_002
* @tc.name : trash
* @tc.desc : video asset Trash by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_PROMISE_01_002", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_PROMISE_01_002";
let rOps = fetchOps(testNum, "Videos/trash/", VIDEO_TYPE);
let aOps = albumFetchOps(testNum, "Videos/", "trash", VIDEO_TYPE);
let noAlbum = false;
await setTrash(done, testNum, rOps, aOps, noAlbum);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_PROMISE_01_003
* @tc.name : trash
* @tc.desc : audio asset Trash by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_PROMISE_01_003", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_PROMISE_01_003";
let rOps = fetchOps(testNum, "Audios/trash/", AUDIO_TYPE);
let aOps = albumFetchOps(testNum, "Audios/", "trash", AUDIO_TYPE);
let noAlbum = false;
await setTrash(done, testNum, rOps, aOps, noAlbum);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_PROMISE_01_004
* @tc.name : trash
* @tc.desc : file asset Trash by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_PROMISE_01_004", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_PROMISE_01_004";
let rOps = fetchOps(testNum, "Documents/trash/", FILE_TYPE);
let aOps = albumFetchOps(testNum, "Documents/", "trash", FILE_TYPE);
let noAlbum = true;
await setTrash(done, testNum, rOps, aOps, noAlbum);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_PROMISE_02_001
* @tc.name : trash
* @tc.desc : image asset Trash by 1
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 3
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_PROMISE_02_001", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_PROMISE_02_001";
let rOps = fetchOps(testNum, "Pictures/trash/", IMAGE_TYPE);
let value = 1;
await trashError(done, testNum, rOps, value);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_PROMISE_02_002
* @tc.name : trash
* @tc.desc : image asset Trash by 'abc'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 3
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_PROMISE_02_002", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_PROMISE_02_002";
let rOps = fetchOps(testNum, "Pictures/trash/", IMAGE_TYPE);
let value = "abc";
await trashError(done, testNum, rOps, value);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_PROMISE_02_003
* @tc.name : trash
* @tc.desc : image asset Trash by {a:10}
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 3
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_PROMISE_02_003", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_PROMISE_02_003";
let rOps = fetchOps(testNum, "Pictures/trash/", IMAGE_TYPE);
let value = { a: 10 };
await trashError(done, testNum, rOps, value);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_PROMISE_02_004
* @tc.name : trash
* @tc.desc : image asset Trash by undefined
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 3
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_PROMISE_02_004", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_PROMISE_02_004";
let rOps = fetchOps(testNum, "Pictures/trash/", IMAGE_TYPE);
let value = undefined;
await trashError(done, testNum, rOps, value);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_PROMISE_02_005
* @tc.name : trash
* @tc.desc : image asset Trash by null
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 3
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_PROMISE_02_005", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_ERROR_PROMISE_02_005";
let rOps = fetchOps(testNum, "Pictures/trash/", IMAGE_TYPE);
let value = null;
await trashError(done, testNum, rOps, value);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_PROMISE_03_001
* @tc.name : trash
* @tc.desc : image asset Trash by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_PROMISE_03_001", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_PROMISE_03_001";
let rOps = fetchOps(testNum, "Pictures/trash/", IMAGE_TYPE);
let aOps = albumFetchOps(testNum, "Pictures/", "trash", IMAGE_TYPE);
let noAlbum = false;
await recovery(done, testNum, rOps, aOps, noAlbum);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_PROMISE_03_002
* @tc.name : trash
* @tc.desc : video asset Trash by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_PROMISE_03_002", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_PROMISE_03_002";
let rOps = fetchOps(testNum, "Videos/trash/", VIDEO_TYPE);
let aOps = albumFetchOps(testNum, "Videos/", "trash", VIDEO_TYPE);
let noAlbum = false;
await recovery(done, testNum, rOps, aOps, noAlbum);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_PROMISE_03_003
* @tc.name : trash
* @tc.desc : audio asset Trash by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_PROMISE_03_003", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_PROMISE_03_003";
let rOps = fetchOps(testNum, "Audios/trash/", AUDIO_TYPE);
let aOps = albumFetchOps(testNum, "Audios/", "trash", AUDIO_TYPE);
let noAlbum = false;
await recovery(done, testNum, rOps, aOps, noAlbum);
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_PROMISE_03_004
* @tc.name : trash
* @tc.desc : file asset Trash by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it("SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_PROMISE_03_004", 0, async function (done) {
let testNum = "SUB_MEDIA_MEDIALIBRARY_TRASH_RECOVERY_PROMISE_03_004";
let rOps = fetchOps(testNum, "Documents/trash/", FILE_TYPE);
let aOps = albumFetchOps(testNum, "Documents/", "trash", FILE_TYPE);
let noAlbum = true;
await recovery(done, testNum, rOps, aOps, noAlbum);
});
});
}
{ {
"module": { "module": {
"name": "phone", "name": "phone",
"type": "entry", "type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts", "srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:mainability_description", "description": "$string:mainability_description",
"mainElement": "MainAbility", "mainElement": "MainAbility",
"deviceTypes": [ "deviceTypes": [
"phone" "phone"
], ],
"deliveryWithInstall": true, "deliveryWithInstall": true,
"installationFree": false, "installationFree": false,
"uiSyntax": "ets", "uiSyntax": "ets",
"pages": "$profile:main_pages", "pages": "$profile:main_pages",
"abilities": [ "abilities": [
{ {
"name": "ohos.acts.multimedia.mediaLibrary.MainAbility", "name": "ohos.acts.multimedia.mediaLibrary.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts", "srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:mainability_description", "description": "$string:mainability_description",
"icon": "$media:icon", "icon": "$media:icon",
"label": "$string:entry_MainAbility", "label": "$string:entry_MainAbility",
"visible": true, "visible": true,
"orientation": "portrait", "orientation": "portrait",
"skills": [ "skills": [
{ {
"actions": [ "actions": [
"action.system.home" "action.system.home"
], ],
"entities":[ "entities":[
"entity.system.home" "entity.system.home"
] ]
} }
] ]
} }
], ],
"requestPermissions": [ "requestPermissions": [
{ {
"name": "ohos.permission.GET_BUNDLE_INFO", "name": "ohos.permission.GET_BUNDLE_INFO",
"reason": "use ohos.permission.GET_BUNDLE_INFO" "reason": "use ohos.permission.GET_BUNDLE_INFO"
}, },
{ {
"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": "entry_MainAbility",
"value": "MediaLibraryJSTestMain" "value": "MediaLibraryJSTestMain"
}, },
{ {
"name": "mainability_description", "name": "mainability_description",
"value": "MediaLibraryJSTestMain Ability" "value": "MediaLibraryJSTestMain Ability"
} }
] ]
} }
\ No newline at end of file
{ {
"src": [ "src": [
"pages/index/index", "pages/index/index",
"pages/second/second" "pages/second/second"
] ]
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册