summaryrefslogtreecommitdiffstats
path: root/test/wpt/tests/FileAPI/blob/Blob-constructor-dom.window.js
blob: 4fd4a43ec4bea7ad12ce6a0c95b7ea52f56637f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// META: title=Blob constructor
// META: script=../support/Blob.js
'use strict';

var test_error = {
  name: "test",
  message: "test error",
};

test(function() {
  var args = [
    document.createElement("div"),
    window,
  ];
  args.forEach(function(arg) {
    assert_throws_js(TypeError, function() {
      new Blob(arg);
    }, "Should throw for argument " + format_value(arg) + ".");
  });
}, "Passing platform objects for blobParts should throw a TypeError.");

test(function() {
  var element = document.createElement("div");
  element.appendChild(document.createElement("div"));
  element.appendChild(document.createElement("p"));
  var list = element.children;
  Object.defineProperty(list, "length", {
    get: function() { throw test_error; }
  });
  assert_throws_exactly(test_error, function() {
    new Blob(list);
  });
}, "A platform object that supports indexed properties should be treated as a sequence for the blobParts argument (overwritten 'length'.)");

test_blob(function() {
  var select = document.createElement("select");
  select.appendChild(document.createElement("option"));
  return new Blob(select);
}, {
  expected: "[object HTMLOptionElement]",
  type: "",
  desc: "Passing an platform object that supports indexed properties as the blobParts array should work (select)."
});

test_blob(function() {
  var elm = document.createElement("div");
  elm.setAttribute("foo", "bar");
  return new Blob(elm.attributes);
}, {
  expected: "[object Attr]",
  type: "",
  desc: "Passing an platform object that supports indexed properties as the blobParts array should work (attributes)."
});