| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include <public/WebLayer.h> | |
| 7 | |
| 8 #include "CompositorFakeWebGraphicsContext3D.h" | |
| 9 #include "WebLayerImpl.h" | |
| 10 #include "WebLayerTreeViewTestCommon.h" | |
| 11 #include <public/WebCompositor.h> | |
| 12 #include <public/WebContentLayer.h> | |
| 13 #include <public/WebContentLayerClient.h> | |
| 14 #include <public/WebExternalTextureLayer.h> | |
| 15 #include <public/WebFloatPoint.h> | |
| 16 #include <public/WebFloatRect.h> | |
| 17 #include <public/WebLayerTreeView.h> | |
| 18 #include <public/WebLayerTreeViewClient.h> | |
| 19 #include <public/WebRect.h> | |
| 20 #include <public/WebSize.h> | |
| 21 | |
| 22 #include <gmock/gmock.h> | |
| 23 | |
| 24 using namespace WebKit; | |
| 25 using testing::AnyNumber; | |
| 26 using testing::AtLeast; | |
| 27 using testing::Mock; | |
| 28 using testing::Test; | |
| 29 using testing::_; | |
| 30 | |
| 31 namespace { | |
| 32 | |
| 33 class MockWebContentLayerClient : public WebContentLayerClient { | |
| 34 public: | |
| 35 MOCK_METHOD3(paintContents, void(WebCanvas*, const WebRect& clip, WebFloatRe
ct& opaque)); | |
| 36 }; | |
| 37 | |
| 38 class WebLayerTest : public Test { | |
| 39 public: | |
| 40 virtual void SetUp() | |
| 41 { | |
| 42 // Initialize without threading support. | |
| 43 WebKit::WebCompositor::initialize(0); | |
| 44 m_rootLayer = adoptPtr(WebLayer::create()); | |
| 45 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | |
| 46 EXPECT_TRUE(m_view = adoptPtr(WebLayerTreeView::create(&m_client, *m_roo
tLayer, WebLayerTreeView::Settings()))); | |
| 47 Mock::VerifyAndClearExpectations(&m_client); | |
| 48 } | |
| 49 | |
| 50 virtual void TearDown() | |
| 51 { | |
| 52 // We may get any number of scheduleComposite calls during shutdown. | |
| 53 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | |
| 54 m_rootLayer.clear(); | |
| 55 m_view.clear(); | |
| 56 WebKit::WebCompositor::shutdown(); | |
| 57 } | |
| 58 | |
| 59 protected: | |
| 60 MockWebLayerTreeViewClient m_client; | |
| 61 OwnPtr<WebLayer> m_rootLayer; | |
| 62 OwnPtr<WebLayerTreeView> m_view; | |
| 63 }; | |
| 64 | |
| 65 // Tests that the client gets called to ask for a composite if we change the | |
| 66 // fields. | |
| 67 TEST_F(WebLayerTest, Client) | |
| 68 { | |
| 69 // Base layer. | |
| 70 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | |
| 71 OwnPtr<WebLayer> layer = adoptPtr(WebLayer::create()); | |
| 72 m_rootLayer->addChild(layer.get()); | |
| 73 Mock::VerifyAndClearExpectations(&m_client); | |
| 74 | |
| 75 WebFloatPoint point(3, 4); | |
| 76 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | |
| 77 layer->setAnchorPoint(point); | |
| 78 Mock::VerifyAndClearExpectations(&m_client); | |
| 79 EXPECT_EQ(point, layer->anchorPoint()); | |
| 80 | |
| 81 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | |
| 82 float anchorZ = 5; | |
| 83 layer->setAnchorPointZ(anchorZ); | |
| 84 Mock::VerifyAndClearExpectations(&m_client); | |
| 85 EXPECT_EQ(anchorZ, layer->anchorPointZ()); | |
| 86 | |
| 87 WebSize size(7, 8); | |
| 88 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | |
| 89 layer->setBounds(size); | |
| 90 Mock::VerifyAndClearExpectations(&m_client); | |
| 91 EXPECT_EQ(size, layer->bounds()); | |
| 92 | |
| 93 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | |
| 94 layer->setMasksToBounds(true); | |
| 95 Mock::VerifyAndClearExpectations(&m_client); | |
| 96 EXPECT_TRUE(layer->masksToBounds()); | |
| 97 | |
| 98 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | |
| 99 OwnPtr<WebLayer> otherLayer = adoptPtr(WebLayer::create()); | |
| 100 m_rootLayer->addChild(otherLayer.get()); | |
| 101 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | |
| 102 layer->setMaskLayer(otherLayer.get()); | |
| 103 Mock::VerifyAndClearExpectations(&m_client); | |
| 104 | |
| 105 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | |
| 106 float opacity = 0.123f; | |
| 107 layer->setOpacity(opacity); | |
| 108 Mock::VerifyAndClearExpectations(&m_client); | |
| 109 EXPECT_EQ(opacity, layer->opacity()); | |
| 110 | |
| 111 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | |
| 112 layer->setOpaque(true); | |
| 113 Mock::VerifyAndClearExpectations(&m_client); | |
| 114 EXPECT_TRUE(layer->opaque()); | |
| 115 | |
| 116 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | |
| 117 layer->setPosition(point); | |
| 118 Mock::VerifyAndClearExpectations(&m_client); | |
| 119 EXPECT_EQ(point, layer->position()); | |
| 120 | |
| 121 // Texture layer. | |
| 122 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | |
| 123 OwnPtr<WebExternalTextureLayer> textureLayer = adoptPtr(WebExternalTextureLa
yer::create()); | |
| 124 m_rootLayer->addChild(textureLayer->layer()); | |
| 125 Mock::VerifyAndClearExpectations(&m_client); | |
| 126 | |
| 127 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | |
| 128 textureLayer->setTextureId(3); | |
| 129 Mock::VerifyAndClearExpectations(&m_client); | |
| 130 | |
| 131 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | |
| 132 textureLayer->setFlipped(true); | |
| 133 Mock::VerifyAndClearExpectations(&m_client); | |
| 134 | |
| 135 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | |
| 136 WebFloatRect uvRect(0.1f, 0.1f, 0.9f, 0.9f); | |
| 137 textureLayer->setUVRect(uvRect); | |
| 138 Mock::VerifyAndClearExpectations(&m_client); | |
| 139 | |
| 140 | |
| 141 // Content layer. | |
| 142 MockWebContentLayerClient contentClient; | |
| 143 EXPECT_CALL(contentClient, paintContents(_, _, _)).Times(AnyNumber()); | |
| 144 EXPECT_CALL(m_client, scheduleComposite()).Times(AnyNumber()); | |
| 145 OwnPtr<WebContentLayer> contentLayer = adoptPtr(WebContentLayer::create(&con
tentClient)); | |
| 146 m_rootLayer->addChild(contentLayer->layer()); | |
| 147 Mock::VerifyAndClearExpectations(&m_client); | |
| 148 | |
| 149 EXPECT_CALL(m_client, scheduleComposite()).Times(AtLeast(1)); | |
| 150 contentLayer->layer()->setDrawsContent(false); | |
| 151 Mock::VerifyAndClearExpectations(&m_client); | |
| 152 EXPECT_FALSE(contentLayer->layer()->drawsContent()); | |
| 153 } | |
| 154 | |
| 155 } | |
| OLD | NEW |