@@ -727,6 +727,120 @@ describe("Console", function () {
727727 } ) ;
728728} ) ;
729729
730+ describe ( "Blob" , function ( ) {
731+ let emptyBlobs , helloBlobs , stringBlob , typedArrayBlob , arrayBufferBlob , blobBlob ;
732+
733+ before ( function ( ) {
734+ emptyBlobs = [ new Blob ( ) , new Blob ( [ ] ) ] ;
735+ stringBlob = new Blob ( [ "Hello" ] ) ;
736+ typedArrayBlob = new Blob ( [ new Uint8Array ( [ 72 , 101 , 108 , 108 , 111 ] ) ] ) ,
737+ arrayBufferBlob = new Blob ( [ new Uint8Array ( [ 72 , 101 , 108 , 108 , 111 ] ) . buffer ] ) ,
738+ blobBlob = new Blob ( [ new Blob ( [ "Hello" ] ) ] ) ,
739+ helloBlobs = [ stringBlob , typedArrayBlob , arrayBufferBlob , blobBlob ]
740+ } ) ;
741+
742+ // -------------------------------- Blob Construction --------------------------------
743+ it ( "creates empty blobs" , function ( ) {
744+ for ( const blob of emptyBlobs ) {
745+ expect ( blob . size ) . to . equal ( 0 ) ;
746+ expect ( blob . type ) . to . equal ( "" ) ;
747+ }
748+ } ) ;
749+
750+ it ( "creates blob from string array" , function ( ) {
751+ expect ( stringBlob . size ) . to . equal ( 5 ) ;
752+ expect ( stringBlob . type ) . to . equal ( "" ) ;
753+ } ) ;
754+
755+ it ( "creates blob from TypedArray" , function ( ) {
756+ expect ( typedArrayBlob . size ) . to . equal ( 5 ) ;
757+ expect ( typedArrayBlob . type ) . to . equal ( "" ) ;
758+ } ) ;
759+
760+ it ( "creates blob from ArrayBuffer" , function ( ) {
761+ expect ( arrayBufferBlob . size ) . to . equal ( 5 ) ;
762+ expect ( arrayBufferBlob . type ) . to . equal ( "" ) ;
763+ } ) ;
764+
765+ it ( "creates blob from another Blob" , function ( ) {
766+ expect ( blobBlob . size ) . to . equal ( 5 ) ;
767+ expect ( blobBlob . type ) . to . equal ( "" ) ;
768+ } ) ;
769+
770+ it ( "applies MIME type from options" , function ( ) {
771+ const modelGltfJson = new Blob ( [ "glTF" ] , { type : "model/gltf+json" } )
772+ expect ( modelGltfJson . type ) . to . equal ( "model/gltf+json" ) ;
773+ } ) ;
774+
775+ // -------------------------------- Blob.text() --------------------------------
776+ it ( "returns empty string for empty blobs" , async function ( ) {
777+ for ( const blob of emptyBlobs ) {
778+ const text = await blob . text ( ) ;
779+ expect ( text ) . to . equal ( "" ) ;
780+ }
781+ } ) ;
782+
783+ it ( "returns correct string content for non-empty blobs" , async function ( ) {
784+ for ( const blob of helloBlobs ) {
785+ const text = await blob . text ( ) ;
786+ expect ( text ) . to . equal ( "Hello" ) ;
787+ }
788+ } ) ;
789+
790+ it ( "handles multi-byte UTF-8 characters" , async function ( ) {
791+ const utf8Blob = new Blob ( [ "你好, 世界" ] ) ;
792+ const text = await utf8Blob . text ( ) ;
793+ expect ( text ) . to . equal ( "你好, 世界" ) ;
794+ } ) ;
795+
796+ it ( "preserves line endings like default transparent mode" , async function ( ) {
797+ const lineEndingsBlob = new Blob ( [ "Hello\nWorld" ] ) ;
798+ const text = await lineEndingsBlob . text ( ) ;
799+ expect ( text ) . to . equal ( "Hello\nWorld" ) ;
800+ } ) ;
801+
802+ // -------------------------------- Blob.bytes() --------------------------------
803+ it ( "returns empty Uint8Array for empty blobs" , async function ( ) {
804+ for ( const blob of emptyBlobs ) {
805+ const bytes = await blob . bytes ( ) ;
806+ expect ( bytes ) . to . be . instanceOf ( Uint8Array ) ;
807+ expect ( bytes . length ) . to . equal ( 0 ) ;
808+ }
809+ } ) ;
810+
811+ it ( "returns correct byte content from non-empty blobs" , async function ( ) {
812+ for ( const blob of helloBlobs ) {
813+ const bytes = await blob . bytes ( ) ;
814+ expect ( bytes ) . to . be . instanceOf ( Uint8Array ) ;
815+ expect ( bytes . length ) . to . equal ( 5 ) ;
816+ expect ( bytes [ 0 ] ) . to . equal ( 72 ) ; // 'H'
817+ expect ( bytes [ 4 ] ) . to . equal ( 111 ) ; // 'o'
818+ }
819+ } ) ;
820+
821+ // -------------------------------- Blob.arrayBuffer() --------------------------------
822+ it ( "returns empty buffer for empty blobs" , async function ( ) {
823+ for ( const blob of emptyBlobs ) {
824+ const buffer = await blob . arrayBuffer ( ) ;
825+ expect ( buffer ) . to . be . instanceOf ( ArrayBuffer ) ;
826+ expect ( buffer . byteLength ) . to . equal ( 0 ) ;
827+ }
828+ } ) ;
829+
830+ it ( "returns correct buffer content for non-empty blobs" , async function ( ) {
831+ for ( const blob of helloBlobs ) {
832+ const buffer = await blob . arrayBuffer ( ) ;
833+ expect ( buffer ) . to . be . instanceOf ( ArrayBuffer ) ;
834+ expect ( buffer . byteLength ) . to . equal ( 5 ) ;
835+
836+ const view = new Uint8Array ( buffer ) ;
837+ expect ( view [ 0 ] ) . to . equal ( 72 ) ; // 'H'
838+ expect ( view [ 4 ] ) . to . equal ( 111 ) ; // 'o'
839+
840+ }
841+ } ) ;
842+ } ) ;
843+
730844function runTests ( ) {
731845 mocha . run ( failures => {
732846 // Test program will wait for code to be set before exiting
0 commit comments