提交 28afd11b 编写于 作者: H hu0475

修复gn格式问题和按接口人要求完善代码

Signed-off-by: Nhu0475 <huyanqiang5@huawei.com>
上级 842c5fe2
...@@ -16,7 +16,7 @@ group("graphic") { ...@@ -16,7 +16,7 @@ group("graphic") {
testonly = true testonly = true
if (is_standard_system) { if (is_standard_system) {
deps = [ deps = [
"crossplatform/window:window_ets_normal_test", "crossplatform/window:ActsCrossplatformWindowTest",
"effectKit:EffectKitTest", "effectKit:EffectKitTest",
"graphicColorSpace:ActsColorSpaceManagerTest", "graphicColorSpace:ActsColorSpaceManagerTest",
"graphicnapidrawingtest:ActsGraphicNapiDrawingTest", "graphicnapidrawingtest:ActsGraphicNapiDrawingTest",
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
"versionName": "1.0.0", "versionName": "1.0.0",
"icon": "$media:app_icon", "icon": "$media:app_icon",
"label": "$string:app_name", "label": "$string:app_name",
"minAPIVersion": 9, "minAPIVersion": 10,
"targetAPIVersion": 9, "targetAPIVersion": 10,
"car": { "car": {
"apiCompatibleVersion": 9, "apiCompatibleVersion": 10,
"singleUser": false "singleUser": false
} }
} }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
import("//test/xts/tools/build/suite.gni") import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("window_ets_normal_test") { ohos_js_hap_suite("ActsCrossplatformWindowTest") {
hap_profile = "src/main/module.json" hap_profile = "src/main/module.json"
deps = [ deps = [
":windowStage_js_assets", ":windowStage_js_assets",
...@@ -21,7 +21,7 @@ ohos_js_hap_suite("window_ets_normal_test") { ...@@ -21,7 +21,7 @@ ohos_js_hap_suite("window_ets_normal_test") {
] ]
ets2abc = true ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b" certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsWindowTest" hap_name = "ActsCrossplatformWindowTest"
subsystem_name = "window" subsystem_name = "window"
part_name = "window_manager" part_name = "window_manager"
} }
...@@ -36,4 +36,4 @@ ohos_resources("windowStage_resources") { ...@@ -36,4 +36,4 @@ ohos_resources("windowStage_resources") {
sources = [ "src/main/resources" ] sources = [ "src/main/resources" ]
deps = [ ":windowStage_app_profile" ] deps = [ ":windowStage_app_profile" ]
hap_profile = "src/main/module.json" hap_profile = "src/main/module.json"
} }
\ No newline at end of file
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
"shell-timeout": "300000", "shell-timeout": "300000",
"bundle-name": "ohos.acts.graphic.crossplatform.window", "bundle-name": "ohos.acts.graphic.crossplatform.window",
"module-name": "window", "module-name": "window",
"testcase-timeout": 5000 "testcase-timeout": 10000
}, },
"kits": [ "kits": [
{ {
"test-file-name": [ "test-file-name": [
"ActsWindowTest.hap" "ActsCrossplatformWindowTest.hap"
], ],
"type": "AppInstallKit", "type": "AppInstallKit",
"cleanup-apps": true "cleanup-apps": true
......
/*
* Copyright (c) 2023 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.
*/
@Entry
@Component
struct Index1 {
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World \n pages/Index1!!!')
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
...@@ -23,6 +23,10 @@ export default function Window() { ...@@ -23,6 +23,10 @@ export default function Window() {
let storage; let storage;
const TRUE_FLAG = true; const TRUE_FLAG = true;
function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time))
}
beforeAll(async function () { beforeAll(async function () {
console.info("beforeAll case"); console.info("beforeAll case");
context = globalThis.abilityContext; context = globalThis.abilityContext;
...@@ -172,7 +176,11 @@ export default function Window() { ...@@ -172,7 +176,11 @@ export default function Window() {
return; return;
} }
console.info(msgStr + 'Succeeded in obtaining the top window. Data: ' + JSON.stringify(data)); console.info(msgStr + 'Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
expect(data != null).assertTrue(); try {
expect(data != null).assertTrue();
} catch (err) {
console.info(msgStr + "err " + err);
}
await windowData.destroyWindow(); await windowData.destroyWindow();
done(); done();
}) })
...@@ -197,8 +205,9 @@ export default function Window() { ...@@ -197,8 +205,9 @@ export default function Window() {
try { try {
tempWnd = await windowStage.createSubWindow('testShowWindowPromise001'); tempWnd = await windowStage.createSubWindow('testShowWindowPromise001');
expect(!!tempWnd).assertTrue(); expect(!!tempWnd).assertTrue();
await tempWnd.showWindow().then(async (data) => { await tempWnd.showWindow().then(async () => {
console.info(msgStr + 'Succeeded in showing the window. Data: ' + JSON.stringify(data)); expect(TRUE_FLAG).assertTrue();
console.info(msgStr + 'Succeeded in showing the window. ');
await tempWnd.destroyWindow(); await tempWnd.destroyWindow();
done(); done();
}).catch((err) => { }).catch((err) => {
...@@ -227,7 +236,7 @@ export default function Window() { ...@@ -227,7 +236,7 @@ export default function Window() {
let winData; let winData;
winData = await windowStage.createSubWindow('testShowWindowCb001'); winData = await windowStage.createSubWindow('testShowWindowCb001');
expect(!!winData).assertTrue(); expect(!!winData).assertTrue();
winData.showWindow(async (err, data) => { winData.showWindow(async (err) => {
if (err.code) { if (err.code) {
console.error(msgStr + 'Failed to show the window. Cause: ' + JSON.stringify(err)); console.error(msgStr + 'Failed to show the window. Cause: ' + JSON.stringify(err));
try { try {
...@@ -238,7 +247,8 @@ export default function Window() { ...@@ -238,7 +247,8 @@ export default function Window() {
done(); done();
return; return;
} }
console.info(msgStr + 'Succeeded in showing the window. Data: ' + JSON.stringify(data)); console.info(msgStr + 'Succeeded in showing the window.');
expect(TRUE_FLAG).assertTrue();
await winData.destroyWindow(); await winData.destroyWindow();
done(); done();
}) })
...@@ -314,7 +324,11 @@ export default function Window() { ...@@ -314,7 +324,11 @@ export default function Window() {
expect(!findWnd).assertTrue(); expect(!findWnd).assertTrue();
} catch (exception) { } catch (exception) {
console.error(msgStr + 'try catch Failed to find the Window. Cause: ' + JSON.stringify(exception)); console.error(msgStr + 'try catch Failed to find the Window. Cause: ' + JSON.stringify(exception));
expect(exception.code).assertEqual(1300002); try {
expect(exception.code).assertEqual(1300002);
} catch (err) {
console.error(msgStr + 'fail ' + JSON.stringify(err));
}
} }
} }
done(); done();
...@@ -520,7 +534,7 @@ export default function Window() { ...@@ -520,7 +534,7 @@ export default function Window() {
expect(!!winData).assertTrue(); expect(!!winData).assertTrue();
try { try {
await winData.showWindow(); await winData.showWindow();
winData.moveWindowTo(300, 300, async (err, data) => { winData.moveWindowTo(300, 300, async (err) => {
if (err.code) { if (err.code) {
console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err));
try { try {
...@@ -532,7 +546,7 @@ export default function Window() { ...@@ -532,7 +546,7 @@ export default function Window() {
done(); done();
return; return;
} }
console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); console.info(msgStr + 'Succeeded in moving the window. ');
await winData.destroyWindow(); await winData.destroyWindow();
done(); done();
}) })
...@@ -559,7 +573,7 @@ export default function Window() { ...@@ -559,7 +573,7 @@ export default function Window() {
expect(!!winData).assertTrue(); expect(!!winData).assertTrue();
try { try {
await winData.showWindow(); await winData.showWindow();
winData.moveWindowTo(100, 50, async (err, data) => { winData.moveWindowTo(100, 50, async (err) => {
if (err.code) { if (err.code) {
console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err));
try { try {
...@@ -571,7 +585,7 @@ export default function Window() { ...@@ -571,7 +585,7 @@ export default function Window() {
done(); done();
return; return;
} }
console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); console.info(msgStr + 'Succeeded in moving the window. ');
await winData.destroyWindow(); await winData.destroyWindow();
done(); done();
}) })
...@@ -598,7 +612,7 @@ export default function Window() { ...@@ -598,7 +612,7 @@ export default function Window() {
expect(!!winData).assertTrue(); expect(!!winData).assertTrue();
try { try {
await winData.showWindow(); await winData.showWindow();
winData.moveWindowTo(20000, 20000, async (err, data) => { winData.moveWindowTo(20000, 20000, async (err) => {
if (err.code) { if (err.code) {
console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err));
try { try {
...@@ -610,7 +624,7 @@ export default function Window() { ...@@ -610,7 +624,7 @@ export default function Window() {
done(); done();
return; return;
} }
console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); console.info(msgStr + 'Succeeded in moving the window. ');
await winData.destroyWindow(); await winData.destroyWindow();
done(); done();
}) })
...@@ -637,7 +651,7 @@ export default function Window() { ...@@ -637,7 +651,7 @@ export default function Window() {
expect(!!winData).assertTrue(); expect(!!winData).assertTrue();
try { try {
await winData.showWindow(); await winData.showWindow();
winData.moveWindowTo(-200, -200, async (err, data) => { winData.moveWindowTo(-200, -200, async (err) => {
if (err.code) { if (err.code) {
console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err));
try { try {
...@@ -649,7 +663,7 @@ export default function Window() { ...@@ -649,7 +663,7 @@ export default function Window() {
done(); done();
return; return;
} }
console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); console.info(msgStr + 'Succeeded in moving the window.');
await winData.destroyWindow(); await winData.destroyWindow();
done(); done();
}) })
...@@ -1239,7 +1253,7 @@ export default function Window() { ...@@ -1239,7 +1253,7 @@ export default function Window() {
expect(!!mainWin).assertTrue(); expect(!!mainWin).assertTrue();
let num = 0 let num = 0
let orientationItem = ['UNSPECIFIED', 'PORTRAIT', 'LANDSCAPE', 'PORTRAIT_INVERTED', let orientationItem = ['UNSPECIFIED', 'PORTRAIT', 'LANDSCAPE', 'PORTRAIT_INVERTED',
'LANDSCAPE_INVERTED']; 'LANDSCAPE_INVERTED', 'UNSPECIFIED'];
for (let i = 0; i < orientationItem.length; i++) { for (let i = 0; i < orientationItem.length; i++) {
let orientation = window.Orientation[orientationItem[i]] let orientation = window.Orientation[orientationItem[i]]
console.log(msgStr + 'i : ' + i + ' ,orientation : ' + orientation); console.log(msgStr + 'i : ' + i + ' ,orientation : ' + orientation);
...@@ -1249,8 +1263,9 @@ export default function Window() { ...@@ -1249,8 +1263,9 @@ export default function Window() {
num++ num++
if (num == orientationItem.length) done(); if (num == orientationItem.length) done();
}).catch(err => { }).catch(err => {
console.log(msgStr + 'window.setPreferredOrientation failed set error:' + orientation); console.log(msgStr + 'window.setPreferredOrientation failed set error:' + orientation + err);
}); });
await sleep(500);
} }
}) })
/** /**
...@@ -1294,7 +1309,11 @@ export default function Window() { ...@@ -1294,7 +1309,11 @@ export default function Window() {
let orientation = window.Orientation[orientationItem[i]] let orientation = window.Orientation[orientationItem[i]]
await setPreferredOrientationFun(mainWin, orientation).catch((err) => { await setPreferredOrientationFun(mainWin, orientation).catch((err) => {
console.error(msgStr + 'Failed to obtain the main window. Cause: ' + JSON.stringify(err)); console.error(msgStr + 'Failed to obtain the main window. Cause: ' + JSON.stringify(err));
expect().assertFail(); try {
expect().assertFail();
} catch (err) {
console.error(msgStr + 'Failed to obtain the main window. Cause: ' + JSON.stringify(err));
}
done(); done();
}); });
console.info(msgStr + 'Succeeded in setting window orientation. orientation: ' + orientation + "step: " + i); console.info(msgStr + 'Succeeded in setting window orientation. orientation: ' + orientation + "step: " + i);
...@@ -1322,14 +1341,14 @@ export default function Window() { ...@@ -1322,14 +1341,14 @@ export default function Window() {
tempWnd = await windowStage.createSubWindow(windowId); tempWnd = await windowStage.createSubWindow(windowId);
expect(!!tempWnd).assertTrue(); expect(!!tempWnd).assertTrue();
console.log(msgStr + 'tempWnd.loadContent start'); console.log(msgStr + 'tempWnd.loadContent start');
let load = await tempWnd.loadContent('pages/second/second', storage).catch((err) => { await tempWnd.loadContent('TestAbility/pages/index1', storage).then(async () => {
console.log(msgStr + 'tempWnd.loadContent() success');
expect(TRUE_FLAG).assertTrue();
await tempWnd.destroyWindow();
done();
}).catch((err) => {
unexpectedError(err, caseName, 'tempWnd.loadContent', done); unexpectedError(err, caseName, 'tempWnd.loadContent', done);
console.log(msgStr + 'tempWnd.loadContent(pages/second/second) err=' + JSON.stringify(err));
}); });
console.log(msgStr + 'tempWnd.loadContent(pages/second/second) load=' + JSON.stringify(load));
expect(!load).assertTrue();
await tempWnd.destroyWindow();
done();
}) })
/** /**
* @tc.number : TEST_LOADCONTENT_PROMISE_002 * @tc.number : TEST_LOADCONTENT_PROMISE_002
...@@ -1348,15 +1367,13 @@ export default function Window() { ...@@ -1348,15 +1367,13 @@ export default function Window() {
tempWnd = await windowStage.createSubWindow(windowId); tempWnd = await windowStage.createSubWindow(windowId);
expect(!!tempWnd).assertTrue(); expect(!!tempWnd).assertTrue();
console.log(msgStr + 'tempWnd.loadContent start'); console.log(msgStr + 'tempWnd.loadContent start');
await tempWnd.destroyWindow();
let errFlag = false;
try { try {
await tempWnd.loadContent(null, storage); await tempWnd.loadContent(null, storage);
expect().assertFail(); expect().assertFail();
done(); done();
} catch (err) { } catch (err) {
errFlag = true;
expectedError(err, caseName, 'tempWnd.loadContent', done, 401); expectedError(err, caseName, 'tempWnd.loadContent', done, 401);
await tempWnd.destroyWindow();
console.log(msgStr + 'tempWnd.loadContent(null)' + JSON.stringify(err)); console.log(msgStr + 'tempWnd.loadContent(null)' + JSON.stringify(err));
} }
}) })
...@@ -1378,17 +1395,19 @@ export default function Window() { ...@@ -1378,17 +1395,19 @@ export default function Window() {
tempWnd = await windowStage.createSubWindow(windowId); tempWnd = await windowStage.createSubWindow(windowId);
expect(!!tempWnd).assertTrue(); expect(!!tempWnd).assertTrue();
tempWnd.loadContent('pages/index', storage, async (err, data) => { tempWnd.loadContent('TestAbility/pages/index1', storage, async (err) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(err, caseName, 'tempWnd.loadContent', done); unexpectedError(err, caseName, 'tempWnd.loadContent', done);
} else { } else {
try { try {
expect(!data).assertTrue(); console.log(msgStr + 'tempWnd.loadContent() success');
expect(TRUE_FLAG).assertTrue();
done();
} catch (error) { } catch (error) {
console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`) console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`)
done()
} }
await tempWnd.destroyWindow(); await tempWnd.destroyWindow();
done()
} }
}) })
}) })
...@@ -1409,7 +1428,7 @@ export default function Window() { ...@@ -1409,7 +1428,7 @@ export default function Window() {
tempWnd = await windowStage.createSubWindow(windowId); tempWnd = await windowStage.createSubWindow(windowId);
expect(!!tempWnd).assertTrue(); expect(!!tempWnd).assertTrue();
try { try {
tempWnd.loadContent(null, storage, async (err, data) => { tempWnd.loadContent(null, storage, async (err) => {
if (err && err.code) { if (err && err.code) {
try { try {
expect(err.code === 401).assertTrue(); expect(err.code === 401).assertTrue();
...@@ -1434,7 +1453,7 @@ export default function Window() { ...@@ -1434,7 +1453,7 @@ export default function Window() {
} }
}) })
/** /**
* @tc.number : testGetUIContext001 * @tc.number : TEST_GETUICONTEXT_001
* @tc.name : testGetUIContext001 * @tc.name : testGetUIContext001
* @tc.desc : test getUIContext * @tc.desc : test getUIContext
* @tc.size : MediumTest * @tc.size : MediumTest
...@@ -1442,20 +1461,12 @@ export default function Window() { ...@@ -1442,20 +1461,12 @@ export default function Window() {
* @tc.level : Level 2 * @tc.level : Level 2
*/ */
it('testGetUIContext001', 0, async function (done) { it('testGetUIContext001', 0, async function (done) {
windowStage.getMainWindow((err, data) => { let tempWnd = await windowStage.getMainWindow();
if (err.code) { expect(!!tempWnd).assertTrue();
console.error('testGetUIContext001 Failed to obtain the main window. Cause: ' + JSON.stringify(err)); let UIContext = tempWnd.getUIContext();
expect(false).assertTrue(); expect(UIContext != undefined).assertTrue();
done() console.info('testGetUIContext001 Succeeded');
} else { done();
console.info('testGetUIContext001 Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
expect(data != undefined).assertTrue();
let UIContext = data.getUIContext();
expect(UIContext != undefined).assertTrue();
console.info('testGetUIContext001 Succeeded');
done();
}
})
}) })
/** /**
* @tc.number : TEST_SETUICONTENT_PROMISE_001 * @tc.number : TEST_SETUICONTENT_PROMISE_001
...@@ -1470,7 +1481,7 @@ export default function Window() { ...@@ -1470,7 +1481,7 @@ export default function Window() {
try { try {
win = await windowStage.createSubWindow('testSetUIContentPromise001'); win = await windowStage.createSubWindow('testSetUIContentPromise001');
expect(win != null); expect(win != null);
await win.setUIContent('pages/second/second').then(async () => { await win.setUIContent('TestAbility/pages/index1').then(async () => {
console.info('setUIContent1 . Cause: success'); console.info('setUIContent1 . Cause: success');
expect(TRUE_FLAG).assertTrue(); expect(TRUE_FLAG).assertTrue();
await win.destroyWindow(); await win.destroyWindow();
...@@ -1537,7 +1548,7 @@ export default function Window() { ...@@ -1537,7 +1548,7 @@ export default function Window() {
try { try {
win = await windowStage.createSubWindow('testSetUIContentPromise003'); win = await windowStage.createSubWindow('testSetUIContentPromise003');
expect(win != null).assertTrue(); expect(win != null).assertTrue();
await win.setUIContent('pages/second/he').then(async () => { await win.setUIContent('wrong pages').then(async () => {
console.info('setUIContent3 . Cause: success'); console.info('setUIContent3 . Cause: success');
expect(TRUE_FLAG).assertTrue(); expect(TRUE_FLAG).assertTrue();
await win.destroyWindow(); await win.destroyWindow();
...@@ -1567,12 +1578,11 @@ export default function Window() { ...@@ -1567,12 +1578,11 @@ export default function Window() {
winData = await windowStage.createSubWindow('testSetUIContentCb001'); winData = await windowStage.createSubWindow('testSetUIContentCb001');
expect(!!winData).assertTrue(); expect(!!winData).assertTrue();
try { try {
winData.setUIContent('pages/second/second', async (err) => { winData.setUIContent('TestAbility/pages/index1', async (err) => {
try { try {
if (err.code) { if (err.code) {
console.error('Failed to load the content callback. Cause:' + JSON.stringify(err)); console.error('Failed to load the content callback. Cause:' + JSON.stringify(err));
expect().assertFail(); expect().assertFail();
} else { } else {
console.info('Succeeded in loading the content.'); console.info('Succeeded in loading the content.');
expect(TRUE_FLAG).assertTrue(); expect(TRUE_FLAG).assertTrue();
...@@ -1585,7 +1595,11 @@ export default function Window() { ...@@ -1585,7 +1595,11 @@ export default function Window() {
}); });
} catch (exception) { } catch (exception) {
console.error('Failed callback to load the content. Cause:' + JSON.stringify(exception)); console.error('Failed callback to load the content. Cause:' + JSON.stringify(exception));
expect().assertFail(); try {
expect().assertFail();
} catch (err) {
console.error('Failed callback to load the content. Cause:' + JSON.stringify(err));
}
await winData.destroyWindow(); await winData.destroyWindow();
done(); done();
} }
...@@ -1867,7 +1881,7 @@ export default function Window() { ...@@ -1867,7 +1881,7 @@ export default function Window() {
let wnd = windowStage.getMainWindowSync(); let wnd = windowStage.getMainWindowSync();
expect(wnd != null).assertTrue(); expect(wnd != null).assertTrue();
await wnd.setWindowBrightness(Number.MIN_VALUE).then(() => { await wnd.setWindowBrightness(Number.MIN_VALUE).then(() => {
console.info('windowTest setWindowBrightnessTest3 setBrightness(Number.MAX_VALUE) success '); console.info('windowTest setWindowBrightnessTest4 setBrightness(Number.MIN_VALUE) success ');
expect(TRUE_FLAG).assertTrue(); expect(TRUE_FLAG).assertTrue();
done(); done();
}, (err) => { }, (err) => {
...@@ -2075,7 +2089,7 @@ export default function Window() { ...@@ -2075,7 +2089,7 @@ export default function Window() {
} }
done(); done();
} else { } else {
console.info('windowTest setBrightnessTest4CallBack setBrightness(Number.MAX_VALUE) success '); console.info('windowTest setBrightnessTest4CallBack setBrightness(Number.MIN_VALUE) success ');
try { try {
expect(TRUE_FLAG).assertTrue(); expect(TRUE_FLAG).assertTrue();
} catch (error) { } catch (error) {
...@@ -2113,7 +2127,7 @@ export default function Window() { ...@@ -2113,7 +2127,7 @@ export default function Window() {
} }
done(); done();
} else { } else {
console.info('windowTest setBrightnessTest5CallBack setBrightness(Number.MAX_VALUE) success '); console.info('windowTest setBrightnessTest5CallBack setBrightness(1.1) success ');
try { try {
expect().assertFail(); expect().assertFail();
} catch (error) { } catch (error) {
...@@ -2187,7 +2201,7 @@ export default function Window() { ...@@ -2187,7 +2201,7 @@ export default function Window() {
console.info('windowTest testSetWindowKeepScreenOnCb001 begin'); console.info('windowTest testSetWindowKeepScreenOnCb001 begin');
let wnd = windowStage.getMainWindowSync(); let wnd = windowStage.getMainWindowSync();
expect(wnd != null).assertTrue(); expect(wnd != null).assertTrue();
wnd.setWindowKeepScreenOn(true, (err, data) => { wnd.setWindowKeepScreenOn(true, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err));
try { try {
...@@ -2197,7 +2211,7 @@ export default function Window() { ...@@ -2197,7 +2211,7 @@ export default function Window() {
} }
done(); done();
} else { } else {
console.info('success set the screen to be always on. Cause: ' + JSON.stringify(data)); console.info('success set the screen to be always on.');
let data2 = wnd.getWindowProperties(); let data2 = wnd.getWindowProperties();
try { try {
expect(data2.isKeepScreenOn).assertTrue(); expect(data2.isKeepScreenOn).assertTrue();
...@@ -2220,7 +2234,7 @@ export default function Window() { ...@@ -2220,7 +2234,7 @@ export default function Window() {
console.info('windowTest testSetWindowKeepScreenOnCb002 begin'); console.info('windowTest testSetWindowKeepScreenOnCb002 begin');
let wnd = windowStage.getMainWindowSync(); let wnd = windowStage.getMainWindowSync();
expect(wnd != null).assertTrue(); expect(wnd != null).assertTrue();
wnd.setWindowKeepScreenOn(false, (err, data) => { wnd.setWindowKeepScreenOn(false, (err) => {
if (err.code) { if (err.code) {
console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err));
try { try {
...@@ -2230,7 +2244,7 @@ export default function Window() { ...@@ -2230,7 +2244,7 @@ export default function Window() {
} }
done(); done();
} else { } else {
console.info('success set the screen to be always on. Cause: ' + JSON.stringify(data)); console.info('success set the screen to be always on. ');
let data2 = wnd.getWindowProperties(); let data2 = wnd.getWindowProperties();
try { try {
expect(!data2.isKeepScreenOn).assertTrue(); expect(!data2.isKeepScreenOn).assertTrue();
......
...@@ -13,19 +13,23 @@ ...@@ -13,19 +13,23 @@
* limitations under the License. * limitations under the License.
*/ */
import window from '@ohos.window';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function WindowStage() { export default function WindowStage() {
describe("WindowStage", function () { describe("WindowStage", function () {
let windowStage; let windowStage;
let abilityStorage; let storage;
const TRUE_FLAG = true; const TRUE_FLAG = true;
function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time))
}
beforeAll(async function () { beforeAll(async function () {
console.info("beforeAll case"); console.info("beforeAll case");
windowStage = globalThis.windowStage; windowStage = globalThis.windowStage;
abilityStorage = globalThis.abilityStorage; storage = new LocalStorage();
storage.setOrCreate('storageSimpleProp', 121);
}); });
beforeEach(async function () { beforeEach(async function () {
...@@ -40,16 +44,6 @@ export default function WindowStage() { ...@@ -40,16 +44,6 @@ export default function WindowStage() {
console.info("afterAll case"); console.info("afterAll case");
}); });
async function sleep(time) {
let timeoutId = null;
let promise = new Promise(resolve => {
timeoutId = setTimeout(() => {
resolve('sleep finished');
}, time);
})
clearTimeout(timeoutId)
}
function expectedError(error, caseName, apiName, done, code) { function expectedError(error, caseName, apiName, done, code) {
let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: '; let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: ';
console.log(msgStr + JSON.stringify(error)); console.log(msgStr + JSON.stringify(error));
...@@ -66,15 +60,13 @@ export default function WindowStage() { ...@@ -66,15 +60,13 @@ export default function WindowStage() {
let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: '; let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: ';
console.log(msgStr + JSON.stringify(error)); console.log(msgStr + JSON.stringify(error));
try { try {
expect().assertFail();
expect(TRUE_FLAG).assertFail();
} catch (error) { } catch (error) {
console.info(`unexpectedError catch error: ${JSON.stringify(error)}`) console.info(`unexpectedError catch error: ${JSON.stringify(error)}`)
} }
done(); done();
} }
/** /**
* @tc.number : TEST_GETMAINWINDOW_PROMISE_001 * @tc.number : TEST_GETMAINWINDOW_PROMISE_001
* @tc.name : testGetMainWindowPromise001 * @tc.name : testGetMainWindowPromise001
...@@ -109,12 +101,15 @@ export default function WindowStage() { ...@@ -109,12 +101,15 @@ export default function WindowStage() {
windowStage.getMainWindow((err, data) => { windowStage.getMainWindow((err, data) => {
if (err.code) { if (err.code) {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done); unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
expect(false).assertTrue(); return;
}
try {
expect(!!data).assertTrue();
console.log(msgStr + 'getMainWindow success');
done(); done();
} catch (err) {
unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
} }
expect(!!data).assertTrue();
console.log(msgStr + 'getMainWindow success');
done();
}) })
}) })
/** /**
...@@ -152,14 +147,14 @@ export default function WindowStage() { ...@@ -152,14 +147,14 @@ export default function WindowStage() {
let caseName = 'testCreateSubWindowPromise001'; let caseName = 'testCreateSubWindowPromise001';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let subWindow = await windowStage.createSubWindow('createSubWindow').catch((err) => { let subWindow = await windowStage.createSubWindow('testCreateSubWindowPromise001').catch((err) => {
unexpectedError(err, caseName, 'windowStage.createSubWindow', done); unexpectedError(err, caseName, 'windowStage.createSubWindow', done);
console.log(msgStr + 'windowStage.createSubWindow(createSubWindowTest1)=' + JSON.stringify(err)); console.log(msgStr + 'windowStage.createSubWindow(createSubWindowTest1)=' + JSON.stringify(err));
}); });
expect(!!subWindow).assertTrue(); expect(!!subWindow).assertTrue();
await subWindow.destroy();
console.log(msgStr + 'windowStage.createSubWindow end subWindow=' + JSON.stringify(subWindow)); console.log(msgStr + 'windowStage.createSubWindow end subWindow=' + JSON.stringify(subWindow));
console.log(msgStr + 'windowStage.createSubWindow end !!subWindow=' + !!subWindow); console.log(msgStr + 'windowStage.createSubWindow end !!subWindow=' + !!subWindow);
await subWindow.destroyWindow();
done(); done();
}) })
/** /**
...@@ -180,8 +175,7 @@ export default function WindowStage() { ...@@ -180,8 +175,7 @@ export default function WindowStage() {
console.log(msgStr + 'windowStage.createSubWindow(null) err=' + JSON.stringify(err)); console.log(msgStr + 'windowStage.createSubWindow(null) err=' + JSON.stringify(err));
}); });
console.log(msgStr + 'windowStage.createSubWindow end subWindow=' + JSON.stringify(subWindow)); console.log(msgStr + 'windowStage.createSubWindow end subWindow=' + JSON.stringify(subWindow));
} } catch (err) {
catch (err) {
expectedError(err, caseName, 'windowStage.createSubWindow', done, 401); expectedError(err, caseName, 'windowStage.createSubWindow', done, 401);
console.log(msgStr + 'windowStage.createSubWindow catch err=' + JSON.stringify(err)); console.log(msgStr + 'windowStage.createSubWindow catch err=' + JSON.stringify(err));
} }
...@@ -199,70 +193,19 @@ export default function WindowStage() { ...@@ -199,70 +193,19 @@ export default function WindowStage() {
let caseName = 'testCreateSubWindowCb001'; let caseName = 'testCreateSubWindowCb001';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let subWnd = null
function createSubWindow() {
return new Promise(function (resolve, reject) {
windowStage.createSubWindow('createSubWindow', (err, data) => {
if (err && err.code) {
reject(null)
console.log(msgStr + 'windowStage.createSubWindow(createSubWindowTest3) err=' + JSON.stringify(err));
} else {
resolve(data)
}
})
})
}
function findWin() {
return new Promise(function (resolve, reject) {
window.find('createSubWindow', (err, data) => {
if (err && err.code) {
reject(false)
} else {
resolve(data)
}
})
})
}
function destroyWin(win) { windowStage.createSubWindow('testCreateSubWindowCb001', async (err, data) => {
return new Promise(function (resolve, reject) { if (err && err.code) {
win.destroy((err, data) => { unexpectedError(err, caseName, 'windowStage.createSubWindow', done);
if (err && err.code) { } else {
reject(null) try {
} else { expect(!!data).assertTrue();
resolve(true) console.log(msgStr + ' success');
} done();
}) } catch (err) {
}) unexpectedError(err, caseName, 'windowStage.getMainWindow', done);
} }
}
subWnd = await createSubWindow().catch(err => {
console.info(`window.create failed error: ${JSON.stringify(err)}`)
expect().assertFail();
done();
})
expect(!!subWnd).assertTrue();
let subWindow;
subWindow = await findWin().catch(err => {
console.info(`window.find failed error: ${JSON.stringify(err)}`)
expect().assertFail();
done();
})
await destroyWin(subWindow).catch(err => {
console.info(`window.destroy failed error: ${JSON.stringify(err)}`)
expect().assertFail();
done();
})
let subWindowLast;
subWindowLast = await findWin().catch(err => {
console.info(`window.find failed error: ${JSON.stringify(err)}`)
expect(!err).assertTrue();
done()
}) })
}) })
/** /**
...@@ -359,12 +302,17 @@ export default function WindowStage() { ...@@ -359,12 +302,17 @@ export default function WindowStage() {
let caseName = 'testLoadContentPromise001'; let caseName = 'testLoadContentPromise001';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let load3 = await windowStage.loadContent('MainAbility/pages/second/second').catch((err) => { await sleep(500);
await windowStage.loadContent('TestAbility/pages/Index1').then(async () => {
expect(true).assertTrue();
await sleep(500);
await windowStage.loadContent('TestAbility/pages/Index')
await sleep(500);
console.log(msgStr + 'tempWnd.loadContent success');
done();
}).catch((err) => {
unexpectedError(err, caseName, 'windowStage loadContent', done); unexpectedError(err, caseName, 'windowStage loadContent', done);
console.log(msgStr + 'windowStage loadContent MainAbility/pages/second/second' + JSON.stringify(err));
}); });
expect(!load3).assertTrue();
console.log(msgStr + 'tempWnd.loadContent end load=' + JSON.stringify(load3));
done(); done();
}) })
/** /**
...@@ -380,11 +328,11 @@ export default function WindowStage() { ...@@ -380,11 +328,11 @@ export default function WindowStage() {
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
try { try {
let load4 = await windowStage.loadContent(null).catch((err) => { let load = await windowStage.loadContent(null).catch((err) => {
expect(false).assertTrue(); expect(false).assertTrue();
console.log(msgStr + 'windowStage loadContent null' + JSON.stringify(err)); console.log(msgStr + 'windowStage loadContent null' + JSON.stringify(err));
}); });
console.log(msgStr + 'windowStage loadContent end load5=' + JSON.stringify(load4)); console.log(msgStr + 'windowStage loadContent end load=' + JSON.stringify(load));
} }
catch (err) { catch (err) {
console.log(msgStr + 'windowStage loadContent catch err=' + JSON.stringify(err)); console.log(msgStr + 'windowStage loadContent catch err=' + JSON.stringify(err));
...@@ -395,7 +343,7 @@ export default function WindowStage() { ...@@ -395,7 +343,7 @@ export default function WindowStage() {
/** /**
* @tc.number : TEST_LOADCONTENT_PROMISE_003 * @tc.number : TEST_LOADCONTENT_PROMISE_003
* @tc.name : testLoadContentPromise003 * @tc.name : testLoadContentPromise003
* @tc.desc : Verify the scenario of loading an null page with abilityStorage * @tc.desc : Verify the scenario of loading an null page with storage
* @tc.size : MediumTest * @tc.size : MediumTest
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 2 * @tc.level : Level 2
...@@ -405,11 +353,11 @@ export default function WindowStage() { ...@@ -405,11 +353,11 @@ export default function WindowStage() {
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
try { try {
let load5 = await windowStage.loadContent(null, abilityStorage).catch((err) => { let load = await windowStage.loadContent(null, storage).catch((err) => {
expect(false).assertTrue(); expect(false).assertTrue();
console.log(msgStr + 'windowStage loadContent null' + JSON.stringify(err)); console.log(msgStr + 'windowStage loadContent null' + JSON.stringify(err));
}); });
console.log(msgStr + 'windowStage loadContent end load5=' + JSON.stringify(load5)); console.log(msgStr + 'windowStage loadContent end load=' + JSON.stringify(load));
} }
catch (err) { catch (err) {
console.log(msgStr + 'windowStage loadContent catch err=' + JSON.stringify(err)); console.log(msgStr + 'windowStage loadContent catch err=' + JSON.stringify(err));
...@@ -420,7 +368,7 @@ export default function WindowStage() { ...@@ -420,7 +368,7 @@ export default function WindowStage() {
/** /**
* @tc.number : TEST_LOADCONTENT_PROMISE_004 * @tc.number : TEST_LOADCONTENT_PROMISE_004
* @tc.name : testLoadContentPromise004 * @tc.name : testLoadContentPromise004
* @tc.desc : Verify the scenario of loading an page and abilityStorage of null * @tc.desc : Verify the scenario of loading an page and storage of null
* @tc.size : MediumTest * @tc.size : MediumTest
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 2 * @tc.level : Level 2
...@@ -429,11 +377,17 @@ export default function WindowStage() { ...@@ -429,11 +377,17 @@ export default function WindowStage() {
let caseName = 'testLoadContentPromise004'; let caseName = 'testLoadContentPromise004';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let load6 = await windowStage.loadContent('MainAbility/pages/second/second', null).catch((err) => { await sleep(500);
await windowStage.loadContent('TestAbility/pages/Index1', null).then(async () => {
expect(true).assertTrue();
await sleep(500);
await windowStage.loadContent('TestAbility/pages/Index')
await sleep(500);
console.log(msgStr + 'tempWnd.loadContent success');
done();
}).catch((err) => {
unexpectedError(err, caseName, 'windowStage loadContent', done); unexpectedError(err, caseName, 'windowStage loadContent', done);
console.log(msgStr + 'windowStage loadContent MainAbility/pages/second/second' + JSON.stringify(err));
}); });
expect(!load6).assertTrue();
done(); done();
}) })
...@@ -449,18 +403,21 @@ export default function WindowStage() { ...@@ -449,18 +403,21 @@ export default function WindowStage() {
let caseName = 'testLoadContentCb001'; let caseName = 'testLoadContentCb001';
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
windowStage.loadContent('MainAbility/pages/second/second', (err, data) => { await sleep(500);
windowStage.loadContent('TestAbility/pages/Index1', async (err) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(err, caseName, 'windowStage.loadContent', done); unexpectedError(err, caseName, 'windowStage.loadContent', done);
console.log(msgStr + 'windowStage loadContent MainAbility/pages/second/second' + JSON.stringify(err));
} else { } else {
try { try {
expect(!data).assertTrue(); expect(true).assertTrue();
} catch (error) { await sleep(500);
console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) await windowStage.loadContent('TestAbility/pages/Index')
await sleep(500);
console.log(msgStr + 'tempWnd.loadContent success');
done();
} catch (err) {
unexpectedError(err, caseName, 'windowStage.loadContent', done);
} }
console.log(msgStr + 'windowStage.loadContent end data=' + JSON.stringify(data));
done();
} }
}) })
}) })
...@@ -478,7 +435,7 @@ export default function WindowStage() { ...@@ -478,7 +435,7 @@ export default function WindowStage() {
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
try { try {
windowStage.loadContent(null, (err, data) => { windowStage.loadContent(null, (err) => {
console.log(msgStr + 'windowStage loadContent null' + JSON.stringify(err)); console.log(msgStr + 'windowStage loadContent null' + JSON.stringify(err));
try { try {
expect(false).assertTrue(); expect(false).assertTrue();
...@@ -502,7 +459,7 @@ export default function WindowStage() { ...@@ -502,7 +459,7 @@ export default function WindowStage() {
/** /**
* @tc.number : TEST_LOADCONTENT_STORAGE_CB_001 * @tc.number : TEST_LOADCONTENT_STORAGE_CB_001
* @tc.name : testLoadContentStorageCb001 * @tc.name : testLoadContentStorageCb001
* @tc.desc : Verify the scenario of loading an page and abilityStorage * @tc.desc : Verify the scenario of loading an page and storage
* @tc.size : MediumTest * @tc.size : MediumTest
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 2 * @tc.level : Level 2
...@@ -512,25 +469,27 @@ export default function WindowStage() { ...@@ -512,25 +469,27 @@ export default function WindowStage() {
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
windowStage.loadContent('MainAbility/pages/second/second', abilityStorage, (err, data) => { windowStage.loadContent('TestAbility/pages/Index1', storage, async (err) => {
if (err && err.code) { if (err && err.code) {
unexpectedError(err, caseName, 'windowStage.loadContent', done); unexpectedError(err, caseName, 'windowStage.loadContent', done);
console.log(msgStr + 'windowStage loadContent MainAbility/pages/second/second' + JSON.stringify(err));
} else { } else {
try { try {
expect(!data).assertTrue(); expect(true).assertTrue();
} catch (error) { await sleep(500);
console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) await windowStage.loadContent('TestAbility/pages/Index')
await sleep(500);
console.log(msgStr + 'tempWnd.loadContent success');
done();
} catch (err) {
unexpectedError(err, caseName, 'windowStage.loadContent', done);
} }
done();
console.log(msgStr + 'windowStage.loadContent end data=' + JSON.stringify(data));
} }
}) })
}) })
/** /**
* @tc.number : TEST_LOADCONTENT_STORAGE_CB_002 * @tc.number : TEST_LOADCONTENT_STORAGE_CB_002
* @tc.name : testLoadContentStorageCb002 * @tc.name : testLoadContentStorageCb002
* @tc.desc : Verify the scenario of loading an null page with abilityStorage * @tc.desc : Verify the scenario of loading an null page with storage
* @tc.size : MediumTest * @tc.size : MediumTest
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 2 * @tc.level : Level 2
...@@ -541,7 +500,7 @@ export default function WindowStage() { ...@@ -541,7 +500,7 @@ export default function WindowStage() {
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
try { try {
windowStage.loadContent(null, abilityStorage, (err, data) => { windowStage.loadContent(null, storage, (err) => {
console.log(msgStr + 'windowStage loadContent null ' + JSON.stringify(err)); console.log(msgStr + 'windowStage loadContent null ' + JSON.stringify(err));
try { try {
expect(false).assertTrue(); expect(false).assertTrue();
......
{ {
"src": [ "src": [
"TestAbility/pages/Index" "TestAbility/pages/Index",
"TestAbility/pages/Index1"
] ]
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册