From 0e70aacc511d910232790c519d971767e3542b92 Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Tue, 11 Dec 2012 11:07:58 -0600 Subject: [PATCH] Tests presence of the xhr-response in the worker --- src/worker.js | 14 +++++++++++++- test/features/tests.js | 31 +++++++++++++++++++++++++++++++ test/features/worker-stub.js | 13 +++++++++++-- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/worker.js b/src/worker.js index 33caa4049..47eb8b1da 100644 --- a/src/worker.js +++ b/src/worker.js @@ -152,7 +152,19 @@ var WorkerMessageHandler = { } handler.on('test', function wphSetupTest(data) { - handler.send('test', data instanceof Uint8Array); + // check if Uint8Array can be sent to worker + if (!(data instanceof Uint8Array)) { + handler.send('test', false); + return; + } + // check if the response property is supported by xhr + var xhr = new XMLHttpRequest(); + if (!('response' in xhr || 'mozResponse' in xhr || + 'responseArrayBuffer' in xhr || 'mozResponseArrayBuffer' in xhr)) { + handler.send('test', false); + return; + } + handler.send('test', true); }); handler.on('GetDocRequest', function wphSetupDoc(data) { diff --git a/test/features/tests.js b/test/features/tests.js index 1b246dd5f..a8cfbca7c 100644 --- a/test/features/tests.js +++ b/test/features/tests.js @@ -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' } ]; diff --git a/test/features/worker-stub.js b/test/features/worker-stub.js index a8d2afba1..d9726cb24 100644 --- a/test/features/worker-stub.js +++ b/test/features/worker-stub.js @@ -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; + } };