1 // Copyright 2014 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 "cc/layers/solid_color_scrollbar_layer_impl.h"
7 #include "cc/test/layer_test_common.h"
8 #include "testing/gtest/include/gtest/gtest.h"
13 TEST(SolidColorScrollbarLayerImplTest, Occlusion) {
14 gfx::Size layer_size(10, 1000);
15 gfx::Size viewport_size(1000, 1000);
17 LayerTestCommon::LayerImplTest impl;
19 ScrollbarOrientation orientation = VERTICAL;
20 int thumb_thickness = layer_size.width();
22 bool is_left_side_vertical_scrollbar = false;
23 bool is_overlay = false;
25 SolidColorScrollbarLayerImpl* scrollbar_layer_impl =
26 impl.AddChildToRoot<SolidColorScrollbarLayerImpl>(
30 is_left_side_vertical_scrollbar,
32 scrollbar_layer_impl->SetAnchorPoint(gfx::PointF());
33 scrollbar_layer_impl->SetBounds(layer_size);
34 scrollbar_layer_impl->SetContentBounds(layer_size);
35 scrollbar_layer_impl->SetDrawsContent(true);
36 scrollbar_layer_impl->SetCurrentPos(100.f / 4);
37 scrollbar_layer_impl->SetMaximum(100);
38 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(1.f / 2);
39 // SolidColorScrollbarLayers construct with opacity = 0.f, so override.
40 scrollbar_layer_impl->SetOpacity(1.f);
42 impl.CalcDrawProps(viewport_size);
44 gfx::Rect thumb_rect = scrollbar_layer_impl->ComputeThumbQuadRect();
45 EXPECT_EQ(gfx::Rect(0, 500 / 4, 10, layer_size.height() / 2).ToString(),
46 thumb_rect.ToString());
49 SCOPED_TRACE("No occlusion");
51 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded);
53 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), thumb_rect);
54 EXPECT_EQ(1u, impl.quad_list().size());
58 SCOPED_TRACE("Full occlusion");
59 gfx::Rect occluded(scrollbar_layer_impl->visible_content_rect());
60 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded);
62 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
63 EXPECT_EQ(impl.quad_list().size(), 0u);
67 SCOPED_TRACE("Partial occlusion");
68 gfx::Rect occluded(0, 0, 5, 1000);
69 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded);
71 size_t partially_occluded_count = 0;
72 LayerTestCommon::VerifyQuadsCoverRectWithOcclusion(
73 impl.quad_list(), thumb_rect, occluded, &partially_occluded_count);
74 // The layer outputs one quad, which is partially occluded.
75 EXPECT_EQ(1u, impl.quad_list().size());
76 EXPECT_EQ(1u, partially_occluded_count);