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

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

Issue 1922783002: Move gfx::Display/Screen to display::Display/Screen in aura/events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 20 matching lines...) Expand all
31 #include "ui/aura/window_event_dispatcher.h" 31 #include "ui/aura/window_event_dispatcher.h"
32 #include "ui/aura/window_observer.h" 32 #include "ui/aura/window_observer.h"
33 #include "ui/aura/window_property.h" 33 #include "ui/aura/window_property.h"
34 #include "ui/aura/window_tree_host.h" 34 #include "ui/aura/window_tree_host.h"
35 #include "ui/base/hit_test.h" 35 #include "ui/base/hit_test.h"
36 #include "ui/compositor/layer.h" 36 #include "ui/compositor/layer.h"
37 #include "ui/compositor/layer_animation_observer.h" 37 #include "ui/compositor/layer_animation_observer.h"
38 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 38 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
39 #include "ui/compositor/scoped_layer_animation_settings.h" 39 #include "ui/compositor/scoped_layer_animation_settings.h"
40 #include "ui/compositor/test/test_layers.h" 40 #include "ui/compositor/test/test_layers.h"
41 #include "ui/display/screen.h"
41 #include "ui/events/event.h" 42 #include "ui/events/event.h"
42 #include "ui/events/event_utils.h" 43 #include "ui/events/event_utils.h"
43 #include "ui/events/gesture_detection/gesture_configuration.h" 44 #include "ui/events/gesture_detection/gesture_configuration.h"
44 #include "ui/events/keycodes/keyboard_codes.h" 45 #include "ui/events/keycodes/keyboard_codes.h"
45 #include "ui/events/test/event_generator.h" 46 #include "ui/events/test/event_generator.h"
46 #include "ui/gfx/canvas.h" 47 #include "ui/gfx/canvas.h"
47 #include "ui/gfx/geometry/vector2d.h" 48 #include "ui/gfx/geometry/vector2d.h"
48 #include "ui/gfx/screen.h"
49 #include "ui/gfx/skia_util.h" 49 #include "ui/gfx/skia_util.h"
50 50
51 DECLARE_WINDOW_PROPERTY_TYPE(const char*) 51 DECLARE_WINDOW_PROPERTY_TYPE(const char*)
52 52
53 namespace { 53 namespace {
54 54
55 enum class DeletionOrder { 55 enum class DeletionOrder {
56 LAYOUT_MANAGER_FIRST, 56 LAYOUT_MANAGER_FIRST,
57 PROPERTY_FIRST, 57 PROPERTY_FIRST,
58 UNKNOWN, 58 UNKNOWN,
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 std::unique_ptr<Window> w11( 400 std::unique_ptr<Window> w11(
401 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); 401 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get()));
402 std::unique_ptr<Window> w111( 402 std::unique_ptr<Window> w111(
403 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); 403 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get()));
404 std::unique_ptr<Window> w1111( 404 std::unique_ptr<Window> w1111(
405 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); 405 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get()));
406 406
407 Window* root = root_window(); 407 Window* root = root_window();
408 root->MoveCursorTo(gfx::Point(10, 10)); 408 root->MoveCursorTo(gfx::Point(10, 10));
409 EXPECT_EQ("10,10", 409 EXPECT_EQ("10,10",
410 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); 410 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
411 w1->MoveCursorTo(gfx::Point(10, 10)); 411 w1->MoveCursorTo(gfx::Point(10, 10));
412 EXPECT_EQ("20,20", 412 EXPECT_EQ("20,20",
413 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); 413 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
414 w11->MoveCursorTo(gfx::Point(10, 10)); 414 w11->MoveCursorTo(gfx::Point(10, 10));
415 EXPECT_EQ("25,25", 415 EXPECT_EQ("25,25",
416 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); 416 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
417 w111->MoveCursorTo(gfx::Point(10, 10)); 417 w111->MoveCursorTo(gfx::Point(10, 10));
418 EXPECT_EQ("30,30", 418 EXPECT_EQ("30,30",
419 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); 419 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
420 w1111->MoveCursorTo(gfx::Point(10, 10)); 420 w1111->MoveCursorTo(gfx::Point(10, 10));
421 EXPECT_EQ("35,35", 421 EXPECT_EQ("35,35",
422 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); 422 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
423 } 423 }
424 424
425 TEST_F(WindowTest, ContainsMouse) { 425 TEST_F(WindowTest, ContainsMouse) {
426 std::unique_ptr<Window> w(CreateTestWindow( 426 std::unique_ptr<Window> w(CreateTestWindow(
427 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); 427 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window()));
428 w->Show(); 428 w->Show();
429 WindowTestApi w_test_api(w.get()); 429 WindowTestApi w_test_api(w.get());
430 Window* root = root_window(); 430 Window* root = root_window();
431 root->MoveCursorTo(gfx::Point(10, 10)); 431 root->MoveCursorTo(gfx::Point(10, 10));
432 EXPECT_TRUE(w_test_api.ContainsMouse()); 432 EXPECT_TRUE(w_test_api.ContainsMouse());
433 root->MoveCursorTo(gfx::Point(9, 10)); 433 root->MoveCursorTo(gfx::Point(9, 10));
434 EXPECT_FALSE(w_test_api.ContainsMouse()); 434 EXPECT_FALSE(w_test_api.ContainsMouse());
435 } 435 }
436 436
437 // Test Window::ConvertPointToWindow() with transform to root_window. 437 // Test Window::ConvertPointToWindow() with transform to root_window.
438 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { 438 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) {
439 gfx::Transform transform; 439 gfx::Transform transform;
440 transform.Translate(100.0, 100.0); 440 transform.Translate(100.0, 100.0);
441 transform.Rotate(90.0); 441 transform.Rotate(90.0);
442 transform.Scale(2.0, 5.0); 442 transform.Scale(2.0, 5.0);
443 host()->SetRootTransform(transform); 443 host()->SetRootTransform(transform);
444 host()->MoveCursorTo(gfx::Point(10, 10)); 444 host()->MoveCursorTo(gfx::Point(10, 10));
445 #if !defined(OS_WIN) 445 #if !defined(OS_WIN)
446 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD 446 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD
447 EXPECT_EQ("50,120", QueryLatestMousePositionRequestInHost(host()).ToString()); 447 EXPECT_EQ("50,120", QueryLatestMousePositionRequestInHost(host()).ToString());
448 #endif 448 #endif
449 EXPECT_EQ("10,10", 449 EXPECT_EQ("10,10",
450 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); 450 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
451 } 451 }
452 452
453 // Tests Window::ConvertPointToWindow() with transform to non-root windows. 453 // Tests Window::ConvertPointToWindow() with transform to non-root windows.
454 TEST_F(WindowTest, MoveCursorToWithTransformWindow) { 454 TEST_F(WindowTest, MoveCursorToWithTransformWindow) {
455 std::unique_ptr<Window> w1(CreateTestWindow( 455 std::unique_ptr<Window> w1(CreateTestWindow(
456 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); 456 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window()));
457 457
458 gfx::Transform transform1; 458 gfx::Transform transform1;
459 transform1.Scale(2, 2); 459 transform1.Scale(2, 2);
460 w1->SetTransform(transform1); 460 w1->SetTransform(transform1);
461 w1->MoveCursorTo(gfx::Point(10, 10)); 461 w1->MoveCursorTo(gfx::Point(10, 10));
462 EXPECT_EQ("30,30", 462 EXPECT_EQ("30,30",
463 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); 463 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
464 464
465 gfx::Transform transform2; 465 gfx::Transform transform2;
466 transform2.Translate(-10, 20); 466 transform2.Translate(-10, 20);
467 w1->SetTransform(transform2); 467 w1->SetTransform(transform2);
468 w1->MoveCursorTo(gfx::Point(10, 10)); 468 w1->MoveCursorTo(gfx::Point(10, 10));
469 EXPECT_EQ("10,40", 469 EXPECT_EQ("10,40",
470 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); 470 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
471 471
472 gfx::Transform transform3; 472 gfx::Transform transform3;
473 transform3.Rotate(90.0); 473 transform3.Rotate(90.0);
474 w1->SetTransform(transform3); 474 w1->SetTransform(transform3);
475 w1->MoveCursorTo(gfx::Point(5, 5)); 475 w1->MoveCursorTo(gfx::Point(5, 5));
476 EXPECT_EQ("5,15", 476 EXPECT_EQ("5,15",
477 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); 477 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
478 478
479 gfx::Transform transform4; 479 gfx::Transform transform4;
480 transform4.Translate(100.0, 100.0); 480 transform4.Translate(100.0, 100.0);
481 transform4.Rotate(90.0); 481 transform4.Rotate(90.0);
482 transform4.Scale(2.0, 5.0); 482 transform4.Scale(2.0, 5.0);
483 w1->SetTransform(transform4); 483 w1->SetTransform(transform4);
484 w1->MoveCursorTo(gfx::Point(10, 10)); 484 w1->MoveCursorTo(gfx::Point(10, 10));
485 EXPECT_EQ("60,130", 485 EXPECT_EQ("60,130",
486 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); 486 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
487 } 487 }
488 488
489 // Test Window::ConvertPointToWindow() with complex transforms to both root and 489 // Test Window::ConvertPointToWindow() with complex transforms to both root and
490 // non-root windows. 490 // non-root windows.
491 // Test Window::ConvertPointToWindow() with transform to root_window. 491 // Test Window::ConvertPointToWindow() with transform to root_window.
492 TEST_F(WindowTest, MoveCursorToWithComplexTransform) { 492 TEST_F(WindowTest, MoveCursorToWithComplexTransform) {
493 std::unique_ptr<Window> w1(CreateTestWindow( 493 std::unique_ptr<Window> w1(CreateTestWindow(
494 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); 494 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window()));
495 std::unique_ptr<Window> w11( 495 std::unique_ptr<Window> w11(
496 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); 496 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get()));
(...skipping 19 matching lines...) Expand all
516 w111->SetTransform(transform); 516 w111->SetTransform(transform);
517 w1111->SetTransform(transform); 517 w1111->SetTransform(transform);
518 518
519 w1111->MoveCursorTo(gfx::Point(10, 10)); 519 w1111->MoveCursorTo(gfx::Point(10, 10));
520 520
521 #if !defined(OS_WIN) 521 #if !defined(OS_WIN)
522 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413. 522 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.
523 EXPECT_EQ("169,80", QueryLatestMousePositionRequestInHost(host()).ToString()); 523 EXPECT_EQ("169,80", QueryLatestMousePositionRequestInHost(host()).ToString());
524 #endif 524 #endif
525 EXPECT_EQ("20,53", 525 EXPECT_EQ("20,53",
526 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); 526 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
527 } 527 }
528 528
529 // Tests that we do not crash when a Window is destroyed by going out of 529 // Tests that we do not crash when a Window is destroyed by going out of
530 // scope (as opposed to being explicitly deleted by its WindowDelegate). 530 // scope (as opposed to being explicitly deleted by its WindowDelegate).
531 TEST_F(WindowTest, NoCrashOnWindowDelete) { 531 TEST_F(WindowTest, NoCrashOnWindowDelete) {
532 CaptureWindowDelegateImpl delegate; 532 CaptureWindowDelegateImpl delegate;
533 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( 533 std::unique_ptr<Window> window(CreateTestWindowWithDelegate(
534 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); 534 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window()));
535 } 535 }
536 536
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); 1604 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160)));
1605 w12->set_ignore_events(true); 1605 w12->set_ignore_events(true);
1606 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); 1606 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160)));
1607 w111->set_ignore_events(true); 1607 w111->set_ignore_events(true);
1608 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); 1608 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160)));
1609 } 1609 }
1610 1610
1611 // Tests transformation on the root window. 1611 // Tests transformation on the root window.
1612 TEST_F(WindowTest, Transform) { 1612 TEST_F(WindowTest, Transform) {
1613 gfx::Size size = host()->GetBounds().size(); 1613 gfx::Size size = host()->GetBounds().size();
1614 EXPECT_EQ(gfx::Rect(size), 1614 EXPECT_EQ(gfx::Rect(size), display::Screen::GetScreen()
1615 gfx::Screen::GetScreen()->GetDisplayNearestPoint( 1615 ->GetDisplayNearestPoint(gfx::Point())
1616 gfx::Point()).bounds()); 1616 .bounds());
1617 1617
1618 // Rotate it clock-wise 90 degrees. 1618 // Rotate it clock-wise 90 degrees.
1619 gfx::Transform transform; 1619 gfx::Transform transform;
1620 transform.Translate(size.height(), 0); 1620 transform.Translate(size.height(), 0);
1621 transform.Rotate(90.0); 1621 transform.Rotate(90.0);
1622 host()->SetRootTransform(transform); 1622 host()->SetRootTransform(transform);
1623 1623
1624 // The size should be the transformed size. 1624 // The size should be the transformed size.
1625 gfx::Size transformed_size(size.height(), size.width()); 1625 gfx::Size transformed_size(size.height(), size.width());
1626 EXPECT_EQ(transformed_size.ToString(), 1626 EXPECT_EQ(transformed_size.ToString(),
1627 root_window()->bounds().size().ToString()); 1627 root_window()->bounds().size().ToString());
1628 EXPECT_EQ( 1628 EXPECT_EQ(gfx::Rect(transformed_size).ToString(),
1629 gfx::Rect(transformed_size).ToString(), 1629 display::Screen::GetScreen()
1630 gfx::Screen::GetScreen()->GetDisplayNearestPoint( 1630 ->GetDisplayNearestPoint(gfx::Point())
1631 gfx::Point()).bounds().ToString()); 1631 .bounds()
1632 .ToString());
1632 1633
1633 // Host size shouldn't change. 1634 // Host size shouldn't change.
1634 EXPECT_EQ(size.ToString(), host()->GetBounds().size().ToString()); 1635 EXPECT_EQ(size.ToString(), host()->GetBounds().size().ToString());
1635 } 1636 }
1636 1637
1637 TEST_F(WindowTest, TransformGesture) { 1638 TEST_F(WindowTest, TransformGesture) {
1638 gfx::Size size = host()->GetBounds().size(); 1639 gfx::Size size = host()->GetBounds().size();
1639 1640
1640 std::unique_ptr<GestureTrackPositionDelegate> delegate( 1641 std::unique_ptr<GestureTrackPositionDelegate> delegate(
1641 new GestureTrackPositionDelegate); 1642 new GestureTrackPositionDelegate);
(...skipping 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after
2980 2981
2981 EXPECT_TRUE(animator.get()); 2982 EXPECT_TRUE(animator.get());
2982 EXPECT_FALSE(animator->is_animating()); 2983 EXPECT_FALSE(animator->is_animating());
2983 EXPECT_TRUE(observer.animation_completed()); 2984 EXPECT_TRUE(observer.animation_completed());
2984 EXPECT_FALSE(observer.animation_aborted()); 2985 EXPECT_FALSE(observer.animation_aborted());
2985 animator->RemoveObserver(&observer); 2986 animator->RemoveObserver(&observer);
2986 } 2987 }
2987 2988
2988 } // namespace test 2989 } // namespace test
2989 } // namespace aura 2990 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698