blob: f4767910181282ca6c33ca531bcca9da10f9836b [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
loyso2cb3f32f2016-11-08 07:08:347#include "cc/animation/animation_host.h"
ccamerona54da382015-11-27 00:52:338#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
14using ::testing::Mock;
15using ::testing::_;
16
17namespace cc {
18
19namespace {
20
21class MockScrollbar : public FakeScrollbar {
22 public:
23 MockScrollbar() : FakeScrollbar(true, true, true) {}
24 MOCK_METHOD3(PaintPart,
enne5a9630362017-02-24 23:41:0325 void(PaintCanvas* canvas,
ccamerona54da382015-11-27 00:52:3326 ScrollbarPart part,
27 const gfx::Rect& content_rect));
28};
29
30TEST(PaintedScrollbarLayerTest, NeedsPaint) {
danakj6021ec32016-07-22 22:16:0831 FakeLayerTreeHostClient fake_client_;
ccamerona54da382015-11-27 00:52:3332 TestTaskGraphRunner task_graph_runner_;
ccamerona54da382015-11-27 00:52:3333
loyso2cb3f32f2016-11-08 07:08:3434 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
35 auto layer_tree_host = FakeLayerTreeHost::Create(
36 &fake_client_, &task_graph_runner_, animation_host.get());
ccamerona54da382015-11-27 00:52:3337
38 MockScrollbar* scrollbar = new MockScrollbar();
39 scoped_refptr<PaintedScrollbarLayer> scrollbar_layer =
pdr75a6cc52017-04-20 19:21:1440 PaintedScrollbarLayer::Create(std::unique_ptr<Scrollbar>(scrollbar));
ccamerona54da382015-11-27 00:52:3341
42 scrollbar_layer->SetIsDrawable(true);
43 scrollbar_layer->SetBounds(gfx::Size(100, 100));
44
loyso2cb3f32f2016-11-08 07:08:3445 layer_tree_host->SetRootLayer(scrollbar_layer);
khushalsagarb1931ad2016-09-15 02:07:5146 EXPECT_EQ(scrollbar_layer->GetLayerTreeHostForTesting(),
loyso2cb3f32f2016-11-08 07:08:3447 layer_tree_host.get());
ccamerona54da382015-11-27 00:52:3348
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