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

Unified 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: Rebase and resolve 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/layers/painted_scrollbar_layer_impl_unittest.cc ('k') | cc/output/ca_layer_overlay.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/layers/painted_scrollbar_layer_unittest.cc
diff --git a/cc/layers/painted_scrollbar_layer_unittest.cc b/cc/layers/painted_scrollbar_layer_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ac814eec91c50cbd140a8582a2e50fcc27698f93
--- /dev/null
+++ b/cc/layers/painted_scrollbar_layer_unittest.cc
@@ -0,0 +1,87 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/layers/painted_scrollbar_layer.h"
+
+#include "cc/layers/layer_settings.h"
+#include "cc/test/fake_layer_tree_host.h"
+#include "cc/test/fake_layer_tree_host_client.h"
+#include "cc/test/fake_scrollbar.h"
+#include "cc/test/test_task_graph_runner.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+using ::testing::Mock;
+using ::testing::_;
+
+namespace cc {
+
+namespace {
+
+class MockScrollbar : public FakeScrollbar {
+ public:
+ MockScrollbar() : FakeScrollbar(true, true, true) {}
+ MOCK_METHOD3(PaintPart,
+ void(SkCanvas* canvas,
+ ScrollbarPart part,
+ const gfx::Rect& content_rect));
+};
+
+TEST(PaintedScrollbarLayerTest, NeedsPaint) {
+ FakeLayerTreeHostClient fake_client_(FakeLayerTreeHostClient::DIRECT_3D);
+ TestTaskGraphRunner task_graph_runner_;
+ scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
+ LayerSettings layer_settings_;
+
+ layer_tree_host_ =
+ FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_);
+ RendererCapabilities renderer_capabilities;
+ renderer_capabilities.max_texture_size = 2048;
+ layer_tree_host_->set_renderer_capabilities(renderer_capabilities);
+
+ MockScrollbar* scrollbar = new MockScrollbar();
+ scoped_refptr<PaintedScrollbarLayer> scrollbar_layer =
+ PaintedScrollbarLayer::Create(layer_settings_,
+ scoped_ptr<Scrollbar>(scrollbar).Pass(), 1);
+
+ scrollbar_layer->SetIsDrawable(true);
+ scrollbar_layer->SetBounds(gfx::Size(100, 100));
+
+ layer_tree_host_->SetRootLayer(scrollbar_layer);
+ EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
+ scrollbar_layer->SavePaintProperties();
+
+ // Request no paint, but expect them to be painted because they have not
+ // yet been initialized.
+ scrollbar->set_needs_paint_thumb(false);
+ scrollbar->set_needs_paint_track(false);
+ EXPECT_CALL(*scrollbar, PaintPart(_, THUMB, _)).Times(1);
+ EXPECT_CALL(*scrollbar, PaintPart(_, TRACK, _)).Times(1);
+ scrollbar_layer->Update();
+ Mock::VerifyAndClearExpectations(scrollbar);
+
+ // The next update will paint nothing because the first update caused a paint.
+ EXPECT_CALL(*scrollbar, PaintPart(_, THUMB, _)).Times(0);
+ EXPECT_CALL(*scrollbar, PaintPart(_, TRACK, _)).Times(0);
+ scrollbar_layer->Update();
+ Mock::VerifyAndClearExpectations(scrollbar);
+
+ // Enable the thumb.
+ EXPECT_CALL(*scrollbar, PaintPart(_, THUMB, _)).Times(1);
+ EXPECT_CALL(*scrollbar, PaintPart(_, TRACK, _)).Times(0);
+ scrollbar->set_needs_paint_thumb(true);
+ scrollbar->set_needs_paint_track(false);
+ scrollbar_layer->Update();
+ Mock::VerifyAndClearExpectations(scrollbar);
+
+ // Enable the track.
+ EXPECT_CALL(*scrollbar, PaintPart(_, THUMB, _)).Times(0);
+ EXPECT_CALL(*scrollbar, PaintPart(_, TRACK, _)).Times(1);
+ scrollbar->set_needs_paint_thumb(false);
+ scrollbar->set_needs_paint_track(true);
+ scrollbar_layer->Update();
+ Mock::VerifyAndClearExpectations(scrollbar);
+}
+
+} // namespace
+} // namespace cc
« no previous file with comments | « cc/layers/painted_scrollbar_layer_impl_unittest.cc ('k') | cc/output/ca_layer_overlay.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698