@@ -128,4 +128,44 @@ trait BrowserTests extends WebCryptoApiTests {
128
128
_ <- reasonPromise.future.map(assertEquals(expectedReason, _))
129
129
} yield ()
130
130
}
131
+
132
+ @ Test
133
+ final def ImageDataTest (): Unit = {
134
+ // Test ImageDataConstructors
135
+ // from https://developer.mozilla.org/en-US/docs/Web/API/ImageData/ImageData
136
+
137
+ import org .scalajs .dom .{ImageData , ImageDataSettings , PredefinedColorSpace }
138
+ import PredefinedColorSpace ._
139
+
140
+ val width : Int = 200
141
+ val height : Int = 100
142
+
143
+ // new ImageData(width, height)
144
+ val imgDat1 : ImageData = new ImageData (width, height)
145
+ assertEquals(imgDat1.width, width)
146
+ assertEquals(imgDat1.height, height)
147
+ assertEquals(imgDat1.data.length, width * height * 4 )
148
+
149
+ // new ImageData(width, height, settings) // Firefox doesn't support this constructor.
150
+ // val defaultImageData: ImageData = new ImageData(width, height, new ImageDataSettings { colorSpace = `display-p3` })
151
+ // assertEquals(defaultImageData.width, width)
152
+ // assertEquals(defaultImageData.height, height)
153
+
154
+ // new ImageData(dataArray, width)
155
+ val imgDat2 : ImageData = new ImageData (imgDat1.data, width)
156
+ assertEquals(imgDat2.width, width)
157
+ assertEquals(imgDat2.height, height)
158
+ assertEquals(imgDat2.data.length, width * height * 4 )
159
+
160
+ // new ImageData(dataArray, width, height)
161
+ val imgDat3 : ImageData = new ImageData (imgDat2.data, width, height)
162
+ assertEquals(imgDat3.width, width)
163
+ assertEquals(imgDat3.height, height)
164
+ assertEquals(imgDat3.data.length, width * height * 4 )
165
+
166
+ // new ImageData(dataArray, width, height, settings)
167
+ val defaultImageData : ImageData = new ImageData (imgDat3.data, width, height, new ImageDataSettings { colorSpace = `display-p3` })
168
+ assertEquals(defaultImageData.width, width)
169
+ assertEquals(defaultImageData.height, height)
170
+ }
131
171
}
0 commit comments