| 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/display/display_manager.h" | 7 #include "ash/display/display_manager.h" |
| 8 #include "ash/launcher/launcher.h" | 8 #include "ash/launcher/launcher.h" |
| 9 #include "ash/screen_ash.h" | 9 #include "ash/screen_ash.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/test/cursor_manager_test_api.h" | 12 #include "ash/test/cursor_manager_test_api.h" |
| 13 #include "base/debug/stack_trace.h" | |
| 14 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
| 15 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
| 16 #include "ui/aura/window_tracker.h" | 15 #include "ui/aura/window_tracker.h" |
| 17 #include "ui/gfx/display.h" | 16 #include "ui/gfx/display.h" |
| 18 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
| 19 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 20 | 19 |
| 21 namespace ash { | 20 namespace ash { |
| 22 namespace test { | 21 namespace test { |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 class TestObserver : public DisplayController::Observer { | 24 class TestObserver : public DisplayController::Observer { |
| 26 public: | 25 public: |
| 27 TestObserver() : count_(0) { | 26 TestObserver() : count_(0) { |
| 28 Shell::GetInstance()->display_controller()->AddObserver(this); | 27 Shell::GetInstance()->display_controller()->AddObserver(this); |
| 29 } | 28 } |
| 30 | 29 |
| 31 virtual ~TestObserver() { | 30 virtual ~TestObserver() { |
| 32 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 31 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| 33 } | 32 } |
| 34 | 33 |
| 35 virtual void OnDisplayConfigurationChanging() OVERRIDE { | 34 virtual void OnDisplayConfigurationChanging() OVERRIDE { |
| 36 if (!count_) | |
| 37 stack_traces_.str(std::string()); | |
| 38 stack_traces_ << "=========\n"; | |
| 39 base::debug::StackTrace().OutputToStream(&stack_traces_); | |
| 40 ++count_; | 35 ++count_; |
| 41 } | 36 } |
| 42 | 37 |
| 43 int CountAndReset() { | 38 int CountAndReset() { |
| 44 int c = count_; | 39 int c = count_; |
| 45 count_ = 0; | 40 count_ = 0; |
| 46 return c; | 41 return c; |
| 47 } | 42 } |
| 48 | 43 |
| 49 std::string ToString() { | |
| 50 std::string str = stack_traces_.str(); | |
| 51 stack_traces_.str(std::string()); | |
| 52 return str; | |
| 53 } | |
| 54 | |
| 55 private: | 44 private: |
| 56 int count_; | 45 int count_; |
| 57 std::stringstream stack_traces_; | |
| 58 | 46 |
| 59 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 47 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
| 60 }; | 48 }; |
| 61 | 49 |
| 62 gfx::Display GetPrimaryDisplay() { | 50 gfx::Display GetPrimaryDisplay() { |
| 63 return Shell::GetScreen()->GetDisplayNearestWindow( | 51 return Shell::GetScreen()->GetDisplayNearestWindow( |
| 64 Shell::GetAllRootWindows()[0]); | 52 Shell::GetAllRootWindows()[0]); |
| 65 } | 53 } |
| 66 | 54 |
| 67 gfx::Display GetSecondaryDisplay() { | 55 gfx::Display GetSecondaryDisplay() { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 98 | 86 |
| 99 typedef test::AshTestBase DisplayControllerTest; | 87 typedef test::AshTestBase DisplayControllerTest; |
| 100 | 88 |
| 101 TEST_F(DisplayControllerShutdownTest, Shutdown) { | 89 TEST_F(DisplayControllerShutdownTest, Shutdown) { |
| 102 UpdateDisplay("444x333, 200x200"); | 90 UpdateDisplay("444x333, 200x200"); |
| 103 } | 91 } |
| 104 | 92 |
| 105 TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { | 93 TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { |
| 106 TestObserver observer; | 94 TestObserver observer; |
| 107 UpdateDisplay("500x500,400x400"); | 95 UpdateDisplay("500x500,400x400"); |
| 108 EXPECT_EQ(2, observer.CountAndReset()) | 96 EXPECT_EQ(2, observer.CountAndReset()); // resize and add |
| 109 << observer.ToString(); // resize and add | |
| 110 gfx::Display* secondary_display = | 97 gfx::Display* secondary_display = |
| 111 Shell::GetInstance()->display_manager()->GetDisplayAt(1); | 98 Shell::GetInstance()->display_manager()->GetDisplayAt(1); |
| 112 gfx::Insets insets(5, 5, 5, 5); | 99 gfx::Insets insets(5, 5, 5, 5); |
| 113 secondary_display->UpdateWorkAreaFromInsets(insets); | 100 secondary_display->UpdateWorkAreaFromInsets(insets); |
| 114 | 101 |
| 115 // Default layout is RIGHT. | 102 // Default layout is RIGHT. |
| 116 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()) | 103 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
| 117 << observer.ToString(); | 104 EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString()); |
| 118 EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString()) | 105 EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString()); |
| 119 << observer.ToString(); | |
| 120 EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString()) | |
| 121 << observer.ToString(); | |
| 122 | 106 |
| 123 // Layout the secondary display to the bottom of the primary. | 107 // Layout the secondary display to the bottom of the primary. |
| 124 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); | 108 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); |
| 125 EXPECT_EQ(1, observer.CountAndReset()) | 109 EXPECT_EQ(1, observer.CountAndReset()); |
| 126 << observer.ToString(); | 110 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
| 127 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()) | 111 EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString()); |
| 128 << observer.ToString(); | 112 EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString()); |
| 129 EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString()) | |
| 130 << observer.ToString(); | |
| 131 EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString()) | |
| 132 << observer.ToString(); | |
| 133 | 113 |
| 134 // Layout the secondary display to the left of the primary. | 114 // Layout the secondary display to the left of the primary. |
| 135 SetSecondaryDisplayLayout(DisplayLayout::LEFT); | 115 SetSecondaryDisplayLayout(DisplayLayout::LEFT); |
| 136 EXPECT_EQ(1, observer.CountAndReset()) | 116 EXPECT_EQ(1, observer.CountAndReset()); |
| 137 << observer.ToString(); | 117 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
| 138 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()) | 118 EXPECT_EQ("-400,0 400x400", GetSecondaryDisplay().bounds().ToString()); |
| 139 << observer.ToString(); | 119 EXPECT_EQ("-395,5 390x390", GetSecondaryDisplay().work_area().ToString()); |
| 140 EXPECT_EQ("-400,0 400x400", GetSecondaryDisplay().bounds().ToString()) | |
| 141 << observer.ToString(); | |
| 142 EXPECT_EQ("-395,5 390x390", GetSecondaryDisplay().work_area().ToString()) | |
| 143 << observer.ToString(); | |
| 144 | 120 |
| 145 // Layout the secondary display to the top of the primary. | 121 // Layout the secondary display to the top of the primary. |
| 146 SetSecondaryDisplayLayout(DisplayLayout::TOP); | 122 SetSecondaryDisplayLayout(DisplayLayout::TOP); |
| 147 EXPECT_EQ(1, observer.CountAndReset()) | 123 EXPECT_EQ(1, observer.CountAndReset()); |
| 148 << observer.ToString(); | 124 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
| 149 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()) | 125 EXPECT_EQ("0,-400 400x400", GetSecondaryDisplay().bounds().ToString()); |
| 150 << observer.ToString(); | 126 EXPECT_EQ("5,-395 390x390", GetSecondaryDisplay().work_area().ToString()); |
| 151 EXPECT_EQ("0,-400 400x400", GetSecondaryDisplay().bounds().ToString()) | |
| 152 << observer.ToString(); | |
| 153 EXPECT_EQ("5,-395 390x390", GetSecondaryDisplay().work_area().ToString()) | |
| 154 << observer.ToString(); | |
| 155 | 127 |
| 156 // Layout to the right with an offset. | 128 // Layout to the right with an offset. |
| 157 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, 300); | 129 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, 300); |
| 158 EXPECT_EQ(1, observer.CountAndReset()) | 130 EXPECT_EQ(1, observer.CountAndReset()); // resize and add |
| 159 << observer.ToString(); | 131 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
| 160 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()) | 132 EXPECT_EQ("500,300 400x400", GetSecondaryDisplay().bounds().ToString()); |
| 161 << observer.ToString(); | |
| 162 EXPECT_EQ("500,300 400x400", GetSecondaryDisplay().bounds().ToString()) | |
| 163 << observer.ToString(); | |
| 164 | 133 |
| 165 // Keep the minimum 100. | 134 // Keep the minimum 100. |
| 166 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, 490); | 135 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, 490); |
| 167 EXPECT_EQ(1, observer.CountAndReset()) | 136 EXPECT_EQ(1, observer.CountAndReset()); // resize and add |
| 168 << observer.ToString(); | 137 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
| 169 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()) | 138 EXPECT_EQ("500,400 400x400", GetSecondaryDisplay().bounds().ToString()); |
| 170 << observer.ToString(); | |
| 171 EXPECT_EQ("500,400 400x400", GetSecondaryDisplay().bounds().ToString()) | |
| 172 << observer.ToString(); | |
| 173 | 139 |
| 174 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, -400); | 140 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, -400); |
| 175 EXPECT_EQ(1, observer.CountAndReset()) | 141 EXPECT_EQ(1, observer.CountAndReset()); // resize and add |
| 176 << observer.ToString(); | 142 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
| 177 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()) | 143 EXPECT_EQ("500,-300 400x400", GetSecondaryDisplay().bounds().ToString()); |
| 178 << observer.ToString(); | |
| 179 EXPECT_EQ("500,-300 400x400", GetSecondaryDisplay().bounds().ToString()) | |
| 180 << observer.ToString(); | |
| 181 | 144 |
| 182 // Layout to the bottom with an offset. | 145 // Layout to the bottom with an offset. |
| 183 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -200); | 146 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -200); |
| 184 EXPECT_EQ(1, observer.CountAndReset()) | 147 EXPECT_EQ(1, observer.CountAndReset()); // resize and add |
| 185 << observer.ToString(); | 148 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
| 186 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()) | 149 EXPECT_EQ("-200,500 400x400", GetSecondaryDisplay().bounds().ToString()); |
| 187 << observer.ToString(); | |
| 188 EXPECT_EQ("-200,500 400x400", GetSecondaryDisplay().bounds().ToString()) | |
| 189 << observer.ToString(); | |
| 190 | 150 |
| 191 // Keep the minimum 100. | 151 // Keep the minimum 100. |
| 192 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, 490); | 152 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, 490); |
| 193 EXPECT_EQ(1, observer.CountAndReset()) | 153 EXPECT_EQ(1, observer.CountAndReset()); // resize and add |
| 194 << observer.ToString(); | 154 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
| 195 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()) | 155 EXPECT_EQ("400,500 400x400", GetSecondaryDisplay().bounds().ToString()); |
| 196 << observer.ToString(); | |
| 197 EXPECT_EQ("400,500 400x400", GetSecondaryDisplay().bounds().ToString()) | |
| 198 << observer.ToString(); | |
| 199 | 156 |
| 200 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -400); | 157 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -400); |
| 201 EXPECT_EQ(1, observer.CountAndReset()) | 158 EXPECT_EQ(1, observer.CountAndReset()); // resize and add |
| 202 << observer.ToString(); | 159 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
| 203 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()) | 160 EXPECT_EQ("-300,500 400x400", GetSecondaryDisplay().bounds().ToString()); |
| 204 << observer.ToString(); | |
| 205 EXPECT_EQ("-300,500 400x400", GetSecondaryDisplay().bounds().ToString()) | |
| 206 << observer.ToString(); | |
| 207 | 161 |
| 208 } | 162 } |
| 209 | 163 |
| 210 TEST_F(DisplayControllerTest, BoundsUpdated) { | 164 TEST_F(DisplayControllerTest, BoundsUpdated) { |
| 211 TestObserver observer; | 165 TestObserver observer; |
| 212 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); | 166 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); |
| 213 UpdateDisplay("200x200,300x300"); // layout, resize and add. | 167 UpdateDisplay("200x200,300x300"); // layout, resize and add. |
| 214 EXPECT_EQ(3, observer.CountAndReset()); | 168 EXPECT_EQ(3, observer.CountAndReset()); |
| 215 | 169 |
| 216 gfx::Display* secondary_display = | 170 gfx::Display* secondary_display = |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 UpdateDisplay("100+200-100x200,300+500-200x300"); | 521 UpdateDisplay("100+200-100x200,300+500-200x300"); |
| 568 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); | 522 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); |
| 569 EXPECT_EQ("100,200", root_windows[0]->GetHostOrigin().ToString()); | 523 EXPECT_EQ("100,200", root_windows[0]->GetHostOrigin().ToString()); |
| 570 EXPECT_EQ("100x200", root_windows[0]->GetHostSize().ToString()); | 524 EXPECT_EQ("100x200", root_windows[0]->GetHostSize().ToString()); |
| 571 EXPECT_EQ("300,500", root_windows[1]->GetHostOrigin().ToString()); | 525 EXPECT_EQ("300,500", root_windows[1]->GetHostOrigin().ToString()); |
| 572 EXPECT_EQ("200x300", root_windows[1]->GetHostSize().ToString()); | 526 EXPECT_EQ("200x300", root_windows[1]->GetHostSize().ToString()); |
| 573 } | 527 } |
| 574 | 528 |
| 575 } // namespace test | 529 } // namespace test |
| 576 } // namespace ash | 530 } // namespace ash |
| OLD | NEW |