Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / files / blob-constructor.html
blobcdf4684e0fc111eeb9507a10f73dc7ae6a5cd117
1 <!DOCTYPE html>
3 <script src="../../resources/js-test.js"></script>
4 <script>
5 description("Test the Blob constructor.");
6 var jsTestIsAsync = true;
8 // Test the different ways you can construct a Blob.
9 shouldBeTrue("(new Blob()) instanceof window.Blob");
10 shouldBeTrue("(new Blob([])) instanceof window.Blob");
11 shouldBeTrue("(new Blob(['hello'])) instanceof window.Blob");
12 shouldBeTrue("(new Blob(['hello'], {})) instanceof window.Blob");
13 shouldBeTrue("(new Blob(['hello'], {type:'text/html'})) instanceof window.Blob");
14 shouldBeTrue("(new Blob(['hello'], {type:'text/html', endings:'native'})) instanceof window.Blob");
15 shouldBeTrue("(new Blob(['hello'], {type:'text/html', endings:'transparent'})) instanceof window.Blob");
17 // Test invalid blob parts.
18 shouldThrow("new Blob('hello')", '"TypeError: Failed to construct \'Blob\': The 1st argument is neither an array, nor does it have indexed properties."');
19 shouldThrow("new Blob(0)", '"TypeError: Failed to construct \'Blob\': The 1st argument is neither an array, nor does it have indexed properties."');
20 shouldThrow("new Blob(null)", '"TypeError: Failed to construct \'Blob\': The 1st argument is neither an array, nor does it have indexed properties."');
22 // Test valid blob parts.
23 shouldBeTrue("(new Blob([])) instanceof window.Blob");
24 shouldBeTrue("(new Blob(['stringPrimitive'])) instanceof window.Blob");
25 shouldBeTrue("(new Blob([String('stringObject')])) instanceof window.Blob");
26 shouldBeTrue("(new Blob([new Blob])) instanceof window.Blob");
27 shouldBeTrue("(new Blob([new Blob([new Blob])])) instanceof window.Blob");
29 // Test some conversions to string in the parts array.
30 shouldBe("(new Blob([12])).size", "2");
31 shouldBe("(new Blob([[]])).size", "0"); // [].toString() is the empty string
32 shouldBe("(new Blob([{}])).size", "15");; // {}.toString() is the string "[object Object]"
33 shouldBe("(new Blob([document])).size", "21"); // document.toString() is the string "[object HTMLDocument]"
35 var toStringingObj = { toString: function() { return "A string"; } };
36 shouldBe("(new Blob([toStringingObj])).size", "8");
38 var throwingObj = { toString: function() { throw "Error"; } };
39 shouldThrow("new Blob([throwingObj])", "'Error'");
41 // Test some invalid property bags.
42 shouldBeTrue("(new Blob([], {unknownKey:'value'})) instanceof window.Blob"); // Ignore invalid keys
43 shouldThrow("new Blob([], {endings:'illegalValue'})", "'TypeError: Failed to construct \\'Blob\\': The provided value \\'illegalValue\\' is not a valid enum value of type NormalizeLineEndings.'");
44 shouldThrow("new Blob([], {endings:throwingObj})", "'Error'");
45 shouldThrow("new Blob([], {type:throwingObj})", "'Error'");
46 shouldThrow("new Blob([], {type:'hello\u00EE'})", "'SyntaxError: Failed to construct \\'Blob\\': The \\'type\\' property must consist of ASCII characters.'");
48 // Test that order of property bag evaluation is lexigraphical
49 var throwingObj1 = { toString: function() { throw "Error 1"; } };
50 var throwingObj2 = { toString: function() { throw "Error 2"; } };
51 shouldThrow("new Blob([], {endings:throwingObj1, type:throwingObj2})", "'Error 1'");
52 shouldThrow("new Blob([], {type:throwingObj2, endings:throwingObj1})", "'Error 1'");
53 shouldThrow("new Blob([], {type:throwingObj2, endings:'illegal'})", "'TypeError: Failed to construct \\'Blob\\': The provided value \\'illegal\\' is not a valid enum value of type NormalizeLineEndings.'");
55 // Test various non-object literals being used as property bags.
56 shouldBeTrue("(new Blob([], null)) instanceof window.Blob");
57 shouldBeTrue("(new Blob([], undefined)) instanceof window.Blob");
58 shouldThrow("(new Blob([], 123)) instanceof window.Blob", "'TypeError: Failed to construct \\'Blob\\': parameter 2 (\\'options\\') is not an object.'");
59 shouldThrow("(new Blob([], 123.4)) instanceof window.Blob", "'TypeError: Failed to construct \\'Blob\\': parameter 2 (\\'options\\') is not an object.'");
60 shouldThrow("(new Blob([], true)) instanceof window.Blob", "'TypeError: Failed to construct \\'Blob\\': parameter 2 (\\'options\\') is not an object.'");
61 shouldThrow("(new Blob([], 'abc')) instanceof window.Blob", "'TypeError: Failed to construct \\'Blob\\': parameter 2 (\\'options\\') is not an object.'");
62 shouldBeTrue("(new Blob([], [])) instanceof window.Blob");
63 shouldBeTrue("(new Blob([], /abc/)) instanceof window.Blob");
64 shouldBeTrue("(new Blob([], function () {})) instanceof window.Blob");
66 // Test that the type/size is correctly added to the Blob.
67 shouldBe("(new Blob([], {type:'text/html'})).type", "'text/html'");
68 shouldBe("(new Blob([], {type:'text/html'})).size", "0");
69 shouldBe("(new Blob([], {type:'text/plain;charset=UTF-8'})).type", "'text/plain;charset=utf-8'");
71 // Test that the File-specific lastModified is not set by the Blob constructor.
72 shouldBe("(new Blob([])).lastModified", "undefined");
73 shouldBe("(new Blob([], {})).lastModified", "undefined");
74 shouldBe("(new Blob([], {lastModified: new Date()})).lastModified", "undefined");
76 // Test the number of expected arguments in the Blob constructor.
77 shouldBe("window.Blob.length", "0");
79 // Test ArrayBufferView parameters.
80 shouldBe("new Blob([new DataView(new ArrayBuffer(100))]).size", "100");
81 shouldBe("new Blob([new Uint8Array(100)]).size", "100");
82 shouldBe("new Blob([new Uint8ClampedArray(100)]).size", "100");
83 shouldBe("new Blob([new Uint16Array(100)]).size", "200");
84 shouldBe("new Blob([new Uint32Array(100)]).size", "400");
85 shouldBe("new Blob([new Int8Array(100)]).size", "100");
86 shouldBe("new Blob([new Int16Array(100)]).size", "200");
87 shouldBe("new Blob([new Int32Array(100)]).size", "400");
88 shouldBe("new Blob([new Float32Array(100)]).size", "400");
89 shouldBe("new Blob([new Float64Array(100)]).size", "800");
90 shouldBe("new Blob([new Float64Array(100), new Int32Array(100), new Uint8Array(100), new DataView(new ArrayBuffer(100))]).size", "1400");
91 shouldBe("new Blob([new Blob([new Int32Array(100)]), new Uint8Array(100), new Float32Array(100), new DataView(new ArrayBuffer(100))]).size", "1000");
93 // Test ArrayBuffer parameters.
94 shouldBe("new Blob([(new DataView(new ArrayBuffer(100))).buffer]).size", "100");
95 shouldBe("new Blob([(new Uint8Array(100)).buffer]).size", "100");
96 shouldBe("new Blob([(new Uint8ClampedArray(100)).buffer]).size", "100");
97 shouldBe("new Blob([(new Uint16Array(100)).buffer]).size", "200");
98 shouldBe("new Blob([(new Uint32Array(100)).buffer]).size", "400");
99 shouldBe("new Blob([(new Int8Array(100)).buffer]).size", "100");
100 shouldBe("new Blob([(new Int16Array(100)).buffer]).size", "200");
101 shouldBe("new Blob([(new Int32Array(100)).buffer]).size", "400");
102 shouldBe("new Blob([(new Float32Array(100)).buffer]).size", "400");
103 shouldBe("new Blob([(new Float64Array(100)).buffer]).size", "800");
104 shouldBe("new Blob([(new Float64Array(100)).buffer, (new Int32Array(100)).buffer, (new Uint8Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer]).size", "1400");
105 shouldBe("new Blob([new Blob([(new Int32Array(100)).buffer]), (new Uint8Array(100)).buffer, (new Float32Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer]).size", "1000");
107 // Test passing blob parts in objects with indexed properties.
108 // (This depends on the bindings code handling of sequence<T>)
109 shouldBe("new Blob({length: 0}).size", "0");
110 shouldBe("new Blob({length: 1, 0: 'string'}).size", "6");
112 // Test that strings are not NFC normalized
113 var OMICRON_WITH_OXIA = '\u1F79'; // NFC normalized to U+3CC
114 shouldBe("OMICRON_WITH_OXIA.charCodeAt(0)", "0x1F79");
115 var reader = new FileReader();
116 reader.readAsText(new Blob([OMICRON_WITH_OXIA]));
117 reader.onload = function() {
118 shouldBe("reader.result.charCodeAt(0)", "0x1F79");
119 finishJSTest();
121 </script>