blob: 0d53bd5f7f6a9b17eecafe0781c250d5d9ff6f3e [file] [log] [blame]
<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<script>
description("Test the File constructor.");
// Test valid file parts.
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 Blob([new File([new Blob], 'world.txt')])], 'world.html')) instanceof window.File");
// Test that the lastModified is correctly added to the File.
var aDate = new Date(441532800000);
shouldBe("(new File([], 'world.html', {lastModified: 441532800000})).lastModified", "441532800000");
// Unless specified, lastModified should default to now.
shouldBeNow("(new File([], 'world.html')).lastModified", 20000);
shouldBeNow("(new File([], 'world.html', {})).lastModified", 20000);
shouldBeNow("(new File([], 'world.html', {type: 'text/plain'})).lastModified", 20000);
// Test that Date instances are implicitly converted to numbers.
shouldBe("(new File([], 'world.html', {lastModified: new Date(441532800000)})).lastModified", "441532800000");
// Test the deprecated attribute lastModifiedDate.
shouldBeTrue("(new File([], 'world.html', {lastModified: 441532800000})).lastModifiedDate instanceof Date");
shouldBe("(new File([], 'world.html', {lastModified: 441532800000})).lastModifiedDate.valueOf()", "441532800000");
// 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");
</script>