| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "core/html/canvas/CanvasRenderingContext2D.h" | 7 #include "core/html/canvas/CanvasRenderingContext2D.h" |
| 8 | 8 |
| 9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
| 10 #include "core/html/HTMLDocument.h" | 10 #include "core/html/HTMLDocument.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 EXPECT_EQ(String("rgba(0, 0, 0, 0)"), context2d()->shadowColor()); | 177 EXPECT_EQ(String("rgba(0, 0, 0, 0)"), context2d()->shadowColor()); |
| 178 } | 178 } |
| 179 | 179 |
| 180 TEST_F(CanvasRenderingContext2DAPITest, CreateImageData) | 180 TEST_F(CanvasRenderingContext2DAPITest, CreateImageData) |
| 181 { | 181 { |
| 182 createContext(NonOpaque); | 182 createContext(NonOpaque); |
| 183 | 183 |
| 184 NonThrowableExceptionState exceptionState; | 184 NonThrowableExceptionState exceptionState; |
| 185 | 185 |
| 186 // create a 100x50 imagedata and fill it with white pixels | 186 // create a 100x50 imagedata and fill it with white pixels |
| 187 RefPtrWillBeRawPtr<ImageData> imageData = context2d()->createImageData(100,
50, exceptionState); | 187 ImageData* imageData = context2d()->createImageData(100, 50, exceptionState)
; |
| 188 EXPECT_FALSE(exceptionState.hadException()); | 188 EXPECT_FALSE(exceptionState.hadException()); |
| 189 EXPECT_EQ(100, imageData->width()); | 189 EXPECT_EQ(100, imageData->width()); |
| 190 EXPECT_EQ(50, imageData->height()); | 190 EXPECT_EQ(50, imageData->height()); |
| 191 | 191 |
| 192 for (unsigned i = 0; i < imageData->data()->length(); ++i) | 192 for (unsigned i = 0; i < imageData->data()->length(); ++i) |
| 193 imageData->data()->data()[i] = 255; | 193 imageData->data()->data()[i] = 255; |
| 194 | 194 |
| 195 EXPECT_EQ(255, imageData->data()->data()[32]); | 195 EXPECT_EQ(255, imageData->data()->data()[32]); |
| 196 | 196 |
| 197 // createImageData(imageData) should create a new ImageData of the same size
as 'imageData' | 197 // createImageData(imageData) should create a new ImageData of the same size
as 'imageData' |
| 198 // but filled with transparent black | 198 // but filled with transparent black |
| 199 | 199 |
| 200 RefPtrWillBeRawPtr<ImageData> sameSizeImageData = context2d()->createImageDa
ta(imageData); | 200 ImageData* sameSizeImageData = context2d()->createImageData(imageData); |
| 201 EXPECT_EQ(100, sameSizeImageData->width()); | 201 EXPECT_EQ(100, sameSizeImageData->width()); |
| 202 EXPECT_EQ(50, sameSizeImageData->height()); | 202 EXPECT_EQ(50, sameSizeImageData->height()); |
| 203 EXPECT_EQ(0, sameSizeImageData->data()->data()[32]); | 203 EXPECT_EQ(0, sameSizeImageData->data()->data()[32]); |
| 204 | 204 |
| 205 // createImageData(width, height) takes the absolute magnitude of the size a
rguments | 205 // createImageData(width, height) takes the absolute magnitude of the size a
rguments |
| 206 | 206 |
| 207 RefPtrWillBeRawPtr<ImageData> imgdata1 = context2d()->createImageData(10, 20
, exceptionState); | 207 ImageData* imgdata1 = context2d()->createImageData(10, 20, exceptionState); |
| 208 EXPECT_FALSE(exceptionState.hadException()); | 208 EXPECT_FALSE(exceptionState.hadException()); |
| 209 RefPtrWillBeRawPtr<ImageData> imgdata2 = context2d()->createImageData(-10, 2
0, exceptionState); | 209 ImageData* imgdata2 = context2d()->createImageData(-10, 20, exceptionState); |
| 210 EXPECT_FALSE(exceptionState.hadException()); | 210 EXPECT_FALSE(exceptionState.hadException()); |
| 211 RefPtrWillBeRawPtr<ImageData> imgdata3 = context2d()->createImageData(10, -2
0, exceptionState); | 211 ImageData* imgdata3 = context2d()->createImageData(10, -20, exceptionState); |
| 212 EXPECT_FALSE(exceptionState.hadException()); | 212 EXPECT_FALSE(exceptionState.hadException()); |
| 213 RefPtrWillBeRawPtr<ImageData> imgdata4 = context2d()->createImageData(-10, -
20, exceptionState); | 213 ImageData* imgdata4 = context2d()->createImageData(-10, -20, exceptionState)
; |
| 214 EXPECT_FALSE(exceptionState.hadException()); | 214 EXPECT_FALSE(exceptionState.hadException()); |
| 215 | 215 |
| 216 EXPECT_EQ((unsigned)800, imgdata1->data()->length()); | 216 EXPECT_EQ((unsigned)800, imgdata1->data()->length()); |
| 217 EXPECT_EQ((unsigned)800, imgdata2->data()->length()); | 217 EXPECT_EQ((unsigned)800, imgdata2->data()->length()); |
| 218 EXPECT_EQ((unsigned)800, imgdata3->data()->length()); | 218 EXPECT_EQ((unsigned)800, imgdata3->data()->length()); |
| 219 EXPECT_EQ((unsigned)800, imgdata4->data()->length()); | 219 EXPECT_EQ((unsigned)800, imgdata4->data()->length()); |
| 220 } | 220 } |
| 221 | 221 |
| 222 } // unnamed namespace | 222 } // unnamed namespace |
| OLD | NEW |