diff options
| author | costan@gmail.com <costan@gmail.com@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2013-11-15 13:24:42 +0000 |
|---|---|---|
| committer | costan@gmail.com <costan@gmail.com@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2013-11-15 13:24:42 +0000 |
| commit | 83dc38cd16e7cc8dec3d0f9224a8d4a2e453459f (patch) | |
| tree | a4b52e7b1a6c1709431a6745dfb2371711311b4a /third_party/WebKit/LayoutTests/fast/files/blob-constructor.html | |
| parent | 4a2309898062a594325174ab56c5018cf1be2c95 (diff) | |
| download | chromium_src-83dc38cd16e7cc8dec3d0f9224a8d4a2e453459f.zip chromium_src-83dc38cd16e7cc8dec3d0f9224a8d4a2e453459f.tar.gz chromium_src-83dc38cd16e7cc8dec3d0f9224a8d4a2e453459f.tar.bz2 | |
Implement File constructor.
The feature is behind the FileConstructor RuntimeEnabledFeature with
status=experimental.
BUG=164933
Review URL: https://codereview.chromium.org/57483002
git-svn-id: svn://svn.chromium.org/blink/trunk@162116 bbb929c8-8fbe-4397-9dbb-9b2b20218538
Diffstat (limited to 'third_party/WebKit/LayoutTests/fast/files/blob-constructor.html')
| -rw-r--r-- | third_party/WebKit/LayoutTests/fast/files/blob-constructor.html | 126 |
1 files changed, 118 insertions, 8 deletions
diff --git a/third_party/WebKit/LayoutTests/fast/files/blob-constructor.html b/third_party/WebKit/LayoutTests/fast/files/blob-constructor.html index 08e22a9..f5c125f 100644 --- a/third_party/WebKit/LayoutTests/fast/files/blob-constructor.html +++ b/third_party/WebKit/LayoutTests/fast/files/blob-constructor.html @@ -1,9 +1,119 @@ -<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> -<html> -<head> +<!DOCTYPE html> + <script src="../../resources/js-test.js"></script> -</head> -<body> -<script src="script-tests/blob-constructor.js"></script> -</body> -</html> +<script> +description("Test the Blob constructor."); + +// Test the different ways you can construct a Blob. +shouldBeTrue("(new Blob()) instanceof window.Blob"); +shouldBeTrue("(new Blob([])) instanceof window.Blob"); +shouldBeTrue("(new Blob(['hello'])) instanceof window.Blob"); +shouldBeTrue("(new Blob(['hello'], {})) instanceof window.Blob"); +shouldBeTrue("(new Blob(['hello'], {type:'text/html'})) instanceof window.Blob"); +shouldBeTrue("(new Blob(['hello'], {type:'text/html', endings:'native'})) instanceof window.Blob"); +shouldBeTrue("(new Blob(['hello'], {type:'text/html', endings:'transparent'})) instanceof window.Blob"); + +// Test invalid blob parts. +shouldThrow("new Blob('hello')", '"TypeError: Failed to construct \'Blob\': The 1st argument is neither an array, nor does it have indexed properties."'); +shouldThrow("new Blob(0)", '"TypeError: Failed to construct \'Blob\': The 1st argument is neither an array, nor does it have indexed properties."'); + +// Test valid blob parts. +shouldBeTrue("(new Blob([])) instanceof window.Blob"); +shouldBeTrue("(new Blob(['stringPrimitive'])) instanceof window.Blob"); +shouldBeTrue("(new Blob([String('stringObject')])) instanceof window.Blob"); +shouldBeTrue("(new Blob([new Blob])) instanceof window.Blob"); +shouldBeTrue("(new Blob([new Blob([new Blob])])) instanceof window.Blob"); + +// Test some conversions to string in the parts array. +shouldBe("(new Blob([12])).size", "2"); +shouldBe("(new Blob([[]])).size", "0"); // [].toString() is the empty string +shouldBe("(new Blob([{}])).size", "15");; // {}.toString() is the string "[object Object]" +shouldBe("(new Blob([document])).size", "21"); // document.toString() is the string "[object HTMLDocument]" + +var toStringingObj = { toString: function() { return "A string"; } }; +shouldBe("(new Blob([toStringingObj])).size", "8"); + +var throwingObj = { toString: function() { throw "Error"; } }; +shouldThrow("new Blob([throwingObj])", "'Error'"); + +// Test some invalid property bags. +shouldBeTrue("(new Blob([], {unknownKey:'value'})) instanceof window.Blob"); // Ignore invalid keys +shouldThrow("new Blob([], {endings:'illegalValue'})", "'TypeError: Failed to construct \\'Blob\\': The \"endings\" property must be either \"transparent\" or \"native\".'"); +shouldThrow("new Blob([], {endings:throwingObj})", "'Error'"); +shouldThrow("new Blob([], {type:throwingObj})", "'Error'"); +shouldThrow("new Blob([], {type:'hello\u00EE'})", "'SyntaxError: Failed to construct \\'Blob\\': The \"type\" property must consist of ASCII characters.'"); + +// Test that order of property bag evaluation is lexigraphical +var throwingObj1 = { toString: function() { throw "Error 1"; } }; +var throwingObj2 = { toString: function() { throw "Error 2"; } }; +shouldThrow("new Blob([], {endings:throwingObj1, type:throwingObj2})", "'Error 1'"); +shouldThrow("new Blob([], {type:throwingObj2, endings:throwingObj1})", "'Error 1'"); +shouldThrow("new Blob([], {type:throwingObj2, endings:'illegal'})", "'TypeError: Failed to construct \\'Blob\\': The \"endings\" property must be either \"transparent\" or \"native\".'"); + +// Test various non-object literals being used as property bags. +shouldThrow("(new Blob([], null)) instanceof window.Blob", "'TypeError: Failed to construct \\'Blob\\': The 2nd argument is not of type Object.'"); +shouldThrow("(new Blob([], undefined)) instanceof window.Blob", "'TypeError: Failed to construct \\'Blob\\': The 2nd argument is not of type Object.'"); +shouldThrow("(new Blob([], 123)) instanceof window.Blob", "'TypeError: Failed to construct \\'Blob\\': The 2nd argument is not of type Object.'"); +shouldThrow("(new Blob([], 123.4)) instanceof window.Blob", "'TypeError: Failed to construct \\'Blob\\': The 2nd argument is not of type Object.'"); +shouldThrow("(new Blob([], true)) instanceof window.Blob", "'TypeError: Failed to construct \\'Blob\\': The 2nd argument is not of type Object.'"); +shouldThrow("(new Blob([], 'abc')) instanceof window.Blob", "'TypeError: Failed to construct \\'Blob\\': The 2nd argument is not of type Object.'"); +shouldBeTrue("(new Blob([], [])) instanceof window.Blob"); +shouldBeTrue("(new Blob([], /abc/)) instanceof window.Blob"); +shouldBeTrue("(new Blob([], function () {})) instanceof window.Blob"); + +// Test that the type/size is correctly added to the Blob +shouldBe("(new Blob([], {type:'text/html'})).type", "'text/html'"); +shouldBe("(new Blob([], {type:'text/html'})).size", "0"); +shouldBe("(new Blob([], {type:'text/plain;charset=UTF-8'})).type", "'text/plain;charset=utf-8'"); + +// Test the number of expected arguments in the Blob constructor. +shouldBe("window.Blob.length", "0"); + +// Test ArrayBufferView parameters. +shouldBe("new Blob([new DataView(new ArrayBuffer(100))]).size", "100"); +shouldBe("new Blob([new Uint8Array(100)]).size", "100"); +shouldBe("new Blob([new Uint8ClampedArray(100)]).size", "100"); +shouldBe("new Blob([new Uint16Array(100)]).size", "200"); +shouldBe("new Blob([new Uint32Array(100)]).size", "400"); +shouldBe("new Blob([new Int8Array(100)]).size", "100"); +shouldBe("new Blob([new Int16Array(100)]).size", "200"); +shouldBe("new Blob([new Int32Array(100)]).size", "400"); +shouldBe("new Blob([new Float32Array(100)]).size", "400"); +shouldBe("new Blob([new Float64Array(100)]).size", "800"); +shouldBe("new Blob([new Float64Array(100), new Int32Array(100), new Uint8Array(100), new DataView(new ArrayBuffer(100))]).size", "1400"); +shouldBe("new Blob([new Blob([new Int32Array(100)]), new Uint8Array(100), new Float32Array(100), new DataView(new ArrayBuffer(100))]).size", "1000"); + +// Test ArrayBuffer parameters. +shouldBe("new Blob([(new DataView(new ArrayBuffer(100))).buffer]).size", "100"); +shouldBe("new Blob([(new Uint8Array(100)).buffer]).size", "100"); +shouldBe("new Blob([(new Uint8ClampedArray(100)).buffer]).size", "100"); +shouldBe("new Blob([(new Uint16Array(100)).buffer]).size", "200"); +shouldBe("new Blob([(new Uint32Array(100)).buffer]).size", "400"); +shouldBe("new Blob([(new Int8Array(100)).buffer]).size", "100"); +shouldBe("new Blob([(new Int16Array(100)).buffer]).size", "200"); +shouldBe("new Blob([(new Int32Array(100)).buffer]).size", "400"); +shouldBe("new Blob([(new Float32Array(100)).buffer]).size", "400"); +shouldBe("new Blob([(new Float64Array(100)).buffer]).size", "800"); +shouldBe("new Blob([(new Float64Array(100)).buffer, (new Int32Array(100)).buffer, (new Uint8Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer]).size", "1400"); +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"); + +// Test passing blob parts in sequences. +shouldBeTrue("new Blob({length: 0}) instanceof window.Blob"); +shouldBe("new Blob({length: 0}).size", "0"); +shouldBe("new Blob({length: 1, 0: 'string'}).size", "6"); +shouldBe("new Blob({length: 2, 0: new Uint8Array(100), 1: new Int16Array(100)}).size", "300"); +shouldBe("new Blob({length: 1, 0: 'string'}, {type: 'text/html'}).type", "'text/html'"); +shouldThrow("new Blob({length: 0}, {endings:'illegal'})", "'TypeError: Failed to construct \\'Blob\\': The \"endings\" property must be either \"transparent\" or \"native\".'"); + +// Test passing blog parts in a sequence-like object that throws on property access. +var throwingSequence = {length: 4, 0: 'hello', 3: 'world'}; +Object.defineProperty(throwingSequence, "1", { + get: function() { throw new Error("Misbehaving property"); }, + enumerable: true, configurable: true +}); +Object.defineProperty(throwingSequence, "2", { + get: function() { throw new Error("This should not be thrown"); }, + enumerable: true, configurable: true +}); +shouldThrow("new Blob(throwingSequence)", "'Error: Misbehaving property'"); +</script> |
