OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 "web/WebViewImpl.h" | |
6 | |
7 #include "platform/RuntimeEnabledFeatures.h" | |
8 #include "platform/graphics/compositing/PaintArtifactCompositor.h" | |
9 #include "public/platform/WebLayerTreeView.h" | |
10 #include "public/web/WebViewClient.h" | |
11 #include "testing/gmock/include/gmock/gmock.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 #include "web/tests/FrameTestHelpers.h" | |
14 | |
15 // Tests that WebViewImpl attaches the layer owned by PaintArtifactCompositor to | |
16 // the WebLayerTreeView when requested. | |
17 | |
18 using testing::Property; | |
19 | |
20 namespace blink { | |
21 namespace { | |
22 | |
23 class MockWebLayerTreeView : public WebLayerTreeView { | |
24 public: | |
25 // WebLayerTreeView | |
26 MOCK_METHOD1(setRootLayer, void(const WebLayer&)); | |
27 MOCK_METHOD0(clearRootLayer, void()); | |
28 }; | |
29 | |
30 class TestWebViewClientWithLayerTreeView : public FrameTestHelpers::TestWebViewC
lient { | |
31 public: | |
32 TestWebViewClientWithLayerTreeView(WebLayerTreeView* layerTreeView) | |
33 : m_layerTreeView(layerTreeView) { } | |
34 | |
35 // WebViewClient | |
36 WebLayerTreeView* layerTreeView() override { return m_layerTreeView; } | |
37 | |
38 private: | |
39 WebLayerTreeView* m_layerTreeView; | |
40 }; | |
41 | |
42 class WebViewImplPaintArtifactCompositorTest : public testing::Test { | |
43 protected: | |
44 WebViewImplPaintArtifactCompositorTest() | |
45 : m_webViewClient(&m_webLayerTreeView) { } | |
46 | |
47 void SetUp() override | |
48 { | |
49 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); | |
50 m_helper.initialize(false, nullptr, &m_webViewClient); | |
51 } | |
52 | |
53 void TearDown() override | |
54 { | |
55 m_featuresBackup.restore(); | |
56 } | |
57 | |
58 MockWebLayerTreeView& webLayerTreeView() { return m_webLayerTreeView; } | |
59 WebViewImpl& webViewImpl() { return *m_helper.webView(); } | |
60 PaintArtifactCompositor& getPaintArtifactCompositor() { return webViewImpl()
.getPaintArtifactCompositor(); } | |
61 | |
62 private: | |
63 RuntimeEnabledFeatures::Backup m_featuresBackup; | |
64 MockWebLayerTreeView m_webLayerTreeView; | |
65 TestWebViewClientWithLayerTreeView m_webViewClient; | |
66 FrameTestHelpers::WebViewHelper m_helper; | |
67 }; | |
68 | |
69 TEST_F(WebViewImplPaintArtifactCompositorTest, AttachAndDetach) | |
70 { | |
71 cc::Layer* rootLayer = getPaintArtifactCompositor().rootLayer(); | |
72 ASSERT_TRUE(rootLayer); | |
73 | |
74 EXPECT_CALL(webLayerTreeView(), setRootLayer(Property(&WebLayer::ccLayer, ro
otLayer))); | |
75 webViewImpl().attachPaintArtifactCompositor(); | |
76 testing::Mock::VerifyAndClearExpectations(&webLayerTreeView()); | |
77 | |
78 EXPECT_CALL(webLayerTreeView(), clearRootLayer()); | |
79 webViewImpl().detachPaintArtifactCompositor(); | |
80 testing::Mock::VerifyAndClearExpectations(&webLayerTreeView()); | |
81 } | |
82 | |
83 } // namespace | |
84 } // namespace blink | |
OLD | NEW |