| 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/monitor/multi_monitor_manager.h" | 5 #include "ash/display/multi_display_manager.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 "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "ui/aura/display_observer.h" | 11 #include "ui/aura/display_observer.h" |
| 12 #include "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
| 13 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
| 14 #include "ui/aura/window_observer.h" | 14 #include "ui/aura/window_observer.h" |
| 15 #include "ui/gfx/display.h" | 15 #include "ui/gfx/display.h" |
| 16 | 16 |
| 17 namespace ash { | 17 namespace ash { |
| 18 namespace test { | 18 namespace test { |
| 19 | 19 |
| 20 using std::vector; | 20 using std::vector; |
| 21 using std::string; | 21 using std::string; |
| 22 | 22 |
| 23 class MultiMonitorManagerTest : public test::AshTestBase, | 23 class MultiDisplayManagerTest : public test::AshTestBase, |
| 24 public aura::DisplayObserver, | 24 public aura::DisplayObserver, |
| 25 public aura::WindowObserver { | 25 public aura::WindowObserver { |
| 26 public: | 26 public: |
| 27 MultiMonitorManagerTest() | 27 MultiDisplayManagerTest() |
| 28 : removed_count_(0U), | 28 : removed_count_(0U), |
| 29 root_window_destroyed_(false) { | 29 root_window_destroyed_(false) { |
| 30 } | 30 } |
| 31 virtual ~MultiMonitorManagerTest() {} | 31 virtual ~MultiDisplayManagerTest() {} |
| 32 | 32 |
| 33 virtual void SetUp() OVERRIDE { | 33 virtual void SetUp() OVERRIDE { |
| 34 AshTestBase::SetUp(); | 34 AshTestBase::SetUp(); |
| 35 monitor_manager()->AddObserver(this); | 35 display_manager()->AddObserver(this); |
| 36 Shell::GetPrimaryRootWindow()->AddObserver(this); | 36 Shell::GetPrimaryRootWindow()->AddObserver(this); |
| 37 } | 37 } |
| 38 virtual void TearDown() OVERRIDE { | 38 virtual void TearDown() OVERRIDE { |
| 39 Shell::GetPrimaryRootWindow()->RemoveObserver(this); | 39 Shell::GetPrimaryRootWindow()->RemoveObserver(this); |
| 40 monitor_manager()->RemoveObserver(this); | 40 display_manager()->RemoveObserver(this); |
| 41 AshTestBase::TearDown(); | 41 AshTestBase::TearDown(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 aura::MonitorManager* monitor_manager() { | 44 aura::DisplayManager* display_manager() { |
| 45 return aura::Env::GetInstance()->monitor_manager(); | 45 return aura::Env::GetInstance()->display_manager(); |
| 46 } | 46 } |
| 47 const vector<gfx::Display>& changed() const { return changed_; } | 47 const vector<gfx::Display>& changed() const { return changed_; } |
| 48 const vector<gfx::Display>& added() const { return added_; } | 48 const vector<gfx::Display>& added() const { return added_; } |
| 49 | 49 |
| 50 string GetCountSummary() const { | 50 string GetCountSummary() const { |
| 51 return StringPrintf("%"PRIuS" %"PRIuS" %"PRIuS, | 51 return StringPrintf("%"PRIuS" %"PRIuS" %"PRIuS, |
| 52 changed_.size(), added_.size(), removed_count_); | 52 changed_.size(), added_.size(), removed_count_); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void reset() { | 55 void reset() { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 79 ASSERT_EQ(Shell::GetPrimaryRootWindow(), window); | 79 ASSERT_EQ(Shell::GetPrimaryRootWindow(), window); |
| 80 root_window_destroyed_ = true; | 80 root_window_destroyed_ = true; |
| 81 } | 81 } |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 vector<gfx::Display> changed_; | 84 vector<gfx::Display> changed_; |
| 85 vector<gfx::Display> added_; | 85 vector<gfx::Display> added_; |
| 86 size_t removed_count_; | 86 size_t removed_count_; |
| 87 bool root_window_destroyed_; | 87 bool root_window_destroyed_; |
| 88 | 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(MultiMonitorManagerTest); | 89 DISALLOW_COPY_AND_ASSIGN(MultiDisplayManagerTest); |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 TEST_F(MultiMonitorManagerTest, NativeMonitorTest) { | 92 TEST_F(MultiDisplayManagerTest, NativeDisplayTest) { |
| 93 aura::MonitorManager::set_use_fullscreen_host_window(true); | 93 aura::DisplayManager::set_use_fullscreen_host_window(true); |
| 94 | 94 |
| 95 EXPECT_EQ(1U, monitor_manager()->GetNumDisplays()); | 95 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 96 | 96 |
| 97 // Update primary and add seconary. | 97 // Update primary and add seconary. |
| 98 UpdateMonitor("0+0-500x500,0+501-400x400"); | 98 UpdateDisplay("0+0-500x500,0+501-400x400"); |
| 99 EXPECT_EQ(2U, monitor_manager()->GetNumDisplays()); | 99 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
| 100 EXPECT_EQ("1 1 0", GetCountSummary()); | 100 EXPECT_EQ("1 1 0", GetCountSummary()); |
| 101 EXPECT_EQ(monitor_manager()->GetDisplayAt(0).id(), changed()[0].id()); | 101 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id()); |
| 102 EXPECT_EQ(monitor_manager()->GetDisplayAt(1).id(), added()[0].id()); | 102 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id()); |
| 103 EXPECT_EQ("0,0 500x500", changed()[0].bounds().ToString()); | 103 EXPECT_EQ("0,0 500x500", changed()[0].bounds().ToString()); |
| 104 EXPECT_EQ("0,0 400x400", added()[0].bounds().ToString()); | 104 EXPECT_EQ("0,0 400x400", added()[0].bounds().ToString()); |
| 105 EXPECT_EQ("0,501 400x400", added()[0].bounds_in_pixel().ToString()); | 105 EXPECT_EQ("0,501 400x400", added()[0].bounds_in_pixel().ToString()); |
| 106 reset(); | 106 reset(); |
| 107 | 107 |
| 108 // Delete secondary. | 108 // Delete secondary. |
| 109 UpdateMonitor("0+0-500x500"); | 109 UpdateDisplay("0+0-500x500"); |
| 110 EXPECT_EQ("0 0 1", GetCountSummary()); | 110 EXPECT_EQ("0 0 1", GetCountSummary()); |
| 111 reset(); | 111 reset(); |
| 112 | 112 |
| 113 // Change primary. | 113 // Change primary. |
| 114 UpdateMonitor("0+0-1000x600"); | 114 UpdateDisplay("0+0-1000x600"); |
| 115 EXPECT_EQ("1 0 0", GetCountSummary()); | 115 EXPECT_EQ("1 0 0", GetCountSummary()); |
| 116 EXPECT_EQ(monitor_manager()->GetDisplayAt(0).id(), changed()[0].id()); | 116 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id()); |
| 117 EXPECT_EQ("0,0 1000x600", changed()[0].bounds().ToString()); | 117 EXPECT_EQ("0,0 1000x600", changed()[0].bounds().ToString()); |
| 118 reset(); | 118 reset(); |
| 119 | 119 |
| 120 // Add secondary. | 120 // Add secondary. |
| 121 UpdateMonitor("0+0-1000x600,1001+0-600x400"); | 121 UpdateDisplay("0+0-1000x600,1001+0-600x400"); |
| 122 EXPECT_EQ(2U, monitor_manager()->GetNumDisplays()); | 122 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
| 123 EXPECT_EQ("0 1 0", GetCountSummary()); | 123 EXPECT_EQ("0 1 0", GetCountSummary()); |
| 124 EXPECT_EQ(monitor_manager()->GetDisplayAt(1).id(), added()[0].id()); | 124 EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id()); |
| 125 EXPECT_EQ("0,0 600x400", added()[0].bounds().ToString()); | 125 EXPECT_EQ("0,0 600x400", added()[0].bounds().ToString()); |
| 126 EXPECT_EQ("1001,0 600x400", added()[0].bounds_in_pixel().ToString()); | 126 EXPECT_EQ("1001,0 600x400", added()[0].bounds_in_pixel().ToString()); |
| 127 reset(); | 127 reset(); |
| 128 | 128 |
| 129 // Secondary removed, primary changed. | 129 // Secondary removed, primary changed. |
| 130 UpdateMonitor("0+0-800x300"); | 130 UpdateDisplay("0+0-800x300"); |
| 131 EXPECT_EQ(1U, monitor_manager()->GetNumDisplays()); | 131 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 132 EXPECT_EQ("1 0 1", GetCountSummary()); | 132 EXPECT_EQ("1 0 1", GetCountSummary()); |
| 133 EXPECT_EQ(monitor_manager()->GetDisplayAt(0).id(), changed()[0].id()); | 133 EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id()); |
| 134 EXPECT_EQ("0,0 800x300", changed()[0].bounds().ToString()); | 134 EXPECT_EQ("0,0 800x300", changed()[0].bounds().ToString()); |
| 135 reset(); | 135 reset(); |
| 136 | 136 |
| 137 // # of display can go to zero when screen is off. | 137 // # of display can go to zero when screen is off. |
| 138 const vector<gfx::Display> empty; | 138 const vector<gfx::Display> empty; |
| 139 monitor_manager()->OnNativeMonitorsChanged(empty); | 139 display_manager()->OnNativeDisplaysChanged(empty); |
| 140 EXPECT_EQ(1U, monitor_manager()->GetNumDisplays()); | 140 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 141 EXPECT_EQ("0 0 0", GetCountSummary()); | 141 EXPECT_EQ("0 0 0", GetCountSummary()); |
| 142 EXPECT_FALSE(root_window_destroyed()); | 142 EXPECT_FALSE(root_window_destroyed()); |
| 143 // Monitor configuration stays the same | 143 // Display configuration stays the same |
| 144 EXPECT_EQ("0,0 800x300", | 144 EXPECT_EQ("0,0 800x300", |
| 145 monitor_manager()->GetDisplayAt(0).bounds().ToString()); | 145 display_manager()->GetDisplayAt(0).bounds().ToString()); |
| 146 reset(); | 146 reset(); |
| 147 | 147 |
| 148 // Connect to monitor again | 148 // Connect to display again |
| 149 UpdateMonitor("100+100-500x400"); | 149 UpdateDisplay("100+100-500x400"); |
| 150 EXPECT_EQ(1U, monitor_manager()->GetNumDisplays()); | 150 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 151 EXPECT_EQ("1 0 0", GetCountSummary()); | 151 EXPECT_EQ("1 0 0", GetCountSummary()); |
| 152 EXPECT_FALSE(root_window_destroyed()); | 152 EXPECT_FALSE(root_window_destroyed()); |
| 153 EXPECT_EQ("0,0 500x400", changed()[0].bounds().ToString()); | 153 EXPECT_EQ("0,0 500x400", changed()[0].bounds().ToString()); |
| 154 EXPECT_EQ("100,100 500x400", changed()[0].bounds_in_pixel().ToString()); | 154 EXPECT_EQ("100,100 500x400", changed()[0].bounds_in_pixel().ToString()); |
| 155 reset(); | 155 reset(); |
| 156 | 156 |
| 157 // Go back to zero and wake up with multiple monitors. | 157 // Go back to zero and wake up with multiple displays. |
| 158 monitor_manager()->OnNativeMonitorsChanged(empty); | 158 display_manager()->OnNativeDisplaysChanged(empty); |
| 159 EXPECT_EQ(1U, monitor_manager()->GetNumDisplays()); | 159 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 160 EXPECT_FALSE(root_window_destroyed()); | 160 EXPECT_FALSE(root_window_destroyed()); |
| 161 reset(); | 161 reset(); |
| 162 | 162 |
| 163 // Add secondary. | 163 // Add secondary. |
| 164 UpdateMonitor("0+0-1000x600,1000+0-600x400"); | 164 UpdateDisplay("0+0-1000x600,1000+0-600x400"); |
| 165 EXPECT_EQ(2U, monitor_manager()->GetNumDisplays()); | 165 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
| 166 EXPECT_EQ("0,0 1000x600", | 166 EXPECT_EQ("0,0 1000x600", |
| 167 monitor_manager()->GetDisplayAt(0).bounds().ToString()); | 167 display_manager()->GetDisplayAt(0).bounds().ToString()); |
| 168 EXPECT_EQ("0,0 600x400", | 168 EXPECT_EQ("0,0 600x400", |
| 169 monitor_manager()->GetDisplayAt(1).bounds().ToString()); | 169 display_manager()->GetDisplayAt(1).bounds().ToString()); |
| 170 EXPECT_EQ("1000,0 600x400", | 170 EXPECT_EQ("1000,0 600x400", |
| 171 monitor_manager()->GetDisplayAt(1).bounds_in_pixel().ToString()); | 171 display_manager()->GetDisplayAt(1).bounds_in_pixel().ToString()); |
| 172 reset(); | 172 reset(); |
| 173 | 173 |
| 174 aura::MonitorManager::set_use_fullscreen_host_window(false); | 174 aura::DisplayManager::set_use_fullscreen_host_window(false); |
| 175 } | 175 } |
| 176 | 176 |
| 177 // Test in emulation mode (use_fullscreen_host_window=false) | 177 // Test in emulation mode (use_fullscreen_host_window=false) |
| 178 TEST_F(MultiMonitorManagerTest, EmulatorTest) { | 178 TEST_F(MultiDisplayManagerTest, EmulatorTest) { |
| 179 EXPECT_EQ(1U, monitor_manager()->GetNumDisplays()); | 179 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 180 | 180 |
| 181 internal::MultiMonitorManager::AddRemoveMonitor(); | 181 internal::MultiDisplayManager::AddRemoveDisplay(); |
| 182 // Update primary and add seconary. | 182 // Update primary and add seconary. |
| 183 EXPECT_EQ(2U, monitor_manager()->GetNumDisplays()); | 183 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
| 184 #if defined(OS_WIN) | 184 #if defined(OS_WIN) |
| 185 // TODO(oshima): Windows receives resize event for some reason. | 185 // TODO(oshima): Windows receives resize event for some reason. |
| 186 EXPECT_EQ("1 1 0", GetCountSummary()); | 186 EXPECT_EQ("1 1 0", GetCountSummary()); |
| 187 #else | 187 #else |
| 188 EXPECT_EQ("0 1 0", GetCountSummary()); | 188 EXPECT_EQ("0 1 0", GetCountSummary()); |
| 189 #endif | 189 #endif |
| 190 reset(); | 190 reset(); |
| 191 | 191 |
| 192 internal::MultiMonitorManager::CycleMonitor(); | 192 internal::MultiDisplayManager::CycleDisplay(); |
| 193 EXPECT_EQ(2U, monitor_manager()->GetNumDisplays()); | 193 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
| 194 // Observer gets called twice in this mode because | 194 // Observer gets called twice in this mode because |
| 195 // it gets notified both from |OnNativeMonitorChagned| | 195 // it gets notified both from |OnNativeDisplayChagned| |
| 196 // and from |RootWindowObserver|, which is the consequence of | 196 // and from |RootWindowObserver|, which is the consequence of |
| 197 // |SetHostSize()|. | 197 // |SetHostSize()|. |
| 198 EXPECT_EQ("4 0 0", GetCountSummary()); | 198 EXPECT_EQ("4 0 0", GetCountSummary()); |
| 199 reset(); | 199 reset(); |
| 200 | 200 |
| 201 internal::MultiMonitorManager::AddRemoveMonitor(); | 201 internal::MultiDisplayManager::AddRemoveDisplay(); |
| 202 EXPECT_EQ(1U, monitor_manager()->GetNumDisplays()); | 202 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 203 EXPECT_EQ("0 0 1", GetCountSummary()); | 203 EXPECT_EQ("0 0 1", GetCountSummary()); |
| 204 reset(); | 204 reset(); |
| 205 | 205 |
| 206 internal::MultiMonitorManager::CycleMonitor(); | 206 internal::MultiDisplayManager::CycleDisplay(); |
| 207 EXPECT_EQ(1U, monitor_manager()->GetNumDisplays()); | 207 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 208 EXPECT_EQ("0 0 0", GetCountSummary()); | 208 EXPECT_EQ("0 0 0", GetCountSummary()); |
| 209 reset(); | 209 reset(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 // TODO(oshima): Device scale factor is supported on chromeos only for now. | 212 // TODO(oshima): Device scale factor is supported on chromeos only for now. |
| 213 #if defined(OS_CHROMEOS) | 213 #if defined(OS_CHROMEOS) |
| 214 #define MAYBE_TestDeviceScaleOnlyChange TestDeviceScaleOnlyChange | 214 #define MAYBE_TestDeviceScaleOnlyChange TestDeviceScaleOnlyChange |
| 215 #else | 215 #else |
| 216 #define MAYBE_TestDeviceScaleOnlyChange DISABLED_TestDeviceScaleOnlyChange | 216 #define MAYBE_TestDeviceScaleOnlyChange DISABLED_TestDeviceScaleOnlyChange |
| 217 #endif | 217 #endif |
| 218 | 218 |
| 219 TEST_F(MultiMonitorManagerTest, MAYBE_TestDeviceScaleOnlyChange) { | 219 TEST_F(MultiDisplayManagerTest, MAYBE_TestDeviceScaleOnlyChange) { |
| 220 aura::MonitorManager::set_use_fullscreen_host_window(true); | 220 aura::DisplayManager::set_use_fullscreen_host_window(true); |
| 221 UpdateMonitor("0+0-1000x600"); | 221 UpdateDisplay("0+0-1000x600"); |
| 222 EXPECT_EQ(1, | 222 EXPECT_EQ(1, |
| 223 Shell::GetPrimaryRootWindow()->compositor()->device_scale_factor()); | 223 Shell::GetPrimaryRootWindow()->compositor()->device_scale_factor()); |
| 224 EXPECT_EQ("1000x600", | 224 EXPECT_EQ("1000x600", |
| 225 Shell::GetPrimaryRootWindow()->bounds().size().ToString()); | 225 Shell::GetPrimaryRootWindow()->bounds().size().ToString()); |
| 226 UpdateMonitor("0+0-1000x600*2"); | 226 UpdateDisplay("0+0-1000x600*2"); |
| 227 EXPECT_EQ(2, | 227 EXPECT_EQ(2, |
| 228 Shell::GetPrimaryRootWindow()->compositor()->device_scale_factor()); | 228 Shell::GetPrimaryRootWindow()->compositor()->device_scale_factor()); |
| 229 EXPECT_EQ("500x300", | 229 EXPECT_EQ("500x300", |
| 230 Shell::GetPrimaryRootWindow()->bounds().size().ToString()); | 230 Shell::GetPrimaryRootWindow()->bounds().size().ToString()); |
| 231 aura::MonitorManager::set_use_fullscreen_host_window(false); | 231 aura::DisplayManager::set_use_fullscreen_host_window(false); |
| 232 } | 232 } |
| 233 | 233 |
| 234 } // namespace test | 234 } // namespace test |
| 235 } // namespace ash | 235 } // namespace ash |
| OLD | NEW |