| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "config.h" | 5 #include "config.h" |
| 6 #include <public/WebLayer.h> | 6 #include <public/WebLayer.h> |
| 7 | 7 |
| 8 #include "CompositorFakeWebGraphicsContext3D.h" | 8 #include "CompositorFakeWebGraphicsContext3D.h" |
| 9 #include "WebCompositorInitializer.h" |
| 9 #include "WebLayerImpl.h" | 10 #include "WebLayerImpl.h" |
| 10 #include "WebLayerTreeViewTestCommon.h" | 11 #include "WebLayerTreeViewTestCommon.h" |
| 11 #include <public/WebCompositor.h> | |
| 12 #include <public/WebContentLayer.h> | 12 #include <public/WebContentLayer.h> |
| 13 #include <public/WebContentLayerClient.h> | 13 #include <public/WebContentLayerClient.h> |
| 14 #include <public/WebExternalTextureLayer.h> | 14 #include <public/WebExternalTextureLayer.h> |
| 15 #include <public/WebFloatPoint.h> | 15 #include <public/WebFloatPoint.h> |
| 16 #include <public/WebFloatRect.h> | 16 #include <public/WebFloatRect.h> |
| 17 #include <public/WebLayerScrollClient.h> | 17 #include <public/WebLayerScrollClient.h> |
| 18 #include <public/WebLayerTreeView.h> | 18 #include <public/WebLayerTreeView.h> |
| 19 #include <public/WebLayerTreeViewClient.h> | 19 #include <public/WebLayerTreeViewClient.h> |
| 20 #include <public/WebRect.h> | 20 #include <public/WebRect.h> |
| 21 #include <public/WebSize.h> | 21 #include <public/WebSize.h> |
| 22 #include <public/WebSolidColorLayer.h> |
| 22 | 23 |
| 23 #include <gmock/gmock.h> | 24 #include <gmock/gmock.h> |
| 24 | 25 |
| 25 using namespace WebKit; | 26 using namespace WebKit; |
| 26 using testing::AnyNumber; | 27 using testing::AnyNumber; |
| 27 using testing::AtLeast; | 28 using testing::AtLeast; |
| 28 using testing::Mock; | 29 using testing::Mock; |
| 29 using testing::Test; | 30 using testing::Test; |
| 30 using testing::_; | 31 using testing::_; |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 class MockWebContentLayerClient : public WebContentLayerClient { | 35 class MockWebContentLayerClient : public WebContentLayerClient { |
| 35 public: | 36 public: |
| 36 MOCK_METHOD3(paintContents, void(WebCanvas*, const WebRect& clip, WebFloatRe
ct& opaque)); | 37 MOCK_METHOD3(paintContents, void(WebCanvas*, const WebRect& clip, WebFloatRe
ct& opaque)); |
| 37 }; | 38 }; |
| 38 | 39 |
| 39 class WebLayerTest : public Test { | 40 class WebLayerTest : public Test { |
| 40 public: | 41 public: |
| 42 WebLayerTest() |
| 43 : m_compositorInitializer(0) |
| 44 { |
| 45 } |
| 46 |
| 41 virtual void SetUp() | 47 virtual void SetUp() |
| 42 { | 48 { |
| 43 // Initialize without threading support. | |
| 44 WebKit::WebCompositor::initialize(0); | |
| 45 m_rootLayer = adoptPtr(WebLayer::create()); | 49 m_rootLayer = adoptPtr(WebLayer::create()); |
| 46 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | 50 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); |
| 47 EXPECT_TRUE(m_view = adoptPtr(WebLayerTreeView::create(&m_client, *m_roo
tLayer, WebLayerTreeView::Settings()))); | 51 EXPECT_TRUE(m_view = adoptPtr(WebLayerTreeView::create(&m_client, *m_roo
tLayer, WebLayerTreeView::Settings()))); |
| 48 Mock::VerifyAndClearExpectations(&m_client); | 52 Mock::VerifyAndClearExpectations(&m_client); |
| 49 } | 53 } |
| 50 | 54 |
| 51 virtual void TearDown() | 55 virtual void TearDown() |
| 52 { | 56 { |
| 53 // We may get any number of scheduleComposite calls during shutdown. | 57 // We may get any number of scheduleComposite calls during shutdown. |
| 54 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | 58 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); |
| 55 m_rootLayer.clear(); | 59 m_rootLayer.clear(); |
| 56 m_view.clear(); | 60 m_view.clear(); |
| 57 WebKit::WebCompositor::shutdown(); | |
| 58 } | 61 } |
| 59 | 62 |
| 60 protected: | 63 protected: |
| 64 WebKitTests::WebCompositorInitializer m_compositorInitializer; |
| 61 MockWebLayerTreeViewClient m_client; | 65 MockWebLayerTreeViewClient m_client; |
| 62 OwnPtr<WebLayer> m_rootLayer; | 66 OwnPtr<WebLayer> m_rootLayer; |
| 63 OwnPtr<WebLayerTreeView> m_view; | 67 OwnPtr<WebLayerTreeView> m_view; |
| 64 }; | 68 }; |
| 65 | 69 |
| 66 // Tests that the client gets called to ask for a composite if we change the | 70 // Tests that the client gets called to ask for a composite if we change the |
| 67 // fields. | 71 // fields. |
| 68 TEST_F(WebLayerTest, Client) | 72 TEST_F(WebLayerTest, Client) |
| 69 { | 73 { |
| 70 // Base layer. | 74 // Base layer. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 layer->setOpaque(true); | 117 layer->setOpaque(true); |
| 114 Mock::VerifyAndClearExpectations(&m_client); | 118 Mock::VerifyAndClearExpectations(&m_client); |
| 115 EXPECT_TRUE(layer->opaque()); | 119 EXPECT_TRUE(layer->opaque()); |
| 116 | 120 |
| 117 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 121 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 118 layer->setPosition(point); | 122 layer->setPosition(point); |
| 119 Mock::VerifyAndClearExpectations(&m_client); | 123 Mock::VerifyAndClearExpectations(&m_client); |
| 120 EXPECT_EQ(point, layer->position()); | 124 EXPECT_EQ(point, layer->position()); |
| 121 | 125 |
| 122 // Texture layer. | 126 // Texture layer. |
| 123 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | 127 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 124 OwnPtr<WebExternalTextureLayer> textureLayer = adoptPtr(WebExternalTextureLa
yer::create()); | 128 OwnPtr<WebExternalTextureLayer> textureLayer = adoptPtr(WebExternalTextureLa
yer::create()); |
| 125 m_rootLayer->addChild(textureLayer->layer()); | 129 m_rootLayer->addChild(textureLayer->layer()); |
| 126 Mock::VerifyAndClearExpectations(&m_client); | 130 Mock::VerifyAndClearExpectations(&m_client); |
| 127 | 131 |
| 128 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 132 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 129 textureLayer->setTextureId(3); | 133 textureLayer->setTextureId(3); |
| 130 Mock::VerifyAndClearExpectations(&m_client); | 134 Mock::VerifyAndClearExpectations(&m_client); |
| 131 | 135 |
| 132 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 136 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 133 textureLayer->setFlipped(true); | 137 textureLayer->setFlipped(true); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 144 EXPECT_CALL(contentClient, paintContents(_, _, _)).Times(AnyNumber()); | 148 EXPECT_CALL(contentClient, paintContents(_, _, _)).Times(AnyNumber()); |
| 145 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | 149 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); |
| 146 OwnPtr<WebContentLayer> contentLayer = adoptPtr(WebContentLayer::create(&con
tentClient)); | 150 OwnPtr<WebContentLayer> contentLayer = adoptPtr(WebContentLayer::create(&con
tentClient)); |
| 147 m_rootLayer->addChild(contentLayer->layer()); | 151 m_rootLayer->addChild(contentLayer->layer()); |
| 148 Mock::VerifyAndClearExpectations(&m_client); | 152 Mock::VerifyAndClearExpectations(&m_client); |
| 149 | 153 |
| 150 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 154 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 151 contentLayer->layer()->setDrawsContent(false); | 155 contentLayer->layer()->setDrawsContent(false); |
| 152 Mock::VerifyAndClearExpectations(&m_client); | 156 Mock::VerifyAndClearExpectations(&m_client); |
| 153 EXPECT_FALSE(contentLayer->layer()->drawsContent()); | 157 EXPECT_FALSE(contentLayer->layer()->drawsContent()); |
| 158 |
| 159 // Solid color layer. |
| 160 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 161 OwnPtr<WebSolidColorLayer> solidColorLayer = adoptPtr(WebSolidColorLayer::cr
eate()); |
| 162 m_rootLayer->addChild(solidColorLayer->layer()); |
| 163 Mock::VerifyAndClearExpectations(&m_client); |
| 164 |
| 154 } | 165 } |
| 155 | 166 |
| 156 class MockScrollClient : public WebLayerScrollClient { | 167 class MockScrollClient : public WebLayerScrollClient { |
| 157 public: | 168 public: |
| 158 MOCK_METHOD0(didScroll, void()); | 169 MOCK_METHOD0(didScroll, void()); |
| 159 }; | 170 }; |
| 160 | 171 |
| 161 TEST_F(WebLayerTest, notifyScrollClient) | 172 TEST_F(WebLayerTest, notifyScrollClient) |
| 162 { | 173 { |
| 163 MockScrollClient scrollClient; | 174 MockScrollClient scrollClient; |
| 164 | 175 |
| 165 EXPECT_CALL(scrollClient, didScroll()).Times(0); | 176 EXPECT_CALL(scrollClient, didScroll()).Times(0); |
| 166 m_rootLayer->setScrollClient(&scrollClient); | 177 m_rootLayer->setScrollClient(&scrollClient); |
| 167 Mock::VerifyAndClearExpectations(&scrollClient); | 178 Mock::VerifyAndClearExpectations(&scrollClient); |
| 168 | 179 |
| 169 EXPECT_CALL(scrollClient, didScroll()).Times(1); | 180 EXPECT_CALL(scrollClient, didScroll()).Times(1); |
| 170 m_rootLayer->setScrollPosition(WebPoint(14, 19)); | 181 m_rootLayer->setScrollPosition(WebPoint(14, 19)); |
| 171 Mock::VerifyAndClearExpectations(&scrollClient); | 182 Mock::VerifyAndClearExpectations(&scrollClient); |
| 172 | 183 |
| 173 EXPECT_CALL(scrollClient, didScroll()).Times(0); | 184 EXPECT_CALL(scrollClient, didScroll()).Times(0); |
| 174 m_rootLayer->setScrollPosition(WebPoint(14, 19)); | 185 m_rootLayer->setScrollPosition(WebPoint(14, 19)); |
| 175 Mock::VerifyAndClearExpectations(&scrollClient); | 186 Mock::VerifyAndClearExpectations(&scrollClient); |
| 176 | 187 |
| 177 m_rootLayer->setScrollClient(0); | 188 m_rootLayer->setScrollClient(0); |
| 178 } | 189 } |
| 179 | 190 |
| 180 } | 191 } |
| OLD | NEW |