| 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/HTMLCanvasElement.h" |
| 6 |
| 7 #include "core/dom/Document.h" |
| 8 #include "core/frame/FrameView.h" |
| 9 #include "core/frame/Settings.h" |
| 10 #include "core/html/canvas/CanvasContextCreationAttributes.h" |
| 11 #include "core/layout/LayoutBoxModelObject.h" |
| 12 #include "core/page/Page.h" |
| 13 #include "core/paint/PaintLayer.h" |
| 14 #include "core/testing/DummyPageHolder.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 namespace blink { |
| 18 |
| 19 class HTMLCanvasElementTest : public testing::Test { |
| 20 protected: |
| 21 HTMLCanvasElementTest() {} |
| 22 |
| 23 void SetUp() override; |
| 24 |
| 25 Document& document() const { return *m_document; } |
| 26 |
| 27 void setHtmlInnerHTML(const char* htmlContent); |
| 28 |
| 29 void createContext(HTMLCanvasElement*, OpacityMode); |
| 30 |
| 31 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 32 Persistent<Document> m_document; |
| 33 }; |
| 34 |
| 35 void OverrideSettings(Settings& settings) { |
| 36 // Simulate that we allow scripts, so that HTMLCanvasElement uses |
| 37 // LayoutHTMLCanvas. |
| 38 settings.setScriptEnabled(true); |
| 39 } |
| 40 |
| 41 void HTMLCanvasElementTest::SetUp() { |
| 42 m_dummyPageHolder = DummyPageHolder::create( |
| 43 IntSize(800, 600), nullptr, nullptr, &OverrideSettings, nullptr); |
| 44 m_document = &m_dummyPageHolder->document(); |
| 45 DCHECK(m_document); |
| 46 } |
| 47 |
| 48 void HTMLCanvasElementTest::setHtmlInnerHTML(const char* htmlContent) { |
| 49 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent)); |
| 50 document().view()->updateAllLifecyclePhases(); |
| 51 } |
| 52 |
| 53 void HTMLCanvasElementTest::createContext(HTMLCanvasElement* canvas, |
| 54 OpacityMode opacityMode) { |
| 55 String canvasType("2d"); |
| 56 CanvasContextCreationAttributes attributes; |
| 57 attributes.setAlpha(opacityMode == NonOpaque); |
| 58 canvas->getCanvasRenderingContext(canvasType, attributes); |
| 59 } |
| 60 |
| 61 // https://crbug.com/708445: When visibility changes, the compositing reasons |
| 62 // for the canvas element may change. Thus, it should request a compositing |
| 63 // update. |
| 64 TEST_F(HTMLCanvasElementTest, RequestsCompositingUpdateWhenVisibilityChanges) { |
| 65 setHtmlInnerHTML("<canvas id='canvas' width='800' height='600'></canvas>"); |
| 66 document().view()->layout(); |
| 67 |
| 68 auto* element = document().getElementById("canvas"); |
| 69 ASSERT_TRUE(element); |
| 70 ASSERT_TRUE(isHTMLCanvasElement(element)); |
| 71 HTMLCanvasElement* canvas = toHTMLCanvasElement(element); |
| 72 EXPECT_TRUE(canvas->layoutBoxModelObject()); |
| 73 PaintLayer* layer = canvas->layoutBoxModelObject()->layer(); |
| 74 EXPECT_TRUE(layer); |
| 75 |
| 76 // Create context so that pageVisibilityChanged() doesn't early-out. |
| 77 createContext(canvas, NonOpaque); |
| 78 document().view()->updateAllLifecyclePhases(); |
| 79 |
| 80 document().page()->setVisibilityState(PageVisibilityStateHidden, false); |
| 81 EXPECT_TRUE(layer->needsCompositingInputsUpdate()); |
| 82 document().view()->updateAllLifecyclePhases(); |
| 83 |
| 84 document().page()->setVisibilityState(PageVisibilityStateVisible, false); |
| 85 EXPECT_TRUE(layer->needsCompositingInputsUpdate()); |
| 86 } |
| 87 |
| 88 } // namespace blink |
| OLD | NEW |