|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 const Ci = Components.interfaces; |
|
6 |
|
7 function run_test() { |
|
8 // throw if anything goes wrong |
|
9 let testContent = "<a id=\"a\"><b id=\"b\">hey!<\/b><\/a>"; |
|
10 // should be able to construct a file |
|
11 var f1 = Blob([testContent], {"type" : "text/xml"}); |
|
12 // with either constructor syntax |
|
13 var f2 = new Blob([testContent], {"type" : "text/xml"}); |
|
14 |
|
15 // do some tests |
|
16 do_check_true(f1 instanceof Ci.nsIDOMBlob, "Should be a DOM Blob"); |
|
17 do_check_true(f2 instanceof Ci.nsIDOMBlob, "Should be a DOM Blob"); |
|
18 |
|
19 do_check_true(!(f1 instanceof Ci.nsIDOMFile), "Should not be a DOM File"); |
|
20 do_check_true(!(f2 instanceof Ci.nsIDOMFile), "Should not be a DOM File"); |
|
21 |
|
22 do_check_true(f1.type == "text/xml", "Wrong type"); |
|
23 do_check_true(f2.type == "text/xml", "Wrong type"); |
|
24 |
|
25 do_check_true(f1.size == testContent.length, "Wrong content size"); |
|
26 do_check_true(f2.size == testContent.length, "Wrong content size"); |
|
27 |
|
28 var f3 = new Blob(); |
|
29 do_check_true(f3.size == 0, "Wrong size"); |
|
30 do_check_true(f3.type == "", "Wrong type"); |
|
31 |
|
32 var threw = false; |
|
33 try { |
|
34 // Needs a valid ctor argument |
|
35 var f3 = Blob(Date(132131532)); |
|
36 } catch (e) { |
|
37 threw = true; |
|
38 } |
|
39 do_check_true(threw, "Passing a random object should fail"); |
|
40 } |