diff --git a/graphic/BUILD.gn b/graphic/BUILD.gn index 7d70e74ed1cd77df44b9dc8a489a31ca9b6f0f48..1eab54cab6686a2be17adc4bbc3099b99e766e28 100755 --- a/graphic/BUILD.gn +++ b/graphic/BUILD.gn @@ -16,7 +16,7 @@ group("graphic") { testonly = true if (is_standard_system) { deps = [ - "crossplatform/window:window_ets_normal_test", + "crossplatform/window:ActsCrossplatformWindowTest", "effectKit:EffectKitTest", "graphicColorSpace:ActsColorSpaceManagerTest", "graphicnapidrawingtest:ActsGraphicNapiDrawingTest", diff --git a/graphic/crossplatform/window/AppScope/app.json b/graphic/crossplatform/window/AppScope/app.json index c39ac0e1bdfbe9a6dfaaf2296beb3ca15ad7c7ec..78b4ece4056229056fc3f030df9e43063ac077c2 100644 --- a/graphic/crossplatform/window/AppScope/app.json +++ b/graphic/crossplatform/window/AppScope/app.json @@ -6,10 +6,10 @@ "versionName": "1.0.0", "icon": "$media:app_icon", "label": "$string:app_name", - "minAPIVersion": 9, - "targetAPIVersion": 9, + "minAPIVersion": 10, + "targetAPIVersion": 10, "car": { - "apiCompatibleVersion": 9, + "apiCompatibleVersion": 10, "singleUser": false } } diff --git a/graphic/crossplatform/window/BUILD.gn b/graphic/crossplatform/window/BUILD.gn index bb574fbe98acb8edafde1e31ca1429a38165febc..e186fde88cdc534997e58bda7cbb1fd22bfd7172 100644 --- a/graphic/crossplatform/window/BUILD.gn +++ b/graphic/crossplatform/window/BUILD.gn @@ -13,7 +13,7 @@ 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" deps = [ ":windowStage_js_assets", @@ -21,7 +21,7 @@ ohos_js_hap_suite("window_ets_normal_test") { ] ets2abc = true certificate_profile = "./signature/openharmony_sx.p7b" - hap_name = "ActsWindowTest" + hap_name = "ActsCrossplatformWindowTest" subsystem_name = "window" part_name = "window_manager" } @@ -36,4 +36,4 @@ ohos_resources("windowStage_resources") { sources = [ "src/main/resources" ] deps = [ ":windowStage_app_profile" ] hap_profile = "src/main/module.json" -} \ No newline at end of file +} diff --git a/graphic/crossplatform/window/Test.json b/graphic/crossplatform/window/Test.json index 0cf0df8d0a2088c8aa12d5732b71a09c9de21ef7..368cdd3692dc912ba671ddd77762c97cbc8e6dc2 100644 --- a/graphic/crossplatform/window/Test.json +++ b/graphic/crossplatform/window/Test.json @@ -6,12 +6,12 @@ "shell-timeout": "300000", "bundle-name": "ohos.acts.graphic.crossplatform.window", "module-name": "window", - "testcase-timeout": 5000 + "testcase-timeout": 10000 }, "kits": [ { "test-file-name": [ - "ActsWindowTest.hap" + "ActsCrossplatformWindowTest.hap" ], "type": "AppInstallKit", "cleanup-apps": true diff --git a/graphic/crossplatform/window/src/main/ets/TestAbility/pages/Index1.ets b/graphic/crossplatform/window/src/main/ets/TestAbility/pages/Index1.ets new file mode 100644 index 0000000000000000000000000000000000000000..c16ed555635cdffd7e87be1c553e9163b77f0163 --- /dev/null +++ b/graphic/crossplatform/window/src/main/ets/TestAbility/pages/Index1.ets @@ -0,0 +1,28 @@ +/* + * 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 diff --git a/graphic/crossplatform/window/src/main/ets/test/Window.test.ets b/graphic/crossplatform/window/src/main/ets/test/Window.test.ets index d0e901e81881cb54e2087c93679267b03ffbfe46..715c0b03bab0accae7dfc08d9670d57d770e67bc 100644 --- a/graphic/crossplatform/window/src/main/ets/test/Window.test.ets +++ b/graphic/crossplatform/window/src/main/ets/test/Window.test.ets @@ -23,6 +23,10 @@ export default function Window() { let storage; const TRUE_FLAG = true; + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)) + } + beforeAll(async function () { console.info("beforeAll case"); context = globalThis.abilityContext; @@ -172,7 +176,11 @@ export default function Window() { return; } 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(); done(); }) @@ -197,8 +205,9 @@ export default function Window() { try { tempWnd = await windowStage.createSubWindow('testShowWindowPromise001'); expect(!!tempWnd).assertTrue(); - await tempWnd.showWindow().then(async (data) => { - console.info(msgStr + 'Succeeded in showing the window. Data: ' + JSON.stringify(data)); + await tempWnd.showWindow().then(async () => { + expect(TRUE_FLAG).assertTrue(); + console.info(msgStr + 'Succeeded in showing the window. '); await tempWnd.destroyWindow(); done(); }).catch((err) => { @@ -227,7 +236,7 @@ export default function Window() { let winData; winData = await windowStage.createSubWindow('testShowWindowCb001'); expect(!!winData).assertTrue(); - winData.showWindow(async (err, data) => { + winData.showWindow(async (err) => { if (err.code) { console.error(msgStr + 'Failed to show the window. Cause: ' + JSON.stringify(err)); try { @@ -238,7 +247,8 @@ export default function Window() { done(); 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(); done(); }) @@ -314,7 +324,11 @@ export default function Window() { expect(!findWnd).assertTrue(); } catch (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(); @@ -520,7 +534,7 @@ export default function Window() { expect(!!winData).assertTrue(); try { await winData.showWindow(); - winData.moveWindowTo(300, 300, async (err, data) => { + winData.moveWindowTo(300, 300, async (err) => { if (err.code) { console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); try { @@ -532,7 +546,7 @@ export default function Window() { done(); return; } - console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); + console.info(msgStr + 'Succeeded in moving the window. '); await winData.destroyWindow(); done(); }) @@ -559,7 +573,7 @@ export default function Window() { expect(!!winData).assertTrue(); try { await winData.showWindow(); - winData.moveWindowTo(100, 50, async (err, data) => { + winData.moveWindowTo(100, 50, async (err) => { if (err.code) { console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); try { @@ -571,7 +585,7 @@ export default function Window() { done(); return; } - console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); + console.info(msgStr + 'Succeeded in moving the window. '); await winData.destroyWindow(); done(); }) @@ -598,7 +612,7 @@ export default function Window() { expect(!!winData).assertTrue(); try { await winData.showWindow(); - winData.moveWindowTo(20000, 20000, async (err, data) => { + winData.moveWindowTo(20000, 20000, async (err) => { if (err.code) { console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); try { @@ -610,7 +624,7 @@ export default function Window() { done(); return; } - console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); + console.info(msgStr + 'Succeeded in moving the window. '); await winData.destroyWindow(); done(); }) @@ -637,7 +651,7 @@ export default function Window() { expect(!!winData).assertTrue(); try { await winData.showWindow(); - winData.moveWindowTo(-200, -200, async (err, data) => { + winData.moveWindowTo(-200, -200, async (err) => { if (err.code) { console.error(msgStr + 'Failed to move the window. Cause:' + JSON.stringify(err)); try { @@ -649,7 +663,7 @@ export default function Window() { done(); return; } - console.info(msgStr + 'Succeeded in moving the window. Data: ' + JSON.stringify(data)); + console.info(msgStr + 'Succeeded in moving the window.'); await winData.destroyWindow(); done(); }) @@ -1239,7 +1253,7 @@ export default function Window() { expect(!!mainWin).assertTrue(); let num = 0 let orientationItem = ['UNSPECIFIED', 'PORTRAIT', 'LANDSCAPE', 'PORTRAIT_INVERTED', - 'LANDSCAPE_INVERTED']; + 'LANDSCAPE_INVERTED', 'UNSPECIFIED']; for (let i = 0; i < orientationItem.length; i++) { let orientation = window.Orientation[orientationItem[i]] console.log(msgStr + 'i : ' + i + ' ,orientation : ' + orientation); @@ -1249,8 +1263,9 @@ export default function Window() { num++ if (num == orientationItem.length) done(); }).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() { let orientation = window.Orientation[orientationItem[i]] await setPreferredOrientationFun(mainWin, orientation).catch((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(); }); console.info(msgStr + 'Succeeded in setting window orientation. orientation: ' + orientation + "step: " + i); @@ -1322,14 +1341,14 @@ export default function Window() { tempWnd = await windowStage.createSubWindow(windowId); expect(!!tempWnd).assertTrue(); 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); - 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 @@ -1348,15 +1367,13 @@ export default function Window() { tempWnd = await windowStage.createSubWindow(windowId); expect(!!tempWnd).assertTrue(); console.log(msgStr + 'tempWnd.loadContent start'); - await tempWnd.destroyWindow(); - let errFlag = false; try { await tempWnd.loadContent(null, storage); expect().assertFail(); done(); } catch (err) { - errFlag = true; expectedError(err, caseName, 'tempWnd.loadContent', done, 401); + await tempWnd.destroyWindow(); console.log(msgStr + 'tempWnd.loadContent(null)' + JSON.stringify(err)); } }) @@ -1378,17 +1395,19 @@ export default function Window() { tempWnd = await windowStage.createSubWindow(windowId); expect(!!tempWnd).assertTrue(); - tempWnd.loadContent('pages/index', storage, async (err, data) => { + tempWnd.loadContent('TestAbility/pages/index1', storage, async (err) => { if (err && err.code) { unexpectedError(err, caseName, 'tempWnd.loadContent', done); } else { try { - expect(!data).assertTrue(); + console.log(msgStr + 'tempWnd.loadContent() success'); + expect(TRUE_FLAG).assertTrue(); + done(); } catch (error) { console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`) + done() } await tempWnd.destroyWindow(); - done() } }) }) @@ -1409,7 +1428,7 @@ export default function Window() { tempWnd = await windowStage.createSubWindow(windowId); expect(!!tempWnd).assertTrue(); try { - tempWnd.loadContent(null, storage, async (err, data) => { + tempWnd.loadContent(null, storage, async (err) => { if (err && err.code) { try { expect(err.code === 401).assertTrue(); @@ -1434,7 +1453,7 @@ export default function Window() { } }) /** - * @tc.number : testGetUIContext001 + * @tc.number : TEST_GETUICONTEXT_001 * @tc.name : testGetUIContext001 * @tc.desc : test getUIContext * @tc.size : MediumTest @@ -1442,20 +1461,12 @@ export default function Window() { * @tc.level : Level 2 */ it('testGetUIContext001', 0, async function (done) { - windowStage.getMainWindow((err, data) => { - if (err.code) { - console.error('testGetUIContext001 Failed to obtain the main window. Cause: ' + JSON.stringify(err)); - expect(false).assertTrue(); - done() - } else { - 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(); - } - }) + let tempWnd = await windowStage.getMainWindow(); + expect(!!tempWnd).assertTrue(); + let UIContext = tempWnd.getUIContext(); + expect(UIContext != undefined).assertTrue(); + console.info('testGetUIContext001 Succeeded'); + done(); }) /** * @tc.number : TEST_SETUICONTENT_PROMISE_001 @@ -1470,7 +1481,7 @@ export default function Window() { try { win = await windowStage.createSubWindow('testSetUIContentPromise001'); expect(win != null); - await win.setUIContent('pages/second/second').then(async () => { + await win.setUIContent('TestAbility/pages/index1').then(async () => { console.info('setUIContent1 . Cause: success'); expect(TRUE_FLAG).assertTrue(); await win.destroyWindow(); @@ -1537,7 +1548,7 @@ export default function Window() { try { win = await windowStage.createSubWindow('testSetUIContentPromise003'); expect(win != null).assertTrue(); - await win.setUIContent('pages/second/he').then(async () => { + await win.setUIContent('wrong pages').then(async () => { console.info('setUIContent3 . Cause: success'); expect(TRUE_FLAG).assertTrue(); await win.destroyWindow(); @@ -1567,12 +1578,11 @@ export default function Window() { winData = await windowStage.createSubWindow('testSetUIContentCb001'); expect(!!winData).assertTrue(); try { - winData.setUIContent('pages/second/second', async (err) => { + winData.setUIContent('TestAbility/pages/index1', async (err) => { try { if (err.code) { console.error('Failed to load the content callback. Cause:' + JSON.stringify(err)); expect().assertFail(); - } else { console.info('Succeeded in loading the content.'); expect(TRUE_FLAG).assertTrue(); @@ -1585,7 +1595,11 @@ export default function Window() { }); } catch (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(); done(); } @@ -1867,7 +1881,7 @@ export default function Window() { let wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); 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(); done(); }, (err) => { @@ -2075,7 +2089,7 @@ export default function Window() { } done(); } else { - console.info('windowTest setBrightnessTest4CallBack setBrightness(Number.MAX_VALUE) success '); + console.info('windowTest setBrightnessTest4CallBack setBrightness(Number.MIN_VALUE) success '); try { expect(TRUE_FLAG).assertTrue(); } catch (error) { @@ -2113,7 +2127,7 @@ export default function Window() { } done(); } else { - console.info('windowTest setBrightnessTest5CallBack setBrightness(Number.MAX_VALUE) success '); + console.info('windowTest setBrightnessTest5CallBack setBrightness(1.1) success '); try { expect().assertFail(); } catch (error) { @@ -2187,7 +2201,7 @@ export default function Window() { console.info('windowTest testSetWindowKeepScreenOnCb001 begin'); let wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); - wnd.setWindowKeepScreenOn(true, (err, data) => { + wnd.setWindowKeepScreenOn(true, (err) => { if (err.code) { console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); try { @@ -2197,7 +2211,7 @@ export default function Window() { } done(); } 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(); try { expect(data2.isKeepScreenOn).assertTrue(); @@ -2220,7 +2234,7 @@ export default function Window() { console.info('windowTest testSetWindowKeepScreenOnCb002 begin'); let wnd = windowStage.getMainWindowSync(); expect(wnd != null).assertTrue(); - wnd.setWindowKeepScreenOn(false, (err, data) => { + wnd.setWindowKeepScreenOn(false, (err) => { if (err.code) { console.error('Failed to set the screen to be always on. Cause: ' + JSON.stringify(err)); try { @@ -2230,7 +2244,7 @@ export default function Window() { } done(); } 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(); try { expect(!data2.isKeepScreenOn).assertTrue(); diff --git a/graphic/crossplatform/window/src/main/ets/test/WindowStage.test.ets b/graphic/crossplatform/window/src/main/ets/test/WindowStage.test.ets index f22f01eb74bce9782b2aee1012fd66460d73e735..ce3977f9102dd2c089e7c37f4210353a3b7e461b 100644 --- a/graphic/crossplatform/window/src/main/ets/test/WindowStage.test.ets +++ b/graphic/crossplatform/window/src/main/ets/test/WindowStage.test.ets @@ -13,19 +13,23 @@ * limitations under the License. */ -import window from '@ohos.window'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; export default function WindowStage() { describe("WindowStage", function () { let windowStage; - let abilityStorage; + let storage; const TRUE_FLAG = true; + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)) + } + beforeAll(async function () { console.info("beforeAll case"); windowStage = globalThis.windowStage; - abilityStorage = globalThis.abilityStorage; + storage = new LocalStorage(); + storage.setOrCreate('storageSimpleProp', 121); }); beforeEach(async function () { @@ -40,16 +44,6 @@ export default function WindowStage() { 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) { let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: '; console.log(msgStr + JSON.stringify(error)); @@ -66,15 +60,13 @@ export default function WindowStage() { let msgStr = 'jsunittest ' + caseName + ' ' + apiName + ' failed, err: '; console.log(msgStr + JSON.stringify(error)); try { - - expect(TRUE_FLAG).assertFail(); + expect().assertFail(); } catch (error) { console.info(`unexpectedError catch error: ${JSON.stringify(error)}`) } done(); } - /** * @tc.number : TEST_GETMAINWINDOW_PROMISE_001 * @tc.name : testGetMainWindowPromise001 @@ -109,12 +101,15 @@ export default function WindowStage() { windowStage.getMainWindow((err, data) => { if (err.code) { unexpectedError(err, caseName, 'windowStage.getMainWindow', done); - expect(false).assertTrue(); + return; + } + try { + expect(!!data).assertTrue(); + console.log(msgStr + 'getMainWindow success'); 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() { let caseName = 'testCreateSubWindowPromise001'; let msgStr = 'jsunittest ' + caseName + ' '; 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); console.log(msgStr + 'windowStage.createSubWindow(createSubWindowTest1)=' + JSON.stringify(err)); }); expect(!!subWindow).assertTrue(); - await subWindow.destroy(); console.log(msgStr + 'windowStage.createSubWindow end subWindow=' + JSON.stringify(subWindow)); console.log(msgStr + 'windowStage.createSubWindow end !!subWindow=' + !!subWindow); + await subWindow.destroyWindow(); done(); }) /** @@ -180,8 +175,7 @@ export default function WindowStage() { console.log(msgStr + 'windowStage.createSubWindow(null) err=' + JSON.stringify(err)); }); console.log(msgStr + 'windowStage.createSubWindow end subWindow=' + JSON.stringify(subWindow)); - } - catch (err) { + } catch (err) { expectedError(err, caseName, 'windowStage.createSubWindow', done, 401); console.log(msgStr + 'windowStage.createSubWindow catch err=' + JSON.stringify(err)); } @@ -199,70 +193,19 @@ export default function WindowStage() { let caseName = 'testCreateSubWindowCb001'; let msgStr = 'jsunittest ' + caseName + ' '; 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) { - return new Promise(function (resolve, reject) { - win.destroy((err, data) => { - if (err && err.code) { - reject(null) - } else { - resolve(true) - } - }) - }) - } - - 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() + windowStage.createSubWindow('testCreateSubWindowCb001', async (err, data) => { + if (err && err.code) { + unexpectedError(err, caseName, 'windowStage.createSubWindow', done); + } else { + try { + expect(!!data).assertTrue(); + console.log(msgStr + ' success'); + done(); + } catch (err) { + unexpectedError(err, caseName, 'windowStage.getMainWindow', done); + } + } }) }) /** @@ -359,12 +302,17 @@ export default function WindowStage() { let caseName = 'testLoadContentPromise001'; let msgStr = 'jsunittest ' + caseName + ' '; 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); - 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(); }) /** @@ -380,11 +328,11 @@ export default function WindowStage() { let msgStr = 'jsunittest ' + caseName + ' '; console.log(msgStr + 'begin'); try { - let load4 = await windowStage.loadContent(null).catch((err) => { + let load = await windowStage.loadContent(null).catch((err) => { expect(false).assertTrue(); 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) { console.log(msgStr + 'windowStage loadContent catch err=' + JSON.stringify(err)); @@ -395,7 +343,7 @@ export default function WindowStage() { /** * @tc.number : TEST_LOADCONTENT_PROMISE_003 * @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.type : Function * @tc.level : Level 2 @@ -405,11 +353,11 @@ export default function WindowStage() { let msgStr = 'jsunittest ' + caseName + ' '; console.log(msgStr + 'begin'); try { - let load5 = await windowStage.loadContent(null, abilityStorage).catch((err) => { + let load = await windowStage.loadContent(null, storage).catch((err) => { expect(false).assertTrue(); 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) { console.log(msgStr + 'windowStage loadContent catch err=' + JSON.stringify(err)); @@ -420,7 +368,7 @@ export default function WindowStage() { /** * @tc.number : TEST_LOADCONTENT_PROMISE_004 * @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.type : Function * @tc.level : Level 2 @@ -429,11 +377,17 @@ export default function WindowStage() { let caseName = 'testLoadContentPromise004'; let msgStr = 'jsunittest ' + caseName + ' '; 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); - console.log(msgStr + 'windowStage loadContent MainAbility/pages/second/second' + JSON.stringify(err)); }); - expect(!load6).assertTrue(); done(); }) @@ -449,18 +403,21 @@ export default function WindowStage() { let caseName = 'testLoadContentCb001'; let msgStr = 'jsunittest ' + caseName + ' '; 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) { unexpectedError(err, caseName, 'windowStage.loadContent', done); - console.log(msgStr + 'windowStage loadContent MainAbility/pages/second/second' + JSON.stringify(err)); } else { try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) + 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); } - console.log(msgStr + 'windowStage.loadContent end data=' + JSON.stringify(data)); - done(); } }) }) @@ -478,7 +435,7 @@ export default function WindowStage() { console.log(msgStr + 'begin'); try { - windowStage.loadContent(null, (err, data) => { + windowStage.loadContent(null, (err) => { console.log(msgStr + 'windowStage loadContent null' + JSON.stringify(err)); try { expect(false).assertTrue(); @@ -502,7 +459,7 @@ export default function WindowStage() { /** * @tc.number : TEST_LOADCONTENT_STORAGE_CB_001 * @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.type : Function * @tc.level : Level 2 @@ -512,25 +469,27 @@ export default function WindowStage() { let msgStr = 'jsunittest ' + caseName + ' '; 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) { unexpectedError(err, caseName, 'windowStage.loadContent', done); - console.log(msgStr + 'windowStage loadContent MainAbility/pages/second/second' + JSON.stringify(err)); } else { try { - expect(!data).assertTrue(); - } catch (error) { - console.info(`windowStage.loadContent catch error: ${JSON.stringify(error)}`) + 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); } - done(); - console.log(msgStr + 'windowStage.loadContent end data=' + JSON.stringify(data)); } }) }) /** * @tc.number : TEST_LOADCONTENT_STORAGE_CB_002 * @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.type : Function * @tc.level : Level 2 @@ -541,7 +500,7 @@ export default function WindowStage() { console.log(msgStr + 'begin'); try { - windowStage.loadContent(null, abilityStorage, (err, data) => { + windowStage.loadContent(null, storage, (err) => { console.log(msgStr + 'windowStage loadContent null ' + JSON.stringify(err)); try { expect(false).assertTrue(); diff --git a/graphic/crossplatform/window/src/main/resources/base/profile/test_pages.json b/graphic/crossplatform/window/src/main/resources/base/profile/test_pages.json index 77e90731b5a38d861663029b483df3d3ac9ec74b..27e58b1181b64282d22b1dcc4784b17bbf1fd16e 100644 --- a/graphic/crossplatform/window/src/main/resources/base/profile/test_pages.json +++ b/graphic/crossplatform/window/src/main/resources/base/profile/test_pages.json @@ -1,5 +1,6 @@ { "src": [ - "TestAbility/pages/Index" + "TestAbility/pages/Index", + "TestAbility/pages/Index1" ] }