| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/paint/VideoPainter.h" | 5 #include "core/paint/VideoPainter.h" |
| 6 | 6 |
| 7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
| 8 #include "core/frame/Settings.h" | 8 #include "core/frame/Settings.h" |
| 9 #include "core/html/HTMLMediaElement.h" | 9 #include "core/html/HTMLMediaElement.h" |
| 10 #include "core/loader/EmptyClients.h" | 10 #include "core/loader/EmptyClients.h" |
| 11 #include "core/paint/StubChromeClientForSPv2.h" |
| 11 #include "core/testing/DummyPageHolder.h" | 12 #include "core/testing/DummyPageHolder.h" |
| 12 #include "platform/graphics/compositing/PaintArtifactCompositor.h" | |
| 13 #include "platform/testing/UnitTestHelpers.h" | 13 #include "platform/testing/UnitTestHelpers.h" |
| 14 #include "platform/testing/WebLayerTreeViewImplForTesting.h" | |
| 15 #include "public/platform/Platform.h" | 14 #include "public/platform/Platform.h" |
| 16 #include "public/platform/WebCompositorSupport.h" | 15 #include "public/platform/WebCompositorSupport.h" |
| 17 #include "public/platform/WebLayer.h" | 16 #include "public/platform/WebLayer.h" |
| 18 #include "public/platform/WebMediaPlayer.h" | 17 #include "public/platform/WebMediaPlayer.h" |
| 19 #include "public/platform/WebSize.h" | 18 #include "public/platform/WebSize.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 20 |
| 22 // Integration tests of video painting code (in SPv2 mode). | 21 // Integration tests of video painting code (in SPv2 mode). |
| 23 | 22 |
| 24 namespace blink { | 23 namespace blink { |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 class StubChromeClient : public EmptyChromeClient { | |
| 28 public: | |
| 29 StubChromeClient(WebLayerTreeViewImplForTesting::LayerListPolicy layerListPo
licy) | |
| 30 : m_layerTreeView(layerListPolicy) | |
| 31 { | |
| 32 m_layerTreeView.setRootLayer(*m_paintArtifactCompositor.getWebLayer()); | |
| 33 } | |
| 34 | |
| 35 bool hasLayer(const WebLayer& layer) { return m_layerTreeView.hasLayer(layer
); } | |
| 36 | |
| 37 // ChromeClient | |
| 38 void didPaint(const PaintArtifact& artifact) | |
| 39 { | |
| 40 m_paintArtifactCompositor.update(artifact); | |
| 41 } | |
| 42 | |
| 43 private: | |
| 44 WebLayerTreeViewImplForTesting m_layerTreeView; | |
| 45 PaintArtifactCompositor m_paintArtifactCompositor; | |
| 46 }; | |
| 47 | |
| 48 class StubWebMediaPlayer : public WebMediaPlayer { | 26 class StubWebMediaPlayer : public WebMediaPlayer { |
| 49 public: | 27 public: |
| 50 StubWebMediaPlayer(WebMediaPlayerClient* client) | 28 StubWebMediaPlayer(WebMediaPlayerClient* client) |
| 51 : m_client(client) {} | 29 : m_client(client) {} |
| 52 | 30 |
| 53 const WebLayer* getWebLayer() { return m_webLayer.get(); } | 31 const WebLayer* getWebLayer() { return m_webLayer.get(); } |
| 54 | 32 |
| 55 // WebMediaPlayer | 33 // WebMediaPlayer |
| 56 void load(LoadType, const WebMediaPlayerSource&, CORSMode) | 34 void load(LoadType, const WebMediaPlayerSource&, CORSMode) |
| 57 { | 35 { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 { | 83 { |
| 106 return wrapUnique(new StubWebMediaPlayer(client)); | 84 return wrapUnique(new StubWebMediaPlayer(client)); |
| 107 } | 85 } |
| 108 }; | 86 }; |
| 109 | 87 |
| 110 class VideoPainterTestForSPv2 : public ::testing::TestWithParam<WebLayerTreeView
ImplForTesting::LayerListPolicy> { | 88 class VideoPainterTestForSPv2 : public ::testing::TestWithParam<WebLayerTreeView
ImplForTesting::LayerListPolicy> { |
| 111 protected: | 89 protected: |
| 112 void SetUp() override | 90 void SetUp() override |
| 113 { | 91 { |
| 114 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); | 92 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); |
| 115 m_chromeClient = new StubChromeClient(GetParam()); | 93 m_chromeClient = new StubChromeClientForSPv2(GetParam()); |
| 116 m_frameLoaderClient = new StubFrameLoaderClient; | 94 m_frameLoaderClient = new StubFrameLoaderClient; |
| 117 Page::PageClients clients; | 95 Page::PageClients clients; |
| 118 fillWithEmptyClients(clients); | 96 fillWithEmptyClients(clients); |
| 119 clients.chromeClient = m_chromeClient.get(); | 97 clients.chromeClient = m_chromeClient.get(); |
| 120 m_pageHolder = DummyPageHolder::create(IntSize(800, 600), &clients, m_fr
ameLoaderClient.get(), | 98 m_pageHolder = DummyPageHolder::create(IntSize(800, 600), &clients, m_fr
ameLoaderClient.get(), |
| 121 [](Settings& settings) { settings.setAcceleratedCompositingEnabled(t
rue); }); | 99 [](Settings& settings) { settings.setAcceleratedCompositingEnabled(t
rue); }); |
| 122 document().view()->setParentVisible(true); | 100 document().view()->setParentVisible(true); |
| 123 document().view()->setSelfVisible(true); | 101 document().view()->setSelfVisible(true); |
| 124 document().setURL(KURL(KURL(), "https://example.com/")); | 102 document().setURL(KURL(KURL(), "https://example.com/")); |
| 125 } | 103 } |
| 126 | 104 |
| 127 void TearDown() override | 105 void TearDown() override |
| 128 { | 106 { |
| 129 m_featuresBackup.restore(); | 107 m_featuresBackup.restore(); |
| 130 } | 108 } |
| 131 | 109 |
| 132 Document& document() { return m_pageHolder->document(); } | 110 Document& document() { return m_pageHolder->document(); } |
| 133 bool hasLayerAttached(const WebLayer& layer) { return m_chromeClient->hasLay
er(layer); } | 111 bool hasLayerAttached(const WebLayer& layer) { return m_chromeClient->hasLay
er(layer); } |
| 134 | 112 |
| 135 private: | 113 private: |
| 136 RuntimeEnabledFeatures::Backup m_featuresBackup; | 114 RuntimeEnabledFeatures::Backup m_featuresBackup; |
| 137 Persistent<StubChromeClient> m_chromeClient; | 115 Persistent<StubChromeClientForSPv2> m_chromeClient; |
| 138 Persistent<StubFrameLoaderClient> m_frameLoaderClient; | 116 Persistent<StubFrameLoaderClient> m_frameLoaderClient; |
| 139 std::unique_ptr<DummyPageHolder> m_pageHolder; | 117 std::unique_ptr<DummyPageHolder> m_pageHolder; |
| 140 }; | 118 }; |
| 141 | 119 |
| 142 INSTANTIATE_TEST_CASE_P(, VideoPainterTestForSPv2, ::testing::Values( | 120 INSTANTIATE_TEST_CASE_P(, VideoPainterTestForSPv2, ::testing::Values( |
| 143 WebLayerTreeViewImplForTesting::DontUseLayerLists, | 121 WebLayerTreeViewImplForTesting::DontUseLayerLists, |
| 144 WebLayerTreeViewImplForTesting::UseLayerLists)); | 122 WebLayerTreeViewImplForTesting::UseLayerLists)); |
| 145 | 123 |
| 146 TEST_P(VideoPainterTestForSPv2, VideoLayerAppearsInLayerTree) | 124 TEST_P(VideoPainterTestForSPv2, VideoLayerAppearsInLayerTree) |
| 147 { | 125 { |
| 148 // Insert a <video> and allow it to begin loading. | 126 // Insert a <video> and allow it to begin loading. |
| 149 document().body()->setInnerHTML("<video width=300 height=200 src=test.ogv>",
ASSERT_NO_EXCEPTION); | 127 document().body()->setInnerHTML("<video width=300 height=200 src=test.ogv>",
ASSERT_NO_EXCEPTION); |
| 150 testing::runPendingTasks(); | 128 testing::runPendingTasks(); |
| 151 | 129 |
| 152 // Force the page to paint. | 130 // Force the page to paint. |
| 153 document().view()->updateAllLifecyclePhases(); | 131 document().view()->updateAllLifecyclePhases(); |
| 154 | 132 |
| 155 // Fetch the layer associated with the <video>, and check that it was | 133 // Fetch the layer associated with the <video>, and check that it was |
| 156 // correctly configured in the layer tree. | 134 // correctly configured in the layer tree. |
| 157 HTMLMediaElement* element = toHTMLMediaElement(document().body()->firstChild
()); | 135 HTMLMediaElement* element = toHTMLMediaElement(document().body()->firstChild
()); |
| 158 StubWebMediaPlayer* player = static_cast<StubWebMediaPlayer*>(element->webMe
diaPlayer()); | 136 StubWebMediaPlayer* player = static_cast<StubWebMediaPlayer*>(element->webMe
diaPlayer()); |
| 159 const WebLayer* layer = player->getWebLayer(); | 137 const WebLayer* layer = player->getWebLayer(); |
| 160 ASSERT_TRUE(layer); | 138 ASSERT_TRUE(layer); |
| 161 EXPECT_TRUE(hasLayerAttached(*layer)); | 139 EXPECT_TRUE(hasLayerAttached(*layer)); |
| 162 EXPECT_EQ(WebSize(300, 200), layer->bounds()); | 140 EXPECT_EQ(WebSize(300, 200), layer->bounds()); |
| 163 } | 141 } |
| 164 | 142 |
| 165 } // namespace | 143 } // namespace |
| 166 } // namespace blink | 144 } // namespace blink |
| OLD | NEW |