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

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

Issue 11421006: Desktop aura: Break aura::Window::SetParent in two. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: I think the content_unittests timeout on linux_aura is flake, but try to fix it anyway. Created 8 years 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 <utility> 7 #include <utility>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 ui::GestureConfiguration:: 53 ui::GestureConfiguration::
54 set_max_separation_for_gesture_touches_in_pixels(0); 54 set_max_separation_for_gesture_touches_in_pixels(0);
55 } 55 }
56 56
57 virtual void TearDown() OVERRIDE { 57 virtual void TearDown() OVERRIDE {
58 AuraTestBase::TearDown(); 58 AuraTestBase::TearDown();
59 ui::GestureConfiguration:: 59 ui::GestureConfiguration::
60 set_max_separation_for_gesture_touches_in_pixels(max_separation_); 60 set_max_separation_for_gesture_touches_in_pixels(max_separation_);
61 } 61 }
62 62
63 // Adds |window| to |root_window_|, through the StackingClient.
64 void AddToRootWindow(aura::Window* window) {
sky 2012/11/21 23:35:59 Again, I think this should match the method name y
65 window->SetDefaultParentByTargetRoot(root_window(), gfx::Rect());
66 }
67
68
63 private: 69 private:
64 int max_separation_; 70 int max_separation_;
65 71
66 DISALLOW_COPY_AND_ASSIGN(WindowTest); 72 DISALLOW_COPY_AND_ASSIGN(WindowTest);
67 }; 73 };
68 74
69 namespace { 75 namespace {
70 76
71 // Used for verifying destruction methods are invoked. 77 // Used for verifying destruction methods are invoked.
72 class DestroyTrackingDelegateImpl : public TestWindowDelegate { 78 class DestroyTrackingDelegateImpl : public TestWindowDelegate {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 return false; 252 return false;
247 } 253 }
248 254
249 private: 255 private:
250 DISALLOW_COPY_AND_ASSIGN(SelfEventHandlingWindowDelegate); 256 DISALLOW_COPY_AND_ASSIGN(SelfEventHandlingWindowDelegate);
251 }; 257 };
252 258
253 } // namespace 259 } // namespace
254 260
255 TEST_F(WindowTest, GetChildById) { 261 TEST_F(WindowTest, GetChildById) {
256 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); 262 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
257 scoped_ptr<Window> w11(CreateTestWindowWithId(11, w1.get())); 263 scoped_ptr<Window> w11(CreateTestWindowWithId(11, w1.get()));
258 scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); 264 scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get()));
259 scoped_ptr<Window> w12(CreateTestWindowWithId(12, w1.get())); 265 scoped_ptr<Window> w12(CreateTestWindowWithId(12, w1.get()));
260 266
261 EXPECT_EQ(NULL, w1->GetChildById(57)); 267 EXPECT_EQ(NULL, w1->GetChildById(57));
262 EXPECT_EQ(w12.get(), w1->GetChildById(12)); 268 EXPECT_EQ(w12.get(), w1->GetChildById(12));
263 EXPECT_EQ(w111.get(), w1->GetChildById(111)); 269 EXPECT_EQ(w111.get(), w1->GetChildById(111));
264 } 270 }
265 271
266 // Make sure that Window::Contains correctly handles children, grandchildren, 272 // Make sure that Window::Contains correctly handles children, grandchildren,
267 // and not containing NULL or parents. 273 // and not containing NULL or parents.
268 TEST_F(WindowTest, Contains) { 274 TEST_F(WindowTest, Contains) {
269 Window parent(NULL); 275 Window parent(NULL);
270 parent.Init(ui::LAYER_NOT_DRAWN); 276 parent.Init(ui::LAYER_NOT_DRAWN);
271 Window child1(NULL); 277 Window child1(NULL);
272 child1.Init(ui::LAYER_NOT_DRAWN); 278 child1.Init(ui::LAYER_NOT_DRAWN);
273 Window child2(NULL); 279 Window child2(NULL);
274 child2.Init(ui::LAYER_NOT_DRAWN); 280 child2.Init(ui::LAYER_NOT_DRAWN);
275 281
276 child1.SetParent(&parent); 282 parent.AddChild(&child1);
277 child2.SetParent(&child1); 283 child1.AddChild(&child2);
278 284
279 EXPECT_TRUE(parent.Contains(&parent)); 285 EXPECT_TRUE(parent.Contains(&parent));
280 EXPECT_TRUE(parent.Contains(&child1)); 286 EXPECT_TRUE(parent.Contains(&child1));
281 EXPECT_TRUE(parent.Contains(&child2)); 287 EXPECT_TRUE(parent.Contains(&child2));
282 288
283 EXPECT_FALSE(parent.Contains(NULL)); 289 EXPECT_FALSE(parent.Contains(NULL));
284 EXPECT_FALSE(child1.Contains(&parent)); 290 EXPECT_FALSE(child1.Contains(&parent));
285 EXPECT_FALSE(child2.Contains(&child1)); 291 EXPECT_FALSE(child2.Contains(&child1));
286 } 292 }
287 293
288 TEST_F(WindowTest, ContainsPointInRoot) { 294 TEST_F(WindowTest, ContainsPointInRoot) {
289 scoped_ptr<Window> w( 295 scoped_ptr<Window> w(
290 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), NULL)); 296 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5),
297 root_window()));
291 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(9, 9))); 298 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(9, 9)));
292 EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(10, 10))); 299 EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(10, 10)));
293 EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(14, 14))); 300 EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(14, 14)));
294 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(15, 15))); 301 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(15, 15)));
295 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(20, 20))); 302 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(20, 20)));
296 } 303 }
297 304
298 TEST_F(WindowTest, ContainsPoint) { 305 TEST_F(WindowTest, ContainsPoint) {
299 scoped_ptr<Window> w( 306 scoped_ptr<Window> w(
300 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), NULL)); 307 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5),
308 root_window()));
301 EXPECT_TRUE(w->ContainsPoint(gfx::Point(0, 0))); 309 EXPECT_TRUE(w->ContainsPoint(gfx::Point(0, 0)));
302 EXPECT_TRUE(w->ContainsPoint(gfx::Point(4, 4))); 310 EXPECT_TRUE(w->ContainsPoint(gfx::Point(4, 4)));
303 EXPECT_FALSE(w->ContainsPoint(gfx::Point(5, 5))); 311 EXPECT_FALSE(w->ContainsPoint(gfx::Point(5, 5)));
304 EXPECT_FALSE(w->ContainsPoint(gfx::Point(10, 10))); 312 EXPECT_FALSE(w->ContainsPoint(gfx::Point(10, 10)));
305 } 313 }
306 314
307 TEST_F(WindowTest, ConvertPointToWindow) { 315 TEST_F(WindowTest, ConvertPointToWindow) {
308 // Window::ConvertPointToWindow is mostly identical to 316 // Window::ConvertPointToWindow is mostly identical to
309 // Layer::ConvertPointToLayer, except NULL values for |source| are permitted, 317 // Layer::ConvertPointToLayer, except NULL values for |source| are permitted,
310 // in which case the function just returns. 318 // in which case the function just returns.
311 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); 319 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
312 gfx::Point reference_point(100, 100); 320 gfx::Point reference_point(100, 100);
313 gfx::Point test_point = reference_point; 321 gfx::Point test_point = reference_point;
314 Window::ConvertPointToTarget(NULL, w1.get(), &test_point); 322 Window::ConvertPointToTarget(NULL, w1.get(), &test_point);
315 EXPECT_EQ(reference_point, test_point); 323 EXPECT_EQ(reference_point, test_point);
316 } 324 }
317 325
318 TEST_F(WindowTest, MoveCursorTo) { 326 TEST_F(WindowTest, MoveCursorTo) {
319 scoped_ptr<Window> w1( 327 scoped_ptr<Window> w1(
320 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); 328 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500),
329 root_window()));
321 scoped_ptr<Window> w11( 330 scoped_ptr<Window> w11(
322 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); 331 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get()));
323 scoped_ptr<Window> w111( 332 scoped_ptr<Window> w111(
324 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); 333 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get()));
325 scoped_ptr<Window> w1111( 334 scoped_ptr<Window> w1111(
326 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); 335 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get()));
327 336
328 RootWindow* root = root_window(); 337 RootWindow* root = root_window();
329 root->MoveCursorTo(gfx::Point(10, 10)); 338 root->MoveCursorTo(gfx::Point(10, 10));
330 EXPECT_EQ("10,10", 339 EXPECT_EQ("10,10",
331 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); 340 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString());
332 w1->MoveCursorTo(gfx::Point(10, 10)); 341 w1->MoveCursorTo(gfx::Point(10, 10));
333 EXPECT_EQ("20,20", 342 EXPECT_EQ("20,20",
334 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); 343 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString());
335 w11->MoveCursorTo(gfx::Point(10, 10)); 344 w11->MoveCursorTo(gfx::Point(10, 10));
336 EXPECT_EQ("25,25", 345 EXPECT_EQ("25,25",
337 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); 346 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString());
338 w111->MoveCursorTo(gfx::Point(10, 10)); 347 w111->MoveCursorTo(gfx::Point(10, 10));
339 EXPECT_EQ("30,30", 348 EXPECT_EQ("30,30",
340 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); 349 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString());
341 w1111->MoveCursorTo(gfx::Point(10, 10)); 350 w1111->MoveCursorTo(gfx::Point(10, 10));
342 EXPECT_EQ("35,35", 351 EXPECT_EQ("35,35",
343 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); 352 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString());
344 } 353 }
345 354
346 TEST_F(WindowTest, ContainsMouse) { 355 TEST_F(WindowTest, ContainsMouse) {
347 scoped_ptr<Window> w( 356 scoped_ptr<Window> w(
348 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); 357 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500),
358 root_window()));
349 w->Show(); 359 w->Show();
350 Window::TestApi w_test_api(w.get()); 360 Window::TestApi w_test_api(w.get());
351 RootWindow* root = root_window(); 361 RootWindow* root = root_window();
352 root->MoveCursorTo(gfx::Point(10, 10)); 362 root->MoveCursorTo(gfx::Point(10, 10));
353 EXPECT_TRUE(w_test_api.ContainsMouse()); 363 EXPECT_TRUE(w_test_api.ContainsMouse());
354 root->MoveCursorTo(gfx::Point(9, 10)); 364 root->MoveCursorTo(gfx::Point(9, 10));
355 EXPECT_FALSE(w_test_api.ContainsMouse()); 365 EXPECT_FALSE(w_test_api.ContainsMouse());
356 } 366 }
357 367
358 // Test Window::ConvertPointToWindow() with transform to root_window. 368 // Test Window::ConvertPointToWindow() with transform to root_window.
359 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { 369 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) {
360 RootWindow* root = root_window(); 370 RootWindow* root = root_window();
361 gfx::Transform transform; 371 gfx::Transform transform;
362 transform.ConcatScale(2, 5); 372 transform.ConcatScale(2, 5);
363 transform.ConcatRotate(90.0f); 373 transform.ConcatRotate(90.0f);
364 transform.ConcatTranslate(100, 100); 374 transform.ConcatTranslate(100, 100);
365 root->SetTransform(transform); 375 root->SetTransform(transform);
366 root->MoveCursorTo(gfx::Point(10, 10)); 376 root->MoveCursorTo(gfx::Point(10, 10));
367 #if !defined(OS_WIN) 377 #if !defined(OS_WIN)
368 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD 378 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD
369 EXPECT_EQ("50,120", root->QueryMouseLocationForTest().ToString()); 379 EXPECT_EQ("50,120", root->QueryMouseLocationForTest().ToString());
370 #endif 380 #endif
371 EXPECT_EQ("10,10", 381 EXPECT_EQ("10,10",
372 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); 382 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString());
373 } 383 }
374 384
375 // Tests Window::ConvertPointToWindow() with transform to non-root windows. 385 // Tests Window::ConvertPointToWindow() with transform to non-root windows.
376 TEST_F(WindowTest, MoveCursorToWithTransformWindow) { 386 TEST_F(WindowTest, MoveCursorToWithTransformWindow) {
377 scoped_ptr<Window> w1( 387 scoped_ptr<Window> w1(
378 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); 388 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500),
389 root_window()));
379 390
380 gfx::Transform transform1; 391 gfx::Transform transform1;
381 transform1.ConcatScale(2, 2); 392 transform1.ConcatScale(2, 2);
382 w1->SetTransform(transform1); 393 w1->SetTransform(transform1);
383 w1->MoveCursorTo(gfx::Point(10, 10)); 394 w1->MoveCursorTo(gfx::Point(10, 10));
384 EXPECT_EQ("30,30", 395 EXPECT_EQ("30,30",
385 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); 396 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString());
386 397
387 gfx::Transform transform2; 398 gfx::Transform transform2;
388 transform2.ConcatTranslate(-10, 20); 399 transform2.ConcatTranslate(-10, 20);
(...skipping 16 matching lines...) Expand all
405 w1->SetTransform(transform4); 416 w1->SetTransform(transform4);
406 w1->MoveCursorTo(gfx::Point(10, 10)); 417 w1->MoveCursorTo(gfx::Point(10, 10));
407 EXPECT_EQ("60,130", 418 EXPECT_EQ("60,130",
408 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); 419 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString());
409 } 420 }
410 421
411 // Test Window::ConvertPointToWindow() with complex transforms to both root and 422 // Test Window::ConvertPointToWindow() with complex transforms to both root and
412 // non-root windows. 423 // non-root windows.
413 TEST_F(WindowTest, MoveCursorToWithComplexTransform) { 424 TEST_F(WindowTest, MoveCursorToWithComplexTransform) {
414 scoped_ptr<Window> w1( 425 scoped_ptr<Window> w1(
415 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); 426 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500),
427 root_window()));
416 scoped_ptr<Window> w11( 428 scoped_ptr<Window> w11(
417 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); 429 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get()));
418 scoped_ptr<Window> w111( 430 scoped_ptr<Window> w111(
419 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); 431 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get()));
420 scoped_ptr<Window> w1111( 432 scoped_ptr<Window> w1111(
421 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); 433 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get()));
422 434
423 RootWindow* root = root_window(); 435 RootWindow* root = root_window();
424 436
425 // The root window expects transforms that produce integer rects. 437 // The root window expects transforms that produce integer rects.
(...skipping 23 matching lines...) Expand all
449 EXPECT_EQ("20,53", 461 EXPECT_EQ("20,53",
450 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); 462 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString());
451 } 463 }
452 464
453 TEST_F(WindowTest, HitTest) { 465 TEST_F(WindowTest, HitTest) {
454 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); 466 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE));
455 w1.set_id(1); 467 w1.set_id(1);
456 w1.Init(ui::LAYER_TEXTURED); 468 w1.Init(ui::LAYER_TEXTURED);
457 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); 469 w1.SetBounds(gfx::Rect(10, 20, 50, 60));
458 w1.Show(); 470 w1.Show();
459 w1.SetParent(NULL); 471 AddToRootWindow(&w1);
460 472
461 // Points are in the Window's coordinates. 473 // Points are in the Window's coordinates.
462 EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1))); 474 EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1)));
463 EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1))); 475 EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1)));
464 476
465 // We can expand the bounds slightly to track events outside our border. 477 // We can expand the bounds slightly to track events outside our border.
466 w1.SetHitTestBoundsOverrideOuter(gfx::Insets(-1, -1, -1, -1), 5); 478 w1.SetHitTestBoundsOverrideOuter(gfx::Insets(-1, -1, -1, -1), 5);
467 EXPECT_TRUE(w1.HitTest(gfx::Point(-1, -1))); 479 EXPECT_TRUE(w1.HitTest(gfx::Point(-1, -1)));
468 EXPECT_FALSE(w1.HitTest(gfx::Point(-2, -2))); 480 EXPECT_FALSE(w1.HitTest(gfx::Point(-2, -2)));
469 481
(...skipping 10 matching lines...) Expand all
480 492
481 // TODO(beng): clip Window to parent. 493 // TODO(beng): clip Window to parent.
482 } 494 }
483 495
484 TEST_F(WindowTest, HitTestMask) { 496 TEST_F(WindowTest, HitTestMask) {
485 MaskedWindowDelegate d1(gfx::Rect(5, 6, 20, 30)); 497 MaskedWindowDelegate d1(gfx::Rect(5, 6, 20, 30));
486 Window w1(&d1); 498 Window w1(&d1);
487 w1.Init(ui::LAYER_NOT_DRAWN); 499 w1.Init(ui::LAYER_NOT_DRAWN);
488 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); 500 w1.SetBounds(gfx::Rect(10, 20, 50, 60));
489 w1.Show(); 501 w1.Show();
490 w1.SetParent(NULL); 502 AddToRootWindow(&w1);
491 503
492 // Points inside the mask. 504 // Points inside the mask.
493 EXPECT_TRUE(w1.HitTest(gfx::Point(5, 6))); // top-left 505 EXPECT_TRUE(w1.HitTest(gfx::Point(5, 6))); // top-left
494 EXPECT_TRUE(w1.HitTest(gfx::Point(15, 21))); // center 506 EXPECT_TRUE(w1.HitTest(gfx::Point(15, 21))); // center
495 EXPECT_TRUE(w1.HitTest(gfx::Point(24, 35))); // bottom-right 507 EXPECT_TRUE(w1.HitTest(gfx::Point(24, 35))); // bottom-right
496 508
497 // Points outside the mask. 509 // Points outside the mask.
498 EXPECT_FALSE(w1.HitTest(gfx::Point(0, 0))); 510 EXPECT_FALSE(w1.HitTest(gfx::Point(0, 0)));
499 EXPECT_FALSE(w1.HitTest(gfx::Point(60, 80))); 511 EXPECT_FALSE(w1.HitTest(gfx::Point(60, 80)));
500 EXPECT_FALSE(w1.HitTest(gfx::Point(4, 6))); 512 EXPECT_FALSE(w1.HitTest(gfx::Point(4, 6)));
501 EXPECT_FALSE(w1.HitTest(gfx::Point(5, 5))); 513 EXPECT_FALSE(w1.HitTest(gfx::Point(5, 5)));
502 EXPECT_FALSE(w1.HitTest(gfx::Point(25, 36))); 514 EXPECT_FALSE(w1.HitTest(gfx::Point(25, 36)));
503 } 515 }
504 516
505 TEST_F(WindowTest, GetEventHandlerForPoint) { 517 TEST_F(WindowTest, GetEventHandlerForPoint) {
506 scoped_ptr<Window> w1( 518 scoped_ptr<Window> w1(
507 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); 519 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500),
520 root_window()));
508 scoped_ptr<Window> w11( 521 scoped_ptr<Window> w11(
509 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); 522 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get()));
510 scoped_ptr<Window> w111( 523 scoped_ptr<Window> w111(
511 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); 524 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get()));
512 scoped_ptr<Window> w1111( 525 scoped_ptr<Window> w1111(
513 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); 526 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get()));
514 scoped_ptr<Window> w12( 527 scoped_ptr<Window> w12(
515 CreateTestWindow(SK_ColorMAGENTA, 12, gfx::Rect(10, 420, 25, 25), 528 CreateTestWindow(SK_ColorMAGENTA, 12, gfx::Rect(10, 420, 25, 25),
516 w1.get())); 529 w1.get()));
517 scoped_ptr<Window> w121( 530 scoped_ptr<Window> w121(
(...skipping 10 matching lines...) Expand all
528 EXPECT_EQ(w1111.get(), root->GetEventHandlerForPoint(gfx::Point(26, 26))); 541 EXPECT_EQ(w1111.get(), root->GetEventHandlerForPoint(gfx::Point(26, 26)));
529 EXPECT_EQ(w12.get(), root->GetEventHandlerForPoint(gfx::Point(21, 431))); 542 EXPECT_EQ(w12.get(), root->GetEventHandlerForPoint(gfx::Point(21, 431)));
530 EXPECT_EQ(w121.get(), root->GetEventHandlerForPoint(gfx::Point(26, 436))); 543 EXPECT_EQ(w121.get(), root->GetEventHandlerForPoint(gfx::Point(26, 436)));
531 EXPECT_EQ(w13.get(), root->GetEventHandlerForPoint(gfx::Point(26, 481))); 544 EXPECT_EQ(w13.get(), root->GetEventHandlerForPoint(gfx::Point(26, 481)));
532 } 545 }
533 546
534 TEST_F(WindowTest, GetEventHandlerForPointWithOverride) { 547 TEST_F(WindowTest, GetEventHandlerForPointWithOverride) {
535 // If our child is flush to our top-left corner he gets events just inside the 548 // If our child is flush to our top-left corner he gets events just inside the
536 // window edges. 549 // window edges.
537 scoped_ptr<Window> parent( 550 scoped_ptr<Window> parent(
538 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 20, 400, 500), NULL)); 551 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 20, 400, 500),
552 root_window()));
539 scoped_ptr<Window> child( 553 scoped_ptr<Window> child(
540 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 60, 70), parent.get())); 554 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 60, 70), parent.get()));
541 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); 555 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0)));
542 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); 556 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1)));
543 557
544 // We can override the hit test bounds of the parent to make the parent grab 558 // We can override the hit test bounds of the parent to make the parent grab
545 // events along that edge. 559 // events along that edge.
546 parent->set_hit_test_bounds_override_inner(gfx::Insets(1, 1, 1, 1)); 560 parent->set_hit_test_bounds_override_inner(gfx::Insets(1, 1, 1, 1));
547 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); 561 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0)));
548 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); 562 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1)));
549 } 563 }
550 564
551 TEST_F(WindowTest, GetEventHandlerForPointWithOverrideDescendingOrder) { 565 TEST_F(WindowTest, GetEventHandlerForPointWithOverrideDescendingOrder) {
552 scoped_ptr<SelfEventHandlingWindowDelegate> parent_delegate( 566 scoped_ptr<SelfEventHandlingWindowDelegate> parent_delegate(
553 new SelfEventHandlingWindowDelegate); 567 new SelfEventHandlingWindowDelegate);
554 scoped_ptr<Window> parent(CreateTestWindowWithDelegate( 568 scoped_ptr<Window> parent(CreateTestWindowWithDelegate(
555 parent_delegate.get(), 1, gfx::Rect(10, 20, 400, 500), NULL)); 569 parent_delegate.get(), 1, gfx::Rect(10, 20, 400, 500), root_window()));
556 scoped_ptr<Window> child( 570 scoped_ptr<Window> child(
557 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 390, 480), 571 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 390, 480),
558 parent.get())); 572 parent.get()));
559 573
560 // We can override ShouldDescendIntoChildForEventHandling to make the parent 574 // We can override ShouldDescendIntoChildForEventHandling to make the parent
561 // grab all events. 575 // grab all events.
562 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); 576 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0)));
563 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(50, 50))); 577 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(50, 50)));
564 } 578 }
565 579
566 TEST_F(WindowTest, GetTopWindowContainingPoint) { 580 TEST_F(WindowTest, GetTopWindowContainingPoint) {
567 Window* root = root_window(); 581 Window* root = root_window();
568 root->SetBounds(gfx::Rect(0, 0, 300, 300)); 582 root->SetBounds(gfx::Rect(0, 0, 300, 300));
569 583
570 scoped_ptr<Window> w1( 584 scoped_ptr<Window> w1(
571 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100), NULL)); 585 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100),
586 root_window()));
572 scoped_ptr<Window> w11( 587 scoped_ptr<Window> w11(
573 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(0, 0, 120, 120), w1.get())); 588 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(0, 0, 120, 120), w1.get()));
574 589
575 scoped_ptr<Window> w2( 590 scoped_ptr<Window> w2(
576 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(5, 5, 55, 55), NULL)); 591 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(5, 5, 55, 55),
592 root_window()));
577 593
578 scoped_ptr<Window> w3( 594 scoped_ptr<Window> w3(
579 CreateTestWindowWithDelegate( 595 CreateTestWindowWithDelegate(
580 NULL, 3, gfx::Rect(200, 200, 100, 100), NULL)); 596 NULL, 3, gfx::Rect(200, 200, 100, 100), root_window()));
581 scoped_ptr<Window> w31( 597 scoped_ptr<Window> w31(
582 CreateTestWindow(SK_ColorCYAN, 31, gfx::Rect(0, 0, 50, 50), w3.get())); 598 CreateTestWindow(SK_ColorCYAN, 31, gfx::Rect(0, 0, 50, 50), w3.get()));
583 scoped_ptr<Window> w311( 599 scoped_ptr<Window> w311(
584 CreateTestWindow(SK_ColorBLUE, 311, gfx::Rect(0, 0, 10, 10), w31.get())); 600 CreateTestWindow(SK_ColorBLUE, 311, gfx::Rect(0, 0, 10, 10), w31.get()));
585 601
586 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(0, 0))); 602 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(0, 0)));
587 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(5, 5))); 603 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(5, 5)));
588 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(10, 10))); 604 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(10, 10)));
589 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(59, 59))); 605 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(59, 59)));
590 EXPECT_EQ(w1.get(), root->GetTopWindowContainingPoint(gfx::Point(60, 60))); 606 EXPECT_EQ(w1.get(), root->GetTopWindowContainingPoint(gfx::Point(60, 60)));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 641
626 private: 642 private:
627 bool called_; 643 bool called_;
628 644
629 DISALLOW_COPY_AND_ASSIGN(AddedToRootWindowObserver); 645 DISALLOW_COPY_AND_ASSIGN(AddedToRootWindowObserver);
630 }; 646 };
631 647
632 TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) { 648 TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) {
633 AddedToRootWindowObserver parent_observer; 649 AddedToRootWindowObserver parent_observer;
634 AddedToRootWindowObserver child_observer; 650 AddedToRootWindowObserver child_observer;
635 scoped_ptr<Window> parent_window(CreateTestWindowWithId(1, NULL)); 651 scoped_ptr<Window> parent_window(CreateTestWindowWithId(1, root_window()));
636 scoped_ptr<Window> child_window(new Window(NULL)); 652 scoped_ptr<Window> child_window(new Window(NULL));
637 child_window->Init(ui::LAYER_TEXTURED); 653 child_window->Init(ui::LAYER_TEXTURED);
638 child_window->Show(); 654 child_window->Show();
639 655
640 parent_window->AddObserver(&parent_observer); 656 parent_window->AddObserver(&parent_observer);
641 child_window->AddObserver(&child_observer); 657 child_window->AddObserver(&child_observer);
642 658
643 parent_window->AddChild(child_window.get()); 659 parent_window->AddChild(child_window.get());
644 660
645 EXPECT_FALSE(parent_observer.called()); 661 EXPECT_FALSE(parent_observer.called());
646 EXPECT_TRUE(child_observer.called()); 662 EXPECT_TRUE(child_observer.called());
647 663
648 parent_window->RemoveObserver(&parent_observer); 664 parent_window->RemoveObserver(&parent_observer);
649 child_window->RemoveObserver(&child_observer); 665 child_window->RemoveObserver(&child_observer);
650 } 666 }
651 667
652 // Various destruction assertions. 668 // Various destruction assertions.
653 TEST_F(WindowTest, DestroyTest) { 669 TEST_F(WindowTest, DestroyTest) {
654 DestroyTrackingDelegateImpl parent_delegate; 670 DestroyTrackingDelegateImpl parent_delegate;
655 ChildWindowDelegateImpl child_delegate(&parent_delegate); 671 ChildWindowDelegateImpl child_delegate(&parent_delegate);
656 { 672 {
657 scoped_ptr<Window> parent( 673 scoped_ptr<Window> parent(
658 CreateTestWindowWithDelegate(&parent_delegate, 0, gfx::Rect(), NULL)); 674 CreateTestWindowWithDelegate(&parent_delegate, 0, gfx::Rect(),
675 root_window()));
659 CreateTestWindowWithDelegate(&child_delegate, 0, gfx::Rect(), parent.get()); 676 CreateTestWindowWithDelegate(&child_delegate, 0, gfx::Rect(), parent.get());
660 } 677 }
661 // Both the parent and child should have been destroyed. 678 // Both the parent and child should have been destroyed.
662 EXPECT_EQ(1, parent_delegate.destroying_count()); 679 EXPECT_EQ(1, parent_delegate.destroying_count());
663 EXPECT_EQ(1, parent_delegate.destroyed_count()); 680 EXPECT_EQ(1, parent_delegate.destroyed_count());
664 EXPECT_EQ(1, child_delegate.destroying_count()); 681 EXPECT_EQ(1, child_delegate.destroying_count());
665 EXPECT_EQ(1, child_delegate.destroyed_count()); 682 EXPECT_EQ(1, child_delegate.destroyed_count());
666 } 683 }
667 684
668 // Tests that a window is orphaned before OnWindowDestroyed is called. 685 // Tests that a window is orphaned before OnWindowDestroyed is called.
669 TEST_F(WindowTest, OrphanedBeforeOnDestroyed) { 686 TEST_F(WindowTest, OrphanedBeforeOnDestroyed) {
670 TestWindowDelegate parent_delegate; 687 TestWindowDelegate parent_delegate;
671 DestroyOrphanDelegate child_delegate; 688 DestroyOrphanDelegate child_delegate;
672 { 689 {
673 scoped_ptr<Window> parent( 690 scoped_ptr<Window> parent(
674 CreateTestWindowWithDelegate(&parent_delegate, 0, gfx::Rect(), NULL)); 691 CreateTestWindowWithDelegate(&parent_delegate, 0, gfx::Rect(),
692 root_window()));
675 scoped_ptr<Window> child(CreateTestWindowWithDelegate(&child_delegate, 0, 693 scoped_ptr<Window> child(CreateTestWindowWithDelegate(&child_delegate, 0,
676 gfx::Rect(), parent.get())); 694 gfx::Rect(), parent.get()));
677 child_delegate.set_window(child.get()); 695 child_delegate.set_window(child.get());
678 } 696 }
679 } 697 }
680 698
681 // Make sure StackChildAtTop moves both the window and layer to the front. 699 // Make sure StackChildAtTop moves both the window and layer to the front.
682 TEST_F(WindowTest, StackChildAtTop) { 700 TEST_F(WindowTest, StackChildAtTop) {
683 Window parent(NULL); 701 Window parent(NULL);
684 parent.Init(ui::LAYER_NOT_DRAWN); 702 parent.Init(ui::LAYER_NOT_DRAWN);
685 Window child1(NULL); 703 Window child1(NULL);
686 child1.Init(ui::LAYER_NOT_DRAWN); 704 child1.Init(ui::LAYER_NOT_DRAWN);
687 Window child2(NULL); 705 Window child2(NULL);
688 child2.Init(ui::LAYER_NOT_DRAWN); 706 child2.Init(ui::LAYER_NOT_DRAWN);
689 707
690 child1.SetParent(&parent); 708 parent.AddChild(&child1);
691 child2.SetParent(&parent); 709 parent.AddChild(&child2);
692 ASSERT_EQ(2u, parent.children().size()); 710 ASSERT_EQ(2u, parent.children().size());
693 EXPECT_EQ(&child1, parent.children()[0]); 711 EXPECT_EQ(&child1, parent.children()[0]);
694 EXPECT_EQ(&child2, parent.children()[1]); 712 EXPECT_EQ(&child2, parent.children()[1]);
695 ASSERT_EQ(2u, parent.layer()->children().size()); 713 ASSERT_EQ(2u, parent.layer()->children().size());
696 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]); 714 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]);
697 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]); 715 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]);
698 716
699 parent.StackChildAtTop(&child1); 717 parent.StackChildAtTop(&child1);
700 ASSERT_EQ(2u, parent.children().size()); 718 ASSERT_EQ(2u, parent.children().size());
701 EXPECT_EQ(&child1, parent.children()[1]); 719 EXPECT_EQ(&child1, parent.children()[1]);
(...skipping 10 matching lines...) Expand all
712 Window child1(NULL); 730 Window child1(NULL);
713 child1.Init(ui::LAYER_NOT_DRAWN); 731 child1.Init(ui::LAYER_NOT_DRAWN);
714 child1.set_id(1); 732 child1.set_id(1);
715 Window child2(NULL); 733 Window child2(NULL);
716 child2.Init(ui::LAYER_NOT_DRAWN); 734 child2.Init(ui::LAYER_NOT_DRAWN);
717 child2.set_id(2); 735 child2.set_id(2);
718 Window child3(NULL); 736 Window child3(NULL);
719 child3.Init(ui::LAYER_NOT_DRAWN); 737 child3.Init(ui::LAYER_NOT_DRAWN);
720 child3.set_id(3); 738 child3.set_id(3);
721 739
722 child1.SetParent(&parent); 740 parent.AddChild(&child1);
723 child2.SetParent(&parent); 741 parent.AddChild(&child2);
724 child3.SetParent(&parent); 742 parent.AddChild(&child3);
725 EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent)); 743 EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent));
726 744
727 parent.StackChildBelow(&child1, &child2); 745 parent.StackChildBelow(&child1, &child2);
728 EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent)); 746 EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent));
729 747
730 parent.StackChildBelow(&child2, &child1); 748 parent.StackChildBelow(&child2, &child1);
731 EXPECT_EQ("2 1 3", ChildWindowIDsAsString(&parent)); 749 EXPECT_EQ("2 1 3", ChildWindowIDsAsString(&parent));
732 750
733 parent.StackChildBelow(&child3, &child2); 751 parent.StackChildBelow(&child3, &child2);
734 EXPECT_EQ("3 2 1", ChildWindowIDsAsString(&parent)); 752 EXPECT_EQ("3 2 1", ChildWindowIDsAsString(&parent));
735 753
736 parent.StackChildBelow(&child3, &child1); 754 parent.StackChildBelow(&child3, &child1);
737 EXPECT_EQ("2 3 1", ChildWindowIDsAsString(&parent)); 755 EXPECT_EQ("2 3 1", ChildWindowIDsAsString(&parent));
738 } 756 }
739 757
740 // Various assertions for StackChildAbove. 758 // Various assertions for StackChildAbove.
741 TEST_F(WindowTest, StackChildAbove) { 759 TEST_F(WindowTest, StackChildAbove) {
742 Window parent(NULL); 760 Window parent(NULL);
743 parent.Init(ui::LAYER_NOT_DRAWN); 761 parent.Init(ui::LAYER_NOT_DRAWN);
744 Window child1(NULL); 762 Window child1(NULL);
745 child1.Init(ui::LAYER_NOT_DRAWN); 763 child1.Init(ui::LAYER_NOT_DRAWN);
746 Window child2(NULL); 764 Window child2(NULL);
747 child2.Init(ui::LAYER_NOT_DRAWN); 765 child2.Init(ui::LAYER_NOT_DRAWN);
748 Window child3(NULL); 766 Window child3(NULL);
749 child3.Init(ui::LAYER_NOT_DRAWN); 767 child3.Init(ui::LAYER_NOT_DRAWN);
750 768
751 child1.SetParent(&parent); 769 parent.AddChild(&child1);
752 child2.SetParent(&parent); 770 parent.AddChild(&child2);
753 771
754 // Move 1 in front of 2. 772 // Move 1 in front of 2.
755 parent.StackChildAbove(&child1, &child2); 773 parent.StackChildAbove(&child1, &child2);
756 ASSERT_EQ(2u, parent.children().size()); 774 ASSERT_EQ(2u, parent.children().size());
757 EXPECT_EQ(&child2, parent.children()[0]); 775 EXPECT_EQ(&child2, parent.children()[0]);
758 EXPECT_EQ(&child1, parent.children()[1]); 776 EXPECT_EQ(&child1, parent.children()[1]);
759 ASSERT_EQ(2u, parent.layer()->children().size()); 777 ASSERT_EQ(2u, parent.layer()->children().size());
760 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); 778 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]);
761 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); 779 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]);
762 780
763 // Add 3, resulting in order [2, 1, 3], then move 2 in front of 1, resulting 781 // Add 3, resulting in order [2, 1, 3], then move 2 in front of 1, resulting
764 // in [1, 2, 3]. 782 // in [1, 2, 3].
765 child3.SetParent(&parent); 783 parent.AddChild(&child3);
766 parent.StackChildAbove(&child2, &child1); 784 parent.StackChildAbove(&child2, &child1);
767 ASSERT_EQ(3u, parent.children().size()); 785 ASSERT_EQ(3u, parent.children().size());
768 EXPECT_EQ(&child1, parent.children()[0]); 786 EXPECT_EQ(&child1, parent.children()[0]);
769 EXPECT_EQ(&child2, parent.children()[1]); 787 EXPECT_EQ(&child2, parent.children()[1]);
770 EXPECT_EQ(&child3, parent.children()[2]); 788 EXPECT_EQ(&child3, parent.children()[2]);
771 ASSERT_EQ(3u, parent.layer()->children().size()); 789 ASSERT_EQ(3u, parent.layer()->children().size());
772 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]); 790 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]);
773 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]); 791 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]);
774 EXPECT_EQ(child3.layer(), parent.layer()->children()[2]); 792 EXPECT_EQ(child3.layer(), parent.layer()->children()[2]);
775 793
(...skipping 17 matching lines...) Expand all
793 ASSERT_EQ(3u, parent.layer()->children().size()); 811 ASSERT_EQ(3u, parent.layer()->children().size());
794 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); 812 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]);
795 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); 813 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]);
796 EXPECT_EQ(child3.layer(), parent.layer()->children()[2]); 814 EXPECT_EQ(child3.layer(), parent.layer()->children()[2]);
797 } 815 }
798 816
799 // Various capture assertions. 817 // Various capture assertions.
800 TEST_F(WindowTest, CaptureTests) { 818 TEST_F(WindowTest, CaptureTests) {
801 CaptureWindowDelegateImpl delegate; 819 CaptureWindowDelegateImpl delegate;
802 scoped_ptr<Window> window(CreateTestWindowWithDelegate( 820 scoped_ptr<Window> window(CreateTestWindowWithDelegate(
803 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); 821 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window()));
804 EXPECT_FALSE(window->HasCapture()); 822 EXPECT_FALSE(window->HasCapture());
805 823
806 delegate.ResetCounts(); 824 delegate.ResetCounts();
807 825
808 // Do a capture. 826 // Do a capture.
809 window->SetCapture(); 827 window->SetCapture();
810 EXPECT_TRUE(window->HasCapture()); 828 EXPECT_TRUE(window->HasCapture());
811 EXPECT_EQ(0, delegate.capture_lost_count()); 829 EXPECT_EQ(0, delegate.capture_lost_count());
812 EXPECT_EQ(0, delegate.capture_changed_event_count()); 830 EXPECT_EQ(0, delegate.capture_changed_event_count());
813 EventGenerator generator(root_window(), gfx::Point(50, 50)); 831 EventGenerator generator(root_window(), gfx::Point(50, 50));
(...skipping 30 matching lines...) Expand all
844 window->SetCapture(); 862 window->SetCapture();
845 EXPECT_EQ(window.get(), aura::client::GetCaptureWindow(root_window())); 863 EXPECT_EQ(window.get(), aura::client::GetCaptureWindow(root_window()));
846 window->parent()->RemoveChild(window.get()); 864 window->parent()->RemoveChild(window.get());
847 EXPECT_FALSE(window->HasCapture()); 865 EXPECT_FALSE(window->HasCapture());
848 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); 866 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window()));
849 } 867 }
850 868
851 TEST_F(WindowTest, TouchCaptureCancelsOtherTouches) { 869 TEST_F(WindowTest, TouchCaptureCancelsOtherTouches) {
852 CaptureWindowDelegateImpl delegate1; 870 CaptureWindowDelegateImpl delegate1;
853 scoped_ptr<Window> w1(CreateTestWindowWithDelegate( 871 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(
854 &delegate1, 0, gfx::Rect(0, 0, 20, 20), NULL)); 872 &delegate1, 0, gfx::Rect(0, 0, 20, 20), root_window()));
855 CaptureWindowDelegateImpl delegate2; 873 CaptureWindowDelegateImpl delegate2;
856 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( 874 scoped_ptr<Window> w2(CreateTestWindowWithDelegate(
857 &delegate2, 0, gfx::Rect(20, 20, 20, 20), NULL)); 875 &delegate2, 0, gfx::Rect(20, 20, 20, 20), root_window()));
858 876
859 // Press on w1. 877 // Press on w1.
860 ui::TouchEvent press( 878 ui::TouchEvent press(
861 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); 879 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime());
862 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 880 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
863 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. 881 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN.
864 EXPECT_EQ(2, delegate1.gesture_event_count()); 882 EXPECT_EQ(2, delegate1.gesture_event_count());
865 delegate1.ResetCounts(); 883 delegate1.ResetCounts();
866 w2->SetCapture(); 884 w2->SetCapture();
867 885
(...skipping 24 matching lines...) Expand all
892 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); 910 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime());
893 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 911 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
894 EXPECT_EQ(0, delegate1.gesture_event_count()); 912 EXPECT_EQ(0, delegate1.gesture_event_count());
895 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. 913 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN.
896 EXPECT_EQ(2, delegate2.gesture_event_count()); 914 EXPECT_EQ(2, delegate2.gesture_event_count());
897 } 915 }
898 916
899 TEST_F(WindowTest, TouchCaptureDoesntCancelCapturedTouches) { 917 TEST_F(WindowTest, TouchCaptureDoesntCancelCapturedTouches) {
900 CaptureWindowDelegateImpl delegate; 918 CaptureWindowDelegateImpl delegate;
901 scoped_ptr<Window> window(CreateTestWindowWithDelegate( 919 scoped_ptr<Window> window(CreateTestWindowWithDelegate(
902 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); 920 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window()));
903 921
904 ui::TouchEvent press( 922 ui::TouchEvent press(
905 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); 923 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime());
906 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 924 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
907 925
908 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. 926 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN.
909 EXPECT_EQ(2, delegate.gesture_event_count()); 927 EXPECT_EQ(2, delegate.gesture_event_count());
910 delegate.ResetCounts(); 928 delegate.ResetCounts();
911 929
912 window->SetCapture(); 930 window->SetCapture();
913 EXPECT_EQ(0, delegate.gesture_event_count()); 931 EXPECT_EQ(0, delegate.gesture_event_count());
914 delegate.ResetCounts(); 932 delegate.ResetCounts();
915 933
916 // The move event should still create a gesture, as this touch was 934 // The move event should still create a gesture, as this touch was
917 // on the window which was captured. 935 // on the window which was captured.
918 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, 936 ui::TouchEvent release(ui::ET_TOUCH_RELEASED,
919 gfx::Point(10, 10), 0, getTime() + 937 gfx::Point(10, 10), 0, getTime() +
920 base::TimeDelta::FromMilliseconds(50)); 938 base::TimeDelta::FromMilliseconds(50));
921 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 939 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
922 EXPECT_EQ(2, delegate.gesture_event_count()); 940 EXPECT_EQ(2, delegate.gesture_event_count());
923 } 941 }
924 942
925 // Assertions around SetCapture() and touch/gestures. 943 // Assertions around SetCapture() and touch/gestures.
926 TEST_F(WindowTest, TransferCaptureTouchEvents) { 944 TEST_F(WindowTest, TransferCaptureTouchEvents) {
927 // Touch on |w1|. 945 // Touch on |w1|.
928 CaptureWindowDelegateImpl d1; 946 CaptureWindowDelegateImpl d1;
929 scoped_ptr<Window> w1(CreateTestWindowWithDelegate( 947 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(
930 &d1, 0, gfx::Rect(0, 0, 20, 20), NULL)); 948 &d1, 0, gfx::Rect(0, 0, 20, 20), root_window()));
931 ui::TouchEvent p1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); 949 ui::TouchEvent p1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime());
932 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&p1); 950 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&p1);
933 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. 951 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN.
934 EXPECT_EQ(2, d1.gesture_event_count()); 952 EXPECT_EQ(2, d1.gesture_event_count());
935 d1.ResetCounts(); 953 d1.ResetCounts();
936 954
937 // Touch on |w2| with a different id. 955 // Touch on |w2| with a different id.
938 CaptureWindowDelegateImpl d2; 956 CaptureWindowDelegateImpl d2;
939 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( 957 scoped_ptr<Window> w2(CreateTestWindowWithDelegate(
940 &d2, 0, gfx::Rect(40, 0, 40, 20), NULL)); 958 &d2, 0, gfx::Rect(40, 0, 40, 20), root_window()));
941 ui::TouchEvent p2(ui::ET_TOUCH_PRESSED, gfx::Point(41, 10), 1, getTime()); 959 ui::TouchEvent p2(ui::ET_TOUCH_PRESSED, gfx::Point(41, 10), 1, getTime());
942 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&p2); 960 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&p2);
943 EXPECT_EQ(0, d1.gesture_event_count()); 961 EXPECT_EQ(0, d1.gesture_event_count());
944 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN for new target window. 962 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN for new target window.
945 EXPECT_EQ(2, d2.gesture_event_count()); 963 EXPECT_EQ(2, d2.gesture_event_count());
946 d1.ResetCounts(); 964 d1.ResetCounts();
947 d2.ResetCounts(); 965 d2.ResetCounts();
948 966
949 // Set capture on |w2|, this should send a cancel (TAP_CANCEL, END) to |w1| 967 // Set capture on |w2|, this should send a cancel (TAP_CANCEL, END) to |w1|
950 // but not |w2|. 968 // but not |w2|.
951 w2->SetCapture(); 969 w2->SetCapture();
952 EXPECT_EQ(2, d1.gesture_event_count()); 970 EXPECT_EQ(2, d1.gesture_event_count());
953 EXPECT_EQ(0, d2.gesture_event_count()); 971 EXPECT_EQ(0, d2.gesture_event_count());
954 d1.ResetCounts(); 972 d1.ResetCounts();
955 d2.ResetCounts(); 973 d2.ResetCounts();
956 974
957 CaptureWindowDelegateImpl d3; 975 CaptureWindowDelegateImpl d3;
958 scoped_ptr<Window> w3(CreateTestWindowWithDelegate( 976 scoped_ptr<Window> w3(CreateTestWindowWithDelegate(
959 &d3, 0, gfx::Rect(0, 0, 100, 101), NULL)); 977 &d3, 0, gfx::Rect(0, 0, 100, 101), root_window()));
960 // Set capture on w3. No new events should be received. 978 // Set capture on w3. No new events should be received.
961 w3->SetCapture(); 979 w3->SetCapture();
962 EXPECT_EQ(0, d1.gesture_event_count()); 980 EXPECT_EQ(0, d1.gesture_event_count());
963 EXPECT_EQ(0, d2.gesture_event_count()); 981 EXPECT_EQ(0, d2.gesture_event_count());
964 EXPECT_EQ(0, d3.gesture_event_count()); 982 EXPECT_EQ(0, d3.gesture_event_count());
965 983
966 // Move touch id originally associated with |w2|. Since capture was transfered 984 // Move touch id originally associated with |w2|. Since capture was transfered
967 // from 2 to 3 only |w3| should get the event. 985 // from 2 to 3 only |w3| should get the event.
968 ui::TouchEvent m3(ui::ET_TOUCH_MOVED, gfx::Point(110, 105), 1, getTime()); 986 ui::TouchEvent m3(ui::ET_TOUCH_MOVED, gfx::Point(110, 105), 1, getTime());
969 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&m3); 987 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&m3);
970 EXPECT_EQ(0, d1.gesture_event_count()); 988 EXPECT_EQ(0, d1.gesture_event_count());
971 EXPECT_EQ(0, d2.gesture_event_count()); 989 EXPECT_EQ(0, d2.gesture_event_count());
972 // |w3| gets a TAP_CANCEL and two scroll related events. 990 // |w3| gets a TAP_CANCEL and two scroll related events.
973 EXPECT_EQ(3, d3.gesture_event_count()); 991 EXPECT_EQ(3, d3.gesture_event_count());
974 } 992 }
975 993
976 // Changes capture while capture is already ongoing. 994 // Changes capture while capture is already ongoing.
977 TEST_F(WindowTest, ChangeCaptureWhileMouseDown) { 995 TEST_F(WindowTest, ChangeCaptureWhileMouseDown) {
978 CaptureWindowDelegateImpl delegate; 996 CaptureWindowDelegateImpl delegate;
979 scoped_ptr<Window> window(CreateTestWindowWithDelegate( 997 scoped_ptr<Window> window(CreateTestWindowWithDelegate(
980 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); 998 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window()));
981 CaptureWindowDelegateImpl delegate2; 999 CaptureWindowDelegateImpl delegate2;
982 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( 1000 scoped_ptr<Window> w2(CreateTestWindowWithDelegate(
983 &delegate2, 0, gfx::Rect(20, 20, 20, 20), NULL)); 1001 &delegate2, 0, gfx::Rect(20, 20, 20, 20), root_window()));
984 1002
985 // Execute the scheduled draws so that mouse events are not 1003 // Execute the scheduled draws so that mouse events are not
986 // aggregated. 1004 // aggregated.
987 RunAllPendingInMessageLoop(); 1005 RunAllPendingInMessageLoop();
988 1006
989 EXPECT_FALSE(window->HasCapture()); 1007 EXPECT_FALSE(window->HasCapture());
990 1008
991 // Do a capture. 1009 // Do a capture.
992 delegate.ResetCounts(); 1010 delegate.ResetCounts();
993 window->SetCapture(); 1011 window->SetCapture();
(...skipping 15 matching lines...) Expand all
1009 EXPECT_EQ(1, delegate.capture_lost_count()); 1027 EXPECT_EQ(1, delegate.capture_lost_count());
1010 EXPECT_EQ(1, delegate.capture_changed_event_count()); 1028 EXPECT_EQ(1, delegate.capture_changed_event_count());
1011 EXPECT_EQ(1, delegate.mouse_event_count()); 1029 EXPECT_EQ(1, delegate.mouse_event_count());
1012 EXPECT_EQ(2, delegate2.mouse_event_count()); 1030 EXPECT_EQ(2, delegate2.mouse_event_count());
1013 } 1031 }
1014 1032
1015 // Verifies capture is reset when a window is destroyed. 1033 // Verifies capture is reset when a window is destroyed.
1016 TEST_F(WindowTest, ReleaseCaptureOnDestroy) { 1034 TEST_F(WindowTest, ReleaseCaptureOnDestroy) {
1017 CaptureWindowDelegateImpl delegate; 1035 CaptureWindowDelegateImpl delegate;
1018 scoped_ptr<Window> window(CreateTestWindowWithDelegate( 1036 scoped_ptr<Window> window(CreateTestWindowWithDelegate(
1019 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); 1037 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window()));
1020 EXPECT_FALSE(window->HasCapture()); 1038 EXPECT_FALSE(window->HasCapture());
1021 1039
1022 // Do a capture. 1040 // Do a capture.
1023 window->SetCapture(); 1041 window->SetCapture();
1024 EXPECT_TRUE(window->HasCapture()); 1042 EXPECT_TRUE(window->HasCapture());
1025 1043
1026 // Destroy the window. 1044 // Destroy the window.
1027 window.reset(); 1045 window.reset();
1028 1046
1029 // Make sure the root window doesn't reference the window anymore. 1047 // Make sure the root window doesn't reference the window anymore.
1030 EXPECT_EQ(NULL, root_window()->mouse_pressed_handler()); 1048 EXPECT_EQ(NULL, root_window()->mouse_pressed_handler());
1031 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); 1049 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window()));
1032 } 1050 }
1033 1051
1034 TEST_F(WindowTest, GetBoundsInRootWindow) { 1052 TEST_F(WindowTest, GetBoundsInRootWindow) {
1035 scoped_ptr<Window> viewport(CreateTestWindowWithBounds( 1053 scoped_ptr<Window> viewport(CreateTestWindowWithBounds(
1036 gfx::Rect(0, 0, 300, 300), NULL)); 1054 gfx::Rect(0, 0, 300, 300), root_window()));
1037 scoped_ptr<Window> child(CreateTestWindowWithBounds( 1055 scoped_ptr<Window> child(CreateTestWindowWithBounds(
1038 gfx::Rect(0, 0, 100, 100), viewport.get())); 1056 gfx::Rect(0, 0, 100, 100), viewport.get()));
1039 // Sanity check. 1057 // Sanity check.
1040 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); 1058 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString());
1041 1059
1042 // The |child| window's screen bounds should move along with the |viewport|. 1060 // The |child| window's screen bounds should move along with the |viewport|.
1043 viewport->SetBounds(gfx::Rect(-100, -100, 300, 300)); 1061 viewport->SetBounds(gfx::Rect(-100, -100, 300, 300));
1044 EXPECT_EQ("-100,-100 100x100", child->GetBoundsInRootWindow().ToString()); 1062 EXPECT_EQ("-100,-100 100x100", child->GetBoundsInRootWindow().ToString());
1045 1063
1046 // The |child| window is moved to the 0,0 in screen coordinates. 1064 // The |child| window is moved to the 0,0 in screen coordinates.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 1100
1083 DISALLOW_COPY_AND_ASSIGN(MouseEnterExitWindowDelegate); 1101 DISALLOW_COPY_AND_ASSIGN(MouseEnterExitWindowDelegate);
1084 }; 1102 };
1085 1103
1086 1104
1087 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for 1105 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for
1088 // mouse transitions from window to window. 1106 // mouse transitions from window to window.
1089 TEST_F(WindowTest, MouseEnterExit) { 1107 TEST_F(WindowTest, MouseEnterExit) {
1090 MouseEnterExitWindowDelegate d1; 1108 MouseEnterExitWindowDelegate d1;
1091 scoped_ptr<Window> w1( 1109 scoped_ptr<Window> w1(
1092 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL)); 1110 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50),
1111 root_window()));
1093 MouseEnterExitWindowDelegate d2; 1112 MouseEnterExitWindowDelegate d2;
1094 scoped_ptr<Window> w2( 1113 scoped_ptr<Window> w2(
1095 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50), NULL)); 1114 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50),
1115 root_window()));
1096 1116
1097 test::EventGenerator generator(root_window()); 1117 test::EventGenerator generator(root_window());
1098 generator.MoveMouseToCenterOf(w1.get()); 1118 generator.MoveMouseToCenterOf(w1.get());
1099 EXPECT_TRUE(d1.entered()); 1119 EXPECT_TRUE(d1.entered());
1100 EXPECT_FALSE(d1.exited()); 1120 EXPECT_FALSE(d1.exited());
1101 EXPECT_FALSE(d2.entered()); 1121 EXPECT_FALSE(d2.entered());
1102 EXPECT_FALSE(d2.exited()); 1122 EXPECT_FALSE(d2.exited());
1103 1123
1104 generator.MoveMouseToCenterOf(w2.get()); 1124 generator.MoveMouseToCenterOf(w2.get());
1105 EXPECT_TRUE(d1.entered()); 1125 EXPECT_TRUE(d1.entered());
1106 EXPECT_TRUE(d1.exited()); 1126 EXPECT_TRUE(d1.exited());
1107 EXPECT_TRUE(d2.entered()); 1127 EXPECT_TRUE(d2.entered());
1108 EXPECT_FALSE(d2.exited()); 1128 EXPECT_FALSE(d2.exited());
1109 } 1129 }
1110 1130
1111 #if !defined(OS_WIN) 1131 #if !defined(OS_WIN)
1112 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for 1132 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for
1113 // mouse transitions from window to window, even if the entered window sets 1133 // mouse transitions from window to window, even if the entered window sets
1114 // and releases capture. 1134 // and releases capture.
1115 TEST_F(WindowTest, MouseEnterExitWithClick) { 1135 TEST_F(WindowTest, MouseEnterExitWithClick) {
1116 MouseEnterExitWindowDelegate d1; 1136 MouseEnterExitWindowDelegate d1;
1117 scoped_ptr<Window> w1( 1137 scoped_ptr<Window> w1(
1118 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL)); 1138 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50),
1139 root_window()));
1119 MouseEnterExitWindowDelegate d2; 1140 MouseEnterExitWindowDelegate d2;
1120 scoped_ptr<Window> w2( 1141 scoped_ptr<Window> w2(
1121 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50), NULL)); 1142 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50),
1143 root_window()));
1122 1144
1123 test::EventGenerator generator(root_window()); 1145 test::EventGenerator generator(root_window());
1124 generator.MoveMouseToCenterOf(w1.get()); 1146 generator.MoveMouseToCenterOf(w1.get());
1125 EXPECT_TRUE(d1.entered()); 1147 EXPECT_TRUE(d1.entered());
1126 EXPECT_FALSE(d1.exited()); 1148 EXPECT_FALSE(d1.exited());
1127 EXPECT_FALSE(d2.entered()); 1149 EXPECT_FALSE(d2.entered());
1128 EXPECT_FALSE(d2.exited()); 1150 EXPECT_FALSE(d2.exited());
1129 1151
1130 // Emmulate what Views does on a click by grabbing and releasing capture. 1152 // Emmulate what Views does on a click by grabbing and releasing capture.
1131 generator.PressLeftButton(); 1153 generator.PressLeftButton();
1132 w1->SetCapture(); 1154 w1->SetCapture();
1133 w1->ReleaseCapture(); 1155 w1->ReleaseCapture();
1134 generator.ReleaseLeftButton(); 1156 generator.ReleaseLeftButton();
1135 1157
1136 generator.MoveMouseToCenterOf(w2.get()); 1158 generator.MoveMouseToCenterOf(w2.get());
1137 EXPECT_TRUE(d1.entered()); 1159 EXPECT_TRUE(d1.entered());
1138 EXPECT_TRUE(d1.exited()); 1160 EXPECT_TRUE(d1.exited());
1139 EXPECT_TRUE(d2.entered()); 1161 EXPECT_TRUE(d2.entered());
1140 EXPECT_FALSE(d2.exited()); 1162 EXPECT_FALSE(d2.exited());
1141 } 1163 }
1142 1164
1143 // Temporarily disabled for windows. See crbug.com/112222. 1165 // Temporarily disabled for windows. See crbug.com/112222.
1144 // Verifies that enter / exits are sent if windows appear and are deleted 1166 // Verifies that enter / exits are sent if windows appear and are deleted
1145 // under the current mouse position.. 1167 // under the current mouse position..
1146 TEST_F(WindowTest, MouseEnterExitWithDelete) { 1168 TEST_F(WindowTest, MouseEnterExitWithDelete) {
1147 MouseEnterExitWindowDelegate d1; 1169 MouseEnterExitWindowDelegate d1;
1148 scoped_ptr<Window> w1( 1170 scoped_ptr<Window> w1(
1149 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL)); 1171 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50),
1172 root_window()));
1150 1173
1151 test::EventGenerator generator(root_window()); 1174 test::EventGenerator generator(root_window());
1152 generator.MoveMouseToCenterOf(w1.get()); 1175 generator.MoveMouseToCenterOf(w1.get());
1153 EXPECT_TRUE(d1.entered()); 1176 EXPECT_TRUE(d1.entered());
1154 EXPECT_FALSE(d1.exited()); 1177 EXPECT_FALSE(d1.exited());
1155 1178
1156 { 1179 {
1157 MouseEnterExitWindowDelegate d2; 1180 MouseEnterExitWindowDelegate d2;
1158 scoped_ptr<Window> w2( 1181 scoped_ptr<Window> w2(
1159 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), NULL)); 1182 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50),
1183 root_window()));
1160 // Enters / exits can be send asynchronously. 1184 // Enters / exits can be send asynchronously.
1161 RunAllPendingInMessageLoop(); 1185 RunAllPendingInMessageLoop();
1162 EXPECT_TRUE(d1.entered()); 1186 EXPECT_TRUE(d1.entered());
1163 EXPECT_TRUE(d1.exited()); 1187 EXPECT_TRUE(d1.exited());
1164 EXPECT_TRUE(d2.entered()); 1188 EXPECT_TRUE(d2.entered());
1165 EXPECT_FALSE(d2.exited()); 1189 EXPECT_FALSE(d2.exited());
1166 d1.ResetExpectations(); 1190 d1.ResetExpectations();
1167 } 1191 }
1168 // Enters / exits can be send asynchronously. 1192 // Enters / exits can be send asynchronously.
1169 RunAllPendingInMessageLoop(); 1193 RunAllPendingInMessageLoop();
1170 EXPECT_TRUE(d1.entered()); 1194 EXPECT_TRUE(d1.entered());
1171 } 1195 }
1172 1196
1173 // Verifies that enter / exits are sent if windows appear and are hidden 1197 // Verifies that enter / exits are sent if windows appear and are hidden
1174 // under the current mouse position.. 1198 // under the current mouse position..
1175 TEST_F(WindowTest, MouseEnterExitWithHide) { 1199 TEST_F(WindowTest, MouseEnterExitWithHide) {
1176 MouseEnterExitWindowDelegate d1; 1200 MouseEnterExitWindowDelegate d1;
1177 scoped_ptr<Window> w1( 1201 scoped_ptr<Window> w1(
1178 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL)); 1202 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50),
1203 root_window()));
1179 1204
1180 test::EventGenerator generator(root_window()); 1205 test::EventGenerator generator(root_window());
1181 generator.MoveMouseToCenterOf(w1.get()); 1206 generator.MoveMouseToCenterOf(w1.get());
1182 EXPECT_TRUE(d1.entered()); 1207 EXPECT_TRUE(d1.entered());
1183 EXPECT_FALSE(d1.exited()); 1208 EXPECT_FALSE(d1.exited());
1184 1209
1185 MouseEnterExitWindowDelegate d2; 1210 MouseEnterExitWindowDelegate d2;
1186 scoped_ptr<Window> w2( 1211 scoped_ptr<Window> w2(
1187 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), NULL)); 1212 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50),
1213 root_window()));
1188 // Enters / exits can be send asynchronously. 1214 // Enters / exits can be send asynchronously.
1189 RunAllPendingInMessageLoop(); 1215 RunAllPendingInMessageLoop();
1190 EXPECT_TRUE(d1.entered()); 1216 EXPECT_TRUE(d1.entered());
1191 EXPECT_TRUE(d1.exited()); 1217 EXPECT_TRUE(d1.exited());
1192 EXPECT_TRUE(d2.entered()); 1218 EXPECT_TRUE(d2.entered());
1193 EXPECT_FALSE(d2.exited()); 1219 EXPECT_FALSE(d2.exited());
1194 1220
1195 d1.ResetExpectations(); 1221 d1.ResetExpectations();
1196 w2->Hide(); 1222 w2->Hide();
1197 // Enters / exits can be send asynchronously. 1223 // Enters / exits can be send asynchronously.
1198 RunAllPendingInMessageLoop(); 1224 RunAllPendingInMessageLoop();
1199 EXPECT_TRUE(d1.entered()); 1225 EXPECT_TRUE(d1.entered());
1200 } 1226 }
1201 #endif 1227 #endif
1202 1228
1203 // Creates a window with a delegate (w111) that can handle events at a lower 1229 // Creates a window with a delegate (w111) that can handle events at a lower
1204 // z-index than a window without a delegate (w12). w12 is sized to fill the 1230 // z-index than a window without a delegate (w12). w12 is sized to fill the
1205 // entire bounds of the container. This test verifies that 1231 // entire bounds of the container. This test verifies that
1206 // GetEventHandlerForPoint() skips w12 even though its bounds contain the event, 1232 // GetEventHandlerForPoint() skips w12 even though its bounds contain the event,
1207 // because it has no children that can handle the event and it has no delegate 1233 // because it has no children that can handle the event and it has no delegate
1208 // allowing it to handle the event itself. 1234 // allowing it to handle the event itself.
1209 TEST_F(WindowTest, GetEventHandlerForPoint_NoDelegate) { 1235 TEST_F(WindowTest, GetEventHandlerForPoint_NoDelegate) {
1210 TestWindowDelegate d111; 1236 TestWindowDelegate d111;
1211 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1, 1237 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1,
1212 gfx::Rect(0, 0, 500, 500), NULL)); 1238 gfx::Rect(0, 0, 500, 500), root_window()));
1213 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(NULL, 11, 1239 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(NULL, 11,
1214 gfx::Rect(0, 0, 500, 500), w1.get())); 1240 gfx::Rect(0, 0, 500, 500), w1.get()));
1215 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111, 1241 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111,
1216 gfx::Rect(50, 50, 450, 450), w11.get())); 1242 gfx::Rect(50, 50, 450, 450), w11.get()));
1217 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(NULL, 12, 1243 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(NULL, 12,
1218 gfx::Rect(0, 0, 500, 500), w1.get())); 1244 gfx::Rect(0, 0, 500, 500), w1.get()));
1219 1245
1220 gfx::Point target_point = w111->bounds().CenterPoint(); 1246 gfx::Point target_point = w111->bounds().CenterPoint();
1221 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(target_point)); 1247 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(target_point));
1222 } 1248 }
(...skipping 23 matching lines...) Expand all
1246 int shown_; 1272 int shown_;
1247 int hidden_; 1273 int hidden_;
1248 1274
1249 DISALLOW_COPY_AND_ASSIGN(VisibilityWindowDelegate); 1275 DISALLOW_COPY_AND_ASSIGN(VisibilityWindowDelegate);
1250 }; 1276 };
1251 1277
1252 // Verifies show/hide propagate correctly to children and the layer. 1278 // Verifies show/hide propagate correctly to children and the layer.
1253 TEST_F(WindowTest, Visibility) { 1279 TEST_F(WindowTest, Visibility) {
1254 VisibilityWindowDelegate d; 1280 VisibilityWindowDelegate d;
1255 VisibilityWindowDelegate d2; 1281 VisibilityWindowDelegate d2;
1256 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(&d, 1, gfx::Rect(), NULL)); 1282 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(&d, 1, gfx::Rect(),
1283 root_window()));
1257 scoped_ptr<Window> w2( 1284 scoped_ptr<Window> w2(
1258 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), w1.get())); 1285 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), w1.get()));
1259 scoped_ptr<Window> w3(CreateTestWindowWithId(3, w2.get())); 1286 scoped_ptr<Window> w3(CreateTestWindowWithId(3, w2.get()));
1260 1287
1261 // Create shows all the windows. 1288 // Create shows all the windows.
1262 EXPECT_TRUE(w1->IsVisible()); 1289 EXPECT_TRUE(w1->IsVisible());
1263 EXPECT_TRUE(w2->IsVisible()); 1290 EXPECT_TRUE(w2->IsVisible());
1264 EXPECT_TRUE(w3->IsVisible()); 1291 EXPECT_TRUE(w3->IsVisible());
1265 EXPECT_EQ(1, d.shown()); 1292 EXPECT_EQ(1, d.shown());
1266 1293
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 EXPECT_EQ(0, d2.hidden()); 1334 EXPECT_EQ(0, d2.hidden());
1308 EXPECT_EQ(1, d2.shown()); 1335 EXPECT_EQ(1, d2.shown());
1309 } 1336 }
1310 1337
1311 TEST_F(WindowTest, IgnoreEventsTest) { 1338 TEST_F(WindowTest, IgnoreEventsTest) {
1312 TestWindowDelegate d11; 1339 TestWindowDelegate d11;
1313 TestWindowDelegate d12; 1340 TestWindowDelegate d12;
1314 TestWindowDelegate d111; 1341 TestWindowDelegate d111;
1315 TestWindowDelegate d121; 1342 TestWindowDelegate d121;
1316 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1, 1343 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1,
1317 gfx::Rect(0, 0, 500, 500), NULL)); 1344 gfx::Rect(0, 0, 500, 500), root_window()));
1318 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(&d11, 11, 1345 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(&d11, 11,
1319 gfx::Rect(0, 0, 500, 500), w1.get())); 1346 gfx::Rect(0, 0, 500, 500), w1.get()));
1320 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111, 1347 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111,
1321 gfx::Rect(50, 50, 450, 450), w11.get())); 1348 gfx::Rect(50, 50, 450, 450), w11.get()));
1322 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(&d12, 12, 1349 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(&d12, 12,
1323 gfx::Rect(0, 0, 500, 500), w1.get())); 1350 gfx::Rect(0, 0, 500, 500), w1.get()));
1324 scoped_ptr<Window> w121(CreateTestWindowWithDelegate(&d121, 121, 1351 scoped_ptr<Window> w121(CreateTestWindowWithDelegate(&d121, 121,
1325 gfx::Rect(150, 150, 50, 50), w12.get())); 1352 gfx::Rect(150, 150, 50, 50), w12.get()));
1326 1353
1327 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10))); 1354 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10)));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 EXPECT_EQ(size.ToString(), 1391 EXPECT_EQ(size.ToString(),
1365 root_window()->GetHostSize().ToString()); 1392 root_window()->GetHostSize().ToString());
1366 } 1393 }
1367 1394
1368 TEST_F(WindowTest, TransformGesture) { 1395 TEST_F(WindowTest, TransformGesture) {
1369 gfx::Size size = root_window()->GetHostSize(); 1396 gfx::Size size = root_window()->GetHostSize();
1370 1397
1371 scoped_ptr<GestureTrackPositionDelegate> delegate( 1398 scoped_ptr<GestureTrackPositionDelegate> delegate(
1372 new GestureTrackPositionDelegate); 1399 new GestureTrackPositionDelegate);
1373 scoped_ptr<Window> window(CreateTestWindowWithDelegate(delegate.get(), -1234, 1400 scoped_ptr<Window> window(CreateTestWindowWithDelegate(delegate.get(), -1234,
1374 gfx::Rect(0, 0, 20, 20), NULL)); 1401 gfx::Rect(0, 0, 20, 20), root_window()));
1375 1402
1376 // Rotate the root-window clock-wise 90 degrees. 1403 // Rotate the root-window clock-wise 90 degrees.
1377 gfx::Transform transform; 1404 gfx::Transform transform;
1378 transform.SetRotate(90.0f); 1405 transform.SetRotate(90.0f);
1379 transform.ConcatTranslate(size.height(), 0); 1406 transform.ConcatTranslate(size.height(), 0);
1380 root_window()->SetTransform(transform); 1407 root_window()->SetTransform(transform);
1381 1408
1382 ui::TouchEvent press( 1409 ui::TouchEvent press(
1383 ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime()); 1410 ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime());
1384 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1411 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1385 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString()); 1412 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString());
1386 } 1413 }
1387 1414
1388 // Various assertions for transient children. 1415 // Various assertions for transient children.
1389 TEST_F(WindowTest, TransientChildren) { 1416 TEST_F(WindowTest, TransientChildren) {
1390 scoped_ptr<Window> parent(CreateTestWindowWithId(0, NULL)); 1417 scoped_ptr<Window> parent(CreateTestWindowWithId(0, root_window()));
1391 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); 1418 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get()));
1392 scoped_ptr<Window> w3(CreateTestWindowWithId(3, parent.get())); 1419 scoped_ptr<Window> w3(CreateTestWindowWithId(3, parent.get()));
1393 Window* w2 = CreateTestWindowWithId(2, parent.get()); 1420 Window* w2 = CreateTestWindowWithId(2, parent.get());
1394 w1->AddTransientChild(w2); // w2 is now owned by w1. 1421 w1->AddTransientChild(w2); // w2 is now owned by w1.
1395 // Stack w1 at the top (end), this should force w2 to be last (on top of w1). 1422 // Stack w1 at the top (end), this should force w2 to be last (on top of w1).
1396 parent->StackChildAtTop(w1.get()); 1423 parent->StackChildAtTop(w1.get());
1397 ASSERT_EQ(3u, parent->children().size()); 1424 ASSERT_EQ(3u, parent->children().size());
1398 EXPECT_EQ(w2, parent->children().back()); 1425 EXPECT_EQ(w2, parent->children().back());
1399 1426
1400 // Destroy w1, which should also destroy w3 (since it's a transient child). 1427 // Destroy w1, which should also destroy w3 (since it's a transient child).
(...skipping 14 matching lines...) Expand all
1415 EXPECT_EQ(w1.get(), parent->children()[1]); 1442 EXPECT_EQ(w1.get(), parent->children()[1]);
1416 1443
1417 // Hiding parent should hide transient children. 1444 // Hiding parent should hide transient children.
1418 EXPECT_TRUE(w2->IsVisible()); 1445 EXPECT_TRUE(w2->IsVisible());
1419 w1->Hide(); 1446 w1->Hide();
1420 EXPECT_FALSE(w2->IsVisible()); 1447 EXPECT_FALSE(w2->IsVisible());
1421 } 1448 }
1422 1449
1423 // Tests that when a focused window is closed, its parent inherits the focus. 1450 // Tests that when a focused window is closed, its parent inherits the focus.
1424 TEST_F(WindowTest, FocusedWindowTest) { 1451 TEST_F(WindowTest, FocusedWindowTest) {
1425 scoped_ptr<Window> parent(CreateTestWindowWithId(0, NULL)); 1452 scoped_ptr<Window> parent(CreateTestWindowWithId(0, root_window()));
1426 scoped_ptr<Window> child(CreateTestWindowWithId(1, parent.get())); 1453 scoped_ptr<Window> child(CreateTestWindowWithId(1, parent.get()));
1427 1454
1428 parent->Show(); 1455 parent->Show();
1429 1456
1430 child->Focus(); 1457 child->Focus();
1431 EXPECT_TRUE(child->HasFocus()); 1458 EXPECT_TRUE(child->HasFocus());
1432 EXPECT_FALSE(parent->HasFocus()); 1459 EXPECT_FALSE(parent->HasFocus());
1433 1460
1434 child.reset(); 1461 child.reset();
1435 EXPECT_TRUE(parent->HasFocus()); 1462 EXPECT_TRUE(parent->HasFocus());
1436 } 1463 }
1437 1464
1438 // Tests that the previously-focused window is passed to 1465 // Tests that the previously-focused window is passed to
1439 // WindowDelegate::OnFocus(). 1466 // WindowDelegate::OnFocus().
1440 TEST_F(WindowTest, OldFocusedWindowTest) { 1467 TEST_F(WindowTest, OldFocusedWindowTest) {
1441 const gfx::Rect kBounds(0, 0, 100, 100); 1468 const gfx::Rect kBounds(0, 0, 100, 100);
1442 1469
1443 FocusDelegate delegate1; 1470 FocusDelegate delegate1;
1444 scoped_ptr<Window> window1( 1471 scoped_ptr<Window> window1(
1445 CreateTestWindowWithDelegate(&delegate1, 0, kBounds, NULL)); 1472 CreateTestWindowWithDelegate(&delegate1, 0, kBounds, root_window()));
1446 window1->Focus(); 1473 window1->Focus();
1447 ASSERT_TRUE(window1->HasFocus()); 1474 ASSERT_TRUE(window1->HasFocus());
1448 EXPECT_TRUE(delegate1.previous_focused_window() == NULL); 1475 EXPECT_TRUE(delegate1.previous_focused_window() == NULL);
1449 1476
1450 FocusDelegate delegate2; 1477 FocusDelegate delegate2;
1451 scoped_ptr<Window> window2( 1478 scoped_ptr<Window> window2(
1452 CreateTestWindowWithDelegate(&delegate2, 1, kBounds, NULL)); 1479 CreateTestWindowWithDelegate(&delegate2, 1, kBounds, root_window()));
1453 window2->Focus(); 1480 window2->Focus();
1454 ASSERT_TRUE(window2->HasFocus()); 1481 ASSERT_TRUE(window2->HasFocus());
1455 EXPECT_FALSE(window1->HasFocus()); 1482 EXPECT_FALSE(window1->HasFocus());
1456 EXPECT_EQ(window1.get(), delegate2.previous_focused_window()); 1483 EXPECT_EQ(window1.get(), delegate2.previous_focused_window());
1457 } 1484 }
1458 1485
1459 namespace { 1486 namespace {
1460 DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2); 1487 DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2);
1461 DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish"); 1488 DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish");
1462 } 1489 }
1463 1490
1464 TEST_F(WindowTest, Property) { 1491 TEST_F(WindowTest, Property) {
1465 scoped_ptr<Window> w(CreateTestWindowWithId(0, NULL)); 1492 scoped_ptr<Window> w(CreateTestWindowWithId(0, root_window()));
1466 1493
1467 static const char native_prop_key[] = "fnord"; 1494 static const char native_prop_key[] = "fnord";
1468 1495
1469 // Non-existent properties should return the default values. 1496 // Non-existent properties should return the default values.
1470 EXPECT_EQ(-2, w->GetProperty(kIntKey)); 1497 EXPECT_EQ(-2, w->GetProperty(kIntKey));
1471 EXPECT_EQ(std::string("squeamish"), w->GetProperty(kStringKey)); 1498 EXPECT_EQ(std::string("squeamish"), w->GetProperty(kStringKey));
1472 EXPECT_EQ(NULL, w->GetNativeWindowProperty(native_prop_key)); 1499 EXPECT_EQ(NULL, w->GetNativeWindowProperty(native_prop_key));
1473 1500
1474 // A set property value should be returned again (even if it's the default 1501 // A set property value should be returned again (even if it's the default
1475 // value). 1502 // value).
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 DISALLOW_COPY_AND_ASSIGN(TestProperty); 1541 DISALLOW_COPY_AND_ASSIGN(TestProperty);
1515 }; 1542 };
1516 1543
1517 TestProperty* TestProperty::last_deleted_ = NULL; 1544 TestProperty* TestProperty::last_deleted_ = NULL;
1518 1545
1519 DEFINE_OWNED_WINDOW_PROPERTY_KEY(TestProperty, kOwnedKey, NULL); 1546 DEFINE_OWNED_WINDOW_PROPERTY_KEY(TestProperty, kOwnedKey, NULL);
1520 1547
1521 } // namespace 1548 } // namespace
1522 1549
1523 TEST_F(WindowTest, OwnedProperty) { 1550 TEST_F(WindowTest, OwnedProperty) {
1524 scoped_ptr<Window> w(CreateTestWindowWithId(0, NULL)); 1551 scoped_ptr<Window> w(CreateTestWindowWithId(0, root_window()));
1525 EXPECT_EQ(NULL, w->GetProperty(kOwnedKey)); 1552 EXPECT_EQ(NULL, w->GetProperty(kOwnedKey));
1526 TestProperty* p1 = new TestProperty(); 1553 TestProperty* p1 = new TestProperty();
1527 w->SetProperty(kOwnedKey, p1); 1554 w->SetProperty(kOwnedKey, p1);
1528 EXPECT_EQ(p1, w->GetProperty(kOwnedKey)); 1555 EXPECT_EQ(p1, w->GetProperty(kOwnedKey));
1529 EXPECT_EQ(NULL, TestProperty::last_deleted()); 1556 EXPECT_EQ(NULL, TestProperty::last_deleted());
1530 1557
1531 TestProperty* p2 = new TestProperty(); 1558 TestProperty* p2 = new TestProperty();
1532 w->SetProperty(kOwnedKey, p2); 1559 w->SetProperty(kOwnedKey, p2);
1533 EXPECT_EQ(p2, w->GetProperty(kOwnedKey)); 1560 EXPECT_EQ(p2, w->GetProperty(kOwnedKey));
1534 EXPECT_EQ(p1, TestProperty::last_deleted()); 1561 EXPECT_EQ(p1, TestProperty::last_deleted());
1535 1562
1536 w->ClearProperty(kOwnedKey); 1563 w->ClearProperty(kOwnedKey);
1537 EXPECT_EQ(NULL, w->GetProperty(kOwnedKey)); 1564 EXPECT_EQ(NULL, w->GetProperty(kOwnedKey));
1538 EXPECT_EQ(p2, TestProperty::last_deleted()); 1565 EXPECT_EQ(p2, TestProperty::last_deleted());
1539 1566
1540 TestProperty* p3 = new TestProperty(); 1567 TestProperty* p3 = new TestProperty();
1541 w->SetProperty(kOwnedKey, p3); 1568 w->SetProperty(kOwnedKey, p3);
1542 EXPECT_EQ(p3, w->GetProperty(kOwnedKey)); 1569 EXPECT_EQ(p3, w->GetProperty(kOwnedKey));
1543 EXPECT_EQ(p2, TestProperty::last_deleted()); 1570 EXPECT_EQ(p2, TestProperty::last_deleted());
1544 w.reset(); 1571 w.reset();
1545 EXPECT_EQ(p3, TestProperty::last_deleted()); 1572 EXPECT_EQ(p3, TestProperty::last_deleted());
1546 } 1573 }
1547 1574
1548 TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) { 1575 TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) {
1549 // We cannot short-circuit animations in this test. 1576 // We cannot short-circuit animations in this test.
1550 ui::LayerAnimator::set_disable_animations_for_test(false); 1577 ui::LayerAnimator::set_disable_animations_for_test(false);
1551 1578
1552 scoped_ptr<Window> w1( 1579 scoped_ptr<Window> w1(
1553 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), NULL)); 1580 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), root_window()));
1554 1581
1555 EXPECT_FALSE(!w1->layer()); 1582 EXPECT_FALSE(!w1->layer());
1556 w1->layer()->GetAnimator()->set_disable_timer_for_test(true); 1583 w1->layer()->GetAnimator()->set_disable_timer_for_test(true);
1557 ui::AnimationContainerElement* element = w1->layer()->GetAnimator(); 1584 ui::AnimationContainerElement* element = w1->layer()->GetAnimator();
1558 1585
1559 EXPECT_EQ("0,0 100x100", w1->bounds().ToString()); 1586 EXPECT_EQ("0,0 100x100", w1->bounds().ToString());
1560 EXPECT_EQ("0,0 100x100", w1->layer()->GetTargetBounds().ToString()); 1587 EXPECT_EQ("0,0 100x100", w1->layer()->GetTargetBounds().ToString());
1561 1588
1562 // Animate to a different position. 1589 // Animate to a different position.
1563 { 1590 {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 int destroyed_count_; 1700 int destroyed_count_;
1674 scoped_ptr<VisibilityInfo> visibility_info_; 1701 scoped_ptr<VisibilityInfo> visibility_info_;
1675 const void* property_key_; 1702 const void* property_key_;
1676 intptr_t old_property_value_; 1703 intptr_t old_property_value_;
1677 1704
1678 DISALLOW_COPY_AND_ASSIGN(WindowObserverTest); 1705 DISALLOW_COPY_AND_ASSIGN(WindowObserverTest);
1679 }; 1706 };
1680 1707
1681 // Various assertions for WindowObserver. 1708 // Various assertions for WindowObserver.
1682 TEST_F(WindowObserverTest, WindowObserver) { 1709 TEST_F(WindowObserverTest, WindowObserver) {
1683 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); 1710 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
1684 w1->AddObserver(this); 1711 w1->AddObserver(this);
1685 1712
1686 // Create a new window as a child of w1, our observer should be notified. 1713 // Create a new window as a child of w1, our observer should be notified.
1687 scoped_ptr<Window> w2(CreateTestWindowWithId(2, w1.get())); 1714 scoped_ptr<Window> w2(CreateTestWindowWithId(2, w1.get()));
1688 EXPECT_EQ("added=1 removed=0", WindowObserverCountStateAndClear()); 1715 EXPECT_EQ("added=1 removed=0", WindowObserverCountStateAndClear());
1689 1716
1690 // Delete w2, which should result in the remove notification. 1717 // Delete w2, which should result in the remove notification.
1691 w2.reset(); 1718 w2.reset();
1692 EXPECT_EQ("added=0 removed=1", WindowObserverCountStateAndClear()); 1719 EXPECT_EQ("added=0 removed=1", WindowObserverCountStateAndClear());
1693 1720
1694 // Create a window that isn't parented to w1, we shouldn't get any 1721 // Create a window that isn't parented to w1, we shouldn't get any
1695 // notification. 1722 // notification.
1696 scoped_ptr<Window> w3(CreateTestWindowWithId(3, NULL)); 1723 scoped_ptr<Window> w3(CreateTestWindowWithId(3, root_window()));
1697 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear()); 1724 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear());
1698 1725
1699 // Similarly destroying w3 shouldn't notify us either. 1726 // Similarly destroying w3 shouldn't notify us either.
1700 w3.reset(); 1727 w3.reset();
1701 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear()); 1728 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear());
1702 w1->RemoveObserver(this); 1729 w1->RemoveObserver(this);
1703 } 1730 }
1704 1731
1705 // Test if OnWindowVisibilityChagned is invoked with expected 1732 // Test if OnWindowVisibilityChagned is invoked with expected
1706 // parameters. 1733 // parameters.
1707 TEST_F(WindowObserverTest, WindowVisibility) { 1734 TEST_F(WindowObserverTest, WindowVisibility) {
1708 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); 1735 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
1709 scoped_ptr<Window> w2(CreateTestWindowWithId(1, w1.get())); 1736 scoped_ptr<Window> w2(CreateTestWindowWithId(1, w1.get()));
1710 w2->AddObserver(this); 1737 w2->AddObserver(this);
1711 1738
1712 // Hide should make the window invisible and the passed visible 1739 // Hide should make the window invisible and the passed visible
1713 // parameter is false. 1740 // parameter is false.
1714 w2->Hide(); 1741 w2->Hide();
1715 EXPECT_FALSE(!GetVisibilityInfo()); 1742 EXPECT_FALSE(!GetVisibilityInfo());
1716 EXPECT_FALSE(!GetVisibilityInfo()); 1743 EXPECT_FALSE(!GetVisibilityInfo());
1717 if (!GetVisibilityInfo()) 1744 if (!GetVisibilityInfo())
1718 return; 1745 return;
(...skipping 21 matching lines...) Expand all
1740 EXPECT_FALSE(!GetVisibilityInfo()); 1767 EXPECT_FALSE(!GetVisibilityInfo());
1741 if (!GetVisibilityInfo()) 1768 if (!GetVisibilityInfo())
1742 return; 1769 return;
1743 EXPECT_TRUE(GetVisibilityInfo()->window_visible); 1770 EXPECT_TRUE(GetVisibilityInfo()->window_visible);
1744 EXPECT_TRUE(GetVisibilityInfo()->visible_param); 1771 EXPECT_TRUE(GetVisibilityInfo()->visible_param);
1745 } 1772 }
1746 1773
1747 // Test if OnWindowDestroyed is invoked as expected. 1774 // Test if OnWindowDestroyed is invoked as expected.
1748 TEST_F(WindowObserverTest, WindowDestroyed) { 1775 TEST_F(WindowObserverTest, WindowDestroyed) {
1749 // Delete a window should fire a destroyed notification. 1776 // Delete a window should fire a destroyed notification.
1750 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); 1777 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
1751 w1->AddObserver(this); 1778 w1->AddObserver(this);
1752 w1.reset(); 1779 w1.reset();
1753 EXPECT_EQ(1, DestroyedCountAndClear()); 1780 EXPECT_EQ(1, DestroyedCountAndClear());
1754 1781
1755 // Observe on child and delete parent window should fire a notification. 1782 // Observe on child and delete parent window should fire a notification.
1756 scoped_ptr<Window> parent(CreateTestWindowWithId(1, NULL)); 1783 scoped_ptr<Window> parent(CreateTestWindowWithId(1, root_window()));
1757 Window* child = CreateTestWindowWithId(1, parent.get()); // owned by parent 1784 Window* child = CreateTestWindowWithId(1, parent.get()); // owned by parent
1758 child->AddObserver(this); 1785 child->AddObserver(this);
1759 parent.reset(); 1786 parent.reset();
1760 EXPECT_EQ(1, DestroyedCountAndClear()); 1787 EXPECT_EQ(1, DestroyedCountAndClear());
1761 } 1788 }
1762 1789
1763 TEST_F(WindowObserverTest, PropertyChanged) { 1790 TEST_F(WindowObserverTest, PropertyChanged) {
1764 // Setting property should fire a property change notification. 1791 // Setting property should fire a property change notification.
1765 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); 1792 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
1766 w1->AddObserver(this); 1793 w1->AddObserver(this);
1767 1794
1768 static const WindowProperty<int> prop = {-2}; 1795 static const WindowProperty<int> prop = {-2};
1769 static const char native_prop_key[] = "fnord"; 1796 static const char native_prop_key[] = "fnord";
1770 1797
1771 w1->SetProperty(&prop, 1); 1798 w1->SetProperty(&prop, 1);
1772 EXPECT_EQ(PropertyChangeInfo(&prop, -2), PropertyChangeInfoAndClear()); 1799 EXPECT_EQ(PropertyChangeInfo(&prop, -2), PropertyChangeInfoAndClear());
1773 w1->SetProperty(&prop, -2); 1800 w1->SetProperty(&prop, -2);
1774 EXPECT_EQ(PropertyChangeInfo(&prop, 1), PropertyChangeInfoAndClear()); 1801 EXPECT_EQ(PropertyChangeInfo(&prop, 1), PropertyChangeInfoAndClear());
1775 w1->SetProperty(&prop, 3); 1802 w1->SetProperty(&prop, 3);
1776 EXPECT_EQ(PropertyChangeInfo(&prop, -2), PropertyChangeInfoAndClear()); 1803 EXPECT_EQ(PropertyChangeInfo(&prop, -2), PropertyChangeInfoAndClear());
1777 w1->ClearProperty(&prop); 1804 w1->ClearProperty(&prop);
1778 EXPECT_EQ(PropertyChangeInfo(&prop, 3), PropertyChangeInfoAndClear()); 1805 EXPECT_EQ(PropertyChangeInfo(&prop, 3), PropertyChangeInfoAndClear());
1779 1806
1780 w1->SetNativeWindowProperty(native_prop_key, &*w1); 1807 w1->SetNativeWindowProperty(native_prop_key, &*w1);
1781 EXPECT_EQ(PropertyChangeInfo(native_prop_key, 0), 1808 EXPECT_EQ(PropertyChangeInfo(native_prop_key, 0),
1782 PropertyChangeInfoAndClear()); 1809 PropertyChangeInfoAndClear());
1783 w1->SetNativeWindowProperty(native_prop_key, NULL); 1810 w1->SetNativeWindowProperty(native_prop_key, NULL);
1784 EXPECT_EQ(PropertyChangeInfo(native_prop_key, 1811 EXPECT_EQ(PropertyChangeInfo(native_prop_key,
1785 reinterpret_cast<intptr_t>(&*w1)), 1812 reinterpret_cast<intptr_t>(&*w1)),
1786 PropertyChangeInfoAndClear()); 1813 PropertyChangeInfoAndClear());
1787 1814
1788 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. 1815 // Sanity check to see if |PropertyChangeInfoAndClear| really clears.
1789 EXPECT_EQ(PropertyChangeInfo( 1816 EXPECT_EQ(PropertyChangeInfo(
1790 reinterpret_cast<const void*>(NULL), -3), PropertyChangeInfoAndClear()); 1817 reinterpret_cast<const void*>(NULL), -3), PropertyChangeInfoAndClear());
1791 } 1818 }
1792 1819
1793 TEST_F(WindowTest, AcquireLayer) { 1820 TEST_F(WindowTest, AcquireLayer) {
1794 scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL)); 1821 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
1795 scoped_ptr<Window> window2(CreateTestWindowWithId(2, NULL)); 1822 scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window()));
1796 ui::Layer* parent = window1->parent()->layer(); 1823 ui::Layer* parent = window1->parent()->layer();
1797 EXPECT_EQ(2U, parent->children().size()); 1824 EXPECT_EQ(2U, parent->children().size());
1798 1825
1799 Window::TestApi window1_test_api(window1.get()); 1826 Window::TestApi window1_test_api(window1.get());
1800 Window::TestApi window2_test_api(window2.get()); 1827 Window::TestApi window2_test_api(window2.get());
1801 1828
1802 EXPECT_TRUE(window1_test_api.OwnsLayer()); 1829 EXPECT_TRUE(window1_test_api.OwnsLayer());
1803 EXPECT_TRUE(window2_test_api.OwnsLayer()); 1830 EXPECT_TRUE(window2_test_api.OwnsLayer());
1804 1831
1805 // After acquisition, window1 should not own its layer, but it should still 1832 // After acquisition, window1 should not own its layer, but it should still
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1839 EXPECT_EQ(ui::LAYER_SOLID_COLOR, layer->type()); 1866 EXPECT_EQ(ui::LAYER_SOLID_COLOR, layer->type());
1840 EXPECT_FALSE(layer->scale_content()); 1867 EXPECT_FALSE(layer->scale_content());
1841 EXPECT_FALSE(layer->visible()); 1868 EXPECT_FALSE(layer->visible());
1842 EXPECT_EQ(1u, layer->children().size()); 1869 EXPECT_EQ(1u, layer->children().size());
1843 } 1870 }
1844 1871
1845 // Ensure that acquiring a layer then recreating a layer does not crash 1872 // Ensure that acquiring a layer then recreating a layer does not crash
1846 // and that RecreateLayer returns null. 1873 // and that RecreateLayer returns null.
1847 TEST_F(WindowTest, AcquireThenRecreateLayer) { 1874 TEST_F(WindowTest, AcquireThenRecreateLayer) {
1848 scoped_ptr<Window> w( 1875 scoped_ptr<Window> w(
1849 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(0, 0, 100, 100), NULL)); 1876 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(0, 0, 100, 100),
1877 root_window()));
1850 scoped_ptr<ui::Layer>acquired_layer(w->AcquireLayer()); 1878 scoped_ptr<ui::Layer>acquired_layer(w->AcquireLayer());
1851 scoped_ptr<ui::Layer>doubly_acquired_layer(w->RecreateLayer()); 1879 scoped_ptr<ui::Layer>doubly_acquired_layer(w->RecreateLayer());
1852 EXPECT_EQ(NULL, doubly_acquired_layer.get()); 1880 EXPECT_EQ(NULL, doubly_acquired_layer.get());
1853 1881
1854 // Destroy window before layer gets destroyed. 1882 // Destroy window before layer gets destroyed.
1855 w.reset(); 1883 w.reset();
1856 } 1884 }
1857 1885
1858 TEST_F(WindowTest, StackWindowsWhoseLayersHaveNoDelegate) { 1886 TEST_F(WindowTest, StackWindowsWhoseLayersHaveNoDelegate) {
1859 scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL)); 1887 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
1860 scoped_ptr<Window> window2(CreateTestWindowWithId(2, NULL)); 1888 scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window()));
1861 1889
1862 // This brings window1 (and its layer) to the front. 1890 // This brings window1 (and its layer) to the front.
1863 root_window()->StackChildAbove(window1.get(), window2.get()); 1891 root_window()->StackChildAbove(window1.get(), window2.get());
1864 EXPECT_EQ(root_window()->children().front(), window2.get()); 1892 EXPECT_EQ(root_window()->children().front(), window2.get());
1865 EXPECT_EQ(root_window()->children().back(), window1.get()); 1893 EXPECT_EQ(root_window()->children().back(), window1.get());
1866 EXPECT_EQ(root_window()->layer()->children().front(), window2->layer()); 1894 EXPECT_EQ(root_window()->layer()->children().front(), window2->layer());
1867 EXPECT_EQ(root_window()->layer()->children().back(), window1->layer()); 1895 EXPECT_EQ(root_window()->layer()->children().back(), window1->layer());
1868 1896
1869 // Since window1 does not have a delegate, window2 should not move in 1897 // Since window1 does not have a delegate, window2 should not move in
1870 // front of it, nor should its layer. 1898 // front of it, nor should its layer.
1871 window1->layer()->set_delegate(NULL); 1899 window1->layer()->set_delegate(NULL);
1872 root_window()->StackChildAbove(window2.get(), window1.get()); 1900 root_window()->StackChildAbove(window2.get(), window1.get());
1873 EXPECT_EQ(root_window()->children().front(), window2.get()); 1901 EXPECT_EQ(root_window()->children().front(), window2.get());
1874 EXPECT_EQ(root_window()->children().back(), window1.get()); 1902 EXPECT_EQ(root_window()->children().back(), window1.get());
1875 EXPECT_EQ(root_window()->layer()->children().front(), window2->layer()); 1903 EXPECT_EQ(root_window()->layer()->children().front(), window2->layer());
1876 EXPECT_EQ(root_window()->layer()->children().back(), window1->layer()); 1904 EXPECT_EQ(root_window()->layer()->children().back(), window1->layer());
1877 } 1905 }
1878 1906
1879 TEST_F(WindowTest, StackTransientsWhoseLayersHaveNoDelegate) { 1907 TEST_F(WindowTest, StackTransientsWhoseLayersHaveNoDelegate) {
1880 RootWindow* root = root_window(); 1908 RootWindow* root = root_window();
1881 1909
1882 // Create a window with several transients, then a couple windows on top. 1910 // Create a window with several transients, then a couple windows on top.
1883 scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL)); 1911 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
1884 scoped_ptr<Window> window11(CreateTransientChild(11, window1.get())); 1912 scoped_ptr<Window> window11(CreateTransientChild(11, window1.get()));
1885 scoped_ptr<Window> window12(CreateTransientChild(12, window1.get())); 1913 scoped_ptr<Window> window12(CreateTransientChild(12, window1.get()));
1886 scoped_ptr<Window> window13(CreateTransientChild(13, window1.get())); 1914 scoped_ptr<Window> window13(CreateTransientChild(13, window1.get()));
1887 scoped_ptr<Window> window2(CreateTestWindowWithId(2, NULL)); 1915 scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window()));
1888 scoped_ptr<Window> window3(CreateTestWindowWithId(3, NULL)); 1916 scoped_ptr<Window> window3(CreateTestWindowWithId(3, root_window()));
1889 1917
1890 EXPECT_EQ("1 11 12 13 2 3", ChildWindowIDsAsString(root)); 1918 EXPECT_EQ("1 11 12 13 2 3", ChildWindowIDsAsString(root));
1891 1919
1892 // Remove the delegates of a couple of transients, as if they are closing 1920 // Remove the delegates of a couple of transients, as if they are closing
1893 // and animating out. 1921 // and animating out.
1894 window11->layer()->set_delegate(NULL); 1922 window11->layer()->set_delegate(NULL);
1895 window13->layer()->set_delegate(NULL); 1923 window13->layer()->set_delegate(NULL);
1896 1924
1897 // Move window1 to the front. All transients should move with it, and their 1925 // Move window1 to the front. All transients should move with it, and their
1898 // order should be preserved. 1926 // order should be preserved.
(...skipping 23 matching lines...) Expand all
1922 } 1950 }
1923 1951
1924 private: 1952 private:
1925 bool ignore_visibility_changes_; 1953 bool ignore_visibility_changes_;
1926 DISALLOW_COPY_AND_ASSIGN(TestVisibilityClient); 1954 DISALLOW_COPY_AND_ASSIGN(TestVisibilityClient);
1927 }; 1955 };
1928 1956
1929 TEST_F(WindowTest, VisibilityClientIsVisible) { 1957 TEST_F(WindowTest, VisibilityClientIsVisible) {
1930 TestVisibilityClient client(root_window()); 1958 TestVisibilityClient client(root_window());
1931 1959
1932 scoped_ptr<Window> window(CreateTestWindowWithId(1, NULL)); 1960 scoped_ptr<Window> window(CreateTestWindowWithId(1, root_window()));
1933 EXPECT_TRUE(window->IsVisible()); 1961 EXPECT_TRUE(window->IsVisible());
1934 EXPECT_TRUE(window->layer()->visible()); 1962 EXPECT_TRUE(window->layer()->visible());
1935 1963
1936 window->Hide(); 1964 window->Hide();
1937 EXPECT_FALSE(window->IsVisible()); 1965 EXPECT_FALSE(window->IsVisible());
1938 EXPECT_FALSE(window->layer()->visible()); 1966 EXPECT_FALSE(window->layer()->visible());
1939 window->Show(); 1967 window->Show();
1940 1968
1941 client.set_ignore_visibility_changes(true); 1969 client.set_ignore_visibility_changes(true);
1942 window->Hide(); 1970 window->Hide();
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
2108 // should not be adjusted. 2136 // should not be adjusted.
2109 // One issue that can arise when a window opens two transient children, and the 2137 // One issue that can arise when a window opens two transient children, and the
2110 // first is hidden. Subsequent attempts to activate the transient parent can 2138 // first is hidden. Subsequent attempts to activate the transient parent can
2111 // result in the transient parent being stacked above the second transient 2139 // result in the transient parent being stacked above the second transient
2112 // child. A fix is made to Window::StackAbove to prevent this, and this test 2140 // child. A fix is made to Window::StackAbove to prevent this, and this test
2113 // verifies this fix. 2141 // verifies this fix.
2114 TEST_F(WindowTest, StackingMadrigal) { 2142 TEST_F(WindowTest, StackingMadrigal) {
2115 new StackingMadrigalLayoutManager(root_window()); 2143 new StackingMadrigalLayoutManager(root_window());
2116 StackingMadrigalVisibilityClient visibility_client(root_window()); 2144 StackingMadrigalVisibilityClient visibility_client(root_window());
2117 2145
2118 scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL)); 2146 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
2119 scoped_ptr<Window> window11(CreateTransientChild(11, window1.get())); 2147 scoped_ptr<Window> window11(CreateTransientChild(11, window1.get()));
2120 2148
2121 visibility_client.set_ignored_window(window11.get()); 2149 visibility_client.set_ignored_window(window11.get());
2122 2150
2123 window11->Show(); 2151 window11->Show();
2124 window11->Hide(); 2152 window11->Hide();
2125 2153
2126 // As a transient, window11 should still be stacked above window1, even when 2154 // As a transient, window11 should still be stacked above window1, even when
2127 // hidden. 2155 // hidden.
2128 EXPECT_TRUE(WindowIsAbove(window11.get(), window1.get())); 2156 EXPECT_TRUE(WindowIsAbove(window11.get(), window1.get()));
(...skipping 17 matching lines...) Expand all
2146 2174
2147 // Both window12 and its layer should be stacked above window1. 2175 // Both window12 and its layer should be stacked above window1.
2148 EXPECT_TRUE(WindowIsAbove(window12.get(), window1.get())); 2176 EXPECT_TRUE(WindowIsAbove(window12.get(), window1.get()));
2149 EXPECT_TRUE(LayerIsAbove(window12.get(), window1.get())); 2177 EXPECT_TRUE(LayerIsAbove(window12.get(), window1.get()));
2150 } 2178 }
2151 2179
2152 // Test for an issue where attempting to stack a primary window on top of a 2180 // Test for an issue where attempting to stack a primary window on top of a
2153 // transient with a NULL layer delegate causes that primary window to be moved, 2181 // transient with a NULL layer delegate causes that primary window to be moved,
2154 // but the layer order not changed to match. http://crbug.com/112562 2182 // but the layer order not changed to match. http://crbug.com/112562
2155 TEST_F(WindowTest, StackOverClosingTransient) { 2183 TEST_F(WindowTest, StackOverClosingTransient) {
2156 scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL)); 2184 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
2157 scoped_ptr<Window> transient1(CreateTransientChild(11, window1.get())); 2185 scoped_ptr<Window> transient1(CreateTransientChild(11, window1.get()));
2158 scoped_ptr<Window> window2(CreateTestWindowWithId(2, NULL)); 2186 scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window()));
2159 scoped_ptr<Window> transient2(CreateTransientChild(21, window2.get())); 2187 scoped_ptr<Window> transient2(CreateTransientChild(21, window2.get()));
2160 2188
2161 // Both windows and layers are stacked in creation order. 2189 // Both windows and layers are stacked in creation order.
2162 RootWindow* root = root_window(); 2190 RootWindow* root = root_window();
2163 ASSERT_EQ(4u, root->children().size()); 2191 ASSERT_EQ(4u, root->children().size());
2164 EXPECT_EQ(root->children()[0], window1.get()); 2192 EXPECT_EQ(root->children()[0], window1.get());
2165 EXPECT_EQ(root->children()[1], transient1.get()); 2193 EXPECT_EQ(root->children()[1], transient1.get());
2166 EXPECT_EQ(root->children()[2], window2.get()); 2194 EXPECT_EQ(root->children()[2], window2.get());
2167 EXPECT_EQ(root->children()[3], transient2.get()); 2195 EXPECT_EQ(root->children()[3], transient2.get());
2168 ASSERT_EQ(4u, root->layer()->children().size()); 2196 ASSERT_EQ(4u, root->layer()->children().size());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2205 ASSERT_EQ(3u, root->children().size()); 2233 ASSERT_EQ(3u, root->children().size());
2206 EXPECT_EQ(root->children()[0], window1.get()); 2234 EXPECT_EQ(root->children()[0], window1.get());
2207 EXPECT_EQ(root->children()[1], window2.get()); 2235 EXPECT_EQ(root->children()[1], window2.get());
2208 EXPECT_EQ(root->children()[2], transient2.get()); 2236 EXPECT_EQ(root->children()[2], transient2.get());
2209 ASSERT_EQ(3u, root->layer()->children().size()); 2237 ASSERT_EQ(3u, root->layer()->children().size());
2210 EXPECT_EQ(root->layer()->children()[0], window1->layer()); 2238 EXPECT_EQ(root->layer()->children()[0], window1->layer());
2211 EXPECT_EQ(root->layer()->children()[1], window2->layer()); 2239 EXPECT_EQ(root->layer()->children()[1], window2->layer());
2212 EXPECT_EQ(root->layer()->children()[2], transient2->layer()); 2240 EXPECT_EQ(root->layer()->children()[2], transient2->layer());
2213 2241
2214 // Open another window on top. 2242 // Open another window on top.
2215 scoped_ptr<Window> window3(CreateTestWindowWithId(3, NULL)); 2243 scoped_ptr<Window> window3(CreateTestWindowWithId(3, root_window()));
2216 2244
2217 ASSERT_EQ(4u, root->children().size()); 2245 ASSERT_EQ(4u, root->children().size());
2218 EXPECT_EQ(root->children()[0], window1.get()); 2246 EXPECT_EQ(root->children()[0], window1.get());
2219 EXPECT_EQ(root->children()[1], window2.get()); 2247 EXPECT_EQ(root->children()[1], window2.get());
2220 EXPECT_EQ(root->children()[2], transient2.get()); 2248 EXPECT_EQ(root->children()[2], transient2.get());
2221 EXPECT_EQ(root->children()[3], window3.get()); 2249 EXPECT_EQ(root->children()[3], window3.get());
2222 ASSERT_EQ(4u, root->layer()->children().size()); 2250 ASSERT_EQ(4u, root->layer()->children().size());
2223 EXPECT_EQ(root->layer()->children()[0], window1->layer()); 2251 EXPECT_EQ(root->layer()->children()[0], window1->layer());
2224 EXPECT_EQ(root->layer()->children()[1], window2->layer()); 2252 EXPECT_EQ(root->layer()->children()[1], window2->layer());
2225 EXPECT_EQ(root->layer()->children()[2], transient2->layer()); 2253 EXPECT_EQ(root->layer()->children()[2], transient2->layer());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2286 }; 2314 };
2287 2315
2288 TEST_F(WindowTest, RootWindowAttachment) { 2316 TEST_F(WindowTest, RootWindowAttachment) {
2289 RootWindowAttachmentObserver observer; 2317 RootWindowAttachmentObserver observer;
2290 2318
2291 // Test a direct add/remove from the RootWindow. 2319 // Test a direct add/remove from the RootWindow.
2292 scoped_ptr<Window> w1(new Window(NULL)); 2320 scoped_ptr<Window> w1(new Window(NULL));
2293 w1->Init(ui::LAYER_NOT_DRAWN); 2321 w1->Init(ui::LAYER_NOT_DRAWN);
2294 w1->AddObserver(&observer); 2322 w1->AddObserver(&observer);
2295 2323
2296 w1->SetParent(NULL); 2324 AddToRootWindow(w1.get());
2297 EXPECT_EQ(1, observer.added_count()); 2325 EXPECT_EQ(1, observer.added_count());
2298 EXPECT_EQ(0, observer.removed_count()); 2326 EXPECT_EQ(0, observer.removed_count());
2299 2327
2300 w1.reset(); 2328 w1.reset();
2301 EXPECT_EQ(1, observer.added_count()); 2329 EXPECT_EQ(1, observer.added_count());
2302 EXPECT_EQ(1, observer.removed_count()); 2330 EXPECT_EQ(1, observer.removed_count());
2303 2331
2304 observer.Clear(); 2332 observer.Clear();
2305 2333
2306 // Test an indirect add/remove from the RootWindow. 2334 // Test an indirect add/remove from the RootWindow.
2307 w1.reset(new Window(NULL)); 2335 w1.reset(new Window(NULL));
2308 w1->Init(ui::LAYER_NOT_DRAWN); 2336 w1->Init(ui::LAYER_NOT_DRAWN);
2309 Window* w11 = new Window(NULL); 2337 Window* w11 = new Window(NULL);
2310 w11->Init(ui::LAYER_NOT_DRAWN); 2338 w11->Init(ui::LAYER_NOT_DRAWN);
2311 w11->AddObserver(&observer); 2339 w11->AddObserver(&observer);
2312 w11->SetParent(w1.get()); 2340 w1->AddChild(w11);
2313 EXPECT_EQ(0, observer.added_count()); 2341 EXPECT_EQ(0, observer.added_count());
2314 EXPECT_EQ(0, observer.removed_count()); 2342 EXPECT_EQ(0, observer.removed_count());
2315 2343
2316 w1->SetParent(NULL); 2344 AddToRootWindow(w1.get());
2317 EXPECT_EQ(1, observer.added_count()); 2345 EXPECT_EQ(1, observer.added_count());
2318 EXPECT_EQ(0, observer.removed_count()); 2346 EXPECT_EQ(0, observer.removed_count());
2319 2347
2320 w1.reset(); // Deletes w11. 2348 w1.reset(); // Deletes w11.
2321 w11 = NULL; 2349 w11 = NULL;
2322 EXPECT_EQ(1, observer.added_count()); 2350 EXPECT_EQ(1, observer.added_count());
2323 EXPECT_EQ(1, observer.removed_count()); 2351 EXPECT_EQ(1, observer.removed_count());
2324 2352
2325 observer.Clear(); 2353 observer.Clear();
2326 2354
2327 // Test an indirect add/remove with nested observers. 2355 // Test an indirect add/remove with nested observers.
2328 w1.reset(new Window(NULL)); 2356 w1.reset(new Window(NULL));
2329 w1->Init(ui::LAYER_NOT_DRAWN); 2357 w1->Init(ui::LAYER_NOT_DRAWN);
2330 w11 = new Window(NULL); 2358 w11 = new Window(NULL);
2331 w11->Init(ui::LAYER_NOT_DRAWN); 2359 w11->Init(ui::LAYER_NOT_DRAWN);
2332 w11->AddObserver(&observer); 2360 w11->AddObserver(&observer);
2333 w11->SetParent(w1.get()); 2361 w1->AddChild(w11);
2334 Window* w111 = new Window(NULL); 2362 Window* w111 = new Window(NULL);
2335 w111->Init(ui::LAYER_NOT_DRAWN); 2363 w111->Init(ui::LAYER_NOT_DRAWN);
2336 w111->AddObserver(&observer); 2364 w111->AddObserver(&observer);
2337 w111->SetParent(w11); 2365 w11->AddChild(w111);
2338 2366
2339 EXPECT_EQ(0, observer.added_count()); 2367 EXPECT_EQ(0, observer.added_count());
2340 EXPECT_EQ(0, observer.removed_count()); 2368 EXPECT_EQ(0, observer.removed_count());
2341 2369
2342 w1->SetParent(NULL); 2370 AddToRootWindow(w1.get());
2343 EXPECT_EQ(2, observer.added_count()); 2371 EXPECT_EQ(2, observer.added_count());
2344 EXPECT_EQ(0, observer.removed_count()); 2372 EXPECT_EQ(0, observer.removed_count());
2345 2373
2346 w1.reset(); // Deletes w11 and w111. 2374 w1.reset(); // Deletes w11 and w111.
2347 w11 = NULL; 2375 w11 = NULL;
2348 w111 = NULL; 2376 w111 = NULL;
2349 EXPECT_EQ(2, observer.added_count()); 2377 EXPECT_EQ(2, observer.added_count());
2350 EXPECT_EQ(2, observer.removed_count()); 2378 EXPECT_EQ(2, observer.removed_count());
2351 } 2379 }
2352 2380
2353 TEST_F(WindowTest, OwnedByParentFalse) { 2381 TEST_F(WindowTest, OwnedByParentFalse) {
2354 // By default, a window is owned by its parent. If this is set to false, the 2382 // By default, a window is owned by its parent. If this is set to false, the
2355 // window will not be destroyed when its parent is. 2383 // window will not be destroyed when its parent is.
2356 2384
2357 scoped_ptr<Window> w1(new Window(NULL)); 2385 scoped_ptr<Window> w1(new Window(NULL));
2358 w1->Init(ui::LAYER_NOT_DRAWN); 2386 w1->Init(ui::LAYER_NOT_DRAWN);
2359 scoped_ptr<Window> w2(new Window(NULL)); 2387 scoped_ptr<Window> w2(new Window(NULL));
2360 w2->set_owned_by_parent(false); 2388 w2->set_owned_by_parent(false);
2361 w2->Init(ui::LAYER_NOT_DRAWN); 2389 w2->Init(ui::LAYER_NOT_DRAWN);
2362 w2->SetParent(w1.get()); 2390 w1->AddChild(w2.get());
2363 2391
2364 w1.reset(); 2392 w1.reset();
2365 2393
2366 // We should be able to deref w2 still, but its parent should now be NULL. 2394 // We should be able to deref w2 still, but its parent should now be NULL.
2367 EXPECT_EQ(NULL, w2->parent()); 2395 EXPECT_EQ(NULL, w2->parent());
2368 } 2396 }
2369 2397
2370 namespace { 2398 namespace {
2371 2399
2372 // Used By DeleteWindowFromOnWindowDestroyed. Destroys a Window from 2400 // Used By DeleteWindowFromOnWindowDestroyed. Destroys a Window from
(...skipping 22 matching lines...) Expand all
2395 // destroyed (WindowDelegate::OnWindowDestroyed) it deletes the second child. 2423 // destroyed (WindowDelegate::OnWindowDestroyed) it deletes the second child.
2396 // This synthesizes BrowserView and the status bubble. Both are children of the 2424 // This synthesizes BrowserView and the status bubble. Both are children of the
2397 // same parent and destroying BrowserView triggers it destroying the status 2425 // same parent and destroying BrowserView triggers it destroying the status
2398 // bubble. 2426 // bubble.
2399 TEST_F(WindowTest, DeleteWindowFromOnWindowDestroyed) { 2427 TEST_F(WindowTest, DeleteWindowFromOnWindowDestroyed) {
2400 scoped_ptr<Window> parent(new Window(NULL)); 2428 scoped_ptr<Window> parent(new Window(NULL));
2401 parent->Init(ui::LAYER_NOT_DRAWN); 2429 parent->Init(ui::LAYER_NOT_DRAWN);
2402 OwningWindowDelegate delegate; 2430 OwningWindowDelegate delegate;
2403 Window* c1 = new Window(&delegate); 2431 Window* c1 = new Window(&delegate);
2404 c1->Init(ui::LAYER_NOT_DRAWN); 2432 c1->Init(ui::LAYER_NOT_DRAWN);
2405 c1->SetParent(parent.get()); 2433 parent->AddChild(c1);
2406 Window* c2 = new Window(NULL); 2434 Window* c2 = new Window(NULL);
2407 c2->Init(ui::LAYER_NOT_DRAWN); 2435 c2->Init(ui::LAYER_NOT_DRAWN);
2408 c2->SetParent(parent.get()); 2436 parent->AddChild(c2);
2409 delegate.SetOwnedWindow(c2); 2437 delegate.SetOwnedWindow(c2);
2410 parent.reset(); 2438 parent.reset();
2411 } 2439 }
2412 2440
2413 namespace { 2441 namespace {
2414 2442
2415 // Used by DelegateNotifiedAsBoundsChange to verify OnBoundsChanged() is 2443 // Used by DelegateNotifiedAsBoundsChange to verify OnBoundsChanged() is
2416 // invoked. 2444 // invoked.
2417 class BoundsChangeDelegate : public TestWindowDelegate { 2445 class BoundsChangeDelegate : public TestWindowDelegate {
2418 public: 2446 public:
(...skipping 22 matching lines...) Expand all
2441 // Verifies the delegate is notified when the actual bounds of the layer 2469 // Verifies the delegate is notified when the actual bounds of the layer
2442 // change. 2470 // change.
2443 TEST_F(WindowTest, DelegateNotifiedAsBoundsChange) { 2471 TEST_F(WindowTest, DelegateNotifiedAsBoundsChange) {
2444 BoundsChangeDelegate delegate; 2472 BoundsChangeDelegate delegate;
2445 2473
2446 // We cannot short-circuit animations in this test. 2474 // We cannot short-circuit animations in this test.
2447 ui::LayerAnimator::set_disable_animations_for_test(false); 2475 ui::LayerAnimator::set_disable_animations_for_test(false);
2448 2476
2449 scoped_ptr<Window> window( 2477 scoped_ptr<Window> window(
2450 CreateTestWindowWithDelegate(&delegate, 1, 2478 CreateTestWindowWithDelegate(&delegate, 1,
2451 gfx::Rect(0, 0, 100, 100), NULL)); 2479 gfx::Rect(0, 0, 100, 100), root_window()));
2452 window->layer()->GetAnimator()->set_disable_timer_for_test(true); 2480 window->layer()->GetAnimator()->set_disable_timer_for_test(true);
2453 2481
2454 delegate.clear_bounds_changed(); 2482 delegate.clear_bounds_changed();
2455 2483
2456 // Animate to a different position. 2484 // Animate to a different position.
2457 { 2485 {
2458 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 2486 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
2459 window->SetBounds(gfx::Rect(100, 100, 100, 100)); 2487 window->SetBounds(gfx::Rect(100, 100, 100, 100));
2460 } 2488 }
2461 2489
(...skipping 13 matching lines...) Expand all
2475 // Verifies the delegate is notified when the actual bounds of the layer 2503 // Verifies the delegate is notified when the actual bounds of the layer
2476 // change even when the window is not the layer's delegate 2504 // change even when the window is not the layer's delegate
2477 TEST_F(WindowTest, DelegateNotifiedAsBoundsChangeInHiddenLayer) { 2505 TEST_F(WindowTest, DelegateNotifiedAsBoundsChangeInHiddenLayer) {
2478 BoundsChangeDelegate delegate; 2506 BoundsChangeDelegate delegate;
2479 2507
2480 // We cannot short-circuit animations in this test. 2508 // We cannot short-circuit animations in this test.
2481 ui::LayerAnimator::set_disable_animations_for_test(false); 2509 ui::LayerAnimator::set_disable_animations_for_test(false);
2482 2510
2483 scoped_ptr<Window> window( 2511 scoped_ptr<Window> window(
2484 CreateTestWindowWithDelegate(&delegate, 1, 2512 CreateTestWindowWithDelegate(&delegate, 1,
2485 gfx::Rect(0, 0, 100, 100), NULL)); 2513 gfx::Rect(0, 0, 100, 100), root_window()));
2486 window->layer()->GetAnimator()->set_disable_timer_for_test(true); 2514 window->layer()->GetAnimator()->set_disable_timer_for_test(true);
2487 2515
2488 delegate.clear_bounds_changed(); 2516 delegate.clear_bounds_changed();
2489 2517
2490 // Suppress paint on the window since it is hidden (should reset the layer's 2518 // Suppress paint on the window since it is hidden (should reset the layer's
2491 // delegate to NULL) 2519 // delegate to NULL)
2492 window->SuppressPaint(); 2520 window->SuppressPaint();
2493 EXPECT_EQ(NULL, window->layer()->delegate()); 2521 EXPECT_EQ(NULL, window->layer()->delegate());
2494 2522
2495 // Animate to a different position. 2523 // Animate to a different position.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2543 int removed_count_; 2571 int removed_count_;
2544 2572
2545 DISALLOW_COPY_AND_ASSIGN(AddChildNotificationsObserver); 2573 DISALLOW_COPY_AND_ASSIGN(AddChildNotificationsObserver);
2546 }; 2574 };
2547 2575
2548 } // namespace 2576 } // namespace
2549 2577
2550 // Assertions around when root window notifications are sent. 2578 // Assertions around when root window notifications are sent.
2551 TEST_F(WindowTest, AddChildNotifications) { 2579 TEST_F(WindowTest, AddChildNotifications) {
2552 AddChildNotificationsObserver observer; 2580 AddChildNotificationsObserver observer;
2553 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); 2581 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window()));
2554 scoped_ptr<Window> w2(CreateTestWindowWithId(1, NULL)); 2582 scoped_ptr<Window> w2(CreateTestWindowWithId(1, root_window()));
2555 w2->AddObserver(&observer); 2583 w2->AddObserver(&observer);
2556 w2->Focus(); 2584 w2->Focus();
2557 EXPECT_TRUE(w2->HasFocus()); 2585 EXPECT_TRUE(w2->HasFocus());
2558 2586
2559 // Move |w2| to be a child of |w1|. 2587 // Move |w2| to be a child of |w1|.
2560 w1->AddChild(w2.get()); 2588 w1->AddChild(w2.get());
2561 // Sine we moved in the same root, observer shouldn't be notified. 2589 // Sine we moved in the same root, observer shouldn't be notified.
2562 EXPECT_EQ("0 0", observer.CountStringAndReset()); 2590 EXPECT_EQ("0 0", observer.CountStringAndReset());
2563 // |w2| should still have focus after moving. 2591 // |w2| should still have focus after moving.
2564 EXPECT_TRUE(w2->HasFocus()); 2592 EXPECT_TRUE(w2->HasFocus());
2565 } 2593 }
2566 2594
2567 } // namespace test 2595 } // namespace test
2568 } // namespace aura 2596 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698