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 | |
ccameron | a54da38 | 2015-11-27 00:52:33 | [diff] [blame] | 7 | #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 | |
| 13 | using ::testing::Mock; |
| 14 | using ::testing::_; |
| 15 | |
| 16 | namespace cc { |
| 17 | |
| 18 | namespace { |
| 19 | |
| 20 | class 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 | |
| 29 | TEST(PaintedScrollbarLayerTest, NeedsPaint) { |
danakj | 6021ec3 | 2016-07-22 22:16:08 | [diff] [blame] | 30 | FakeLayerTreeHostClient fake_client_; |
ccameron | a54da38 | 2015-11-27 00:52:33 | [diff] [blame] | 31 | TestTaskGraphRunner task_graph_runner_; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 32 | std::unique_ptr<FakeLayerTreeHost> layer_tree_host_; |
ccameron | a54da38 | 2015-11-27 00:52:33 | [diff] [blame] | 33 | |
| 34 | layer_tree_host_ = |
| 35 | FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_); |
ccameron | a54da38 | 2015-11-27 00:52:33 | [diff] [blame] | 36 | |
| 37 | MockScrollbar* scrollbar = new MockScrollbar(); |
| 38 | scoped_refptr<PaintedScrollbarLayer> scrollbar_layer = |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 39 | PaintedScrollbarLayer::Create(std::unique_ptr<Scrollbar>(scrollbar), 1); |
ccameron | a54da38 | 2015-11-27 00:52:33 | [diff] [blame] | 40 | |
| 41 | scrollbar_layer->SetIsDrawable(true); |
| 42 | scrollbar_layer->SetBounds(gfx::Size(100, 100)); |
| 43 | |
| 44 | layer_tree_host_->SetRootLayer(scrollbar_layer); |
khushalsagar | b1931ad | 2016-09-15 02:07:51 | [diff] [blame^] | 45 | EXPECT_EQ(scrollbar_layer->GetLayerTreeHostForTesting(), |
| 46 | layer_tree_host_.get()); |
ccameron | a54da38 | 2015-11-27 00:52:33 | [diff] [blame] | 47 | 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 |