|
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 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
6 |
|
7 const Cc = Components.classes; |
|
8 const Ci = Components.interfaces; |
|
9 const Cu = Components.utils; |
|
10 |
|
11 function do_check_true(cond, text) { |
|
12 // we don't have the test harness' utilities in this scope, so we need this |
|
13 // little helper. In the failure case, the exception is propagated to the |
|
14 // caller in the main run_test() function, and the test fails. |
|
15 if (!cond) |
|
16 throw "Failed check: " + text; |
|
17 } |
|
18 |
|
19 function BlobComponent() { |
|
20 this.wrappedJSObject = this; |
|
21 } |
|
22 BlobComponent.prototype = |
|
23 { |
|
24 doTest: function() { |
|
25 // throw if anything goes wrong |
|
26 let testContent = "<a id=\"a\"><b id=\"b\">hey!<\/b><\/a>"; |
|
27 // should be able to construct a file |
|
28 var f1 = Blob([testContent], {"type" : "text/xml"}); |
|
29 // with either constructor syntax |
|
30 var f2 = new Blob([testContent], {"type" : "text/xml"}); |
|
31 |
|
32 // do some tests |
|
33 do_check_true(f1 instanceof Ci.nsIDOMBlob, "Should be a DOM Blob"); |
|
34 do_check_true(f2 instanceof Ci.nsIDOMBlob, "Should be a DOM Blob"); |
|
35 |
|
36 do_check_true(!(f1 instanceof Ci.nsIDOMFile), "Should not be a DOM File"); |
|
37 do_check_true(!(f2 instanceof Ci.nsIDOMFile), "Should not be a DOM File"); |
|
38 |
|
39 do_check_true(f1.type == "text/xml", "Wrong type"); |
|
40 do_check_true(f2.type == "text/xml", "Wrong type"); |
|
41 |
|
42 do_check_true(f1.size == testContent.length, "Wrong content size"); |
|
43 do_check_true(f2.size == testContent.length, "Wrong content size"); |
|
44 |
|
45 var f3 = new Blob(); |
|
46 do_check_true(f3.size == 0, "Wrong size"); |
|
47 do_check_true(f3.type == "", "Wrong type"); |
|
48 |
|
49 var threw = false; |
|
50 try { |
|
51 // Needs a valid ctor argument |
|
52 var f3 = Blob(Date(132131532)); |
|
53 } catch (e) { |
|
54 threw = true; |
|
55 } |
|
56 do_check_true(threw, "Passing a random object should fail"); |
|
57 |
|
58 return true; |
|
59 }, |
|
60 |
|
61 // nsIClassInfo + information for XPCOM registration code in XPCOMUtils.jsm |
|
62 classDescription: "Blob in components scope code", |
|
63 classID: Components.ID("{06215993-a3c2-41e3-bdfd-0a3a2cc0b65c}"), |
|
64 contractID: "@mozilla.org/tests/component-blob;1", |
|
65 |
|
66 // nsIClassInfo |
|
67 implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT, |
|
68 flags: 0, |
|
69 |
|
70 getInterfaces: function getInterfaces(aCount) { |
|
71 var interfaces = [Components.interfaces.nsIClassInfo]; |
|
72 aCount.value = interfaces.length; |
|
73 return interfaces; |
|
74 }, |
|
75 |
|
76 getHelperForLanguage: function getHelperForLanguage(aLanguage) { |
|
77 return null; |
|
78 }, |
|
79 |
|
80 // nsISupports |
|
81 QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIClassInfo]) |
|
82 }; |
|
83 |
|
84 var gComponentsArray = [BlobComponent]; |
|
85 this.NSGetFactory = XPCOMUtils.generateNSGetFactory(gComponentsArray); |