[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 1 | // 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] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 5 | #include "cc/scrollbar_layer.h" |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 6 | |
[email protected] | c4040a52 | 2012-10-21 15:01:40 | [diff] [blame] | 7 | #include "cc/scrollbar_animation_controller.h" |
| 8 | #include "cc/scrollbar_layer_impl.h" |
[email protected] | 4456eee2 | 2012-10-19 18:16:38 | [diff] [blame] | 9 | #include "cc/single_thread_proxy.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 10 | #include "cc/test/fake_impl_proxy.h" |
| 11 | #include "cc/test/fake_layer_tree_host_impl.h" |
[email protected] | 1c7008ac | 2012-12-18 07:54:17 | [diff] [blame] | 12 | #include "cc/test/fake_scrollbar_theme_painter.h" |
[email protected] | 501a770 | 2012-12-19 05:25:05 | [diff] [blame^] | 13 | #include "cc/test/fake_web_graphics_context_3d.h" |
[email protected] | 1c7008ac | 2012-12-18 07:54:17 | [diff] [blame] | 14 | #include "cc/test/fake_web_scrollbar.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 15 | #include "cc/test/fake_web_scrollbar_theme_geometry.h" |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 16 | #include "cc/test/layer_tree_test_common.h" |
[email protected] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 17 | #include "cc/tree_synchronizer.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 18 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 920caa5 | 2012-12-18 22:39:50 | [diff] [blame] | 19 | #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h" |
[email protected] | 1c7008ac | 2012-12-18 07:54:17 | [diff] [blame] | 20 | #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbarThemeGeometry.h" |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 21 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 22 | namespace cc { |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 23 | namespace { |
| 24 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 25 | TEST(ScrollbarLayerTest, resolveScrollLayerPointer) |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 26 | { |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 27 | FakeImplProxy proxy; |
| 28 | FakeLayerTreeHostImpl hostImpl(&proxy); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 29 | |
| 30 | { |
[email protected] | 3116158 | 2012-10-16 21:08:03 | [diff] [blame] | 31 | scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 32 | scoped_refptr<Layer> layerTreeRoot = Layer::create(); |
| 33 | scoped_refptr<Layer> child1 = Layer::create(); |
[email protected] | 1c7008ac | 2012-12-18 07:54:17 | [diff] [blame] | 34 | scoped_refptr<Layer> child2 = ScrollbarLayer::create(scrollbar.Pass(), FakeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWebScrollbarThemeGeometry::create(), child1->id()); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 35 | layerTreeRoot->addChild(child1); |
| 36 | layerTreeRoot->addChild(child2); |
| 37 | |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 38 | scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.activeTree()); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 39 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 40 | LayerImpl* ccChild1 = layerImplTreeRoot->children()[0]; |
| 41 | ScrollbarLayerImpl* ccChild2 = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[1]); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 42 | |
| 43 | EXPECT_TRUE(ccChild1->scrollbarAnimationController()); |
| 44 | EXPECT_EQ(ccChild1->horizontalScrollbarLayer(), ccChild2); |
| 45 | } |
| 46 | |
| 47 | { // another traverse order |
[email protected] | 3116158 | 2012-10-16 21:08:03 | [diff] [blame] | 48 | scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 49 | scoped_refptr<Layer> layerTreeRoot = Layer::create(); |
| 50 | scoped_refptr<Layer> child2 = Layer::create(); |
[email protected] | 1c7008ac | 2012-12-18 07:54:17 | [diff] [blame] | 51 | scoped_refptr<Layer> child1 = ScrollbarLayer::create(scrollbar.Pass(), FakeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWebScrollbarThemeGeometry::create(), child2->id()); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 52 | layerTreeRoot->addChild(child1); |
| 53 | layerTreeRoot->addChild(child2); |
| 54 | |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 55 | scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.activeTree()); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 56 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 57 | ScrollbarLayerImpl* ccChild1 = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[0]); |
| 58 | LayerImpl* ccChild2 = layerImplTreeRoot->children()[1]; |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 59 | |
| 60 | EXPECT_TRUE(ccChild2->scrollbarAnimationController()); |
| 61 | EXPECT_EQ(ccChild2->horizontalScrollbarLayer(), ccChild1); |
| 62 | } |
| 63 | } |
| 64 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 65 | TEST(ScrollbarLayerTest, scrollOffsetSynchronization) |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 66 | { |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 67 | FakeImplProxy proxy; |
| 68 | FakeLayerTreeHostImpl hostImpl(&proxy); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 69 | |
[email protected] | 3116158 | 2012-10-16 21:08:03 | [diff] [blame] | 70 | scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 71 | scoped_refptr<Layer> layerTreeRoot = Layer::create(); |
| 72 | scoped_refptr<Layer> contentLayer = Layer::create(); |
[email protected] | 1c7008ac | 2012-12-18 07:54:17 | [diff] [blame] | 73 | scoped_refptr<Layer> scrollbarLayer = ScrollbarLayer::create(scrollbar.Pass(), FakeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWebScrollbarThemeGeometry::create(), layerTreeRoot->id()); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 74 | layerTreeRoot->addChild(contentLayer); |
| 75 | layerTreeRoot->addChild(scrollbarLayer); |
| 76 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 77 | layerTreeRoot->setScrollOffset(gfx::Vector2d(10, 20)); |
| 78 | layerTreeRoot->setMaxScrollOffset(gfx::Vector2d(30, 50)); |
| 79 | contentLayer->setBounds(gfx::Size(100, 200)); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 80 | |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 81 | scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), scoped_ptr<LayerImpl>(), hostImpl.activeTree()); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 82 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 83 | ScrollbarLayerImpl* ccScrollbarLayer = static_cast<ScrollbarLayerImpl*>(layerImplTreeRoot->children()[1]); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 84 | |
| 85 | EXPECT_EQ(10, ccScrollbarLayer->currentPos()); |
| 86 | EXPECT_EQ(100, ccScrollbarLayer->totalSize()); |
| 87 | EXPECT_EQ(30, ccScrollbarLayer->maximum()); |
| 88 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 89 | layerTreeRoot->setScrollOffset(gfx::Vector2d(100, 200)); |
| 90 | layerTreeRoot->setMaxScrollOffset(gfx::Vector2d(300, 500)); |
| 91 | contentLayer->setBounds(gfx::Size(1000, 2000)); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 92 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 93 | ScrollbarAnimationController* scrollbarController = layerImplTreeRoot->scrollbarAnimationController(); |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 94 | layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), layerImplTreeRoot.Pass(), hostImpl.activeTree()); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 95 | EXPECT_EQ(scrollbarController, layerImplTreeRoot->scrollbarAnimationController()); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 96 | |
| 97 | EXPECT_EQ(100, ccScrollbarLayer->currentPos()); |
| 98 | EXPECT_EQ(1000, ccScrollbarLayer->totalSize()); |
| 99 | EXPECT_EQ(300, ccScrollbarLayer->maximum()); |
| 100 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 101 | layerImplTreeRoot->scrollBy(gfx::Vector2d(12, 34)); |
[email protected] | 8958360 | 2012-09-18 21:51:41 | [diff] [blame] | 102 | |
| 103 | EXPECT_EQ(112, ccScrollbarLayer->currentPos()); |
| 104 | EXPECT_EQ(1000, ccScrollbarLayer->totalSize()); |
| 105 | EXPECT_EQ(300, ccScrollbarLayer->maximum()); |
| 106 | } |
| 107 | |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 108 | class ScrollbarLayerTestMaxTextureSize : public ThreadedTest { |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 109 | public: |
| 110 | ScrollbarLayerTestMaxTextureSize() {} |
| 111 | |
| 112 | void setScrollbarBounds(gfx::Size bounds) { |
| 113 | m_bounds = bounds; |
| 114 | } |
| 115 | |
| 116 | virtual void beginTest() OVERRIDE |
| 117 | { |
[email protected] | 344e58d0 | 2012-12-16 04:52:53 | [diff] [blame] | 118 | m_layerTreeHost->initializeRendererIfNeeded(); |
| 119 | |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 120 | scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); |
[email protected] | 1c7008ac | 2012-12-18 07:54:17 | [diff] [blame] | 121 | m_scrollbarLayer = ScrollbarLayer::create(scrollbar.Pass(), FakeScrollbarThemePainter::Create(false).PassAs<ScrollbarThemePainter>(), FakeWebScrollbarThemeGeometry::create(), 1); |
[email protected] | 344e58d0 | 2012-12-16 04:52:53 | [diff] [blame] | 122 | m_scrollbarLayer->setLayerTreeHost(m_layerTreeHost.get()); |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 123 | 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] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 135 | 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 | |
| 150 | private: |
| 151 | scoped_refptr<ScrollbarLayer> m_scrollbarLayer; |
| 152 | scoped_refptr<Layer> m_scrollLayer; |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 153 | gfx::Size m_bounds; |
| 154 | }; |
| 155 | |
| 156 | TEST_F(ScrollbarLayerTestMaxTextureSize, runTest) { |
[email protected] | 501a770 | 2012-12-19 05:25:05 | [diff] [blame^] | 157 | scoped_ptr<FakeWebGraphicsContext3D> context = FakeWebGraphicsContext3D::create(); |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 158 | int max_size = 0; |
[email protected] | 501a770 | 2012-12-19 05:25:05 | [diff] [blame^] | 159 | context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); |
[email protected] | 9281fc0 | 2012-11-28 06:34:44 | [diff] [blame] | 160 | setScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); |
| 161 | runTest(true); |
| 162 | } |
| 163 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 164 | } // namespace |
| 165 | } // namespace cc |