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