2019-01-01 19:58:40 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-03-06 20:48:46 -05:00
|
|
|
import { test, assert, assertEquals } from "./test_util.ts";
|
2018-09-14 08:45:50 -04:00
|
|
|
|
2019-01-13 09:39:23 -05:00
|
|
|
test(function blobString() {
|
2018-09-14 08:45:50 -04:00
|
|
|
const b1 = new Blob(["Hello World"]);
|
|
|
|
const str = "Test";
|
|
|
|
const b2 = new Blob([b1, str]);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(b2.size, b1.size + str.length);
|
2018-09-14 08:45:50 -04:00
|
|
|
});
|
|
|
|
|
2019-01-13 09:39:23 -05:00
|
|
|
test(function blobBuffer() {
|
2018-09-14 08:45:50 -04:00
|
|
|
const buffer = new ArrayBuffer(12);
|
|
|
|
const u8 = new Uint8Array(buffer);
|
|
|
|
const f1 = new Float32Array(buffer);
|
|
|
|
const b1 = new Blob([buffer, u8]);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(b1.size, 2 * u8.length);
|
2018-09-14 08:45:50 -04:00
|
|
|
const b2 = new Blob([b1, f1]);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(b2.size, 3 * u8.length);
|
2018-09-14 08:45:50 -04:00
|
|
|
});
|
|
|
|
|
2019-01-13 09:39:23 -05:00
|
|
|
test(function blobSlice() {
|
2018-09-14 08:45:50 -04:00
|
|
|
const blob = new Blob(["Deno", "Foo"]);
|
|
|
|
const b1 = blob.slice(0, 3, "Text/HTML");
|
|
|
|
assert(b1 instanceof Blob);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(b1.size, 3);
|
|
|
|
assertEquals(b1.type, "text/html");
|
2018-09-14 08:45:50 -04:00
|
|
|
const b2 = blob.slice(-1, 3);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(b2.size, 0);
|
2018-09-14 08:45:50 -04:00
|
|
|
const b3 = blob.slice(100, 3);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(b3.size, 0);
|
2018-09-14 08:45:50 -04:00
|
|
|
const b4 = blob.slice(0, 10);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(b4.size, blob.size);
|
2018-09-14 08:45:50 -04:00
|
|
|
});
|
|
|
|
|
2019-04-18 21:56:33 -04:00
|
|
|
test(function blobShouldNotThrowError() {
|
|
|
|
let hasThrown = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const options1: object = {
|
|
|
|
ending: "utf8",
|
|
|
|
hasOwnProperty: "hasOwnProperty"
|
|
|
|
};
|
|
|
|
const options2: object = Object.create(null);
|
|
|
|
new Blob(["Hello World"], options1);
|
|
|
|
new Blob(["Hello World"], options2);
|
|
|
|
} catch {
|
|
|
|
hasThrown = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(hasThrown, false);
|
|
|
|
});
|
|
|
|
|
2018-09-14 08:45:50 -04:00
|
|
|
// TODO(qti3e) Test the stored data in a Blob after implementing FileReader API.
|