js/xpconnect/tests/unit/component-blob.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     5 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
     7 const Cc = Components.classes;
     8 const Ci = Components.interfaces;
     9 const Cu = Components.utils;
    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 }
    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"});
    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");
    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");
    39     do_check_true(f1.type == "text/xml", "Wrong type");
    40     do_check_true(f2.type == "text/xml", "Wrong type");
    42     do_check_true(f1.size == testContent.length, "Wrong content size");
    43     do_check_true(f2.size == testContent.length, "Wrong content size");
    45     var f3 = new Blob();
    46     do_check_true(f3.size == 0, "Wrong size");
    47     do_check_true(f3.type == "", "Wrong type");
    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");
    58     return true;
    59   },
    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",
    66   // nsIClassInfo
    67   implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT,
    68   flags: 0,
    70   getInterfaces: function getInterfaces(aCount) {
    71     var interfaces = [Components.interfaces.nsIClassInfo];
    72     aCount.value = interfaces.length;
    73     return interfaces;
    74   },
    76   getHelperForLanguage: function getHelperForLanguage(aLanguage) {
    77     return null;
    78   },
    80   // nsISupports
    81   QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIClassInfo])
    82 };
    84 var gComponentsArray = [BlobComponent];
    85 this.NSGetFactory = XPCOMUtils.generateNSGetFactory(gComponentsArray);

mercurial