Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/canvas/canvas-imageSmoothingQuality.html

Issue 2679083003: Use testharness.js instead of js-test.js in LayoutTests/fast/canvas tests. (Closed)
Patch Set: Adding virtual/gpu/fast/canvas/canvas-imageSmoothingQuality.html to TestExpectations Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html>
2 <html> 1 <html>
3 <body> 2 <body>
4 <script src="../../resources/js-test.js"></script> 3 <script src="../../resources/testharness.js"></script>
5 <canvas id="source"></canvas> 4 <script src="../../resources/testharnessreport.js"></script>
6 <canvas id="default"></canvas> 5 <canvas id="source"></canvas>
7 <script> 6 <canvas id="default"></canvas>
7 <script>
8 8
9 description("Tests for the imageSmoothingQuality attribute."); 9 var source = document.createElement('canvas');
10
11 var source = document.getElementById("source");
12 source.width = 60; 10 source.width = 60;
13 source.height = 12; 11 source.height = 12;
14 var sourceContext = source.getContext("2d"); 12 var sourceContext = source.getContext('2d');
15 var sourceImage = sourceContext.createImageData(source.width, source.height); 13 var sourceImage = sourceContext.createImageData(source.width, source.height);
16 14
17 function drawBlackDot(x, y) { 15 function drawBlackDot(x, y) {
18 var offset = y * 4 * source.width + x * 4; 16 var offset = y * 4 * source.width + x * 4;
19 sourceImage.data[offset + 0] = 0 ; // R 17 sourceImage.data[offset + 0] = 0 ; // R
20 sourceImage.data[offset + 1] = 0 ; // G 18 sourceImage.data[offset + 1] = 0 ; // G
21 sourceImage.data[offset + 2] = 0 ; // B 19 sourceImage.data[offset + 2] = 0 ; // B
22 sourceImage.data[offset + 3] = 202 - y ; // Alpha 20 sourceImage.data[offset + 3] = 202 - y ; // Alpha
23 } 21 }
24 22
25 for (var x = 0; x < source.width; x++) { 23 for (var x = 0; x < source.width; x++) {
26 » for (var y = 1; y < 3; y++) { 24 for (var y = 1; y < 3; y++) {
27 » » drawBlackDot(x, y); 25 drawBlackDot(x, y);
28 » } 26 }
29 } 27 }
30 28
31 sourceContext.putImageData(sourceImage, 0, 0); 29 sourceContext.putImageData(sourceImage, 0, 0);
32 30
33 function scaleTestResults(quality){ 31 function scaleTestResults(quality){
34 var canvas = document.createElement("canvas"); 32 var canvas = document.createElement("canvas");
35 canvas.id = quality + "Canvas"; 33 canvas.id = quality + "Canvas";
36 document.body.appendChild(canvas); 34 document.body.appendChild(canvas);
37 canvas.width = sourceImage.width / 4; 35 canvas.width = sourceImage.width / 4;
38 canvas.height = sourceImage.height / 4; 36 canvas.height = sourceImage.height / 4;
39 return scaleImageData(canvas, quality); 37 return scaleImageData(canvas, quality);
40 } 38 }
41 39
42 function scaleImageData(destinationCanvas, quality) { 40 function scaleImageData(destinationCanvas, quality) {
43 var context = destinationCanvas.getContext("2d"); 41 var context = destinationCanvas.getContext("2d");
44 42
45 if (quality) 43 if (quality)
46 context.imageSmoothingQuality = quality; 44 context.imageSmoothingQuality = quality;
47 45
48 context.drawImage(source, 0, 0, destinationCanvas.width, 46 context.drawImage(source, 0, 0, destinationCanvas.width,
49 destinationCanvas.height); 47 destinationCanvas.height);
50 var data = context.getImageData(0, 0, 1, 1).data; 48 var data = context.getImageData(0, 0, 1, 1).data;
51 context.clearRect(0, 0, destinationCanvas.width, destinationCanvas.height); 49 context.clearRect(0, 0, destinationCanvas.width, destinationCanvas.height);
52 return JSON.stringify(data); 50 return JSON.stringify(data);
53 } 51 }
54 52
55 function testInvalidInput(badInput){
56 shouldNotThrow(badInput);
57 shouldBe("highContext.imageSmoothingQuality", "'high'");
58 }
59
60 function sampleAlpha(data){ 53 function sampleAlpha(data){
61 return JSON.parse(data)[3] 54 return JSON.parse(data)[3]
62 } 55 }
63 56
64 debug("On getting, must return the last value it was set to."); 57 test(function(t) {
65 var lowData = scaleTestResults("low"); 58 // On getting, must return the last value it was set to.");
66 var lowContext = document.getElementById("lowCanvas").getContext('2d'); 59 var lowData = scaleTestResults("low");
67 shouldBe("lowContext.imageSmoothingQuality", "'low'"); 60 var lowContext = document.getElementById("lowCanvas").getContext('2d');
68 61 assert_equals(lowContext.imageSmoothingQuality, 'low');
69 var mediumData = scaleTestResults("medium"); 62
70 var mediumContext = document.getElementById("mediumCanvas").getContext('2d'); 63 var mediumData = scaleTestResults("medium");
71 shouldBe("mediumContext.imageSmoothingQuality", "'medium'"); 64 var mediumContext = document.getElementById("mediumCanvas").getContext('2d') ;
72 65 assert_equals(mediumContext.imageSmoothingQuality, 'medium');
73 var highData = scaleTestResults("high"); 66
74 var highContext = document.getElementById("highCanvas").getContext('2d'); 67 var highData = scaleTestResults("high");
75 var highCanvas = document.getElementById("highCanvas"); 68 var highContext = document.getElementById("highCanvas").getContext('2d');
76 shouldBe("highContext.imageSmoothingQuality", "'high'"); 69 var highCanvas = document.getElementById("highCanvas");
77 70 assert_equals(highContext.imageSmoothingQuality, 'high');
78 lowContext.imageSmoothingEnabled = false; 71
79 var noFilterData = scaleImageData(lowCanvas, lowCanvas.imageSmoothingQuality); 72 lowContext.imageSmoothingEnabled = false;
80 73 var noFilterData = scaleImageData(lowCanvas, lowCanvas.imageSmoothingQuality );
81 debug(""); 74
82 shouldNotBe("lowData", "mediumData"); 75 assert_false(lowData === mediumData);
83 // Skia uses mipmaps when downscaling, for both high and medium quality 76 // Skia uses mipmaps when downscaling, for both high and medium quality
84 shouldBe("mediumData", "highData"); 77 assert_equals(mediumData, highData);
85 shouldNotBe("lowData", "highData"); 78 assert_false(lowData === highData);
86 79
87 debug(""); 80 assert_equals(sampleAlpha(noFilterData), sampleAlpha(lowData));
88 shouldBe("sampleAlpha(noFilterData)", "sampleAlpha(lowData)"); 81 assert_true(sampleAlpha(lowData) > sampleAlpha(mediumData));
89 shouldBeGreaterThan("sampleAlpha(lowData)", "sampleAlpha(mediumData)"); 82 // Skia uses mipmaps when downscaling, for both high and medium quality
90 // Skia uses mipmaps when downscaling, for both high and medium quality 83 assert_equals(sampleAlpha(mediumData), sampleAlpha(highData));
91 shouldBe("sampleAlpha(mediumData)", "sampleAlpha(highData)"); 84
92 85 // On setting, it must be set to the new value.
93 86 highContext.imageSmoothingQuality = 'medium';
94 debug("\n\nOn setting, it must be set to the new value."); 87 assert_equals(highContext.imageSmoothingQuality, 'medium');
95 evalAndLog("highContext.imageSmoothingQuality = 'medium';"); 88 assert_equals(scaleImageData(highCanvas, highCanvas.imageSmoothingQuality),
96 shouldBe("highContext.imageSmoothingQuality", "'medium'"); 89 mediumData);
97 shouldBe("scaleImageData(highCanvas, highCanvas.imageSmoothingQuality);", 90 highContext.imageSmoothingQuality = 'high';
98 » » » "mediumData"); 91 assert_equals(highContext.imageSmoothingQuality, 'high');
99 evalAndLog("highContext.imageSmoothingQuality = 'high';"); 92 assert_equals(scaleImageData(highCanvas, highCanvas.imageSmoothingQuality),
100 shouldBe("highContext.imageSmoothingQuality", "'high'"); 93 highData);
101 shouldBe("scaleImageData(highCanvas, highCanvas.imageSmoothingQuality);", 94
102 » » "highData"); 95 // When the CanvasRenderingContext2D object is created, the attribute must b e set to 'low'.
103 96 assert_equals(document.getElementById("default").getContext("2d").imageSmoot hingQuality, 'low');
104 97
105 debug("\n\nWhen the CanvasRenderingContext2D object is created, " + 98 // ImageSmoothingQuality can be set without real effect when imageSmoothingE nabled is false.
106 » » "the attribute must be set to 'low'."); 99 highContext.imageSmoothingEnabled = false;
107 shouldBe('document.getElementById("default").getContext("2d").' + 100 assert_equals(highContext.imageSmoothingQuality, 'high');
108 » » 'imageSmoothingQuality', "'low'"); 101 assert_equals(scaleImageData(highCanvas, highCanvas.imageSmoothingQuality),
109 102 noFilterData);
110 103 highContext.imageSmoothingQuality = 'medium';
111 debug("\n\nImageSmoothingQuality can be set without real effect when " + 104 assert_equals(highContext.imageSmoothingQuality, 'medium');
112 » » "imageSmoothingEnabled is false."); 105 assert_equals(scaleImageData(highCanvas, highCanvas.imageSmoothingQuality),
113 evalAndLog("highContext.imageSmoothingEnabled = false;"); 106 noFilterData);
114 shouldBe("highContext.imageSmoothingQuality", "'high'"); 107
115 shouldBe("scaleImageData(highCanvas, highCanvas.imageSmoothingQuality)", 108 // Invalid Input is not accepted.
116 » » "noFilterData"); 109 highContext.imageSmoothingEnabled = true;
117 evalAndLog("highContext.imageSmoothingQuality = 'medium'"); 110 highContext.imageSmoothingQuality = 'high';
118 shouldBe("highContext.imageSmoothingQuality", "'medium'"); 111 scaleImageData(highCanvas, '3223');
119 shouldBe("scaleImageData(highCanvas, highCanvas.imageSmoothingQuality)", 112 assert_equals(highContext.imageSmoothingQuality, 'high');
120 » » "noFilterData"); 113 scaleImageData(highCanvas, 'bad_input');
121 114 assert_equals(highContext.imageSmoothingQuality, 'high');
122 115 scaleImageData(highCanvas, 'LOW');
123 debug("\n\nInvalid Input is not accpeted."); 116 assert_equals(highContext.imageSmoothingQuality, 'high');
124 evalAndLog("highContext.imageSmoothingEnabled = true; " + 117 scaleImageData(highCanvas, 'Medium');
125 » » "highContext.imageSmoothingQuality = 'high';"); 118 assert_equals(highContext.imageSmoothingQuality, 'high');
126 testInvalidInput("scaleImageData(highCanvas, '3223')"); 119
127 testInvalidInput("scaleImageData(highCanvas, 'bad_input')"); 120
128 testInvalidInput("scaleImageData(highCanvas, 'LOW')"); 121 // The save() and restore() should work.
129 testInvalidInput("scaleImageData(highCanvas, 'Medium')"); 122 highContext.save();
130 123 highContext.imageSmoothingQuality = 'medium';
131 124 assert_equals(highContext.imageSmoothingQuality, 'medium');
132 debug("\n\nThe save() and restore() should work."); 125 assert_equals(scaleImageData(highCanvas, highCanvas.imageSmoothingQuality), mediumData);
133 evalAndLog("highContext.save(); highContext.imageSmoothingQuality = 'medium';"); 126 highContext.restore();
134 shouldBe("highContext.imageSmoothingQuality", "'medium'"); 127 assert_equals(highContext.imageSmoothingQuality, 'high');
135 shouldBe("scaleImageData(highCanvas, highCanvas.imageSmoothingQuality);", 128 assert_equals(scaleImageData(highCanvas, highCanvas.imageSmoothingQuality), highData);
136 » » "mediumData"); 129
137 shouldBe("highContext.restore(); highContext.imageSmoothingQuality", "'high'"); 130 }, 'Tests for the imageSmoothingQuality attribute.');
138 shouldBe("scaleImageData(highCanvas, highCanvas.imageSmoothingQuality);", 131 </script>
139 » » "highData"); 132 </body>
140
141 debug("");
142 </script>
143 </body>
144 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698