1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Tests presence of the xhr-response in the worker

This commit is contained in:
Yury Delendik 2012-12-11 11:07:58 -06:00
parent 9583cb7108
commit 0e70aacc51
3 changed files with 55 additions and 3 deletions

View file

@ -512,6 +512,37 @@ var tests = [
},
impact: 'Important',
area: 'Core'
},
{
id: 'Worker-xhr-response',
name: 'XMLHttpRequest supports the reponse property in web workers',
run: function () {
if (typeof Worker == 'undefined')
return { output: 'Skipped', emulated: '' };
try {
var worker = new Worker('worker-stub.js');
var promise = new Promise();
var timeout = setTimeout(function () {
promise.resolve({ output: 'Failed', emulated: '?' });
}, 5000);
worker.addEventListener('message', function (e) {
var data = e.data;
if (data.action == 'xhr' && data.result)
promise.resolve({ output: 'Success', emulated: '' });
else
promise.resolve({ output: 'Failed', emulated: 'Yes' });
});
worker.postMessage({action: 'xhr'});
return promise;
} catch (e) {
return { output: 'Failed', emulated: 'Yes' };
}
},
impact: 'Important',
area: 'Core'
}
];

View file

@ -17,7 +17,16 @@
onmessage = function (e) {
var data = e.data;
postMessage({action: 'test', result: data.action == 'test' &&
data.data instanceof Uint8Array});
switch (data.action) {
case 'test':
postMessage({action: 'test', result: data.data instanceof Uint8Array});
break;
case 'xhr':
var xhr = new XMLHttpRequest();
var responseExists = 'response' in xhr || 'mozResponse' in xhr ||
'responseArrayBuffer' in xhr || 'mozResponseArrayBuffer' in xhr;
postMessage({action: 'xhr', result: responseExists});
break;
}
};