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

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

Issue 1458703010: Mac: Don't repaint scrollbars every frame (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master2
Patch Set: Add missed file in rebase Created 5 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright 2015 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.h"
6
7 #include "cc/layers/layer_settings.h"
8 #include "cc/test/fake_layer_tree_host.h"
9 #include "cc/test/fake_layer_tree_host_client.h"
10 #include "cc/test/fake_scrollbar.h"
11 #include "cc/test/test_task_graph_runner.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13
14 using ::testing::Mock;
15 using ::testing::_;
16
17 namespace cc {
18
19 namespace {
20
21 class MockScrollbar : public FakeScrollbar {
22 public:
23 MockScrollbar() : FakeScrollbar(true, true, true) {}
24 MOCK_METHOD3(PaintPart,
25 void(SkCanvas* canvas,
26 ScrollbarPart part,
27 const gfx::Rect& content_rect));
28 };
29
30 TEST(PaintedScrollbarLayerTest, NeedsPaint) {
31 FakeLayerTreeHostClient fake_client_(FakeLayerTreeHostClient::DIRECT_3D);
32 TestTaskGraphRunner task_graph_runner_;
33 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
34 LayerSettings layer_settings_;
35
36 layer_tree_host_ =
37 FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_);
38 RendererCapabilities renderer_capabilities;
39 renderer_capabilities.max_texture_size = 2048;
40 layer_tree_host_->set_renderer_capabilities(renderer_capabilities);
41
42 MockScrollbar* scrollbar = new MockScrollbar();
43 scoped_refptr<PaintedScrollbarLayer> scrollbar_layer =
44 PaintedScrollbarLayer::Create(layer_settings_,
45 scoped_ptr<Scrollbar>(scrollbar).Pass(), 1);
46
47 scrollbar_layer->SetIsDrawable(true);
48 scrollbar_layer->SetBounds(gfx::Size(100, 100));
49
50 layer_tree_host_->SetRootLayer(scrollbar_layer);
51 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
52 scrollbar_layer->SavePaintProperties();
53
54 // Request no paint, but expect them to be painted because they have not
55 // yet bee initialized.
enne (OOO) 2015/11/24 17:59:18 typo
ccameron 2015/11/24 18:48:19 Oops -- fixed.
56 scrollbar->set_needs_paint_thumb(false);
57 scrollbar->set_needs_paint_track(false);
58 EXPECT_CALL(*scrollbar, PaintPart(_, THUMB, _)).Times(1);
59 EXPECT_CALL(*scrollbar, PaintPart(_, TRACK, _)).Times(1);
60 scrollbar_layer->Update();
61 Mock::VerifyAndClearExpectations(scrollbar);
62
63 // The next update will paint nothing because the first update caused a paint.
64 EXPECT_CALL(*scrollbar, PaintPart(_, THUMB, _)).Times(0);
65 EXPECT_CALL(*scrollbar, PaintPart(_, TRACK, _)).Times(0);
66 scrollbar_layer->Update();
67 Mock::VerifyAndClearExpectations(scrollbar);
68
69 // Enable the thumb.
70 EXPECT_CALL(*scrollbar, PaintPart(_, THUMB, _)).Times(1);
71 EXPECT_CALL(*scrollbar, PaintPart(_, TRACK, _)).Times(0);
72 scrollbar->set_needs_paint_thumb(true);
73 scrollbar->set_needs_paint_track(false);
74 scrollbar_layer->Update();
75 Mock::VerifyAndClearExpectations(scrollbar);
76
77 // Enable the track.
78 EXPECT_CALL(*scrollbar, PaintPart(_, THUMB, _)).Times(0);
79 EXPECT_CALL(*scrollbar, PaintPart(_, TRACK, _)).Times(1);
80 scrollbar->set_needs_paint_thumb(false);
81 scrollbar->set_needs_paint_track(true);
82 scrollbar_layer->Update();
83 Mock::VerifyAndClearExpectations(scrollbar);
84 }
85
86 } // namespace
87 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698