test_blob2.js (1040B)
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 Cu.importGlobalProperties(['Blob', 'File']); 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 = new Blob([testContent], {"type" : "text/xml"}); 12 13 // do some tests 14 Assert.ok(f1 instanceof Blob, "Should be a DOM Blob"); 15 16 Assert.ok(!(f1 instanceof File), "Should not be a DOM File"); 17 18 Assert.ok(f1.type == "text/xml", "Wrong type"); 19 20 Assert.ok(f1.size == testContent.length, "Wrong content size"); 21 22 var f2 = new Blob(); 23 Assert.ok(f2.size == 0, "Wrong size"); 24 Assert.ok(f2.type == "", "Wrong type"); 25 26 var threw = false; 27 try { 28 // Needs a valid ctor argument 29 var f2 = new Blob(Date(132131532)); 30 } catch (e) { 31 threw = true; 32 } 33 Assert.ok(threw, "Passing a random object should fail"); 34 }