summaryrefslogtreecommitdiff
path: root/dom/manifest/test/test_ImageObjectProcessor_src.html
blob: cb77af0bddc0333c05d1a9e9eba34a9f5851eaf7 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1079453
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1079453</title>
  <script type="application/javascript" 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 src member
 * https://w3c.github.io/manifest/#src-member
 **/
'use strict';
var noSrc = {
  icons: [{}, {
    src: []
  }, {
    src: {}
  }, {
    src: null
  }, {
    type: 'image/jpg'
  }, {
    sizes: '1x1,2x2'
  }, {
    sizes: 'any',
    type: 'image/jpg'
  }]
};

var expected = `Expect icons without a src prop to be filtered out.`;
data.jsonText = JSON.stringify(noSrc);
var result = processor.process(data);
is(result.icons.length, 0, expected);

var invalidSrc = {
  icons: [{
    src: null
  }, {
    src: 1
  }, {
    src: []
  }, {
    src: {}
  }, {
    src: true
  }, {
    src: ''
  }]
};

var expected = `Expect icons with invalid src prop to be filtered out.`;
data.jsonText = JSON.stringify(noSrc);
var result = processor.process(data);
is(result.icons.length, 0, expected);

var expected = `Expect icon's src to be a string.`;
var withSrc = {
  icons: [{
    src: 'pass'
  }]
};
data.jsonText = JSON.stringify(withSrc);
var result = processor.process(data);
is(typeof result.icons[0].src, "string", expected);

var expected = `Expect only icons with a src prop to be kept.`;
var withSrc = {
  icons: [{
    src: 'pass'
  }, {
    src: 'pass',
  }, {}, {
    foo: 'foo'
  }]
};
data.jsonText = JSON.stringify(withSrc);
var result = processor.process(data);
is(result.icons.length, 2, expected);

var expectedURL = new URL('pass', manifestURL);
for (var icon of result.icons) {
  var expected = `Expect src prop to be ${expectedURL.toString()}`;
  is(icon.src.toString(), expectedURL.toString(), expected);
}

//Resolve URLs relative to manfiest
var URLs = ['path', '/path', '../../path'];

URLs.forEach((url) => {
  var expected = `Resolve icon src URLs relative to manifest.`;
  data.jsonText = JSON.stringify({
    icons: [{
      src: url
    }]
  });
  var absURL = new URL(url, manifestURL).toString();
  var result = processor.process(data);
  is(result.icons[0].src.toString(), absURL, expected);
});
  </script>
</head>