| 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 "cc/thread.h" | 5 #include "cc/thread.h" |
| 6 #include "testing/gmock/include/gmock/gmock.h" | 6 #include "testing/gmock/include/gmock/gmock.h" |
| 7 #include "third_party/WebKit/Source/Platform/chromium/public/WebContentLayer.h" | 7 #include "third_party/WebKit/Source/Platform/chromium/public/WebContentLayer.h" |
| 8 #include "third_party/WebKit/Source/Platform/chromium/public/WebContentLayerClie
nt.h" | 8 #include "third_party/WebKit/Source/Platform/chromium/public/WebContentLayerClie
nt.h" |
| 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureL
ayer.h" | 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureL
ayer.h" |
| 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h" | 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h" |
| 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatRect.h" | 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatRect.h" |
| 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" | 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" |
| 13 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerScrollClien
t.h" | 13 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerScrollClien
t.h" |
| 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeView.h" | 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeView.h" |
| 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewCli
ent.h" | 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewCli
ent.h" |
| 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" | 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" |
| 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
| 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebSolidColorLayer.
h" | 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebSolidColorLayer.
h" |
| 19 #include "webkit/compositor_bindings/test/web_layer_tree_view_test_common.h" | 19 #include "webkit/compositor_bindings/test/web_layer_tree_view_test_common.h" |
| 20 #include "webkit/compositor_bindings/web_content_layer_impl.h" |
| 21 #include "webkit/compositor_bindings/web_external_texture_layer_impl.h" |
| 20 #include "webkit/compositor_bindings/web_layer_impl.h" | 22 #include "webkit/compositor_bindings/web_layer_impl.h" |
| 21 #include "webkit/compositor_bindings/web_layer_tree_view_impl.h" | 23 #include "webkit/compositor_bindings/web_layer_tree_view_impl.h" |
| 24 #include "webkit/compositor_bindings/web_solid_color_layer_impl.h" |
| 22 | 25 |
| 23 using namespace WebKit; | 26 using namespace WebKit; |
| 24 using testing::AnyNumber; | 27 using testing::AnyNumber; |
| 25 using testing::AtLeast; | 28 using testing::AtLeast; |
| 26 using testing::Mock; | 29 using testing::Mock; |
| 27 using testing::Test; | 30 using testing::Test; |
| 28 using testing::_; | 31 using testing::_; |
| 29 | 32 |
| 30 namespace { | 33 namespace { |
| 31 | 34 |
| 32 class MockWebContentLayerClient : public WebContentLayerClient { | 35 class MockWebContentLayerClient : public WebContentLayerClient { |
| 33 public: | 36 public: |
| 34 MOCK_METHOD4(paintContents, void(WebCanvas*, const WebRect& clip, bool canPa
intLCDText, WebFloatRect& opaque)); | 37 MOCK_METHOD4(paintContents, void(WebCanvas*, const WebRect& clip, bool canPa
intLCDText, WebFloatRect& opaque)); |
| 35 }; | 38 }; |
| 36 | 39 |
| 37 class WebLayerTest : public Test { | 40 class WebLayerTest : public Test { |
| 38 public: | 41 public: |
| 39 WebLayerTest() | 42 WebLayerTest() |
| 40 { | 43 { |
| 41 } | 44 } |
| 42 | 45 |
| 43 virtual void SetUp() | 46 virtual void SetUp() |
| 44 { | 47 { |
| 45 m_rootLayer.reset(WebLayer::create()); | 48 m_rootLayer.reset(new WebLayerImpl); |
| 46 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | 49 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); |
| 47 m_view.reset(new WebLayerTreeViewImpl(&m_client)); | 50 m_view.reset(new WebLayerTreeViewImpl(&m_client)); |
| 48 EXPECT_TRUE(m_view->initialize(WebLayerTreeView::Settings(), scoped_ptr<
cc::Thread>(NULL))); | 51 EXPECT_TRUE(m_view->initialize(WebLayerTreeView::Settings(), scoped_ptr<
cc::Thread>(NULL))); |
| 49 m_view->setRootLayer(*m_rootLayer); | 52 m_view->setRootLayer(*m_rootLayer); |
| 50 EXPECT_TRUE(m_view); | 53 EXPECT_TRUE(m_view); |
| 51 Mock::VerifyAndClearExpectations(&m_client); | 54 Mock::VerifyAndClearExpectations(&m_client); |
| 52 } | 55 } |
| 53 | 56 |
| 54 virtual void TearDown() | 57 virtual void TearDown() |
| 55 { | 58 { |
| 56 // We may get any number of scheduleComposite calls during shutdown. | 59 // We may get any number of scheduleComposite calls during shutdown. |
| 57 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | 60 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); |
| 58 m_rootLayer.reset(); | 61 m_rootLayer.reset(); |
| 59 m_view.reset(); | 62 m_view.reset(); |
| 60 } | 63 } |
| 61 | 64 |
| 62 protected: | 65 protected: |
| 63 MockWebLayerTreeViewClient m_client; | 66 MockWebLayerTreeViewClient m_client; |
| 64 scoped_ptr<WebLayer> m_rootLayer; | 67 scoped_ptr<WebLayer> m_rootLayer; |
| 65 scoped_ptr<WebLayerTreeViewImpl> m_view; | 68 scoped_ptr<WebLayerTreeViewImpl> m_view; |
| 66 }; | 69 }; |
| 67 | 70 |
| 68 // Tests that the client gets called to ask for a composite if we change the | 71 // Tests that the client gets called to ask for a composite if we change the |
| 69 // fields. | 72 // fields. |
| 70 TEST_F(WebLayerTest, Client) | 73 TEST_F(WebLayerTest, Client) |
| 71 { | 74 { |
| 72 // Base layer. | 75 // Base layer. |
| 73 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | 76 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); |
| 74 scoped_ptr<WebLayer> layer(WebLayer::create()); | 77 scoped_ptr<WebLayer> layer(new WebLayerImpl); |
| 75 layer->setDrawsContent(true); | 78 layer->setDrawsContent(true); |
| 76 m_rootLayer->addChild(layer.get()); | 79 m_rootLayer->addChild(layer.get()); |
| 77 Mock::VerifyAndClearExpectations(&m_client); | 80 Mock::VerifyAndClearExpectations(&m_client); |
| 78 | 81 |
| 79 WebFloatPoint point(3, 4); | 82 WebFloatPoint point(3, 4); |
| 80 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 83 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 81 layer->setAnchorPoint(point); | 84 layer->setAnchorPoint(point); |
| 82 Mock::VerifyAndClearExpectations(&m_client); | 85 Mock::VerifyAndClearExpectations(&m_client); |
| 83 EXPECT_EQ(point, layer->anchorPoint()); | 86 EXPECT_EQ(point, layer->anchorPoint()); |
| 84 | 87 |
| 85 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 88 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 86 float anchorZ = 5; | 89 float anchorZ = 5; |
| 87 layer->setAnchorPointZ(anchorZ); | 90 layer->setAnchorPointZ(anchorZ); |
| 88 Mock::VerifyAndClearExpectations(&m_client); | 91 Mock::VerifyAndClearExpectations(&m_client); |
| 89 EXPECT_EQ(anchorZ, layer->anchorPointZ()); | 92 EXPECT_EQ(anchorZ, layer->anchorPointZ()); |
| 90 | 93 |
| 91 WebSize size(7, 8); | 94 WebSize size(7, 8); |
| 92 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 95 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 93 layer->setBounds(size); | 96 layer->setBounds(size); |
| 94 Mock::VerifyAndClearExpectations(&m_client); | 97 Mock::VerifyAndClearExpectations(&m_client); |
| 95 EXPECT_EQ(size, layer->bounds()); | 98 EXPECT_EQ(size, layer->bounds()); |
| 96 | 99 |
| 97 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 100 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 98 layer->setMasksToBounds(true); | 101 layer->setMasksToBounds(true); |
| 99 Mock::VerifyAndClearExpectations(&m_client); | 102 Mock::VerifyAndClearExpectations(&m_client); |
| 100 EXPECT_TRUE(layer->masksToBounds()); | 103 EXPECT_TRUE(layer->masksToBounds()); |
| 101 | 104 |
| 102 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | 105 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); |
| 103 scoped_ptr<WebLayer> otherLayer(WebLayer::create()); | 106 scoped_ptr<WebLayer> otherLayer(new WebLayerImpl); |
| 104 m_rootLayer->addChild(otherLayer.get()); | 107 m_rootLayer->addChild(otherLayer.get()); |
| 105 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 108 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 106 layer->setMaskLayer(otherLayer.get()); | 109 layer->setMaskLayer(otherLayer.get()); |
| 107 Mock::VerifyAndClearExpectations(&m_client); | 110 Mock::VerifyAndClearExpectations(&m_client); |
| 108 | 111 |
| 109 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 112 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 110 float opacity = 0.123f; | 113 float opacity = 0.123f; |
| 111 layer->setOpacity(opacity); | 114 layer->setOpacity(opacity); |
| 112 Mock::VerifyAndClearExpectations(&m_client); | 115 Mock::VerifyAndClearExpectations(&m_client); |
| 113 EXPECT_EQ(opacity, layer->opacity()); | 116 EXPECT_EQ(opacity, layer->opacity()); |
| 114 | 117 |
| 115 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 118 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 116 layer->setOpaque(true); | 119 layer->setOpaque(true); |
| 117 Mock::VerifyAndClearExpectations(&m_client); | 120 Mock::VerifyAndClearExpectations(&m_client); |
| 118 EXPECT_TRUE(layer->opaque()); | 121 EXPECT_TRUE(layer->opaque()); |
| 119 | 122 |
| 120 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 123 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 121 layer->setPosition(point); | 124 layer->setPosition(point); |
| 122 Mock::VerifyAndClearExpectations(&m_client); | 125 Mock::VerifyAndClearExpectations(&m_client); |
| 123 EXPECT_EQ(point, layer->position()); | 126 EXPECT_EQ(point, layer->position()); |
| 124 | 127 |
| 125 // Texture layer. | 128 // Texture layer. |
| 126 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 129 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 127 scoped_ptr<WebExternalTextureLayer> textureLayer(WebExternalTextureLayer::cr
eate()); | 130 scoped_ptr<WebExternalTextureLayer> textureLayer(new WebExternalTextureLayer
Impl(NULL)); |
| 128 m_rootLayer->addChild(textureLayer->layer()); | 131 m_rootLayer->addChild(textureLayer->layer()); |
| 129 Mock::VerifyAndClearExpectations(&m_client); | 132 Mock::VerifyAndClearExpectations(&m_client); |
| 130 | 133 |
| 131 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 134 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 132 textureLayer->setTextureId(3); | 135 textureLayer->setTextureId(3); |
| 133 Mock::VerifyAndClearExpectations(&m_client); | 136 Mock::VerifyAndClearExpectations(&m_client); |
| 134 | 137 |
| 135 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 138 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 136 textureLayer->setFlipped(true); | 139 textureLayer->setFlipped(true); |
| 137 Mock::VerifyAndClearExpectations(&m_client); | 140 Mock::VerifyAndClearExpectations(&m_client); |
| 138 | 141 |
| 139 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 142 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 140 WebFloatRect uvRect(0.1f, 0.1f, 0.9f, 0.9f); | 143 WebFloatRect uvRect(0.1f, 0.1f, 0.9f, 0.9f); |
| 141 textureLayer->setUVRect(uvRect); | 144 textureLayer->setUVRect(uvRect); |
| 142 Mock::VerifyAndClearExpectations(&m_client); | 145 Mock::VerifyAndClearExpectations(&m_client); |
| 143 | 146 |
| 144 | 147 |
| 145 // Content layer. | 148 // Content layer. |
| 146 MockWebContentLayerClient contentClient; | 149 MockWebContentLayerClient contentClient; |
| 147 EXPECT_CALL(contentClient, paintContents(_, _, _, _)).Times(AnyNumber()); | 150 EXPECT_CALL(contentClient, paintContents(_, _, _, _)).Times(AnyNumber()); |
| 148 | 151 |
| 149 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | 152 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); |
| 150 scoped_ptr<WebContentLayer> contentLayer(WebContentLayer::create(&contentCli
ent)); | 153 scoped_ptr<WebContentLayer> contentLayer(new WebContentLayerImpl(&contentCli
ent)); |
| 151 m_rootLayer->addChild(contentLayer->layer()); | 154 m_rootLayer->addChild(contentLayer->layer()); |
| 152 Mock::VerifyAndClearExpectations(&m_client); | 155 Mock::VerifyAndClearExpectations(&m_client); |
| 153 | 156 |
| 154 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 157 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 155 contentLayer->layer()->setDrawsContent(false); | 158 contentLayer->layer()->setDrawsContent(false); |
| 156 Mock::VerifyAndClearExpectations(&m_client); | 159 Mock::VerifyAndClearExpectations(&m_client); |
| 157 EXPECT_FALSE(contentLayer->layer()->drawsContent()); | 160 EXPECT_FALSE(contentLayer->layer()->drawsContent()); |
| 158 | 161 |
| 159 // Solid color layer. | 162 // Solid color layer. |
| 160 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | 163 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); |
| 161 scoped_ptr<WebSolidColorLayer> solidColorLayer(WebSolidColorLayer::create())
; | 164 scoped_ptr<WebSolidColorLayer> solidColorLayer(new WebSolidColorLayerImpl); |
| 162 m_rootLayer->addChild(solidColorLayer->layer()); | 165 m_rootLayer->addChild(solidColorLayer->layer()); |
| 163 Mock::VerifyAndClearExpectations(&m_client); | 166 Mock::VerifyAndClearExpectations(&m_client); |
| 164 | 167 |
| 165 } | 168 } |
| 166 | 169 |
| 167 class MockScrollClient : public WebLayerScrollClient { | 170 class MockScrollClient : public WebLayerScrollClient { |
| 168 public: | 171 public: |
| 169 MOCK_METHOD0(didScroll, void()); | 172 MOCK_METHOD0(didScroll, void()); |
| 170 }; | 173 }; |
| 171 | 174 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 182 Mock::VerifyAndClearExpectations(&scrollClient); | 185 Mock::VerifyAndClearExpectations(&scrollClient); |
| 183 | 186 |
| 184 EXPECT_CALL(scrollClient, didScroll()).Times(0); | 187 EXPECT_CALL(scrollClient, didScroll()).Times(0); |
| 185 m_rootLayer->setScrollPosition(WebPoint(14, 19)); | 188 m_rootLayer->setScrollPosition(WebPoint(14, 19)); |
| 186 Mock::VerifyAndClearExpectations(&scrollClient); | 189 Mock::VerifyAndClearExpectations(&scrollClient); |
| 187 | 190 |
| 188 m_rootLayer->setScrollClient(0); | 191 m_rootLayer->setScrollClient(0); |
| 189 } | 192 } |
| 190 | 193 |
| 191 } | 194 } |
| OLD | NEW |