| 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 "core/html/canvas/CanvasFontCache.h" | 5 #include "core/html/canvas/CanvasFontCache.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" |
| 7 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 8 #include "core/html/HTMLDocument.h" | |
| 9 #include "core/html/canvas/CanvasContextCreationAttributes.h" | 9 #include "core/html/canvas/CanvasContextCreationAttributes.h" |
| 10 #include "core/html/canvas/CanvasRenderingContext.h" | 10 #include "core/html/canvas/CanvasRenderingContext.h" |
| 11 #include "core/loader/EmptyClients.h" | 11 #include "core/loader/EmptyClients.h" |
| 12 #include "core/testing/DummyPageHolder.h" | 12 #include "core/testing/DummyPageHolder.h" |
| 13 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 13 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include <memory> | 16 #include <memory> |
| 17 | 17 |
| 18 using ::testing::Mock; | 18 using ::testing::Mock; |
| 19 | 19 |
| 20 namespace blink { | 20 namespace blink { |
| 21 | 21 |
| 22 class CanvasFontCacheTest : public ::testing::Test { | 22 class CanvasFontCacheTest : public ::testing::Test { |
| 23 protected: | 23 protected: |
| 24 CanvasFontCacheTest(); | 24 CanvasFontCacheTest(); |
| 25 void SetUp() override; | 25 void SetUp() override; |
| 26 | 26 |
| 27 DummyPageHolder& page() const { return *m_dummyPageHolder; } | 27 DummyPageHolder& page() const { return *m_dummyPageHolder; } |
| 28 HTMLDocument& document() const { return *m_document; } | 28 Document& document() const { return *m_document; } |
| 29 HTMLCanvasElement& canvasElement() const { return *m_canvasElement; } | 29 HTMLCanvasElement& canvasElement() const { return *m_canvasElement; } |
| 30 CanvasRenderingContext* context2d() const; | 30 CanvasRenderingContext* context2d() const; |
| 31 CanvasFontCache* cache() { return m_document->canvasFontCache(); } | 31 CanvasFontCache* cache() { return m_document->canvasFontCache(); } |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 34 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 35 Persistent<HTMLDocument> m_document; | 35 Persistent<Document> m_document; |
| 36 Persistent<HTMLCanvasElement> m_canvasElement; | 36 Persistent<HTMLCanvasElement> m_canvasElement; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 CanvasFontCacheTest::CanvasFontCacheTest() | 39 CanvasFontCacheTest::CanvasFontCacheTest() |
| 40 { } | 40 { } |
| 41 | 41 |
| 42 CanvasRenderingContext* CanvasFontCacheTest::context2d() const | 42 CanvasRenderingContext* CanvasFontCacheTest::context2d() const |
| 43 { | 43 { |
| 44 // If the following check fails, perhaps you forgot to call createContext | 44 // If the following check fails, perhaps you forgot to call createContext |
| 45 // in your test? | 45 // in your test? |
| 46 EXPECT_NE(nullptr, canvasElement().renderingContext()); | 46 EXPECT_NE(nullptr, canvasElement().renderingContext()); |
| 47 EXPECT_TRUE(canvasElement().renderingContext()->is2d()); | 47 EXPECT_TRUE(canvasElement().renderingContext()->is2d()); |
| 48 return canvasElement().renderingContext(); | 48 return canvasElement().renderingContext(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void CanvasFontCacheTest::SetUp() | 51 void CanvasFontCacheTest::SetUp() |
| 52 { | 52 { |
| 53 Page::PageClients pageClients; | 53 Page::PageClients pageClients; |
| 54 fillWithEmptyClients(pageClients); | 54 fillWithEmptyClients(pageClients); |
| 55 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients)
; | 55 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients)
; |
| 56 m_document = toHTMLDocument(&m_dummyPageHolder->document()); | 56 m_document = &m_dummyPageHolder->document(); |
| 57 m_document->documentElement()->setInnerHTML("<body><canvas id='c'></canvas><
/body>", ASSERT_NO_EXCEPTION); | 57 m_document->documentElement()->setInnerHTML("<body><canvas id='c'></canvas><
/body>", ASSERT_NO_EXCEPTION); |
| 58 m_document->view()->updateAllLifecyclePhases(); | 58 m_document->view()->updateAllLifecyclePhases(); |
| 59 m_canvasElement = toHTMLCanvasElement(m_document->getElementById("c")); | 59 m_canvasElement = toHTMLCanvasElement(m_document->getElementById("c")); |
| 60 String canvasType("2d"); | 60 String canvasType("2d"); |
| 61 CanvasContextCreationAttributes attributes; | 61 CanvasContextCreationAttributes attributes; |
| 62 attributes.setAlpha(true); | 62 attributes.setAlpha(true); |
| 63 m_canvasElement->getCanvasRenderingContext(canvasType, attributes); | 63 m_canvasElement->getCanvasRenderingContext(canvasType, attributes); |
| 64 context2d(); // Calling this for the checks | 64 context2d(); // Calling this for the checks |
| 65 } | 65 } |
| 66 | 66 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 96 EXPECT_FALSE(cache()->isInCache("15px sans-serif")); | 96 EXPECT_FALSE(cache()->isInCache("15px sans-serif")); |
| 97 | 97 |
| 98 page().page().setVisibilityState(PageVisibilityStateVisible, false); | 98 page().page().setVisibilityState(PageVisibilityStateVisible, false); |
| 99 context2d()->setFont("15px sans-serif"); | 99 context2d()->setFont("15px sans-serif"); |
| 100 context2d()->setFont("10px sans-serif"); | 100 context2d()->setFont("10px sans-serif"); |
| 101 EXPECT_TRUE(cache()->isInCache("10px sans-serif")); | 101 EXPECT_TRUE(cache()->isInCache("10px sans-serif")); |
| 102 EXPECT_TRUE(cache()->isInCache("15px sans-serif")); | 102 EXPECT_TRUE(cache()->isInCache("15px sans-serif")); |
| 103 } | 103 } |
| 104 | 104 |
| 105 } // namespace blink | 105 } // namespace blink |
| OLD | NEW |