michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cu = Components.utils; michael@0: michael@0: function do_check_true(cond, text) { michael@0: // we don't have the test harness' utilities in this scope, so we need this michael@0: // little helper. In the failure case, the exception is propagated to the michael@0: // caller in the main run_test() function, and the test fails. michael@0: if (!cond) michael@0: throw "Failed check: " + text; michael@0: } michael@0: michael@0: function BlobComponent() { michael@0: this.wrappedJSObject = this; michael@0: } michael@0: BlobComponent.prototype = michael@0: { michael@0: doTest: function() { michael@0: // throw if anything goes wrong michael@0: let testContent = "hey!<\/b><\/a>"; michael@0: // should be able to construct a file michael@0: var f1 = Blob([testContent], {"type" : "text/xml"}); michael@0: // with either constructor syntax michael@0: var f2 = new Blob([testContent], {"type" : "text/xml"}); michael@0: michael@0: // do some tests michael@0: do_check_true(f1 instanceof Ci.nsIDOMBlob, "Should be a DOM Blob"); michael@0: do_check_true(f2 instanceof Ci.nsIDOMBlob, "Should be a DOM Blob"); michael@0: michael@0: do_check_true(!(f1 instanceof Ci.nsIDOMFile), "Should not be a DOM File"); michael@0: do_check_true(!(f2 instanceof Ci.nsIDOMFile), "Should not be a DOM File"); michael@0: michael@0: do_check_true(f1.type == "text/xml", "Wrong type"); michael@0: do_check_true(f2.type == "text/xml", "Wrong type"); michael@0: michael@0: do_check_true(f1.size == testContent.length, "Wrong content size"); michael@0: do_check_true(f2.size == testContent.length, "Wrong content size"); michael@0: michael@0: var f3 = new Blob(); michael@0: do_check_true(f3.size == 0, "Wrong size"); michael@0: do_check_true(f3.type == "", "Wrong type"); michael@0: michael@0: var threw = false; michael@0: try { michael@0: // Needs a valid ctor argument michael@0: var f3 = Blob(Date(132131532)); michael@0: } catch (e) { michael@0: threw = true; michael@0: } michael@0: do_check_true(threw, "Passing a random object should fail"); michael@0: michael@0: return true; michael@0: }, michael@0: michael@0: // nsIClassInfo + information for XPCOM registration code in XPCOMUtils.jsm michael@0: classDescription: "Blob in components scope code", michael@0: classID: Components.ID("{06215993-a3c2-41e3-bdfd-0a3a2cc0b65c}"), michael@0: contractID: "@mozilla.org/tests/component-blob;1", michael@0: michael@0: // nsIClassInfo michael@0: implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT, michael@0: flags: 0, michael@0: michael@0: getInterfaces: function getInterfaces(aCount) { michael@0: var interfaces = [Components.interfaces.nsIClassInfo]; michael@0: aCount.value = interfaces.length; michael@0: return interfaces; michael@0: }, michael@0: michael@0: getHelperForLanguage: function getHelperForLanguage(aLanguage) { michael@0: return null; michael@0: }, michael@0: michael@0: // nsISupports michael@0: QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIClassInfo]) michael@0: }; michael@0: michael@0: var gComponentsArray = [BlobComponent]; michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory(gComponentsArray);