blob: cd15e90ceb6e5b22254de5f725d01eb3ba8bb4ef [file] [log] [blame]
[email protected]89583602012-09-18 21:51:411// Copyright 2012 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
[email protected]a8461d82012-10-16 21:11:145#include "cc/scrollbar_layer.h"
[email protected]89583602012-09-18 21:51:416
[email protected]c4040a522012-10-21 15:01:407#include "cc/scrollbar_animation_controller.h"
8#include "cc/scrollbar_layer_impl.h"
[email protected]4456eee22012-10-19 18:16:389#include "cc/single_thread_proxy.h"
[email protected]586d51ed2012-12-07 20:31:4510#include "cc/test/fake_impl_proxy.h"
11#include "cc/test/fake_layer_tree_host_impl.h"
[email protected]1c7008ac2012-12-18 07:54:1712#include "cc/test/fake_scrollbar_theme_painter.h"
[email protected]501a7702012-12-19 05:25:0513#include "cc/test/fake_web_graphics_context_3d.h"
[email protected]1c7008ac2012-12-18 07:54:1714#include "cc/test/fake_web_scrollbar.h"
[email protected]101441ce2012-10-16 01:45:0315#include "cc/test/fake_web_scrollbar_theme_geometry.h"
[email protected]9281fc02012-11-28 06:34:4416#include "cc/test/layer_tree_test_common.h"
[email protected]a8461d82012-10-16 21:11:1417#include "cc/tree_synchronizer.h"
[email protected]7f0c53db2012-10-02 00:23:1818#include "testing/gtest/include/gtest/gtest.h"
[email protected]920caa52012-12-18 22:39:5019#include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h"
[email protected]1c7008ac2012-12-18 07:54:1720#include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbarThemeGeometry.h"
[email protected]89583602012-09-18 21:51:4121
[email protected]ba565742012-11-10 09:29:4822namespace cc {
[email protected]89583602012-09-18 21:51:4123namespace {
24
[email protected]96baf3e2012-10-22 23:09:5525TEST(ScrollbarLayerTest, resolveScrollLayerPointer)
[email protected]89583602012-09-18 21:51:4126{
[email protected]586d51ed2012-12-07 20:31:4527 FakeImplProxy proxy;
28 FakeLayerTreeHostImpl hostImpl(&proxy);
[email protected]89583602012-09-18 21:51:4129
30 {
[email protected]31161582012-10-16 21:08:0331 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create());
[email protected]96baf3e2012-10-22 23:09:5532 scoped_refptr<Layer> layerTreeRoot = Layer::create();
33 scoped_refptr<Layer> child1 = Layer::create();
[email protected]1c7008ac2012-12-18 07:54:1734 scoped_refptr<Layer> child2 = ScrollbarLayer::create(scrollbar.Pass(), FakeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWebScrollbarThemeGeometry::create(), child1->id());
[email protected]89583602012-09-18 21:51:4135 layerTreeRoot->addChild(child1);
36 layerTreeRoot->addChild(child2);
37
[email protected]8bef40572012-12-11 21:38:0838 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.activeTree());
[email protected]89583602012-09-18 21:51:4139
[email protected]96baf3e2012-10-22 23:09:5540 LayerImpl* ccChild1 = layerImplTreeRoot->children()[0];
41 ScrollbarLayerImpl* ccChild2 = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[1]);
[email protected]89583602012-09-18 21:51:4142
43 EXPECT_TRUE(ccChild1->scrollbarAnimationController());
44 EXPECT_EQ(ccChild1->horizontalScrollbarLayer(), ccChild2);
45 }
46
47 { // another traverse order
[email protected]31161582012-10-16 21:08:0348 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create());
[email protected]96baf3e2012-10-22 23:09:5549 scoped_refptr<Layer> layerTreeRoot = Layer::create();
50 scoped_refptr<Layer> child2 = Layer::create();
[email protected]1c7008ac2012-12-18 07:54:1751 scoped_refptr<Layer> child1 = ScrollbarLayer::create(scrollbar.Pass(), FakeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWebScrollbarThemeGeometry::create(), child2->id());
[email protected]89583602012-09-18 21:51:4152 layerTreeRoot->addChild(child1);
53 layerTreeRoot->addChild(child2);
54
[email protected]8bef40572012-12-11 21:38:0855 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.activeTree());
[email protected]89583602012-09-18 21:51:4156
[email protected]96baf3e2012-10-22 23:09:5557 ScrollbarLayerImpl* ccChild1 = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[0]);
58 LayerImpl* ccChild2 = layerImplTreeRoot->children()[1];
[email protected]89583602012-09-18 21:51:4159
60 EXPECT_TRUE(ccChild2->scrollbarAnimationController());
61 EXPECT_EQ(ccChild2->horizontalScrollbarLayer(), ccChild1);
62 }
63}
64
[email protected]96baf3e2012-10-22 23:09:5565TEST(ScrollbarLayerTest, scrollOffsetSynchronization)
[email protected]89583602012-09-18 21:51:4166{
[email protected]586d51ed2012-12-07 20:31:4567 FakeImplProxy proxy;
68 FakeLayerTreeHostImpl hostImpl(&proxy);
[email protected]89583602012-09-18 21:51:4169
[email protected]31161582012-10-16 21:08:0370 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create());
[email protected]96baf3e2012-10-22 23:09:5571 scoped_refptr<Layer> layerTreeRoot = Layer::create();
72 scoped_refptr<Layer> contentLayer = Layer::create();
[email protected]1c7008ac2012-12-18 07:54:1773 scoped_refptr<Layer> scrollbarLayer = ScrollbarLayer::create(scrollbar.Pass(), FakeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWebScrollbarThemeGeometry::create(), layerTreeRoot->id());
[email protected]89583602012-09-18 21:51:4174 layerTreeRoot->addChild(contentLayer);
75 layerTreeRoot->addChild(scrollbarLayer);
76
[email protected]c9c1ebe2012-11-05 20:46:1377 layerTreeRoot->setScrollOffset(gfx::Vector2d(10, 20));
78 layerTreeRoot->setMaxScrollOffset(gfx::Vector2d(30, 50));
79 contentLayer->setBounds(gfx::Size(100, 200));
[email protected]89583602012-09-18 21:51:4180
[email protected]8bef40572012-12-11 21:38:0881 scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.activeTree());
[email protected]89583602012-09-18 21:51:4182
[email protected]96baf3e2012-10-22 23:09:5583 ScrollbarLayerImpl* ccScrollbarLayer = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[1]);
[email protected]89583602012-09-18 21:51:4184
85 EXPECT_EQ(10, ccScrollbarLayer->currentPos());
86 EXPECT_EQ(100, ccScrollbarLayer->totalSize());
87 EXPECT_EQ(30, ccScrollbarLayer->maximum());
88
[email protected]c9c1ebe2012-11-05 20:46:1389 layerTreeRoot->setScrollOffset(gfx::Vector2d(100, 200));
90 layerTreeRoot->setMaxScrollOffset(gfx::Vector2d(300, 500));
91 contentLayer->setBounds(gfx::Size(1000, 2000));
[email protected]89583602012-09-18 21:51:4192
[email protected]96baf3e2012-10-22 23:09:5593 ScrollbarAnimationController* scrollbarController = layerImplTreeRoot->scrollbarAnimationController();
[email protected]8bef40572012-12-11 21:38:0894 layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.activeTree());
[email protected]96baf3e2012-10-22 23:09:5595 EXPECT_EQ(scrollbarController, layerImplTreeRoot->scrollbarAnimationController());
[email protected]89583602012-09-18 21:51:4196
97 EXPECT_EQ(100, ccScrollbarLayer->currentPos());
98 EXPECT_EQ(1000, ccScrollbarLayer->totalSize());
99 EXPECT_EQ(300, ccScrollbarLayer->maximum());
100
[email protected]c9c1ebe2012-11-05 20:46:13101 layerImplTreeRoot->scrollBy(gfx::Vector2d(12, 34));
[email protected]89583602012-09-18 21:51:41102
103 EXPECT_EQ(112, ccScrollbarLayer->currentPos());
104 EXPECT_EQ(1000, ccScrollbarLayer->totalSize());
105 EXPECT_EQ(300, ccScrollbarLayer->maximum());
106}
107
[email protected]a46f32932012-12-07 21:43:16108class ScrollbarLayerTestMaxTextureSize : public ThreadedTest {
[email protected]9281fc02012-11-28 06:34:44109public:
110 ScrollbarLayerTestMaxTextureSize() {}
111
112 void setScrollbarBounds(gfx::Size bounds) {
113 m_bounds = bounds;
114 }
115
116 virtual void beginTest() OVERRIDE
117 {
[email protected]344e58d02012-12-16 04:52:53118 m_layerTreeHost->initializeRendererIfNeeded();
119
[email protected]9281fc02012-11-28 06:34:44120 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create());
[email protected]1c7008ac2012-12-18 07:54:17121 m_scrollbarLayer = ScrollbarLayer::create(scrollbar.Pass(), FakeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWebScrollbarThemeGeometry::create(), 1);
[email protected]344e58d02012-12-16 04:52:53122 m_scrollbarLayer->setLayerTreeHost(m_layerTreeHost.get());
[email protected]9281fc02012-11-28 06:34:44123 m_scrollbarLayer->setBounds(m_bounds);
124 m_layerTreeHost->rootLayer()->addChild(m_scrollbarLayer);
125
126 m_scrollLayer = Layer::create();
127 m_scrollbarLayer->setScrollLayerId(m_scrollLayer->id());
128 m_layerTreeHost->rootLayer()->addChild(m_scrollLayer);
129
130 postSetNeedsCommitToMainThread();
131 }
132
133 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE
134 {
[email protected]9281fc02012-11-28 06:34:44135 const int kMaxTextureSize = m_layerTreeHost->rendererCapabilities().maxTextureSize;
136
137 // Check first that we're actually testing something.
138 EXPECT_GT(m_scrollbarLayer->bounds().width(), kMaxTextureSize);
139
140 EXPECT_EQ(m_scrollbarLayer->contentBounds().width(), kMaxTextureSize - 1);
141 EXPECT_EQ(m_scrollbarLayer->contentBounds().height(), kMaxTextureSize - 1);
142
143 endTest();
144 }
145
146 virtual void afterTest() OVERRIDE
147 {
148 }
149
150private:
151 scoped_refptr<ScrollbarLayer> m_scrollbarLayer;
152 scoped_refptr<Layer> m_scrollLayer;
[email protected]9281fc02012-11-28 06:34:44153 gfx::Size m_bounds;
154};
155
156TEST_F(ScrollbarLayerTestMaxTextureSize, runTest) {
[email protected]501a7702012-12-19 05:25:05157 scoped_ptr<FakeWebGraphicsContext3D> context = FakeWebGraphicsContext3D::create();
[email protected]9281fc02012-11-28 06:34:44158 int max_size = 0;
[email protected]501a7702012-12-19 05:25:05159 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size);
[email protected]9281fc02012-11-28 06:34:44160 setScrollbarBounds(gfx::Size(max_size + 100, max_size + 100));
161 runTest(true);
162}
163
[email protected]ba565742012-11-10 09:29:48164} // namespace
165} // namespace cc