| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/html/ImageData.h" |
| 6 |
| 7 #include "core/dom/ExceptionCode.h" |
| 8 #include "platform/geometry/IntSize.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace blink { |
| 12 namespace { |
| 13 |
| 14 class ImageDataTest : public ::testing::Test { |
| 15 protected: |
| 16 ImageDataTest(){}; |
| 17 void TearDown(){}; |
| 18 }; |
| 19 |
| 20 TEST_F(ImageDataTest, NegativeAndZeroIntSizeTest) { |
| 21 ImageData* imageData; |
| 22 |
| 23 imageData = ImageData::create(IntSize(0, 10)); |
| 24 EXPECT_EQ(imageData, nullptr); |
| 25 |
| 26 imageData = ImageData::create(IntSize(10, 0)); |
| 27 EXPECT_EQ(imageData, nullptr); |
| 28 |
| 29 imageData = ImageData::create(IntSize(0, 0)); |
| 30 EXPECT_EQ(imageData, nullptr); |
| 31 |
| 32 imageData = ImageData::create(IntSize(-1, 10)); |
| 33 EXPECT_EQ(imageData, nullptr); |
| 34 |
| 35 imageData = ImageData::create(IntSize(10, -1)); |
| 36 EXPECT_EQ(imageData, nullptr); |
| 37 |
| 38 imageData = ImageData::create(IntSize(-1, -1)); |
| 39 EXPECT_EQ(imageData, nullptr); |
| 40 } |
| 41 |
| 42 // This test passes if it does not crash. If the required memory is not |
| 43 // allocated to the ImageData, then an exception must raise. |
| 44 TEST_F(ImageDataTest, CreateImageDataTooBig) { |
| 45 DummyExceptionStateForTesting exceptionState; |
| 46 ImageData* tooBigImageData = ImageData::create(32767, 32767, exceptionState); |
| 47 if (!tooBigImageData) { |
| 48 EXPECT_TRUE(exceptionState.hadException()); |
| 49 EXPECT_EQ(exceptionState.code(), V8RangeError); |
| 50 } |
| 51 } |
| 52 |
| 53 } // namspace |
| 54 } // namespace blink |
| OLD | NEW |