diff options
Diffstat (limited to 'third_party/WebKit/LayoutTests/fast/files')
10 files changed, 740 insertions, 234 deletions
diff --git a/third_party/WebKit/LayoutTests/fast/files/blob-constructor-expected.txt b/third_party/WebKit/LayoutTests/fast/files/blob-constructor-expected.txt index 35e7b05..8d65661 100644 --- a/third_party/WebKit/LayoutTests/fast/files/blob-constructor-expected.txt +++ b/third_party/WebKit/LayoutTests/fast/files/blob-constructor-expected.txt @@ -24,13 +24,13 @@ PASS (new Blob([document])).size is 21 PASS (new Blob([toStringingObj])).size is 8 PASS new Blob([throwingObj]) threw exception Error. PASS (new Blob([], {unknownKey:'value'})) instanceof window.Blob is true -PASS new Blob([], {endings:'illegalValue'}) threw exception TypeError: Failed to construct 'Blob': The 2nd argument's "endings" property must be either "transparent" or "native".. +PASS new Blob([], {endings:'illegalValue'}) threw exception TypeError: Failed to construct 'Blob': The "endings" property must be either "transparent" or "native".. PASS new Blob([], {endings:throwingObj}) threw exception Error. PASS new Blob([], {type:throwingObj}) threw exception Error. -PASS new Blob([], {type:'helloî'}) threw exception SyntaxError: Failed to construct 'Blob': The 2nd argument's "type" property must consist of ASCII characters.. +PASS new Blob([], {type:'helloî'}) threw exception SyntaxError: Failed to construct 'Blob': The "type" property must consist of ASCII characters.. PASS new Blob([], {endings:throwingObj1, type:throwingObj2}) threw exception Error 1. PASS new Blob([], {type:throwingObj2, endings:throwingObj1}) threw exception Error 1. -PASS new Blob([], {type:throwingObj2, endings:'illegal'}) threw exception TypeError: Failed to construct 'Blob': The 2nd argument's "endings" property must be either "transparent" or "native".. +PASS new Blob([], {type:throwingObj2, endings:'illegal'}) threw exception TypeError: Failed to construct 'Blob': The "endings" property must be either "transparent" or "native".. PASS (new Blob([], null)) instanceof window.Blob threw exception TypeError: Failed to construct 'Blob': The 2nd argument is not of type Object.. PASS (new Blob([], undefined)) instanceof window.Blob threw exception TypeError: Failed to construct 'Blob': The 2nd argument is not of type Object.. PASS (new Blob([], 123)) instanceof window.Blob threw exception TypeError: Failed to construct 'Blob': The 2nd argument is not of type Object.. @@ -43,7 +43,7 @@ PASS (new Blob([], function () {})) instanceof window.Blob is true PASS (new Blob([], {type:'text/html'})).type is 'text/html' PASS (new Blob([], {type:'text/html'})).size is 0 PASS (new Blob([], {type:'text/plain;charset=UTF-8'})).type is 'text/plain;charset=utf-8' -FAIL window.Blob.length should be 2. Was 0. +PASS window.Blob.length is 0 PASS new Blob([new DataView(new ArrayBuffer(100))]).size is 100 PASS new Blob([new Uint8Array(100)]).size is 100 PASS new Blob([new Uint8ClampedArray(100)]).size is 100 @@ -73,7 +73,7 @@ PASS new Blob({length: 0}).size is 0 PASS new Blob({length: 1, 0: 'string'}).size is 6 PASS new Blob({length: 2, 0: new Uint8Array(100), 1: new Int16Array(100)}).size is 300 PASS new Blob({length: 1, 0: 'string'}, {type: 'text/html'}).type is 'text/html' -PASS new Blob({length: 0}, {endings:'illegal'}) threw exception TypeError: Failed to construct 'Blob': The 2nd argument's "endings" property must be either "transparent" or "native".. +PASS new Blob({length: 0}, {endings:'illegal'}) threw exception TypeError: Failed to construct 'Blob': The "endings" property must be either "transparent" or "native".. PASS new Blob(throwingSequence) threw exception Error: Misbehaving property. PASS successfullyParsed is true 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> diff --git a/third_party/WebKit/LayoutTests/fast/files/blob-parts-slice-test-expected.txt b/third_party/WebKit/LayoutTests/fast/files/blob-parts-slice-test-expected.txt new file mode 100644 index 0000000..87727d8 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/files/blob-parts-slice-test-expected.txt @@ -0,0 +1,117 @@ +Test the Blob.slice() behavior for Blobs made of multiple parts. + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +Blob .slice(2, 3) +PASS blobContents is "2" +File .slice(2, 3) +PASS fileContents is "2" +Blob .slice(2, 12) +PASS blobContents is "23456789" +File .slice(2, 12) +PASS fileContents is "23456789" +Blob .slice(2, 2) +PASS blobContents is "" +File .slice(2, 2) +PASS fileContents is "" +Blob .slice(2, 1) +PASS blobContents is "" +File .slice(2, 1) +PASS fileContents is "" +Blob .slice(2, -12) +PASS blobContents is "" +File .slice(2, -12) +PASS fileContents is "" +Blob .slice(2, 2147483647) +PASS blobContents is "23456789" +File .slice(2, 2147483647) +PASS fileContents is "23456789" +Blob .slice(2, -2147483648) +PASS blobContents is "" +File .slice(2, -2147483648) +PASS fileContents is "" +Blob .slice(2, 9223372036854775000) +PASS blobContents is "23456789" +File .slice(2, 9223372036854775000) +PASS fileContents is "23456789" +Blob .slice(2, -9223372036854775000) +PASS blobContents is "" +File .slice(2, -9223372036854775000) +PASS fileContents is "" +Blob .slice(-2, -1) +PASS blobContents is "8" +File .slice(-2, -1) +PASS fileContents is "8" +Blob .slice(-2, -2) +PASS blobContents is "" +File .slice(-2, -2) +PASS fileContents is "" +Blob .slice(-2, -3) +PASS blobContents is "" +File .slice(-2, -3) +PASS fileContents is "" +Blob .slice(-2, -12) +PASS blobContents is "" +File .slice(-2, -12) +PASS fileContents is "" +Blob .slice(-2, 2147483647) +PASS blobContents is "89" +File .slice(-2, 2147483647) +PASS fileContents is "89" +Blob .slice(-2, -2147483648) +PASS blobContents is "" +File .slice(-2, -2147483648) +PASS fileContents is "" +Blob .slice(-2, 9223372036854775000) +PASS blobContents is "89" +File .slice(-2, 9223372036854775000) +PASS fileContents is "89" +Blob .slice(-2, -9223372036854775000) +PASS blobContents is "" +File .slice(-2, -9223372036854775000) +PASS fileContents is "" +Blob .slice(0) +PASS blobContents is "0123456789" +File .slice(0) +PASS fileContents is "0123456789" +Blob .slice(2) +PASS blobContents is "23456789" +File .slice(2) +PASS fileContents is "23456789" +Blob .slice(-2) +PASS blobContents is "89" +File .slice(-2) +PASS fileContents is "89" +Blob .slice(12) +PASS blobContents is "" +File .slice(12) +PASS fileContents is "" +Blob .slice(-12) +PASS blobContents is "0123456789" +File .slice(-12) +PASS fileContents is "0123456789" +Blob .slice(2147483647) +PASS blobContents is "" +File .slice(2147483647) +PASS fileContents is "" +Blob .slice(-2147483648) +PASS blobContents is "0123456789" +File .slice(-2147483648) +PASS fileContents is "0123456789" +Blob .slice(9223372036854775000) +PASS blobContents is "" +File .slice(9223372036854775000) +PASS fileContents is "" +Blob .slice(-9223372036854775000) +PASS blobContents is "0123456789" +File .slice(-9223372036854775000) +PASS fileContents is "0123456789" +Blob .slice() +PASS blobContents is "0123456789" +File .slice() +PASS fileContents is "0123456789" +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/third_party/WebKit/LayoutTests/fast/files/blob-parts-slice-test.html b/third_party/WebKit/LayoutTests/fast/files/blob-parts-slice-test.html new file mode 100644 index 0000000..9f2f47b --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/files/blob-parts-slice-test.html @@ -0,0 +1,55 @@ +<!DOCTYPE html> +<html> +<head> +<script src="../../resources/js-test.js"></script> +<script src="resources/blob-slice-common.js"></script> +<script> +description("Test the Blob.slice() behavior for Blobs made of multiple parts."); + +var sliceTestCases = [ + [2, 3, "2"], + [2, 12, "23456789"], + [2, 2, ""], + [2, 1, ""], + [2, -12, ""], + [2, 2147483647, "23456789"], + [2, -2147483648, ""], + [2, 9223372036854775000, "23456789"], + [2, -9223372036854775000, ""], + [-2, -1, "8"], + [-2, -2, ""], + [-2, -3, ""], + [-2, -12, ""], + [-2, 2147483647, "89"], + [-2, -2147483648, ""], + [-2, 9223372036854775000, "89"], + [-2, -9223372036854775000, ""], + [0, null, "0123456789"], + [2, null, "23456789"], + [-2, null, "89"], + [12, null, ""], + [-12, null, "0123456789"], + [2147483647, null, ""], + [-2147483648, null, "0123456789"], + [9223372036854775000, null, ""], + [-9223372036854775000, null, "0123456789"], + [null, null, "0123456789"], +]; + +function runTests() +{ + blob = new Blob(["0", new File(["12"], "slice-piece.txt"), + new Blob(["345"]), "6789"]); + file = new File(["0", new File(["12"], "slice-piece.txt"), + new Blob(["345"]), "6789"], "slice-text.txt"); + + runNextTest(); +} + +window.jsTestIsAsync = true; +</script> +</head> +<body onload="runTests()"> +<pre id='console'></pre> +</body> +</html> diff --git a/third_party/WebKit/LayoutTests/fast/files/blob-slice-test-expected.txt b/third_party/WebKit/LayoutTests/fast/files/blob-slice-test-expected.txt index 0f274d3..2f12c4f 100644 --- a/third_party/WebKit/LayoutTests/fast/files/blob-slice-test-expected.txt +++ b/third_party/WebKit/LayoutTests/fast/files/blob-slice-test-expected.txt @@ -1,28 +1,117 @@ -Slicing from 2 to 3: 2 -Slicing from 2 to 12: 23456789 -Slicing from 2 to 2: -Slicing from 2 to 1: -Slicing from 2 to -12: -Slicing from 2 to 2147483647: 23456789 -Slicing from 2 to -2147483648: -Slicing from 2 to 9223372036854775000: 23456789 -Slicing from 2 to -9223372036854775000: -Slicing from -2 to -1: 8 -Slicing from -2 to -2: -Slicing from -2 to -3: -Slicing from -2 to -12: -Slicing from -2 to 2147483647: 89 -Slicing from -2 to -2147483648: -Slicing from -2 to 9223372036854775000: 89 -Slicing from -2 to -9223372036854775000: -Slicing from 0: 0123456789 -Slicing from 2: 23456789 -Slicing from -2: 89 -Slicing from 12: -Slicing from -12: 0123456789 -Slicing from 2147483647: -Slicing from -2147483648: 0123456789 -Slicing from 9223372036854775000: -Slicing from -9223372036854775000: 0123456789 -Slicing without parameters: 0123456789 +Test Blob.slice(). + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +Blob .slice(2, 3) +PASS blobContents is "2" +File .slice(2, 3) +PASS fileContents is "2" +Blob .slice(2, 12) +PASS blobContents is "23456789" +File .slice(2, 12) +PASS fileContents is "23456789" +Blob .slice(2, 2) +PASS blobContents is "" +File .slice(2, 2) +PASS fileContents is "" +Blob .slice(2, 1) +PASS blobContents is "" +File .slice(2, 1) +PASS fileContents is "" +Blob .slice(2, -12) +PASS blobContents is "" +File .slice(2, -12) +PASS fileContents is "" +Blob .slice(2, 2147483647) +PASS blobContents is "23456789" +File .slice(2, 2147483647) +PASS fileContents is "23456789" +Blob .slice(2, -2147483648) +PASS blobContents is "" +File .slice(2, -2147483648) +PASS fileContents is "" +Blob .slice(2, 9223372036854775000) +PASS blobContents is "23456789" +File .slice(2, 9223372036854775000) +PASS fileContents is "23456789" +Blob .slice(2, -9223372036854775000) +PASS blobContents is "" +File .slice(2, -9223372036854775000) +PASS fileContents is "" +Blob .slice(-2, -1) +PASS blobContents is "8" +File .slice(-2, -1) +PASS fileContents is "8" +Blob .slice(-2, -2) +PASS blobContents is "" +File .slice(-2, -2) +PASS fileContents is "" +Blob .slice(-2, -3) +PASS blobContents is "" +File .slice(-2, -3) +PASS fileContents is "" +Blob .slice(-2, -12) +PASS blobContents is "" +File .slice(-2, -12) +PASS fileContents is "" +Blob .slice(-2, 2147483647) +PASS blobContents is "89" +File .slice(-2, 2147483647) +PASS fileContents is "89" +Blob .slice(-2, -2147483648) +PASS blobContents is "" +File .slice(-2, -2147483648) +PASS fileContents is "" +Blob .slice(-2, 9223372036854775000) +PASS blobContents is "89" +File .slice(-2, 9223372036854775000) +PASS fileContents is "89" +Blob .slice(-2, -9223372036854775000) +PASS blobContents is "" +File .slice(-2, -9223372036854775000) +PASS fileContents is "" +Blob .slice(0) +PASS blobContents is "0123456789" +File .slice(0) +PASS fileContents is "0123456789" +Blob .slice(2) +PASS blobContents is "23456789" +File .slice(2) +PASS fileContents is "23456789" +Blob .slice(-2) +PASS blobContents is "89" +File .slice(-2) +PASS fileContents is "89" +Blob .slice(12) +PASS blobContents is "" +File .slice(12) +PASS fileContents is "" +Blob .slice(-12) +PASS blobContents is "0123456789" +File .slice(-12) +PASS fileContents is "0123456789" +Blob .slice(2147483647) +PASS blobContents is "" +File .slice(2147483647) +PASS fileContents is "" +Blob .slice(-2147483648) +PASS blobContents is "0123456789" +File .slice(-2147483648) +PASS fileContents is "0123456789" +Blob .slice(9223372036854775000) +PASS blobContents is "" +File .slice(9223372036854775000) +PASS fileContents is "" +Blob .slice(-9223372036854775000) +PASS blobContents is "0123456789" +File .slice(-9223372036854775000) +PASS fileContents is "0123456789" +Blob .slice() +PASS blobContents is "0123456789" +File .slice() +PASS fileContents is "0123456789" +PASS successfullyParsed is true + +TEST COMPLETE diff --git a/third_party/WebKit/LayoutTests/fast/files/blob-slice-test.html b/third_party/WebKit/LayoutTests/fast/files/blob-slice-test.html index 06fec6e..e6a2989 100644 --- a/third_party/WebKit/LayoutTests/fast/files/blob-slice-test.html +++ b/third_party/WebKit/LayoutTests/fast/files/blob-slice-test.html @@ -1,96 +1,50 @@ <!DOCTYPE html> <html> <head> +<script src="../../resources/js-test.js"></script> +<script src="resources/blob-slice-common.js"></script> <script> -var blob; -var testIndex = 0; -var sliceParams = [ - [2, 3], - [2, 12], - [2, 2], - [2, 1], - [2, -12], - [2, 2147483647], - [2, -2147483648], - [2, 9223372036854775000], - [2, -9223372036854775000], - [-2, -1], - [-2, -2], - [-2, -3], - [-2, -12], - [-2, 2147483647], - [-2, -2147483648], - [-2, 9223372036854775000], - [-2, -9223372036854775000], - [0], - [2], - [-2], - [12], - [-12], - [2147483647], - [-2147483648], - [9223372036854775000], - [-9223372036854775000], - [], -]; - -function log(message) -{ - document.getElementById('console').appendChild(document.createTextNode(message + "\n")); -} - -function testSlicing(start, end) -{ - var subBlob; - var reader = new FileReader(); - var message = "Slicing "; - if (start == undefined && end == undefined) { - message += "without parameters"; - subBlob = blob.slice(); - } else if (end == undefined) { - message += "from " + start; - subBlob = blob.slice(start); - } else { - message += "from " + start + " to " + end; - subBlob = blob.slice(start, end); - } - message += ": "; - reader.onload = function(event) { - log(message + event.target.result); - runNextTest(); - }; - reader.onerror = function(event) { - log(message + "error " + event.target.error.code); - runNextTest(); - }; - reader.readAsText(subBlob); -} - -function runNextTest() -{ - if (testIndex >= sliceParams.length) { - if (window.testRunner) - testRunner.notifyDone(); - return; - } +description("Test Blob.slice()."); - var start = sliceParams[testIndex][0]; - var end = sliceParams[testIndex][1]; - testIndex++; - testSlicing(start, end); -} +var sliceTestCases = [ + [2, 3, "2"], + [2, 12, "23456789"], + [2, 2, ""], + [2, 1, ""], + [2, -12, ""], + [2, 2147483647, "23456789"], + [2, -2147483648, ""], + [2, 9223372036854775000, "23456789"], + [2, -9223372036854775000, ""], + [-2, -1, "8"], + [-2, -2, ""], + [-2, -3, ""], + [-2, -12, ""], + [-2, 2147483647, "89"], + [-2, -2147483648, ""], + [-2, 9223372036854775000, "89"], + [-2, -9223372036854775000, ""], + [0, null, "0123456789"], + [2, null, "23456789"], + [-2, null, "89"], + [12, null, ""], + [-12, null, "0123456789"], + [2147483647, null, ""], + [-2147483648, null, "0123456789"], + [9223372036854775000, null, ""], + [-9223372036854775000, null, "0123456789"], + [null, null, "0123456789"], +]; function runTests() { blob = new Blob(["0123456789"]); + file = new File(["0123456789"], "slice-test.txt"); runNextTest(); } -if (window.testRunner) { - testRunner.dumpAsText(); - testRunner.waitUntilDone(); -} +window.jsTestIsAsync = true; </script> </head> <body onload="runTests()"> diff --git a/third_party/WebKit/LayoutTests/fast/files/file-constructor-expected.txt b/third_party/WebKit/LayoutTests/fast/files/file-constructor-expected.txt new file mode 100644 index 0000000..2c4bf48 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/files/file-constructor-expected.txt @@ -0,0 +1,100 @@ +Test the File constructor. + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +PASS (new File([], 'world.html')) instanceof window.File is true +PASS (new File(['hello'], 'world.html')) instanceof window.File is true +PASS (new File(['hello'], 'world.html', {})) instanceof window.File is true +PASS (new File(['hello'], 'world.html', {type:'text/html'})) instanceof window.File is true +PASS (new File(['hello'], 'world.html', {type:'text/html', endings:'native'})) instanceof window.File is true +PASS (new File(['hello'], 'world.html', {type:'text/html', endings:'transparent'})) instanceof window.File is true +PASS (new File([], 'world.html')) instanceof window.File is true +PASS (new File()) threw exception TypeError: File constructor requires at least two arguments. +PASS (new File([])) threw exception TypeError: File constructor requires at least two arguments. +PASS (new File([], null)) instanceof window.File is true +PASS (new File([], 1)) instanceof window.File is true +PASS (new File([], '')) instanceof window.File is true +PASS (new File([], document)) instanceof window.File is true +PASS new File('hello', 'world.html') threw exception TypeError: Failed to construct 'File': The 1st argument is neither an array, nor does it have indexed properties.. +PASS new File(0, 'world.html') threw exception TypeError: Failed to construct 'File': The 1st argument is neither an array, nor does it have indexed properties.. +PASS (new File([], 'world.html')) instanceof window.File is true +PASS (new File(['stringPrimitive'], 'world.html')) instanceof window.File is true +PASS (new File([String('stringObject')], 'world.html')) instanceof window.File is true +PASS (new File([new Blob], 'world.html')) instanceof window.File is true +PASS (new File([new Blob([new Blob])], 'world.html')) instanceof window.File is true +PASS (new Blob([new File([], 'world.txt')])) instanceof window.Blob is true +PASS (new Blob([new Blob([new File([new Blob], 'world.txt')])])) instanceof window.Blob is true +PASS (new File([new File([], 'world.txt')], 'world.html')) instanceof window.File is true +PASS (new File([new Blob([new File([new Blob], 'world.txt')])], 'world.html')) instanceof window.File is true +PASS (new File([12], 'world.html')).size is 2 +PASS (new File([[]], 'world.html')).size is 0 +PASS (new File([{}], 'world.html')).size is 15 +PASS (new File([document], 'world.html')).size is 21 +PASS (new File([toStringingObj], 'world.html')).size is 8 +PASS new File([throwingObj], 'world.html') threw exception Error. +PASS (new File([], null)).name is 'null' +PASS (new File([], 12)).name is '12' +PASS (new File([], '')).name is '' +PASS (new File([], {})).name is '[object Object]' +PASS (new File([], document)).name is '[object HTMLDocument]' +PASS (new File([], toStringingObj)).name is 'A string' +PASS (new File([], throwingObj)).name threw exception Error. +PASS (new File([], 'world.html', {unknownKey:'value'})) instanceof window.File is true +PASS new File([], 'world.html', {endings:'illegalValue'}) threw exception TypeError: Failed to construct 'File': The "endings" property must be either "transparent" or "native".. +PASS new File([], 'world.html', {endings:throwingObj}) threw exception Error. +PASS new File([], 'world.html', {type:throwingObj}) threw exception Error. +PASS new File([], 'world.html', {type:'helloî'}) threw exception SyntaxError: Failed to construct 'File': The "type" property must consist of ASCII characters.. +PASS (new File([], 'world.html', null)) instanceof window.File threw exception TypeError: Failed to construct 'File': The 3rd argument is not of type Object.. +PASS (new File([], 'world.html', undefined)) instanceof window.File threw exception TypeError: Failed to construct 'File': The 3rd argument is not of type Object.. +PASS (new File([], 'world.html', 123)) instanceof window.File threw exception TypeError: Failed to construct 'File': The 3rd argument is not of type Object.. +PASS (new File([], 'world.html', 123.4)) instanceof window.File threw exception TypeError: Failed to construct 'File': The 3rd argument is not of type Object.. +PASS (new File([], 'world.html', true)) instanceof window.File threw exception TypeError: Failed to construct 'File': The 3rd argument is not of type Object.. +PASS (new File([], 'world.html', 'abc')) instanceof window.File threw exception TypeError: Failed to construct 'File': The 3rd argument is not of type Object.. +PASS (new File([], 'world.html', [])) instanceof window.File is true +PASS (new File([], 'world.html', /abc/)) instanceof window.File is true +PASS (new File([], 'world.html', function () {})) instanceof window.File is true +PASS (new File([], 'world.html', {type:'text/html'})).name is 'world.html' +PASS (new File([], 'world.html', {type:'text/html'})).type is 'text/html' +PASS (new File([], 'world.html', {type:'text/html'})).size is 0 +PASS (new File([], 'world.html', {type:'text/plain;charset=UTF-8'})).type is 'text/plain;charset=utf-8' +PASS window.File.length is 2 +PASS new File([new DataView(new ArrayBuffer(100))], 'world.html').size is 100 +PASS new File([new Uint8Array(100)], 'world.html').size is 100 +PASS new File([new Uint8ClampedArray(100)], 'world.html').size is 100 +PASS new File([new Uint16Array(100)], 'world.html').size is 200 +PASS new File([new Uint32Array(100)], 'world.html').size is 400 +PASS new File([new Int8Array(100)], 'world.html').size is 100 +PASS new File([new Int16Array(100)], 'world.html').size is 200 +PASS new File([new Int32Array(100)], 'world.html').size is 400 +PASS new File([new Float32Array(100)], 'world.html').size is 400 +PASS new File([new Float64Array(100)], 'world.html').size is 800 +PASS new File([new Float64Array(100), new Int32Array(100), new Uint8Array(100), new DataView(new ArrayBuffer(100))], 'world.html').size is 1400 +PASS new File([new Blob([new Int32Array(100)]), new Uint8Array(100), new Float32Array(100), new DataView(new ArrayBuffer(100))], 'world.html').size is 1000 +PASS new File([new Blob([new Int32Array(100)]), new File([new Uint16Array(100)], 'world.txt'), new Uint8Array(100), new Float32Array(100), new DataView(new ArrayBuffer(100))], 'world.html').size is 1200 +PASS new File([(new DataView(new ArrayBuffer(100))).buffer], 'world.html').size is 100 +PASS new File([(new Uint8Array(100)).buffer], 'world.html').size is 100 +PASS new File([(new Uint8ClampedArray(100)).buffer], 'world.html').size is 100 +PASS new File([(new Uint16Array(100)).buffer], 'world.html').size is 200 +PASS new File([(new Uint32Array(100)).buffer], 'world.html').size is 400 +PASS new File([(new Int8Array(100)).buffer], 'world.html').size is 100 +PASS new File([(new Int16Array(100)).buffer], 'world.html').size is 200 +PASS new File([(new Int32Array(100)).buffer], 'world.html').size is 400 +PASS new File([(new Float32Array(100)).buffer], 'world.html').size is 400 +PASS new File([(new Float64Array(100)).buffer], 'world.html').size is 800 +PASS new File([(new Float64Array(100)).buffer, (new Int32Array(100)).buffer, (new Uint8Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer], 'world.html').size is 1400 +PASS new File([new Blob([(new Int32Array(100)).buffer]), (new Uint8Array(100)).buffer, (new Float32Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer], 'world.html').size is 1000 +PASS new File([new Blob([(new Int32Array(100)).buffer]), new File([new Uint16Array(100).buffer], 'world.txt'), (new Uint8Array(100)).buffer, (new Float32Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer], 'world.html').size is 1200 +PASS new Blob([new Blob([new Int32Array(100)]), new File([new Uint16Array(100)], 'world.txt'), new Uint8Array(100), new Float32Array(100), new DataView(new ArrayBuffer(100))]).size is 1200 +PASS new Blob([new Blob([(new Int32Array(100)).buffer]), new File([new Uint16Array(100).buffer], 'world.txt'), (new Uint8Array(100)).buffer, (new Float32Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer]).size is 1200 +PASS new File({length: 0}, 'world.txt') instanceof window.File is true +PASS new File({length: 0}, 'world.txt').size is 0 +PASS new File({length: 1, 0: 'string'}, 'world.txt').size is 6 +PASS new File({length: 2, 0: new Uint8Array(100), 1: new Int16Array(100)}, 'world.txt').size is 300 +PASS new File({length: 1, 0: 'string'}, 'world.txt', {type: 'text/html'}).type is 'text/html' +PASS new File({length: 0}, 'world.txt', {endings:'illegal'}) threw exception TypeError: Failed to construct 'File': The "endings" property must be either "transparent" or "native".. +PASS new File(throwingSequence, 'world.txt') threw exception Error: Misbehaving property. +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/third_party/WebKit/LayoutTests/fast/files/file-constructor.html b/third_party/WebKit/LayoutTests/fast/files/file-constructor.html new file mode 100644 index 0000000..f615864 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/files/file-constructor.html @@ -0,0 +1,146 @@ +<!DOCTYPE html> + +<script src="../../resources/js-test.js"></script> +<script> +description("Test the File constructor."); + +// Test the different ways you can construct a File. +shouldBeTrue("(new File([], 'world.html')) instanceof window.File"); +shouldBeTrue("(new File(['hello'], 'world.html')) instanceof window.File"); +shouldBeTrue("(new File(['hello'], 'world.html', {})) instanceof window.File"); +shouldBeTrue("(new File(['hello'], 'world.html', {type:'text/html'})) instanceof window.File"); +shouldBeTrue("(new File(['hello'], 'world.html', {type:'text/html', endings:'native'})) instanceof window.File"); +shouldBeTrue("(new File(['hello'], 'world.html', {type:'text/html', endings:'transparent'})) instanceof window.File"); + +// Test that File inherits from File. +shouldBeTrue("(new File([], 'world.html')) instanceof window.File") + +// Verify that the file name argument is required. +shouldThrow("(new File())", "'TypeError: File constructor requires at least two arguments'"); +shouldThrow("(new File([]))", "'TypeError: File constructor requires at least two arguments'"); + +// Test valid file names. +shouldBeTrue("(new File([], null)) instanceof window.File"); +shouldBeTrue("(new File([], 1)) instanceof window.File"); +shouldBeTrue("(new File([], '')) instanceof window.File"); +shouldBeTrue("(new File([], document)) instanceof window.File"); + +// Test invalid blob parts. +shouldThrow("new File('hello', 'world.html')", '"TypeError: Failed to construct \'File\': The 1st argument is neither an array, nor does it have indexed properties."'); +shouldThrow("new File(0, 'world.html')", '"TypeError: Failed to construct \'File\': The 1st argument is neither an array, nor does it have indexed properties."'); + +// Test valid blob parts. +shouldBeTrue("(new File([], 'world.html')) instanceof window.File"); +shouldBeTrue("(new File(['stringPrimitive'], 'world.html')) instanceof window.File"); +shouldBeTrue("(new File([String('stringObject')], 'world.html')) instanceof window.File"); +shouldBeTrue("(new File([new Blob], 'world.html')) instanceof window.File"); +shouldBeTrue("(new File([new Blob([new Blob])], 'world.html')) instanceof window.File"); + +// Test File instances used as blob parts. +shouldBeTrue("(new Blob([new File([], 'world.txt')])) instanceof window.Blob"); +shouldBeTrue("(new Blob([new Blob([new File([new Blob], 'world.txt')])])) instanceof window.Blob"); +shouldBeTrue("(new File([new File([], 'world.txt')], 'world.html')) instanceof window.File"); +shouldBeTrue("(new File([new Blob([new File([new Blob], 'world.txt')])], 'world.html')) instanceof window.File"); + +// Test some conversions to string in the parts array. +shouldBe("(new File([12], 'world.html')).size", "2"); +shouldBe("(new File([[]], 'world.html')).size", "0"); // [].toString() is the empty string +shouldBe("(new File([{}], 'world.html')).size", "15");; // {}.toString() is the string "[object Object]" +shouldBe("(new File([document], 'world.html')).size", "21"); // document.toString() is the string "[object HTMLDocument]" + +var toStringingObj = { toString: function() { return "A string"; } }; +shouldBe("(new File([toStringingObj], 'world.html')).size", "8"); + +var throwingObj = { toString: function() { throw "Error"; } }; +shouldThrow("new File([throwingObj], 'world.html')", "'Error'"); + +// Test some conversions to string in the file name. +shouldBe("(new File([], null)).name", "'null'"); +shouldBe("(new File([], 12)).name", "'12'"); +shouldBe("(new File([], '')).name", "''"); +shouldBe("(new File([], {})).name", "'[object Object]'"); +shouldBe("(new File([], document)).name", "'[object HTMLDocument]'"); +shouldBe("(new File([], toStringingObj)).name", "'A string'"); +shouldThrow("(new File([], throwingObj)).name", "'Error'"); + +// Test some invalid property bags. +shouldBeTrue("(new File([], 'world.html', {unknownKey:'value'})) instanceof window.File"); // Ignore invalid keys +shouldThrow("new File([], 'world.html', {endings:'illegalValue'})", "'TypeError: Failed to construct \\'File\\': The \"endings\" property must be either \"transparent\" or \"native\".'"); +shouldThrow("new File([], 'world.html', {endings:throwingObj})", "'Error'"); +shouldThrow("new File([], 'world.html', {type:throwingObj})", "'Error'"); +shouldThrow("new File([], 'world.html', {type:'hello\u00EE'})", "'SyntaxError: Failed to construct \\'File\\': The \"type\" property must consist of ASCII characters.'"); + +// Test various non-object literals being used as property bags. +shouldThrow("(new File([], 'world.html', null)) instanceof window.File", "'TypeError: Failed to construct \\'File\\': The 3rd argument is not of type Object.'"); +shouldThrow("(new File([], 'world.html', undefined)) instanceof window.File", "'TypeError: Failed to construct \\'File\\': The 3rd argument is not of type Object.'"); +shouldThrow("(new File([], 'world.html', 123)) instanceof window.File", "'TypeError: Failed to construct \\'File\\': The 3rd argument is not of type Object.'"); +shouldThrow("(new File([], 'world.html', 123.4)) instanceof window.File", "'TypeError: Failed to construct \\'File\\': The 3rd argument is not of type Object.'"); +shouldThrow("(new File([], 'world.html', true)) instanceof window.File", "'TypeError: Failed to construct \\'File\\': The 3rd argument is not of type Object.'"); +shouldThrow("(new File([], 'world.html', 'abc')) instanceof window.File", "'TypeError: Failed to construct \\'File\\': The 3rd argument is not of type Object.'"); +shouldBeTrue("(new File([], 'world.html', [])) instanceof window.File"); +shouldBeTrue("(new File([], 'world.html', /abc/)) instanceof window.File"); +shouldBeTrue("(new File([], 'world.html', function () {})) instanceof window.File"); + +// Test that the name/type/size are correctly added to the File. +shouldBe("(new File([], 'world.html', {type:'text/html'})).name", "'world.html'"); +shouldBe("(new File([], 'world.html', {type:'text/html'})).type", "'text/html'"); +shouldBe("(new File([], 'world.html', {type:'text/html'})).size", "0"); +shouldBe("(new File([], 'world.html', {type:'text/plain;charset=UTF-8'})).type", "'text/plain;charset=utf-8'"); + +// Test the number of expected arguments in the File constructor. +shouldBe("window.File.length", "2"); + +// Test ArrayBufferView parameters. +shouldBe("new File([new DataView(new ArrayBuffer(100))], 'world.html').size", "100"); +shouldBe("new File([new Uint8Array(100)], 'world.html').size", "100"); +shouldBe("new File([new Uint8ClampedArray(100)], 'world.html').size", "100"); +shouldBe("new File([new Uint16Array(100)], 'world.html').size", "200"); +shouldBe("new File([new Uint32Array(100)], 'world.html').size", "400"); +shouldBe("new File([new Int8Array(100)], 'world.html').size", "100"); +shouldBe("new File([new Int16Array(100)], 'world.html').size", "200"); +shouldBe("new File([new Int32Array(100)], 'world.html').size", "400"); +shouldBe("new File([new Float32Array(100)], 'world.html').size", "400"); +shouldBe("new File([new Float64Array(100)], 'world.html').size", "800"); +shouldBe("new File([new Float64Array(100), new Int32Array(100), new Uint8Array(100), new DataView(new ArrayBuffer(100))], 'world.html').size", "1400"); +shouldBe("new File([new Blob([new Int32Array(100)]), new Uint8Array(100), new Float32Array(100), new DataView(new ArrayBuffer(100))], 'world.html').size", "1000"); +shouldBe("new File([new Blob([new Int32Array(100)]), new File([new Uint16Array(100)], 'world.txt'), new Uint8Array(100), new Float32Array(100), new DataView(new ArrayBuffer(100))], 'world.html').size", "1200"); + +// Test ArrayBuffer parameters. +shouldBe("new File([(new DataView(new ArrayBuffer(100))).buffer], 'world.html').size", "100"); +shouldBe("new File([(new Uint8Array(100)).buffer], 'world.html').size", "100"); +shouldBe("new File([(new Uint8ClampedArray(100)).buffer], 'world.html').size", "100"); +shouldBe("new File([(new Uint16Array(100)).buffer], 'world.html').size", "200"); +shouldBe("new File([(new Uint32Array(100)).buffer], 'world.html').size", "400"); +shouldBe("new File([(new Int8Array(100)).buffer], 'world.html').size", "100"); +shouldBe("new File([(new Int16Array(100)).buffer], 'world.html').size", "200"); +shouldBe("new File([(new Int32Array(100)).buffer], 'world.html').size", "400"); +shouldBe("new File([(new Float32Array(100)).buffer], 'world.html').size", "400"); +shouldBe("new File([(new Float64Array(100)).buffer], 'world.html').size", "800"); +shouldBe("new File([(new Float64Array(100)).buffer, (new Int32Array(100)).buffer, (new Uint8Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer], 'world.html').size", "1400"); +shouldBe("new File([new Blob([(new Int32Array(100)).buffer]), (new Uint8Array(100)).buffer, (new Float32Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer], 'world.html').size", "1000"); +shouldBe("new File([new Blob([(new Int32Array(100)).buffer]), new File([new Uint16Array(100).buffer], 'world.txt'), (new Uint8Array(100)).buffer, (new Float32Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer], 'world.html').size", "1200"); + +// Test building Blobs with ArrayBuffer / ArrayBufferView parts enclosed in files. +shouldBe("new Blob([new Blob([new Int32Array(100)]), new File([new Uint16Array(100)], 'world.txt'), new Uint8Array(100), new Float32Array(100), new DataView(new ArrayBuffer(100))]).size", "1200"); +shouldBe("new Blob([new Blob([(new Int32Array(100)).buffer]), new File([new Uint16Array(100).buffer], 'world.txt'), (new Uint8Array(100)).buffer, (new Float32Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer]).size", "1200"); + +// Test passing blob parts in sequences. +shouldBeTrue("new File({length: 0}, 'world.txt') instanceof window.File"); +shouldBe("new File({length: 0}, 'world.txt').size", "0"); +shouldBe("new File({length: 1, 0: 'string'}, 'world.txt').size", "6"); +shouldBe("new File({length: 2, 0: new Uint8Array(100), 1: new Int16Array(100)}, 'world.txt').size", "300"); +shouldBe("new File({length: 1, 0: 'string'}, 'world.txt', {type: 'text/html'}).type", "'text/html'"); +shouldThrow("new File({length: 0}, 'world.txt', {endings:'illegal'})", "'TypeError: Failed to construct \\'File\\': 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 File(throwingSequence, 'world.txt')", "'Error: Misbehaving property'"); +</script> diff --git a/third_party/WebKit/LayoutTests/fast/files/resources/blob-slice-common.js b/third_party/WebKit/LayoutTests/fast/files/resources/blob-slice-common.js new file mode 100644 index 0000000..ba7a251 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/files/resources/blob-slice-common.js @@ -0,0 +1,49 @@ +var blob, file; // Populated by runTests() in individual tests. +var sliceParams = []; // Populated by individual tests. +var testIndex = 0; + +function testSlicing(start, end, expectedResult, blob, doneCallback) +{ + var blobClass = blob.constructor.name; + var sliced; + var reader = new FileReader(); + var message = ".slice"; + if (start === null && end === null) { + message += "()"; + sliced = blob.slice(); + } else if (end == undefined) { + message += "(" + start + ")"; + sliced = blob.slice(start); + } else { + message += "(" + start + ", " + end + ")"; + sliced = blob.slice(start, end); + } + reader.onloadend = function(event) { + var error = event.target.error; + if (error) { + testFailed("File read error " + message + error); + doneCallback(); + return; + } + var blobContentsVar = blobClass.toLowerCase() + "Contents"; + window[blobContentsVar] = event.target.result; + shouldBeEqualToString(blobContentsVar, expectedResult); + doneCallback(); + }; + debug(blobClass + " " + message); + reader.readAsText(sliced); +} + +function runNextTest() +{ + if (testIndex >= sliceTestCases.length) { + finishJSTest(); + return; + } + + var testCase = sliceTestCases[testIndex]; + testIndex++; + testSlicing(testCase[0], testCase[1], testCase[2], blob, function() { + testSlicing(testCase[0], testCase[1], testCase[2], file, runNextTest); + }); +} diff --git a/third_party/WebKit/LayoutTests/fast/files/script-tests/blob-constructor.js b/third_party/WebKit/LayoutTests/fast/files/script-tests/blob-constructor.js deleted file mode 100644 index 77ad34a..0000000 --- a/third_party/WebKit/LayoutTests/fast/files/script-tests/blob-constructor.js +++ /dev/null @@ -1,114 +0,0 @@ -description("Test the Blob constructor."); - -// Test the diffrent 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 2nd argument\\'s \"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 2nd argument\\'s \"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 2nd argument\\'s \"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'"); - -// Odds and ends -shouldBe("window.Blob.length", "2"); - -// 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 2nd argument\\'s \"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'"); |
