tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Blob-constructor-dom.window.js (1617B)


      1 // META: title=Blob constructor
      2 // META: script=../support/Blob.js
      3 'use strict';
      4 
      5 var test_error = {
      6  name: "test",
      7  message: "test error",
      8 };
      9 
     10 test(function() {
     11  var args = [
     12    document.createElement("div"),
     13    window,
     14  ];
     15  args.forEach(function(arg) {
     16    assert_throws_js(TypeError, function() {
     17      new Blob(arg);
     18    }, "Should throw for argument " + format_value(arg) + ".");
     19  });
     20 }, "Passing platform objects for blobParts should throw a TypeError.");
     21 
     22 test(function() {
     23  var element = document.createElement("div");
     24  element.appendChild(document.createElement("div"));
     25  element.appendChild(document.createElement("p"));
     26  var list = element.children;
     27  Object.defineProperty(list, "length", {
     28    get: function() { throw test_error; }
     29  });
     30  assert_throws_exactly(test_error, function() {
     31    new Blob(list);
     32  });
     33 }, "A platform object that supports indexed properties should be treated as a sequence for the blobParts argument (overwritten 'length'.)");
     34 
     35 test_blob(function() {
     36  var select = document.createElement("select");
     37  select.appendChild(document.createElement("option"));
     38  return new Blob(select);
     39 }, {
     40  expected: "[object HTMLOptionElement]",
     41  type: "",
     42  desc: "Passing an platform object that supports indexed properties as the blobParts array should work (select)."
     43 });
     44 
     45 test_blob(function() {
     46  var elm = document.createElement("div");
     47  elm.setAttribute("foo", "bar");
     48  return new Blob(elm.attributes);
     49 }, {
     50  expected: "[object Attr]",
     51  type: "",
     52  desc: "Passing an platform object that supports indexed properties as the blobParts array should work (attributes)."
     53 });