js/xpconnect/tests/unit/test_blob2.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/tests/unit/test_blob2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,40 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +const Ci = Components.interfaces;
     1.9 +
    1.10 +function run_test() {
    1.11 +  // throw if anything goes wrong
    1.12 +  let testContent = "<a id=\"a\"><b id=\"b\">hey!<\/b><\/a>";
    1.13 +  // should be able to construct a file
    1.14 +  var f1 = Blob([testContent], {"type" : "text/xml"});
    1.15 +  // with either constructor syntax
    1.16 +  var f2 = new Blob([testContent], {"type" : "text/xml"});
    1.17 +
    1.18 +  // do some tests
    1.19 +  do_check_true(f1 instanceof Ci.nsIDOMBlob, "Should be a DOM Blob");
    1.20 +  do_check_true(f2 instanceof Ci.nsIDOMBlob, "Should be a DOM Blob");
    1.21 +
    1.22 +  do_check_true(!(f1 instanceof Ci.nsIDOMFile), "Should not be a DOM File");
    1.23 +  do_check_true(!(f2 instanceof Ci.nsIDOMFile), "Should not be a DOM File");
    1.24 +
    1.25 +  do_check_true(f1.type == "text/xml", "Wrong type");
    1.26 +  do_check_true(f2.type == "text/xml", "Wrong type");
    1.27 +
    1.28 +  do_check_true(f1.size == testContent.length, "Wrong content size");
    1.29 +  do_check_true(f2.size == testContent.length, "Wrong content size");
    1.30 +
    1.31 +  var f3 = new Blob();
    1.32 +  do_check_true(f3.size == 0, "Wrong size");
    1.33 +  do_check_true(f3.type == "", "Wrong type");
    1.34 +
    1.35 +  var threw = false;
    1.36 +  try {
    1.37 +    // Needs a valid ctor argument
    1.38 +    var f3 = Blob(Date(132131532));
    1.39 +  } catch (e) {
    1.40 +    threw = true;
    1.41 +  }
    1.42 +  do_check_true(threw, "Passing a random object should fail");
    1.43 +}

mercurial