Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / cc / layers / painted_scrollbar_layer_impl_unittest.cc
blob3fb3fb22bd1a2687dc16598302194fab8e5e99a8
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/painted_scrollbar_layer_impl.h"
7 #include "cc/quads/draw_quad.h"
8 #include "cc/test/layer_test_common.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace cc {
12 namespace {
14 TEST(PaintedScrollbarLayerImplTest, Occlusion) {
15 gfx::Size layer_size(10, 1000);
16 float scale = 2.f;
17 gfx::Size scaled_layer_size(20, 2000);
18 gfx::Size viewport_size(1000, 1000);
20 LayerTestCommon::LayerImplTest impl;
22 SkBitmap thumb_sk_bitmap;
23 thumb_sk_bitmap.allocN32Pixels(10, 10);
24 thumb_sk_bitmap.setImmutable();
25 UIResourceId thumb_uid = 5;
26 UIResourceBitmap thumb_bitmap(thumb_sk_bitmap);
27 impl.host_impl()->CreateUIResource(thumb_uid, thumb_bitmap);
29 SkBitmap track_sk_bitmap;
30 track_sk_bitmap.allocN32Pixels(10, 10);
31 track_sk_bitmap.setImmutable();
32 UIResourceId track_uid = 6;
33 UIResourceBitmap track_bitmap(track_sk_bitmap);
34 impl.host_impl()->CreateUIResource(track_uid, track_bitmap);
36 ScrollbarOrientation orientation = VERTICAL;
38 PaintedScrollbarLayerImpl* scrollbar_layer_impl =
39 impl.AddChildToRoot<PaintedScrollbarLayerImpl>(orientation);
40 scrollbar_layer_impl->SetBounds(layer_size);
41 scrollbar_layer_impl->SetContentBounds(layer_size);
42 scrollbar_layer_impl->SetContentsOpaque(true);
43 scrollbar_layer_impl->set_internal_contents_scale_and_bounds(
44 scale, scaled_layer_size);
45 scrollbar_layer_impl->SetDrawsContent(true);
46 scrollbar_layer_impl->SetThumbThickness(layer_size.width());
47 scrollbar_layer_impl->SetThumbLength(500);
48 scrollbar_layer_impl->SetTrackLength(layer_size.height());
49 scrollbar_layer_impl->SetCurrentPos(100.f / 4);
50 scrollbar_layer_impl->SetMaximum(100);
51 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(1.f / 2);
52 scrollbar_layer_impl->set_track_ui_resource_id(track_uid);
53 scrollbar_layer_impl->set_thumb_ui_resource_id(thumb_uid);
55 impl.CalcDrawProps(viewport_size);
57 gfx::Rect thumb_rect = scrollbar_layer_impl->ComputeThumbQuadRect();
58 EXPECT_EQ(gfx::Rect(0, 500 / 4, 10, layer_size.height() / 2).ToString(),
59 thumb_rect.ToString());
62 SCOPED_TRACE("No occlusion");
63 gfx::Rect occluded;
64 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded);
66 size_t partially_occluded_count = 0;
67 LayerTestCommon::VerifyQuadsAreOccluded(
68 impl.quad_list(), occluded, &partially_occluded_count);
69 EXPECT_EQ(2u, impl.quad_list().size());
70 EXPECT_EQ(0u, partially_occluded_count);
72 // Note: this is also testing that the thumb and track are both
73 // scaled by the internal contents scale. It's not occlusion-related
74 // but is easy to verify here.
75 const DrawQuad* thumb_quad = impl.quad_list().ElementAt(0);
76 const DrawQuad* track_quad = impl.quad_list().ElementAt(1);
78 gfx::Rect scaled_thumb_rect = gfx::ScaleToEnclosingRect(thumb_rect, scale);
79 EXPECT_EQ(track_quad->rect.ToString(),
80 gfx::Rect(scaled_layer_size).ToString());
81 EXPECT_EQ(track_quad->opaque_rect.ToString(),
82 gfx::Rect(scaled_layer_size).ToString());
83 EXPECT_EQ(track_quad->visible_rect.ToString(),
84 gfx::Rect(scaled_layer_size).ToString());
85 EXPECT_EQ(thumb_quad->rect.ToString(), scaled_thumb_rect.ToString());
86 EXPECT_EQ(thumb_quad->visible_rect.ToString(),
87 scaled_thumb_rect.ToString());
91 SCOPED_TRACE("Full occlusion");
92 gfx::Rect occluded(scrollbar_layer_impl->visible_content_rect());
93 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded);
95 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
96 EXPECT_EQ(impl.quad_list().size(), 0u);
100 SCOPED_TRACE("Partial occlusion");
101 gfx::Rect occluded(0, 0, 5, 1000);
102 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded);
104 size_t partially_occluded_count = 0;
105 LayerTestCommon::VerifyQuadsAreOccluded(
106 impl.quad_list(), occluded, &partially_occluded_count);
107 // The layer outputs two quads, which is partially occluded.
108 EXPECT_EQ(2u, impl.quad_list().size());
109 EXPECT_EQ(2u, partially_occluded_count);
113 } // namespace
114 } // namespace cc