Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / canvas / canvas-createImageBitmap-invalid-args.html
blob57d20eae43dbb2e808532cc5b9a6498c13a845e9
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <script>
8 description("Ensure correct behavior of createImageBitmap for invalid inputs.");
9 window.jsTestIsAsync = true;
11 var reason;
13 function shouldBeRejected(promise, message) {
14 return promise.then(function() {
15 testFailed('Resolved unexpectedly: ' + message);
16 }, function(e) {
17 reason = e;
18 testPassed('Rejected as expected: ' + message);
19 shouldBeTrue('reason instanceof Error');
20 debug(e);
21 });
24 function checkInvalidRange(source, message) {
25 return Promise.resolve().then(function() {
26 return shouldBeRejected(createImageBitmap(source, 0, 0, 10, 0), message + ' / invalid range');
27 }).then(function() {
28 return shouldBeRejected(createImageBitmap(source, 0, 0, 0, 10), message + ' / invalid range');
29 });
32 function createCanvas() {
33 return new Promise(function(resolve, reject) {
34 var canvas = document.createElement('canvas');
35 canvas.setAttribute('width', '200');
36 canvas.setAttribute('height', '200');
37 resolve(canvas);
38 });
41 function createInvalidCanvas() {
42 // Create a terapixel canvas to generate an invalid canvas through
43 // allocation failure
44 return new Promise(function(resolve, reject) {
45 var canvas = document.createElement('canvas');
46 canvas.setAttribute('width', '100000000');
47 canvas.setAttribute('height', '100000000');
48 resolve(canvas);
49 });
52 function createVideo() {
53 return new Promise(function(resolve, reject) {
54 var video = document.createElement('video');
55 video.addEventListener('canplaythrough', resolve.bind(undefined, video), false);
56 video.src = '../../compositing/resources/video.ogv';
57 });
60 function createImage() {
61 return createCanvas().then(function(canvas) {
62 var image = new Image();
63 var promise = new Promise(function(resolve, reject) {
64 image.onload = resolve.bind(undefined, image);
65 });
66 image.src = canvas.toDataURL();
67 return promise;
68 });
71 function createBlob(url) {
72 return new Promise(function(resolve, reject) {
73 var xhr = new XMLHttpRequest();
74 xhr.open('GET', url);
75 xhr.responseType = 'blob';
76 xhr.onload = function() {
77 resolve(xhr.response);
79 xhr.onerror = reject;
80 xhr.send();
81 });
84 Promise.resolve().then(function() {
85 return shouldBeRejected(createImageBitmap(undefined), 'undefined');
86 }).then(function() {
87 return shouldBeRejected(createImageBitmap(null), 'null');
88 }).then(function() {
89 return shouldBeRejected(createImageBitmap(new Image), 'empty image');
90 }).then(function() {
91 return shouldBeRejected(createImageBitmap(document.createElement('video')), 'empty video');
92 }).then(function() {
93 return createImage().then(function(image) {
94 return checkInvalidRange(image, 'image');
95 });
96 }).then(function() {
97 return createVideo().then(function(video) {
98 return checkInvalidRange(video, 'video');
99 });
100 }).then(function() {
101 return createCanvas().then(function(canvas) {
102 return checkInvalidRange(canvas, 'canvas');
104 }).then(function() {
105 return createCanvas().then(function(canvas) {
106 return checkInvalidRange(canvas.getContext('2d'), 'canvas context');
108 }).then(function() {
109 return createCanvas().then(function(canvas) {
110 var imagedata = canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height);
111 return checkInvalidRange(imagedata, 'canvas imagedata')
113 }).then(function() {
114 return createImage().then(function(image) {
115 return createImageBitmap(image);
116 }).then(function(bitmap) {
117 return checkInvalidRange(bitmap, 'image bitmap');
119 }).then(function() {
120 return createBlob('resources/pattern.png').then(function(blob) {
121 return checkInvalidRange(blob, 'blob');
123 }).then(function() {
124 return createBlob('resources/shadow-offset.js').then(function(blob) {
125 return shouldBeRejected(createImageBitmap(blob), 'invalid blob');
127 }).then(function() {
128 return createInvalidCanvas().then(function(invalidCanvas) {
129 return shouldBeRejected(createImageBitmap(invalidCanvas), 'invalid canvas');
131 }).catch(function(e) {
132 testFailed('Unexpected rejection: ' + e);
133 }).then(finishJSTest, finishJSTest);
135 </script>
136 </body>
137 </html>