Remove extra line from unit_tests.isolate
[chromium-blink-merge.git] / cc / ScrollbarLayerChromiumTest.cpp
blob0231e786758cc83f4894614a2b135f7f92c7d224
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.
5 #include "config.h"
7 #include "ScrollbarLayerChromium.h"
9 #include "CCScrollbarAnimationController.h"
10 #include "CCScrollbarLayerImpl.h"
11 #include "CCSingleThreadProxy.h"
12 #include "FakeWebScrollbarThemeGeometry.h"
13 #include "TreeSynchronizer.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include <public/WebScrollbar.h>
16 #include <public/WebScrollbarThemeGeometry.h>
17 #include <public/WebScrollbarThemePainter.h>
19 using namespace cc;
21 namespace {
23 class FakeWebScrollbar : public WebKit::WebScrollbar {
24 public:
25 static PassOwnPtr<FakeWebScrollbar> create() { return adoptPtr(new FakeWebScrollbar()); }
27 // WebScrollbar implementation
28 virtual bool isOverlay() const OVERRIDE { return false; }
29 virtual int value() const OVERRIDE { return 0; }
30 virtual WebKit::WebPoint location() const OVERRIDE { return WebKit::WebPoint(); }
31 virtual WebKit::WebSize size() const OVERRIDE { return WebKit::WebSize(); }
32 virtual bool enabled() const OVERRIDE { return true; }
33 virtual int maximum() const OVERRIDE { return 0; }
34 virtual int totalSize() const OVERRIDE { return 0; }
35 virtual bool isScrollViewScrollbar() const OVERRIDE { return false; }
36 virtual bool isScrollableAreaActive() const OVERRIDE { return true; }
37 virtual void getTickmarks(WebKit::WebVector<WebKit::WebRect>&) const OVERRIDE { }
38 virtual ScrollbarControlSize controlSize() const OVERRIDE { return WebScrollbar::RegularScrollbar; }
39 virtual ScrollbarPart pressedPart() const OVERRIDE { return WebScrollbar::NoPart; }
40 virtual ScrollbarPart hoveredPart() const OVERRIDE { return WebScrollbar::NoPart; }
41 virtual ScrollbarOverlayStyle scrollbarOverlayStyle() const OVERRIDE { return WebScrollbar::ScrollbarOverlayStyleDefault; }
42 virtual bool isCustomScrollbar() const OVERRIDE { return false; }
43 virtual Orientation orientation() const OVERRIDE { return WebScrollbar::Horizontal; }
46 TEST(ScrollbarLayerChromiumTest, resolveScrollLayerPointer)
48 DebugScopedSetImplThread impl;
50 WebKit::WebScrollbarThemePainter painter;
53 OwnPtr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create());
54 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create();
55 scoped_refptr<LayerChromium> child1 = LayerChromium::create();
56 scoped_refptr<LayerChromium> child2 = ScrollbarLayerChromium::create(scrollbar.release(), painter, WebKit::FakeWebScrollbarThemeGeometry::create(), child1->id());
57 layerTreeRoot->addChild(child1);
58 layerTreeRoot->addChild(child2);
60 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), nullptr, 0);
62 CCLayerImpl* ccChild1 = ccLayerTreeRoot->children()[0];
63 CCScrollbarLayerImpl* ccChild2 = static_cast<CCScrollbarLayerImpl*>(ccLayerTreeRoot->children()[1]);
65 EXPECT_TRUE(ccChild1->scrollbarAnimationController());
66 EXPECT_EQ(ccChild1->horizontalScrollbarLayer(), ccChild2);
69 { // another traverse order
70 OwnPtr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create());
71 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create();
72 scoped_refptr<LayerChromium> child2 = LayerChromium::create();
73 scoped_refptr<LayerChromium> child1 = ScrollbarLayerChromium::create(scrollbar.release(), painter, WebKit::FakeWebScrollbarThemeGeometry::create(), child2->id());
74 layerTreeRoot->addChild(child1);
75 layerTreeRoot->addChild(child2);
77 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), nullptr, 0);
79 CCScrollbarLayerImpl* ccChild1 = static_cast<CCScrollbarLayerImpl*>(ccLayerTreeRoot->children()[0]);
80 CCLayerImpl* ccChild2 = ccLayerTreeRoot->children()[1];
82 EXPECT_TRUE(ccChild2->scrollbarAnimationController());
83 EXPECT_EQ(ccChild2->horizontalScrollbarLayer(), ccChild1);
87 TEST(ScrollbarLayerChromiumTest, scrollOffsetSynchronization)
89 DebugScopedSetImplThread impl;
91 WebKit::WebScrollbarThemePainter painter;
93 OwnPtr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create());
94 scoped_refptr<LayerChromium> layerTreeRoot = LayerChromium::create();
95 scoped_refptr<LayerChromium> contentLayer = LayerChromium::create();
96 scoped_refptr<LayerChromium> scrollbarLayer = ScrollbarLayerChromium::create(scrollbar.release(), painter, WebKit::FakeWebScrollbarThemeGeometry::create(), layerTreeRoot->id());
97 layerTreeRoot->addChild(contentLayer);
98 layerTreeRoot->addChild(scrollbarLayer);
100 layerTreeRoot->setScrollPosition(IntPoint(10, 20));
101 layerTreeRoot->setMaxScrollPosition(IntSize(30, 50));
102 contentLayer->setBounds(IntSize(100, 200));
104 OwnPtr<CCLayerImpl> ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), nullptr, 0);
106 CCScrollbarLayerImpl* ccScrollbarLayer = static_cast<CCScrollbarLayerImpl*>(ccLayerTreeRoot->children()[1]);
108 EXPECT_EQ(10, ccScrollbarLayer->currentPos());
109 EXPECT_EQ(100, ccScrollbarLayer->totalSize());
110 EXPECT_EQ(30, ccScrollbarLayer->maximum());
112 layerTreeRoot->setScrollPosition(IntPoint(100, 200));
113 layerTreeRoot->setMaxScrollPosition(IntSize(300, 500));
114 contentLayer->setBounds(IntSize(1000, 2000));
116 CCScrollbarAnimationController* scrollbarController = ccLayerTreeRoot->scrollbarAnimationController();
117 ccLayerTreeRoot = TreeSynchronizer::synchronizeTrees(layerTreeRoot.get(), ccLayerTreeRoot.release(), 0);
118 EXPECT_EQ(scrollbarController, ccLayerTreeRoot->scrollbarAnimationController());
120 EXPECT_EQ(100, ccScrollbarLayer->currentPos());
121 EXPECT_EQ(1000, ccScrollbarLayer->totalSize());
122 EXPECT_EQ(300, ccScrollbarLayer->maximum());
124 ccLayerTreeRoot->scrollBy(FloatSize(12, 34));
126 EXPECT_EQ(112, ccScrollbarLayer->currentPos());
127 EXPECT_EQ(1000, ccScrollbarLayer->totalSize());
128 EXPECT_EQ(300, ccScrollbarLayer->maximum());