Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / cc / layers / solid_color_scrollbar_layer_impl_unittest.cc
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.
4
5 #include "cc/layers/solid_color_scrollbar_layer_impl.h"
6
7 #include "cc/test/layer_test_common.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace cc {
11 namespace {
12
13 TEST(SolidColorScrollbarLayerImplTest, Occlusion) {
14   gfx::Size layer_size(10, 1000);
15   gfx::Size viewport_size(1000, 1000);
16
17   LayerTestCommon::LayerImplTest impl;
18
19   ScrollbarOrientation orientation = VERTICAL;
20   int thumb_thickness = layer_size.width();
21   int track_start = 0;
22   bool is_left_side_vertical_scrollbar = false;
23   bool is_overlay = false;
24
25   SolidColorScrollbarLayerImpl* scrollbar_layer_impl =
26       impl.AddChildToRoot<SolidColorScrollbarLayerImpl>(
27           orientation,
28           thumb_thickness,
29           track_start,
30           is_left_side_vertical_scrollbar,
31           is_overlay);
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);
41
42   impl.CalcDrawProps(viewport_size);
43
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());
47
48   {
49     SCOPED_TRACE("No occlusion");
50     gfx::Rect occluded;
51     impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded);
52
53     LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), thumb_rect);
54     EXPECT_EQ(1u, impl.quad_list().size());
55   }
56
57   {
58     SCOPED_TRACE("Full occlusion");
59     gfx::Rect occluded(scrollbar_layer_impl->visible_content_rect());
60     impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded);
61
62     LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
63     EXPECT_EQ(impl.quad_list().size(), 0u);
64   }
65
66   {
67     SCOPED_TRACE("Partial occlusion");
68     gfx::Rect occluded(0, 0, 5, 1000);
69     impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded);
70
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);
77   }
78 }
79
80 }  // namespace
81 }  // namespace cc