OLD | NEW |
1 description("Test the Blob constructor."); | 1 description("Test the Blob constructor."); |
2 | 2 |
3 // Test the diffrent ways you can construct a Blob. | 3 // Test the diffrent ways you can construct a Blob. |
4 shouldBeTrue("(new Blob()) instanceof window.Blob"); | 4 shouldBeTrue("(new Blob()) instanceof window.Blob"); |
5 shouldBeTrue("(new Blob([])) instanceof window.Blob"); | 5 shouldBeTrue("(new Blob([])) instanceof window.Blob"); |
6 shouldBeTrue("(new Blob(['hello'])) instanceof window.Blob"); | 6 shouldBeTrue("(new Blob(['hello'])) instanceof window.Blob"); |
7 shouldBeTrue("(new Blob(['hello'], {})) instanceof window.Blob"); | 7 shouldBeTrue("(new Blob(['hello'], {})) instanceof window.Blob"); |
8 shouldBeTrue("(new Blob(['hello'], {type:'text/html'})) instanceof window.Blob")
; | 8 shouldBeTrue("(new Blob(['hello'], {type:'text/html'})) instanceof window.Blob")
; |
9 shouldBeTrue("(new Blob(['hello'], {type:'text/html', endings:'native'})) instan
ceof window.Blob"); | 9 shouldBeTrue("(new Blob(['hello'], {type:'text/html', endings:'native'})) instan
ceof window.Blob"); |
10 shouldBeTrue("(new Blob(['hello'], {type:'text/html', endings:'transparent'})) i
nstanceof window.Blob"); | 10 shouldBeTrue("(new Blob(['hello'], {type:'text/html', endings:'transparent'})) i
nstanceof window.Blob"); |
11 | 11 |
12 // Test invalid blob parts | 12 // Test invalid blob parts |
13 shouldThrow("new Blob('hello')", "'TypeError: First argument of the constructor
is not of type Array'"); | 13 shouldThrow("new Blob('hello')", '"TypeError: Failed to construct \'Blob\': The
1st argument is neither an array, nor does it have indexed properties."'); |
14 shouldThrow("new Blob(0)", "'TypeError: First argument of the constructor is not
of type Array'"); | 14 shouldThrow("new Blob(0)", '"TypeError: Failed to construct \'Blob\': The 1st ar
gument is neither an array, nor does it have indexed properties."'); |
15 | 15 |
16 // Test valid blob parts. | 16 // Test valid blob parts. |
17 shouldBeTrue("(new Blob([])) instanceof window.Blob"); | 17 shouldBeTrue("(new Blob([])) instanceof window.Blob"); |
18 shouldBeTrue("(new Blob(['stringPrimitive'])) instanceof window.Blob"); | 18 shouldBeTrue("(new Blob(['stringPrimitive'])) instanceof window.Blob"); |
19 shouldBeTrue("(new Blob([String('stringObject')])) instanceof window.Blob"); | 19 shouldBeTrue("(new Blob([String('stringObject')])) instanceof window.Blob"); |
20 shouldBeTrue("(new Blob([new Blob])) instanceof window.Blob"); | 20 shouldBeTrue("(new Blob([new Blob])) instanceof window.Blob"); |
21 shouldBeTrue("(new Blob([new Blob([new Blob])])) instanceof window.Blob"); | 21 shouldBeTrue("(new Blob([new Blob([new Blob])])) instanceof window.Blob"); |
22 | 22 |
23 // Test some conversions to string in the parts array. | 23 // Test some conversions to string in the parts array. |
24 shouldBe("(new Blob([12])).size", "2"); | 24 shouldBe("(new Blob([12])).size", "2"); |
25 shouldBe("(new Blob([[]])).size", "0"); // [].toString() is the empty st
ring | 25 shouldBe("(new Blob([[]])).size", "0"); // [].toString() is the empty st
ring |
26 shouldBe("(new Blob([{}])).size", "15");; // {}.toString() is the string "
[object Object]" | 26 shouldBe("(new Blob([{}])).size", "15");; // {}.toString() is the string "
[object Object]" |
27 shouldBe("(new Blob([document])).size", "21"); // document.toString() is the st
ring "[object HTMLDocument]" | 27 shouldBe("(new Blob([document])).size", "21"); // document.toString() is the st
ring "[object HTMLDocument]" |
28 | 28 |
29 var toStringingObj = { toString: function() { return "A string"; } }; | 29 var toStringingObj = { toString: function() { return "A string"; } }; |
30 shouldBe("(new Blob([toStringingObj])).size", "8"); | 30 shouldBe("(new Blob([toStringingObj])).size", "8"); |
31 | 31 |
32 var throwingObj = { toString: function() { throw "Error"; } }; | 32 var throwingObj = { toString: function() { throw "Error"; } }; |
33 shouldThrow("new Blob([throwingObj])", "'Error'"); | 33 shouldThrow("new Blob([throwingObj])", "'Error'"); |
34 | 34 |
35 // Test some invalid property bags | 35 // Test some invalid property bags |
36 shouldBeTrue("(new Blob([], {unknownKey:'value'})) instanceof window.Blob");
// Ignore invalid keys | 36 shouldBeTrue("(new Blob([], {unknownKey:'value'})) instanceof window.Blob");
// Ignore invalid keys |
37 shouldThrow("new Blob([], {endings:'illegalValue'})", "'TypeError: The endings p
roperty must be either \"transparent\" or \"native\"'"); | 37 shouldThrow("new Blob([], {endings:'illegalValue'})", "'TypeError: Failed to con
struct \\'Blob\\': The 2nd argument\\'s \"endings\" property must be either \"tr
ansparent\" or \"native\".'"); |
38 shouldThrow("new Blob([], {endings:throwingObj})", "'Error'"); | 38 shouldThrow("new Blob([], {endings:throwingObj})", "'Error'"); |
39 shouldThrow("new Blob([], {type:throwingObj})", "'Error'"); | 39 shouldThrow("new Blob([], {type:throwingObj})", "'Error'"); |
40 shouldThrow("new Blob([], {type:'hello\u00EE'})", "'SyntaxError: type must consi
st of ASCII characters'"); | 40 shouldThrow("new Blob([], {type:'hello\u00EE'})", "'SyntaxError: Failed to const
ruct \\'Blob\\': The 2nd argument\\'s \"type\" property must consist of ASCII ch
aracters.'"); |
41 | 41 |
42 // Test that order of property bag evaluation is lexigraphical | 42 // Test that order of property bag evaluation is lexigraphical |
43 var throwingObj1 = { toString: function() { throw "Error 1"; } }; | 43 var throwingObj1 = { toString: function() { throw "Error 1"; } }; |
44 var throwingObj2 = { toString: function() { throw "Error 2"; } }; | 44 var throwingObj2 = { toString: function() { throw "Error 2"; } }; |
45 shouldThrow("new Blob([], {endings:throwingObj1, type:throwingObj2})", "'Error 1
'"); | 45 shouldThrow("new Blob([], {endings:throwingObj1, type:throwingObj2})", "'Error 1
'"); |
46 shouldThrow("new Blob([], {type:throwingObj2, endings:throwingObj1})", "'Error 1
'"); | 46 shouldThrow("new Blob([], {type:throwingObj2, endings:throwingObj1})", "'Error 1
'"); |
47 shouldThrow("new Blob([], {type:throwingObj2, endings:'illegal'})", "'TypeError:
The endings property must be either \"transparent\" or \"native\"'"); | 47 shouldThrow("new Blob([], {type:throwingObj2, endings:'illegal'})", "'TypeError:
Failed to construct \\'Blob\\': The 2nd argument\\'s \"endings\" property must
be either \"transparent\" or \"native\".'"); |
48 | 48 |
49 // Test various non-object literals being used as property bags | 49 // Test various non-object literals being used as property bags |
50 shouldThrow("(new Blob([], null)) instanceof window.Blob", "'TypeError: Second a
rgument of the constructor is not of type Object'"); | 50 shouldThrow("(new Blob([], null)) instanceof window.Blob", "'TypeError: Failed t
o construct \\'Blob\\': The 2nd argument is not of type Object.'"); |
51 shouldThrow("(new Blob([], undefined)) instanceof window.Blob", "'TypeError: Sec
ond argument of the constructor is not of type Object'"); | 51 shouldThrow("(new Blob([], undefined)) instanceof window.Blob", "'TypeError: Fai
led to construct \\'Blob\\': The 2nd argument is not of type Object.'"); |
52 shouldThrow("(new Blob([], 123)) instanceof window.Blob", "'TypeError: Second ar
gument of the constructor is not of type Object'"); | 52 shouldThrow("(new Blob([], 123)) instanceof window.Blob", "'TypeError: Failed to
construct \\'Blob\\': The 2nd argument is not of type Object.'"); |
53 shouldThrow("(new Blob([], 123.4)) instanceof window.Blob", "'TypeError: Second
argument of the constructor is not of type Object'"); | 53 shouldThrow("(new Blob([], 123.4)) instanceof window.Blob", "'TypeError: Failed
to construct \\'Blob\\': The 2nd argument is not of type Object.'"); |
54 shouldThrow("(new Blob([], true)) instanceof window.Blob", "'TypeError: Second a
rgument of the constructor is not of type Object'"); | 54 shouldThrow("(new Blob([], true)) instanceof window.Blob", "'TypeError: Failed t
o construct \\'Blob\\': The 2nd argument is not of type Object.'"); |
55 shouldThrow("(new Blob([], 'abc')) instanceof window.Blob", "'TypeError: Second
argument of the constructor is not of type Object'"); | 55 shouldThrow("(new Blob([], 'abc')) instanceof window.Blob", "'TypeError: Failed
to construct \\'Blob\\': The 2nd argument is not of type Object.'"); |
56 shouldBeTrue("(new Blob([], [])) instanceof window.Blob"); | 56 shouldBeTrue("(new Blob([], [])) instanceof window.Blob"); |
57 shouldBeTrue("(new Blob([], /abc/)) instanceof window.Blob"); | 57 shouldBeTrue("(new Blob([], /abc/)) instanceof window.Blob"); |
58 shouldBeTrue("(new Blob([], function () {})) instanceof window.Blob"); | 58 shouldBeTrue("(new Blob([], function () {})) instanceof window.Blob"); |
59 | 59 |
60 // Test that the type/size is correctly added to the Blob | 60 // Test that the type/size is correctly added to the Blob |
61 shouldBe("(new Blob([], {type:'text/html'})).type", "'text/html'"); | 61 shouldBe("(new Blob([], {type:'text/html'})).type", "'text/html'"); |
62 shouldBe("(new Blob([], {type:'text/html'})).size", "0"); | 62 shouldBe("(new Blob([], {type:'text/html'})).size", "0"); |
63 shouldBe("(new Blob([], {type:'text/plain;charset=UTF-8'})).type", "'text/plain;
charset=utf-8'"); | 63 shouldBe("(new Blob([], {type:'text/plain;charset=UTF-8'})).type", "'text/plain;
charset=utf-8'"); |
64 | 64 |
65 // Odds and ends | 65 // Odds and ends |
(...skipping 26 matching lines...) Expand all Loading... |
92 shouldBe("new Blob([(new Float64Array(100)).buffer]).size", "800"); | 92 shouldBe("new Blob([(new Float64Array(100)).buffer]).size", "800"); |
93 shouldBe("new Blob([(new Float64Array(100)).buffer, (new Int32Array(100)).buffer
, (new Uint8Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer]).si
ze", "1400"); | 93 shouldBe("new Blob([(new Float64Array(100)).buffer, (new Int32Array(100)).buffer
, (new Uint8Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer]).si
ze", "1400"); |
94 shouldBe("new Blob([new Blob([(new Int32Array(100)).buffer]), (new Uint8Array(10
0)).buffer, (new Float32Array(100)).buffer, (new DataView(new ArrayBuffer(100)))
.buffer]).size", "1000"); | 94 shouldBe("new Blob([new Blob([(new Int32Array(100)).buffer]), (new Uint8Array(10
0)).buffer, (new Float32Array(100)).buffer, (new DataView(new ArrayBuffer(100)))
.buffer]).size", "1000"); |
95 | 95 |
96 // Test passing blob parts in sequences. | 96 // Test passing blob parts in sequences. |
97 shouldBeTrue("new Blob({length: 0}) instanceof window.Blob"); | 97 shouldBeTrue("new Blob({length: 0}) instanceof window.Blob"); |
98 shouldBe("new Blob({length: 0}).size", "0"); | 98 shouldBe("new Blob({length: 0}).size", "0"); |
99 shouldBe("new Blob({length: 1, 0: 'string'}).size", "6"); | 99 shouldBe("new Blob({length: 1, 0: 'string'}).size", "6"); |
100 shouldBe("new Blob({length: 2, 0: new Uint8Array(100), 1: new Int16Array(100)}).
size", "300"); | 100 shouldBe("new Blob({length: 2, 0: new Uint8Array(100), 1: new Int16Array(100)}).
size", "300"); |
101 shouldBe("new Blob({length: 1, 0: 'string'}, {type: 'text/html'}).type", "'text/
html'"); | 101 shouldBe("new Blob({length: 1, 0: 'string'}, {type: 'text/html'}).type", "'text/
html'"); |
102 shouldThrow("new Blob({length: 0}, {endings:'illegal'})", "'TypeError: The endin
gs property must be either \"transparent\" or \"native\"'"); | 102 shouldThrow("new Blob({length: 0}, {endings:'illegal'})", "'TypeError: Failed to
construct \\'Blob\\': The 2nd argument\\'s \"endings\" property must be either
\"transparent\" or \"native\".'"); |
OLD | NEW |