未验证 提交 7a4e0ebf 编写于 作者: O openharmony_ci 提交者: Gitee

!9370 跨平台测试window模块完善修改部分测试用例

Merge pull request !9370 from huyanqiang/master
...@@ -56,7 +56,6 @@ export default function Window() { ...@@ -56,7 +56,6 @@ export default function Window() {
done(); done();
} catch (error) { } catch (error) {
console.info(caseName + " fail: " + error); console.info(caseName + " fail: " + error);
expect().assertFail();
done(); done();
} }
} }
...@@ -137,11 +136,9 @@ export default function Window() { ...@@ -137,11 +136,9 @@ export default function Window() {
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
try { try {
let windowData = await windowStage.createSubWindow('testGetLastWindowPromise001'); await sleep(500);
await windowData.showWindow();
let lastWindow = await window.getLastWindow(context); let lastWindow = await window.getLastWindow(context);
expect(lastWindow != null).assertTrue(); expect(lastWindow != null).assertTrue();
await windowData.destroyWindow();
done(); done();
} catch (exception) { } catch (exception) {
console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(exception));
...@@ -162,8 +159,7 @@ export default function Window() { ...@@ -162,8 +159,7 @@ export default function Window() {
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
try { try {
let windowData = await windowStage.createSubWindow('testGetLastWindowCb001'); await sleep(500);
await windowData.showWindow();
window.getLastWindow(context, async (err, data) => { window.getLastWindow(context, async (err, data) => {
if (err.code) { if (err.code) {
console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(err)); console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(err));
...@@ -181,11 +177,12 @@ export default function Window() { ...@@ -181,11 +177,12 @@ export default function Window() {
} catch (err) { } catch (err) {
console.info(msgStr + "err " + err); console.info(msgStr + "err " + err);
} }
await windowData.destroyWindow();
done(); done();
}) })
} catch (exception) { } catch (exception) {
console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(exception)); console.error(msgStr + 'Failed to obtain the top window. Cause: ' + JSON.stringify(exception));
expect().assertFail();
done();
} }
}) })
...@@ -1017,7 +1014,7 @@ export default function Window() { ...@@ -1017,7 +1014,7 @@ export default function Window() {
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
let wnd = null; let wnd = null;
try { try {
wnd = await window.getLastWindow(context); wnd = windowStage.getMainWindowSync();
expect(wnd != null).assertTrue(); expect(wnd != null).assertTrue();
try { try {
await wnd.setWindowSystemBarEnable([]).then(() => { await wnd.setWindowSystemBarEnable([]).then(() => {
...@@ -1053,7 +1050,7 @@ export default function Window() { ...@@ -1053,7 +1050,7 @@ export default function Window() {
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
let wnd = null; let wnd = null;
try { try {
wnd = await window.getLastWindow(context); wnd = windowStage.getMainWindowSync();
expect(wnd != null).assertTrue(); expect(wnd != null).assertTrue();
try { try {
await wnd.setWindowSystemBarEnable(['status', 'navigation']).then(() => { await wnd.setWindowSystemBarEnable(['status', 'navigation']).then(() => {
...@@ -1089,7 +1086,7 @@ export default function Window() { ...@@ -1089,7 +1086,7 @@ export default function Window() {
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
let wnd = null; let wnd = null;
try { try {
wnd = await window.getLastWindow(context); wnd = windowStage.getMainWindowSync();
expect(wnd != null).assertTrue(); expect(wnd != null).assertTrue();
try { try {
await wnd.setWindowSystemBarEnable(['status']).then(() => { await wnd.setWindowSystemBarEnable(['status']).then(() => {
...@@ -1125,7 +1122,7 @@ export default function Window() { ...@@ -1125,7 +1122,7 @@ export default function Window() {
let msgStr = 'jsunittest ' + caseName + ' '; let msgStr = 'jsunittest ' + caseName + ' ';
let wnd = null; let wnd = null;
try { try {
wnd = await window.getLastWindow(context); wnd = windowStage.getMainWindowSync();
expect(wnd != null).assertTrue(); expect(wnd != null).assertTrue();
try { try {
await wnd.setWindowSystemBarEnable(['navigation']).then(() => { await wnd.setWindowSystemBarEnable(['navigation']).then(() => {
...@@ -1163,7 +1160,7 @@ export default function Window() { ...@@ -1163,7 +1160,7 @@ export default function Window() {
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let wnd = null; let wnd = null;
try { try {
wnd = await window.getLastWindow(context); wnd = windowStage.getMainWindowSync();
expect(wnd != null).assertTrue(); expect(wnd != null).assertTrue();
try { try {
wnd.setWindowSystemBarEnable(['status', 'navigation'], (err) => { wnd.setWindowSystemBarEnable(['status', 'navigation'], (err) => {
...@@ -1206,7 +1203,7 @@ export default function Window() { ...@@ -1206,7 +1203,7 @@ export default function Window() {
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let wnd = null; let wnd = null;
try { try {
wnd = await window.getLastWindow(context); wnd = windowStage.getMainWindowSync();
expect(wnd != null).assertTrue(); expect(wnd != null).assertTrue();
try { try {
await wnd.setWindowSystemBarEnable([], (err) => { await wnd.setWindowSystemBarEnable([], (err) => {
...@@ -1282,7 +1279,7 @@ export default function Window() { ...@@ -1282,7 +1279,7 @@ export default function Window() {
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let mainWin = null; let mainWin = null;
let orientationItem = ['UNSPECIFIED', 'PORTRAIT', 'LANDSCAPE', 'PORTRAIT_INVERTED', let orientationItem = ['UNSPECIFIED', 'PORTRAIT', 'LANDSCAPE', 'PORTRAIT_INVERTED',
'LANDSCAPE_INVERTED']; 'LANDSCAPE_INVERTED', 'UNSPECIFIED'];
function setPreferredOrientationFun(win, orientation) { function setPreferredOrientationFun(win, orientation) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
...@@ -1317,6 +1314,7 @@ export default function Window() { ...@@ -1317,6 +1314,7 @@ export default function Window() {
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);
await sleep(500);
if (i == orientationItem.length - 1) { if (i == orientationItem.length - 1) {
expect(true).assertTrue(); expect(true).assertTrue();
done(); done();
...@@ -1391,7 +1389,7 @@ export default function Window() { ...@@ -1391,7 +1389,7 @@ export default function Window() {
let windowId = 'testLoadContentCb001'; let windowId = 'testLoadContentCb001';
console.log(msgStr + 'begin'); console.log(msgStr + 'begin');
let tempWnd = null let tempWnd = null
try {
tempWnd = await windowStage.createSubWindow(windowId); tempWnd = await windowStage.createSubWindow(windowId);
expect(!!tempWnd).assertTrue(); expect(!!tempWnd).assertTrue();
...@@ -1410,6 +1408,9 @@ export default function Window() { ...@@ -1410,6 +1408,9 @@ export default function Window() {
await tempWnd.destroyWindow(); await tempWnd.destroyWindow();
} }
}) })
} catch (err) {
unexpectedError(err, caseName, 'tempWnd.loadContent', done);
}
}) })
/** /**
* @tc.number : TEST_LOADCONTENT_CB_002 * @tc.number : TEST_LOADCONTENT_CB_002
...@@ -1430,8 +1431,9 @@ export default function Window() { ...@@ -1430,8 +1431,9 @@ export default function Window() {
try { try {
tempWnd.loadContent(null, storage, async (err) => { tempWnd.loadContent(null, storage, async (err) => {
if (err && err.code) { if (err && err.code) {
console.info(`tempWnd.loadContent catch error: ${JSON.stringify(err)}`)
try { try {
expect(err.code === 401).assertTrue(); expect(err.code).assertEqual(401);
} catch (error) { } catch (error) {
console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`) console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`)
} }
...@@ -1443,8 +1445,9 @@ export default function Window() { ...@@ -1443,8 +1445,9 @@ export default function Window() {
} }
}) })
} catch (err) { } catch (err) {
console.info(`tempWnd.loadContent catch error: ${JSON.stringify(err)}`);
try { try {
expect(err.code === 401).assertTrue(); expect(err.code).assertEqual(401);
} catch (error) { } catch (error) {
console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`) console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`)
} }
...@@ -1461,12 +1464,18 @@ export default function Window() { ...@@ -1461,12 +1464,18 @@ export default function Window() {
* @tc.level : Level 2 * @tc.level : Level 2
*/ */
it('testGetUIContext001', 0, async function (done) { it('testGetUIContext001', 0, async function (done) {
try {
let tempWnd = await windowStage.getMainWindow(); let tempWnd = await windowStage.getMainWindow();
expect(!!tempWnd).assertTrue(); expect(!!tempWnd).assertTrue();
let UIContext = tempWnd.getUIContext(); let UIContext = tempWnd.getUIContext();
expect(UIContext != undefined).assertTrue(); expect(UIContext != undefined).assertTrue();
console.info('testGetUIContext001 Succeeded'); console.info('testGetUIContext001 Succeeded');
done(); done();
} catch (err) {
console.info('testGetUIContext001 fail ' + err);
expect().assertFail();
done();
}
}) })
/** /**
* @tc.number : TEST_SETUICONTENT_PROMISE_001 * @tc.number : TEST_SETUICONTENT_PROMISE_001
...@@ -1518,14 +1527,22 @@ export default function Window() { ...@@ -1518,14 +1527,22 @@ export default function Window() {
await win.destroyWindow(); await win.destroyWindow();
done(); done();
}).catch(async (err) => { }).catch(async (err) => {
console.error('Failed to load the content. Cause: ' + JSON.stringify(err)); console.error('Failed to load the content. Cause1: ' + JSON.stringify(err));
try {
expect(err.code).assertEqual(401); expect(err.code).assertEqual(401);
} catch (err) {
console.error('Failed to load the content. Cause2: ' + JSON.stringify(err));
}
await win.destroyWindow(); await win.destroyWindow();
done() done()
}); });
} catch (exception) { } catch (exception) {
console.error('Failed to load the content. exception: ' + JSON.stringify(exception)); console.error('Failed to load the content. exception: ' + JSON.stringify(exception));
try {
expect(exception.code).assertEqual(401); expect(exception.code).assertEqual(401);
} catch (err) {
console.error('Failed to load the content. Cause2: ' + JSON.stringify(err));
}
await win.destroyWindow(); await win.destroyWindow();
done() done()
} }
...@@ -1648,18 +1665,11 @@ export default function Window() { ...@@ -1648,18 +1665,11 @@ export default function Window() {
let color = '#00ff33'; let color = '#00ff33';
try { try {
wnd.setWindowBackgroundColor(color); wnd.setWindowBackgroundColor(color);
console.log('testSetWindowBackgroundColor001 success');
await sleep(2000);
done(); done();
try { } catch (err) {
let properties = wnd.getWindowProperties(); console.error('Failed to set the background1 color. Cause: ' + JSON.stringify(err));
expect(!properties.isTransparent).assertTrue();
done()
} catch (exception) {
console.error('Failed to obtain the window properties001. Cause: ' + JSON.stringify(exception));
expect(exception.code).assertEqual(401);
done();
}
} catch (exception) {
console.error('Failed to set the background1 color. Cause: ' + JSON.stringify(exception));
expect().assertFail(); expect().assertFail();
done(); done();
} }
...@@ -1679,16 +1689,9 @@ export default function Window() { ...@@ -1679,16 +1689,9 @@ export default function Window() {
let color = '#ffffff00'; let color = '#ffffff00';
try { try {
wnd.setWindowBackgroundColor(color); wnd.setWindowBackgroundColor(color);
console.log('testSetWindowBackgroundColor002 success');
await sleep(2000);
done(); done();
try {
let properties = wnd.getWindowProperties();
expect(!properties.isTransparent).assertTrue();
done()
} catch (exception) {
console.error('Failed to obtain the window properties002. Cause: ' + JSON.stringify(exception));
expect(exception.code).assertEqual(401);
done();
}
} catch (exception) { } catch (exception) {
console.error('Failed to set the background2 color. Cause: ' + JSON.stringify(exception)); console.error('Failed to set the background2 color. Cause: ' + JSON.stringify(exception));
expect().assertFail(); expect().assertFail();
...@@ -1710,16 +1713,11 @@ export default function Window() { ...@@ -1710,16 +1713,11 @@ export default function Window() {
let color = '#00ffff00'; let color = '#00ffff00';
try { try {
wnd.setWindowBackgroundColor(color); wnd.setWindowBackgroundColor(color);
console.log('testSetWindowBackgroundColor003 success');
await sleep(2000);
wnd.setWindowBackgroundColor('#ffffff');
await sleep(2000);
done(); done();
try {
let properties = wnd.getWindowProperties();
expect(properties.isTransparent).assertTrue();
done()
} catch (exception) {
console.error('Failed to obtain the window properties003. Cause: ' + JSON.stringify(exception));
expect(exception.code).assertEqual(401);
done();
}
} catch (exception) { } catch (exception) {
console.error('Failed to set the background3 color. Cause: ' + JSON.stringify(exception)); console.error('Failed to set the background3 color. Cause: ' + JSON.stringify(exception));
expect().assertFail(); expect().assertFail();
...@@ -1741,6 +1739,8 @@ export default function Window() { ...@@ -1741,6 +1739,8 @@ export default function Window() {
let color = '#ff00'; let color = '#ff00';
try { try {
wnd.setWindowBackgroundColor(color); wnd.setWindowBackgroundColor(color);
console.log('testSetWindowBackgroundColor004 fail');
expect().assertFail();
done(); done();
} catch (exception) { } catch (exception) {
console.error('Failed to set the background4 color. Cause: ' + JSON.stringify(exception)); console.error('Failed to set the background4 color. Cause: ' + JSON.stringify(exception));
...@@ -1763,18 +1763,12 @@ export default function Window() { ...@@ -1763,18 +1763,12 @@ export default function Window() {
let color = '#hhgghhgg'; let color = '#hhgghhgg';
try { try {
wnd.setWindowBackgroundColor(color); wnd.setWindowBackgroundColor(color);
try { console.log('testSetWindowBackgroundColor005 fail');
let properties = wnd.getWindowProperties(); expect().assertFail();
expect(!properties.isTransparent).assertTrue(); done();
done() } catch (err) {
} catch (exception) { console.error('Failed to set the background5 color. Cause: ' + JSON.stringify(err));
console.error('Failed to obtain the window properties005. Cause: ' + JSON.stringify(exception)); expect(err.code).assertEqual(401);
expect(exception.code).assertEqual(401);
done()
}
} catch (exception) {
console.error('Failed to set the background5 color. Cause: ' + JSON.stringify(exception));
expect(exception.code).assertEqual(401);
done() done()
} }
}) })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册