summaryrefslogtreecommitdiffstats
path: root/dom/security/test/csp/file_blob_data_schemes.html
blob: 0a4a49160684fb91f0ca09836bb7d3955d50870f (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Bug 1086999 - Wildcard should not match blob:, data:</title>
</head>
<body>
<script type="text/javascript">

var base64data =
"iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12" +
"P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";


// construct an image element using *data:*
var data_src = "data:image/png;base64," + base64data;
var data_img = document.createElement('img');
data_img.onload = function() {
  window.parent.postMessage({scheme: "data", result: "allowed"}, "*");
}
data_img.onerror = function() {
  window.parent.postMessage({scheme: "data", result: "blocked"}, "*");
}
data_img.src = data_src;
document.body.appendChild(data_img);


// construct an image element using *blob:*
var byteCharacters = atob(base64data);
var byteNumbers = new Array(byteCharacters.length);
for (var i = 0; i < byteCharacters.length; i++) {
  byteNumbers[i] = byteCharacters.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
var blob = new Blob([byteArray], {type: "image/png"});
var imageUrl = URL.createObjectURL( blob );

var blob_img = document.createElement('img');
blob_img.onload = function() {
  window.parent.postMessage({scheme: "blob", result: "allowed"}, "*");
}
blob_img.onerror = function() {
  window.parent.postMessage({scheme: "blob", result: "blocked"}, "*");
}
blob_img.src = imageUrl;
document.body.appendChild(blob_img);

</script>
</body>
</html>