Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <title>Test resizing an OffscreenCanvas with a 2d context</title> | |
| 3 <script src="../../resources/testharness.js"></script> | |
| 4 <script src="../../resources/testharnessreport.js"></script> | |
| 5 | |
| 6 <script> | |
| 7 test(function() { | |
| 8 var canvas = new OffscreenCanvas(10, 20); | |
| 9 canvas.width = 30; | |
| 10 canvas.height = 40; | |
|
xidachen
2016/11/17 02:12:22
I am guessing that when you make the pull request
| |
| 11 assert_equals(canvas.width, 30); | |
| 12 assert_equals(canvas.height, 40); | |
| 13 }, "Verify that writing to the width and height attributes of an OffscreenCanvas works when there is no context attached."); | |
| 14 | |
| 15 test(function() { | |
| 16 var canvas = new OffscreenCanvas(10, 20); | |
| 17 canvas.getContext('2d'); | |
| 18 canvas.width = 30; | |
| 19 canvas.height = 40; | |
| 20 assert_equals(canvas.width, 30); | |
| 21 assert_equals(canvas.height, 40); | |
| 22 var image = canvas.transferToImageBitmap(); | |
| 23 assert_equals(image.width, 30); | |
| 24 assert_equals(image.height, 40); | |
| 25 }, "Verify that writing to the width and height attributes of an OffscreenCanvas works when there is a 2d context attached."); | |
| 26 | |
| 27 test(function() { | |
| 28 var canvas = new OffscreenCanvas(10, 20); | |
| 29 canvas.getContext('webgl'); | |
| 30 canvas.width = 30; | |
| 31 canvas.height = 40; | |
| 32 assert_equals(canvas.width, 30); | |
| 33 assert_equals(canvas.height, 40); | |
| 34 var image = canvas.transferToImageBitmap(); | |
| 35 assert_equals(image.width, 30); | |
| 36 assert_equals(image.height, 40); | |
| 37 }, "Verify that writing to the width and height attributes of an OffscreenCanvas works when there is a webgl context attached."); | |
| 38 | |
| 39 test(function() { | |
| 40 var canvas = new OffscreenCanvas(10, 20); | |
| 41 var ctx = canvas.getContext('2d'); | |
| 42 ctx.lineWidth = 5; | |
| 43 canvas.width = 30; | |
| 44 assert_equals(ctx.lineWidth, 1); | |
| 45 ctx.lineWidth = 5; | |
| 46 canvas.height = 40; | |
| 47 assert_equals(ctx.lineWidth, 1); | |
| 48 | |
| 49 }, "Verify that resizing a 2d context resets its state."); | |
| 50 | |
| 51 test(function() { | |
| 52 var canvas = new OffscreenCanvas(10, 20); | |
| 53 var ctx = canvas.getContext('2d'); | |
| 54 ctx.lineWidth = 5; | |
| 55 canvas.width = canvas.width; | |
| 56 assert_equals(ctx.lineWidth, 1); | |
| 57 ctx.lineWidth = 5; | |
| 58 canvas.height = canvas.height; | |
| 59 assert_equals(ctx.lineWidth, 1); | |
| 60 }, "Verify that setting the size of a 2d context to the same size it already had resets its state."); | |
| 61 | |
| 62 async_test(function(t) { | |
| 63 var placeholder = document.createElement('canvas'); | |
| 64 placeholder.width = 10; | |
| 65 placeholder.height = 20; | |
| 66 var offscreen = placeholder.transferControlToOffscreen(); | |
| 67 var ctx = offscreen.getContext('2d'); | |
| 68 t.step(function() { | |
| 69 // Verify that setting the size of an OffscreenCanvas that has a placeholder works. | |
| 70 offscreen.width = 30; | |
| 71 offscreen.height = 40; | |
| 72 assert_equals(offscreen.width, 30); | |
| 73 assert_equals(offscreen.height, 40); | |
| 74 var image = offscreen.transferToImageBitmap(); | |
| 75 assert_equals(image.width, 30); | |
| 76 assert_equals(image.height, 40); | |
| 77 }); | |
| 78 t.step(function() { | |
| 79 // Verify that setting the size of an OffscreenCanvas does not directly upda te the size of its placeholder canvas. | |
| 80 assert_equals(placeholder.width, 10); | |
| 81 assert_equals(placeholder.height, 20); | |
| 82 }); | |
| 83 ctx.commit(); | |
| 84 t.step(function() { | |
| 85 // Verify that commit() does not synchronously update the size of its placeh older canvas. | |
| 86 assert_equals(placeholder.width, 10); | |
| 87 assert_equals(placeholder.height, 20); | |
| 88 }); | |
| 89 // Set timeout acts as a sync barrier to allow commit to propagate | |
| 90 setTimeout(function(){ | |
| 91 t.step(function() { | |
| 92 // Verify that commit() asynchronously updates the size of its placeholder canvas. | |
| 93 assert_equals(placeholder.width, 30); | |
| 94 assert_equals(placeholder.height, 40); | |
| 95 }); | |
| 96 createImageBitmap(placeholder).then(image => { | |
| 97 t.step(function() { | |
| 98 // Verify that an image grabbed from the placeholder has the correct dim ensions | |
| 99 assert_equals(image.width, 30); | |
| 100 assert_equals(image.height, 40); | |
| 101 }); | |
| 102 t.done(); | |
| 103 }); | |
| 104 }, 0); | |
| 105 }, "Verify that resizing an OffscreenCanvas with a 2d context propagates the new size to its placeholder canvas asynchronously, upon commit."); | |
| 106 | |
| 107 async_test(function(t) { | |
| 108 var placeholder = document.createElement('canvas'); | |
| 109 placeholder.width = 10; | |
| 110 placeholder.height = 20; | |
| 111 var offscreen = placeholder.transferControlToOffscreen(); | |
| 112 var ctx = offscreen.getContext('webgl'); | |
| 113 t.step(function() { | |
| 114 // Verify that setting the size of an OffscreenCanvas that has a placeholder works. | |
| 115 offscreen.width = 30; | |
| 116 offscreen.height = 40; | |
| 117 assert_equals(offscreen.width, 30); | |
| 118 assert_equals(offscreen.height, 40); | |
| 119 var image = offscreen.transferToImageBitmap(); | |
| 120 assert_equals(image.width, 30); | |
| 121 assert_equals(image.height, 40); | |
| 122 }); | |
| 123 t.step(function() { | |
| 124 // Verify that setting the size of an OffscreenCanvas does not directly upda te the size of its placeholder canvas. | |
| 125 assert_equals(placeholder.width, 10); | |
| 126 assert_equals(placeholder.height, 20); | |
| 127 }); | |
| 128 ctx.commit(); | |
| 129 t.step(function() { | |
| 130 // Verify that commit() does not synchronously update the size of its placeh older canvas. | |
| 131 assert_equals(placeholder.width, 10); | |
| 132 assert_equals(placeholder.height, 20); | |
| 133 }); | |
| 134 // Set timeout acts as a sync barrier to allow commit to propagate | |
| 135 setTimeout(function(){ | |
| 136 t.step(function() { | |
| 137 // Verify that commit() asynchronously updates the size of its placeholder canvas. | |
| 138 assert_equals(placeholder.width, 30); | |
| 139 assert_equals(placeholder.height, 40); | |
| 140 }); | |
| 141 createImageBitmap(placeholder).then(image => { | |
| 142 t.step(function() { | |
| 143 // Verify that an image grabbed from the placeholder has the correct dim ensions | |
| 144 assert_equals(image.width, 30); | |
| 145 assert_equals(image.height, 40); | |
| 146 }); | |
| 147 t.done(); | |
| 148 }); | |
| 149 }, 0); | |
| 150 }, "Verify that resizing an OffscreenCanvas with a webgl context propagates the new size to its placeholder canvas asynchronously, upon commit."); | |
| 151 | |
| 152 </script> | |
| OLD | NEW |