summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/test_invalid_mime_type_blob.html
blob: 45d360634792699cb88bd702f5bad79b59b9f80f (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE HTML>
<title>createImageBitmap from Blob with invalid type</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<body>
<script>

function syncBlob() {
  info("Let's create a small memory blob...");

  // A 1x1 PNG image.
  // Source: https://commons.wikimedia.org/wiki/File:1x1.png (Public Domain)
  const IMAGE = atob("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAA" +
                     "ACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=");

  let bytes = new Array(IMAGE.length);
  for (let i = 0; i < IMAGE.length; i++) {
    bytes[i] = IMAGE.charCodeAt(i);
  }

  let blob = new Blob([new Uint8Array(bytes)], { type: "text/html"});
  window.createImageBitmap(blob)
  .then(imageBitmap => {
    ok(true, "Image created!");
    is(imageBitmap.width, 1, "Image is 1x1");
    is(imageBitmap.height, 1, "Image is 1x1");
  })
  .then(next);
}

function asyncBlob() {
  info("Let's create a big memory blob...");

  // A 1x1 PNG image.
  // Source: https://commons.wikimedia.org/wiki/File:1x1.png (Public Domain)
  const IMAGE = atob("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAA" +
                     "ACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=");

  let bytes = new Array(IMAGE.length);
  for (let i = 0; i < IMAGE.length; i++) {
    bytes[i] = IMAGE.charCodeAt(i);
  }

  let blob = new Blob([new Uint8Array(bytes)], { type: "text/html"});
  while (blob.size <= 1024*1024) {
    blob = new Blob([blob, blob], { type: "text/html"});
  }

  ok(blob.size > 1024 * 1024, "More than 1mb");

  let bc = new BroadcastChannel('a');
  bc.onmessage = e => {
    window.createImageBitmap(e.data)
    .then(imageBitmap => {
      ok(true, "Image created!");
      is(imageBitmap.width, 1, "Image is 1x1");
      is(imageBitmap.height, 1, "Image is 1x1");
    })
    .then(next);
  }

  new BroadcastChannel('a').postMessage(blob);
}

let tests = [
 syncBlob,
 asyncBlob,
];

function next() {
  if (!tests.length) {
    SimpleTest.finish();
    return;
  }

  let test = tests.shift();
  test();
}

SimpleTest.requestLongerTimeout(3); // slow on Android
SimpleTest.waitForExplicitFinish();
next();
</script>
</body>
</html>