ccameron | a54da38 | 2015-11-27 00:52:33 | [diff] [blame] | 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 | |
loyso | 2cb3f32f | 2016-11-08 07:08:34 | [diff] [blame] | 7 | #include "cc/animation/animation_host.h" |
ccameron | a54da38 | 2015-11-27 00:52:33 | [diff] [blame] | 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, |
enne | 5a963036 | 2017-02-24 23:41:03 | [diff] [blame] | 25 | void(PaintCanvas* canvas, |
ccameron | a54da38 | 2015-11-27 00:52:33 | [diff] [blame] | 26 | ScrollbarPart part, |
| 27 | const gfx::Rect& content_rect)); |
| 28 | }; |
| 29 | |
| 30 | TEST(PaintedScrollbarLayerTest, NeedsPaint) { |
danakj | 6021ec3 | 2016-07-22 22:16:08 | [diff] [blame] | 31 | FakeLayerTreeHostClient fake_client_; |
ccameron | a54da38 | 2015-11-27 00:52:33 | [diff] [blame] | 32 | TestTaskGraphRunner task_graph_runner_; |
ccameron | a54da38 | 2015-11-27 00:52:33 | [diff] [blame] | 33 | |
loyso | 2cb3f32f | 2016-11-08 07:08:34 | [diff] [blame] | 34 | auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); |
| 35 | auto layer_tree_host = FakeLayerTreeHost::Create( |
| 36 | &fake_client_, &task_graph_runner_, animation_host.get()); |
ccameron | a54da38 | 2015-11-27 00:52:33 | [diff] [blame] | 37 | |
| 38 | MockScrollbar* scrollbar = new MockScrollbar(); |
| 39 | scoped_refptr<PaintedScrollbarLayer> scrollbar_layer = |
pdr | 75a6cc5 | 2017-04-20 19:21:14 | [diff] [blame] | 40 | PaintedScrollbarLayer::Create(std::unique_ptr<Scrollbar>(scrollbar)); |
ccameron | a54da38 | 2015-11-27 00:52:33 | [diff] [blame] | 41 | |
| 42 | scrollbar_layer->SetIsDrawable(true); |
| 43 | scrollbar_layer->SetBounds(gfx::Size(100, 100)); |
| 44 | |
loyso | 2cb3f32f | 2016-11-08 07:08:34 | [diff] [blame] | 45 | layer_tree_host->SetRootLayer(scrollbar_layer); |
khushalsagar | b1931ad | 2016-09-15 02:07:51 | [diff] [blame] | 46 | EXPECT_EQ(scrollbar_layer->GetLayerTreeHostForTesting(), |
loyso | 2cb3f32f | 2016-11-08 07:08:34 | [diff] [blame] | 47 | layer_tree_host.get()); |
ccameron | a54da38 | 2015-11-27 00:52:33 | [diff] [blame] | 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 |