File tree Expand file tree Collapse file tree 3 files changed +55
-3
lines changed Expand file tree Collapse file tree 3 files changed +55
-3
lines changed Original file line number Diff line number Diff line change @@ -152,7 +152,19 @@ var WorkerMessageHandler = {
152152 }
153153
154154 handler .on ('test' , function wphSetupTest (data ) {
155- handler .send ('test' , data instanceof Uint8Array );
155+ // check if Uint8Array can be sent to worker
156+ if (!(data instanceof Uint8Array )) {
157+ handler .send ('test' , false );
158+ return ;
159+ }
160+ // check if the response property is supported by xhr
161+ var xhr = new XMLHttpRequest ();
162+ if (!('response' in xhr || 'mozResponse' in xhr ||
163+ 'responseArrayBuffer' in xhr || 'mozResponseArrayBuffer' in xhr )) {
164+ handler .send ('test' , false );
165+ return ;
166+ }
167+ handler .send ('test' , true );
156168 });
157169
158170 handler .on ('GetDocRequest' , function wphSetupDoc (data ) {
Original file line number Diff line number Diff line change @@ -512,6 +512,37 @@ var tests = [
512512 },
513513 impact : 'Important' ,
514514 area : 'Core'
515+ },
516+ {
517+ id : 'Worker-xhr-response' ,
518+ name : 'XMLHttpRequest supports the reponse property in web workers' ,
519+ run : function () {
520+ if (typeof Worker == 'undefined' )
521+ return { output : 'Skipped' , emulated : '' };
522+
523+ try {
524+ var worker = new Worker ('worker-stub.js' );
525+
526+ var promise = new Promise ();
527+ var timeout = setTimeout (function () {
528+ promise .resolve ({ output : 'Failed' , emulated : '?' });
529+ }, 5000 );
530+
531+ worker .addEventListener ('message' , function (e ) {
532+ var data = e .data ;
533+ if (data .action == 'xhr' && data .result )
534+ promise .resolve ({ output : 'Success' , emulated : '' });
535+ else
536+ promise .resolve ({ output : 'Failed' , emulated : 'Yes' });
537+ });
538+ worker .postMessage ({action : 'xhr' });
539+ return promise ;
540+ } catch (e ) {
541+ return { output : 'Failed' , emulated : 'Yes' };
542+ }
543+ },
544+ impact : 'Important' ,
545+ area : 'Core'
515546 }
516547];
517548
Original file line number Diff line number Diff line change 1717
1818onmessage = function (e ) {
1919 var data = e .data ;
20- postMessage ({action : 'test' , result : data .action == 'test' &&
21- data .data instanceof Uint8Array });
20+ switch (data .action ) {
21+ case 'test' :
22+ postMessage ({action : 'test' , result : data .data instanceof Uint8Array });
23+ break ;
24+ case 'xhr' :
25+ var xhr = new XMLHttpRequest ();
26+ var responseExists = 'response' in xhr || 'mozResponse' in xhr ||
27+ 'responseArrayBuffer' in xhr || 'mozResponseArrayBuffer' in xhr ;
28+ postMessage ({action : 'xhr' , result : responseExists });
29+ break ;
30+ }
2231};
2332
You can’t perform that action at this time.
0 commit comments