| OLD | NEW |
| 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 <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 273 |
| 274 void OffsetBounds(Window* window, int horizontal, int vertical) { | 274 void OffsetBounds(Window* window, int horizontal, int vertical) { |
| 275 gfx::Rect bounds = window->bounds(); | 275 gfx::Rect bounds = window->bounds(); |
| 276 bounds.Offset(horizontal, vertical); | 276 bounds.Offset(horizontal, vertical); |
| 277 window->SetBounds(bounds); | 277 window->SetBounds(bounds); |
| 278 } | 278 } |
| 279 | 279 |
| 280 } // namespace | 280 } // namespace |
| 281 | 281 |
| 282 TEST_F(WindowTest, GetChildById) { | 282 TEST_F(WindowTest, GetChildById) { |
| 283 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 283 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 284 scoped_ptr<Window> w11(CreateTestWindowWithId(11, w1.get())); | 284 std::unique_ptr<Window> w11(CreateTestWindowWithId(11, w1.get())); |
| 285 scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); | 285 std::unique_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); |
| 286 scoped_ptr<Window> w12(CreateTestWindowWithId(12, w1.get())); | 286 std::unique_ptr<Window> w12(CreateTestWindowWithId(12, w1.get())); |
| 287 | 287 |
| 288 EXPECT_EQ(NULL, w1->GetChildById(57)); | 288 EXPECT_EQ(NULL, w1->GetChildById(57)); |
| 289 EXPECT_EQ(w12.get(), w1->GetChildById(12)); | 289 EXPECT_EQ(w12.get(), w1->GetChildById(12)); |
| 290 EXPECT_EQ(w111.get(), w1->GetChildById(111)); | 290 EXPECT_EQ(w111.get(), w1->GetChildById(111)); |
| 291 } | 291 } |
| 292 | 292 |
| 293 // Make sure that Window::Contains correctly handles children, grandchildren, | 293 // Make sure that Window::Contains correctly handles children, grandchildren, |
| 294 // and not containing NULL or parents. | 294 // and not containing NULL or parents. |
| 295 TEST_F(WindowTest, Contains) { | 295 TEST_F(WindowTest, Contains) { |
| 296 Window parent(NULL); | 296 Window parent(NULL); |
| 297 parent.Init(ui::LAYER_NOT_DRAWN); | 297 parent.Init(ui::LAYER_NOT_DRAWN); |
| 298 Window child1(NULL); | 298 Window child1(NULL); |
| 299 child1.Init(ui::LAYER_NOT_DRAWN); | 299 child1.Init(ui::LAYER_NOT_DRAWN); |
| 300 Window child2(NULL); | 300 Window child2(NULL); |
| 301 child2.Init(ui::LAYER_NOT_DRAWN); | 301 child2.Init(ui::LAYER_NOT_DRAWN); |
| 302 | 302 |
| 303 parent.AddChild(&child1); | 303 parent.AddChild(&child1); |
| 304 child1.AddChild(&child2); | 304 child1.AddChild(&child2); |
| 305 | 305 |
| 306 EXPECT_TRUE(parent.Contains(&parent)); | 306 EXPECT_TRUE(parent.Contains(&parent)); |
| 307 EXPECT_TRUE(parent.Contains(&child1)); | 307 EXPECT_TRUE(parent.Contains(&child1)); |
| 308 EXPECT_TRUE(parent.Contains(&child2)); | 308 EXPECT_TRUE(parent.Contains(&child2)); |
| 309 | 309 |
| 310 EXPECT_FALSE(parent.Contains(NULL)); | 310 EXPECT_FALSE(parent.Contains(NULL)); |
| 311 EXPECT_FALSE(child1.Contains(&parent)); | 311 EXPECT_FALSE(child1.Contains(&parent)); |
| 312 EXPECT_FALSE(child2.Contains(&child1)); | 312 EXPECT_FALSE(child2.Contains(&child1)); |
| 313 } | 313 } |
| 314 | 314 |
| 315 TEST_F(WindowTest, ContainsPointInRoot) { | 315 TEST_F(WindowTest, ContainsPointInRoot) { |
| 316 scoped_ptr<Window> w( | 316 std::unique_ptr<Window> w(CreateTestWindow( |
| 317 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), | 317 SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), root_window())); |
| 318 root_window())); | |
| 319 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(9, 9))); | 318 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(9, 9))); |
| 320 EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(10, 10))); | 319 EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(10, 10))); |
| 321 EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(14, 14))); | 320 EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(14, 14))); |
| 322 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(15, 15))); | 321 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(15, 15))); |
| 323 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(20, 20))); | 322 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(20, 20))); |
| 324 } | 323 } |
| 325 | 324 |
| 326 TEST_F(WindowTest, ContainsPoint) { | 325 TEST_F(WindowTest, ContainsPoint) { |
| 327 scoped_ptr<Window> w( | 326 std::unique_ptr<Window> w(CreateTestWindow( |
| 328 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), | 327 SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), root_window())); |
| 329 root_window())); | |
| 330 EXPECT_TRUE(w->ContainsPoint(gfx::Point(0, 0))); | 328 EXPECT_TRUE(w->ContainsPoint(gfx::Point(0, 0))); |
| 331 EXPECT_TRUE(w->ContainsPoint(gfx::Point(4, 4))); | 329 EXPECT_TRUE(w->ContainsPoint(gfx::Point(4, 4))); |
| 332 EXPECT_FALSE(w->ContainsPoint(gfx::Point(5, 5))); | 330 EXPECT_FALSE(w->ContainsPoint(gfx::Point(5, 5))); |
| 333 EXPECT_FALSE(w->ContainsPoint(gfx::Point(10, 10))); | 331 EXPECT_FALSE(w->ContainsPoint(gfx::Point(10, 10))); |
| 334 } | 332 } |
| 335 | 333 |
| 336 TEST_F(WindowTest, ConvertPointToWindow) { | 334 TEST_F(WindowTest, ConvertPointToWindow) { |
| 337 // Window::ConvertPointToWindow is mostly identical to | 335 // Window::ConvertPointToWindow is mostly identical to |
| 338 // Layer::ConvertPointToLayer, except NULL values for |source| are permitted, | 336 // Layer::ConvertPointToLayer, except NULL values for |source| are permitted, |
| 339 // in which case the function just returns. | 337 // in which case the function just returns. |
| 340 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 338 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 341 gfx::Point reference_point(100, 100); | 339 gfx::Point reference_point(100, 100); |
| 342 gfx::Point test_point = reference_point; | 340 gfx::Point test_point = reference_point; |
| 343 Window::ConvertPointToTarget(NULL, w1.get(), &test_point); | 341 Window::ConvertPointToTarget(NULL, w1.get(), &test_point); |
| 344 EXPECT_EQ(reference_point, test_point); | 342 EXPECT_EQ(reference_point, test_point); |
| 345 } | 343 } |
| 346 | 344 |
| 347 TEST_F(WindowTest, MoveCursorTo) { | 345 TEST_F(WindowTest, MoveCursorTo) { |
| 348 scoped_ptr<Window> w1( | 346 std::unique_ptr<Window> w1(CreateTestWindow( |
| 349 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), | 347 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); |
| 350 root_window())); | 348 std::unique_ptr<Window> w11( |
| 351 scoped_ptr<Window> w11( | |
| 352 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); | 349 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); |
| 353 scoped_ptr<Window> w111( | 350 std::unique_ptr<Window> w111( |
| 354 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); | 351 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); |
| 355 scoped_ptr<Window> w1111( | 352 std::unique_ptr<Window> w1111( |
| 356 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); | 353 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
| 357 | 354 |
| 358 Window* root = root_window(); | 355 Window* root = root_window(); |
| 359 root->MoveCursorTo(gfx::Point(10, 10)); | 356 root->MoveCursorTo(gfx::Point(10, 10)); |
| 360 EXPECT_EQ("10,10", | 357 EXPECT_EQ("10,10", |
| 361 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 358 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 362 w1->MoveCursorTo(gfx::Point(10, 10)); | 359 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 363 EXPECT_EQ("20,20", | 360 EXPECT_EQ("20,20", |
| 364 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 361 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 365 w11->MoveCursorTo(gfx::Point(10, 10)); | 362 w11->MoveCursorTo(gfx::Point(10, 10)); |
| 366 EXPECT_EQ("25,25", | 363 EXPECT_EQ("25,25", |
| 367 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 364 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 368 w111->MoveCursorTo(gfx::Point(10, 10)); | 365 w111->MoveCursorTo(gfx::Point(10, 10)); |
| 369 EXPECT_EQ("30,30", | 366 EXPECT_EQ("30,30", |
| 370 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 367 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 371 w1111->MoveCursorTo(gfx::Point(10, 10)); | 368 w1111->MoveCursorTo(gfx::Point(10, 10)); |
| 372 EXPECT_EQ("35,35", | 369 EXPECT_EQ("35,35", |
| 373 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 370 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 374 } | 371 } |
| 375 | 372 |
| 376 TEST_F(WindowTest, ContainsMouse) { | 373 TEST_F(WindowTest, ContainsMouse) { |
| 377 scoped_ptr<Window> w( | 374 std::unique_ptr<Window> w(CreateTestWindow( |
| 378 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), | 375 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); |
| 379 root_window())); | |
| 380 w->Show(); | 376 w->Show(); |
| 381 WindowTestApi w_test_api(w.get()); | 377 WindowTestApi w_test_api(w.get()); |
| 382 Window* root = root_window(); | 378 Window* root = root_window(); |
| 383 root->MoveCursorTo(gfx::Point(10, 10)); | 379 root->MoveCursorTo(gfx::Point(10, 10)); |
| 384 EXPECT_TRUE(w_test_api.ContainsMouse()); | 380 EXPECT_TRUE(w_test_api.ContainsMouse()); |
| 385 root->MoveCursorTo(gfx::Point(9, 10)); | 381 root->MoveCursorTo(gfx::Point(9, 10)); |
| 386 EXPECT_FALSE(w_test_api.ContainsMouse()); | 382 EXPECT_FALSE(w_test_api.ContainsMouse()); |
| 387 } | 383 } |
| 388 | 384 |
| 389 // Test Window::ConvertPointToWindow() with transform to root_window. | 385 // Test Window::ConvertPointToWindow() with transform to root_window. |
| 390 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { | 386 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { |
| 391 gfx::Transform transform; | 387 gfx::Transform transform; |
| 392 transform.Translate(100.0, 100.0); | 388 transform.Translate(100.0, 100.0); |
| 393 transform.Rotate(90.0); | 389 transform.Rotate(90.0); |
| 394 transform.Scale(2.0, 5.0); | 390 transform.Scale(2.0, 5.0); |
| 395 host()->SetRootTransform(transform); | 391 host()->SetRootTransform(transform); |
| 396 host()->MoveCursorTo(gfx::Point(10, 10)); | 392 host()->MoveCursorTo(gfx::Point(10, 10)); |
| 397 #if !defined(OS_WIN) | 393 #if !defined(OS_WIN) |
| 398 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD | 394 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD |
| 399 EXPECT_EQ("50,120", QueryLatestMousePositionRequestInHost(host()).ToString()); | 395 EXPECT_EQ("50,120", QueryLatestMousePositionRequestInHost(host()).ToString()); |
| 400 #endif | 396 #endif |
| 401 EXPECT_EQ("10,10", | 397 EXPECT_EQ("10,10", |
| 402 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 398 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 403 } | 399 } |
| 404 | 400 |
| 405 // Tests Window::ConvertPointToWindow() with transform to non-root windows. | 401 // Tests Window::ConvertPointToWindow() with transform to non-root windows. |
| 406 TEST_F(WindowTest, MoveCursorToWithTransformWindow) { | 402 TEST_F(WindowTest, MoveCursorToWithTransformWindow) { |
| 407 scoped_ptr<Window> w1( | 403 std::unique_ptr<Window> w1(CreateTestWindow( |
| 408 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), | 404 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); |
| 409 root_window())); | |
| 410 | 405 |
| 411 gfx::Transform transform1; | 406 gfx::Transform transform1; |
| 412 transform1.Scale(2, 2); | 407 transform1.Scale(2, 2); |
| 413 w1->SetTransform(transform1); | 408 w1->SetTransform(transform1); |
| 414 w1->MoveCursorTo(gfx::Point(10, 10)); | 409 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 415 EXPECT_EQ("30,30", | 410 EXPECT_EQ("30,30", |
| 416 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 411 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 417 | 412 |
| 418 gfx::Transform transform2; | 413 gfx::Transform transform2; |
| 419 transform2.Translate(-10, 20); | 414 transform2.Translate(-10, 20); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 436 w1->SetTransform(transform4); | 431 w1->SetTransform(transform4); |
| 437 w1->MoveCursorTo(gfx::Point(10, 10)); | 432 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 438 EXPECT_EQ("60,130", | 433 EXPECT_EQ("60,130", |
| 439 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 434 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 440 } | 435 } |
| 441 | 436 |
| 442 // Test Window::ConvertPointToWindow() with complex transforms to both root and | 437 // Test Window::ConvertPointToWindow() with complex transforms to both root and |
| 443 // non-root windows. | 438 // non-root windows. |
| 444 // Test Window::ConvertPointToWindow() with transform to root_window. | 439 // Test Window::ConvertPointToWindow() with transform to root_window. |
| 445 TEST_F(WindowTest, MoveCursorToWithComplexTransform) { | 440 TEST_F(WindowTest, MoveCursorToWithComplexTransform) { |
| 446 scoped_ptr<Window> w1( | 441 std::unique_ptr<Window> w1(CreateTestWindow( |
| 447 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), | 442 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); |
| 448 root_window())); | 443 std::unique_ptr<Window> w11( |
| 449 scoped_ptr<Window> w11( | |
| 450 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); | 444 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); |
| 451 scoped_ptr<Window> w111( | 445 std::unique_ptr<Window> w111( |
| 452 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); | 446 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); |
| 453 scoped_ptr<Window> w1111( | 447 std::unique_ptr<Window> w1111( |
| 454 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); | 448 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
| 455 | 449 |
| 456 // The root window expects transforms that produce integer rects. | 450 // The root window expects transforms that produce integer rects. |
| 457 gfx::Transform root_transform; | 451 gfx::Transform root_transform; |
| 458 root_transform.Translate(60.0, 70.0); | 452 root_transform.Translate(60.0, 70.0); |
| 459 root_transform.Rotate(-90.0); | 453 root_transform.Rotate(-90.0); |
| 460 root_transform.Translate(-50.0, -50.0); | 454 root_transform.Translate(-50.0, -50.0); |
| 461 root_transform.Scale(2.0, 3.0); | 455 root_transform.Scale(2.0, 3.0); |
| 462 | 456 |
| 463 gfx::Transform transform; | 457 gfx::Transform transform; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 477 EXPECT_EQ("169,80", QueryLatestMousePositionRequestInHost(host()).ToString()); | 471 EXPECT_EQ("169,80", QueryLatestMousePositionRequestInHost(host()).ToString()); |
| 478 #endif | 472 #endif |
| 479 EXPECT_EQ("20,53", | 473 EXPECT_EQ("20,53", |
| 480 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 474 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 481 } | 475 } |
| 482 | 476 |
| 483 // Tests that we do not crash when a Window is destroyed by going out of | 477 // Tests that we do not crash when a Window is destroyed by going out of |
| 484 // scope (as opposed to being explicitly deleted by its WindowDelegate). | 478 // scope (as opposed to being explicitly deleted by its WindowDelegate). |
| 485 TEST_F(WindowTest, NoCrashOnWindowDelete) { | 479 TEST_F(WindowTest, NoCrashOnWindowDelete) { |
| 486 CaptureWindowDelegateImpl delegate; | 480 CaptureWindowDelegateImpl delegate; |
| 487 scoped_ptr<Window> window(CreateTestWindowWithDelegate( | 481 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 488 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); | 482 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
| 489 } | 483 } |
| 490 | 484 |
| 491 TEST_F(WindowTest, GetEventHandlerForPoint) { | 485 TEST_F(WindowTest, GetEventHandlerForPoint) { |
| 492 scoped_ptr<Window> w1( | 486 std::unique_ptr<Window> w1(CreateTestWindow( |
| 493 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), | 487 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); |
| 494 root_window())); | 488 std::unique_ptr<Window> w11( |
| 495 scoped_ptr<Window> w11( | |
| 496 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); | 489 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); |
| 497 scoped_ptr<Window> w111( | 490 std::unique_ptr<Window> w111( |
| 498 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); | 491 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); |
| 499 scoped_ptr<Window> w1111( | 492 std::unique_ptr<Window> w1111( |
| 500 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); | 493 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
| 501 scoped_ptr<Window> w12( | 494 std::unique_ptr<Window> w12(CreateTestWindow( |
| 502 CreateTestWindow(SK_ColorMAGENTA, 12, gfx::Rect(10, 420, 25, 25), | 495 SK_ColorMAGENTA, 12, gfx::Rect(10, 420, 25, 25), w1.get())); |
| 503 w1.get())); | 496 std::unique_ptr<Window> w121( |
| 504 scoped_ptr<Window> w121( | |
| 505 CreateTestWindow(SK_ColorYELLOW, 121, gfx::Rect(5, 5, 5, 5), w12.get())); | 497 CreateTestWindow(SK_ColorYELLOW, 121, gfx::Rect(5, 5, 5, 5), w12.get())); |
| 506 scoped_ptr<Window> w13( | 498 std::unique_ptr<Window> w13( |
| 507 CreateTestWindow(SK_ColorGRAY, 13, gfx::Rect(5, 470, 50, 50), w1.get())); | 499 CreateTestWindow(SK_ColorGRAY, 13, gfx::Rect(5, 470, 50, 50), w1.get())); |
| 508 | 500 |
| 509 Window* root = root_window(); | 501 Window* root = root_window(); |
| 510 w1->parent()->SetBounds(gfx::Rect(500, 500)); | 502 w1->parent()->SetBounds(gfx::Rect(500, 500)); |
| 511 EXPECT_EQ(NULL, root->GetEventHandlerForPoint(gfx::Point(5, 5))); | 503 EXPECT_EQ(NULL, root->GetEventHandlerForPoint(gfx::Point(5, 5))); |
| 512 EXPECT_EQ(w1.get(), root->GetEventHandlerForPoint(gfx::Point(11, 11))); | 504 EXPECT_EQ(w1.get(), root->GetEventHandlerForPoint(gfx::Point(11, 11))); |
| 513 EXPECT_EQ(w11.get(), root->GetEventHandlerForPoint(gfx::Point(16, 16))); | 505 EXPECT_EQ(w11.get(), root->GetEventHandlerForPoint(gfx::Point(16, 16))); |
| 514 EXPECT_EQ(w111.get(), root->GetEventHandlerForPoint(gfx::Point(21, 21))); | 506 EXPECT_EQ(w111.get(), root->GetEventHandlerForPoint(gfx::Point(21, 21))); |
| 515 EXPECT_EQ(w1111.get(), root->GetEventHandlerForPoint(gfx::Point(26, 26))); | 507 EXPECT_EQ(w1111.get(), root->GetEventHandlerForPoint(gfx::Point(26, 26))); |
| 516 EXPECT_EQ(w12.get(), root->GetEventHandlerForPoint(gfx::Point(21, 431))); | 508 EXPECT_EQ(w12.get(), root->GetEventHandlerForPoint(gfx::Point(21, 431))); |
| 517 EXPECT_EQ(w121.get(), root->GetEventHandlerForPoint(gfx::Point(26, 436))); | 509 EXPECT_EQ(w121.get(), root->GetEventHandlerForPoint(gfx::Point(26, 436))); |
| 518 EXPECT_EQ(w13.get(), root->GetEventHandlerForPoint(gfx::Point(26, 481))); | 510 EXPECT_EQ(w13.get(), root->GetEventHandlerForPoint(gfx::Point(26, 481))); |
| 519 } | 511 } |
| 520 | 512 |
| 521 TEST_F(WindowTest, GetEventHandlerForPointWithOverride) { | 513 TEST_F(WindowTest, GetEventHandlerForPointWithOverride) { |
| 522 // If our child is flush to our top-left corner he gets events just inside the | 514 // If our child is flush to our top-left corner he gets events just inside the |
| 523 // window edges. | 515 // window edges. |
| 524 scoped_ptr<Window> parent( | 516 std::unique_ptr<Window> parent(CreateTestWindow( |
| 525 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 20, 400, 500), | 517 SK_ColorWHITE, 1, gfx::Rect(10, 20, 400, 500), root_window())); |
| 526 root_window())); | 518 std::unique_ptr<Window> child( |
| 527 scoped_ptr<Window> child( | |
| 528 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 60, 70), parent.get())); | 519 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 60, 70), parent.get())); |
| 529 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); | 520 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); |
| 530 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); | 521 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); |
| 531 | 522 |
| 532 // We can override the hit test bounds of the parent to make the parent grab | 523 // We can override the hit test bounds of the parent to make the parent grab |
| 533 // events along that edge. | 524 // events along that edge. |
| 534 parent->set_hit_test_bounds_override_inner(gfx::Insets(1, 1, 1, 1)); | 525 parent->set_hit_test_bounds_override_inner(gfx::Insets(1, 1, 1, 1)); |
| 535 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); | 526 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); |
| 536 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); | 527 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); |
| 537 } | 528 } |
| 538 | 529 |
| 539 TEST_F(WindowTest, GetEventHandlerForPointWithOverrideDescendingOrder) { | 530 TEST_F(WindowTest, GetEventHandlerForPointWithOverrideDescendingOrder) { |
| 540 scoped_ptr<SelfEventHandlingWindowDelegate> parent_delegate( | 531 std::unique_ptr<SelfEventHandlingWindowDelegate> parent_delegate( |
| 541 new SelfEventHandlingWindowDelegate); | 532 new SelfEventHandlingWindowDelegate); |
| 542 scoped_ptr<Window> parent(CreateTestWindowWithDelegate( | 533 std::unique_ptr<Window> parent(CreateTestWindowWithDelegate( |
| 543 parent_delegate.get(), 1, gfx::Rect(10, 20, 400, 500), root_window())); | 534 parent_delegate.get(), 1, gfx::Rect(10, 20, 400, 500), root_window())); |
| 544 scoped_ptr<Window> child( | 535 std::unique_ptr<Window> child(CreateTestWindow( |
| 545 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 390, 480), | 536 SK_ColorRED, 2, gfx::Rect(0, 0, 390, 480), parent.get())); |
| 546 parent.get())); | |
| 547 | 537 |
| 548 // We can override ShouldDescendIntoChildForEventHandling to make the parent | 538 // We can override ShouldDescendIntoChildForEventHandling to make the parent |
| 549 // grab all events. | 539 // grab all events. |
| 550 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); | 540 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); |
| 551 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(50, 50))); | 541 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(50, 50))); |
| 552 } | 542 } |
| 553 | 543 |
| 554 TEST_F(WindowTest, GetTopWindowContainingPoint) { | 544 TEST_F(WindowTest, GetTopWindowContainingPoint) { |
| 555 Window* root = root_window(); | 545 Window* root = root_window(); |
| 556 root->SetBounds(gfx::Rect(0, 0, 300, 300)); | 546 root->SetBounds(gfx::Rect(0, 0, 300, 300)); |
| 557 | 547 |
| 558 scoped_ptr<Window> w1( | 548 std::unique_ptr<Window> w1(CreateTestWindow( |
| 559 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100), | 549 SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100), root_window())); |
| 560 root_window())); | 550 std::unique_ptr<Window> w11( |
| 561 scoped_ptr<Window> w11( | |
| 562 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(0, 0, 120, 120), w1.get())); | 551 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(0, 0, 120, 120), w1.get())); |
| 563 | 552 |
| 564 scoped_ptr<Window> w2( | 553 std::unique_ptr<Window> w2( |
| 565 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(5, 5, 55, 55), | 554 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(5, 5, 55, 55), root_window())); |
| 566 root_window())); | |
| 567 | 555 |
| 568 scoped_ptr<Window> w3( | 556 std::unique_ptr<Window> w3(CreateTestWindowWithDelegate( |
| 569 CreateTestWindowWithDelegate( | 557 NULL, 3, gfx::Rect(200, 200, 100, 100), root_window())); |
| 570 NULL, 3, gfx::Rect(200, 200, 100, 100), root_window())); | 558 std::unique_ptr<Window> w31( |
| 571 scoped_ptr<Window> w31( | |
| 572 CreateTestWindow(SK_ColorCYAN, 31, gfx::Rect(0, 0, 50, 50), w3.get())); | 559 CreateTestWindow(SK_ColorCYAN, 31, gfx::Rect(0, 0, 50, 50), w3.get())); |
| 573 scoped_ptr<Window> w311( | 560 std::unique_ptr<Window> w311( |
| 574 CreateTestWindow(SK_ColorBLUE, 311, gfx::Rect(0, 0, 10, 10), w31.get())); | 561 CreateTestWindow(SK_ColorBLUE, 311, gfx::Rect(0, 0, 10, 10), w31.get())); |
| 575 | 562 |
| 576 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(0, 0))); | 563 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(0, 0))); |
| 577 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(5, 5))); | 564 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(5, 5))); |
| 578 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(10, 10))); | 565 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(10, 10))); |
| 579 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(59, 59))); | 566 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(59, 59))); |
| 580 EXPECT_EQ(w1.get(), root->GetTopWindowContainingPoint(gfx::Point(60, 60))); | 567 EXPECT_EQ(w1.get(), root->GetTopWindowContainingPoint(gfx::Point(60, 60))); |
| 581 EXPECT_EQ(w1.get(), root->GetTopWindowContainingPoint(gfx::Point(109, 109))); | 568 EXPECT_EQ(w1.get(), root->GetTopWindowContainingPoint(gfx::Point(109, 109))); |
| 582 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(110, 110))); | 569 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(110, 110))); |
| 583 EXPECT_EQ(w31.get(), root->GetTopWindowContainingPoint(gfx::Point(200, 200))); | 570 EXPECT_EQ(w31.get(), root->GetTopWindowContainingPoint(gfx::Point(200, 200))); |
| 584 EXPECT_EQ(w31.get(), root->GetTopWindowContainingPoint(gfx::Point(220, 220))); | 571 EXPECT_EQ(w31.get(), root->GetTopWindowContainingPoint(gfx::Point(220, 220))); |
| 585 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(260, 260))); | 572 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(260, 260))); |
| 586 } | 573 } |
| 587 | 574 |
| 588 TEST_F(WindowTest, GetToplevelWindow) { | 575 TEST_F(WindowTest, GetToplevelWindow) { |
| 589 const gfx::Rect kBounds(0, 0, 10, 10); | 576 const gfx::Rect kBounds(0, 0, 10, 10); |
| 590 TestWindowDelegate delegate; | 577 TestWindowDelegate delegate; |
| 591 | 578 |
| 592 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 579 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 593 scoped_ptr<Window> w11( | 580 std::unique_ptr<Window> w11( |
| 594 CreateTestWindowWithDelegate(&delegate, 11, kBounds, w1.get())); | 581 CreateTestWindowWithDelegate(&delegate, 11, kBounds, w1.get())); |
| 595 scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); | 582 std::unique_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); |
| 596 scoped_ptr<Window> w1111( | 583 std::unique_ptr<Window> w1111( |
| 597 CreateTestWindowWithDelegate(&delegate, 1111, kBounds, w111.get())); | 584 CreateTestWindowWithDelegate(&delegate, 1111, kBounds, w111.get())); |
| 598 | 585 |
| 599 EXPECT_TRUE(root_window()->GetToplevelWindow() == NULL); | 586 EXPECT_TRUE(root_window()->GetToplevelWindow() == NULL); |
| 600 EXPECT_TRUE(w1->GetToplevelWindow() == NULL); | 587 EXPECT_TRUE(w1->GetToplevelWindow() == NULL); |
| 601 EXPECT_EQ(w11.get(), w11->GetToplevelWindow()); | 588 EXPECT_EQ(w11.get(), w11->GetToplevelWindow()); |
| 602 EXPECT_EQ(w11.get(), w111->GetToplevelWindow()); | 589 EXPECT_EQ(w11.get(), w111->GetToplevelWindow()); |
| 603 EXPECT_EQ(w11.get(), w1111->GetToplevelWindow()); | 590 EXPECT_EQ(w11.get(), w1111->GetToplevelWindow()); |
| 604 } | 591 } |
| 605 | 592 |
| 606 class AddedToRootWindowObserver : public WindowObserver { | 593 class AddedToRootWindowObserver : public WindowObserver { |
| 607 public: | 594 public: |
| 608 AddedToRootWindowObserver() : called_(false) {} | 595 AddedToRootWindowObserver() : called_(false) {} |
| 609 | 596 |
| 610 void OnWindowAddedToRootWindow(Window* window) override { called_ = true; } | 597 void OnWindowAddedToRootWindow(Window* window) override { called_ = true; } |
| 611 | 598 |
| 612 bool called() const { return called_; } | 599 bool called() const { return called_; } |
| 613 | 600 |
| 614 private: | 601 private: |
| 615 bool called_; | 602 bool called_; |
| 616 | 603 |
| 617 DISALLOW_COPY_AND_ASSIGN(AddedToRootWindowObserver); | 604 DISALLOW_COPY_AND_ASSIGN(AddedToRootWindowObserver); |
| 618 }; | 605 }; |
| 619 | 606 |
| 620 TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) { | 607 TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) { |
| 621 AddedToRootWindowObserver parent_observer; | 608 AddedToRootWindowObserver parent_observer; |
| 622 AddedToRootWindowObserver child_observer; | 609 AddedToRootWindowObserver child_observer; |
| 623 scoped_ptr<Window> parent_window(CreateTestWindowWithId(1, root_window())); | 610 std::unique_ptr<Window> parent_window( |
| 624 scoped_ptr<Window> child_window(new Window(NULL)); | 611 CreateTestWindowWithId(1, root_window())); |
| 612 std::unique_ptr<Window> child_window(new Window(NULL)); |
| 625 child_window->Init(ui::LAYER_TEXTURED); | 613 child_window->Init(ui::LAYER_TEXTURED); |
| 626 child_window->Show(); | 614 child_window->Show(); |
| 627 | 615 |
| 628 parent_window->AddObserver(&parent_observer); | 616 parent_window->AddObserver(&parent_observer); |
| 629 child_window->AddObserver(&child_observer); | 617 child_window->AddObserver(&child_observer); |
| 630 | 618 |
| 631 parent_window->AddChild(child_window.get()); | 619 parent_window->AddChild(child_window.get()); |
| 632 | 620 |
| 633 EXPECT_FALSE(parent_observer.called()); | 621 EXPECT_FALSE(parent_observer.called()); |
| 634 EXPECT_TRUE(child_observer.called()); | 622 EXPECT_TRUE(child_observer.called()); |
| 635 | 623 |
| 636 parent_window->RemoveObserver(&parent_observer); | 624 parent_window->RemoveObserver(&parent_observer); |
| 637 child_window->RemoveObserver(&child_observer); | 625 child_window->RemoveObserver(&child_observer); |
| 638 } | 626 } |
| 639 | 627 |
| 640 // Various destruction assertions. | 628 // Various destruction assertions. |
| 641 TEST_F(WindowTest, DestroyTest) { | 629 TEST_F(WindowTest, DestroyTest) { |
| 642 DestroyTrackingDelegateImpl parent_delegate; | 630 DestroyTrackingDelegateImpl parent_delegate; |
| 643 ChildWindowDelegateImpl child_delegate(&parent_delegate); | 631 ChildWindowDelegateImpl child_delegate(&parent_delegate); |
| 644 { | 632 { |
| 645 scoped_ptr<Window> parent( | 633 std::unique_ptr<Window> parent(CreateTestWindowWithDelegate( |
| 646 CreateTestWindowWithDelegate(&parent_delegate, 0, gfx::Rect(), | 634 &parent_delegate, 0, gfx::Rect(), root_window())); |
| 647 root_window())); | |
| 648 CreateTestWindowWithDelegate(&child_delegate, 0, gfx::Rect(), parent.get()); | 635 CreateTestWindowWithDelegate(&child_delegate, 0, gfx::Rect(), parent.get()); |
| 649 } | 636 } |
| 650 // Both the parent and child should have been destroyed. | 637 // Both the parent and child should have been destroyed. |
| 651 EXPECT_EQ(1, parent_delegate.destroying_count()); | 638 EXPECT_EQ(1, parent_delegate.destroying_count()); |
| 652 EXPECT_EQ(1, parent_delegate.destroyed_count()); | 639 EXPECT_EQ(1, parent_delegate.destroyed_count()); |
| 653 EXPECT_EQ(1, child_delegate.destroying_count()); | 640 EXPECT_EQ(1, child_delegate.destroying_count()); |
| 654 EXPECT_EQ(1, child_delegate.destroyed_count()); | 641 EXPECT_EQ(1, child_delegate.destroyed_count()); |
| 655 } | 642 } |
| 656 | 643 |
| 657 // Tests that a window is orphaned before OnWindowDestroyed is called. | 644 // Tests that a window is orphaned before OnWindowDestroyed is called. |
| 658 TEST_F(WindowTest, OrphanedBeforeOnDestroyed) { | 645 TEST_F(WindowTest, OrphanedBeforeOnDestroyed) { |
| 659 TestWindowDelegate parent_delegate; | 646 TestWindowDelegate parent_delegate; |
| 660 DestroyOrphanDelegate child_delegate; | 647 DestroyOrphanDelegate child_delegate; |
| 661 { | 648 { |
| 662 scoped_ptr<Window> parent( | 649 std::unique_ptr<Window> parent(CreateTestWindowWithDelegate( |
| 663 CreateTestWindowWithDelegate(&parent_delegate, 0, gfx::Rect(), | 650 &parent_delegate, 0, gfx::Rect(), root_window())); |
| 664 root_window())); | 651 std::unique_ptr<Window> child(CreateTestWindowWithDelegate( |
| 665 scoped_ptr<Window> child(CreateTestWindowWithDelegate(&child_delegate, 0, | 652 &child_delegate, 0, gfx::Rect(), parent.get())); |
| 666 gfx::Rect(), parent.get())); | |
| 667 child_delegate.set_window(child.get()); | 653 child_delegate.set_window(child.get()); |
| 668 } | 654 } |
| 669 } | 655 } |
| 670 | 656 |
| 671 // Make sure StackChildAtTop moves both the window and layer to the front. | 657 // Make sure StackChildAtTop moves both the window and layer to the front. |
| 672 TEST_F(WindowTest, StackChildAtTop) { | 658 TEST_F(WindowTest, StackChildAtTop) { |
| 673 Window parent(NULL); | 659 Window parent(NULL); |
| 674 parent.Init(ui::LAYER_NOT_DRAWN); | 660 parent.Init(ui::LAYER_NOT_DRAWN); |
| 675 Window child1(NULL); | 661 Window child1(NULL); |
| 676 child1.Init(ui::LAYER_NOT_DRAWN); | 662 child1.Init(ui::LAYER_NOT_DRAWN); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 EXPECT_EQ(&child3, parent.children()[2]); | 768 EXPECT_EQ(&child3, parent.children()[2]); |
| 783 ASSERT_EQ(3u, parent.layer()->children().size()); | 769 ASSERT_EQ(3u, parent.layer()->children().size()); |
| 784 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); | 770 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); |
| 785 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); | 771 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); |
| 786 EXPECT_EQ(child3.layer(), parent.layer()->children()[2]); | 772 EXPECT_EQ(child3.layer(), parent.layer()->children()[2]); |
| 787 } | 773 } |
| 788 | 774 |
| 789 // Various capture assertions. | 775 // Various capture assertions. |
| 790 TEST_F(WindowTest, CaptureTests) { | 776 TEST_F(WindowTest, CaptureTests) { |
| 791 CaptureWindowDelegateImpl delegate; | 777 CaptureWindowDelegateImpl delegate; |
| 792 scoped_ptr<Window> window(CreateTestWindowWithDelegate( | 778 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 793 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); | 779 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
| 794 EXPECT_FALSE(window->HasCapture()); | 780 EXPECT_FALSE(window->HasCapture()); |
| 795 | 781 |
| 796 delegate.ResetCounts(); | 782 delegate.ResetCounts(); |
| 797 | 783 |
| 798 // Do a capture. | 784 // Do a capture. |
| 799 window->SetCapture(); | 785 window->SetCapture(); |
| 800 EXPECT_TRUE(window->HasCapture()); | 786 EXPECT_TRUE(window->HasCapture()); |
| 801 EXPECT_EQ(0, delegate.capture_lost_count()); | 787 EXPECT_EQ(0, delegate.capture_lost_count()); |
| 802 EXPECT_EQ(0, delegate.capture_changed_event_count()); | 788 EXPECT_EQ(0, delegate.capture_changed_event_count()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 833 // in the root window. | 819 // in the root window. |
| 834 window->SetCapture(); | 820 window->SetCapture(); |
| 835 EXPECT_EQ(window.get(), aura::client::GetCaptureWindow(root_window())); | 821 EXPECT_EQ(window.get(), aura::client::GetCaptureWindow(root_window())); |
| 836 window->parent()->RemoveChild(window.get()); | 822 window->parent()->RemoveChild(window.get()); |
| 837 EXPECT_FALSE(window->HasCapture()); | 823 EXPECT_FALSE(window->HasCapture()); |
| 838 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); | 824 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); |
| 839 } | 825 } |
| 840 | 826 |
| 841 TEST_F(WindowTest, TouchCaptureCancelsOtherTouches) { | 827 TEST_F(WindowTest, TouchCaptureCancelsOtherTouches) { |
| 842 CaptureWindowDelegateImpl delegate1; | 828 CaptureWindowDelegateImpl delegate1; |
| 843 scoped_ptr<Window> w1(CreateTestWindowWithDelegate( | 829 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 844 &delegate1, 0, gfx::Rect(0, 0, 50, 50), root_window())); | 830 &delegate1, 0, gfx::Rect(0, 0, 50, 50), root_window())); |
| 845 CaptureWindowDelegateImpl delegate2; | 831 CaptureWindowDelegateImpl delegate2; |
| 846 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( | 832 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( |
| 847 &delegate2, 0, gfx::Rect(50, 50, 50, 50), root_window())); | 833 &delegate2, 0, gfx::Rect(50, 50, 50, 50), root_window())); |
| 848 | 834 |
| 849 // Press on w1. | 835 // Press on w1. |
| 850 ui::TouchEvent press1( | 836 ui::TouchEvent press1( |
| 851 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); | 837 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); |
| 852 DispatchEventUsingWindowDispatcher(&press1); | 838 DispatchEventUsingWindowDispatcher(&press1); |
| 853 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. | 839 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. |
| 854 EXPECT_EQ(2, delegate1.gesture_event_count()); | 840 EXPECT_EQ(2, delegate1.gesture_event_count()); |
| 855 delegate1.ResetCounts(); | 841 delegate1.ResetCounts(); |
| 856 | 842 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 // And releasing capture changes nothing. | 874 // And releasing capture changes nothing. |
| 889 w2->ReleaseCapture(); | 875 w2->ReleaseCapture(); |
| 890 EXPECT_EQ(0, delegate1.gesture_event_count()); | 876 EXPECT_EQ(0, delegate1.gesture_event_count()); |
| 891 EXPECT_EQ(0, delegate1.touch_event_count()); | 877 EXPECT_EQ(0, delegate1.touch_event_count()); |
| 892 EXPECT_EQ(0, delegate2.gesture_event_count()); | 878 EXPECT_EQ(0, delegate2.gesture_event_count()); |
| 893 EXPECT_EQ(0, delegate2.touch_event_count()); | 879 EXPECT_EQ(0, delegate2.touch_event_count()); |
| 894 } | 880 } |
| 895 | 881 |
| 896 TEST_F(WindowTest, TouchCaptureDoesntCancelCapturedTouches) { | 882 TEST_F(WindowTest, TouchCaptureDoesntCancelCapturedTouches) { |
| 897 CaptureWindowDelegateImpl delegate; | 883 CaptureWindowDelegateImpl delegate; |
| 898 scoped_ptr<Window> window(CreateTestWindowWithDelegate( | 884 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 899 &delegate, 0, gfx::Rect(0, 0, 50, 50), root_window())); | 885 &delegate, 0, gfx::Rect(0, 0, 50, 50), root_window())); |
| 900 base::TimeDelta time = getTime(); | 886 base::TimeDelta time = getTime(); |
| 901 const int kTimeDelta = 100; | 887 const int kTimeDelta = 100; |
| 902 | 888 |
| 903 ui::TouchEvent press( | 889 ui::TouchEvent press( |
| 904 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, time); | 890 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, time); |
| 905 DispatchEventUsingWindowDispatcher(&press); | 891 DispatchEventUsingWindowDispatcher(&press); |
| 906 | 892 |
| 907 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. | 893 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. |
| 908 EXPECT_EQ(2, delegate.gesture_event_count()); | 894 EXPECT_EQ(2, delegate.gesture_event_count()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 DispatchEventUsingWindowDispatcher(&release); | 930 DispatchEventUsingWindowDispatcher(&release); |
| 945 EXPECT_EQ(1, delegate.touch_event_count()); | 931 EXPECT_EQ(1, delegate.touch_event_count()); |
| 946 EXPECT_EQ(2, delegate.gesture_event_count()); | 932 EXPECT_EQ(2, delegate.gesture_event_count()); |
| 947 } | 933 } |
| 948 | 934 |
| 949 | 935 |
| 950 // Assertions around SetCapture() and touch/gestures. | 936 // Assertions around SetCapture() and touch/gestures. |
| 951 TEST_F(WindowTest, TransferCaptureTouchEvents) { | 937 TEST_F(WindowTest, TransferCaptureTouchEvents) { |
| 952 // Touch on |w1|. | 938 // Touch on |w1|. |
| 953 CaptureWindowDelegateImpl d1; | 939 CaptureWindowDelegateImpl d1; |
| 954 scoped_ptr<Window> w1(CreateTestWindowWithDelegate( | 940 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 955 &d1, 0, gfx::Rect(0, 0, 20, 20), root_window())); | 941 &d1, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
| 956 ui::TouchEvent p1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); | 942 ui::TouchEvent p1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); |
| 957 DispatchEventUsingWindowDispatcher(&p1); | 943 DispatchEventUsingWindowDispatcher(&p1); |
| 958 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. | 944 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. |
| 959 EXPECT_EQ(1, d1.touch_event_count()); | 945 EXPECT_EQ(1, d1.touch_event_count()); |
| 960 EXPECT_EQ(2, d1.gesture_event_count()); | 946 EXPECT_EQ(2, d1.gesture_event_count()); |
| 961 d1.ResetCounts(); | 947 d1.ResetCounts(); |
| 962 | 948 |
| 963 // Touch on |w2| with a different id. | 949 // Touch on |w2| with a different id. |
| 964 CaptureWindowDelegateImpl d2; | 950 CaptureWindowDelegateImpl d2; |
| 965 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( | 951 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( |
| 966 &d2, 0, gfx::Rect(40, 0, 40, 20), root_window())); | 952 &d2, 0, gfx::Rect(40, 0, 40, 20), root_window())); |
| 967 ui::TouchEvent p2(ui::ET_TOUCH_PRESSED, gfx::Point(41, 10), 1, getTime()); | 953 ui::TouchEvent p2(ui::ET_TOUCH_PRESSED, gfx::Point(41, 10), 1, getTime()); |
| 968 DispatchEventUsingWindowDispatcher(&p2); | 954 DispatchEventUsingWindowDispatcher(&p2); |
| 969 EXPECT_EQ(0, d1.touch_event_count()); | 955 EXPECT_EQ(0, d1.touch_event_count()); |
| 970 EXPECT_EQ(0, d1.gesture_event_count()); | 956 EXPECT_EQ(0, d1.gesture_event_count()); |
| 971 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN for new target window. | 957 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN for new target window. |
| 972 EXPECT_EQ(1, d2.touch_event_count()); | 958 EXPECT_EQ(1, d2.touch_event_count()); |
| 973 EXPECT_EQ(2, d2.gesture_event_count()); | 959 EXPECT_EQ(2, d2.gesture_event_count()); |
| 974 d1.ResetCounts(); | 960 d1.ResetCounts(); |
| 975 d2.ResetCounts(); | 961 d2.ResetCounts(); |
| 976 | 962 |
| 977 // Set capture on |w2|, this should send a cancel (TAP_CANCEL, END) to |w1| | 963 // Set capture on |w2|, this should send a cancel (TAP_CANCEL, END) to |w1| |
| 978 // but not |w2|. | 964 // but not |w2|. |
| 979 w2->SetCapture(); | 965 w2->SetCapture(); |
| 980 EXPECT_EQ(1, d1.touch_event_count()); | 966 EXPECT_EQ(1, d1.touch_event_count()); |
| 981 EXPECT_EQ(2, d1.gesture_event_count()); | 967 EXPECT_EQ(2, d1.gesture_event_count()); |
| 982 EXPECT_EQ(0, d2.touch_event_count()); | 968 EXPECT_EQ(0, d2.touch_event_count()); |
| 983 EXPECT_EQ(0, d2.gesture_event_count()); | 969 EXPECT_EQ(0, d2.gesture_event_count()); |
| 984 d1.ResetCounts(); | 970 d1.ResetCounts(); |
| 985 d2.ResetCounts(); | 971 d2.ResetCounts(); |
| 986 | 972 |
| 987 CaptureWindowDelegateImpl d3; | 973 CaptureWindowDelegateImpl d3; |
| 988 scoped_ptr<Window> w3(CreateTestWindowWithDelegate( | 974 std::unique_ptr<Window> w3(CreateTestWindowWithDelegate( |
| 989 &d3, 0, gfx::Rect(0, 0, 100, 101), root_window())); | 975 &d3, 0, gfx::Rect(0, 0, 100, 101), root_window())); |
| 990 // Set capture on |w3|. All touches have already been cancelled. | 976 // Set capture on |w3|. All touches have already been cancelled. |
| 991 w3->SetCapture(); | 977 w3->SetCapture(); |
| 992 EXPECT_EQ(0, d1.touch_event_count()); | 978 EXPECT_EQ(0, d1.touch_event_count()); |
| 993 EXPECT_EQ(0, d1.gesture_event_count()); | 979 EXPECT_EQ(0, d1.gesture_event_count()); |
| 994 EXPECT_EQ(1, d2.touch_event_count()); | 980 EXPECT_EQ(1, d2.touch_event_count()); |
| 995 EXPECT_EQ(2, d2.gesture_event_count()); | 981 EXPECT_EQ(2, d2.gesture_event_count()); |
| 996 EXPECT_EQ(0, d3.touch_event_count()); | 982 EXPECT_EQ(0, d3.touch_event_count()); |
| 997 EXPECT_EQ(0, d3.gesture_event_count()); | 983 EXPECT_EQ(0, d3.gesture_event_count()); |
| 998 d2.ResetCounts(); | 984 d2.ResetCounts(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1024 EXPECT_EQ(0, d1.gesture_event_count()); | 1010 EXPECT_EQ(0, d1.gesture_event_count()); |
| 1025 EXPECT_EQ(0, d2.touch_event_count()); | 1011 EXPECT_EQ(0, d2.touch_event_count()); |
| 1026 EXPECT_EQ(0, d2.gesture_event_count()); | 1012 EXPECT_EQ(0, d2.gesture_event_count()); |
| 1027 EXPECT_EQ(0, d3.touch_event_count()); | 1013 EXPECT_EQ(0, d3.touch_event_count()); |
| 1028 EXPECT_EQ(0, d3.gesture_event_count()); | 1014 EXPECT_EQ(0, d3.gesture_event_count()); |
| 1029 } | 1015 } |
| 1030 | 1016 |
| 1031 // Changes capture while capture is already ongoing. | 1017 // Changes capture while capture is already ongoing. |
| 1032 TEST_F(WindowTest, ChangeCaptureWhileMouseDown) { | 1018 TEST_F(WindowTest, ChangeCaptureWhileMouseDown) { |
| 1033 CaptureWindowDelegateImpl delegate; | 1019 CaptureWindowDelegateImpl delegate; |
| 1034 scoped_ptr<Window> window(CreateTestWindowWithDelegate( | 1020 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 1035 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); | 1021 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
| 1036 CaptureWindowDelegateImpl delegate2; | 1022 CaptureWindowDelegateImpl delegate2; |
| 1037 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( | 1023 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( |
| 1038 &delegate2, 0, gfx::Rect(20, 20, 20, 20), root_window())); | 1024 &delegate2, 0, gfx::Rect(20, 20, 20, 20), root_window())); |
| 1039 | 1025 |
| 1040 // Execute the scheduled draws so that mouse events are not | 1026 // Execute the scheduled draws so that mouse events are not |
| 1041 // aggregated. | 1027 // aggregated. |
| 1042 RunAllPendingInMessageLoop(); | 1028 RunAllPendingInMessageLoop(); |
| 1043 | 1029 |
| 1044 EXPECT_FALSE(window->HasCapture()); | 1030 EXPECT_FALSE(window->HasCapture()); |
| 1045 | 1031 |
| 1046 // Do a capture. | 1032 // Do a capture. |
| 1047 delegate.ResetCounts(); | 1033 delegate.ResetCounts(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1063 generator.MoveMouseTo(gfx::Point(40, 40), 2); | 1049 generator.MoveMouseTo(gfx::Point(40, 40), 2); |
| 1064 EXPECT_EQ(1, delegate.capture_lost_count()); | 1050 EXPECT_EQ(1, delegate.capture_lost_count()); |
| 1065 EXPECT_EQ(1, delegate.capture_changed_event_count()); | 1051 EXPECT_EQ(1, delegate.capture_changed_event_count()); |
| 1066 EXPECT_EQ(1, delegate.mouse_event_count()); | 1052 EXPECT_EQ(1, delegate.mouse_event_count()); |
| 1067 EXPECT_EQ(2, delegate2.mouse_event_count()); | 1053 EXPECT_EQ(2, delegate2.mouse_event_count()); |
| 1068 } | 1054 } |
| 1069 | 1055 |
| 1070 // Verifies capture is reset when a window is destroyed. | 1056 // Verifies capture is reset when a window is destroyed. |
| 1071 TEST_F(WindowTest, ReleaseCaptureOnDestroy) { | 1057 TEST_F(WindowTest, ReleaseCaptureOnDestroy) { |
| 1072 CaptureWindowDelegateImpl delegate; | 1058 CaptureWindowDelegateImpl delegate; |
| 1073 scoped_ptr<Window> window(CreateTestWindowWithDelegate( | 1059 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 1074 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); | 1060 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
| 1075 EXPECT_FALSE(window->HasCapture()); | 1061 EXPECT_FALSE(window->HasCapture()); |
| 1076 | 1062 |
| 1077 // Do a capture. | 1063 // Do a capture. |
| 1078 window->SetCapture(); | 1064 window->SetCapture(); |
| 1079 EXPECT_TRUE(window->HasCapture()); | 1065 EXPECT_TRUE(window->HasCapture()); |
| 1080 | 1066 |
| 1081 // Destroy the window. | 1067 // Destroy the window. |
| 1082 window.reset(); | 1068 window.reset(); |
| 1083 | 1069 |
| 1084 // Make sure the root window doesn't reference the window anymore. | 1070 // Make sure the root window doesn't reference the window anymore. |
| 1085 EXPECT_EQ(NULL, host()->dispatcher()->mouse_pressed_handler()); | 1071 EXPECT_EQ(NULL, host()->dispatcher()->mouse_pressed_handler()); |
| 1086 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); | 1072 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); |
| 1087 } | 1073 } |
| 1088 | 1074 |
| 1089 TEST_F(WindowTest, GetBoundsInRootWindow) { | 1075 TEST_F(WindowTest, GetBoundsInRootWindow) { |
| 1090 scoped_ptr<Window> viewport(CreateTestWindowWithBounds( | 1076 std::unique_ptr<Window> viewport( |
| 1091 gfx::Rect(0, 0, 300, 300), root_window())); | 1077 CreateTestWindowWithBounds(gfx::Rect(0, 0, 300, 300), root_window())); |
| 1092 scoped_ptr<Window> child(CreateTestWindowWithBounds( | 1078 std::unique_ptr<Window> child( |
| 1093 gfx::Rect(0, 0, 100, 100), viewport.get())); | 1079 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), viewport.get())); |
| 1094 // Sanity check. | 1080 // Sanity check. |
| 1095 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); | 1081 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); |
| 1096 | 1082 |
| 1097 // The |child| window's screen bounds should move along with the |viewport|. | 1083 // The |child| window's screen bounds should move along with the |viewport|. |
| 1098 viewport->SetBounds(gfx::Rect(-100, -100, 300, 300)); | 1084 viewport->SetBounds(gfx::Rect(-100, -100, 300, 300)); |
| 1099 EXPECT_EQ("-100,-100 100x100", child->GetBoundsInRootWindow().ToString()); | 1085 EXPECT_EQ("-100,-100 100x100", child->GetBoundsInRootWindow().ToString()); |
| 1100 | 1086 |
| 1101 // The |child| window is moved to the 0,0 in screen coordinates. | 1087 // The |child| window is moved to the 0,0 in screen coordinates. |
| 1102 // |GetBoundsInRootWindow()| should return 0,0. | 1088 // |GetBoundsInRootWindow()| should return 0,0. |
| 1103 child->SetBounds(gfx::Rect(100, 100, 100, 100)); | 1089 child->SetBounds(gfx::Rect(100, 100, 100, 100)); |
| 1104 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); | 1090 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); |
| 1105 } | 1091 } |
| 1106 | 1092 |
| 1107 TEST_F(WindowTest, GetBoundsInRootWindowWithLayers) { | 1093 TEST_F(WindowTest, GetBoundsInRootWindowWithLayers) { |
| 1108 scoped_ptr<Window> viewport( | 1094 std::unique_ptr<Window> viewport( |
| 1109 CreateTestWindowWithBounds(gfx::Rect(0, 0, 300, 300), root_window())); | 1095 CreateTestWindowWithBounds(gfx::Rect(0, 0, 300, 300), root_window())); |
| 1110 | 1096 |
| 1111 scoped_ptr<Window> widget( | 1097 std::unique_ptr<Window> widget( |
| 1112 CreateTestWindowWithBounds(gfx::Rect(0, 0, 200, 200), viewport.get())); | 1098 CreateTestWindowWithBounds(gfx::Rect(0, 0, 200, 200), viewport.get())); |
| 1113 | 1099 |
| 1114 scoped_ptr<Window> child( | 1100 std::unique_ptr<Window> child( |
| 1115 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), widget.get())); | 1101 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), widget.get())); |
| 1116 | 1102 |
| 1117 // Sanity check. | 1103 // Sanity check. |
| 1118 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); | 1104 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); |
| 1119 | 1105 |
| 1120 // The |child| window's screen bounds should move along with the |viewport|. | 1106 // The |child| window's screen bounds should move along with the |viewport|. |
| 1121 OffsetBounds(viewport.get(), -100, -100); | 1107 OffsetBounds(viewport.get(), -100, -100); |
| 1122 EXPECT_EQ("-100,-100 100x100", child->GetBoundsInRootWindow().ToString()); | 1108 EXPECT_EQ("-100,-100 100x100", child->GetBoundsInRootWindow().ToString()); |
| 1123 | 1109 |
| 1124 OffsetBounds(widget.get(), 50, 50); | 1110 OffsetBounds(widget.get(), 50, 50); |
| 1125 EXPECT_EQ("-50,-50 100x100", child->GetBoundsInRootWindow().ToString()); | 1111 EXPECT_EQ("-50,-50 100x100", child->GetBoundsInRootWindow().ToString()); |
| 1126 | 1112 |
| 1127 // The |child| window is moved to the 0,0 in screen coordinates. | 1113 // The |child| window is moved to the 0,0 in screen coordinates. |
| 1128 // |GetBoundsInRootWindow()| should return 0,0. | 1114 // |GetBoundsInRootWindow()| should return 0,0. |
| 1129 OffsetBounds(child.get(), 50, 50); | 1115 OffsetBounds(child.get(), 50, 50); |
| 1130 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); | 1116 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); |
| 1131 } | 1117 } |
| 1132 | 1118 |
| 1133 TEST_F(WindowTest, GetBoundsInRootWindowWithLayersAndTranslations) { | 1119 TEST_F(WindowTest, GetBoundsInRootWindowWithLayersAndTranslations) { |
| 1134 scoped_ptr<Window> viewport( | 1120 std::unique_ptr<Window> viewport( |
| 1135 CreateTestWindowWithBounds(gfx::Rect(0, 0, 300, 300), root_window())); | 1121 CreateTestWindowWithBounds(gfx::Rect(0, 0, 300, 300), root_window())); |
| 1136 | 1122 |
| 1137 scoped_ptr<Window> widget( | 1123 std::unique_ptr<Window> widget( |
| 1138 CreateTestWindowWithBounds(gfx::Rect(0, 0, 200, 200), viewport.get())); | 1124 CreateTestWindowWithBounds(gfx::Rect(0, 0, 200, 200), viewport.get())); |
| 1139 | 1125 |
| 1140 scoped_ptr<Window> child( | 1126 std::unique_ptr<Window> child( |
| 1141 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), widget.get())); | 1127 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), widget.get())); |
| 1142 | 1128 |
| 1143 // Sanity check. | 1129 // Sanity check. |
| 1144 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); | 1130 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); |
| 1145 | 1131 |
| 1146 // The |child| window's screen bounds should move along with the |viewport|. | 1132 // The |child| window's screen bounds should move along with the |viewport|. |
| 1147 viewport->SetBounds(gfx::Rect(-100, -100, 300, 300)); | 1133 viewport->SetBounds(gfx::Rect(-100, -100, 300, 300)); |
| 1148 EXPECT_EQ("-100,-100 100x100", child->GetBoundsInRootWindow().ToString()); | 1134 EXPECT_EQ("-100,-100 100x100", child->GetBoundsInRootWindow().ToString()); |
| 1149 | 1135 |
| 1150 widget->SetBounds(gfx::Rect(50, 50, 200, 200)); | 1136 widget->SetBounds(gfx::Rect(50, 50, 200, 200)); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1206 bool entered_; | 1192 bool entered_; |
| 1207 bool exited_; | 1193 bool exited_; |
| 1208 | 1194 |
| 1209 DISALLOW_COPY_AND_ASSIGN(MouseEnterExitWindowDelegate); | 1195 DISALLOW_COPY_AND_ASSIGN(MouseEnterExitWindowDelegate); |
| 1210 }; | 1196 }; |
| 1211 | 1197 |
| 1212 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for | 1198 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for |
| 1213 // mouse transitions from window to window. | 1199 // mouse transitions from window to window. |
| 1214 TEST_F(WindowTest, MouseEnterExit) { | 1200 TEST_F(WindowTest, MouseEnterExit) { |
| 1215 MouseEnterExitWindowDelegate d1; | 1201 MouseEnterExitWindowDelegate d1; |
| 1216 scoped_ptr<Window> w1( | 1202 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1217 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), | 1203 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1218 root_window())); | |
| 1219 MouseEnterExitWindowDelegate d2; | 1204 MouseEnterExitWindowDelegate d2; |
| 1220 scoped_ptr<Window> w2( | 1205 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( |
| 1221 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50), | 1206 &d2, 2, gfx::Rect(70, 70, 50, 50), root_window())); |
| 1222 root_window())); | |
| 1223 | 1207 |
| 1224 ui::test::EventGenerator generator(root_window()); | 1208 ui::test::EventGenerator generator(root_window()); |
| 1225 generator.MoveMouseToCenterOf(w1.get()); | 1209 generator.MoveMouseToCenterOf(w1.get()); |
| 1226 EXPECT_TRUE(d1.entered()); | 1210 EXPECT_TRUE(d1.entered()); |
| 1227 EXPECT_FALSE(d1.exited()); | 1211 EXPECT_FALSE(d1.exited()); |
| 1228 EXPECT_FALSE(d2.entered()); | 1212 EXPECT_FALSE(d2.entered()); |
| 1229 EXPECT_FALSE(d2.exited()); | 1213 EXPECT_FALSE(d2.exited()); |
| 1230 | 1214 |
| 1231 generator.MoveMouseToCenterOf(w2.get()); | 1215 generator.MoveMouseToCenterOf(w2.get()); |
| 1232 EXPECT_TRUE(d1.entered()); | 1216 EXPECT_TRUE(d1.entered()); |
| 1233 EXPECT_TRUE(d1.exited()); | 1217 EXPECT_TRUE(d1.exited()); |
| 1234 EXPECT_TRUE(d2.entered()); | 1218 EXPECT_TRUE(d2.entered()); |
| 1235 EXPECT_FALSE(d2.exited()); | 1219 EXPECT_FALSE(d2.exited()); |
| 1236 } | 1220 } |
| 1237 | 1221 |
| 1238 // Verifies that the WindowDelegate receives MouseExit from ET_MOUSE_EXITED. | 1222 // Verifies that the WindowDelegate receives MouseExit from ET_MOUSE_EXITED. |
| 1239 TEST_F(WindowTest, WindowTreeHostExit) { | 1223 TEST_F(WindowTest, WindowTreeHostExit) { |
| 1240 MouseEnterExitWindowDelegate d1; | 1224 MouseEnterExitWindowDelegate d1; |
| 1241 scoped_ptr<Window> w1( | 1225 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1242 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), | 1226 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1243 root_window())); | |
| 1244 | 1227 |
| 1245 ui::test::EventGenerator generator(root_window()); | 1228 ui::test::EventGenerator generator(root_window()); |
| 1246 generator.MoveMouseToCenterOf(w1.get()); | 1229 generator.MoveMouseToCenterOf(w1.get()); |
| 1247 EXPECT_TRUE(d1.entered()); | 1230 EXPECT_TRUE(d1.entered()); |
| 1248 EXPECT_FALSE(d1.exited()); | 1231 EXPECT_FALSE(d1.exited()); |
| 1249 d1.ResetExpectations(); | 1232 d1.ResetExpectations(); |
| 1250 | 1233 |
| 1251 ui::MouseEvent exit_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), | 1234 ui::MouseEvent exit_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), |
| 1252 ui::EventTimeForNow(), 0, 0); | 1235 ui::EventTimeForNow(), 0, 0); |
| 1253 DispatchEventUsingWindowDispatcher(&exit_event); | 1236 DispatchEventUsingWindowDispatcher(&exit_event); |
| 1254 EXPECT_FALSE(d1.entered()); | 1237 EXPECT_FALSE(d1.entered()); |
| 1255 EXPECT_TRUE(d1.exited()); | 1238 EXPECT_TRUE(d1.exited()); |
| 1256 } | 1239 } |
| 1257 | 1240 |
| 1258 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for | 1241 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for |
| 1259 // mouse transitions from window to window, even if the entered window sets | 1242 // mouse transitions from window to window, even if the entered window sets |
| 1260 // and releases capture. | 1243 // and releases capture. |
| 1261 TEST_F(WindowTest, MouseEnterExitWithClick) { | 1244 TEST_F(WindowTest, MouseEnterExitWithClick) { |
| 1262 MouseEnterExitWindowDelegate d1; | 1245 MouseEnterExitWindowDelegate d1; |
| 1263 scoped_ptr<Window> w1( | 1246 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1264 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), | 1247 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1265 root_window())); | |
| 1266 MouseEnterExitWindowDelegate d2; | 1248 MouseEnterExitWindowDelegate d2; |
| 1267 scoped_ptr<Window> w2( | 1249 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( |
| 1268 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50), | 1250 &d2, 2, gfx::Rect(70, 70, 50, 50), root_window())); |
| 1269 root_window())); | |
| 1270 | 1251 |
| 1271 ui::test::EventGenerator generator(root_window()); | 1252 ui::test::EventGenerator generator(root_window()); |
| 1272 generator.MoveMouseToCenterOf(w1.get()); | 1253 generator.MoveMouseToCenterOf(w1.get()); |
| 1273 EXPECT_TRUE(d1.entered()); | 1254 EXPECT_TRUE(d1.entered()); |
| 1274 EXPECT_FALSE(d1.exited()); | 1255 EXPECT_FALSE(d1.exited()); |
| 1275 EXPECT_FALSE(d2.entered()); | 1256 EXPECT_FALSE(d2.entered()); |
| 1276 EXPECT_FALSE(d2.exited()); | 1257 EXPECT_FALSE(d2.exited()); |
| 1277 | 1258 |
| 1278 // Emmulate what Views does on a click by grabbing and releasing capture. | 1259 // Emmulate what Views does on a click by grabbing and releasing capture. |
| 1279 generator.PressLeftButton(); | 1260 generator.PressLeftButton(); |
| 1280 w1->SetCapture(); | 1261 w1->SetCapture(); |
| 1281 w1->ReleaseCapture(); | 1262 w1->ReleaseCapture(); |
| 1282 generator.ReleaseLeftButton(); | 1263 generator.ReleaseLeftButton(); |
| 1283 | 1264 |
| 1284 generator.MoveMouseToCenterOf(w2.get()); | 1265 generator.MoveMouseToCenterOf(w2.get()); |
| 1285 EXPECT_TRUE(d1.entered()); | 1266 EXPECT_TRUE(d1.entered()); |
| 1286 EXPECT_TRUE(d1.exited()); | 1267 EXPECT_TRUE(d1.exited()); |
| 1287 EXPECT_TRUE(d2.entered()); | 1268 EXPECT_TRUE(d2.entered()); |
| 1288 EXPECT_FALSE(d2.exited()); | 1269 EXPECT_FALSE(d2.exited()); |
| 1289 } | 1270 } |
| 1290 | 1271 |
| 1291 TEST_F(WindowTest, MouseEnterExitWhenDeleteWithCapture) { | 1272 TEST_F(WindowTest, MouseEnterExitWhenDeleteWithCapture) { |
| 1292 MouseEnterExitWindowDelegate delegate; | 1273 MouseEnterExitWindowDelegate delegate; |
| 1293 scoped_ptr<Window> window( | 1274 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 1294 CreateTestWindowWithDelegate(&delegate, 1, gfx::Rect(10, 10, 50, 50), | 1275 &delegate, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1295 root_window())); | |
| 1296 | 1276 |
| 1297 ui::test::EventGenerator generator(root_window()); | 1277 ui::test::EventGenerator generator(root_window()); |
| 1298 generator.MoveMouseToCenterOf(window.get()); | 1278 generator.MoveMouseToCenterOf(window.get()); |
| 1299 EXPECT_TRUE(delegate.entered()); | 1279 EXPECT_TRUE(delegate.entered()); |
| 1300 EXPECT_FALSE(delegate.exited()); | 1280 EXPECT_FALSE(delegate.exited()); |
| 1301 | 1281 |
| 1302 // Emmulate what Views does on a click by grabbing and releasing capture. | 1282 // Emmulate what Views does on a click by grabbing and releasing capture. |
| 1303 generator.PressLeftButton(); | 1283 generator.PressLeftButton(); |
| 1304 window->SetCapture(); | 1284 window->SetCapture(); |
| 1305 | 1285 |
| 1306 delegate.ResetExpectations(); | 1286 delegate.ResetExpectations(); |
| 1307 generator.MoveMouseTo(0, 0); | 1287 generator.MoveMouseTo(0, 0); |
| 1308 EXPECT_FALSE(delegate.entered()); | 1288 EXPECT_FALSE(delegate.entered()); |
| 1309 EXPECT_FALSE(delegate.exited()); | 1289 EXPECT_FALSE(delegate.exited()); |
| 1310 | 1290 |
| 1311 delegate.ResetExpectations(); | 1291 delegate.ResetExpectations(); |
| 1312 window.reset(); | 1292 window.reset(); |
| 1313 EXPECT_FALSE(delegate.entered()); | 1293 EXPECT_FALSE(delegate.entered()); |
| 1314 EXPECT_FALSE(delegate.exited()); | 1294 EXPECT_FALSE(delegate.exited()); |
| 1315 } | 1295 } |
| 1316 | 1296 |
| 1317 // Verifies that the correct enter / exits are sent if windows appear and are | 1297 // Verifies that the correct enter / exits are sent if windows appear and are |
| 1318 // deleted under the current mouse position. | 1298 // deleted under the current mouse position. |
| 1319 TEST_F(WindowTest, MouseEnterExitWithWindowAppearAndDelete) { | 1299 TEST_F(WindowTest, MouseEnterExitWithWindowAppearAndDelete) { |
| 1320 MouseEnterExitWindowDelegate d1; | 1300 MouseEnterExitWindowDelegate d1; |
| 1321 scoped_ptr<Window> w1( | 1301 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1322 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), | 1302 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1323 root_window())); | |
| 1324 | 1303 |
| 1325 // The cursor is moved into the bounds of |w1|. We expect the delegate | 1304 // The cursor is moved into the bounds of |w1|. We expect the delegate |
| 1326 // of |w1| to see an ET_MOUSE_ENTERED event. | 1305 // of |w1| to see an ET_MOUSE_ENTERED event. |
| 1327 ui::test::EventGenerator generator(root_window()); | 1306 ui::test::EventGenerator generator(root_window()); |
| 1328 generator.MoveMouseToCenterOf(w1.get()); | 1307 generator.MoveMouseToCenterOf(w1.get()); |
| 1329 EXPECT_TRUE(d1.entered()); | 1308 EXPECT_TRUE(d1.entered()); |
| 1330 EXPECT_FALSE(d1.exited()); | 1309 EXPECT_FALSE(d1.exited()); |
| 1331 d1.ResetExpectations(); | 1310 d1.ResetExpectations(); |
| 1332 | 1311 |
| 1333 MouseEnterExitWindowDelegate d2; | 1312 MouseEnterExitWindowDelegate d2; |
| 1334 { | 1313 { |
| 1335 scoped_ptr<Window> w2( | 1314 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( |
| 1336 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), | 1315 &d2, 2, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1337 root_window())); | |
| 1338 // Enters / exits can be sent asynchronously. | 1316 // Enters / exits can be sent asynchronously. |
| 1339 RunAllPendingInMessageLoop(); | 1317 RunAllPendingInMessageLoop(); |
| 1340 | 1318 |
| 1341 // |w2| appears over top of |w1|. We expect the delegate of |w1| to see | 1319 // |w2| appears over top of |w1|. We expect the delegate of |w1| to see |
| 1342 // an ET_MOUSE_EXITED and the delegate of |w2| to see an ET_MOUSE_ENTERED. | 1320 // an ET_MOUSE_EXITED and the delegate of |w2| to see an ET_MOUSE_ENTERED. |
| 1343 EXPECT_FALSE(d1.entered()); | 1321 EXPECT_FALSE(d1.entered()); |
| 1344 EXPECT_TRUE(d1.exited()); | 1322 EXPECT_TRUE(d1.exited()); |
| 1345 EXPECT_TRUE(d2.entered()); | 1323 EXPECT_TRUE(d2.entered()); |
| 1346 EXPECT_FALSE(d2.exited()); | 1324 EXPECT_FALSE(d2.exited()); |
| 1347 d1.ResetExpectations(); | 1325 d1.ResetExpectations(); |
| 1348 d2.ResetExpectations(); | 1326 d2.ResetExpectations(); |
| 1349 } | 1327 } |
| 1350 | 1328 |
| 1351 // Enters / exits can be sent asynchronously. | 1329 // Enters / exits can be sent asynchronously. |
| 1352 RunAllPendingInMessageLoop(); | 1330 RunAllPendingInMessageLoop(); |
| 1353 | 1331 |
| 1354 // |w2| has been destroyed, so its delegate should see no further events. | 1332 // |w2| has been destroyed, so its delegate should see no further events. |
| 1355 // The delegate of |w1| should see an ET_MOUSE_ENTERED event. | 1333 // The delegate of |w1| should see an ET_MOUSE_ENTERED event. |
| 1356 EXPECT_TRUE(d1.entered()); | 1334 EXPECT_TRUE(d1.entered()); |
| 1357 EXPECT_FALSE(d1.exited()); | 1335 EXPECT_FALSE(d1.exited()); |
| 1358 EXPECT_FALSE(d2.entered()); | 1336 EXPECT_FALSE(d2.entered()); |
| 1359 EXPECT_FALSE(d2.exited()); | 1337 EXPECT_FALSE(d2.exited()); |
| 1360 } | 1338 } |
| 1361 | 1339 |
| 1362 // Verifies that enter / exits are sent if windows appear and are hidden | 1340 // Verifies that enter / exits are sent if windows appear and are hidden |
| 1363 // under the current mouse position.. | 1341 // under the current mouse position.. |
| 1364 TEST_F(WindowTest, MouseEnterExitWithHide) { | 1342 TEST_F(WindowTest, MouseEnterExitWithHide) { |
| 1365 MouseEnterExitWindowDelegate d1; | 1343 MouseEnterExitWindowDelegate d1; |
| 1366 scoped_ptr<Window> w1( | 1344 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1367 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), | 1345 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1368 root_window())); | |
| 1369 | 1346 |
| 1370 ui::test::EventGenerator generator(root_window()); | 1347 ui::test::EventGenerator generator(root_window()); |
| 1371 generator.MoveMouseToCenterOf(w1.get()); | 1348 generator.MoveMouseToCenterOf(w1.get()); |
| 1372 EXPECT_TRUE(d1.entered()); | 1349 EXPECT_TRUE(d1.entered()); |
| 1373 EXPECT_FALSE(d1.exited()); | 1350 EXPECT_FALSE(d1.exited()); |
| 1374 | 1351 |
| 1375 MouseEnterExitWindowDelegate d2; | 1352 MouseEnterExitWindowDelegate d2; |
| 1376 scoped_ptr<Window> w2( | 1353 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( |
| 1377 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), | 1354 &d2, 2, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1378 root_window())); | |
| 1379 // Enters / exits can be send asynchronously. | 1355 // Enters / exits can be send asynchronously. |
| 1380 RunAllPendingInMessageLoop(); | 1356 RunAllPendingInMessageLoop(); |
| 1381 EXPECT_TRUE(d1.entered()); | 1357 EXPECT_TRUE(d1.entered()); |
| 1382 EXPECT_TRUE(d1.exited()); | 1358 EXPECT_TRUE(d1.exited()); |
| 1383 EXPECT_TRUE(d2.entered()); | 1359 EXPECT_TRUE(d2.entered()); |
| 1384 EXPECT_FALSE(d2.exited()); | 1360 EXPECT_FALSE(d2.exited()); |
| 1385 | 1361 |
| 1386 d1.ResetExpectations(); | 1362 d1.ResetExpectations(); |
| 1387 w2->Hide(); | 1363 w2->Hide(); |
| 1388 // Enters / exits can be send asynchronously. | 1364 // Enters / exits can be send asynchronously. |
| 1389 RunAllPendingInMessageLoop(); | 1365 RunAllPendingInMessageLoop(); |
| 1390 EXPECT_TRUE(d2.exited()); | 1366 EXPECT_TRUE(d2.exited()); |
| 1391 EXPECT_TRUE(d1.entered()); | 1367 EXPECT_TRUE(d1.entered()); |
| 1392 } | 1368 } |
| 1393 | 1369 |
| 1394 TEST_F(WindowTest, MouseEnterExitWithParentHide) { | 1370 TEST_F(WindowTest, MouseEnterExitWithParentHide) { |
| 1395 MouseEnterExitWindowDelegate d1; | 1371 MouseEnterExitWindowDelegate d1; |
| 1396 scoped_ptr<Window> w1( | 1372 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1397 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), | 1373 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1398 root_window())); | |
| 1399 MouseEnterExitWindowDelegate d2; | 1374 MouseEnterExitWindowDelegate d2; |
| 1400 Window* w2 = CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), | 1375 Window* w2 = CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), |
| 1401 w1.get()); | 1376 w1.get()); |
| 1402 ui::test::EventGenerator generator(root_window()); | 1377 ui::test::EventGenerator generator(root_window()); |
| 1403 generator.MoveMouseToCenterOf(w2); | 1378 generator.MoveMouseToCenterOf(w2); |
| 1404 // Enters / exits can be send asynchronously. | 1379 // Enters / exits can be send asynchronously. |
| 1405 RunAllPendingInMessageLoop(); | 1380 RunAllPendingInMessageLoop(); |
| 1406 EXPECT_TRUE(d2.entered()); | 1381 EXPECT_TRUE(d2.entered()); |
| 1407 EXPECT_FALSE(d2.exited()); | 1382 EXPECT_FALSE(d2.exited()); |
| 1408 | 1383 |
| 1409 d2.ResetExpectations(); | 1384 d2.ResetExpectations(); |
| 1410 w1->Hide(); | 1385 w1->Hide(); |
| 1411 RunAllPendingInMessageLoop(); | 1386 RunAllPendingInMessageLoop(); |
| 1412 EXPECT_FALSE(d2.entered()); | 1387 EXPECT_FALSE(d2.entered()); |
| 1413 EXPECT_TRUE(d2.exited()); | 1388 EXPECT_TRUE(d2.exited()); |
| 1414 | 1389 |
| 1415 w1.reset(); | 1390 w1.reset(); |
| 1416 } | 1391 } |
| 1417 | 1392 |
| 1418 TEST_F(WindowTest, MouseEnterExitWithParentDelete) { | 1393 TEST_F(WindowTest, MouseEnterExitWithParentDelete) { |
| 1419 MouseEnterExitWindowDelegate d1; | 1394 MouseEnterExitWindowDelegate d1; |
| 1420 scoped_ptr<Window> w1( | 1395 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1421 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), | 1396 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1422 root_window())); | |
| 1423 MouseEnterExitWindowDelegate d2; | 1397 MouseEnterExitWindowDelegate d2; |
| 1424 Window* w2 = CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), | 1398 Window* w2 = CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), |
| 1425 w1.get()); | 1399 w1.get()); |
| 1426 ui::test::EventGenerator generator(root_window()); | 1400 ui::test::EventGenerator generator(root_window()); |
| 1427 generator.MoveMouseToCenterOf(w2); | 1401 generator.MoveMouseToCenterOf(w2); |
| 1428 | 1402 |
| 1429 // Enters / exits can be send asynchronously. | 1403 // Enters / exits can be send asynchronously. |
| 1430 RunAllPendingInMessageLoop(); | 1404 RunAllPendingInMessageLoop(); |
| 1431 EXPECT_TRUE(d2.entered()); | 1405 EXPECT_TRUE(d2.entered()); |
| 1432 EXPECT_FALSE(d2.exited()); | 1406 EXPECT_FALSE(d2.exited()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1444 } | 1418 } |
| 1445 | 1419 |
| 1446 // Creates a window with a delegate (w111) that can handle events at a lower | 1420 // Creates a window with a delegate (w111) that can handle events at a lower |
| 1447 // z-index than a window without a delegate (w12). w12 is sized to fill the | 1421 // z-index than a window without a delegate (w12). w12 is sized to fill the |
| 1448 // entire bounds of the container. This test verifies that | 1422 // entire bounds of the container. This test verifies that |
| 1449 // GetEventHandlerForPoint() skips w12 even though its bounds contain the event, | 1423 // GetEventHandlerForPoint() skips w12 even though its bounds contain the event, |
| 1450 // because it has no children that can handle the event and it has no delegate | 1424 // because it has no children that can handle the event and it has no delegate |
| 1451 // allowing it to handle the event itself. | 1425 // allowing it to handle the event itself. |
| 1452 TEST_F(WindowTest, GetEventHandlerForPoint_NoDelegate) { | 1426 TEST_F(WindowTest, GetEventHandlerForPoint_NoDelegate) { |
| 1453 TestWindowDelegate d111; | 1427 TestWindowDelegate d111; |
| 1454 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1, | 1428 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1455 gfx::Rect(0, 0, 500, 500), root_window())); | 1429 NULL, 1, gfx::Rect(0, 0, 500, 500), root_window())); |
| 1456 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(NULL, 11, | 1430 std::unique_ptr<Window> w11(CreateTestWindowWithDelegate( |
| 1457 gfx::Rect(0, 0, 500, 500), w1.get())); | 1431 NULL, 11, gfx::Rect(0, 0, 500, 500), w1.get())); |
| 1458 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111, | 1432 std::unique_ptr<Window> w111(CreateTestWindowWithDelegate( |
| 1459 gfx::Rect(50, 50, 450, 450), w11.get())); | 1433 &d111, 111, gfx::Rect(50, 50, 450, 450), w11.get())); |
| 1460 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(NULL, 12, | 1434 std::unique_ptr<Window> w12(CreateTestWindowWithDelegate( |
| 1461 gfx::Rect(0, 0, 500, 500), w1.get())); | 1435 NULL, 12, gfx::Rect(0, 0, 500, 500), w1.get())); |
| 1462 | 1436 |
| 1463 gfx::Point target_point = w111->bounds().CenterPoint(); | 1437 gfx::Point target_point = w111->bounds().CenterPoint(); |
| 1464 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(target_point)); | 1438 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(target_point)); |
| 1465 } | 1439 } |
| 1466 | 1440 |
| 1467 class VisibilityWindowDelegate : public TestWindowDelegate { | 1441 class VisibilityWindowDelegate : public TestWindowDelegate { |
| 1468 public: | 1442 public: |
| 1469 VisibilityWindowDelegate() | 1443 VisibilityWindowDelegate() |
| 1470 : shown_(0), | 1444 : shown_(0), |
| 1471 hidden_(0) { | 1445 hidden_(0) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1489 int shown_; | 1463 int shown_; |
| 1490 int hidden_; | 1464 int hidden_; |
| 1491 | 1465 |
| 1492 DISALLOW_COPY_AND_ASSIGN(VisibilityWindowDelegate); | 1466 DISALLOW_COPY_AND_ASSIGN(VisibilityWindowDelegate); |
| 1493 }; | 1467 }; |
| 1494 | 1468 |
| 1495 // Verifies show/hide propagate correctly to children and the layer. | 1469 // Verifies show/hide propagate correctly to children and the layer. |
| 1496 TEST_F(WindowTest, Visibility) { | 1470 TEST_F(WindowTest, Visibility) { |
| 1497 VisibilityWindowDelegate d; | 1471 VisibilityWindowDelegate d; |
| 1498 VisibilityWindowDelegate d2; | 1472 VisibilityWindowDelegate d2; |
| 1499 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(&d, 1, gfx::Rect(), | 1473 std::unique_ptr<Window> w1( |
| 1500 root_window())); | 1474 CreateTestWindowWithDelegate(&d, 1, gfx::Rect(), root_window())); |
| 1501 scoped_ptr<Window> w2( | 1475 std::unique_ptr<Window> w2( |
| 1502 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), w1.get())); | 1476 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), w1.get())); |
| 1503 scoped_ptr<Window> w3(CreateTestWindowWithId(3, w2.get())); | 1477 std::unique_ptr<Window> w3(CreateTestWindowWithId(3, w2.get())); |
| 1504 | 1478 |
| 1505 // Create shows all the windows. | 1479 // Create shows all the windows. |
| 1506 EXPECT_TRUE(w1->IsVisible()); | 1480 EXPECT_TRUE(w1->IsVisible()); |
| 1507 EXPECT_TRUE(w2->IsVisible()); | 1481 EXPECT_TRUE(w2->IsVisible()); |
| 1508 EXPECT_TRUE(w3->IsVisible()); | 1482 EXPECT_TRUE(w3->IsVisible()); |
| 1509 EXPECT_EQ(1, d.shown()); | 1483 EXPECT_EQ(1, d.shown()); |
| 1510 | 1484 |
| 1511 d.Clear(); | 1485 d.Clear(); |
| 1512 w1->Hide(); | 1486 w1->Hide(); |
| 1513 EXPECT_FALSE(w1->IsVisible()); | 1487 EXPECT_FALSE(w1->IsVisible()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1550 w2->Show(); | 1524 w2->Show(); |
| 1551 EXPECT_EQ(0, d2.hidden()); | 1525 EXPECT_EQ(0, d2.hidden()); |
| 1552 EXPECT_EQ(1, d2.shown()); | 1526 EXPECT_EQ(1, d2.shown()); |
| 1553 } | 1527 } |
| 1554 | 1528 |
| 1555 TEST_F(WindowTest, IgnoreEventsTest) { | 1529 TEST_F(WindowTest, IgnoreEventsTest) { |
| 1556 TestWindowDelegate d11; | 1530 TestWindowDelegate d11; |
| 1557 TestWindowDelegate d12; | 1531 TestWindowDelegate d12; |
| 1558 TestWindowDelegate d111; | 1532 TestWindowDelegate d111; |
| 1559 TestWindowDelegate d121; | 1533 TestWindowDelegate d121; |
| 1560 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1, | 1534 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1561 gfx::Rect(0, 0, 500, 500), root_window())); | 1535 NULL, 1, gfx::Rect(0, 0, 500, 500), root_window())); |
| 1562 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(&d11, 11, | 1536 std::unique_ptr<Window> w11(CreateTestWindowWithDelegate( |
| 1563 gfx::Rect(0, 0, 500, 500), w1.get())); | 1537 &d11, 11, gfx::Rect(0, 0, 500, 500), w1.get())); |
| 1564 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111, | 1538 std::unique_ptr<Window> w111(CreateTestWindowWithDelegate( |
| 1565 gfx::Rect(50, 50, 450, 450), w11.get())); | 1539 &d111, 111, gfx::Rect(50, 50, 450, 450), w11.get())); |
| 1566 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(&d12, 12, | 1540 std::unique_ptr<Window> w12(CreateTestWindowWithDelegate( |
| 1567 gfx::Rect(0, 0, 500, 500), w1.get())); | 1541 &d12, 12, gfx::Rect(0, 0, 500, 500), w1.get())); |
| 1568 scoped_ptr<Window> w121(CreateTestWindowWithDelegate(&d121, 121, | 1542 std::unique_ptr<Window> w121(CreateTestWindowWithDelegate( |
| 1569 gfx::Rect(150, 150, 50, 50), w12.get())); | 1543 &d121, 121, gfx::Rect(150, 150, 50, 50), w12.get())); |
| 1570 | 1544 |
| 1571 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10))); | 1545 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10))); |
| 1572 w12->set_ignore_events(true); | 1546 w12->set_ignore_events(true); |
| 1573 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10))); | 1547 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10))); |
| 1574 w12->set_ignore_events(false); | 1548 w12->set_ignore_events(false); |
| 1575 | 1549 |
| 1576 EXPECT_EQ(w121.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1550 EXPECT_EQ(w121.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); |
| 1577 w121->set_ignore_events(true); | 1551 w121->set_ignore_events(true); |
| 1578 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1552 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); |
| 1579 w12->set_ignore_events(true); | 1553 w12->set_ignore_events(true); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1604 gfx::Screen::GetScreen()->GetDisplayNearestPoint( | 1578 gfx::Screen::GetScreen()->GetDisplayNearestPoint( |
| 1605 gfx::Point()).bounds().ToString()); | 1579 gfx::Point()).bounds().ToString()); |
| 1606 | 1580 |
| 1607 // Host size shouldn't change. | 1581 // Host size shouldn't change. |
| 1608 EXPECT_EQ(size.ToString(), host()->GetBounds().size().ToString()); | 1582 EXPECT_EQ(size.ToString(), host()->GetBounds().size().ToString()); |
| 1609 } | 1583 } |
| 1610 | 1584 |
| 1611 TEST_F(WindowTest, TransformGesture) { | 1585 TEST_F(WindowTest, TransformGesture) { |
| 1612 gfx::Size size = host()->GetBounds().size(); | 1586 gfx::Size size = host()->GetBounds().size(); |
| 1613 | 1587 |
| 1614 scoped_ptr<GestureTrackPositionDelegate> delegate( | 1588 std::unique_ptr<GestureTrackPositionDelegate> delegate( |
| 1615 new GestureTrackPositionDelegate); | 1589 new GestureTrackPositionDelegate); |
| 1616 scoped_ptr<Window> window(CreateTestWindowWithDelegate(delegate.get(), -1234, | 1590 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 1617 gfx::Rect(0, 0, 20, 20), root_window())); | 1591 delegate.get(), -1234, gfx::Rect(0, 0, 20, 20), root_window())); |
| 1618 | 1592 |
| 1619 // Rotate the root-window clock-wise 90 degrees. | 1593 // Rotate the root-window clock-wise 90 degrees. |
| 1620 gfx::Transform transform; | 1594 gfx::Transform transform; |
| 1621 transform.Translate(size.height(), 0.0); | 1595 transform.Translate(size.height(), 0.0); |
| 1622 transform.Rotate(90.0); | 1596 transform.Rotate(90.0); |
| 1623 host()->SetRootTransform(transform); | 1597 host()->SetRootTransform(transform); |
| 1624 | 1598 |
| 1625 ui::TouchEvent press( | 1599 ui::TouchEvent press( |
| 1626 ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime()); | 1600 ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime()); |
| 1627 DispatchEventUsingWindowDispatcher(&press); | 1601 DispatchEventUsingWindowDispatcher(&press); |
| 1628 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString()); | 1602 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString()); |
| 1629 } | 1603 } |
| 1630 | 1604 |
| 1631 namespace { | 1605 namespace { |
| 1632 DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2); | 1606 DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2); |
| 1633 DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish"); | 1607 DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish"); |
| 1634 } | 1608 } |
| 1635 | 1609 |
| 1636 TEST_F(WindowTest, Property) { | 1610 TEST_F(WindowTest, Property) { |
| 1637 scoped_ptr<Window> w(CreateTestWindowWithId(0, root_window())); | 1611 std::unique_ptr<Window> w(CreateTestWindowWithId(0, root_window())); |
| 1638 | 1612 |
| 1639 static const char native_prop_key[] = "fnord"; | 1613 static const char native_prop_key[] = "fnord"; |
| 1640 | 1614 |
| 1641 // Non-existent properties should return the default values. | 1615 // Non-existent properties should return the default values. |
| 1642 EXPECT_EQ(-2, w->GetProperty(kIntKey)); | 1616 EXPECT_EQ(-2, w->GetProperty(kIntKey)); |
| 1643 EXPECT_EQ(std::string("squeamish"), w->GetProperty(kStringKey)); | 1617 EXPECT_EQ(std::string("squeamish"), w->GetProperty(kStringKey)); |
| 1644 EXPECT_EQ(NULL, w->GetNativeWindowProperty(native_prop_key)); | 1618 EXPECT_EQ(NULL, w->GetNativeWindowProperty(native_prop_key)); |
| 1645 | 1619 |
| 1646 // A set property value should be returned again (even if it's the default | 1620 // A set property value should be returned again (even if it's the default |
| 1647 // value). | 1621 // value). |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1665 EXPECT_EQ(NULL, w->GetNativeWindowProperty(native_prop_key)); | 1639 EXPECT_EQ(NULL, w->GetNativeWindowProperty(native_prop_key)); |
| 1666 | 1640 |
| 1667 // ClearProperty should restore the default value. | 1641 // ClearProperty should restore the default value. |
| 1668 w->ClearProperty(kIntKey); | 1642 w->ClearProperty(kIntKey); |
| 1669 EXPECT_EQ(-2, w->GetProperty(kIntKey)); | 1643 EXPECT_EQ(-2, w->GetProperty(kIntKey)); |
| 1670 w->ClearProperty(kStringKey); | 1644 w->ClearProperty(kStringKey); |
| 1671 EXPECT_EQ(std::string("squeamish"), w->GetProperty(kStringKey)); | 1645 EXPECT_EQ(std::string("squeamish"), w->GetProperty(kStringKey)); |
| 1672 } | 1646 } |
| 1673 | 1647 |
| 1674 TEST_F(WindowTest, OwnedProperty) { | 1648 TEST_F(WindowTest, OwnedProperty) { |
| 1675 scoped_ptr<Window> w(CreateTestWindowWithId(0, root_window())); | 1649 std::unique_ptr<Window> w(CreateTestWindowWithId(0, root_window())); |
| 1676 EXPECT_EQ(NULL, w->GetProperty(kOwnedKey)); | 1650 EXPECT_EQ(NULL, w->GetProperty(kOwnedKey)); |
| 1677 TestProperty* last_deleted = TestProperty::last_deleted(); | 1651 TestProperty* last_deleted = TestProperty::last_deleted(); |
| 1678 TestProperty* p1 = new TestProperty(); | 1652 TestProperty* p1 = new TestProperty(); |
| 1679 w->SetProperty(kOwnedKey, p1); | 1653 w->SetProperty(kOwnedKey, p1); |
| 1680 EXPECT_EQ(p1, w->GetProperty(kOwnedKey)); | 1654 EXPECT_EQ(p1, w->GetProperty(kOwnedKey)); |
| 1681 EXPECT_EQ(last_deleted, TestProperty::last_deleted()); | 1655 EXPECT_EQ(last_deleted, TestProperty::last_deleted()); |
| 1682 | 1656 |
| 1683 TestProperty* p2 = new TestProperty(); | 1657 TestProperty* p2 = new TestProperty(); |
| 1684 w->SetProperty(kOwnedKey, p2); | 1658 w->SetProperty(kOwnedKey, p2); |
| 1685 EXPECT_EQ(p2, w->GetProperty(kOwnedKey)); | 1659 EXPECT_EQ(p2, w->GetProperty(kOwnedKey)); |
| 1686 EXPECT_EQ(p1, TestProperty::last_deleted()); | 1660 EXPECT_EQ(p1, TestProperty::last_deleted()); |
| 1687 | 1661 |
| 1688 w->ClearProperty(kOwnedKey); | 1662 w->ClearProperty(kOwnedKey); |
| 1689 EXPECT_EQ(NULL, w->GetProperty(kOwnedKey)); | 1663 EXPECT_EQ(NULL, w->GetProperty(kOwnedKey)); |
| 1690 EXPECT_EQ(p2, TestProperty::last_deleted()); | 1664 EXPECT_EQ(p2, TestProperty::last_deleted()); |
| 1691 | 1665 |
| 1692 TestProperty* p3 = new TestProperty(); | 1666 TestProperty* p3 = new TestProperty(); |
| 1693 w->SetProperty(kOwnedKey, p3); | 1667 w->SetProperty(kOwnedKey, p3); |
| 1694 EXPECT_EQ(p3, w->GetProperty(kOwnedKey)); | 1668 EXPECT_EQ(p3, w->GetProperty(kOwnedKey)); |
| 1695 EXPECT_EQ(p2, TestProperty::last_deleted()); | 1669 EXPECT_EQ(p2, TestProperty::last_deleted()); |
| 1696 w.reset(); | 1670 w.reset(); |
| 1697 EXPECT_EQ(p3, TestProperty::last_deleted()); | 1671 EXPECT_EQ(p3, TestProperty::last_deleted()); |
| 1698 } | 1672 } |
| 1699 | 1673 |
| 1700 TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) { | 1674 TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) { |
| 1701 // We cannot short-circuit animations in this test. | 1675 // We cannot short-circuit animations in this test. |
| 1702 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 1676 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
| 1703 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 1677 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
| 1704 | 1678 |
| 1705 scoped_ptr<Window> w1( | 1679 std::unique_ptr<Window> w1( |
| 1706 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), root_window())); | 1680 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), root_window())); |
| 1707 | 1681 |
| 1708 EXPECT_TRUE(w1->layer()); | 1682 EXPECT_TRUE(w1->layer()); |
| 1709 w1->layer()->GetAnimator()->set_disable_timer_for_test(true); | 1683 w1->layer()->GetAnimator()->set_disable_timer_for_test(true); |
| 1710 ui::LayerAnimator* animator = w1->layer()->GetAnimator(); | 1684 ui::LayerAnimator* animator = w1->layer()->GetAnimator(); |
| 1711 | 1685 |
| 1712 EXPECT_EQ("0,0 100x100", w1->bounds().ToString()); | 1686 EXPECT_EQ("0,0 100x100", w1->bounds().ToString()); |
| 1713 EXPECT_EQ("0,0 100x100", w1->layer()->GetTargetBounds().ToString()); | 1687 EXPECT_EQ("0,0 100x100", w1->layer()->GetTargetBounds().ToString()); |
| 1714 | 1688 |
| 1715 // Animate to a different position. | 1689 // Animate to a different position. |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1834 } | 1808 } |
| 1835 | 1809 |
| 1836 void OnAncestorWindowTransformed(Window* source, Window* window) override { | 1810 void OnAncestorWindowTransformed(Window* source, Window* window) override { |
| 1837 transform_notifications_.push_back( | 1811 transform_notifications_.push_back( |
| 1838 std::make_pair(source->id(), window->id())); | 1812 std::make_pair(source->id(), window->id())); |
| 1839 } | 1813 } |
| 1840 | 1814 |
| 1841 int added_count_; | 1815 int added_count_; |
| 1842 int removed_count_; | 1816 int removed_count_; |
| 1843 int destroyed_count_; | 1817 int destroyed_count_; |
| 1844 scoped_ptr<VisibilityInfo> visibility_info_; | 1818 std::unique_ptr<VisibilityInfo> visibility_info_; |
| 1845 const void* property_key_; | 1819 const void* property_key_; |
| 1846 intptr_t old_property_value_; | 1820 intptr_t old_property_value_; |
| 1847 std::vector<std::pair<int, int> > transform_notifications_; | 1821 std::vector<std::pair<int, int> > transform_notifications_; |
| 1848 | 1822 |
| 1849 DISALLOW_COPY_AND_ASSIGN(WindowObserverTest); | 1823 DISALLOW_COPY_AND_ASSIGN(WindowObserverTest); |
| 1850 }; | 1824 }; |
| 1851 | 1825 |
| 1852 // Various assertions for WindowObserver. | 1826 // Various assertions for WindowObserver. |
| 1853 TEST_F(WindowObserverTest, WindowObserver) { | 1827 TEST_F(WindowObserverTest, WindowObserver) { |
| 1854 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 1828 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 1855 w1->AddObserver(this); | 1829 w1->AddObserver(this); |
| 1856 | 1830 |
| 1857 // Create a new window as a child of w1, our observer should be notified. | 1831 // Create a new window as a child of w1, our observer should be notified. |
| 1858 scoped_ptr<Window> w2(CreateTestWindowWithId(2, w1.get())); | 1832 std::unique_ptr<Window> w2(CreateTestWindowWithId(2, w1.get())); |
| 1859 EXPECT_EQ("added=1 removed=0", WindowObserverCountStateAndClear()); | 1833 EXPECT_EQ("added=1 removed=0", WindowObserverCountStateAndClear()); |
| 1860 | 1834 |
| 1861 // Delete w2, which should result in the remove notification. | 1835 // Delete w2, which should result in the remove notification. |
| 1862 w2.reset(); | 1836 w2.reset(); |
| 1863 EXPECT_EQ("added=0 removed=1", WindowObserverCountStateAndClear()); | 1837 EXPECT_EQ("added=0 removed=1", WindowObserverCountStateAndClear()); |
| 1864 | 1838 |
| 1865 // Create a window that isn't parented to w1, we shouldn't get any | 1839 // Create a window that isn't parented to w1, we shouldn't get any |
| 1866 // notification. | 1840 // notification. |
| 1867 scoped_ptr<Window> w3(CreateTestWindowWithId(3, root_window())); | 1841 std::unique_ptr<Window> w3(CreateTestWindowWithId(3, root_window())); |
| 1868 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear()); | 1842 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear()); |
| 1869 | 1843 |
| 1870 // Similarly destroying w3 shouldn't notify us either. | 1844 // Similarly destroying w3 shouldn't notify us either. |
| 1871 w3.reset(); | 1845 w3.reset(); |
| 1872 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear()); | 1846 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear()); |
| 1873 w1->RemoveObserver(this); | 1847 w1->RemoveObserver(this); |
| 1874 } | 1848 } |
| 1875 | 1849 |
| 1876 // Test if OnWindowVisibilityChanged is invoked with expected | 1850 // Test if OnWindowVisibilityChanged is invoked with expected |
| 1877 // parameters. | 1851 // parameters. |
| 1878 TEST_F(WindowObserverTest, WindowVisibility) { | 1852 TEST_F(WindowObserverTest, WindowVisibility) { |
| 1879 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 1853 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 1880 scoped_ptr<Window> w2(CreateTestWindowWithId(1, w1.get())); | 1854 std::unique_ptr<Window> w2(CreateTestWindowWithId(1, w1.get())); |
| 1881 w2->AddObserver(this); | 1855 w2->AddObserver(this); |
| 1882 | 1856 |
| 1883 // Hide should make the window invisible and the passed visible | 1857 // Hide should make the window invisible and the passed visible |
| 1884 // parameter is false. | 1858 // parameter is false. |
| 1885 w2->Hide(); | 1859 w2->Hide(); |
| 1886 EXPECT_TRUE(GetVisibilityInfo()); | 1860 EXPECT_TRUE(GetVisibilityInfo()); |
| 1887 EXPECT_TRUE(GetVisibilityInfo()); | 1861 EXPECT_TRUE(GetVisibilityInfo()); |
| 1888 if (!GetVisibilityInfo()) | 1862 if (!GetVisibilityInfo()) |
| 1889 return; | 1863 return; |
| 1890 EXPECT_FALSE(GetVisibilityInfo()->window_visible); | 1864 EXPECT_FALSE(GetVisibilityInfo()->window_visible); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1922 w2->Hide(); | 1896 w2->Hide(); |
| 1923 EXPECT_EQ(2, GetVisibilityInfo()->changed_count); | 1897 EXPECT_EQ(2, GetVisibilityInfo()->changed_count); |
| 1924 | 1898 |
| 1925 w2->Hide(); | 1899 w2->Hide(); |
| 1926 EXPECT_EQ(2, GetVisibilityInfo()->changed_count); | 1900 EXPECT_EQ(2, GetVisibilityInfo()->changed_count); |
| 1927 } | 1901 } |
| 1928 | 1902 |
| 1929 // Test if OnWindowDestroyed is invoked as expected. | 1903 // Test if OnWindowDestroyed is invoked as expected. |
| 1930 TEST_F(WindowObserverTest, WindowDestroyed) { | 1904 TEST_F(WindowObserverTest, WindowDestroyed) { |
| 1931 // Delete a window should fire a destroyed notification. | 1905 // Delete a window should fire a destroyed notification. |
| 1932 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 1906 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 1933 w1->AddObserver(this); | 1907 w1->AddObserver(this); |
| 1934 w1.reset(); | 1908 w1.reset(); |
| 1935 EXPECT_EQ(1, DestroyedCountAndClear()); | 1909 EXPECT_EQ(1, DestroyedCountAndClear()); |
| 1936 | 1910 |
| 1937 // Observe on child and delete parent window should fire a notification. | 1911 // Observe on child and delete parent window should fire a notification. |
| 1938 scoped_ptr<Window> parent(CreateTestWindowWithId(1, root_window())); | 1912 std::unique_ptr<Window> parent(CreateTestWindowWithId(1, root_window())); |
| 1939 Window* child = CreateTestWindowWithId(1, parent.get()); // owned by parent | 1913 Window* child = CreateTestWindowWithId(1, parent.get()); // owned by parent |
| 1940 child->AddObserver(this); | 1914 child->AddObserver(this); |
| 1941 parent.reset(); | 1915 parent.reset(); |
| 1942 EXPECT_EQ(1, DestroyedCountAndClear()); | 1916 EXPECT_EQ(1, DestroyedCountAndClear()); |
| 1943 } | 1917 } |
| 1944 | 1918 |
| 1945 TEST_F(WindowObserverTest, PropertyChanged) { | 1919 TEST_F(WindowObserverTest, PropertyChanged) { |
| 1946 // Setting property should fire a property change notification. | 1920 // Setting property should fire a property change notification. |
| 1947 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 1921 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 1948 w1->AddObserver(this); | 1922 w1->AddObserver(this); |
| 1949 | 1923 |
| 1950 static const WindowProperty<int> prop = {-2}; | 1924 static const WindowProperty<int> prop = {-2}; |
| 1951 static const char native_prop_key[] = "fnord"; | 1925 static const char native_prop_key[] = "fnord"; |
| 1952 | 1926 |
| 1953 w1->SetProperty(&prop, 1); | 1927 w1->SetProperty(&prop, 1); |
| 1954 EXPECT_EQ(PropertyChangeInfo(&prop, -2), PropertyChangeInfoAndClear()); | 1928 EXPECT_EQ(PropertyChangeInfo(&prop, -2), PropertyChangeInfoAndClear()); |
| 1955 w1->SetProperty(&prop, -2); | 1929 w1->SetProperty(&prop, -2); |
| 1956 EXPECT_EQ(PropertyChangeInfo(&prop, 1), PropertyChangeInfoAndClear()); | 1930 EXPECT_EQ(PropertyChangeInfo(&prop, 1), PropertyChangeInfoAndClear()); |
| 1957 w1->SetProperty(&prop, 3); | 1931 w1->SetProperty(&prop, 3); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1974 | 1948 |
| 1975 TEST_F(WindowObserverTest, AncestorTransformed) { | 1949 TEST_F(WindowObserverTest, AncestorTransformed) { |
| 1976 // Create following window hierarchy: | 1950 // Create following window hierarchy: |
| 1977 // root_window | 1951 // root_window |
| 1978 // +-- w1 | 1952 // +-- w1 |
| 1979 // +-- w2 | 1953 // +-- w2 |
| 1980 // +-- w3 | 1954 // +-- w3 |
| 1981 // +-- w4 | 1955 // +-- w4 |
| 1982 // Then, apply a transform to |w1| and ensure all its descendants are | 1956 // Then, apply a transform to |w1| and ensure all its descendants are |
| 1983 // notified. | 1957 // notified. |
| 1984 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 1958 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 1985 w1->AddObserver(this); | 1959 w1->AddObserver(this); |
| 1986 scoped_ptr<Window> w2(CreateTestWindowWithId(2, w1.get())); | 1960 std::unique_ptr<Window> w2(CreateTestWindowWithId(2, w1.get())); |
| 1987 w2->AddObserver(this); | 1961 w2->AddObserver(this); |
| 1988 scoped_ptr<Window> w3(CreateTestWindowWithId(3, w1.get())); | 1962 std::unique_ptr<Window> w3(CreateTestWindowWithId(3, w1.get())); |
| 1989 w3->AddObserver(this); | 1963 w3->AddObserver(this); |
| 1990 scoped_ptr<Window> w4(CreateTestWindowWithId(4, w3.get())); | 1964 std::unique_ptr<Window> w4(CreateTestWindowWithId(4, w3.get())); |
| 1991 w4->AddObserver(this); | 1965 w4->AddObserver(this); |
| 1992 | 1966 |
| 1993 EXPECT_EQ(std::string(), TransformNotificationsAndClear()); | 1967 EXPECT_EQ(std::string(), TransformNotificationsAndClear()); |
| 1994 | 1968 |
| 1995 gfx::Transform transform; | 1969 gfx::Transform transform; |
| 1996 transform.Translate(10, 10); | 1970 transform.Translate(10, 10); |
| 1997 w1->SetTransform(transform); | 1971 w1->SetTransform(transform); |
| 1998 | 1972 |
| 1999 EXPECT_EQ("(1,1)(1,2)(1,3)(1,4)", TransformNotificationsAndClear()); | 1973 EXPECT_EQ("(1,1)(1,2)(1,3)(1,4)", TransformNotificationsAndClear()); |
| 2000 } | 1974 } |
| 2001 | 1975 |
| 2002 TEST_F(WindowTest, AcquireLayer) { | 1976 TEST_F(WindowTest, AcquireLayer) { |
| 2003 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window())); | 1977 std::unique_ptr<Window> window1(CreateTestWindowWithId(1, root_window())); |
| 2004 scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window())); | 1978 std::unique_ptr<Window> window2(CreateTestWindowWithId(2, root_window())); |
| 2005 ui::Layer* parent = window1->parent()->layer(); | 1979 ui::Layer* parent = window1->parent()->layer(); |
| 2006 EXPECT_EQ(2U, parent->children().size()); | 1980 EXPECT_EQ(2U, parent->children().size()); |
| 2007 | 1981 |
| 2008 WindowTestApi window1_test_api(window1.get()); | 1982 WindowTestApi window1_test_api(window1.get()); |
| 2009 WindowTestApi window2_test_api(window2.get()); | 1983 WindowTestApi window2_test_api(window2.get()); |
| 2010 | 1984 |
| 2011 EXPECT_TRUE(window1_test_api.OwnsLayer()); | 1985 EXPECT_TRUE(window1_test_api.OwnsLayer()); |
| 2012 EXPECT_TRUE(window2_test_api.OwnsLayer()); | 1986 EXPECT_TRUE(window2_test_api.OwnsLayer()); |
| 2013 | 1987 |
| 2014 // After acquisition, window1 should not own its layer, but it should still | 1988 // After acquisition, window1 should not own its layer, but it should still |
| 2015 // be available to the window. | 1989 // be available to the window. |
| 2016 scoped_ptr<ui::Layer> window1_layer(window1->AcquireLayer()); | 1990 std::unique_ptr<ui::Layer> window1_layer(window1->AcquireLayer()); |
| 2017 EXPECT_FALSE(window1_test_api.OwnsLayer()); | 1991 EXPECT_FALSE(window1_test_api.OwnsLayer()); |
| 2018 EXPECT_TRUE(window1_layer.get() == window1->layer()); | 1992 EXPECT_TRUE(window1_layer.get() == window1->layer()); |
| 2019 | 1993 |
| 2020 // The acquired layer's owner should be set NULL and re-acquring | 1994 // The acquired layer's owner should be set NULL and re-acquring |
| 2021 // should return NULL. | 1995 // should return NULL. |
| 2022 EXPECT_FALSE(window1_layer->owner()); | 1996 EXPECT_FALSE(window1_layer->owner()); |
| 2023 scoped_ptr<ui::Layer> window1_layer_reacquired(window1->AcquireLayer()); | 1997 std::unique_ptr<ui::Layer> window1_layer_reacquired(window1->AcquireLayer()); |
| 2024 EXPECT_FALSE(window1_layer_reacquired.get()); | 1998 EXPECT_FALSE(window1_layer_reacquired.get()); |
| 2025 | 1999 |
| 2026 // Upon destruction, window1's layer should still be valid, and in the layer | 2000 // Upon destruction, window1's layer should still be valid, and in the layer |
| 2027 // hierarchy, but window2's should be gone, and no longer in the hierarchy. | 2001 // hierarchy, but window2's should be gone, and no longer in the hierarchy. |
| 2028 window1.reset(); | 2002 window1.reset(); |
| 2029 window2.reset(); | 2003 window2.reset(); |
| 2030 | 2004 |
| 2031 // This should be set by the window's destructor. | 2005 // This should be set by the window's destructor. |
| 2032 EXPECT_TRUE(window1_layer->delegate() == NULL); | 2006 EXPECT_TRUE(window1_layer->delegate() == NULL); |
| 2033 EXPECT_EQ(1U, parent->children().size()); | 2007 EXPECT_EQ(1U, parent->children().size()); |
| 2034 } | 2008 } |
| 2035 | 2009 |
| 2036 // Make sure that properties which should persist from the old layer to the new | 2010 // Make sure that properties which should persist from the old layer to the new |
| 2037 // layer actually do. | 2011 // layer actually do. |
| 2038 TEST_F(WindowTest, RecreateLayer) { | 2012 TEST_F(WindowTest, RecreateLayer) { |
| 2039 // Set properties to non default values. | 2013 // Set properties to non default values. |
| 2040 gfx::Rect window_bounds(100, 100); | 2014 gfx::Rect window_bounds(100, 100); |
| 2041 Window w(new ColorTestWindowDelegate(SK_ColorWHITE)); | 2015 Window w(new ColorTestWindowDelegate(SK_ColorWHITE)); |
| 2042 w.set_id(1); | 2016 w.set_id(1); |
| 2043 w.Init(ui::LAYER_SOLID_COLOR); | 2017 w.Init(ui::LAYER_SOLID_COLOR); |
| 2044 w.SetBounds(window_bounds); | 2018 w.SetBounds(window_bounds); |
| 2045 | 2019 |
| 2046 ui::Layer* layer = w.layer(); | 2020 ui::Layer* layer = w.layer(); |
| 2047 layer->SetVisible(false); | 2021 layer->SetVisible(false); |
| 2048 layer->SetMasksToBounds(true); | 2022 layer->SetMasksToBounds(true); |
| 2049 | 2023 |
| 2050 ui::Layer child_layer; | 2024 ui::Layer child_layer; |
| 2051 layer->Add(&child_layer); | 2025 layer->Add(&child_layer); |
| 2052 | 2026 |
| 2053 scoped_ptr<ui::Layer> old_layer(w.RecreateLayer()); | 2027 std::unique_ptr<ui::Layer> old_layer(w.RecreateLayer()); |
| 2054 layer = w.layer(); | 2028 layer = w.layer(); |
| 2055 EXPECT_EQ(ui::LAYER_SOLID_COLOR, layer->type()); | 2029 EXPECT_EQ(ui::LAYER_SOLID_COLOR, layer->type()); |
| 2056 EXPECT_FALSE(layer->visible()); | 2030 EXPECT_FALSE(layer->visible()); |
| 2057 EXPECT_EQ(1u, layer->children().size()); | 2031 EXPECT_EQ(1u, layer->children().size()); |
| 2058 EXPECT_TRUE(layer->GetMasksToBounds()); | 2032 EXPECT_TRUE(layer->GetMasksToBounds()); |
| 2059 EXPECT_EQ("0,0 100x100", w.bounds().ToString()); | 2033 EXPECT_EQ("0,0 100x100", w.bounds().ToString()); |
| 2060 EXPECT_EQ("0,0 100x100", layer->bounds().ToString()); | 2034 EXPECT_EQ("0,0 100x100", layer->bounds().ToString()); |
| 2061 } | 2035 } |
| 2062 | 2036 |
| 2063 // Verify that RecreateLayer() stacks the old layer above the newly creatd | 2037 // Verify that RecreateLayer() stacks the old layer above the newly creatd |
| 2064 // layer. | 2038 // layer. |
| 2065 TEST_F(WindowTest, RecreateLayerZOrder) { | 2039 TEST_F(WindowTest, RecreateLayerZOrder) { |
| 2066 scoped_ptr<Window> w( | 2040 std::unique_ptr<Window> w(CreateTestWindow( |
| 2067 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(0, 0, 100, 100), | 2041 SK_ColorWHITE, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 2068 root_window())); | 2042 std::unique_ptr<ui::Layer> old_layer(w->RecreateLayer()); |
| 2069 scoped_ptr<ui::Layer> old_layer(w->RecreateLayer()); | |
| 2070 | 2043 |
| 2071 const std::vector<ui::Layer*>& child_layers = | 2044 const std::vector<ui::Layer*>& child_layers = |
| 2072 root_window()->layer()->children(); | 2045 root_window()->layer()->children(); |
| 2073 ASSERT_EQ(2u, child_layers.size()); | 2046 ASSERT_EQ(2u, child_layers.size()); |
| 2074 EXPECT_EQ(w->layer(), child_layers[0]); | 2047 EXPECT_EQ(w->layer(), child_layers[0]); |
| 2075 EXPECT_EQ(old_layer.get(), child_layers[1]); | 2048 EXPECT_EQ(old_layer.get(), child_layers[1]); |
| 2076 } | 2049 } |
| 2077 | 2050 |
| 2078 // Ensure that acquiring a layer then recreating a layer does not crash | 2051 // Ensure that acquiring a layer then recreating a layer does not crash |
| 2079 // and that RecreateLayer returns null. | 2052 // and that RecreateLayer returns null. |
| 2080 TEST_F(WindowTest, AcquireThenRecreateLayer) { | 2053 TEST_F(WindowTest, AcquireThenRecreateLayer) { |
| 2081 scoped_ptr<Window> w( | 2054 std::unique_ptr<Window> w(CreateTestWindow( |
| 2082 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(0, 0, 100, 100), | 2055 SK_ColorWHITE, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 2083 root_window())); | 2056 std::unique_ptr<ui::Layer> acquired_layer(w->AcquireLayer()); |
| 2084 scoped_ptr<ui::Layer> acquired_layer(w->AcquireLayer()); | 2057 std::unique_ptr<ui::Layer> doubly_acquired_layer(w->RecreateLayer()); |
| 2085 scoped_ptr<ui::Layer> doubly_acquired_layer(w->RecreateLayer()); | |
| 2086 EXPECT_EQ(NULL, doubly_acquired_layer.get()); | 2058 EXPECT_EQ(NULL, doubly_acquired_layer.get()); |
| 2087 | 2059 |
| 2088 // Destroy window before layer gets destroyed. | 2060 // Destroy window before layer gets destroyed. |
| 2089 w.reset(); | 2061 w.reset(); |
| 2090 } | 2062 } |
| 2091 | 2063 |
| 2092 class TestVisibilityClient : public client::VisibilityClient { | 2064 class TestVisibilityClient : public client::VisibilityClient { |
| 2093 public: | 2065 public: |
| 2094 explicit TestVisibilityClient(Window* root_window) | 2066 explicit TestVisibilityClient(Window* root_window) |
| 2095 : ignore_visibility_changes_(false) { | 2067 : ignore_visibility_changes_(false) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2108 } | 2080 } |
| 2109 | 2081 |
| 2110 private: | 2082 private: |
| 2111 bool ignore_visibility_changes_; | 2083 bool ignore_visibility_changes_; |
| 2112 DISALLOW_COPY_AND_ASSIGN(TestVisibilityClient); | 2084 DISALLOW_COPY_AND_ASSIGN(TestVisibilityClient); |
| 2113 }; | 2085 }; |
| 2114 | 2086 |
| 2115 TEST_F(WindowTest, VisibilityClientIsVisible) { | 2087 TEST_F(WindowTest, VisibilityClientIsVisible) { |
| 2116 TestVisibilityClient client(root_window()); | 2088 TestVisibilityClient client(root_window()); |
| 2117 | 2089 |
| 2118 scoped_ptr<Window> window(CreateTestWindowWithId(1, root_window())); | 2090 std::unique_ptr<Window> window(CreateTestWindowWithId(1, root_window())); |
| 2119 EXPECT_TRUE(window->IsVisible()); | 2091 EXPECT_TRUE(window->IsVisible()); |
| 2120 EXPECT_TRUE(window->layer()->visible()); | 2092 EXPECT_TRUE(window->layer()->visible()); |
| 2121 | 2093 |
| 2122 window->Hide(); | 2094 window->Hide(); |
| 2123 EXPECT_FALSE(window->IsVisible()); | 2095 EXPECT_FALSE(window->IsVisible()); |
| 2124 EXPECT_FALSE(window->layer()->visible()); | 2096 EXPECT_FALSE(window->layer()->visible()); |
| 2125 window->Show(); | 2097 window->Show(); |
| 2126 | 2098 |
| 2127 client.set_ignore_visibility_changes(true); | 2099 client.set_ignore_visibility_changes(true); |
| 2128 window->Hide(); | 2100 window->Hide(); |
| 2129 EXPECT_FALSE(window->IsVisible()); | 2101 EXPECT_FALSE(window->IsVisible()); |
| 2130 EXPECT_TRUE(window->layer()->visible()); | 2102 EXPECT_TRUE(window->layer()->visible()); |
| 2131 } | 2103 } |
| 2132 | 2104 |
| 2133 // Tests the mouse events seen by WindowDelegates in a Window hierarchy when | 2105 // Tests the mouse events seen by WindowDelegates in a Window hierarchy when |
| 2134 // changing the properties of a leaf Window. | 2106 // changing the properties of a leaf Window. |
| 2135 TEST_F(WindowTest, MouseEventsOnLeafWindowChange) { | 2107 TEST_F(WindowTest, MouseEventsOnLeafWindowChange) { |
| 2136 gfx::Size size = host()->GetBounds().size(); | 2108 gfx::Size size = host()->GetBounds().size(); |
| 2137 | 2109 |
| 2138 ui::test::EventGenerator generator(root_window()); | 2110 ui::test::EventGenerator generator(root_window()); |
| 2139 generator.MoveMouseTo(50, 50); | 2111 generator.MoveMouseTo(50, 50); |
| 2140 | 2112 |
| 2141 EventCountDelegate d1; | 2113 EventCountDelegate d1; |
| 2142 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(&d1, 1, | 2114 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 2143 gfx::Rect(0, 0, 100, 100), root_window())); | 2115 &d1, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 2144 RunAllPendingInMessageLoop(); | 2116 RunAllPendingInMessageLoop(); |
| 2145 // The format of result is "Enter/Move/Leave". | 2117 // The format of result is "Enter/Move/Leave". |
| 2146 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); | 2118 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); |
| 2147 | 2119 |
| 2148 // Add new window |w11| on top of |w1| which contains the cursor. | 2120 // Add new window |w11| on top of |w1| which contains the cursor. |
| 2149 EventCountDelegate d11; | 2121 EventCountDelegate d11; |
| 2150 scoped_ptr<Window> w11(CreateTestWindowWithDelegate( | 2122 std::unique_ptr<Window> w11(CreateTestWindowWithDelegate( |
| 2151 &d11, 1, gfx::Rect(0, 0, 100, 100), w1.get())); | 2123 &d11, 1, gfx::Rect(0, 0, 100, 100), w1.get())); |
| 2152 RunAllPendingInMessageLoop(); | 2124 RunAllPendingInMessageLoop(); |
| 2153 EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset()); | 2125 EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset()); |
| 2154 EXPECT_EQ("1 1 0", d11.GetMouseMotionCountsAndReset()); | 2126 EXPECT_EQ("1 1 0", d11.GetMouseMotionCountsAndReset()); |
| 2155 | 2127 |
| 2156 // Resize |w11| so that it does not contain the cursor. | 2128 // Resize |w11| so that it does not contain the cursor. |
| 2157 w11->SetBounds(gfx::Rect(0, 0, 10, 10)); | 2129 w11->SetBounds(gfx::Rect(0, 0, 10, 10)); |
| 2158 RunAllPendingInMessageLoop(); | 2130 RunAllPendingInMessageLoop(); |
| 2159 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); | 2131 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); |
| 2160 EXPECT_EQ("0 0 1", d11.GetMouseMotionCountsAndReset()); | 2132 EXPECT_EQ("0 0 1", d11.GetMouseMotionCountsAndReset()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2233 | 2205 |
| 2234 // Tests the mouse events seen by WindowDelegates in a Window hierarchy when | 2206 // Tests the mouse events seen by WindowDelegates in a Window hierarchy when |
| 2235 // deleting a non-leaf Window. | 2207 // deleting a non-leaf Window. |
| 2236 TEST_F(WindowTest, MouseEventsOnNonLeafWindowDelete) { | 2208 TEST_F(WindowTest, MouseEventsOnNonLeafWindowDelete) { |
| 2237 gfx::Size size = host()->GetBounds().size(); | 2209 gfx::Size size = host()->GetBounds().size(); |
| 2238 | 2210 |
| 2239 ui::test::EventGenerator generator(root_window()); | 2211 ui::test::EventGenerator generator(root_window()); |
| 2240 generator.MoveMouseTo(50, 50); | 2212 generator.MoveMouseTo(50, 50); |
| 2241 | 2213 |
| 2242 EventCountDelegate d1; | 2214 EventCountDelegate d1; |
| 2243 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(&d1, 1, | 2215 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 2244 gfx::Rect(0, 0, 100, 100), root_window())); | 2216 &d1, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 2245 RunAllPendingInMessageLoop(); | 2217 RunAllPendingInMessageLoop(); |
| 2246 // The format of result is "Enter/Move/Leave". | 2218 // The format of result is "Enter/Move/Leave". |
| 2247 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); | 2219 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); |
| 2248 | 2220 |
| 2249 // Add new window |w2| on top of |w1| which contains the cursor. | 2221 // Add new window |w2| on top of |w1| which contains the cursor. |
| 2250 EventCountDelegate d2; | 2222 EventCountDelegate d2; |
| 2251 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( | 2223 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( |
| 2252 &d2, 1, gfx::Rect(0, 0, 100, 100), w1.get())); | 2224 &d2, 1, gfx::Rect(0, 0, 100, 100), w1.get())); |
| 2253 RunAllPendingInMessageLoop(); | 2225 RunAllPendingInMessageLoop(); |
| 2254 EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset()); | 2226 EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset()); |
| 2255 EXPECT_EQ("1 1 0", d2.GetMouseMotionCountsAndReset()); | 2227 EXPECT_EQ("1 1 0", d2.GetMouseMotionCountsAndReset()); |
| 2256 | 2228 |
| 2257 // Add new window on top of |w2| which contains the cursor. | 2229 // Add new window on top of |w2| which contains the cursor. |
| 2258 EventCountDelegate d3; | 2230 EventCountDelegate d3; |
| 2259 CreateTestWindowWithDelegate( | 2231 CreateTestWindowWithDelegate( |
| 2260 &d3, 1, gfx::Rect(0, 0, 100, 100), w2.get()); | 2232 &d3, 1, gfx::Rect(0, 0, 100, 100), w2.get()); |
| 2261 RunAllPendingInMessageLoop(); | 2233 RunAllPendingInMessageLoop(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2297 int added_count_; | 2269 int added_count_; |
| 2298 int removed_count_; | 2270 int removed_count_; |
| 2299 | 2271 |
| 2300 DISALLOW_COPY_AND_ASSIGN(RootWindowAttachmentObserver); | 2272 DISALLOW_COPY_AND_ASSIGN(RootWindowAttachmentObserver); |
| 2301 }; | 2273 }; |
| 2302 | 2274 |
| 2303 TEST_F(WindowTest, RootWindowAttachment) { | 2275 TEST_F(WindowTest, RootWindowAttachment) { |
| 2304 RootWindowAttachmentObserver observer; | 2276 RootWindowAttachmentObserver observer; |
| 2305 | 2277 |
| 2306 // Test a direct add/remove from the RootWindow. | 2278 // Test a direct add/remove from the RootWindow. |
| 2307 scoped_ptr<Window> w1(new Window(NULL)); | 2279 std::unique_ptr<Window> w1(new Window(NULL)); |
| 2308 w1->Init(ui::LAYER_NOT_DRAWN); | 2280 w1->Init(ui::LAYER_NOT_DRAWN); |
| 2309 w1->AddObserver(&observer); | 2281 w1->AddObserver(&observer); |
| 2310 | 2282 |
| 2311 ParentWindow(w1.get()); | 2283 ParentWindow(w1.get()); |
| 2312 EXPECT_EQ(1, observer.added_count()); | 2284 EXPECT_EQ(1, observer.added_count()); |
| 2313 EXPECT_EQ(0, observer.removed_count()); | 2285 EXPECT_EQ(0, observer.removed_count()); |
| 2314 | 2286 |
| 2315 w1.reset(); | 2287 w1.reset(); |
| 2316 EXPECT_EQ(1, observer.added_count()); | 2288 EXPECT_EQ(1, observer.added_count()); |
| 2317 EXPECT_EQ(1, observer.removed_count()); | 2289 EXPECT_EQ(1, observer.removed_count()); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2418 // got reparented. | 2390 // got reparented. |
| 2419 EXPECT_EQ(new_bounds.ToString(), child.GetTargetBounds().ToString()); | 2391 EXPECT_EQ(new_bounds.ToString(), child.GetTargetBounds().ToString()); |
| 2420 EXPECT_EQ(new_bounds.ToString(), child.bounds().ToString()); | 2392 EXPECT_EQ(new_bounds.ToString(), child.bounds().ToString()); |
| 2421 EXPECT_EQ("55,55 50x50", child.GetBoundsInRootWindow().ToString()); | 2393 EXPECT_EQ("55,55 50x50", child.GetBoundsInRootWindow().ToString()); |
| 2422 } | 2394 } |
| 2423 | 2395 |
| 2424 TEST_F(WindowTest, OwnedByParentFalse) { | 2396 TEST_F(WindowTest, OwnedByParentFalse) { |
| 2425 // By default, a window is owned by its parent. If this is set to false, the | 2397 // By default, a window is owned by its parent. If this is set to false, the |
| 2426 // window will not be destroyed when its parent is. | 2398 // window will not be destroyed when its parent is. |
| 2427 | 2399 |
| 2428 scoped_ptr<Window> w1(new Window(NULL)); | 2400 std::unique_ptr<Window> w1(new Window(NULL)); |
| 2429 w1->Init(ui::LAYER_NOT_DRAWN); | 2401 w1->Init(ui::LAYER_NOT_DRAWN); |
| 2430 scoped_ptr<Window> w2(new Window(NULL)); | 2402 std::unique_ptr<Window> w2(new Window(NULL)); |
| 2431 w2->set_owned_by_parent(false); | 2403 w2->set_owned_by_parent(false); |
| 2432 w2->Init(ui::LAYER_NOT_DRAWN); | 2404 w2->Init(ui::LAYER_NOT_DRAWN); |
| 2433 w1->AddChild(w2.get()); | 2405 w1->AddChild(w2.get()); |
| 2434 | 2406 |
| 2435 w1.reset(); | 2407 w1.reset(); |
| 2436 | 2408 |
| 2437 // We should be able to deref w2 still, but its parent should now be NULL. | 2409 // We should be able to deref w2 still, but its parent should now be NULL. |
| 2438 EXPECT_EQ(NULL, w2->parent()); | 2410 EXPECT_EQ(NULL, w2->parent()); |
| 2439 } | 2411 } |
| 2440 | 2412 |
| 2441 namespace { | 2413 namespace { |
| 2442 | 2414 |
| 2443 // Used By DeleteWindowFromOnWindowDestroyed. Destroys a Window from | 2415 // Used By DeleteWindowFromOnWindowDestroyed. Destroys a Window from |
| 2444 // OnWindowDestroyed(). | 2416 // OnWindowDestroyed(). |
| 2445 class OwningWindowDelegate : public TestWindowDelegate { | 2417 class OwningWindowDelegate : public TestWindowDelegate { |
| 2446 public: | 2418 public: |
| 2447 OwningWindowDelegate() {} | 2419 OwningWindowDelegate() {} |
| 2448 | 2420 |
| 2449 void SetOwnedWindow(Window* window) { | 2421 void SetOwnedWindow(Window* window) { |
| 2450 owned_window_.reset(window); | 2422 owned_window_.reset(window); |
| 2451 } | 2423 } |
| 2452 | 2424 |
| 2453 void OnWindowDestroyed(Window* window) override { owned_window_.reset(NULL); } | 2425 void OnWindowDestroyed(Window* window) override { owned_window_.reset(NULL); } |
| 2454 | 2426 |
| 2455 private: | 2427 private: |
| 2456 scoped_ptr<Window> owned_window_; | 2428 std::unique_ptr<Window> owned_window_; |
| 2457 | 2429 |
| 2458 DISALLOW_COPY_AND_ASSIGN(OwningWindowDelegate); | 2430 DISALLOW_COPY_AND_ASSIGN(OwningWindowDelegate); |
| 2459 }; | 2431 }; |
| 2460 | 2432 |
| 2461 } // namespace | 2433 } // namespace |
| 2462 | 2434 |
| 2463 // Creates a window with two child windows. When the first child window is | 2435 // Creates a window with two child windows. When the first child window is |
| 2464 // destroyed (WindowDelegate::OnWindowDestroyed) it deletes the second child. | 2436 // destroyed (WindowDelegate::OnWindowDestroyed) it deletes the second child. |
| 2465 // This synthesizes BrowserView and the status bubble. Both are children of the | 2437 // This synthesizes BrowserView and the status bubble. Both are children of the |
| 2466 // same parent and destroying BrowserView triggers it destroying the status | 2438 // same parent and destroying BrowserView triggers it destroying the status |
| 2467 // bubble. | 2439 // bubble. |
| 2468 TEST_F(WindowTest, DeleteWindowFromOnWindowDestroyed) { | 2440 TEST_F(WindowTest, DeleteWindowFromOnWindowDestroyed) { |
| 2469 scoped_ptr<Window> parent(new Window(NULL)); | 2441 std::unique_ptr<Window> parent(new Window(NULL)); |
| 2470 parent->Init(ui::LAYER_NOT_DRAWN); | 2442 parent->Init(ui::LAYER_NOT_DRAWN); |
| 2471 OwningWindowDelegate delegate; | 2443 OwningWindowDelegate delegate; |
| 2472 Window* c1 = new Window(&delegate); | 2444 Window* c1 = new Window(&delegate); |
| 2473 c1->Init(ui::LAYER_NOT_DRAWN); | 2445 c1->Init(ui::LAYER_NOT_DRAWN); |
| 2474 parent->AddChild(c1); | 2446 parent->AddChild(c1); |
| 2475 Window* c2 = new Window(NULL); | 2447 Window* c2 = new Window(NULL); |
| 2476 c2->Init(ui::LAYER_NOT_DRAWN); | 2448 c2->Init(ui::LAYER_NOT_DRAWN); |
| 2477 parent->AddChild(c2); | 2449 parent->AddChild(c2); |
| 2478 delegate.SetOwnedWindow(c2); | 2450 delegate.SetOwnedWindow(c2); |
| 2479 parent.reset(); | 2451 parent.reset(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2509 | 2481 |
| 2510 // Verifies the delegate is notified when the actual bounds of the layer | 2482 // Verifies the delegate is notified when the actual bounds of the layer |
| 2511 // change. | 2483 // change. |
| 2512 TEST_F(WindowTest, DelegateNotifiedAsBoundsChange) { | 2484 TEST_F(WindowTest, DelegateNotifiedAsBoundsChange) { |
| 2513 BoundsChangeDelegate delegate; | 2485 BoundsChangeDelegate delegate; |
| 2514 | 2486 |
| 2515 // We cannot short-circuit animations in this test. | 2487 // We cannot short-circuit animations in this test. |
| 2516 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 2488 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
| 2517 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 2489 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
| 2518 | 2490 |
| 2519 scoped_ptr<Window> window( | 2491 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 2520 CreateTestWindowWithDelegate(&delegate, 1, | 2492 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 2521 gfx::Rect(0, 0, 100, 100), root_window())); | |
| 2522 window->layer()->GetAnimator()->set_disable_timer_for_test(true); | 2493 window->layer()->GetAnimator()->set_disable_timer_for_test(true); |
| 2523 | 2494 |
| 2524 delegate.clear_bounds_changed(); | 2495 delegate.clear_bounds_changed(); |
| 2525 | 2496 |
| 2526 // Animate to a different position. | 2497 // Animate to a different position. |
| 2527 { | 2498 { |
| 2528 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 2499 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
| 2529 window->SetBounds(gfx::Rect(100, 100, 100, 100)); | 2500 window->SetBounds(gfx::Rect(100, 100, 100, 100)); |
| 2530 } | 2501 } |
| 2531 | 2502 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2544 | 2515 |
| 2545 // Verifies the delegate is notified when the actual bounds of the layer | 2516 // Verifies the delegate is notified when the actual bounds of the layer |
| 2546 // change even when the window is not the layer's delegate | 2517 // change even when the window is not the layer's delegate |
| 2547 TEST_F(WindowTest, DelegateNotifiedAsBoundsChangeInHiddenLayer) { | 2518 TEST_F(WindowTest, DelegateNotifiedAsBoundsChangeInHiddenLayer) { |
| 2548 BoundsChangeDelegate delegate; | 2519 BoundsChangeDelegate delegate; |
| 2549 | 2520 |
| 2550 // We cannot short-circuit animations in this test. | 2521 // We cannot short-circuit animations in this test. |
| 2551 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 2522 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
| 2552 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 2523 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
| 2553 | 2524 |
| 2554 scoped_ptr<Window> window( | 2525 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 2555 CreateTestWindowWithDelegate(&delegate, 1, | 2526 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 2556 gfx::Rect(0, 0, 100, 100), root_window())); | |
| 2557 window->layer()->GetAnimator()->set_disable_timer_for_test(true); | 2527 window->layer()->GetAnimator()->set_disable_timer_for_test(true); |
| 2558 | 2528 |
| 2559 delegate.clear_bounds_changed(); | 2529 delegate.clear_bounds_changed(); |
| 2560 | 2530 |
| 2561 // Suppress paint on the window since it is hidden (should reset the layer's | 2531 // Suppress paint on the window since it is hidden (should reset the layer's |
| 2562 // delegate to NULL) | 2532 // delegate to NULL) |
| 2563 window->SuppressPaint(); | 2533 window->SuppressPaint(); |
| 2564 EXPECT_EQ(NULL, window->layer()->delegate()); | 2534 EXPECT_EQ(NULL, window->layer()->delegate()); |
| 2565 | 2535 |
| 2566 // Animate to a different position. | 2536 // Animate to a different position. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2613 int removed_count_; | 2583 int removed_count_; |
| 2614 | 2584 |
| 2615 DISALLOW_COPY_AND_ASSIGN(AddChildNotificationsObserver); | 2585 DISALLOW_COPY_AND_ASSIGN(AddChildNotificationsObserver); |
| 2616 }; | 2586 }; |
| 2617 | 2587 |
| 2618 } // namespace | 2588 } // namespace |
| 2619 | 2589 |
| 2620 // Assertions around when root window notifications are sent. | 2590 // Assertions around when root window notifications are sent. |
| 2621 TEST_F(WindowTest, AddChildNotifications) { | 2591 TEST_F(WindowTest, AddChildNotifications) { |
| 2622 AddChildNotificationsObserver observer; | 2592 AddChildNotificationsObserver observer; |
| 2623 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 2593 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 2624 scoped_ptr<Window> w2(CreateTestWindowWithId(1, root_window())); | 2594 std::unique_ptr<Window> w2(CreateTestWindowWithId(1, root_window())); |
| 2625 w2->AddObserver(&observer); | 2595 w2->AddObserver(&observer); |
| 2626 w2->Focus(); | 2596 w2->Focus(); |
| 2627 EXPECT_TRUE(w2->HasFocus()); | 2597 EXPECT_TRUE(w2->HasFocus()); |
| 2628 | 2598 |
| 2629 // Move |w2| to be a child of |w1|. | 2599 // Move |w2| to be a child of |w1|. |
| 2630 w1->AddChild(w2.get()); | 2600 w1->AddChild(w2.get()); |
| 2631 // Sine we moved in the same root, observer shouldn't be notified. | 2601 // Sine we moved in the same root, observer shouldn't be notified. |
| 2632 EXPECT_EQ("0 0", observer.CountStringAndReset()); | 2602 EXPECT_EQ("0 0", observer.CountStringAndReset()); |
| 2633 // |w2| should still have focus after moving. | 2603 // |w2| should still have focus after moving. |
| 2634 EXPECT_TRUE(w2->HasFocus()); | 2604 EXPECT_TRUE(w2->HasFocus()); |
| 2635 } | 2605 } |
| 2636 | 2606 |
| 2637 // Tests that a delegate that destroys itself when the window is destroyed does | 2607 // Tests that a delegate that destroys itself when the window is destroyed does |
| 2638 // not break. | 2608 // not break. |
| 2639 TEST_F(WindowTest, DelegateDestroysSelfOnWindowDestroy) { | 2609 TEST_F(WindowTest, DelegateDestroysSelfOnWindowDestroy) { |
| 2640 scoped_ptr<Window> w1(CreateTestWindowWithDelegate( | 2610 std::unique_ptr<Window> w1( |
| 2641 new DestroyWindowDelegate(), | 2611 CreateTestWindowWithDelegate(new DestroyWindowDelegate(), 0, |
| 2642 0, | 2612 gfx::Rect(10, 20, 30, 40), root_window())); |
| 2643 gfx::Rect(10, 20, 30, 40), | |
| 2644 root_window())); | |
| 2645 } | 2613 } |
| 2646 | 2614 |
| 2647 class HierarchyObserver : public WindowObserver { | 2615 class HierarchyObserver : public WindowObserver { |
| 2648 public: | 2616 public: |
| 2649 explicit HierarchyObserver(Window* target) : target_(target) { | 2617 explicit HierarchyObserver(Window* target) : target_(target) { |
| 2650 target_->AddObserver(this); | 2618 target_->AddObserver(this); |
| 2651 } | 2619 } |
| 2652 ~HierarchyObserver() override { target_->RemoveObserver(this); } | 2620 ~HierarchyObserver() override { target_->RemoveObserver(this); } |
| 2653 | 2621 |
| 2654 void ValidateState( | 2622 void ValidateState( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2684 | 2652 |
| 2685 DISALLOW_COPY_AND_ASSIGN(HierarchyObserver); | 2653 DISALLOW_COPY_AND_ASSIGN(HierarchyObserver); |
| 2686 }; | 2654 }; |
| 2687 | 2655 |
| 2688 // Tests hierarchy change notifications. | 2656 // Tests hierarchy change notifications. |
| 2689 TEST_F(WindowTest, OnWindowHierarchyChange) { | 2657 TEST_F(WindowTest, OnWindowHierarchyChange) { |
| 2690 { | 2658 { |
| 2691 // Simple add & remove. | 2659 // Simple add & remove. |
| 2692 HierarchyObserver oroot(root_window()); | 2660 HierarchyObserver oroot(root_window()); |
| 2693 | 2661 |
| 2694 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | 2662 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); |
| 2695 HierarchyObserver o1(w1.get()); | 2663 HierarchyObserver o1(w1.get()); |
| 2696 | 2664 |
| 2697 // Add. | 2665 // Add. |
| 2698 root_window()->AddChild(w1.get()); | 2666 root_window()->AddChild(w1.get()); |
| 2699 | 2667 |
| 2700 WindowObserver::HierarchyChangeParams params; | 2668 WindowObserver::HierarchyChangeParams params; |
| 2701 params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING; | 2669 params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING; |
| 2702 params.target = w1.get(); | 2670 params.target = w1.get(); |
| 2703 params.old_parent = NULL; | 2671 params.old_parent = NULL; |
| 2704 params.new_parent = root_window(); | 2672 params.new_parent = root_window(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2730 | 2698 |
| 2731 params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED; | 2699 params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED; |
| 2732 params.receiver = w1.get(); | 2700 params.receiver = w1.get(); |
| 2733 o1.ValidateState(1, params); | 2701 o1.ValidateState(1, params); |
| 2734 } | 2702 } |
| 2735 | 2703 |
| 2736 { | 2704 { |
| 2737 // Add & remove of hierarchy. Tests notification order per documentation in | 2705 // Add & remove of hierarchy. Tests notification order per documentation in |
| 2738 // WindowObserver. | 2706 // WindowObserver. |
| 2739 HierarchyObserver o(root_window()); | 2707 HierarchyObserver o(root_window()); |
| 2740 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | 2708 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); |
| 2741 Window* w11 = CreateTestWindowWithId(11, w1.get()); | 2709 Window* w11 = CreateTestWindowWithId(11, w1.get()); |
| 2742 w1->AddObserver(&o); | 2710 w1->AddObserver(&o); |
| 2743 w11->AddObserver(&o); | 2711 w11->AddObserver(&o); |
| 2744 | 2712 |
| 2745 // Add. | 2713 // Add. |
| 2746 root_window()->AddChild(w1.get()); | 2714 root_window()->AddChild(w1.get()); |
| 2747 | 2715 |
| 2748 // Dispatched to target first. | 2716 // Dispatched to target first. |
| 2749 int index = 0; | 2717 int index = 0; |
| 2750 WindowObserver::HierarchyChangeParams params; | 2718 WindowObserver::HierarchyChangeParams params; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2784 params.receiver = w1.get(); | 2752 params.receiver = w1.get(); |
| 2785 o.ValidateState(index++, params); | 2753 o.ValidateState(index++, params); |
| 2786 params.receiver = w11; | 2754 params.receiver = w11; |
| 2787 o.ValidateState(index++, params); | 2755 o.ValidateState(index++, params); |
| 2788 | 2756 |
| 2789 w1.reset(); | 2757 w1.reset(); |
| 2790 } | 2758 } |
| 2791 | 2759 |
| 2792 { | 2760 { |
| 2793 // Reparent. Tests notification order per documentation in WindowObserver. | 2761 // Reparent. Tests notification order per documentation in WindowObserver. |
| 2794 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 2762 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 2795 Window* w11 = CreateTestWindowWithId(11, w1.get()); | 2763 Window* w11 = CreateTestWindowWithId(11, w1.get()); |
| 2796 Window* w111 = CreateTestWindowWithId(111, w11); | 2764 Window* w111 = CreateTestWindowWithId(111, w11); |
| 2797 scoped_ptr<Window> w2(CreateTestWindowWithId(2, root_window())); | 2765 std::unique_ptr<Window> w2(CreateTestWindowWithId(2, root_window())); |
| 2798 | 2766 |
| 2799 HierarchyObserver o(root_window()); | 2767 HierarchyObserver o(root_window()); |
| 2800 w1->AddObserver(&o); | 2768 w1->AddObserver(&o); |
| 2801 w11->AddObserver(&o); | 2769 w11->AddObserver(&o); |
| 2802 w111->AddObserver(&o); | 2770 w111->AddObserver(&o); |
| 2803 w2->AddObserver(&o); | 2771 w2->AddObserver(&o); |
| 2804 | 2772 |
| 2805 w2->AddChild(w11); | 2773 w2->AddChild(w11); |
| 2806 | 2774 |
| 2807 // Dispatched to target first. | 2775 // Dispatched to target first. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2880 | 2848 |
| 2881 TEST_F(WindowTest, WindowDestroyCompletesAnimations) { | 2849 TEST_F(WindowTest, WindowDestroyCompletesAnimations) { |
| 2882 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 2850 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
| 2883 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 2851 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
| 2884 scoped_refptr<ui::LayerAnimator> animator = | 2852 scoped_refptr<ui::LayerAnimator> animator = |
| 2885 ui::LayerAnimator::CreateImplicitAnimator(); | 2853 ui::LayerAnimator::CreateImplicitAnimator(); |
| 2886 TestLayerAnimationObserver observer; | 2854 TestLayerAnimationObserver observer; |
| 2887 animator->AddObserver(&observer); | 2855 animator->AddObserver(&observer); |
| 2888 // Make sure destroying a Window completes the animation. | 2856 // Make sure destroying a Window completes the animation. |
| 2889 { | 2857 { |
| 2890 scoped_ptr<Window> window(CreateTestWindowWithId(1, root_window())); | 2858 std::unique_ptr<Window> window(CreateTestWindowWithId(1, root_window())); |
| 2891 window->layer()->SetAnimator(animator.get()); | 2859 window->layer()->SetAnimator(animator.get()); |
| 2892 | 2860 |
| 2893 gfx::Transform transform; | 2861 gfx::Transform transform; |
| 2894 transform.Scale(0.5f, 0.5f); | 2862 transform.Scale(0.5f, 0.5f); |
| 2895 window->SetTransform(transform); | 2863 window->SetTransform(transform); |
| 2896 | 2864 |
| 2897 EXPECT_TRUE(animator->is_animating()); | 2865 EXPECT_TRUE(animator->is_animating()); |
| 2898 EXPECT_FALSE(observer.animation_completed()); | 2866 EXPECT_FALSE(observer.animation_completed()); |
| 2899 } | 2867 } |
| 2900 EXPECT_TRUE(animator.get()); | 2868 EXPECT_TRUE(animator.get()); |
| 2901 EXPECT_FALSE(animator->is_animating()); | 2869 EXPECT_FALSE(animator->is_animating()); |
| 2902 EXPECT_TRUE(observer.animation_completed()); | 2870 EXPECT_TRUE(observer.animation_completed()); |
| 2903 EXPECT_FALSE(observer.animation_aborted()); | 2871 EXPECT_FALSE(observer.animation_aborted()); |
| 2904 animator->RemoveObserver(&observer); | 2872 animator->RemoveObserver(&observer); |
| 2905 observer.Reset(); | 2873 observer.Reset(); |
| 2906 | 2874 |
| 2907 animator = ui::LayerAnimator::CreateImplicitAnimator(); | 2875 animator = ui::LayerAnimator::CreateImplicitAnimator(); |
| 2908 animator->AddObserver(&observer); | 2876 animator->AddObserver(&observer); |
| 2909 ui::Layer layer; | 2877 ui::Layer layer; |
| 2910 layer.SetAnimator(animator.get()); | 2878 layer.SetAnimator(animator.get()); |
| 2911 { | 2879 { |
| 2912 scoped_ptr<Window> window(CreateTestWindowWithId(1, root_window())); | 2880 std::unique_ptr<Window> window(CreateTestWindowWithId(1, root_window())); |
| 2913 window->layer()->Add(&layer); | 2881 window->layer()->Add(&layer); |
| 2914 | 2882 |
| 2915 gfx::Transform transform; | 2883 gfx::Transform transform; |
| 2916 transform.Scale(0.5f, 0.5f); | 2884 transform.Scale(0.5f, 0.5f); |
| 2917 layer.SetTransform(transform); | 2885 layer.SetTransform(transform); |
| 2918 | 2886 |
| 2919 EXPECT_TRUE(animator->is_animating()); | 2887 EXPECT_TRUE(animator->is_animating()); |
| 2920 EXPECT_FALSE(observer.animation_completed()); | 2888 EXPECT_FALSE(observer.animation_completed()); |
| 2921 } | 2889 } |
| 2922 | 2890 |
| 2923 EXPECT_TRUE(animator.get()); | 2891 EXPECT_TRUE(animator.get()); |
| 2924 EXPECT_FALSE(animator->is_animating()); | 2892 EXPECT_FALSE(animator->is_animating()); |
| 2925 EXPECT_TRUE(observer.animation_completed()); | 2893 EXPECT_TRUE(observer.animation_completed()); |
| 2926 EXPECT_FALSE(observer.animation_aborted()); | 2894 EXPECT_FALSE(observer.animation_aborted()); |
| 2927 animator->RemoveObserver(&observer); | 2895 animator->RemoveObserver(&observer); |
| 2928 } | 2896 } |
| 2929 | 2897 |
| 2930 } // namespace test | 2898 } // namespace test |
| 2931 } // namespace aura | 2899 } // namespace aura |
| OLD | NEW |