Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4746)

Unified Diff: cc/layers/scrollbar_layer_unittest.cc

Issue 17550008: Make IsSolidColor() a property on CC scrollbar layers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use DCHECK(layer_tree_host()) instead. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/layers/scrollbar_layer_unittest.cc
diff --git a/cc/layers/scrollbar_layer_unittest.cc b/cc/layers/scrollbar_layer_unittest.cc
index aa972940715722fad5aac62cbaf410a12cf4b7cd..1596920c298bac8a80e7bf791dc8caa2f44109d8 100644
--- a/cc/layers/scrollbar_layer_unittest.cc
+++ b/cc/layers/scrollbar_layer_unittest.cc
@@ -29,16 +29,17 @@ namespace cc {
namespace {
scoped_ptr<LayerImpl> LayerImplForScrollAreaAndScrollbar(
+ LayerTreeHost* host,
FakeLayerTreeHostImpl* host_impl,
scoped_ptr<Scrollbar> scrollbar,
- bool reverse_order) {
+ bool reverse_order, bool is_solid_color) {
scoped_refptr<Layer> layer_tree_root = Layer::Create();
scoped_refptr<Layer> child1 = Layer::Create();
scoped_refptr<Layer> child2 =
- ScrollbarLayer::Create(scrollbar.Pass(),
- child1->id());
+ ScrollbarLayer::Create(scrollbar.Pass(), child1->id(), is_solid_color);
layer_tree_root->AddChild(child1);
layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1);
+ layer_tree_root->SetLayerTreeHost(host);
scoped_ptr<LayerImpl> layer_impl =
TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
scoped_ptr<LayerImpl>(),
@@ -47,15 +48,27 @@ scoped_ptr<LayerImpl> LayerImplForScrollAreaAndScrollbar(
return layer_impl.Pass();
}
+class MockLayerTreeHost : public LayerTreeHost {
+ public:
+ MockLayerTreeHost(LayerTreeHostClient* client,
+ const LayerTreeSettings& settings)
+ : LayerTreeHost(client, settings) {
+ Initialize(NULL);
+ }
+};
+
TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) {
FakeImplProxy proxy;
FakeLayerTreeHostImpl host_impl(&proxy);
-
+ FakeLayerTreeHostClient fake_client(FakeLayerTreeHostClient::DIRECT_SOFTWARE);
+ LayerTreeSettings layer_tree_settings;
+ scoped_ptr<MockLayerTreeHost> layer_tree_host(
+ new MockLayerTreeHost(&fake_client, layer_tree_settings));
{
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
scoped_ptr<LayerImpl> layer_impl_tree_root =
LayerImplForScrollAreaAndScrollbar(
- &host_impl, scrollbar.Pass(), false);
+ layer_tree_host.get(), &host_impl, scrollbar.Pass(), false, false);
LayerImpl* cc_child1 = layer_impl_tree_root->children()[0];
ScrollbarLayerImpl* cc_child2 = static_cast<ScrollbarLayerImpl*>(
@@ -68,7 +81,7 @@ TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) {
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
scoped_ptr<LayerImpl> layer_impl_tree_root =
LayerImplForScrollAreaAndScrollbar(
- &host_impl, scrollbar.Pass(), true);
+ layer_tree_host.get(), &host_impl, scrollbar.Pass(), true, false);
ScrollbarLayerImpl* cc_child1 = static_cast<ScrollbarLayerImpl*>(
layer_impl_tree_root->children()[0]);
@@ -81,11 +94,16 @@ TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) {
TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
FakeImplProxy proxy;
FakeLayerTreeHostImpl host_impl(&proxy);
+ FakeLayerTreeHostClient fake_client(FakeLayerTreeHostClient::DIRECT_SOFTWARE);
+ LayerTreeSettings layer_tree_settings;
+ scoped_ptr<MockLayerTreeHost> layer_tree_host(
+ new MockLayerTreeHost(&fake_client, layer_tree_settings));
// Create and attach a non-overlay scrollbar.
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
scoped_ptr<LayerImpl> layer_impl_tree_root =
- LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false);
+ LayerImplForScrollAreaAndScrollbar(
+ layer_tree_host.get(), &host_impl, scrollbar.Pass(), false, false);
ScrollbarLayerImpl* scrollbar_layer_impl =
static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
@@ -99,8 +117,8 @@ TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
// Create and attach an overlay scrollbar.
scrollbar.reset(new FakeScrollbar(false, false, true));
- layer_impl_tree_root =
- LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false);
+ layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
+ layer_tree_host.get(), &host_impl, scrollbar.Pass(), false, false);
scrollbar_layer_impl =
static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
@@ -114,15 +132,19 @@ TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
TEST(ScrollbarLayerTest, ScrollOffsetSynchronization) {
FakeImplProxy proxy;
FakeLayerTreeHostImpl host_impl(&proxy);
+ FakeLayerTreeHostClient fake_client(FakeLayerTreeHostClient::DIRECT_SOFTWARE);
+ LayerTreeSettings layer_tree_settings;
+ scoped_ptr<MockLayerTreeHost> layer_tree_host(
+ new MockLayerTreeHost(&fake_client, layer_tree_settings));
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
scoped_refptr<Layer> layer_tree_root = Layer::Create();
scoped_refptr<Layer> content_layer = Layer::Create();
scoped_refptr<Layer> scrollbar_layer =
- ScrollbarLayer::Create(scrollbar.Pass(),
- layer_tree_root->id());
+ ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id(), false);
layer_tree_root->AddChild(content_layer);
layer_tree_root->AddChild(scrollbar_layer);
+ layer_tree_root->SetLayerTreeHost(layer_tree_host.get());
layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20));
layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50));
@@ -171,18 +193,41 @@ TEST(ScrollbarLayerTest, ScrollOffsetSynchronization) {
EXPECT_EQ(300, cc_scrollbar_layer->Maximum());
}
-TEST(ScrollbarLayerTest, SolidColorDrawQuads) {
+class SolidScrollbarLayerQuadTest
+ : public ::testing::TestWithParam<bool> {
+ public:
+ SolidScrollbarLayerQuadTest()
+ : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {
+ layer_tree_settings.force_solid_color_scrollbars = GetParam();
+ layer_tree_settings.solid_color_scrollbar_thickness_dip = 3;
+ layer_tree_host_.reset(
+ new MockLayerTreeHost(&fake_client_, layer_tree_settings));
+
+ host_impl =
+ make_scoped_ptr(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy));
+ scrollbar = make_scoped_ptr(new FakeScrollbar(false, true, true));
+ layer_impl_tree_root =
+ LayerImplForScrollAreaAndScrollbar(layer_tree_host_.get(),
+ host_impl.get(),
+ scrollbar.Pass(),
+ false,
+ !GetParam());
+ scrollbar_layer_impl =
+ static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
+ }
+
+ protected:
LayerTreeSettings layer_tree_settings;
- layer_tree_settings.solid_color_scrollbars = true;
- layer_tree_settings.solid_color_scrollbar_thickness_dip = 3;
FakeImplProxy proxy;
- FakeLayerTreeHostImpl host_impl(layer_tree_settings, &proxy);
+ scoped_ptr<FakeLayerTreeHostImpl> host_impl;
+ scoped_ptr<Scrollbar> scrollbar;
+ scoped_ptr<LayerImpl> layer_impl_tree_root;
+ ScrollbarLayerImpl* scrollbar_layer_impl;
+ FakeLayerTreeHostClient fake_client_;
+ scoped_ptr<MockLayerTreeHost> layer_tree_host_;
+};
- scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
- scoped_ptr<LayerImpl> layer_impl_tree_root =
- LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false);
- ScrollbarLayerImpl* scrollbar_layer_impl =
- static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
+TEST_P(SolidScrollbarLayerQuadTest, DrawQuads) {
scrollbar_layer_impl->set_thumb_thickness(3);
scrollbar_layer_impl->SetCurrentPos(10.f);
scrollbar_layer_impl->SetMaximum(100);
@@ -232,19 +277,7 @@ TEST(ScrollbarLayerTest, SolidColorDrawQuads) {
}
}
-TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) {
- LayerTreeSettings layer_tree_settings;
- layer_tree_settings.solid_color_scrollbars = true;
- layer_tree_settings.solid_color_scrollbar_thickness_dip = 3;
- FakeImplProxy proxy;
- FakeLayerTreeHostImpl host_impl(layer_tree_settings, &proxy);
-
- scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
- scoped_ptr<LayerImpl> layer_impl_tree_root =
- LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false);
- ScrollbarLayerImpl* scrollbar_layer_impl =
- static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
-
+TEST_P(SolidScrollbarLayerQuadTest, LayerDrivenSolidColorDrawQuads) {
scrollbar_layer_impl->set_thumb_thickness(3);
scrollbar_layer_impl->set_track_length(10);
scrollbar_layer_impl->SetCurrentPos(4.f);
@@ -267,17 +300,21 @@ TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) {
}
}
-class ScrollbarLayerSolidColorThumbTest : public testing::Test {
+INSTANTIATE_TEST_CASE_P(ParameterizedSolidColorScrollbarTest,
+ SolidScrollbarLayerQuadTest,
+ ::testing::Values(true, false));
+
+class ScrollbarLayerSolidColorThumbTest : public testing::TestWithParam<bool> {
public:
ScrollbarLayerSolidColorThumbTest() {
LayerTreeSettings layer_tree_settings;
- layer_tree_settings.solid_color_scrollbars = true;
+ layer_tree_settings.force_solid_color_scrollbars = GetParam();
host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_));
horizontal_scrollbar_layer_ = ScrollbarLayerImpl::Create(
- host_impl_->active_tree(), 1, HORIZONTAL);
+ host_impl_->active_tree(), 1, HORIZONTAL, true);
vertical_scrollbar_layer_ = ScrollbarLayerImpl::Create(
- host_impl_->active_tree(), 2, VERTICAL);
+ host_impl_->active_tree(), 2, VERTICAL, true);
}
protected:
@@ -287,7 +324,7 @@ class ScrollbarLayerSolidColorThumbTest : public testing::Test {
scoped_ptr<ScrollbarLayerImpl> vertical_scrollbar_layer_;
};
-TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) {
+TEST_P(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) {
horizontal_scrollbar_layer_->SetCurrentPos(0);
horizontal_scrollbar_layer_->SetMaximum(10);
horizontal_scrollbar_layer_->set_thumb_thickness(3);
@@ -304,7 +341,7 @@ TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) {
EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width());
}
-TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) {
+TEST_P(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) {
horizontal_scrollbar_layer_->set_track_length(100);
horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.1f);
horizontal_scrollbar_layer_->set_thumb_thickness(3);
@@ -325,7 +362,7 @@ TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) {
EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x());
}
-TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) {
+TEST_P(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) {
ScrollbarLayerImpl* layers[2] =
{ horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() };
for (size_t i = 0; i < 2; ++i) {
@@ -354,6 +391,10 @@ TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) {
vertical_scrollbar_layer_->ComputeThumbQuadRect());
}
+INSTANTIATE_TEST_CASE_P(ParameterizedSolidColorThumbTest,
+ ScrollbarLayerSolidColorThumbTest,
+ ::testing::Values(true, false));
+
class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest {
public:
ScrollbarLayerTestMaxTextureSize() {}
@@ -362,7 +403,7 @@ class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest {
virtual void BeginTest() OVERRIDE {
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
- scrollbar_layer_ = ScrollbarLayer::Create(scrollbar.Pass(), 1);
+ scrollbar_layer_ = ScrollbarLayer::Create(scrollbar.Pass(), 1, false);
scrollbar_layer_->SetLayerTreeHost(layer_tree_host());
scrollbar_layer_->SetBounds(bounds_);
layer_tree_host()->root_layer()->AddChild(scrollbar_layer_);
@@ -415,16 +456,6 @@ TEST_F(ScrollbarLayerTestMaxTextureSize, DelegatingRenderer) {
RunTest(true, true, true);
}
-class MockLayerTreeHost : public LayerTreeHost {
- public:
- MockLayerTreeHost(LayerTreeHostClient* client,
- const LayerTreeSettings& settings)
- : LayerTreeHost(client, settings) {
- Initialize(NULL);
- }
-};
-
-
class ScrollbarLayerTestResourceCreation : public testing::Test {
public:
ScrollbarLayerTestResourceCreation()
@@ -438,7 +469,7 @@ class ScrollbarLayerTestResourceCreation : public testing::Test {
scoped_refptr<Layer> layer_tree_root = Layer::Create();
scoped_refptr<Layer> content_layer = Layer::Create();
scoped_refptr<Layer> scrollbar_layer =
- ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id());
+ ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id(), false);
layer_tree_root->AddChild(content_layer);
layer_tree_root->AddChild(scrollbar_layer);
@@ -482,12 +513,12 @@ class ScrollbarLayerTestResourceCreation : public testing::Test {
};
TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) {
- layer_tree_settings_.solid_color_scrollbars = false;
+ layer_tree_settings_.force_solid_color_scrollbars = false;
TestResourceUpload(2);
}
TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) {
- layer_tree_settings_.solid_color_scrollbars = true;
+ layer_tree_settings_.force_solid_color_scrollbars = true;
TestResourceUpload(0);
}
@@ -506,9 +537,8 @@ class ScaledScrollbarLayerTestResourceCreation : public testing::Test {
scoped_refptr<Layer> layer_tree_root = Layer::Create();
scoped_refptr<Layer> content_layer = Layer::Create();
- scoped_refptr<Layer> scrollbar_layer =
- ScrollbarLayer::Create(scrollbar.PassAs<cc::Scrollbar>(),
- layer_tree_root->id());
+ scoped_refptr<Layer> scrollbar_layer = ScrollbarLayer::Create(
+ scrollbar.PassAs<cc::Scrollbar>(), layer_tree_root->id(), false);
layer_tree_root->AddChild(content_layer);
layer_tree_root->AddChild(scrollbar_layer);
@@ -575,7 +605,7 @@ class ScaledScrollbarLayerTestResourceCreation : public testing::Test {
};
TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) {
- layer_tree_settings_.solid_color_scrollbars = false;
+ layer_tree_settings_.force_solid_color_scrollbars = false;
// Pick a test scale that moves the scrollbar's (non-zero) position to
// a non-pixel-aligned location.
TestResourceUpload(2, 1.41f);

Powered by Google App Engine
This is Rietveld 408576698