提交 a5ef69c8 编写于 作者: H hu0475

window模块完善修改部分测试用例

Signed-off-by: Nhu0475 <huyanqiang5@huawei.com>
上级 e30fb5ee
...@@ -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,25 +1389,28 @@ export default function Window() { ...@@ -1391,25 +1389,28 @@ 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();
tempWnd.loadContent('TestAbility/pages/index1', storage, async (err) => { 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 {
console.log(msgStr + 'tempWnd.loadContent() success'); console.log(msgStr + 'tempWnd.loadContent() success');
expect(TRUE_FLAG).assertTrue(); expect(TRUE_FLAG).assertTrue();
done(); done();
} catch (error) { } catch (error) {
console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`) console.info(`tempWnd.loadContent catch error: ${JSON.stringify(error)}`)
done() done()
}
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) {
let tempWnd = await windowStage.getMainWindow(); try {
expect(!!tempWnd).assertTrue(); let tempWnd = await windowStage.getMainWindow();
let UIContext = tempWnd.getUIContext(); expect(!!tempWnd).assertTrue();
expect(UIContext != undefined).assertTrue(); let UIContext = tempWnd.getUIContext();
console.info('testGetUIContext001 Succeeded'); expect(UIContext != undefined).assertTrue();
done(); console.info('testGetUIContext001 Succeeded');
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));
expect(err.code).assertEqual(401); try {
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));
expect(exception.code).assertEqual(401); try {
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.
先完成此消息的编辑!
想要评论请 注册