diff --git a/graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets b/graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets index 38c4cf75c57d3d62f8d0bed8b7f64e75998c4914..a5075073f82c28dc76dc2293ff7834810a66a0a1 100644 --- a/graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets +++ b/graphic/windowStage/entry/src/main/ets/test/windowCallback.test.ets @@ -1450,5 +1450,64 @@ export default function windowCallbackTest(context, windowStage, abilityStorage) }) }) }) + /** + * @tc.number SUB_WINDOW_SETPREFERREDORIENTATION_JSAPI_001 + * @tc.name Test setPreferredOrientation + * @tc.desc Sets the display direction property of the window + */ + it('setPreferredOrientation', 0, async function (done) { + let caseName = 'setPreferredOrientation'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let mainWin = await windowStage.getMainWindow().catch(err => { + unexpectedError(err, caseName, 'windowStage.getMainWindow', done); + }); + console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin)); + expect(!!mainWin).assertTrue(); + let orientationItem = ['UNSPECIFIED','LOCKED','PORTRAIT_UNSPECIFIED','PORTRAIT','LANDSCAPE','PORTRAIT_INVERTED','LANDSCAPE_INVERTED','AUTO_ROTATION','AUTO_ROTATION_PORTRAIT','AUTO_ROTATION_LANDSCAPE','AUTO_ROTATION_RESTRICTED','AUTO_ROTATION_PORTRAIT_RESTRICTED','AUTO_ROTATION_LANDSCAPE_RESTRICTED']; + for (let i = 0;i < orientationItem.length; i++) { + await sleep(1000); + let orientation=ohosWindow.Orientation[orientationItem[i]] + await mainWin.setPreferredOrientation(orientation,(err,data) => { + if(err.code){ + console.log(msgStr + 'window.setPreferredOrientation failed set error' + orientation); + } + console.log(msgStr + 'success set window.setPreferredOrientation ' + orientation+JSON.stringify(data)); + }) + } + console.log(msgStr + 'done '); + done(); + }) + /** + * @tc.number SUB_WINDOW_SETFORBIDSPLITMOVE_JSAPI_001 + * @tc.name Test setForbidSplitMove + * @tc.desc Sets whether Windows are forbidden to move in split screen mode + */ + it('setForbidSplitMove', 0, async function (done) { + let caseName = 'setForbidSplitMove'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let mainWin = await windowStage.getMainWindow().catch(err => { + unexpectedError(err, caseName, 'windowStage.getMainWindow', done); + }); + console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin)); + expect(!!mainWin).assertTrue(); + await mainWin.setForbidSplitMove(true,(err,data) => { + if(err.code){ + console.log(msgStr + 'failed set window.setForbidSplitMove drag is prohibited'); + return; + } + console.log(msgStr + 'success set window.setForbidSplitMove drag is prohibited'+JSON.stringify(data)); + }) + await mainWin.setForbidSplitMove(false,(err,data) => { + if(err.code){ + console.log(msgStr + 'failed set window.setForbidSplitMove you can drag it now'); + return; + } + console.log(msgStr + 'success set window.setForbidSplitMove you can drag it now'+JSON.stringify(data)); + }) + console.log(msgStr + 'done '); + done(); + }) }) } diff --git a/graphic/windowStage/entry/src/main/ets/test/windowPromise.test.ets b/graphic/windowStage/entry/src/main/ets/test/windowPromise.test.ets index cdf7b91e1793c8c5596715a9041cfa0a410bfe38..76cadd22297a70e7de2f019b35c462e90cd5ebbc 100644 --- a/graphic/windowStage/entry/src/main/ets/test/windowPromise.test.ets +++ b/graphic/windowStage/entry/src/main/ets/test/windowPromise.test.ets @@ -1418,5 +1418,59 @@ export default function windowPromiseTest(context, windowStage, abilityStorage) expect(!isLockedFalse).assertTrue(); done(); }) + /** + * @tc.number SUB_WINDOW_SETPREFERREDORIENTATION_JSAPI_001 + * @tc.name Test setPreferredOrientation + * @tc.desc Sets the display direction property of the window + */ + it('setPreferredOrientation', 0, async function (done) { + let caseName = 'setPreferredOrientation'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let mainWin = await windowStage.getMainWindow().catch(err => { + unexpectedError(err, caseName, 'windowStage.getMainWindow', done); + }); + console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin)); + expect(!!mainWin).assertTrue(); + let orientationItem = ['UNSPECIFIED','LOCKED','PORTRAIT_UNSPECIFIED','PORTRAIT','LANDSCAPE','PORTRAIT_INVERTED','LANDSCAPE_INVERTED','AUTO_ROTATION','AUTO_ROTATION_PORTRAIT','AUTO_ROTATION_LANDSCAPE','AUTO_ROTATION_RESTRICTED','AUTO_ROTATION_PORTRAIT_RESTRICTED','AUTO_ROTATION_LANDSCAPE_RESTRICTED']; + for (let i = 0;i < orientationItem.length; i++) { + await sleep(1000); + let orientation=ohosWindow.Orientation[orientationItem[i]] + await mainWin.setPreferredOrientation(orientation).then(() => { + console.log(msgStr + 'success set window.setPreferredOrientation ' + orientation); + }).catch(err => { + console.log(msgStr + 'window.setPreferredOrientation failed set error' + orientation); + }); + } + console.log(msgStr + 'done '); + done(); + }) + /** + * @tc.number SUB_WINDOW_SETFORBIDSPLITMOVE_JSAPI_001 + * @tc.name Test setForbidSplitMove + * @tc.desc Sets whether Windows are forbidden to move in split screen mode + */ + it('setForbidSplitMove', 0, async function (done) { + let caseName = 'setForbidSplitMove'; + let msgStr = 'jsunittest ' + caseName + ' '; + console.log(msgStr + 'begin'); + let mainWin = await windowStage.getMainWindow().catch(err => { + unexpectedError(err, caseName, 'windowStage.getMainWindow', done); + }); + console.log(msgStr + 'windowStage.getMainWindow' + JSON.stringify(mainWin)); + expect(!!mainWin).assertTrue(); + await mainWin.setForbidSplitMove(true).then(() => { + console.log(msgStr + 'success set window.setForbidSplitMove drag is prohibited'); + }).catch(err => { + console.log(msgStr + 'failed set window.setForbidSplitMove drag is prohibited'); + }); + await mainWin.setForbidSplitMove(false).then(() => { + console.log(msgStr + 'success set window.setForbidSplitMove you can drag it now'); + }).catch(err => { + console.log(msgStr + 'failed set window.setForbidSplitMove you can drag it now'); + }); + console.log(msgStr + 'done '); + done(); + }) }) }