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

Side by Side Diff: ui/aura/window_unittest.cc

Issue 9289036: aura: Add Layer::LAYER_SOLID_COLOR to compositor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor changes Created 8 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/aura/window.h" 5 #include "ui/aura/window.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 EXPECT_EQ(NULL, w1->GetChildById(57)); 175 EXPECT_EQ(NULL, w1->GetChildById(57));
176 EXPECT_EQ(w12.get(), w1->GetChildById(12)); 176 EXPECT_EQ(w12.get(), w1->GetChildById(12));
177 EXPECT_EQ(w111.get(), w1->GetChildById(111)); 177 EXPECT_EQ(w111.get(), w1->GetChildById(111));
178 } 178 }
179 179
180 // Make sure that Window::Contains correctly handles children, grandchildren, 180 // Make sure that Window::Contains correctly handles children, grandchildren,
181 // and not containing NULL or parents. 181 // and not containing NULL or parents.
182 TEST_F(WindowTest, Contains) { 182 TEST_F(WindowTest, Contains) {
183 Window parent(NULL); 183 Window parent(NULL);
184 parent.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); 184 parent.Init(ui::Layer::LAYER_NOT_DRAWN);
185 Window child1(NULL); 185 Window child1(NULL);
186 child1.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); 186 child1.Init(ui::Layer::LAYER_NOT_DRAWN);
187 Window child2(NULL); 187 Window child2(NULL);
188 child2.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); 188 child2.Init(ui::Layer::LAYER_NOT_DRAWN);
189 189
190 child1.SetParent(&parent); 190 child1.SetParent(&parent);
191 child2.SetParent(&child1); 191 child2.SetParent(&child1);
192 192
193 EXPECT_TRUE(parent.Contains(&parent)); 193 EXPECT_TRUE(parent.Contains(&parent));
194 EXPECT_TRUE(parent.Contains(&child1)); 194 EXPECT_TRUE(parent.Contains(&child1));
195 EXPECT_TRUE(parent.Contains(&child2)); 195 EXPECT_TRUE(parent.Contains(&child2));
196 196
197 EXPECT_FALSE(parent.Contains(NULL)); 197 EXPECT_FALSE(parent.Contains(NULL));
198 EXPECT_FALSE(child1.Contains(&parent)); 198 EXPECT_FALSE(child1.Contains(&parent));
199 EXPECT_FALSE(child2.Contains(&child1)); 199 EXPECT_FALSE(child2.Contains(&child1));
200 } 200 }
201 201
202 TEST_F(WindowTest, ConvertPointToWindow) { 202 TEST_F(WindowTest, ConvertPointToWindow) {
203 // Window::ConvertPointToWindow is mostly identical to 203 // Window::ConvertPointToWindow is mostly identical to
204 // Layer::ConvertPointToLayer, except NULL values for |source| are permitted, 204 // Layer::ConvertPointToLayer, except NULL values for |source| are permitted,
205 // in which case the function just returns. 205 // in which case the function just returns.
206 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); 206 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
207 gfx::Point reference_point(100, 100); 207 gfx::Point reference_point(100, 100);
208 gfx::Point test_point = reference_point; 208 gfx::Point test_point = reference_point;
209 Window::ConvertPointToWindow(NULL, w1.get(), &test_point); 209 Window::ConvertPointToWindow(NULL, w1.get(), &test_point);
210 EXPECT_EQ(reference_point, test_point); 210 EXPECT_EQ(reference_point, test_point);
211 } 211 }
212 212
213 TEST_F(WindowTest, HitTest) { 213 TEST_F(WindowTest, HitTest) {
214 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); 214 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE));
215 w1.set_id(1); 215 w1.set_id(1);
216 w1.Init(ui::Layer::LAYER_HAS_TEXTURE); 216 w1.Init(ui::Layer::LAYER_TEXTURED);
217 w1.SetBounds(gfx::Rect(10, 10, 50, 50)); 217 w1.SetBounds(gfx::Rect(10, 10, 50, 50));
218 w1.Show(); 218 w1.Show();
219 w1.SetParent(NULL); 219 w1.SetParent(NULL);
220 220
221 // Points are in the Window's coordinates. 221 // Points are in the Window's coordinates.
222 EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1))); 222 EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1)));
223 EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1))); 223 EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1)));
224 224
225 // TODO(beng): clip Window to parent. 225 // TODO(beng): clip Window to parent.
226 } 226 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 CreateTestWindowWithDelegate(&parent_delegate, 0, gfx::Rect(), NULL)); 334 CreateTestWindowWithDelegate(&parent_delegate, 0, gfx::Rect(), NULL));
335 scoped_ptr<Window> child(CreateTestWindowWithDelegate(&child_delegate, 0, 335 scoped_ptr<Window> child(CreateTestWindowWithDelegate(&child_delegate, 0,
336 gfx::Rect(), parent.get())); 336 gfx::Rect(), parent.get()));
337 child_delegate.set_window(child.get()); 337 child_delegate.set_window(child.get());
338 } 338 }
339 } 339 }
340 340
341 // Make sure StackChildAtTop moves both the window and layer to the front. 341 // Make sure StackChildAtTop moves both the window and layer to the front.
342 TEST_F(WindowTest, StackChildAtTop) { 342 TEST_F(WindowTest, StackChildAtTop) {
343 Window parent(NULL); 343 Window parent(NULL);
344 parent.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); 344 parent.Init(ui::Layer::LAYER_NOT_DRAWN);
345 Window child1(NULL); 345 Window child1(NULL);
346 child1.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); 346 child1.Init(ui::Layer::LAYER_NOT_DRAWN);
347 Window child2(NULL); 347 Window child2(NULL);
348 child2.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); 348 child2.Init(ui::Layer::LAYER_NOT_DRAWN);
349 349
350 child1.SetParent(&parent); 350 child1.SetParent(&parent);
351 child2.SetParent(&parent); 351 child2.SetParent(&parent);
352 ASSERT_EQ(2u, parent.children().size()); 352 ASSERT_EQ(2u, parent.children().size());
353 EXPECT_EQ(&child1, parent.children()[0]); 353 EXPECT_EQ(&child1, parent.children()[0]);
354 EXPECT_EQ(&child2, parent.children()[1]); 354 EXPECT_EQ(&child2, parent.children()[1]);
355 ASSERT_EQ(2u, parent.layer()->children().size()); 355 ASSERT_EQ(2u, parent.layer()->children().size());
356 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]); 356 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]);
357 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]); 357 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]);
358 358
359 parent.StackChildAtTop(&child1); 359 parent.StackChildAtTop(&child1);
360 ASSERT_EQ(2u, parent.children().size()); 360 ASSERT_EQ(2u, parent.children().size());
361 EXPECT_EQ(&child1, parent.children()[1]); 361 EXPECT_EQ(&child1, parent.children()[1]);
362 EXPECT_EQ(&child2, parent.children()[0]); 362 EXPECT_EQ(&child2, parent.children()[0]);
363 ASSERT_EQ(2u, parent.layer()->children().size()); 363 ASSERT_EQ(2u, parent.layer()->children().size());
364 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); 364 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]);
365 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); 365 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]);
366 } 366 }
367 367
368 // Various assertions for StackChildAbove. 368 // Various assertions for StackChildAbove.
369 TEST_F(WindowTest, StackChildAbove) { 369 TEST_F(WindowTest, StackChildAbove) {
370 Window parent(NULL); 370 Window parent(NULL);
371 parent.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); 371 parent.Init(ui::Layer::LAYER_NOT_DRAWN);
372 Window child1(NULL); 372 Window child1(NULL);
373 child1.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); 373 child1.Init(ui::Layer::LAYER_NOT_DRAWN);
374 Window child2(NULL); 374 Window child2(NULL);
375 child2.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); 375 child2.Init(ui::Layer::LAYER_NOT_DRAWN);
376 Window child3(NULL); 376 Window child3(NULL);
377 child3.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); 377 child3.Init(ui::Layer::LAYER_NOT_DRAWN);
378 378
379 child1.SetParent(&parent); 379 child1.SetParent(&parent);
380 child2.SetParent(&parent); 380 child2.SetParent(&parent);
381 381
382 // Move 1 in front of 2. 382 // Move 1 in front of 2.
383 parent.StackChildAbove(&child1, &child2); 383 parent.StackChildAbove(&child1, &child2);
384 ASSERT_EQ(2u, parent.children().size()); 384 ASSERT_EQ(2u, parent.children().size());
385 EXPECT_EQ(&child2, parent.children()[0]); 385 EXPECT_EQ(&child2, parent.children()[0]);
386 EXPECT_EQ(&child1, parent.children()[1]); 386 EXPECT_EQ(&child1, parent.children()[1]);
387 ASSERT_EQ(2u, parent.layer()->children().size()); 387 ASSERT_EQ(2u, parent.layer()->children().size());
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 LayerGrabber grabber(window.get()); 1158 LayerGrabber grabber(window.get());
1159 window.reset(); 1159 window.reset();
1160 EXPECT_FALSE(grabber.layer() == NULL); 1160 EXPECT_FALSE(grabber.layer() == NULL);
1161 EXPECT_FALSE(grabber.layer()->visible()); 1161 EXPECT_FALSE(grabber.layer()->visible());
1162 // This should be set by the window's destructor. 1162 // This should be set by the window's destructor.
1163 EXPECT_TRUE(grabber.layer()->delegate() == NULL); 1163 EXPECT_TRUE(grabber.layer()->delegate() == NULL);
1164 } 1164 }
1165 1165
1166 } // namespace test 1166 } // namespace test
1167 } // namespace aura 1167 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698