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

Side by Side Diff: cc/layers/painted_scrollbar_layer_impl_unittest.cc

Issue 1057283003: Remove parts of //cc we aren't using (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « cc/layers/painted_scrollbar_layer_impl.cc ('k') | cc/layers/picture_image_layer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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/painted_scrollbar_layer_impl.h"
6
7 #include "cc/quads/draw_quad.h"
8 #include "cc/test/layer_test_common.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace cc {
12 namespace {
13
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);
19
20 LayerTestCommon::LayerImplTest impl;
21
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);
28
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);
35
36 ScrollbarOrientation orientation = VERTICAL;
37
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);
54
55 impl.CalcDrawProps(viewport_size);
56
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());
60
61 {
62 SCOPED_TRACE("No occlusion");
63 gfx::Rect occluded;
64 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded);
65
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);
71
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);
77
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());
88 }
89
90 {
91 SCOPED_TRACE("Full occlusion");
92 gfx::Rect occluded(scrollbar_layer_impl->visible_content_rect());
93 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded);
94
95 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
96 EXPECT_EQ(impl.quad_list().size(), 0u);
97 }
98
99 {
100 SCOPED_TRACE("Partial occlusion");
101 gfx::Rect occluded(0, 0, 5, 1000);
102 impl.AppendQuadsWithOcclusion(scrollbar_layer_impl, occluded);
103
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);
110 }
111 }
112
113 } // namespace
114 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/painted_scrollbar_layer_impl.cc ('k') | cc/layers/picture_image_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698