| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>Test resizing an OffscreenCanvas with a 2d context</title> | 2 <title>Test resizing an OffscreenCanvas with a 2d context</title> |
| 3 <script src="../../resources/testharness.js"></script> | 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> | 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 | 5 |
| 6 <script> | 6 <script> |
| 7 test(function() { | 7 test(function() { |
| 8 var canvas = new OffscreenCanvas(10, 20); | 8 var canvas = new OffscreenCanvas(10, 20); |
| 9 canvas.width = 30; | 9 canvas.width = 30; |
| 10 canvas.height = 40; | 10 canvas.height = 40; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // Verify that the placeholder was not updated synchronously. | 152 // Verify that the placeholder was not updated synchronously. |
| 153 assert_equals(image.width, 10); | 153 assert_equals(image.width, 10); |
| 154 assert_equals(image.height, 20); | 154 assert_equals(image.height, 20); |
| 155 }); | 155 }); |
| 156 asyncStepsCompleted = asyncStepsCompleted + 1; | 156 asyncStepsCompleted = asyncStepsCompleted + 1; |
| 157 if (asyncStepsCompleted == 2) { | 157 if (asyncStepsCompleted == 2) { |
| 158 t.done(); | 158 t.done(); |
| 159 } | 159 } |
| 160 }); | 160 }); |
| 161 // Set timeout acts as a sync barrier to allow commit to propagate | 161 // Set timeout acts as a sync barrier to allow commit to propagate |
| 162 // TODO(junov): Use the Promise returned by commit to schedule after the |
| 163 // commit. (crbug.com/709484) |
| 162 setTimeout(function(){ | 164 setTimeout(function(){ |
| 163 t.step(function() { | 165 setTimeout(function(){ |
| 164 // Verify that commit() asynchronously updates the size of its placeholder
canvas. | |
| 165 assert_equals(placeholder.width, 10); | |
| 166 assert_equals(placeholder.height, 20); | |
| 167 }); | |
| 168 t.step(function() { | |
| 169 // Verify that width/height attributes are still settable even though they
have no effect. | |
| 170 placeholder.width = 50; | |
| 171 placeholder.height = 60; | |
| 172 assert_equals(placeholder.width, 50); | |
| 173 assert_equals(placeholder.height, 60); | |
| 174 }); | |
| 175 createImageBitmap(placeholder).then(image => { | |
| 176 t.step(function() { | 166 t.step(function() { |
| 177 // Verify that an image grabbed from the placeholder has the correct dim
ensions | 167 // Verify that commit() asynchronously updates the size of its placehold
er canvas. |
| 178 assert_equals(image.width, 30); | 168 assert_equals(placeholder.width, 10); |
| 179 assert_equals(image.height, 40); | 169 assert_equals(placeholder.height, 20); |
| 180 }); | 170 }); |
| 181 asyncStepsCompleted = asyncStepsCompleted + 1; | 171 t.step(function() { |
| 182 if (asyncStepsCompleted == 2) { | 172 // Verify that width/height attributes are still settable even though th
ey have no effect. |
| 183 t.done(); | 173 placeholder.width = 50; |
| 184 } | 174 placeholder.height = 60; |
| 185 }); | 175 assert_equals(placeholder.width, 50); |
| 186 }, 1); | 176 assert_equals(placeholder.height, 60); |
| 177 }); |
| 178 createImageBitmap(placeholder).then(image => { |
| 179 t.step(function() { |
| 180 // Verify that an image grabbed from the placeholder has the correct d
imensions |
| 181 assert_equals(image.width, 30); |
| 182 assert_equals(image.height, 40); |
| 183 }); |
| 184 asyncStepsCompleted = asyncStepsCompleted + 1; |
| 185 if (asyncStepsCompleted == 2) { |
| 186 t.done(); |
| 187 } |
| 188 }); |
| 189 }, 0); |
| 190 }, 0); |
| 187 }, "Verify that resizing an OffscreenCanvas with a webgl context propagates the
new size to its placeholder canvas asynchronously, upon commit."); | 191 }, "Verify that resizing an OffscreenCanvas with a webgl context propagates the
new size to its placeholder canvas asynchronously, upon commit."); |
| 188 | 192 |
| 189 async_test(function(t){ | 193 async_test(function(t){ |
| 190 var placeholder = document.createElement('canvas'); | 194 var placeholder = document.createElement('canvas'); |
| 191 placeholder.width = 1; | 195 placeholder.width = 1; |
| 192 placeholder.height = 1; | 196 placeholder.height = 1; |
| 193 var offscreen = placeholder.transferControlToOffscreen(); | 197 var offscreen = placeholder.transferControlToOffscreen(); |
| 194 var ctx = offscreen.getContext('2d'); | 198 var ctx = offscreen.getContext('2d'); |
| 195 offscreen.width = offscreen.height = 10; | 199 offscreen.width = offscreen.height = 10; |
| 196 ctx.fillStyle = '#0f0'; | 200 ctx.fillStyle = '#0f0'; |
| 197 ctx.fillRect(0, 0, 10, 10); | 201 ctx.fillRect(0, 0, 10, 10); |
| 198 ctx.commit(); | 202 ctx.commit(); |
| 199 // Set timeout acts as a sync barrier to allow commit to propagate | 203 // Set timeout acts as a sync barrier to allow commit to propagate |
| 200 setTimeout(function(){ | 204 // TODO(junov): Use the Promise returned by commit to schedule after the |
| 201 var testCanvas = document.createElement('canvas'); | 205 // commit. (crbug.com/709484) |
| 202 testCanvas.width = testCanvas.height = 20; | 206 setTimeout(function() { |
| 203 testCtx = testCanvas.getContext('2d'); | 207 setTimeout(function() { |
| 204 testCtx.drawImage(placeholder, 0, 0); | 208 var testCanvas = document.createElement('canvas'); |
| 205 var pixel1 = testCtx.getImageData(9, 9, 1, 1).data; | 209 testCanvas.width = testCanvas.height = 20; |
| 206 var pixel2 = testCtx.getImageData(9, 10, 1, 1).data; | 210 testCtx = testCanvas.getContext('2d'); |
| 207 var pixel3 = testCtx.getImageData(10, 9, 1, 1).data; | 211 testCtx.drawImage(placeholder, 0, 0); |
| 208 t.step(function() { | 212 var pixel1 = testCtx.getImageData(9, 9, 1, 1).data; |
| 209 assert_equals(placeholder.width, 1); | 213 var pixel2 = testCtx.getImageData(9, 10, 1, 1).data; |
| 210 assert_equals(placeholder.height, 1); | 214 var pixel3 = testCtx.getImageData(10, 9, 1, 1).data; |
| 211 assert_array_equals(pixel1, [0, 255, 0, 255]); | 215 t.step(function() { |
| 212 assert_array_equals(pixel2, [0, 0, 0, 0]); | 216 assert_equals(placeholder.width, 1); |
| 213 assert_array_equals(pixel3, [0, 0, 0, 0]); | 217 assert_equals(placeholder.height, 1); |
| 214 }); | 218 assert_array_equals(pixel1, [0, 255, 0, 255]); |
| 215 t.done(); | 219 assert_array_equals(pixel2, [0, 0, 0, 0]); |
| 216 }, 1); | 220 assert_array_equals(pixel3, [0, 0, 0, 0]); |
| 221 }); |
| 222 t.done(); |
| 223 }, 0); |
| 224 }, 0); |
| 217 | 225 |
| 218 }, "Verify that drawImage uses the size of the committed frame as the intinsic s
ize of a placeholder canvas."); | 226 }, "Verify that drawImage uses the size of the committed frame as the intinsic s
ize of a placeholder canvas."); |
| 219 </script> | 227 </script> |
| OLD | NEW |