| 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/monitor/multi_monitor_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/string_split.h" | 10 #include "base/string_split.h" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "ui/aura/display_observer.h" |
| 12 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
| 13 #include "ui/aura/monitor_observer.h" | |
| 14 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
| 15 #include "ui/aura/window_observer.h" | 15 #include "ui/aura/window_observer.h" |
| 16 #include "ui/gfx/monitor.h" | 16 #include "ui/gfx/display.h" |
| 17 | 17 |
| 18 namespace ash { | 18 namespace ash { |
| 19 namespace test { | 19 namespace test { |
| 20 | 20 |
| 21 using std::vector; | 21 using std::vector; |
| 22 using std::string; | 22 using std::string; |
| 23 using gfx::Monitor; | |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 vector<Monitor> CreateMonitorsFromString( | 26 vector<gfx::Display> CreateDisplaysFromString( |
| 28 const std::string specs) { | 27 const std::string specs) { |
| 29 vector<Monitor> monitors; | 28 vector<gfx::Display> displays; |
| 30 vector<string> parts; | 29 vector<string> parts; |
| 31 base::SplitString(specs, ',', &parts); | 30 base::SplitString(specs, ',', &parts); |
| 32 for (vector<string>::const_iterator iter = parts.begin(); | 31 for (vector<string>::const_iterator iter = parts.begin(); |
| 33 iter != parts.end(); ++iter) { | 32 iter != parts.end(); ++iter) { |
| 34 monitors.push_back(aura::MonitorManager::CreateMonitorFromSpec(*iter)); | 33 displays.push_back(aura::MonitorManager::CreateMonitorFromSpec(*iter)); |
| 35 } | 34 } |
| 36 return monitors; | 35 return displays; |
| 37 } | 36 } |
| 38 | 37 |
| 39 } // namespace | 38 } // namespace |
| 40 | 39 |
| 41 class MultiMonitorManagerTest : public test::AshTestBase, | 40 class MultiMonitorManagerTest : public test::AshTestBase, |
| 42 public aura::MonitorObserver, | 41 public aura::DisplayObserver, |
| 43 public aura::WindowObserver { | 42 public aura::WindowObserver { |
| 44 public: | 43 public: |
| 45 MultiMonitorManagerTest() | 44 MultiMonitorManagerTest() |
| 46 : removed_count_(0U), | 45 : removed_count_(0U), |
| 47 root_window_destroyed_(false) { | 46 root_window_destroyed_(false) { |
| 48 } | 47 } |
| 49 virtual ~MultiMonitorManagerTest() {} | 48 virtual ~MultiMonitorManagerTest() {} |
| 50 | 49 |
| 51 virtual void SetUp() OVERRIDE { | 50 virtual void SetUp() OVERRIDE { |
| 52 AshTestBase::SetUp(); | 51 AshTestBase::SetUp(); |
| 53 monitor_manager()->AddObserver(this); | 52 monitor_manager()->AddObserver(this); |
| 54 Shell::GetPrimaryRootWindow()->AddObserver(this); | 53 Shell::GetPrimaryRootWindow()->AddObserver(this); |
| 55 } | 54 } |
| 56 virtual void TearDown() OVERRIDE { | 55 virtual void TearDown() OVERRIDE { |
| 57 Shell::GetPrimaryRootWindow()->RemoveObserver(this); | 56 Shell::GetPrimaryRootWindow()->RemoveObserver(this); |
| 58 monitor_manager()->RemoveObserver(this); | 57 monitor_manager()->RemoveObserver(this); |
| 59 AshTestBase::TearDown(); | 58 AshTestBase::TearDown(); |
| 60 } | 59 } |
| 61 | 60 |
| 62 aura::MonitorManager* monitor_manager() { | 61 aura::MonitorManager* monitor_manager() { |
| 63 return aura::Env::GetInstance()->monitor_manager(); | 62 return aura::Env::GetInstance()->monitor_manager(); |
| 64 } | 63 } |
| 65 const vector<Monitor>& changed() const { return changed_; } | 64 const vector<gfx::Display>& changed() const { return changed_; } |
| 66 const vector<Monitor>& added() const { return added_; } | 65 const vector<gfx::Display>& added() const { return added_; } |
| 67 | 66 |
| 68 string GetCountSummary() const { | 67 string GetCountSummary() const { |
| 69 return StringPrintf("%"PRIuS" %"PRIuS" %"PRIuS, | 68 return StringPrintf("%"PRIuS" %"PRIuS" %"PRIuS, |
| 70 changed_.size(), added_.size(), removed_count_); | 69 changed_.size(), added_.size(), removed_count_); |
| 71 } | 70 } |
| 72 | 71 |
| 73 void reset() { | 72 void reset() { |
| 74 changed_.clear(); | 73 changed_.clear(); |
| 75 added_.clear(); | 74 added_.clear(); |
| 76 removed_count_ = 0U; | 75 removed_count_ = 0U; |
| 77 root_window_destroyed_ = false; | 76 root_window_destroyed_ = false; |
| 78 } | 77 } |
| 79 | 78 |
| 80 bool root_window_destroyed() const { | 79 bool root_window_destroyed() const { |
| 81 return root_window_destroyed_; | 80 return root_window_destroyed_; |
| 82 } | 81 } |
| 83 | 82 |
| 84 // aura::MonitorObserver overrides: | 83 // aura::DisplayObserver overrides: |
| 85 virtual void OnMonitorBoundsChanged(const Monitor& monitor) OVERRIDE { | 84 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE { |
| 86 changed_.push_back(monitor); | 85 changed_.push_back(display); |
| 87 } | 86 } |
| 88 virtual void OnMonitorAdded(const Monitor& new_monitor) OVERRIDE { | 87 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE { |
| 89 added_.push_back(new_monitor); | 88 added_.push_back(new_display); |
| 90 } | 89 } |
| 91 virtual void OnMonitorRemoved(const Monitor& old_monitor) OVERRIDE { | 90 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE { |
| 92 ++removed_count_; | 91 ++removed_count_; |
| 93 } | 92 } |
| 94 | 93 |
| 95 // aura::WindowObserver overrides: | 94 // aura::WindowObserver overrides: |
| 96 virtual void OnWindowDestroying(aura::Window* window) { | 95 virtual void OnWindowDestroying(aura::Window* window) { |
| 97 ASSERT_EQ(Shell::GetPrimaryRootWindow(), window); | 96 ASSERT_EQ(Shell::GetPrimaryRootWindow(), window); |
| 98 root_window_destroyed_ = true; | 97 root_window_destroyed_ = true; |
| 99 } | 98 } |
| 100 | 99 |
| 101 void UpdateMonitor(const std::string str) { | 100 void UpdateMonitor(const std::string str) { |
| 102 vector<Monitor> monitors = CreateMonitorsFromString(str); | 101 vector<gfx::Display> displays = CreateDisplaysFromString(str); |
| 103 monitor_manager()->OnNativeMonitorsChanged(monitors); | 102 monitor_manager()->OnNativeMonitorsChanged(displays); |
| 104 } | 103 } |
| 105 | 104 |
| 106 private: | 105 private: |
| 107 vector<Monitor> changed_; | 106 vector<gfx::Display> changed_; |
| 108 vector<Monitor> added_; | 107 vector<gfx::Display> added_; |
| 109 size_t removed_count_; | 108 size_t removed_count_; |
| 110 bool root_window_destroyed_; | 109 bool root_window_destroyed_; |
| 111 | 110 |
| 112 DISALLOW_COPY_AND_ASSIGN(MultiMonitorManagerTest); | 111 DISALLOW_COPY_AND_ASSIGN(MultiMonitorManagerTest); |
| 113 }; | 112 }; |
| 114 | 113 |
| 115 TEST_F(MultiMonitorManagerTest, NativeMonitorTest) { | 114 TEST_F(MultiMonitorManagerTest, NativeMonitorTest) { |
| 116 aura::MonitorManager::set_use_fullscreen_host_window(true); | 115 aura::MonitorManager::set_use_fullscreen_host_window(true); |
| 117 | 116 |
| 118 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); | 117 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 reset(); | 149 reset(); |
| 151 | 150 |
| 152 // Secondary removed, primary changed. | 151 // Secondary removed, primary changed. |
| 153 UpdateMonitor("0+0-800x300"); | 152 UpdateMonitor("0+0-800x300"); |
| 154 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); | 153 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); |
| 155 EXPECT_EQ("1 0 1", GetCountSummary()); | 154 EXPECT_EQ("1 0 1", GetCountSummary()); |
| 156 EXPECT_EQ(monitor_manager()->GetMonitorAt(0).id(), changed()[0].id()); | 155 EXPECT_EQ(monitor_manager()->GetMonitorAt(0).id(), changed()[0].id()); |
| 157 EXPECT_EQ("0,0 800x300", changed()[0].bounds().ToString()); | 156 EXPECT_EQ("0,0 800x300", changed()[0].bounds().ToString()); |
| 158 reset(); | 157 reset(); |
| 159 | 158 |
| 160 // # of monitor can go to zero when screen is off. | 159 // # of display can go to zero when screen is off. |
| 161 const vector<Monitor> empty; | 160 const vector<gfx::Display> empty; |
| 162 monitor_manager()->OnNativeMonitorsChanged(empty); | 161 monitor_manager()->OnNativeMonitorsChanged(empty); |
| 163 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); | 162 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); |
| 164 EXPECT_EQ("0 0 0", GetCountSummary()); | 163 EXPECT_EQ("0 0 0", GetCountSummary()); |
| 165 EXPECT_FALSE(root_window_destroyed()); | 164 EXPECT_FALSE(root_window_destroyed()); |
| 166 // Monitor configuration stays the same | 165 // Monitor configuration stays the same |
| 167 EXPECT_EQ("0,0 800x300", | 166 EXPECT_EQ("0,0 800x300", |
| 168 monitor_manager()->GetMonitorAt(0).bounds().ToString()); | 167 monitor_manager()->GetMonitorAt(0).bounds().ToString()); |
| 169 reset(); | 168 reset(); |
| 170 | 169 |
| 171 // Connect to monitor again | 170 // Connect to monitor again |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 reset(); | 226 reset(); |
| 228 | 227 |
| 229 internal::MultiMonitorManager::CycleMonitor(); | 228 internal::MultiMonitorManager::CycleMonitor(); |
| 230 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); | 229 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); |
| 231 EXPECT_EQ("0 0 0", GetCountSummary()); | 230 EXPECT_EQ("0 0 0", GetCountSummary()); |
| 232 reset(); | 231 reset(); |
| 233 } | 232 } |
| 234 | 233 |
| 235 } // namespace test | 234 } // namespace test |
| 236 } // namespace ash | 235 } // namespace ash |
| OLD | NEW |