| 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/launcher/launcher.h" |
| 8 #include "ash/screen_ash.h" |
| 7 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 8 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| 9 #include "ui/aura/display_manager.h" | 11 #include "ui/aura/display_manager.h" |
| 10 #include "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
| 11 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
| 14 #include "ui/aura/window_tracker.h" |
| 12 #include "ui/gfx/display.h" | 15 #include "ui/gfx/display.h" |
| 13 #include "ui/gfx/screen.h" | 16 #include "ui/gfx/screen.h" |
| 17 #include "ui/views/widget/widget.h" |
| 14 | 18 |
| 15 namespace ash { | 19 namespace ash { |
| 16 namespace test { | 20 namespace test { |
| 17 namespace { | 21 namespace { |
| 18 | 22 |
| 19 class TestObserver : public DisplayController::Observer { | 23 class TestObserver : public DisplayController::Observer { |
| 20 public: | 24 public: |
| 21 TestObserver() : count_(0) { | 25 TestObserver() : count_(0) { |
| 22 Shell::GetInstance()->display_controller()->AddObserver(this); | 26 Shell::GetInstance()->display_controller()->AddObserver(this); |
| 23 } | 27 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); | 146 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); |
| 143 EXPECT_EQ(1, gfx::Screen::GetNumDisplays()); | 147 EXPECT_EQ(1, gfx::Screen::GetNumDisplays()); |
| 144 | 148 |
| 145 UpdateDisplay("500x500,700x700"); | 149 UpdateDisplay("500x500,700x700"); |
| 146 EXPECT_EQ(2, observer.CountAndReset()); | 150 EXPECT_EQ(2, observer.CountAndReset()); |
| 147 ASSERT_EQ(2, gfx::Screen::GetNumDisplays()); | 151 ASSERT_EQ(2, gfx::Screen::GetNumDisplays()); |
| 148 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 152 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
| 149 EXPECT_EQ("0,500 700x700", GetSecondaryDisplay().bounds().ToString()); | 153 EXPECT_EQ("0,500 700x700", GetSecondaryDisplay().bounds().ToString()); |
| 150 } | 154 } |
| 151 | 155 |
| 156 TEST_F(DisplayControllerTest, InvertLayout) { |
| 157 EXPECT_EQ("left, 0", |
| 158 DisplayLayout(DisplayLayout::RIGHT, 0).Invert().ToString()); |
| 159 EXPECT_EQ("left, -100", |
| 160 DisplayLayout(DisplayLayout::RIGHT, 100).Invert().ToString()); |
| 161 EXPECT_EQ("left, 50", |
| 162 DisplayLayout(DisplayLayout::RIGHT, -50).Invert().ToString()); |
| 163 |
| 164 EXPECT_EQ("right, 0", |
| 165 DisplayLayout(DisplayLayout::LEFT, 0).Invert().ToString()); |
| 166 EXPECT_EQ("right, -90", |
| 167 DisplayLayout(DisplayLayout::LEFT, 90).Invert().ToString()); |
| 168 EXPECT_EQ("right, 60", |
| 169 DisplayLayout(DisplayLayout::LEFT, -60).Invert().ToString()); |
| 170 |
| 171 EXPECT_EQ("bottom, 0", |
| 172 DisplayLayout(DisplayLayout::TOP, 0).Invert().ToString()); |
| 173 EXPECT_EQ("bottom, -80", |
| 174 DisplayLayout(DisplayLayout::TOP, 80).Invert().ToString()); |
| 175 EXPECT_EQ("bottom, 70", |
| 176 DisplayLayout(DisplayLayout::TOP, -70).Invert().ToString()); |
| 177 |
| 178 EXPECT_EQ("top, 0", |
| 179 DisplayLayout(DisplayLayout::BOTTOM, 0).Invert().ToString()); |
| 180 EXPECT_EQ("top, -70", |
| 181 DisplayLayout(DisplayLayout::BOTTOM, 70).Invert().ToString()); |
| 182 EXPECT_EQ("top, 80", |
| 183 DisplayLayout(DisplayLayout::BOTTOM, -80).Invert().ToString()); |
| 184 } |
| 185 |
| 186 TEST_F(DisplayControllerTest, SwapPrimary) { |
| 187 DisplayController* display_controller = |
| 188 Shell::GetInstance()->display_controller(); |
| 189 |
| 190 UpdateDisplay("200x200,300x300"); |
| 191 gfx::Display primary_display = gfx::Screen::GetPrimaryDisplay(); |
| 192 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); |
| 193 |
| 194 std::string secondary_name = aura::Env::GetInstance()-> |
| 195 display_manager()->GetDisplayNameFor(secondary_display); |
| 196 DisplayLayout secondary_layout(DisplayLayout::RIGHT, 50); |
| 197 display_controller->SetLayoutForDisplayName(secondary_name, secondary_layout); |
| 198 |
| 199 EXPECT_NE(primary_display.id(), secondary_display.id()); |
| 200 aura::RootWindow* primary_root = |
| 201 display_controller->GetRootWindowForDisplayId(primary_display.id()); |
| 202 aura::RootWindow* secondary_root = |
| 203 display_controller->GetRootWindowForDisplayId(secondary_display.id()); |
| 204 EXPECT_NE(primary_root, secondary_root); |
| 205 aura::Window* launcher_window = |
| 206 Shell::GetInstance()->launcher()->widget()->GetNativeView(); |
| 207 EXPECT_TRUE(primary_root->Contains(launcher_window)); |
| 208 EXPECT_FALSE(secondary_root->Contains(launcher_window)); |
| 209 |
| 210 // Switch primary and secondary |
| 211 display_controller->SetPrimaryDisplay(secondary_display); |
| 212 EXPECT_EQ(secondary_display.id(), gfx::Screen::GetPrimaryDisplay().id()); |
| 213 EXPECT_EQ(primary_display.id(), ScreenAsh::GetSecondaryDisplay().id()); |
| 214 |
| 215 EXPECT_EQ( |
| 216 primary_root, |
| 217 display_controller->GetRootWindowForDisplayId(secondary_display.id())); |
| 218 EXPECT_EQ( |
| 219 secondary_root, |
| 220 display_controller->GetRootWindowForDisplayId(primary_display.id())); |
| 221 EXPECT_TRUE(primary_root->Contains(launcher_window)); |
| 222 EXPECT_FALSE(secondary_root->Contains(launcher_window)); |
| 223 |
| 224 const DisplayLayout& inverted_layout = |
| 225 display_controller->GetLayoutForDisplay(primary_display); |
| 226 |
| 227 EXPECT_EQ("left, -50", inverted_layout.ToString()); |
| 228 |
| 229 aura::WindowTracker tracker; |
| 230 tracker.Add(primary_root); |
| 231 tracker.Add(secondary_root); |
| 232 |
| 233 // Deleting 2nd display should move the primary to original primary display. |
| 234 UpdateDisplay("200x200"); |
| 235 RunAllPendingInMessageLoop(); // RootWindow is deleted in a posted task. |
| 236 EXPECT_EQ(1, gfx::Screen::GetNumDisplays()); |
| 237 EXPECT_EQ(primary_display.id(), gfx::Screen::GetPrimaryDisplay().id()); |
| 238 EXPECT_TRUE(tracker.Contains(primary_root)); |
| 239 EXPECT_FALSE(tracker.Contains(secondary_root)); |
| 240 EXPECT_TRUE(primary_root->Contains(launcher_window)); |
| 241 } |
| 242 |
| 152 } // namespace test | 243 } // namespace test |
| 153 } // namespace ash | 244 } // namespace ash |
| OLD | NEW |