提交 b603e77d 编写于 作者: Y y00576111

add onmessageerror testcase

Signed-off-by: Ny00576111 <yaojian16@huawei.com>
Change-Id: I5cdd846c3f9f5a0409c58ba2f6ea1a9f2ce50dcb
上级 06843333
...@@ -25,7 +25,7 @@ describe('workerTest', function () { ...@@ -25,7 +25,7 @@ describe('workerTest', function () {
console.info('total case over') console.info('total case over')
}) })
function PromiseCase() { function promiseCase() {
let p = new Promise(function (resolve, reject) { let p = new Promise(function (resolve, reject) {
setTimeout(function () { setTimeout(function () {
resolve() resolve()
...@@ -71,7 +71,7 @@ describe('workerTest', function () { ...@@ -71,7 +71,7 @@ describe('workerTest', function () {
ss.postMessage("hello world") ss.postMessage("hello world")
while (!flag) { while (!flag) {
await PromiseCase() await promiseCase()
} }
expect(res).assertEqual("hello world worker") expect(res).assertEqual("hello world worker")
done() done()
...@@ -92,7 +92,7 @@ describe('workerTest', function () { ...@@ -92,7 +92,7 @@ describe('workerTest', function () {
ss.postMessage(12) ss.postMessage(12)
while (!flag) { while (!flag) {
await PromiseCase() await promiseCase()
} }
expect(res).assertEqual(25) expect(res).assertEqual(25)
done() done()
...@@ -113,7 +113,7 @@ describe('workerTest', function () { ...@@ -113,7 +113,7 @@ describe('workerTest', function () {
ss.postMessage({"message":"hello world"}) ss.postMessage({"message":"hello world"})
while (!flag) { while (!flag) {
await PromiseCase() await promiseCase()
} }
expect(res).assertEqual("hello world worker") expect(res).assertEqual("hello world worker")
done() done()
...@@ -133,7 +133,7 @@ describe('workerTest', function () { ...@@ -133,7 +133,7 @@ describe('workerTest', function () {
ss.postMessage("hello world") ss.postMessage("hello world")
while (!flag) { while (!flag) {
await PromiseCase() await promiseCase()
} }
expect(res).assertEqual("zhangsan") expect(res).assertEqual("zhangsan")
done() done()
...@@ -163,7 +163,7 @@ describe('workerTest', function () { ...@@ -163,7 +163,7 @@ describe('workerTest', function () {
ss.postMessage("hello world") ss.postMessage("hello world")
while (!flag) { while (!flag) {
await PromiseCase() await promiseCase()
} }
expect(res).assertEqual("Error: 123") expect(res).assertEqual("Error: 123")
done() done()
...@@ -181,7 +181,7 @@ describe('workerTest', function () { ...@@ -181,7 +181,7 @@ describe('workerTest', function () {
} }
ss.terminate() ss.terminate()
while (!flag) { while (!flag) {
await PromiseCase() await promiseCase()
} }
expect(res).assertEqual(1) expect(res).assertEqual(1)
done() done()
...@@ -203,7 +203,7 @@ describe('workerTest', function () { ...@@ -203,7 +203,7 @@ describe('workerTest', function () {
ss.terminate() ss.terminate()
while (!flag) { while (!flag) {
await PromiseCase() await promiseCase()
} }
expect(res).assertEqual(1) expect(res).assertEqual(1)
done() done()
...@@ -226,12 +226,12 @@ describe('workerTest', function () { ...@@ -226,12 +226,12 @@ describe('workerTest', function () {
ss.terminate() ss.terminate()
while (!flag) { while (!flag) {
await PromiseCase() await promiseCase()
} }
expect(res).assertEqual(1) expect(res).assertEqual(1)
ss.postMessage("hello world") ss.postMessage("hello world")
await PromiseCase() await promiseCase()
expect(res).assertEqual(1) expect(res).assertEqual(1)
done() done()
}) })
...@@ -508,7 +508,7 @@ describe('workerTest', function () { ...@@ -508,7 +508,7 @@ describe('workerTest', function () {
} }
ss.postMessage("abc") ss.postMessage("abc")
await PromiseCase() await promiseCase()
expect(res).assertEqual(0) expect(res).assertEqual(0)
done() done()
}) })
...@@ -525,11 +525,11 @@ describe('workerTest', function () { ...@@ -525,11 +525,11 @@ describe('workerTest', function () {
} }
ss1.postMessage("abc") ss1.postMessage("abc")
await PromiseCase() await promiseCase()
expect(res).assertEqual(0) expect(res).assertEqual(0)
ss2.postMessage("hello world") ss2.postMessage("hello world")
await PromiseCase() await promiseCase()
expect(res).assertEqual(0) expect(res).assertEqual(0)
done() done()
...@@ -547,7 +547,7 @@ describe('workerTest', function () { ...@@ -547,7 +547,7 @@ describe('workerTest', function () {
} }
ss1.postMessage("abc") ss1.postMessage("abc")
await PromiseCase() await promiseCase()
expect(res).assertEqual(0) expect(res).assertEqual(0)
ss2.addEventListener("zhangsan", ()=>{ ss2.addEventListener("zhangsan", ()=>{
...@@ -575,12 +575,54 @@ describe('workerTest', function () { ...@@ -575,12 +575,54 @@ describe('workerTest', function () {
ss.postMessage("abc") ss.postMessage("abc")
while (!flag) { while (!flag) {
await PromiseCase() await promiseCase()
} }
ss.postMessage("hello") ss.postMessage("hello")
await PromiseCase() await promiseCase()
expect(res).assertEqual(0) expect(res).assertEqual(0)
done() done()
}) })
// check onmessageerror is ok
it('worker_onmessageerror_test_001', 0, async function (done) {
var ss = new worker.Worker("workers/worker_008.js");
var res = 0
var flag = false;
ss.onexit = function () {
flag = true
}
ss.onmessageerror = function (e) {
res++;
}
ss.postMessage("abc")
while (!flag) {
await promiseCase()
}
expect(res).assertEqual(0)
done()
})
// check onmessageerror is ok
it('worker_onmessageerror_test_002', 0, async function (done) {
var ss = new worker.Worker("workers/worker_008.js");
var res = 0
var flag = false;
ss.onmessageerror = function (e) {
flag = true;
res++;
}
function foo() {
}
ss.postMessage(foo)
while (!flag) {
await promiseCase()
}
expect(res).assertEqual(1)
done()
})
}) })
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册