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/multi_display_manager.h" | 5 #include "ash/display/multi_display_manager.h" |
6 | 6 |
| 7 #include "ash/display/display_controller.h" |
7 #include "ash/shell.h" | 8 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
9 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
10 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
11 #include "ui/aura/display_observer.h" | 12 #include "ui/aura/display_observer.h" |
12 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
13 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
14 #include "ui/aura/window_observer.h" | 15 #include "ui/aura/window_observer.h" |
15 #include "ui/gfx/display.h" | 16 #include "ui/gfx/display.h" |
16 | 17 |
17 namespace ash { | 18 namespace ash { |
18 namespace test { | 19 namespace test { |
19 | 20 |
20 using std::vector; | 21 using std::vector; |
21 using std::string; | 22 using std::string; |
22 | 23 |
23 class MultiDisplayManagerTest : public test::AshTestBase, | 24 class MultiDisplayManagerTest : public test::AshTestBase, |
24 public aura::DisplayObserver, | 25 public aura::DisplayObserver, |
25 public aura::WindowObserver { | 26 public aura::WindowObserver { |
26 public: | 27 public: |
27 MultiDisplayManagerTest() | 28 MultiDisplayManagerTest() |
28 : removed_count_(0U), | 29 : removed_count_(0U), |
29 root_window_destroyed_(false) { | 30 root_window_destroyed_(false) { |
30 } | 31 } |
31 virtual ~MultiDisplayManagerTest() {} | 32 virtual ~MultiDisplayManagerTest() {} |
32 | 33 |
33 virtual void SetUp() OVERRIDE { | 34 virtual void SetUp() OVERRIDE { |
| 35 internal::DisplayController::SetExtendedDesktopEnabled(true); |
34 AshTestBase::SetUp(); | 36 AshTestBase::SetUp(); |
35 display_manager()->AddObserver(this); | 37 display_manager()->AddObserver(this); |
36 Shell::GetPrimaryRootWindow()->AddObserver(this); | 38 Shell::GetPrimaryRootWindow()->AddObserver(this); |
37 } | 39 } |
38 virtual void TearDown() OVERRIDE { | 40 virtual void TearDown() OVERRIDE { |
39 Shell::GetPrimaryRootWindow()->RemoveObserver(this); | 41 Shell::GetPrimaryRootWindow()->RemoveObserver(this); |
40 display_manager()->RemoveObserver(this); | 42 display_manager()->RemoveObserver(this); |
41 AshTestBase::TearDown(); | 43 AshTestBase::TearDown(); |
| 44 internal::DisplayController::SetExtendedDesktopEnabled(false); |
42 } | 45 } |
43 | 46 |
44 aura::DisplayManager* display_manager() { | 47 aura::DisplayManager* display_manager() { |
45 return aura::Env::GetInstance()->display_manager(); | 48 return aura::Env::GetInstance()->display_manager(); |
46 } | 49 } |
47 const vector<gfx::Display>& changed() const { return changed_; } | 50 const vector<gfx::Display>& changed() const { return changed_; } |
48 const vector<gfx::Display>& added() const { return added_; } | 51 const vector<gfx::Display>& added() const { return added_; } |
49 | 52 |
50 string GetCountSummary() const { | 53 string GetCountSummary() const { |
51 return StringPrintf("%"PRIuS" %"PRIuS" %"PRIuS, | 54 return StringPrintf("%"PRIuS" %"PRIuS" %"PRIuS, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | 108 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
106 | 109 |
107 // Update primary and add seconary. | 110 // Update primary and add seconary. |
108 LOG(ERROR) << "A"; | 111 LOG(ERROR) << "A"; |
109 UpdateDisplay("0+0-500x500,0+501-400x400"); | 112 UpdateDisplay("0+0-500x500,0+501-400x400"); |
110 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | 113 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
111 EXPECT_EQ("1 1 0", GetCountSummary()); | 114 EXPECT_EQ("1 1 0", GetCountSummary()); |
112 EXPECT_EQ(display_manager()->GetDisplayAt(0)->id(), changed()[0].id()); | 115 EXPECT_EQ(display_manager()->GetDisplayAt(0)->id(), changed()[0].id()); |
113 EXPECT_EQ(display_manager()->GetDisplayAt(1)->id(), added()[0].id()); | 116 EXPECT_EQ(display_manager()->GetDisplayAt(1)->id(), added()[0].id()); |
114 EXPECT_EQ("0,0 500x500", changed()[0].bounds().ToString()); | 117 EXPECT_EQ("0,0 500x500", changed()[0].bounds().ToString()); |
115 EXPECT_EQ("0,0 400x400", added()[0].bounds().ToString()); | 118 // Secondary display is on right. |
| 119 EXPECT_EQ("500,0 400x400", added()[0].bounds().ToString()); |
116 EXPECT_EQ("0,501 400x400", added()[0].bounds_in_pixel().ToString()); | 120 EXPECT_EQ("0,501 400x400", added()[0].bounds_in_pixel().ToString()); |
117 reset(); | 121 reset(); |
118 | 122 |
119 LOG(ERROR) << "B"; | 123 LOG(ERROR) << "B"; |
120 // Delete secondary. | 124 // Delete secondary. |
121 UpdateDisplay("0+0-500x500"); | 125 UpdateDisplay("0+0-500x500"); |
122 EXPECT_EQ("0 0 1", GetCountSummary()); | 126 EXPECT_EQ("0 0 1", GetCountSummary()); |
123 reset(); | 127 reset(); |
124 | 128 |
125 // Change primary. | 129 // Change primary. |
126 UpdateDisplay("0+0-1000x600"); | 130 UpdateDisplay("0+0-1000x600"); |
127 EXPECT_EQ("1 0 0", GetCountSummary()); | 131 EXPECT_EQ("1 0 0", GetCountSummary()); |
128 EXPECT_EQ(display_manager()->GetDisplayAt(0)->id(), changed()[0].id()); | 132 EXPECT_EQ(display_manager()->GetDisplayAt(0)->id(), changed()[0].id()); |
129 EXPECT_EQ("0,0 1000x600", changed()[0].bounds().ToString()); | 133 EXPECT_EQ("0,0 1000x600", changed()[0].bounds().ToString()); |
130 reset(); | 134 reset(); |
131 | 135 |
132 // Add secondary. | 136 // Add secondary. |
133 UpdateDisplay("0+0-1000x600,1001+0-600x400"); | 137 UpdateDisplay("0+0-1000x600,1001+0-600x400"); |
134 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | 138 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
135 EXPECT_EQ("0 1 0", GetCountSummary()); | 139 EXPECT_EQ("0 1 0", GetCountSummary()); |
136 EXPECT_EQ(display_manager()->GetDisplayAt(1)->id(), added()[0].id()); | 140 EXPECT_EQ(display_manager()->GetDisplayAt(1)->id(), added()[0].id()); |
137 EXPECT_EQ("0,0 600x400", added()[0].bounds().ToString()); | 141 // Secondary display is on right. |
| 142 EXPECT_EQ("1000,0 600x400", added()[0].bounds().ToString()); |
138 EXPECT_EQ("1001,0 600x400", added()[0].bounds_in_pixel().ToString()); | 143 EXPECT_EQ("1001,0 600x400", added()[0].bounds_in_pixel().ToString()); |
139 reset(); | 144 reset(); |
140 | 145 |
141 // Secondary removed, primary changed. | 146 // Secondary removed, primary changed. |
142 UpdateDisplay("0+0-800x300"); | 147 UpdateDisplay("0+0-800x300"); |
143 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | 148 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
144 EXPECT_EQ("1 0 1", GetCountSummary()); | 149 EXPECT_EQ("1 0 1", GetCountSummary()); |
145 EXPECT_EQ(display_manager()->GetDisplayAt(0)->id(), changed()[0].id()); | 150 EXPECT_EQ(display_manager()->GetDisplayAt(0)->id(), changed()[0].id()); |
146 EXPECT_EQ("0,0 800x300", changed()[0].bounds().ToString()); | 151 EXPECT_EQ("0,0 800x300", changed()[0].bounds().ToString()); |
147 reset(); | 152 reset(); |
(...skipping 18 matching lines...) Expand all Loading... |
166 EXPECT_EQ("100,100 500x400", changed()[0].bounds_in_pixel().ToString()); | 171 EXPECT_EQ("100,100 500x400", changed()[0].bounds_in_pixel().ToString()); |
167 reset(); | 172 reset(); |
168 | 173 |
169 // Go back to zero and wake up with multiple displays. | 174 // Go back to zero and wake up with multiple displays. |
170 display_manager()->OnNativeDisplaysChanged(empty); | 175 display_manager()->OnNativeDisplaysChanged(empty); |
171 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | 176 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
172 EXPECT_FALSE(root_window_destroyed()); | 177 EXPECT_FALSE(root_window_destroyed()); |
173 reset(); | 178 reset(); |
174 | 179 |
175 // Add secondary. | 180 // Add secondary. |
176 UpdateDisplay("0+0-1000x600,1000+0-600x400"); | 181 UpdateDisplay("0+0-1000x600,1000+1000-600x400"); |
177 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | 182 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
178 EXPECT_EQ("0,0 1000x600", | 183 EXPECT_EQ("0,0 1000x600", |
179 display_manager()->GetDisplayAt(0)->bounds().ToString()); | 184 display_manager()->GetDisplayAt(0)->bounds().ToString()); |
180 EXPECT_EQ("0,0 600x400", | 185 // Secondary display is on right. |
| 186 EXPECT_EQ("1000,0 600x400", |
181 display_manager()->GetDisplayAt(1)->bounds().ToString()); | 187 display_manager()->GetDisplayAt(1)->bounds().ToString()); |
182 EXPECT_EQ("1000,0 600x400", | 188 EXPECT_EQ("1000,1000 600x400", |
183 display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); | 189 display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); |
184 reset(); | 190 reset(); |
185 | 191 |
186 aura::DisplayManager::set_use_fullscreen_host_window(false); | 192 aura::DisplayManager::set_use_fullscreen_host_window(false); |
187 } | 193 } |
188 | 194 |
189 // Test in emulation mode (use_fullscreen_host_window=false) | 195 // Test in emulation mode (use_fullscreen_host_window=false) |
190 TEST_F(MultiDisplayManagerTest, MAYBE_EmulatorTest) { | 196 TEST_F(MultiDisplayManagerTest, MAYBE_EmulatorTest) { |
191 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | 197 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
192 | 198 |
(...skipping 30 matching lines...) Expand all Loading... |
223 | 229 |
224 // TODO(oshima): Device scale factor is supported on chromeos only for now. | 230 // TODO(oshima): Device scale factor is supported on chromeos only for now. |
225 #if defined(OS_CHROMEOS) | 231 #if defined(OS_CHROMEOS) |
226 #define MAYBE_TestDeviceScaleOnlyChange TestDeviceScaleOnlyChange | 232 #define MAYBE_TestDeviceScaleOnlyChange TestDeviceScaleOnlyChange |
227 #else | 233 #else |
228 #define MAYBE_TestDeviceScaleOnlyChange DISABLED_TestDeviceScaleOnlyChange | 234 #define MAYBE_TestDeviceScaleOnlyChange DISABLED_TestDeviceScaleOnlyChange |
229 #endif | 235 #endif |
230 | 236 |
231 TEST_F(MultiDisplayManagerTest, MAYBE_TestDeviceScaleOnlyChange) { | 237 TEST_F(MultiDisplayManagerTest, MAYBE_TestDeviceScaleOnlyChange) { |
232 aura::DisplayManager::set_use_fullscreen_host_window(true); | 238 aura::DisplayManager::set_use_fullscreen_host_window(true); |
233 UpdateDisplay("0+0-1000x600"); | 239 UpdateDisplay("1000x600"); |
234 EXPECT_EQ(1, | 240 EXPECT_EQ(1, |
235 Shell::GetPrimaryRootWindow()->compositor()->device_scale_factor()); | 241 Shell::GetPrimaryRootWindow()->compositor()->device_scale_factor()); |
236 EXPECT_EQ("1000x600", | 242 EXPECT_EQ("1000x600", |
237 Shell::GetPrimaryRootWindow()->bounds().size().ToString()); | 243 Shell::GetPrimaryRootWindow()->bounds().size().ToString()); |
238 UpdateDisplay("0+0-1000x600*2"); | 244 UpdateDisplay("1000x600*2"); |
239 EXPECT_EQ(2, | 245 EXPECT_EQ(2, |
240 Shell::GetPrimaryRootWindow()->compositor()->device_scale_factor()); | 246 Shell::GetPrimaryRootWindow()->compositor()->device_scale_factor()); |
241 EXPECT_EQ("500x300", | 247 EXPECT_EQ("500x300", |
242 Shell::GetPrimaryRootWindow()->bounds().size().ToString()); | 248 Shell::GetPrimaryRootWindow()->bounds().size().ToString()); |
243 aura::DisplayManager::set_use_fullscreen_host_window(false); | 249 aura::DisplayManager::set_use_fullscreen_host_window(false); |
244 } | 250 } |
245 | 251 |
246 } // namespace test | 252 } // namespace test |
247 } // namespace ash | 253 } // namespace ash |
OLD | NEW |