blob: b43c7379e78537dd7772c3442ccea22d9f8b19df [file] [log] [blame]
ccamerona54da382015-11-27 00:52:331// 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
ccamerona54da382015-11-27 00:52:337#include "cc/test/fake_layer_tree_host.h"
8#include "cc/test/fake_layer_tree_host_client.h"
9#include "cc/test/fake_scrollbar.h"
10#include "cc/test/test_task_graph_runner.h"
11#include "testing/gmock/include/gmock/gmock.h"
12
13using ::testing::Mock;
14using ::testing::_;
15
16namespace cc {
17
18namespace {
19
20class MockScrollbar : public FakeScrollbar {
21 public:
22 MockScrollbar() : FakeScrollbar(true, true, true) {}
23 MOCK_METHOD3(PaintPart,
24 void(SkCanvas* canvas,
25 ScrollbarPart part,
26 const gfx::Rect& content_rect));
27};
28
29TEST(PaintedScrollbarLayerTest, NeedsPaint) {
danakj6021ec32016-07-22 22:16:0830 FakeLayerTreeHostClient fake_client_;
ccamerona54da382015-11-27 00:52:3331 TestTaskGraphRunner task_graph_runner_;
danakj60bc3bc2016-04-09 00:24:4832 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_;
ccamerona54da382015-11-27 00:52:3333
34 layer_tree_host_ =
35 FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_);
ccamerona54da382015-11-27 00:52:3336
37 MockScrollbar* scrollbar = new MockScrollbar();
38 scoped_refptr<PaintedScrollbarLayer> scrollbar_layer =
danakj60bc3bc2016-04-09 00:24:4839 PaintedScrollbarLayer::Create(std::unique_ptr<Scrollbar>(scrollbar), 1);
ccamerona54da382015-11-27 00:52:3340
41 scrollbar_layer->SetIsDrawable(true);
42 scrollbar_layer->SetBounds(gfx::Size(100, 100));
43
44 layer_tree_host_->SetRootLayer(scrollbar_layer);
khushalsagarb1931ad2016-09-15 02:07:5145 EXPECT_EQ(scrollbar_layer->GetLayerTreeHostForTesting(),
46 layer_tree_host_.get());
ccamerona54da382015-11-27 00:52:3347 scrollbar_layer->SavePaintProperties();
48
49 // Request no paint, but expect them to be painted because they have not
50 // yet been initialized.
51 scrollbar->set_needs_paint_thumb(false);
52 scrollbar->set_needs_paint_track(false);
53 EXPECT_CALL(*scrollbar, PaintPart(_, THUMB, _)).Times(1);
54 EXPECT_CALL(*scrollbar, PaintPart(_, TRACK, _)).Times(1);
55 scrollbar_layer->Update();
56 Mock::VerifyAndClearExpectations(scrollbar);
57
58 // The next update will paint nothing because the first update caused a paint.
59 EXPECT_CALL(*scrollbar, PaintPart(_, THUMB, _)).Times(0);
60 EXPECT_CALL(*scrollbar, PaintPart(_, TRACK, _)).Times(0);
61 scrollbar_layer->Update();
62 Mock::VerifyAndClearExpectations(scrollbar);
63
64 // Enable the thumb.
65 EXPECT_CALL(*scrollbar, PaintPart(_, THUMB, _)).Times(1);
66 EXPECT_CALL(*scrollbar, PaintPart(_, TRACK, _)).Times(0);
67 scrollbar->set_needs_paint_thumb(true);
68 scrollbar->set_needs_paint_track(false);
69 scrollbar_layer->Update();
70 Mock::VerifyAndClearExpectations(scrollbar);
71
72 // Enable the track.
73 EXPECT_CALL(*scrollbar, PaintPart(_, THUMB, _)).Times(0);
74 EXPECT_CALL(*scrollbar, PaintPart(_, TRACK, _)).Times(1);
75 scrollbar->set_needs_paint_thumb(false);
76 scrollbar->set_needs_paint_track(true);
77 scrollbar_layer->Update();
78 Mock::VerifyAndClearExpectations(scrollbar);
79}
80
81} // namespace
82} // namespace cc