summaryrefslogtreecommitdiffstats
path: root/dom/manifest/test/test_ImageObjectProcessor_type.html
blob: 29627c5e46bc5087bbe4bbe1f6f5a4d7e4a1138f (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1079453
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1079453</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <script src="common.js"></script>
  <script>
/**
 * Image object's type property
 * https://w3c.github.io/manifest/#type-member
 **/

"use strict";
var testIcon = {
  icons: [{
    src: "test",
    type: undefined,
  }],
};

var invalidMimeTypes = [
  "application / text",
  "test;test",
  ";test?test",
  "application\\text",
  "image/jpeg, image/gif",
];
invalidMimeTypes.forEach((invalidMime) => {
  var expected = `Expect invalid mime to be treated like undefined.`;
  testIcon.icons[0].type = invalidMime;
  data.jsonText = JSON.stringify(testIcon);
  var result = processor.process(data);
  is(result.icons[0].type, undefined, expected);
});

var validTypes = [
  "image/jpeg",
  "IMAGE/jPeG",
  `${whiteSpace}image/jpeg${whiteSpace}`,
  "image/JPEG; whatever=something",
  "image/JPEG;whatever",
];

validTypes.forEach((validMime) => {
  var expected = `Expect valid mime to be parsed to : image/jpeg.`;
  testIcon.icons[0].type = validMime;
  data.jsonText = JSON.stringify(testIcon);
  var result = processor.process(data);
  is(result.icons[0].type, "image/jpeg", expected);
});
  </script>
</head>