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

Side by Side Diff: cc/layer_unittest.cc

Issue 12774006: cc: Chromify Layer and LayerImpl classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: MoreAndroidCompilings Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « cc/layer_tree_impl.cc ('k') | cc/nine_patch_layer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layer.h" 5 #include "cc/layer.h"
6 6
7 #include "cc/keyframed_animation_curve.h" 7 #include "cc/keyframed_animation_curve.h"
8 #include "cc/layer_impl.h" 8 #include "cc/layer_impl.h"
9 #include "cc/layer_painter.h" 9 #include "cc/layer_painter.h"
10 #include "cc/layer_tree_host.h" 10 #include "cc/layer_tree_host.h"
11 #include "cc/math_util.h" 11 #include "cc/math_util.h"
12 #include "cc/single_thread_proxy.h" 12 #include "cc/single_thread_proxy.h"
13 #include "cc/test/fake_impl_proxy.h" 13 #include "cc/test/fake_impl_proxy.h"
14 #include "cc/test/fake_layer_tree_host_client.h" 14 #include "cc/test/fake_layer_tree_host_client.h"
15 #include "cc/test/fake_layer_tree_host_impl.h" 15 #include "cc/test/fake_layer_tree_host_impl.h"
16 #include "cc/test/geometry_test_utils.h" 16 #include "cc/test/geometry_test_utils.h"
17 #include "cc/thread.h" 17 #include "cc/thread.h"
18 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/gfx/transform.h" 20 #include "ui/gfx/transform.h"
21 21
22 using ::testing::AnyNumber; 22 using ::testing::AnyNumber;
23 using ::testing::AtLeast; 23 using ::testing::AtLeast;
24 using ::testing::Mock; 24 using ::testing::Mock;
25 using ::testing::StrictMock; 25 using ::testing::StrictMock;
26 using ::testing::_; 26 using ::testing::_;
27 27
28 #define EXPECT_SET_NEEDS_COMMIT(expect, codeToTest) do { \ 28 #define EXPECT_SET_NEEDS_COMMIT(expect, codeToTest) do { \
29 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times((expect)); \ 29 EXPECT_CALL(*layer_tree_host_, setNeedsCommit()).Times((expect)); \
30 codeToTest; \ 30 codeToTest; \
31 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); \ 31 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \
32 } while (0) 32 } while (0)
33 33
34 #define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, codeToTest) do { \ 34 #define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, codeToTest) do { \
35 EXPECT_CALL(*m_layerTreeHost, setNeedsFullTreeSync()).Times((expect)); \ 35 EXPECT_CALL(*layer_tree_host_, setNeedsFullTreeSync()).Times((expect)); \
36 codeToTest; \ 36 codeToTest; \
37 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); \ 37 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \
38 } while (0) 38 } while (0)
39 39
40 40
41 namespace cc { 41 namespace cc {
42 namespace { 42 namespace {
43 43
44 class MockLayerImplTreeHost : public LayerTreeHost { 44 class MockLayerImplTreeHost : public LayerTreeHost {
45 public: 45 public:
46 MockLayerImplTreeHost() 46 MockLayerImplTreeHost()
47 : LayerTreeHost(&m_fakeClient, LayerTreeSettings()) 47 : LayerTreeHost(&m_fakeClient, LayerTreeSettings())
(...skipping 17 matching lines...) Expand all
65 class LayerTest : public testing::Test { 65 class LayerTest : public testing::Test {
66 public: 66 public:
67 LayerTest() 67 LayerTest()
68 : m_hostImpl(&m_proxy) 68 : m_hostImpl(&m_proxy)
69 { 69 {
70 } 70 }
71 71
72 protected: 72 protected:
73 virtual void SetUp() 73 virtual void SetUp()
74 { 74 {
75 m_layerTreeHost.reset(new StrictMock<MockLayerImplTreeHost>); 75 layer_tree_host_.reset(new StrictMock<MockLayerImplTreeHost>);
76 } 76 }
77 77
78 virtual void TearDown() 78 virtual void TearDown()
79 { 79 {
80 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); 80 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
81 EXPECT_CALL(*m_layerTreeHost, setNeedsFullTreeSync()).Times(AnyNumber()) ; 81 EXPECT_CALL(*layer_tree_host_, setNeedsFullTreeSync()).Times(AnyNumber() );
82 m_parent = NULL; 82 parent_ = NULL;
83 m_child1 = NULL; 83 m_child1 = NULL;
84 m_child2 = NULL; 84 m_child2 = NULL;
85 m_child3 = NULL; 85 m_child3 = NULL;
86 m_grandChild1 = NULL; 86 m_grandChild1 = NULL;
87 m_grandChild2 = NULL; 87 m_grandChild2 = NULL;
88 m_grandChild3 = NULL; 88 m_grandChild3 = NULL;
89 89
90 m_layerTreeHost->setRootLayer(0); 90 layer_tree_host_->setRootLayer(0);
91 m_layerTreeHost.reset(); 91 layer_tree_host_.reset();
92 } 92 }
93 93
94 void verifyTestTreeInitialState() const 94 void verifyTestTreeInitialState() const
95 { 95 {
96 ASSERT_EQ(3U, m_parent->children().size()); 96 ASSERT_EQ(3U, parent_->children().size());
97 EXPECT_EQ(m_child1, m_parent->children()[0]); 97 EXPECT_EQ(m_child1, parent_->children()[0]);
98 EXPECT_EQ(m_child2, m_parent->children()[1]); 98 EXPECT_EQ(m_child2, parent_->children()[1]);
99 EXPECT_EQ(m_child3, m_parent->children()[2]); 99 EXPECT_EQ(m_child3, parent_->children()[2]);
100 EXPECT_EQ(m_parent.get(), m_child1->parent()); 100 EXPECT_EQ(parent_.get(), m_child1->parent());
101 EXPECT_EQ(m_parent.get(), m_child2->parent()); 101 EXPECT_EQ(parent_.get(), m_child2->parent());
102 EXPECT_EQ(m_parent.get(), m_child3->parent()); 102 EXPECT_EQ(parent_.get(), m_child3->parent());
103 103
104 ASSERT_EQ(2U, m_child1->children().size()); 104 ASSERT_EQ(2U, m_child1->children().size());
105 EXPECT_EQ(m_grandChild1, m_child1->children()[0]); 105 EXPECT_EQ(m_grandChild1, m_child1->children()[0]);
106 EXPECT_EQ(m_grandChild2, m_child1->children()[1]); 106 EXPECT_EQ(m_grandChild2, m_child1->children()[1]);
107 EXPECT_EQ(m_child1.get(), m_grandChild1->parent()); 107 EXPECT_EQ(m_child1.get(), m_grandChild1->parent());
108 EXPECT_EQ(m_child1.get(), m_grandChild2->parent()); 108 EXPECT_EQ(m_child1.get(), m_grandChild2->parent());
109 109
110 ASSERT_EQ(1U, m_child2->children().size()); 110 ASSERT_EQ(1U, m_child2->children().size());
111 EXPECT_EQ(m_grandChild3, m_child2->children()[0]); 111 EXPECT_EQ(m_grandChild3, m_child2->children()[0]);
112 EXPECT_EQ(m_child2.get(), m_grandChild3->parent()); 112 EXPECT_EQ(m_child2.get(), m_grandChild3->parent());
113 113
114 ASSERT_EQ(0U, m_child3->children().size()); 114 ASSERT_EQ(0U, m_child3->children().size());
115 } 115 }
116 116
117 void createSimpleTestTree() 117 void createSimpleTestTree()
118 { 118 {
119 m_parent = Layer::create(); 119 parent_ = Layer::Create();
120 m_child1 = Layer::create(); 120 m_child1 = Layer::Create();
121 m_child2 = Layer::create(); 121 m_child2 = Layer::Create();
122 m_child3 = Layer::create(); 122 m_child3 = Layer::Create();
123 m_grandChild1 = Layer::create(); 123 m_grandChild1 = Layer::Create();
124 m_grandChild2 = Layer::create(); 124 m_grandChild2 = Layer::Create();
125 m_grandChild3 = Layer::create(); 125 m_grandChild3 = Layer::Create();
126 126
127 EXPECT_CALL(*m_layerTreeHost, setNeedsFullTreeSync()).Times(AnyNumber()) ; 127 EXPECT_CALL(*layer_tree_host_, setNeedsFullTreeSync()).Times(AnyNumber() );
128 m_layerTreeHost->setRootLayer(m_parent); 128 layer_tree_host_->setRootLayer(parent_);
129 129
130 m_parent->addChild(m_child1); 130 parent_->AddChild(m_child1);
131 m_parent->addChild(m_child2); 131 parent_->AddChild(m_child2);
132 m_parent->addChild(m_child3); 132 parent_->AddChild(m_child3);
133 m_child1->addChild(m_grandChild1); 133 m_child1->AddChild(m_grandChild1);
134 m_child1->addChild(m_grandChild2); 134 m_child1->AddChild(m_grandChild2);
135 m_child2->addChild(m_grandChild3); 135 m_child2->AddChild(m_grandChild3);
136 136
137 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); 137 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
138 138
139 verifyTestTreeInitialState(); 139 verifyTestTreeInitialState();
140 } 140 }
141 141
142 FakeImplProxy m_proxy; 142 FakeImplProxy m_proxy;
143 FakeLayerTreeHostImpl m_hostImpl; 143 FakeLayerTreeHostImpl m_hostImpl;
144 144
145 scoped_ptr<StrictMock<MockLayerImplTreeHost> > m_layerTreeHost; 145 scoped_ptr<StrictMock<MockLayerImplTreeHost> > layer_tree_host_;
146 scoped_refptr<Layer> m_parent; 146 scoped_refptr<Layer> parent_;
147 scoped_refptr<Layer> m_child1; 147 scoped_refptr<Layer> m_child1;
148 scoped_refptr<Layer> m_child2; 148 scoped_refptr<Layer> m_child2;
149 scoped_refptr<Layer> m_child3; 149 scoped_refptr<Layer> m_child3;
150 scoped_refptr<Layer> m_grandChild1; 150 scoped_refptr<Layer> m_grandChild1;
151 scoped_refptr<Layer> m_grandChild2; 151 scoped_refptr<Layer> m_grandChild2;
152 scoped_refptr<Layer> m_grandChild3; 152 scoped_refptr<Layer> m_grandChild3;
153 }; 153 };
154 154
155 TEST_F(LayerTest, basicCreateAndDestroy) 155 TEST_F(LayerTest, basicCreateAndDestroy)
156 { 156 {
157 scoped_refptr<Layer> testLayer = Layer::create(); 157 scoped_refptr<Layer> testLayer = Layer::Create();
158 ASSERT_TRUE(testLayer); 158 ASSERT_TRUE(testLayer);
159 159
160 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(0); 160 EXPECT_CALL(*layer_tree_host_, setNeedsCommit()).Times(0);
161 testLayer->setLayerTreeHost(m_layerTreeHost.get()); 161 testLayer->SetLayerTreeHost(layer_tree_host_.get());
162 } 162 }
163 163
164 TEST_F(LayerTest, addAndRemoveChild) 164 TEST_F(LayerTest, addAndRemoveChild)
165 { 165 {
166 scoped_refptr<Layer> parent = Layer::create(); 166 scoped_refptr<Layer> parent = Layer::Create();
167 scoped_refptr<Layer> child = Layer::create(); 167 scoped_refptr<Layer> child = Layer::Create();
168 168
169 // Upon creation, layers should not have children or parent. 169 // Upon creation, layers should not have children or parent.
170 ASSERT_EQ(0U, parent->children().size()); 170 ASSERT_EQ(0U, parent->children().size());
171 EXPECT_FALSE(child->parent()); 171 EXPECT_FALSE(child->parent());
172 172
173 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, m_layerTreeHost->setRootLayer(parent)); 173 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->setRootLayer(parent));
174 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->addChild(child)); 174 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->AddChild(child));
175 175
176 ASSERT_EQ(1U, parent->children().size()); 176 ASSERT_EQ(1U, parent->children().size());
177 EXPECT_EQ(child.get(), parent->children()[0]); 177 EXPECT_EQ(child.get(), parent->children()[0]);
178 EXPECT_EQ(parent.get(), child->parent()); 178 EXPECT_EQ(parent.get(), child->parent());
179 EXPECT_EQ(parent.get(), child->rootLayer()); 179 EXPECT_EQ(parent.get(), child->RootLayer());
180 180
181 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), child->removeFromParent()); 181 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), child->RemoveFromParent());
182 } 182 }
183 183
184 TEST_F(LayerTest, addSameChildTwice) 184 TEST_F(LayerTest, addSameChildTwice)
185 { 185 {
186 EXPECT_CALL(*m_layerTreeHost, setNeedsFullTreeSync()).Times(AtLeast(1)); 186 EXPECT_CALL(*layer_tree_host_, setNeedsFullTreeSync()).Times(AtLeast(1));
187 187
188 scoped_refptr<Layer> parent = Layer::create(); 188 scoped_refptr<Layer> parent = Layer::Create();
189 scoped_refptr<Layer> child = Layer::create(); 189 scoped_refptr<Layer> child = Layer::Create();
190 190
191 m_layerTreeHost->setRootLayer(parent); 191 layer_tree_host_->setRootLayer(parent);
192 192
193 ASSERT_EQ(0u, parent->children().size()); 193 ASSERT_EQ(0u, parent->children().size());
194 194
195 parent->addChild(child); 195 parent->AddChild(child);
196 ASSERT_EQ(1u, parent->children().size()); 196 ASSERT_EQ(1u, parent->children().size());
197 EXPECT_EQ(parent.get(), child->parent()); 197 EXPECT_EQ(parent.get(), child->parent());
198 198
199 parent->addChild(child); 199 parent->AddChild(child);
200 ASSERT_EQ(1u, parent->children().size()); 200 ASSERT_EQ(1u, parent->children().size());
201 EXPECT_EQ(parent.get(), child->parent()); 201 EXPECT_EQ(parent.get(), child->parent());
202 } 202 }
203 203
204 TEST_F(LayerTest, insertChild) 204 TEST_F(LayerTest, insertChild)
205 { 205 {
206 scoped_refptr<Layer> parent = Layer::create(); 206 scoped_refptr<Layer> parent = Layer::Create();
207 scoped_refptr<Layer> child1 = Layer::create(); 207 scoped_refptr<Layer> child1 = Layer::Create();
208 scoped_refptr<Layer> child2 = Layer::create(); 208 scoped_refptr<Layer> child2 = Layer::Create();
209 scoped_refptr<Layer> child3 = Layer::create(); 209 scoped_refptr<Layer> child3 = Layer::Create();
210 scoped_refptr<Layer> child4 = Layer::create(); 210 scoped_refptr<Layer> child4 = Layer::Create();
211 211
212 parent->setLayerTreeHost(m_layerTreeHost.get()); 212 parent->SetLayerTreeHost(layer_tree_host_.get());
213 213
214 ASSERT_EQ(0U, parent->children().size()); 214 ASSERT_EQ(0U, parent->children().size());
215 215
216 // Case 1: inserting to empty list. 216 // Case 1: inserting to empty list.
217 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->insertChild(child3, 0)); 217 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child3, 0));
218 ASSERT_EQ(1U, parent->children().size()); 218 ASSERT_EQ(1U, parent->children().size());
219 EXPECT_EQ(child3, parent->children()[0]); 219 EXPECT_EQ(child3, parent->children()[0]);
220 EXPECT_EQ(parent.get(), child3->parent()); 220 EXPECT_EQ(parent.get(), child3->parent());
221 221
222 // Case 2: inserting to beginning of list 222 // Case 2: inserting to beginning of list
223 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->insertChild(child1, 0)); 223 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0));
224 ASSERT_EQ(2U, parent->children().size()); 224 ASSERT_EQ(2U, parent->children().size());
225 EXPECT_EQ(child1, parent->children()[0]); 225 EXPECT_EQ(child1, parent->children()[0]);
226 EXPECT_EQ(child3, parent->children()[1]); 226 EXPECT_EQ(child3, parent->children()[1]);
227 EXPECT_EQ(parent.get(), child1->parent()); 227 EXPECT_EQ(parent.get(), child1->parent());
228 228
229 // Case 3: inserting to middle of list 229 // Case 3: inserting to middle of list
230 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->insertChild(child2, 1)); 230 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1));
231 ASSERT_EQ(3U, parent->children().size()); 231 ASSERT_EQ(3U, parent->children().size());
232 EXPECT_EQ(child1, parent->children()[0]); 232 EXPECT_EQ(child1, parent->children()[0]);
233 EXPECT_EQ(child2, parent->children()[1]); 233 EXPECT_EQ(child2, parent->children()[1]);
234 EXPECT_EQ(child3, parent->children()[2]); 234 EXPECT_EQ(child3, parent->children()[2]);
235 EXPECT_EQ(parent.get(), child2->parent()); 235 EXPECT_EQ(parent.get(), child2->parent());
236 236
237 // Case 4: inserting to end of list 237 // Case 4: inserting to end of list
238 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->insertChild(child4, 3)); 238 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child4, 3));
239 239
240 ASSERT_EQ(4U, parent->children().size()); 240 ASSERT_EQ(4U, parent->children().size());
241 EXPECT_EQ(child1, parent->children()[0]); 241 EXPECT_EQ(child1, parent->children()[0]);
242 EXPECT_EQ(child2, parent->children()[1]); 242 EXPECT_EQ(child2, parent->children()[1]);
243 EXPECT_EQ(child3, parent->children()[2]); 243 EXPECT_EQ(child3, parent->children()[2]);
244 EXPECT_EQ(child4, parent->children()[3]); 244 EXPECT_EQ(child4, parent->children()[3]);
245 EXPECT_EQ(parent.get(), child4->parent()); 245 EXPECT_EQ(parent.get(), child4->parent());
246 246
247 EXPECT_CALL(*m_layerTreeHost, setNeedsFullTreeSync()).Times(AtLeast(1)); 247 EXPECT_CALL(*layer_tree_host_, setNeedsFullTreeSync()).Times(AtLeast(1));
248 } 248 }
249 249
250 TEST_F(LayerTest, insertChildPastEndOfList) 250 TEST_F(LayerTest, insertChildPastEndOfList)
251 { 251 {
252 scoped_refptr<Layer> parent = Layer::create(); 252 scoped_refptr<Layer> parent = Layer::Create();
253 scoped_refptr<Layer> child1 = Layer::create(); 253 scoped_refptr<Layer> child1 = Layer::Create();
254 scoped_refptr<Layer> child2 = Layer::create(); 254 scoped_refptr<Layer> child2 = Layer::Create();
255 255
256 ASSERT_EQ(0U, parent->children().size()); 256 ASSERT_EQ(0U, parent->children().size());
257 257
258 // insert to an out-of-bounds index 258 // insert to an out-of-bounds index
259 parent->insertChild(child1, 53); 259 parent->InsertChild(child1, 53);
260 260
261 ASSERT_EQ(1U, parent->children().size()); 261 ASSERT_EQ(1U, parent->children().size());
262 EXPECT_EQ(child1, parent->children()[0]); 262 EXPECT_EQ(child1, parent->children()[0]);
263 263
264 // insert another child to out-of-bounds, when list is not already empty. 264 // insert another child to out-of-bounds, when list is not already empty.
265 parent->insertChild(child2, 2459); 265 parent->InsertChild(child2, 2459);
266 266
267 ASSERT_EQ(2U, parent->children().size()); 267 ASSERT_EQ(2U, parent->children().size());
268 EXPECT_EQ(child1, parent->children()[0]); 268 EXPECT_EQ(child1, parent->children()[0]);
269 EXPECT_EQ(child2, parent->children()[1]); 269 EXPECT_EQ(child2, parent->children()[1]);
270 } 270 }
271 271
272 TEST_F(LayerTest, insertSameChildTwice) 272 TEST_F(LayerTest, insertSameChildTwice)
273 { 273 {
274 scoped_refptr<Layer> parent = Layer::create(); 274 scoped_refptr<Layer> parent = Layer::Create();
275 scoped_refptr<Layer> child1 = Layer::create(); 275 scoped_refptr<Layer> child1 = Layer::Create();
276 scoped_refptr<Layer> child2 = Layer::create(); 276 scoped_refptr<Layer> child2 = Layer::Create();
277 277
278 parent->setLayerTreeHost(m_layerTreeHost.get()); 278 parent->SetLayerTreeHost(layer_tree_host_.get());
279 279
280 ASSERT_EQ(0U, parent->children().size()); 280 ASSERT_EQ(0U, parent->children().size());
281 281
282 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->insertChild(child1, 0)); 282 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0));
283 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->insertChild(child2, 1)); 283 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1));
284 284
285 ASSERT_EQ(2U, parent->children().size()); 285 ASSERT_EQ(2U, parent->children().size());
286 EXPECT_EQ(child1, parent->children()[0]); 286 EXPECT_EQ(child1, parent->children()[0]);
287 EXPECT_EQ(child2, parent->children()[1]); 287 EXPECT_EQ(child2, parent->children()[1]);
288 288
289 // Inserting the same child again should cause the child to be removed and r e-inserted at the new location. 289 // Inserting the same child again should cause the child to be removed and r e-inserted at the new location.
290 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent->insertChild(child1, 1)); 290 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent->InsertChild(child1, 1));
291 291
292 // child1 should now be at the end of the list. 292 // child1 should now be at the end of the list.
293 ASSERT_EQ(2U, parent->children().size()); 293 ASSERT_EQ(2U, parent->children().size());
294 EXPECT_EQ(child2, parent->children()[0]); 294 EXPECT_EQ(child2, parent->children()[0]);
295 EXPECT_EQ(child1, parent->children()[1]); 295 EXPECT_EQ(child1, parent->children()[1]);
296 296
297 EXPECT_CALL(*m_layerTreeHost, setNeedsFullTreeSync()).Times(AtLeast(1)); 297 EXPECT_CALL(*layer_tree_host_, setNeedsFullTreeSync()).Times(AtLeast(1));
298 } 298 }
299 299
300 TEST_F(LayerTest, replaceChildWithNewChild) 300 TEST_F(LayerTest, replaceChildWithNewChild)
301 { 301 {
302 createSimpleTestTree(); 302 createSimpleTestTree();
303 scoped_refptr<Layer> child4 = Layer::create(); 303 scoped_refptr<Layer> child4 = Layer::Create();
304 304
305 EXPECT_FALSE(child4->parent()); 305 EXPECT_FALSE(child4->parent());
306 306
307 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), m_parent->replaceChild(m_child2. get(), child4)); 307 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent_->ReplaceChild(m_child2.g et(), child4));
308 EXPECT_FALSE(m_parent->needsDisplayForTesting()); 308 EXPECT_FALSE(parent_->NeedsDisplayForTesting());
309 EXPECT_FALSE(m_child1->needsDisplayForTesting()); 309 EXPECT_FALSE(m_child1->NeedsDisplayForTesting());
310 EXPECT_FALSE(m_child2->needsDisplayForTesting()); 310 EXPECT_FALSE(m_child2->NeedsDisplayForTesting());
311 EXPECT_FALSE(m_child3->needsDisplayForTesting()); 311 EXPECT_FALSE(m_child3->NeedsDisplayForTesting());
312 EXPECT_FALSE(child4->needsDisplayForTesting()); 312 EXPECT_FALSE(child4->NeedsDisplayForTesting());
313 313
314 ASSERT_EQ(static_cast<size_t>(3), m_parent->children().size()); 314 ASSERT_EQ(static_cast<size_t>(3), parent_->children().size());
315 EXPECT_EQ(m_child1, m_parent->children()[0]); 315 EXPECT_EQ(m_child1, parent_->children()[0]);
316 EXPECT_EQ(child4, m_parent->children()[1]); 316 EXPECT_EQ(child4, parent_->children()[1]);
317 EXPECT_EQ(m_child3, m_parent->children()[2]); 317 EXPECT_EQ(m_child3, parent_->children()[2]);
318 EXPECT_EQ(m_parent.get(), child4->parent()); 318 EXPECT_EQ(parent_.get(), child4->parent());
319 319
320 EXPECT_FALSE(m_child2->parent()); 320 EXPECT_FALSE(m_child2->parent());
321 } 321 }
322 322
323 TEST_F(LayerTest, replaceChildWithNewChildAutomaticRasterScale) 323 TEST_F(LayerTest, replaceChildWithNewChildAutomaticRasterScale)
324 { 324 {
325 createSimpleTestTree(); 325 createSimpleTestTree();
326 scoped_refptr<Layer> child4 = Layer::create(); 326 scoped_refptr<Layer> child4 = Layer::Create();
327 EXPECT_SET_NEEDS_COMMIT(1, m_child1->setAutomaticallyComputeRasterScale(true )); 327 EXPECT_SET_NEEDS_COMMIT(1, m_child1->SetAutomaticallyComputeRasterScale(true ));
328 EXPECT_SET_NEEDS_COMMIT(1, m_child2->setAutomaticallyComputeRasterScale(true )); 328 EXPECT_SET_NEEDS_COMMIT(1, m_child2->SetAutomaticallyComputeRasterScale(true ));
329 EXPECT_SET_NEEDS_COMMIT(1, m_child3->setAutomaticallyComputeRasterScale(true )); 329 EXPECT_SET_NEEDS_COMMIT(1, m_child3->SetAutomaticallyComputeRasterScale(true ));
330 330
331 EXPECT_FALSE(child4->parent()); 331 EXPECT_FALSE(child4->parent());
332 332
333 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), m_parent->replaceChild(m_child2. get(), child4)); 333 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent_->ReplaceChild(m_child2.g et(), child4));
334 EXPECT_FALSE(m_parent->needsDisplayForTesting()); 334 EXPECT_FALSE(parent_->NeedsDisplayForTesting());
335 EXPECT_FALSE(m_child1->needsDisplayForTesting()); 335 EXPECT_FALSE(m_child1->NeedsDisplayForTesting());
336 EXPECT_FALSE(m_child2->needsDisplayForTesting()); 336 EXPECT_FALSE(m_child2->NeedsDisplayForTesting());
337 EXPECT_FALSE(m_child3->needsDisplayForTesting()); 337 EXPECT_FALSE(m_child3->NeedsDisplayForTesting());
338 EXPECT_FALSE(child4->needsDisplayForTesting()); 338 EXPECT_FALSE(child4->NeedsDisplayForTesting());
339 339
340 ASSERT_EQ(3U, m_parent->children().size()); 340 ASSERT_EQ(3U, parent_->children().size());
341 EXPECT_EQ(m_child1, m_parent->children()[0]); 341 EXPECT_EQ(m_child1, parent_->children()[0]);
342 EXPECT_EQ(child4, m_parent->children()[1]); 342 EXPECT_EQ(child4, parent_->children()[1]);
343 EXPECT_EQ(m_child3, m_parent->children()[2]); 343 EXPECT_EQ(m_child3, parent_->children()[2]);
344 EXPECT_EQ(m_parent.get(), child4->parent()); 344 EXPECT_EQ(parent_.get(), child4->parent());
345 345
346 EXPECT_FALSE(m_child2->parent()); 346 EXPECT_FALSE(m_child2->parent());
347 } 347 }
348 348
349 TEST_F(LayerTest, replaceChildWithNewChildThatHasOtherParent) 349 TEST_F(LayerTest, replaceChildWithNewChildThatHasOtherParent)
350 { 350 {
351 createSimpleTestTree(); 351 createSimpleTestTree();
352 352
353 // create another simple tree with testLayer and child4. 353 // create another simple tree with testLayer and child4.
354 scoped_refptr<Layer> testLayer = Layer::create(); 354 scoped_refptr<Layer> testLayer = Layer::Create();
355 scoped_refptr<Layer> child4 = Layer::create(); 355 scoped_refptr<Layer> child4 = Layer::Create();
356 testLayer->addChild(child4); 356 testLayer->AddChild(child4);
357 ASSERT_EQ(1U, testLayer->children().size()); 357 ASSERT_EQ(1U, testLayer->children().size());
358 EXPECT_EQ(child4, testLayer->children()[0]); 358 EXPECT_EQ(child4, testLayer->children()[0]);
359 EXPECT_EQ(testLayer.get(), child4->parent()); 359 EXPECT_EQ(testLayer.get(), child4->parent());
360 360
361 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), m_parent->replaceChild(m_child2. get(), child4)); 361 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent_->ReplaceChild(m_child2.g et(), child4));
362 362
363 ASSERT_EQ(3U, m_parent->children().size()); 363 ASSERT_EQ(3U, parent_->children().size());
364 EXPECT_EQ(m_child1, m_parent->children()[0]); 364 EXPECT_EQ(m_child1, parent_->children()[0]);
365 EXPECT_EQ(child4, m_parent->children()[1]); 365 EXPECT_EQ(child4, parent_->children()[1]);
366 EXPECT_EQ(m_child3, m_parent->children()[2]); 366 EXPECT_EQ(m_child3, parent_->children()[2]);
367 EXPECT_EQ(m_parent.get(), child4->parent()); 367 EXPECT_EQ(parent_.get(), child4->parent());
368 368
369 // testLayer should no longer have child4, 369 // testLayer should no longer have child4,
370 // and child2 should no longer have a parent. 370 // and child2 should no longer have a parent.
371 ASSERT_EQ(0U, testLayer->children().size()); 371 ASSERT_EQ(0U, testLayer->children().size());
372 EXPECT_FALSE(m_child2->parent()); 372 EXPECT_FALSE(m_child2->parent());
373 } 373 }
374 374
375 TEST_F(LayerTest, replaceChildWithSameChild) 375 TEST_F(LayerTest, replaceChildWithSameChild)
376 { 376 {
377 createSimpleTestTree(); 377 createSimpleTestTree();
378 378
379 // setNeedsFullTreeSync / setNeedsCommit should not be called because its th e same child 379 // setNeedsFullTreeSync / setNeedsCommit should not be called because its th e same child
380 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(0); 380 EXPECT_CALL(*layer_tree_host_, setNeedsCommit()).Times(0);
381 EXPECT_CALL(*m_layerTreeHost, setNeedsFullTreeSync()).Times(0); 381 EXPECT_CALL(*layer_tree_host_, setNeedsFullTreeSync()).Times(0);
382 m_parent->replaceChild(m_child2.get(), m_child2); 382 parent_->ReplaceChild(m_child2.get(), m_child2);
383 383
384 verifyTestTreeInitialState(); 384 verifyTestTreeInitialState();
385 } 385 }
386 386
387 TEST_F(LayerTest, removeAllChildren) 387 TEST_F(LayerTest, removeAllChildren)
388 { 388 {
389 createSimpleTestTree(); 389 createSimpleTestTree();
390 390
391 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(3), m_parent->removeAllChildren()); 391 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(3), parent_->RemoveAllChildren());
392 392
393 ASSERT_EQ(0U, m_parent->children().size()); 393 ASSERT_EQ(0U, parent_->children().size());
394 EXPECT_FALSE(m_child1->parent()); 394 EXPECT_FALSE(m_child1->parent());
395 EXPECT_FALSE(m_child2->parent()); 395 EXPECT_FALSE(m_child2->parent());
396 EXPECT_FALSE(m_child3->parent()); 396 EXPECT_FALSE(m_child3->parent());
397 } 397 }
398 398
399 TEST_F(LayerTest, setChildren) 399 TEST_F(LayerTest, setChildren)
400 { 400 {
401 scoped_refptr<Layer> oldParent = Layer::create(); 401 scoped_refptr<Layer> oldParent = Layer::Create();
402 scoped_refptr<Layer> newParent = Layer::create(); 402 scoped_refptr<Layer> newParent = Layer::Create();
403 403
404 scoped_refptr<Layer> child1 = Layer::create(); 404 scoped_refptr<Layer> child1 = Layer::Create();
405 scoped_refptr<Layer> child2 = Layer::create(); 405 scoped_refptr<Layer> child2 = Layer::Create();
406 406
407 std::vector<scoped_refptr<Layer> > newChildren; 407 std::vector<scoped_refptr<Layer> > newChildren;
408 newChildren.push_back(child1); 408 newChildren.push_back(child1);
409 newChildren.push_back(child2); 409 newChildren.push_back(child2);
410 410
411 // Set up and verify initial test conditions: child1 has a parent, child2 ha s no parent. 411 // Set up and verify initial test conditions: child1 has a parent, child2 ha s no parent.
412 oldParent->addChild(child1); 412 oldParent->AddChild(child1);
413 ASSERT_EQ(0U, newParent->children().size()); 413 ASSERT_EQ(0U, newParent->children().size());
414 EXPECT_EQ(oldParent.get(), child1->parent()); 414 EXPECT_EQ(oldParent.get(), child1->parent());
415 EXPECT_FALSE(child2->parent()); 415 EXPECT_FALSE(child2->parent());
416 416
417 newParent->setLayerTreeHost(m_layerTreeHost.get()); 417 newParent->SetLayerTreeHost(layer_tree_host_.get());
418 418
419 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), newParent->setChildren(newChildr en)); 419 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), newParent->SetChildren(newChildr en));
420 420
421 ASSERT_EQ(2U, newParent->children().size()); 421 ASSERT_EQ(2U, newParent->children().size());
422 EXPECT_EQ(newParent.get(), child1->parent()); 422 EXPECT_EQ(newParent.get(), child1->parent());
423 EXPECT_EQ(newParent.get(), child2->parent()); 423 EXPECT_EQ(newParent.get(), child2->parent());
424 424
425 EXPECT_CALL(*m_layerTreeHost, setNeedsFullTreeSync()).Times(AtLeast(1)); 425 EXPECT_CALL(*layer_tree_host_, setNeedsFullTreeSync()).Times(AtLeast(1));
426 } 426 }
427 427
428 TEST_F(LayerTest, getRootLayerAfterTreeManipulations) 428 TEST_F(LayerTest, getRootLayerAfterTreeManipulations)
429 { 429 {
430 createSimpleTestTree(); 430 createSimpleTestTree();
431 431
432 // For this test we don't care about setNeedsFullTreeSync calls. 432 // For this test we don't care about setNeedsFullTreeSync calls.
433 EXPECT_CALL(*m_layerTreeHost, setNeedsFullTreeSync()).Times(AnyNumber()); 433 EXPECT_CALL(*layer_tree_host_, setNeedsFullTreeSync()).Times(AnyNumber());
434 434
435 scoped_refptr<Layer> child4 = Layer::create(); 435 scoped_refptr<Layer> child4 = Layer::Create();
436 436
437 EXPECT_EQ(m_parent.get(), m_parent->rootLayer()); 437 EXPECT_EQ(parent_.get(), parent_->RootLayer());
438 EXPECT_EQ(m_parent.get(), m_child1->rootLayer()); 438 EXPECT_EQ(parent_.get(), m_child1->RootLayer());
439 EXPECT_EQ(m_parent.get(), m_child2->rootLayer()); 439 EXPECT_EQ(parent_.get(), m_child2->RootLayer());
440 EXPECT_EQ(m_parent.get(), m_child3->rootLayer()); 440 EXPECT_EQ(parent_.get(), m_child3->RootLayer());
441 EXPECT_EQ(child4.get(), child4->rootLayer()); 441 EXPECT_EQ(child4.get(), child4->RootLayer());
442 EXPECT_EQ(m_parent.get(), m_grandChild1->rootLayer()); 442 EXPECT_EQ(parent_.get(), m_grandChild1->RootLayer());
443 EXPECT_EQ(m_parent.get(), m_grandChild2->rootLayer()); 443 EXPECT_EQ(parent_.get(), m_grandChild2->RootLayer());
444 EXPECT_EQ(m_parent.get(), m_grandChild3->rootLayer()); 444 EXPECT_EQ(parent_.get(), m_grandChild3->RootLayer());
445 445
446 m_child1->removeFromParent(); 446 m_child1->RemoveFromParent();
447 447
448 // child1 and its children, grandChild1 and grandChild2 are now on a separat e subtree. 448 // child1 and its children, grandChild1 and grandChild2 are now on a separat e subtree.
449 EXPECT_EQ(m_parent.get(), m_parent->rootLayer()); 449 EXPECT_EQ(parent_.get(), parent_->RootLayer());
450 EXPECT_EQ(m_child1.get(), m_child1->rootLayer()); 450 EXPECT_EQ(m_child1.get(), m_child1->RootLayer());
451 EXPECT_EQ(m_parent.get(), m_child2->rootLayer()); 451 EXPECT_EQ(parent_.get(), m_child2->RootLayer());
452 EXPECT_EQ(m_parent.get(), m_child3->rootLayer()); 452 EXPECT_EQ(parent_.get(), m_child3->RootLayer());
453 EXPECT_EQ(child4.get(), child4->rootLayer()); 453 EXPECT_EQ(child4.get(), child4->RootLayer());
454 EXPECT_EQ(m_child1.get(), m_grandChild1->rootLayer()); 454 EXPECT_EQ(m_child1.get(), m_grandChild1->RootLayer());
455 EXPECT_EQ(m_child1.get(), m_grandChild2->rootLayer()); 455 EXPECT_EQ(m_child1.get(), m_grandChild2->RootLayer());
456 EXPECT_EQ(m_parent.get(), m_grandChild3->rootLayer()); 456 EXPECT_EQ(parent_.get(), m_grandChild3->RootLayer());
457 457
458 m_grandChild3->addChild(child4); 458 m_grandChild3->AddChild(child4);
459 459
460 EXPECT_EQ(m_parent.get(), m_parent->rootLayer()); 460 EXPECT_EQ(parent_.get(), parent_->RootLayer());
461 EXPECT_EQ(m_child1.get(), m_child1->rootLayer()); 461 EXPECT_EQ(m_child1.get(), m_child1->RootLayer());
462 EXPECT_EQ(m_parent.get(), m_child2->rootLayer()); 462 EXPECT_EQ(parent_.get(), m_child2->RootLayer());
463 EXPECT_EQ(m_parent.get(), m_child3->rootLayer()); 463 EXPECT_EQ(parent_.get(), m_child3->RootLayer());
464 EXPECT_EQ(m_parent.get(), child4->rootLayer()); 464 EXPECT_EQ(parent_.get(), child4->RootLayer());
465 EXPECT_EQ(m_child1.get(), m_grandChild1->rootLayer()); 465 EXPECT_EQ(m_child1.get(), m_grandChild1->RootLayer());
466 EXPECT_EQ(m_child1.get(), m_grandChild2->rootLayer()); 466 EXPECT_EQ(m_child1.get(), m_grandChild2->RootLayer());
467 EXPECT_EQ(m_parent.get(), m_grandChild3->rootLayer()); 467 EXPECT_EQ(parent_.get(), m_grandChild3->RootLayer());
468 468
469 m_child2->replaceChild(m_grandChild3.get(), m_child1); 469 m_child2->ReplaceChild(m_grandChild3.get(), m_child1);
470 470
471 // grandChild3 gets orphaned and the child1 subtree gets planted back into t he tree under child2. 471 // grandChild3 gets orphaned and the child1 subtree gets planted back into t he tree under child2.
472 EXPECT_EQ(m_parent.get(), m_parent->rootLayer()); 472 EXPECT_EQ(parent_.get(), parent_->RootLayer());
473 EXPECT_EQ(m_parent.get(), m_child1->rootLayer()); 473 EXPECT_EQ(parent_.get(), m_child1->RootLayer());
474 EXPECT_EQ(m_parent.get(), m_child2->rootLayer()); 474 EXPECT_EQ(parent_.get(), m_child2->RootLayer());
475 EXPECT_EQ(m_parent.get(), m_child3->rootLayer()); 475 EXPECT_EQ(parent_.get(), m_child3->RootLayer());
476 EXPECT_EQ(m_grandChild3.get(), child4->rootLayer()); 476 EXPECT_EQ(m_grandChild3.get(), child4->RootLayer());
477 EXPECT_EQ(m_parent.get(), m_grandChild1->rootLayer()); 477 EXPECT_EQ(parent_.get(), m_grandChild1->RootLayer());
478 EXPECT_EQ(m_parent.get(), m_grandChild2->rootLayer()); 478 EXPECT_EQ(parent_.get(), m_grandChild2->RootLayer());
479 EXPECT_EQ(m_grandChild3.get(), m_grandChild3->rootLayer()); 479 EXPECT_EQ(m_grandChild3.get(), m_grandChild3->RootLayer());
480 } 480 }
481 481
482 TEST_F(LayerTest, checkSetNeedsDisplayCausesCorrectBehavior) 482 TEST_F(LayerTest, checkSetNeedsDisplayCausesCorrectBehavior)
483 { 483 {
484 // The semantics for setNeedsDisplay which are tested here: 484 // The semantics for setNeedsDisplay which are tested here:
485 // 1. sets needsDisplay flag appropriately. 485 // 1. sets needsDisplay flag appropriately.
486 // 2. indirectly calls setNeedsCommit, exactly once for each call to setNe edsDisplay. 486 // 2. indirectly calls setNeedsCommit, exactly once for each call to setNe edsDisplay.
487 487
488 scoped_refptr<Layer> testLayer = Layer::create(); 488 scoped_refptr<Layer> testLayer = Layer::Create();
489 testLayer->setLayerTreeHost(m_layerTreeHost.get()); 489 testLayer->SetLayerTreeHost(layer_tree_host_.get());
490 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setIsDrawable(true)); 490 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetIsDrawable(true));
491 491
492 gfx::Size testBounds = gfx::Size(501, 508); 492 gfx::Size testBounds = gfx::Size(501, 508);
493 493
494 gfx::RectF dirty1 = gfx::RectF(10, 15, 1, 2); 494 gfx::RectF dirty1 = gfx::RectF(10, 15, 1, 2);
495 gfx::RectF dirty2 = gfx::RectF(20, 25, 3, 4); 495 gfx::RectF dirty2 = gfx::RectF(20, 25, 3, 4);
496 gfx::RectF emptyDirtyRect = gfx::RectF(40, 45, 0, 0); 496 gfx::RectF emptyDirtyRect = gfx::RectF(40, 45, 0, 0);
497 gfx::RectF outOfBoundsDirtyRect = gfx::RectF(400, 405, 500, 502); 497 gfx::RectF outOfBoundsDirtyRect = gfx::RectF(400, 405, 500, 502);
498 498
499 // Before anything, testLayer should not be dirty. 499 // Before anything, testLayer should not be dirty.
500 EXPECT_FALSE(testLayer->needsDisplayForTesting()); 500 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
501 501
502 // This is just initialization, but setNeedsCommit behavior is verified anyw ay to avoid warnings. 502 // This is just initialization, but setNeedsCommit behavior is verified anyw ay to avoid warnings.
503 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setBounds(testBounds)); 503 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetBounds(testBounds));
504 EXPECT_TRUE(testLayer->needsDisplayForTesting()); 504 EXPECT_TRUE(testLayer->NeedsDisplayForTesting());
505 505
506 // The real test begins here. 506 // The real test begins here.
507 testLayer->resetNeedsDisplayForTesting(); 507 testLayer->ResetNeedsDisplayForTesting();
508 EXPECT_FALSE(testLayer->needsDisplayForTesting()); 508 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
509 509
510 // Case 1: Layer should accept dirty rects that go beyond its bounds. 510 // Case 1: Layer should accept dirty rects that go beyond its bounds.
511 testLayer->resetNeedsDisplayForTesting(); 511 testLayer->ResetNeedsDisplayForTesting();
512 EXPECT_FALSE(testLayer->needsDisplayForTesting()); 512 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
513 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setNeedsDisplayRect(outOfBoundsDirtyRe ct)); 513 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetNeedsDisplayRect(outOfBoundsDirtyRe ct));
514 EXPECT_TRUE(testLayer->needsDisplayForTesting()); 514 EXPECT_TRUE(testLayer->NeedsDisplayForTesting());
515 testLayer->resetNeedsDisplayForTesting(); 515 testLayer->ResetNeedsDisplayForTesting();
516 516
517 // Case 2: setNeedsDisplay() without the dirty rect arg. 517 // Case 2: SetNeedsDisplay() without the dirty rect arg.
518 testLayer->resetNeedsDisplayForTesting(); 518 testLayer->ResetNeedsDisplayForTesting();
519 EXPECT_FALSE(testLayer->needsDisplayForTesting()); 519 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
520 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setNeedsDisplay()); 520 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetNeedsDisplay());
521 EXPECT_TRUE(testLayer->needsDisplayForTesting()); 521 EXPECT_TRUE(testLayer->NeedsDisplayForTesting());
522 testLayer->resetNeedsDisplayForTesting(); 522 testLayer->ResetNeedsDisplayForTesting();
523 523
524 // Case 3: setNeedsDisplay() with a non-drawable layer 524 // Case 3: SetNeedsDisplay() with a non-drawable layer
525 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setIsDrawable(false)); 525 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetIsDrawable(false));
526 testLayer->resetNeedsDisplayForTesting(); 526 testLayer->ResetNeedsDisplayForTesting();
527 EXPECT_FALSE(testLayer->needsDisplayForTesting()); 527 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
528 EXPECT_SET_NEEDS_COMMIT(0, testLayer->setNeedsDisplayRect(dirty1)); 528 EXPECT_SET_NEEDS_COMMIT(0, testLayer->SetNeedsDisplayRect(dirty1));
529 EXPECT_TRUE(testLayer->needsDisplayForTesting()); 529 EXPECT_TRUE(testLayer->NeedsDisplayForTesting());
530 } 530 }
531 531
532 TEST_F(LayerTest, checkPropertyChangeCausesCorrectBehavior) 532 TEST_F(LayerTest, checkPropertyChangeCausesCorrectBehavior)
533 { 533 {
534 scoped_refptr<Layer> testLayer = Layer::create(); 534 scoped_refptr<Layer> testLayer = Layer::Create();
535 testLayer->setLayerTreeHost(m_layerTreeHost.get()); 535 testLayer->SetLayerTreeHost(layer_tree_host_.get());
536 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setIsDrawable(true)); 536 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetIsDrawable(true));
537 537
538 scoped_refptr<Layer> dummyLayer1 = Layer::create(); // just a dummy layer fo r this test case. 538 scoped_refptr<Layer> dummyLayer1 = Layer::Create(); // just a dummy layer fo r this test case.
539 scoped_refptr<Layer> dummyLayer2 = Layer::create(); // just a dummy layer fo r this test case. 539 scoped_refptr<Layer> dummyLayer2 = Layer::Create(); // just a dummy layer fo r this test case.
540 540
541 // sanity check of initial test condition 541 // sanity check of initial test condition
542 EXPECT_FALSE(testLayer->needsDisplayForTesting()); 542 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
543 543
544 // Next, test properties that should call setNeedsCommit (but not setNeedsDi splay) 544 // Next, test properties that should call setNeedsCommit (but not setNeedsDi splay)
545 // All properties need to be set to new values in order for setNeedsCommit t o be called. 545 // All properties need to be set to new values in order for setNeedsCommit t o be called.
546 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setAnchorPoint(gfx::PointF(1.23f, 4.56 f))); 546 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetAnchorPoint(gfx::PointF(1.23f, 4.56 f)));
547 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setAnchorPointZ(0.7f)); 547 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetAnchorPointZ(0.7f));
548 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setBackgroundColor(SK_ColorLTGRAY)); 548 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetBackgroundColor(SK_ColorLTGRAY));
549 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setMasksToBounds(true)); 549 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetMasksToBounds(true));
550 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setOpacity(0.5)); 550 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetOpacity(0.5));
551 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setContentsOpaque(true)); 551 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetContentsOpaque(true));
552 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setPosition(gfx::PointF(4, 9))); 552 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetPosition(gfx::PointF(4, 9)));
553 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setSublayerTransform(gfx::Transform(0. 0, 0.0, 0.0, 0.0, 0.0, 0.0))); 553 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetSublayerTransform(gfx::Transform(0. 0, 0.0, 0.0, 0.0, 0.0, 0.0)));
554 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setScrollable(true)); 554 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetScrollable(true));
555 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setScrollOffset(gfx::Vector2d(10, 10)) ); 555 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetScrollOffset(gfx::Vector2d(10, 10)) );
556 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setShouldScrollOnMainThread(true)); 556 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetShouldScrollOnMainThread(true));
557 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setNonFastScrollableRegion(gfx::Rect(1 , 1, 2, 2))); 557 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetNonFastScrollableRegion(gfx::Rect(1 , 1, 2, 2)));
558 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setHaveWheelEventHandlers(true)); 558 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetHaveWheelEventHandlers(true));
559 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setTransform(gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0))); 559 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetTransform(gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)));
560 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setDoubleSided(false)); 560 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetDoubleSided(false));
561 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setDebugName("Test Layer")); 561 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetDebugName("Test Layer"));
562 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setDrawCheckerboardForMissingTiles(!te stLayer->drawCheckerboardForMissingTiles())); 562 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetDrawCheckerboardForMissingTiles(!te stLayer->DrawCheckerboardForMissingTiles()));
563 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setForceRenderSurface(true)); 563 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetForceRenderSurface(true));
564 564
565 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, testLayer->setMaskLayer(dummyLayer1.get() )); 565 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, testLayer->SetMaskLayer(dummyLayer1.get() ));
566 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, testLayer->setReplicaLayer(dummyLayer2.ge t())); 566 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, testLayer->SetReplicaLayer(dummyLayer2.ge t()));
567 567
568 // The above tests should not have caused a change to the needsDisplay flag. 568 // The above tests should not have caused a change to the needsDisplay flag.
569 EXPECT_FALSE(testLayer->needsDisplayForTesting()); 569 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
570 570
571 // As layers are removed from the tree, they will cause a tree sync. 571 // As layers are removed from the tree, they will cause a tree sync.
572 EXPECT_CALL(*m_layerTreeHost, setNeedsFullTreeSync()).Times((AnyNumber())); 572 EXPECT_CALL(*layer_tree_host_, setNeedsFullTreeSync()).Times((AnyNumber()));
573 } 573 }
574 574
575 TEST_F(LayerTest, setBoundsTriggersSetNeedsRedrawAfterGettingNonEmptyBounds) 575 TEST_F(LayerTest, setBoundsTriggersSetNeedsRedrawAfterGettingNonEmptyBounds)
576 { 576 {
577 scoped_refptr<Layer> testLayer = Layer::create(); 577 scoped_refptr<Layer> testLayer = Layer::Create();
578 testLayer->setLayerTreeHost(m_layerTreeHost.get()); 578 testLayer->SetLayerTreeHost(layer_tree_host_.get());
579 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setIsDrawable(true)); 579 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetIsDrawable(true));
580 580
581 EXPECT_FALSE(testLayer->needsDisplayForTesting()); 581 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
582 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setBounds(gfx::Size(0, 10))); 582 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetBounds(gfx::Size(0, 10)));
583 EXPECT_FALSE(testLayer->needsDisplayForTesting()); 583 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
584 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setBounds(gfx::Size(10, 10))); 584 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetBounds(gfx::Size(10, 10)));
585 EXPECT_TRUE(testLayer->needsDisplayForTesting()); 585 EXPECT_TRUE(testLayer->NeedsDisplayForTesting());
586 586
587 testLayer->resetNeedsDisplayForTesting(); 587 testLayer->ResetNeedsDisplayForTesting();
588 EXPECT_FALSE(testLayer->needsDisplayForTesting()); 588 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
589 589
590 // Calling setBounds only invalidates on the first time. 590 // Calling setBounds only invalidates on the first time.
591 EXPECT_SET_NEEDS_COMMIT(1, testLayer->setBounds(gfx::Size(7, 10))); 591 EXPECT_SET_NEEDS_COMMIT(1, testLayer->SetBounds(gfx::Size(7, 10)));
592 EXPECT_FALSE(testLayer->needsDisplayForTesting()); 592 EXPECT_FALSE(testLayer->NeedsDisplayForTesting());
593 } 593 }
594 594
595 TEST_F(LayerTest, verifyPushPropertiesAccumulatesUpdateRect) 595 TEST_F(LayerTest, verifyPushPropertiesAccumulatesUpdateRect)
596 { 596 {
597 scoped_refptr<Layer> testLayer = Layer::create(); 597 scoped_refptr<Layer> testLayer = Layer::Create();
598 scoped_ptr<LayerImpl> implLayer = LayerImpl::create(m_hostImpl.activeTree(), 1); 598 scoped_ptr<LayerImpl> implLayer = LayerImpl::Create(m_hostImpl.activeTree(), 1);
599 599
600 testLayer->setNeedsDisplayRect(gfx::RectF(gfx::PointF(), gfx::SizeF(5, 5))); 600 testLayer->SetNeedsDisplayRect(gfx::RectF(gfx::PointF(), gfx::SizeF(5, 5)));
601 testLayer->pushPropertiesTo(implLayer.get()); 601 testLayer->PushPropertiesTo(implLayer.get());
602 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(), gfx::SizeF(5, 5)), implLayer- >updateRect()); 602 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(), gfx::SizeF(5, 5)), implLayer- >update_rect());
603 603
604 // The LayerImpl's updateRect should be accumulated here, since we did not d o anything to clear it. 604 // The LayerImpl's updateRect should be accumulated here, since we did not d o anything to clear it.
605 testLayer->setNeedsDisplayRect(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5))); 605 testLayer->SetNeedsDisplayRect(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5)));
606 testLayer->pushPropertiesTo(implLayer.get()); 606 testLayer->PushPropertiesTo(implLayer.get());
607 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(), gfx::SizeF(15, 15)), implLaye r->updateRect()); 607 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(), gfx::SizeF(15, 15)), implLaye r->update_rect());
608 608
609 // If we do clear the LayerImpl side, then the next updateRect should be fre sh without accumulation. 609 // If we do clear the LayerImpl side, then the next updateRect should be fre sh without accumulation.
610 implLayer->resetAllChangeTrackingForSubtree(); 610 implLayer->ResetAllChangeTrackingForSubtree();
611 testLayer->setNeedsDisplayRect(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5))); 611 testLayer->SetNeedsDisplayRect(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5)));
612 testLayer->pushPropertiesTo(implLayer.get()); 612 testLayer->PushPropertiesTo(implLayer.get());
613 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5)), impl Layer->updateRect()); 613 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5)), impl Layer->update_rect());
614 } 614 }
615 615
616 TEST_F(LayerTest, verifyPushPropertiesCausesSurfacePropertyChangedForTransform) 616 TEST_F(LayerTest, verifyPushPropertiesCausesSurfacePropertyChangedForTransform)
617 { 617 {
618 scoped_refptr<Layer> testLayer = Layer::create(); 618 scoped_refptr<Layer> testLayer = Layer::Create();
619 scoped_ptr<LayerImpl> implLayer = LayerImpl::create(m_hostImpl.activeTree(), 1); 619 scoped_ptr<LayerImpl> implLayer = LayerImpl::Create(m_hostImpl.activeTree(), 1);
620 620
621 gfx::Transform transform; 621 gfx::Transform transform;
622 transform.Rotate(45.0); 622 transform.Rotate(45.0);
623 testLayer->setTransform(transform); 623 testLayer->SetTransform(transform);
624 624
625 EXPECT_FALSE(implLayer->layerSurfacePropertyChanged()); 625 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged());
626 626
627 testLayer->pushPropertiesTo(implLayer.get()); 627 testLayer->PushPropertiesTo(implLayer.get());
628 628
629 EXPECT_TRUE(implLayer->layerSurfacePropertyChanged()); 629 EXPECT_TRUE(implLayer->LayerSurfacePropertyChanged());
630 } 630 }
631 631
632 TEST_F(LayerTest, verifyPushPropertiesCausesSurfacePropertyChangedForOpacity) 632 TEST_F(LayerTest, verifyPushPropertiesCausesSurfacePropertyChangedForOpacity)
633 { 633 {
634 scoped_refptr<Layer> testLayer = Layer::create(); 634 scoped_refptr<Layer> testLayer = Layer::Create();
635 scoped_ptr<LayerImpl> implLayer = LayerImpl::create(m_hostImpl.activeTree(), 1); 635 scoped_ptr<LayerImpl> implLayer = LayerImpl::Create(m_hostImpl.activeTree(), 1);
636 636
637 testLayer->setOpacity(0.5); 637 testLayer->SetOpacity(0.5);
638 638
639 EXPECT_FALSE(implLayer->layerSurfacePropertyChanged()); 639 EXPECT_FALSE(implLayer->LayerSurfacePropertyChanged());
640 640
641 testLayer->pushPropertiesTo(implLayer.get()); 641 testLayer->PushPropertiesTo(implLayer.get());
642 642
643 EXPECT_TRUE(implLayer->layerSurfacePropertyChanged()); 643 EXPECT_TRUE(implLayer->LayerSurfacePropertyChanged());
644 } 644 }
645 645
646 TEST_F(LayerTest, maskAndReplicaHasParent) 646 TEST_F(LayerTest, maskAndReplicaHasParent)
647 { 647 {
648 scoped_refptr<Layer> parent = Layer::create(); 648 scoped_refptr<Layer> parent = Layer::Create();
649 scoped_refptr<Layer> child = Layer::create(); 649 scoped_refptr<Layer> child = Layer::Create();
650 scoped_refptr<Layer> mask = Layer::create(); 650 scoped_refptr<Layer> mask = Layer::Create();
651 scoped_refptr<Layer> replica = Layer::create(); 651 scoped_refptr<Layer> replica = Layer::Create();
652 scoped_refptr<Layer> replicaMask = Layer::create(); 652 scoped_refptr<Layer> replicaMask = Layer::Create();
653 scoped_refptr<Layer> maskReplacement = Layer::create(); 653 scoped_refptr<Layer> maskReplacement = Layer::Create();
654 scoped_refptr<Layer> replicaReplacement = Layer::create(); 654 scoped_refptr<Layer> replicaReplacement = Layer::Create();
655 scoped_refptr<Layer> replicaMaskReplacement = Layer::create(); 655 scoped_refptr<Layer> replicaMaskReplacement = Layer::Create();
656 656
657 parent->addChild(child); 657 parent->AddChild(child);
658 child->setMaskLayer(mask.get()); 658 child->SetMaskLayer(mask.get());
659 child->setReplicaLayer(replica.get()); 659 child->SetReplicaLayer(replica.get());
660 replica->setMaskLayer(replicaMask.get()); 660 replica->SetMaskLayer(replicaMask.get());
661 661
662 EXPECT_EQ(parent, child->parent()); 662 EXPECT_EQ(parent, child->parent());
663 EXPECT_EQ(child, mask->parent()); 663 EXPECT_EQ(child, mask->parent());
664 EXPECT_EQ(child, replica->parent()); 664 EXPECT_EQ(child, replica->parent());
665 EXPECT_EQ(replica, replicaMask->parent()); 665 EXPECT_EQ(replica, replicaMask->parent());
666 666
667 replica->setMaskLayer(replicaMaskReplacement.get()); 667 replica->SetMaskLayer(replicaMaskReplacement.get());
668 EXPECT_EQ(NULL, replicaMask->parent()); 668 EXPECT_EQ(NULL, replicaMask->parent());
669 EXPECT_EQ(replica, replicaMaskReplacement->parent()); 669 EXPECT_EQ(replica, replicaMaskReplacement->parent());
670 670
671 child->setMaskLayer(maskReplacement.get()); 671 child->SetMaskLayer(maskReplacement.get());
672 EXPECT_EQ(NULL, mask->parent()); 672 EXPECT_EQ(NULL, mask->parent());
673 EXPECT_EQ(child, maskReplacement->parent()); 673 EXPECT_EQ(child, maskReplacement->parent());
674 674
675 child->setReplicaLayer(replicaReplacement.get()); 675 child->SetReplicaLayer(replicaReplacement.get());
676 EXPECT_EQ(NULL, replica->parent()); 676 EXPECT_EQ(NULL, replica->parent());
677 EXPECT_EQ(child, replicaReplacement->parent()); 677 EXPECT_EQ(child, replicaReplacement->parent());
678 678
679 EXPECT_EQ(replica, replica->maskLayer()->parent()); 679 EXPECT_EQ(replica, replica->mask_layer()->parent());
680 } 680 }
681 681
682 class FakeLayerImplTreeHost : public LayerTreeHost { 682 class FakeLayerImplTreeHost : public LayerTreeHost {
683 public: 683 public:
684 static scoped_ptr<FakeLayerImplTreeHost> create() 684 static scoped_ptr<FakeLayerImplTreeHost> Create()
685 { 685 {
686 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost(LayerTr eeSettings())); 686 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost(LayerTr eeSettings()));
687 // The initialize call will fail, since our client doesn't provide a val id GraphicsContext3D, but it doesn't matter in the tests that use this fake so i gnore the return value. 687 // The initialize call will fail, since our client doesn't provide a val id GraphicsContext3D, but it doesn't matter in the tests that use this fake so i gnore the return value.
688 host->initialize(scoped_ptr<Thread>(NULL)); 688 host->initialize(scoped_ptr<Thread>(NULL));
689 return host.Pass(); 689 return host.Pass();
690 } 690 }
691 691
692 static scoped_ptr<FakeLayerImplTreeHost> create(LayerTreeSettings settings) 692 static scoped_ptr<FakeLayerImplTreeHost> Create(LayerTreeSettings settings)
693 { 693 {
694 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost(setting s)); 694 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost(setting s));
695 host->initialize(scoped_ptr<Thread>(NULL)); 695 host->initialize(scoped_ptr<Thread>(NULL));
696 return host.Pass(); 696 return host.Pass();
697 } 697 }
698 698
699 private: 699 private:
700 FakeLayerImplTreeHost(const LayerTreeSettings& settings) 700 FakeLayerImplTreeHost(const LayerTreeSettings& settings)
701 : LayerTreeHost(&m_client, settings) 701 : LayerTreeHost(&m_client, settings)
702 { 702 {
703 } 703 }
704 704
705 FakeLayerImplTreeHostClient m_client; 705 FakeLayerImplTreeHostClient m_client;
706 }; 706 };
707 707
708 void assertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host) 708 void assertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host)
709 { 709 {
710 EXPECT_EQ(host, layer->layerTreeHost()); 710 EXPECT_EQ(host, layer->layer_tree_host());
711 711
712 for (size_t i = 0; i < layer->children().size(); ++i) 712 for (size_t i = 0; i < layer->children().size(); ++i)
713 assertLayerTreeHostMatchesForSubtree(layer->children()[i].get(), host); 713 assertLayerTreeHostMatchesForSubtree(layer->children()[i].get(), host);
714 714
715 if (layer->maskLayer()) 715 if (layer->mask_layer())
716 assertLayerTreeHostMatchesForSubtree(layer->maskLayer(), host); 716 assertLayerTreeHostMatchesForSubtree(layer->mask_layer(), host);
717 717
718 if (layer->replicaLayer()) 718 if (layer->replica_layer())
719 assertLayerTreeHostMatchesForSubtree(layer->replicaLayer(), host); 719 assertLayerTreeHostMatchesForSubtree(layer->replica_layer(), host);
720 } 720 }
721 721
722 TEST(LayerLayerTreeHostTest, enteringTree) 722 TEST(LayerLayerTreeHostTest, enteringTree)
723 { 723 {
724 scoped_refptr<Layer> parent = Layer::create(); 724 scoped_refptr<Layer> parent = Layer::Create();
725 scoped_refptr<Layer> child = Layer::create(); 725 scoped_refptr<Layer> child = Layer::Create();
726 scoped_refptr<Layer> mask = Layer::create(); 726 scoped_refptr<Layer> mask = Layer::Create();
727 scoped_refptr<Layer> replica = Layer::create(); 727 scoped_refptr<Layer> replica = Layer::Create();
728 scoped_refptr<Layer> replicaMask = Layer::create(); 728 scoped_refptr<Layer> replicaMask = Layer::Create();
729 729
730 // Set up a detached tree of layers. The host pointer should be nil for thes e layers. 730 // Set up a detached tree of layers. The host pointer should be nil for thes e layers.
731 parent->addChild(child); 731 parent->AddChild(child);
732 child->setMaskLayer(mask.get()); 732 child->SetMaskLayer(mask.get());
733 child->setReplicaLayer(replica.get()); 733 child->SetReplicaLayer(replica.get());
734 replica->setMaskLayer(replicaMask.get()); 734 replica->SetMaskLayer(replicaMask.get());
735 735
736 assertLayerTreeHostMatchesForSubtree(parent.get(), 0); 736 assertLayerTreeHostMatchesForSubtree(parent.get(), 0);
737 737
738 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat e()); 738 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::Creat e());
739 // Setting the root layer should set the host pointer for all layers in the tree. 739 // Setting the root layer should set the host pointer for all layers in the tree.
740 layerTreeHost->setRootLayer(parent.get()); 740 layerTreeHost->setRootLayer(parent.get());
741 741
742 assertLayerTreeHostMatchesForSubtree(parent.get(), layerTreeHost.get()); 742 assertLayerTreeHostMatchesForSubtree(parent.get(), layerTreeHost.get());
743 743
744 // Clearing the root layer should also clear out the host pointers for all l ayers in the tree. 744 // Clearing the root layer should also clear out the host pointers for all l ayers in the tree.
745 layerTreeHost->setRootLayer(0); 745 layerTreeHost->setRootLayer(NULL);
746 746
747 assertLayerTreeHostMatchesForSubtree(parent.get(), 0); 747 assertLayerTreeHostMatchesForSubtree(parent.get(), 0);
748 } 748 }
749 749
750 TEST(LayerLayerTreeHostTest, addingLayerSubtree) 750 TEST(LayerLayerTreeHostTest, addingLayerSubtree)
751 { 751 {
752 scoped_refptr<Layer> parent = Layer::create(); 752 scoped_refptr<Layer> parent = Layer::Create();
753 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat e()); 753 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::Creat e());
754 754
755 layerTreeHost->setRootLayer(parent.get()); 755 layerTreeHost->setRootLayer(parent.get());
756 756
757 EXPECT_EQ(parent->layerTreeHost(), layerTreeHost.get()); 757 EXPECT_EQ(parent->layer_tree_host(), layerTreeHost.get());
758 758
759 // Adding a subtree to a layer already associated with a host should set the host pointer on all layers in that subtree. 759 // Adding a subtree to a layer already associated with a host should set the host pointer on all layers in that subtree.
760 scoped_refptr<Layer> child = Layer::create(); 760 scoped_refptr<Layer> child = Layer::Create();
761 scoped_refptr<Layer> grandChild = Layer::create(); 761 scoped_refptr<Layer> grandChild = Layer::Create();
762 child->addChild(grandChild); 762 child->AddChild(grandChild);
763 763
764 // Masks, replicas, and replica masks should pick up the new host too. 764 // Masks, replicas, and replica masks should pick up the new host too.
765 scoped_refptr<Layer> childMask = Layer::create(); 765 scoped_refptr<Layer> childMask = Layer::Create();
766 child->setMaskLayer(childMask.get()); 766 child->SetMaskLayer(childMask.get());
767 scoped_refptr<Layer> childReplica = Layer::create(); 767 scoped_refptr<Layer> childReplica = Layer::Create();
768 child->setReplicaLayer(childReplica.get()); 768 child->SetReplicaLayer(childReplica.get());
769 scoped_refptr<Layer> childReplicaMask = Layer::create(); 769 scoped_refptr<Layer> childReplicaMask = Layer::Create();
770 childReplica->setMaskLayer(childReplicaMask.get()); 770 childReplica->SetMaskLayer(childReplicaMask.get());
771 771
772 parent->addChild(child); 772 parent->AddChild(child);
773 assertLayerTreeHostMatchesForSubtree(parent.get(), layerTreeHost.get()); 773 assertLayerTreeHostMatchesForSubtree(parent.get(), layerTreeHost.get());
774 774
775 layerTreeHost->setRootLayer(0); 775 layerTreeHost->setRootLayer(0);
776 } 776 }
777 777
778 TEST(LayerLayerTreeHostTest, changeHost) 778 TEST(LayerLayerTreeHostTest, changeHost)
779 { 779 {
780 scoped_refptr<Layer> parent = Layer::create(); 780 scoped_refptr<Layer> parent = Layer::Create();
781 scoped_refptr<Layer> child = Layer::create(); 781 scoped_refptr<Layer> child = Layer::Create();
782 scoped_refptr<Layer> mask = Layer::create(); 782 scoped_refptr<Layer> mask = Layer::Create();
783 scoped_refptr<Layer> replica = Layer::create(); 783 scoped_refptr<Layer> replica = Layer::Create();
784 scoped_refptr<Layer> replicaMask = Layer::create(); 784 scoped_refptr<Layer> replicaMask = Layer::Create();
785 785
786 // Same setup as the previous test. 786 // Same setup as the previous test.
787 parent->addChild(child); 787 parent->AddChild(child);
788 child->setMaskLayer(mask.get()); 788 child->SetMaskLayer(mask.get());
789 child->setReplicaLayer(replica.get()); 789 child->SetReplicaLayer(replica.get());
790 replica->setMaskLayer(replicaMask.get()); 790 replica->SetMaskLayer(replicaMask.get());
791 791
792 scoped_ptr<FakeLayerImplTreeHost> firstLayerTreeHost(FakeLayerImplTreeHost:: create()); 792 scoped_ptr<FakeLayerImplTreeHost> firstLayerTreeHost(FakeLayerImplTreeHost:: Create());
793 firstLayerTreeHost->setRootLayer(parent.get()); 793 firstLayerTreeHost->setRootLayer(parent.get());
794 794
795 assertLayerTreeHostMatchesForSubtree(parent.get(), firstLayerTreeHost.get()) ; 795 assertLayerTreeHostMatchesForSubtree(parent.get(), firstLayerTreeHost.get()) ;
796 796
797 // Now re-root the tree to a new host (simulating what we do on a context lo st event). 797 // Now re-root the tree to a new host (simulating what we do on a context lo st event).
798 // This should update the host pointers for all layers in the tree. 798 // This should update the host pointers for all layers in the tree.
799 scoped_ptr<FakeLayerImplTreeHost> secondLayerTreeHost(FakeLayerImplTreeHost: :create()); 799 scoped_ptr<FakeLayerImplTreeHost> secondLayerTreeHost(FakeLayerImplTreeHost: :Create());
800 secondLayerTreeHost->setRootLayer(parent.get()); 800 secondLayerTreeHost->setRootLayer(parent.get());
801 801
802 assertLayerTreeHostMatchesForSubtree(parent.get(), secondLayerTreeHost.get() ); 802 assertLayerTreeHostMatchesForSubtree(parent.get(), secondLayerTreeHost.get() );
803 803
804 secondLayerTreeHost->setRootLayer(0); 804 secondLayerTreeHost->setRootLayer(0);
805 } 805 }
806 806
807 TEST(LayerLayerTreeHostTest, changeHostInSubtree) 807 TEST(LayerLayerTreeHostTest, changeHostInSubtree)
808 { 808 {
809 scoped_refptr<Layer> firstParent = Layer::create(); 809 scoped_refptr<Layer> firstParent = Layer::Create();
810 scoped_refptr<Layer> firstChild = Layer::create(); 810 scoped_refptr<Layer> firstChild = Layer::Create();
811 scoped_refptr<Layer> secondParent = Layer::create(); 811 scoped_refptr<Layer> secondParent = Layer::Create();
812 scoped_refptr<Layer> secondChild = Layer::create(); 812 scoped_refptr<Layer> secondChild = Layer::Create();
813 scoped_refptr<Layer> secondGrandChild = Layer::create(); 813 scoped_refptr<Layer> secondGrandChild = Layer::Create();
814 814
815 // First put all children under the first parent and set the first host. 815 // First put all children under the first parent and set the first host.
816 firstParent->addChild(firstChild); 816 firstParent->AddChild(firstChild);
817 secondChild->addChild(secondGrandChild); 817 secondChild->AddChild(secondGrandChild);
818 firstParent->addChild(secondChild); 818 firstParent->AddChild(secondChild);
819 819
820 scoped_ptr<FakeLayerImplTreeHost> firstLayerTreeHost(FakeLayerImplTreeHost:: create()); 820 scoped_ptr<FakeLayerImplTreeHost> firstLayerTreeHost(FakeLayerImplTreeHost:: Create());
821 firstLayerTreeHost->setRootLayer(firstParent.get()); 821 firstLayerTreeHost->setRootLayer(firstParent.get());
822 822
823 assertLayerTreeHostMatchesForSubtree(firstParent.get(), firstLayerTreeHost.g et()); 823 assertLayerTreeHostMatchesForSubtree(firstParent.get(), firstLayerTreeHost.g et());
824 824
825 // Now reparent the subtree starting at secondChild to a layer in a differen t tree. 825 // Now reparent the subtree starting at secondChild to a layer in a differen t tree.
826 scoped_ptr<FakeLayerImplTreeHost> secondLayerTreeHost(FakeLayerImplTreeHost: :create()); 826 scoped_ptr<FakeLayerImplTreeHost> secondLayerTreeHost(FakeLayerImplTreeHost: :Create());
827 secondLayerTreeHost->setRootLayer(secondParent.get()); 827 secondLayerTreeHost->setRootLayer(secondParent.get());
828 828
829 secondParent->addChild(secondChild); 829 secondParent->AddChild(secondChild);
830 830
831 // The moved layer and its children should point to the new host. 831 // The moved layer and its children should point to the new host.
832 EXPECT_EQ(secondLayerTreeHost.get(), secondChild->layerTreeHost()); 832 EXPECT_EQ(secondLayerTreeHost.get(), secondChild->layer_tree_host());
833 EXPECT_EQ(secondLayerTreeHost.get(), secondGrandChild->layerTreeHost()); 833 EXPECT_EQ(secondLayerTreeHost.get(), secondGrandChild->layer_tree_host());
834 834
835 // Test over, cleanup time. 835 // Test over, cleanup time.
836 firstLayerTreeHost->setRootLayer(0); 836 firstLayerTreeHost->setRootLayer(0);
837 secondLayerTreeHost->setRootLayer(0); 837 secondLayerTreeHost->setRootLayer(0);
838 } 838 }
839 839
840 TEST(LayerLayerTreeHostTest, replaceMaskAndReplicaLayer) 840 TEST(LayerLayerTreeHostTest, replaceMaskAndReplicaLayer)
841 { 841 {
842 scoped_refptr<Layer> parent = Layer::create(); 842 scoped_refptr<Layer> parent = Layer::Create();
843 scoped_refptr<Layer> mask = Layer::create(); 843 scoped_refptr<Layer> mask = Layer::Create();
844 scoped_refptr<Layer> replica = Layer::create(); 844 scoped_refptr<Layer> replica = Layer::Create();
845 scoped_refptr<Layer> maskChild = Layer::create(); 845 scoped_refptr<Layer> maskChild = Layer::Create();
846 scoped_refptr<Layer> replicaChild = Layer::create(); 846 scoped_refptr<Layer> replicaChild = Layer::Create();
847 scoped_refptr<Layer> maskReplacement = Layer::create(); 847 scoped_refptr<Layer> maskReplacement = Layer::Create();
848 scoped_refptr<Layer> replicaReplacement = Layer::create(); 848 scoped_refptr<Layer> replicaReplacement = Layer::Create();
849 849
850 parent->setMaskLayer(mask.get()); 850 parent->SetMaskLayer(mask.get());
851 parent->setReplicaLayer(replica.get()); 851 parent->SetReplicaLayer(replica.get());
852 mask->addChild(maskChild); 852 mask->AddChild(maskChild);
853 replica->addChild(replicaChild); 853 replica->AddChild(replicaChild);
854 854
855 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat e()); 855 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::Creat e());
856 layerTreeHost->setRootLayer(parent.get()); 856 layerTreeHost->setRootLayer(parent.get());
857 857
858 assertLayerTreeHostMatchesForSubtree(parent.get(), layerTreeHost.get()); 858 assertLayerTreeHostMatchesForSubtree(parent.get(), layerTreeHost.get());
859 859
860 // Replacing the mask should clear out the old mask's subtree's host pointer s. 860 // Replacing the mask should clear out the old mask's subtree's host pointer s.
861 parent->setMaskLayer(maskReplacement.get()); 861 parent->SetMaskLayer(maskReplacement.get());
862 EXPECT_EQ(0, mask->layerTreeHost()); 862 EXPECT_EQ(0, mask->layer_tree_host());
863 EXPECT_EQ(0, maskChild->layerTreeHost()); 863 EXPECT_EQ(0, maskChild->layer_tree_host());
864 864
865 // Same for replacing a replica layer. 865 // Same for replacing a replica layer.
866 parent->setReplicaLayer(replicaReplacement.get()); 866 parent->SetReplicaLayer(replicaReplacement.get());
867 EXPECT_EQ(0, replica->layerTreeHost()); 867 EXPECT_EQ(0, replica->layer_tree_host());
868 EXPECT_EQ(0, replicaChild->layerTreeHost()); 868 EXPECT_EQ(0, replicaChild->layer_tree_host());
869 869
870 // Test over, cleanup time. 870 // Test over, cleanup time.
871 layerTreeHost->setRootLayer(0); 871 layerTreeHost->setRootLayer(0);
872 } 872 }
873 873
874 TEST(LayerLayerTreeHostTest, destroyHostWithNonNullRootLayer) 874 TEST(LayerLayerTreeHostTest, destroyHostWithNonNullRootLayer)
875 { 875 {
876 scoped_refptr<Layer> root = Layer::create(); 876 scoped_refptr<Layer> root = Layer::Create();
877 scoped_refptr<Layer> child = Layer::create(); 877 scoped_refptr<Layer> child = Layer::Create();
878 root->addChild(child); 878 root->AddChild(child);
879 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat e()); 879 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::Creat e());
880 layerTreeHost->setRootLayer(root); 880 layerTreeHost->setRootLayer(root);
881 } 881 }
882 882
883 static bool addTestAnimation(Layer* layer) 883 static bool addTestAnimation(Layer* layer)
884 { 884 {
885 scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve: :Create()); 885 scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve: :Create());
886 curve->AddKeyframe(FloatKeyframe::Create(0.0, 0.3f, scoped_ptr<TimingFunctio n>())); 886 curve->AddKeyframe(FloatKeyframe::Create(0.0, 0.3f, scoped_ptr<TimingFunctio n>()));
887 curve->AddKeyframe(FloatKeyframe::Create(1.0, 0.7f, scoped_ptr<TimingFunctio n>())); 887 curve->AddKeyframe(FloatKeyframe::Create(1.0, 0.7f, scoped_ptr<TimingFunctio n>()));
888 scoped_ptr<Animation> animation(Animation::Create(curve.PassAs<AnimationCurv e>(), 0, 0, Animation::Opacity)); 888 scoped_ptr<Animation> animation(Animation::Create(curve.PassAs<AnimationCurv e>(), 0, 0, Animation::Opacity));
889 889
890 return layer->AddAnimation(animation.Pass()); 890 return layer->AddAnimation(animation.Pass());
891 } 891 }
892 892
893 TEST(LayerLayerTreeHostTest, shouldNotAddAnimationWithoutAnimationRegistrar) 893 TEST(LayerLayerTreeHostTest, shouldNotAddAnimationWithoutAnimationRegistrar)
894 { 894 {
895 scoped_refptr<Layer> layer = Layer::create(); 895 scoped_refptr<Layer> layer = Layer::Create();
896 896
897 // Case 1: without a LayerTreeHost and without an AnimationRegistrar, the 897 // Case 1: without a LayerTreeHost and without an AnimationRegistrar, the
898 // animation should not be accepted. 898 // animation should not be accepted.
899 EXPECT_FALSE(addTestAnimation(layer.get())); 899 EXPECT_FALSE(addTestAnimation(layer.get()));
900 900
901 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::create(); 901 scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::create();
902 layer->layerAnimationController()->SetAnimationRegistrar(registrar.get()); 902 layer->layer_animation_controller()->SetAnimationRegistrar(registrar.get());
903 903
904 // Case 2: with an AnimationRegistrar, the animation should be accepted. 904 // Case 2: with an AnimationRegistrar, the animation should be accepted.
905 EXPECT_TRUE(addTestAnimation(layer.get())); 905 EXPECT_TRUE(addTestAnimation(layer.get()));
906 906
907 LayerTreeSettings settings; 907 LayerTreeSettings settings;
908 settings.acceleratedAnimationEnabled = false; 908 settings.acceleratedAnimationEnabled = false;
909 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat e(settings)); 909 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::Creat e(settings));
910 layerTreeHost->setRootLayer(layer.get()); 910 layerTreeHost->setRootLayer(layer.get());
911 layer->setLayerTreeHost(layerTreeHost.get()); 911 layer->SetLayerTreeHost(layerTreeHost.get());
912 assertLayerTreeHostMatchesForSubtree(layer.get(), layerTreeHost.get()); 912 assertLayerTreeHostMatchesForSubtree(layer.get(), layerTreeHost.get());
913 913
914 // Case 3: with a LayerTreeHost where accelerated animation is disabled, the 914 // Case 3: with a LayerTreeHost where accelerated animation is disabled, the
915 // animation should be rejected. 915 // animation should be rejected.
916 EXPECT_FALSE(addTestAnimation(layer.get())); 916 EXPECT_FALSE(addTestAnimation(layer.get()));
917 } 917 }
918 918
919 } // namespace 919 } // namespace
920 } // namespace cc 920 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_tree_impl.cc ('k') | cc/nine_patch_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698