@@ -131,11 +131,41 @@ trait BrowserTests extends WebCryptoApiTests {
131131
132132 @ Test
133133 final def ImageDataTest (): Unit = {
134+ // Test ImageDataConstructors
135+ // from https://developer.mozilla.org/en-US/docs/Web/API/ImageData/ImageData
136+
134137 import org .scalajs .dom .{ImageData , ImageDataSettings , PredefinedColorSpace }
135138 import PredefinedColorSpace ._
136139
137- val defaultImageData : ImageData = new ImageData (200 , 100 , new ImageDataSettings { colorSpace = `display-p3` })
138- assertEquals(defaultImageData.width, 200 )
139- assertEquals(defaultImageData.height, 100 )
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)
140170 }
141171}
0 commit comments