| 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 "modules/canvas2d/CanvasRenderingContext2D.h" | 5 #include "modules/canvas2d/CanvasRenderingContext2D.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" |
| 7 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 8 #include "core/frame/Settings.h" | 9 #include "core/frame/Settings.h" |
| 9 #include "core/html/HTMLCanvasElement.h" | 10 #include "core/html/HTMLCanvasElement.h" |
| 10 #include "core/html/HTMLDocument.h" | |
| 11 #include "core/html/ImageData.h" | 11 #include "core/html/ImageData.h" |
| 12 #include "core/loader/EmptyClients.h" | 12 #include "core/loader/EmptyClients.h" |
| 13 #include "core/testing/DummyPageHolder.h" | 13 #include "core/testing/DummyPageHolder.h" |
| 14 #include "modules/accessibility/AXObject.h" | 14 #include "modules/accessibility/AXObject.h" |
| 15 #include "modules/accessibility/AXObjectCacheImpl.h" | 15 #include "modules/accessibility/AXObjectCacheImpl.h" |
| 16 #include "modules/canvas2d/CanvasGradient.h" | 16 #include "modules/canvas2d/CanvasGradient.h" |
| 17 #include "modules/canvas2d/CanvasPattern.h" | 17 #include "modules/canvas2d/CanvasPattern.h" |
| 18 #include "modules/canvas2d/HitRegionOptions.h" | 18 #include "modules/canvas2d/HitRegionOptions.h" |
| 19 #include "modules/webgl/WebGLRenderingContext.h" | 19 #include "modules/webgl/WebGLRenderingContext.h" |
| 20 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 20 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include <memory> | 23 #include <memory> |
| 24 | 24 |
| 25 using ::testing::Mock; | 25 using ::testing::Mock; |
| 26 | 26 |
| 27 namespace blink { | 27 namespace blink { |
| 28 | 28 |
| 29 class CanvasRenderingContext2DAPITest : public ::testing::Test { | 29 class CanvasRenderingContext2DAPITest : public ::testing::Test { |
| 30 protected: | 30 protected: |
| 31 CanvasRenderingContext2DAPITest(); | 31 CanvasRenderingContext2DAPITest(); |
| 32 void SetUp() override; | 32 void SetUp() override; |
| 33 | 33 |
| 34 DummyPageHolder& page() const { return *m_dummyPageHolder; } | 34 DummyPageHolder& page() const { return *m_dummyPageHolder; } |
| 35 HTMLDocument& document() const { return *m_document; } | 35 Document& document() const { return *m_document; } |
| 36 HTMLCanvasElement& canvasElement() const { return *m_canvasElement; } | 36 HTMLCanvasElement& canvasElement() const { return *m_canvasElement; } |
| 37 CanvasRenderingContext2D* context2d() const; | 37 CanvasRenderingContext2D* context2d() const; |
| 38 | 38 |
| 39 void createContext(OpacityMode); | 39 void createContext(OpacityMode); |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 42 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 43 Persistent<HTMLDocument> m_document; | 43 Persistent<Document> m_document; |
| 44 Persistent<HTMLCanvasElement> m_canvasElement; | 44 Persistent<HTMLCanvasElement> m_canvasElement; |
| 45 | 45 |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 CanvasRenderingContext2DAPITest::CanvasRenderingContext2DAPITest() | 48 CanvasRenderingContext2DAPITest::CanvasRenderingContext2DAPITest() |
| 49 { } | 49 { } |
| 50 | 50 |
| 51 CanvasRenderingContext2D* CanvasRenderingContext2DAPITest::context2d() const | 51 CanvasRenderingContext2D* CanvasRenderingContext2DAPITest::context2d() const |
| 52 { | 52 { |
| 53 // If the following check fails, perhaps you forgot to call createContext | 53 // If the following check fails, perhaps you forgot to call createContext |
| (...skipping 10 matching lines...) Expand all Loading... |
| 64 attributes.setAlpha(opacityMode == NonOpaque); | 64 attributes.setAlpha(opacityMode == NonOpaque); |
| 65 m_canvasElement->getCanvasRenderingContext(canvasType, attributes); | 65 m_canvasElement->getCanvasRenderingContext(canvasType, attributes); |
| 66 context2d(); // Calling this for the checks | 66 context2d(); // Calling this for the checks |
| 67 } | 67 } |
| 68 | 68 |
| 69 void CanvasRenderingContext2DAPITest::SetUp() | 69 void CanvasRenderingContext2DAPITest::SetUp() |
| 70 { | 70 { |
| 71 Page::PageClients pageClients; | 71 Page::PageClients pageClients; |
| 72 fillWithEmptyClients(pageClients); | 72 fillWithEmptyClients(pageClients); |
| 73 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients)
; | 73 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients)
; |
| 74 m_document = toHTMLDocument(&m_dummyPageHolder->document()); | 74 m_document = &m_dummyPageHolder->document(); |
| 75 m_document->documentElement()->setInnerHTML("<body><canvas id='c'></canvas><
/body>", ASSERT_NO_EXCEPTION); | 75 m_document->documentElement()->setInnerHTML("<body><canvas id='c'></canvas><
/body>", ASSERT_NO_EXCEPTION); |
| 76 m_document->view()->updateAllLifecyclePhases(); | 76 m_document->view()->updateAllLifecyclePhases(); |
| 77 m_canvasElement = toHTMLCanvasElement(m_document->getElementById("c")); | 77 m_canvasElement = toHTMLCanvasElement(m_document->getElementById("c")); |
| 78 } | 78 } |
| 79 | 79 |
| 80 TEST_F(CanvasRenderingContext2DAPITest, SetShadowColor_Clamping) | 80 TEST_F(CanvasRenderingContext2DAPITest, SetShadowColor_Clamping) |
| 81 { | 81 { |
| 82 createContext(NonOpaque); | 82 createContext(NonOpaque); |
| 83 | 83 |
| 84 context2d()->setShadowColor("rgba(0,0,0,0)"); | 84 context2d()->setShadowColor("rgba(0,0,0,0)"); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 TEST_F(CanvasRenderingContext2DAPITest, GetImageDataTooBig) | 253 TEST_F(CanvasRenderingContext2DAPITest, GetImageDataTooBig) |
| 254 { | 254 { |
| 255 createContext(NonOpaque); | 255 createContext(NonOpaque); |
| 256 TrackExceptionState exceptionState; | 256 TrackExceptionState exceptionState; |
| 257 ImageData* imageData = context2d()->getImageData(0, 0, 1000000, 1000000, exc
eptionState); | 257 ImageData* imageData = context2d()->getImageData(0, 0, 1000000, 1000000, exc
eptionState); |
| 258 EXPECT_EQ(nullptr, imageData); | 258 EXPECT_EQ(nullptr, imageData); |
| 259 EXPECT_TRUE(exceptionState.hadException()); | 259 EXPECT_TRUE(exceptionState.hadException()); |
| 260 EXPECT_EQ(V8RangeError, exceptionState.code()); | 260 EXPECT_EQ(V8RangeError, exceptionState.code()); |
| 261 } | 261 } |
| 262 | 262 |
| 263 void resetCanvasForAccessibilityRectTest(HTMLDocument& document) | 263 void resetCanvasForAccessibilityRectTest(Document& document) |
| 264 { | 264 { |
| 265 document.documentElement()->setInnerHTML( | 265 document.documentElement()->setInnerHTML( |
| 266 "<canvas id='canvas' style='position:absolute; top:0px; left:0px; paddin
g:10px; margin:5px;'>" | 266 "<canvas id='canvas' style='position:absolute; top:0px; left:0px; paddin
g:10px; margin:5px;'>" |
| 267 "<button id='button'></button></canvas>", ASSERT_NO_EXCEPTION); | 267 "<button id='button'></button></canvas>", ASSERT_NO_EXCEPTION); |
| 268 document.settings()->setAccessibilityEnabled(true); | 268 document.settings()->setAccessibilityEnabled(true); |
| 269 HTMLCanvasElement* canvas = toHTMLCanvasElement(document.getElementById("can
vas")); | 269 HTMLCanvasElement* canvas = toHTMLCanvasElement(document.getElementById("can
vas")); |
| 270 | 270 |
| 271 String canvasType("2d"); | 271 String canvasType("2d"); |
| 272 CanvasContextCreationAttributes attributes; | 272 CanvasContextCreationAttributes attributes; |
| 273 attributes.setAlpha(true); | 273 attributes.setAlpha(true); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 AXObjectCacheImpl* axObjectCache = toAXObjectCacheImpl(document().existingAX
ObjectCache()); | 319 AXObjectCacheImpl* axObjectCache = toAXObjectCacheImpl(document().existingAX
ObjectCache()); |
| 320 AXObject* axObject = axObjectCache->getOrCreate(buttonElement); | 320 AXObject* axObject = axObjectCache->getOrCreate(buttonElement); |
| 321 | 321 |
| 322 EXPECT_EQ(25, axObject->elementRect().x().toInt()); | 322 EXPECT_EQ(25, axObject->elementRect().x().toInt()); |
| 323 EXPECT_EQ(25, axObject->elementRect().y().toInt()); | 323 EXPECT_EQ(25, axObject->elementRect().y().toInt()); |
| 324 EXPECT_EQ(40, axObject->elementRect().width().toInt()); | 324 EXPECT_EQ(40, axObject->elementRect().width().toInt()); |
| 325 EXPECT_EQ(40, axObject->elementRect().height().toInt()); | 325 EXPECT_EQ(40, axObject->elementRect().height().toInt()); |
| 326 } | 326 } |
| 327 | 327 |
| 328 } // namespace blink | 328 } // namespace blink |
| OLD | NEW |