From be6cf15060cee35ad987a59bf77c447690d76235 Mon Sep 17 00:00:00 2001 From: vyv03354 Date: Sat, 16 Feb 2013 11:29:07 +0900 Subject: [PATCH] Add feature tests for TextDecoder --- test/features/tests.js | 52 ++++++++++++++++++++++++++++++++++++ test/features/worker-stub.js | 5 ++++ 2 files changed, 57 insertions(+) diff --git a/test/features/tests.js b/test/features/tests.js index a8cfbca7c..c6f253a1f 100644 --- a/test/features/tests.js +++ b/test/features/tests.js @@ -469,6 +469,18 @@ var tests = [ impact: 'Important', area: 'Core' }, + { + id: 'TextDecoder', + name: 'TextDecoder is present', + run: function () { + if (typeof TextDecoder != 'undefined') + return { output: 'Success', emulated: '' }; + else + return { output: 'Failed', emulated: 'No' }; + }, + impact: 'Critical', + area: 'Core' + }, { id: 'Worker', name: 'Worker is present', @@ -543,6 +555,46 @@ var tests = [ }, impact: 'Important', area: 'Core' + }, + { + id: 'Worker-TextDecoder', + name: 'TextDecoder is present in web workers', + run: function () { + if (typeof Worker == 'undefined') + return { output: 'Skipped', emulated: '' }; + + var emulatable = typeof TextDecoder !== 'undefined'; + try { + var worker = new Worker('worker-stub.js'); + + var promise = new Promise(); + var timeout = setTimeout(function () { + promise.resolve({ output: 'Failed', + emulated: emulatable ? '?' : 'No' }); + }, 5000); + + worker.addEventListener('message', function (e) { + var data = e.data; + if (data.action === 'TextDecoder') { + if (data.result) { + promise.resolve({ output: 'Success', emulated: '' }); + } else { + promise.resolve({ output: 'Failed', + emulated: data.emulated ? 'Yes' : 'No' }); + } + } else { + promise.resolve({ output: 'Failed', + emulated: emulatable ? 'Yes' : 'No' }); + } + }); + worker.postMessage({action: 'TextDecoder'}); + return promise; + } catch (e) { + return { output: 'Failed', emulated: emulatable ? 'Yes' : 'No' }; + } + }, + impact: 'Important', + area: 'Core' } ]; diff --git a/test/features/worker-stub.js b/test/features/worker-stub.js index d9726cb24..3673790c2 100644 --- a/test/features/worker-stub.js +++ b/test/features/worker-stub.js @@ -27,6 +27,11 @@ onmessage = function (e) { 'responseArrayBuffer' in xhr || 'mozResponseArrayBuffer' in xhr; postMessage({action: 'xhr', result: responseExists}); break; + case 'TextDecoder': + postMessage({action: 'TextDecoder', + result: typeof TextDecoder !== 'undefined', + emulated: typeof FileReaderSync !== 'undefined'}); + break; } };