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

Side by Side Diff: cc/layers/ui_resource_layer_unittest.cc

Issue 1057283003: Remove parts of //cc we aren't using (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 8 months 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 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/ui_resource_layer.h"
6
7 #include "cc/resources/prioritized_resource_manager.h"
8 #include "cc/resources/resource_provider.h"
9 #include "cc/resources/resource_update_queue.h"
10 #include "cc/resources/scoped_ui_resource.h"
11 #include "cc/test/fake_layer_tree_host.h"
12 #include "cc/test/fake_layer_tree_host_client.h"
13 #include "cc/test/fake_output_surface.h"
14 #include "cc/test/fake_output_surface_client.h"
15 #include "cc/test/geometry_test_utils.h"
16 #include "cc/trees/layer_tree_host.h"
17 #include "cc/trees/occlusion_tracker.h"
18 #include "cc/trees/single_thread_proxy.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/skia/include/core/SkBitmap.h"
22
23 using ::testing::Mock;
24 using ::testing::_;
25 using ::testing::AtLeast;
26 using ::testing::AnyNumber;
27
28 namespace cc {
29 namespace {
30
31 class TestUIResourceLayer : public UIResourceLayer {
32 public:
33 static scoped_refptr<TestUIResourceLayer> Create() {
34 return make_scoped_refptr(new TestUIResourceLayer());
35 }
36
37 UIResourceId GetUIResourceId() {
38 if (ui_resource_holder_)
39 return ui_resource_holder_->id();
40 return 0;
41 }
42
43 protected:
44 TestUIResourceLayer() : UIResourceLayer() { SetIsDrawable(true); }
45 ~TestUIResourceLayer() override {}
46 };
47
48 class UIResourceLayerTest : public testing::Test {
49 public:
50 UIResourceLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
51
52 protected:
53 void SetUp() override {
54 layer_tree_host_ = FakeLayerTreeHost::Create(&fake_client_);
55 layer_tree_host_->InitializeSingleThreaded(
56 &fake_client_,
57 base::MessageLoopProxy::current(),
58 nullptr);
59 }
60
61 void TearDown() override {
62 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
63 }
64
65 FakeLayerTreeHostClient fake_client_;
66 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
67 };
68
69 TEST_F(UIResourceLayerTest, SetBitmap) {
70 scoped_refptr<UIResourceLayer> test_layer = TestUIResourceLayer::Create();
71 ASSERT_TRUE(test_layer.get());
72 test_layer->SetBounds(gfx::Size(100, 100));
73
74 layer_tree_host_->SetRootLayer(test_layer);
75 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
76 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
77
78 ResourceUpdateQueue queue;
79 gfx::Rect screen_space_clip_rect;
80 OcclusionTracker<Layer> occlusion_tracker(screen_space_clip_rect);
81 test_layer->SavePaintProperties();
82 test_layer->Update(&queue, &occlusion_tracker);
83
84 EXPECT_FALSE(test_layer->DrawsContent());
85
86 SkBitmap bitmap;
87 bitmap.allocN32Pixels(10, 10);
88 bitmap.setImmutable();
89
90 test_layer->SetBitmap(bitmap);
91 test_layer->Update(&queue, &occlusion_tracker);
92
93 EXPECT_TRUE(test_layer->DrawsContent());
94 }
95
96 TEST_F(UIResourceLayerTest, SetUIResourceId) {
97 scoped_refptr<TestUIResourceLayer> test_layer = TestUIResourceLayer::Create();
98 ASSERT_TRUE(test_layer.get());
99 test_layer->SetBounds(gfx::Size(100, 100));
100
101 layer_tree_host_->SetRootLayer(test_layer);
102 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
103 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
104
105 ResourceUpdateQueue queue;
106 gfx::Rect screen_space_clip_rect;
107 OcclusionTracker<Layer> occlusion_tracker(screen_space_clip_rect);
108 test_layer->SavePaintProperties();
109 test_layer->Update(&queue, &occlusion_tracker);
110
111 EXPECT_FALSE(test_layer->DrawsContent());
112
113 bool is_opaque = false;
114 scoped_ptr<ScopedUIResource> resource = ScopedUIResource::Create(
115 layer_tree_host_.get(), UIResourceBitmap(gfx::Size(10, 10), is_opaque));
116 test_layer->SetUIResourceId(resource->id());
117 test_layer->Update(&queue, &occlusion_tracker);
118
119 EXPECT_TRUE(test_layer->DrawsContent());
120
121 // ID is preserved even when you set ID first and attach it to the tree.
122 layer_tree_host_->SetRootLayer(nullptr);
123 scoped_ptr<ScopedUIResource> shared_resource = ScopedUIResource::Create(
124 layer_tree_host_.get(), UIResourceBitmap(gfx::Size(5, 5), is_opaque));
125 test_layer->SetUIResourceId(shared_resource->id());
126 layer_tree_host_->SetRootLayer(test_layer);
127 EXPECT_EQ(shared_resource->id(), test_layer->GetUIResourceId());
128 EXPECT_TRUE(test_layer->DrawsContent());
129 }
130
131 TEST_F(UIResourceLayerTest, BitmapClearedOnSetUIResourceId) {
132 scoped_refptr<UIResourceLayer> test_layer = TestUIResourceLayer::Create();
133 ASSERT_TRUE(test_layer.get());
134 test_layer->SetBounds(gfx::Size(100, 100));
135
136 SkBitmap bitmap;
137 bitmap.allocN32Pixels(10, 10);
138 bitmap.setImmutable();
139 ASSERT_FALSE(bitmap.isNull());
140 ASSERT_TRUE(bitmap.pixelRef()->unique());
141
142 test_layer->SetBitmap(bitmap);
143 ASSERT_FALSE(bitmap.pixelRef()->unique());
144
145 test_layer->SetUIResourceId(0);
146 EXPECT_TRUE(bitmap.pixelRef()->unique());
147 }
148
149 } // namespace
150 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/ui_resource_layer_impl_unittest.cc ('k') | cc/layers/video_frame_provider_client_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698