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