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 "ash/display/display_controller.h" | 5 #include "ash/display/display_controller.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "ui/aura/display_manager.h" | 9 #include "ui/aura/display_manager.h" |
10 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
11 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
12 #include "ui/gfx/display.h" | 12 #include "ui/gfx/display.h" |
13 #include "ui/gfx/screen.h" | 13 #include "ui/gfx/screen.h" |
14 | 14 |
15 namespace ash { | 15 namespace ash { |
16 namespace test { | 16 namespace test { |
17 namespace { | 17 namespace { |
18 | 18 |
| 19 class TestObserver : public DisplayController::Observer { |
| 20 public: |
| 21 TestObserver() : count_(0) { |
| 22 Shell::GetInstance()->display_controller()->AddObserver(this); |
| 23 } |
| 24 |
| 25 virtual ~TestObserver() { |
| 26 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| 27 } |
| 28 |
| 29 virtual void OnDisplayConfigurationChanging() OVERRIDE { |
| 30 ++count_; |
| 31 } |
| 32 |
| 33 int CountAndReset() { |
| 34 int c = count_; |
| 35 count_ = 0; |
| 36 return c; |
| 37 } |
| 38 |
| 39 private: |
| 40 int count_; |
| 41 |
| 42 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
| 43 }; |
| 44 |
19 gfx::Display GetPrimaryDisplay() { | 45 gfx::Display GetPrimaryDisplay() { |
20 return gfx::Screen::GetDisplayNearestWindow( | 46 return gfx::Screen::GetDisplayNearestWindow( |
21 Shell::GetAllRootWindows()[0]); | 47 Shell::GetAllRootWindows()[0]); |
22 } | 48 } |
23 | 49 |
24 gfx::Display GetSecondaryDisplay() { | 50 gfx::Display GetSecondaryDisplay() { |
25 return gfx::Screen::GetDisplayNearestWindow( | 51 return gfx::Screen::GetDisplayNearestWindow( |
26 Shell::GetAllRootWindows()[1]); | 52 Shell::GetAllRootWindows()[1]); |
27 } | 53 } |
28 | 54 |
(...skipping 13 matching lines...) Expand all Loading... |
42 // TOD(oshima): Windows creates a window with smaller client area. | 68 // TOD(oshima): Windows creates a window with smaller client area. |
43 // Fix this and enable tests. | 69 // Fix this and enable tests. |
44 #define MAYBE_SecondaryDisplayLayout DISABLED_SecondaryDisplayLayout | 70 #define MAYBE_SecondaryDisplayLayout DISABLED_SecondaryDisplayLayout |
45 #define MAYBE_BoundsUpdated DISABLED_BoundsUpdated | 71 #define MAYBE_BoundsUpdated DISABLED_BoundsUpdated |
46 #else | 72 #else |
47 #define MAYBE_SecondaryDisplayLayout SecondaryDisplayLayout | 73 #define MAYBE_SecondaryDisplayLayout SecondaryDisplayLayout |
48 #define MAYBE_BoundsUpdated BoundsUpdated | 74 #define MAYBE_BoundsUpdated BoundsUpdated |
49 #endif | 75 #endif |
50 | 76 |
51 TEST_F(DisplayControllerTest, MAYBE_SecondaryDisplayLayout) { | 77 TEST_F(DisplayControllerTest, MAYBE_SecondaryDisplayLayout) { |
| 78 TestObserver observer; |
52 UpdateDisplay("500x500,400x400"); | 79 UpdateDisplay("500x500,400x400"); |
| 80 EXPECT_EQ(2, observer.CountAndReset()); // resize and add |
53 gfx::Display* secondary_display = | 81 gfx::Display* secondary_display = |
54 aura::Env::GetInstance()->display_manager()->GetDisplayAt(1); | 82 aura::Env::GetInstance()->display_manager()->GetDisplayAt(1); |
55 gfx::Insets insets(5, 5, 5, 5); | 83 gfx::Insets insets(5, 5, 5, 5); |
56 secondary_display->UpdateWorkAreaFromInsets(insets); | 84 secondary_display->UpdateWorkAreaFromInsets(insets); |
57 | 85 |
58 // Default layout is LEFT. | 86 // Default layout is LEFT. |
59 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 87 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
60 EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString()); | 88 EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString()); |
61 EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString()); | 89 EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString()); |
62 | 90 |
63 // Layout the secondary display to the bottom of the primary. | 91 // Layout the secondary display to the bottom of the primary. |
64 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); | 92 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); |
| 93 EXPECT_EQ(1, observer.CountAndReset()); |
65 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 94 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
66 EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString()); | 95 EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString()); |
67 EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString()); | 96 EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString()); |
68 | 97 |
69 // Layout the secondary display to the left of the primary. | 98 // Layout the secondary display to the left of the primary. |
70 SetSecondaryDisplayLayout(DisplayLayout::LEFT); | 99 SetSecondaryDisplayLayout(DisplayLayout::LEFT); |
| 100 EXPECT_EQ(1, observer.CountAndReset()); |
71 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 101 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
72 EXPECT_EQ("-400,0 400x400", GetSecondaryDisplay().bounds().ToString()); | 102 EXPECT_EQ("-400,0 400x400", GetSecondaryDisplay().bounds().ToString()); |
73 EXPECT_EQ("-395,5 390x390", GetSecondaryDisplay().work_area().ToString()); | 103 EXPECT_EQ("-395,5 390x390", GetSecondaryDisplay().work_area().ToString()); |
74 | 104 |
75 // Layout the secondary display to the top of the primary. | 105 // Layout the secondary display to the top of the primary. |
76 SetSecondaryDisplayLayout(DisplayLayout::TOP); | 106 SetSecondaryDisplayLayout(DisplayLayout::TOP); |
| 107 EXPECT_EQ(1, observer.CountAndReset()); |
77 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 108 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
78 EXPECT_EQ("0,-400 400x400", GetSecondaryDisplay().bounds().ToString()); | 109 EXPECT_EQ("0,-400 400x400", GetSecondaryDisplay().bounds().ToString()); |
79 EXPECT_EQ("5,-395 390x390", GetSecondaryDisplay().work_area().ToString()); | 110 EXPECT_EQ("5,-395 390x390", GetSecondaryDisplay().work_area().ToString()); |
80 } | 111 } |
81 | 112 |
82 TEST_F(DisplayControllerTest, MAYBE_BoundsUpdated) { | 113 TEST_F(DisplayControllerTest, MAYBE_BoundsUpdated) { |
| 114 TestObserver observer; |
83 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); | 115 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); |
84 UpdateDisplay("200x200,300x300"); | 116 UpdateDisplay("200x200,300x300"); // layout, resize and add. |
| 117 EXPECT_EQ(3, observer.CountAndReset()); |
| 118 |
85 gfx::Display* secondary_display = | 119 gfx::Display* secondary_display = |
86 aura::Env::GetInstance()->display_manager()->GetDisplayAt(1); | 120 aura::Env::GetInstance()->display_manager()->GetDisplayAt(1); |
87 gfx::Insets insets(5, 5, 5, 5); | 121 gfx::Insets insets(5, 5, 5, 5); |
88 secondary_display->UpdateWorkAreaFromInsets(insets); | 122 secondary_display->UpdateWorkAreaFromInsets(insets); |
89 | 123 |
90 EXPECT_EQ("0,0 200x200", GetPrimaryDisplay().bounds().ToString()); | 124 EXPECT_EQ("0,0 200x200", GetPrimaryDisplay().bounds().ToString()); |
91 EXPECT_EQ("0,200 300x300", GetSecondaryDisplay().bounds().ToString()); | 125 EXPECT_EQ("0,200 300x300", GetSecondaryDisplay().bounds().ToString()); |
92 EXPECT_EQ("5,205 290x290", GetSecondaryDisplay().work_area().ToString()); | 126 EXPECT_EQ("5,205 290x290", GetSecondaryDisplay().work_area().ToString()); |
93 | 127 |
94 UpdateDisplay("400x400,200x200"); | 128 UpdateDisplay("400x400,200x200"); |
| 129 EXPECT_EQ(2, observer.CountAndReset()); // two resizes |
95 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); | 130 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); |
96 EXPECT_EQ("0,400 200x200", GetSecondaryDisplay().bounds().ToString()); | 131 EXPECT_EQ("0,400 200x200", GetSecondaryDisplay().bounds().ToString()); |
97 EXPECT_EQ("5,405 190x190", GetSecondaryDisplay().work_area().ToString()); | 132 EXPECT_EQ("5,405 190x190", GetSecondaryDisplay().work_area().ToString()); |
98 | 133 |
99 UpdateDisplay("400x400,300x300"); | 134 UpdateDisplay("400x400,300x300"); |
| 135 EXPECT_EQ(1, observer.CountAndReset()); |
100 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); | 136 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); |
101 EXPECT_EQ("0,400 300x300", GetSecondaryDisplay().bounds().ToString()); | 137 EXPECT_EQ("0,400 300x300", GetSecondaryDisplay().bounds().ToString()); |
102 EXPECT_EQ("5,405 290x290", GetSecondaryDisplay().work_area().ToString()); | 138 EXPECT_EQ("5,405 290x290", GetSecondaryDisplay().work_area().ToString()); |
103 | 139 |
104 UpdateDisplay("400x400"); | 140 UpdateDisplay("400x400"); |
| 141 EXPECT_EQ(1, observer.CountAndReset()); |
105 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); | 142 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); |
106 EXPECT_EQ(1, gfx::Screen::GetNumDisplays()); | 143 EXPECT_EQ(1, gfx::Screen::GetNumDisplays()); |
107 | 144 |
108 UpdateDisplay("500x500,700x700"); | 145 UpdateDisplay("500x500,700x700"); |
| 146 EXPECT_EQ(2, observer.CountAndReset()); |
109 ASSERT_EQ(2, gfx::Screen::GetNumDisplays()); | 147 ASSERT_EQ(2, gfx::Screen::GetNumDisplays()); |
110 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 148 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
111 EXPECT_EQ("0,500 700x700", GetSecondaryDisplay().bounds().ToString()); | 149 EXPECT_EQ("0,500 700x700", GetSecondaryDisplay().bounds().ToString()); |
112 } | 150 } |
113 | 151 |
114 } // namespace test | 152 } // namespace test |
115 } // namespace ash | 153 } // namespace ash |
OLD | NEW |