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" | |
11 #include "base/string_split.h" | 10 #include "base/string_split.h" |
12 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
13 #include "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
14 #include "ui/aura/monitor.h" | 13 #include "ui/aura/monitor_observer.h" |
15 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
16 #include "ui/aura/window_observer.h" | 15 #include "ui/aura/window_observer.h" |
| 16 #include "ui/gfx/monitor.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 aura::Monitor; | 23 using gfx::Monitor; |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 vector<const aura::Monitor*> CreateMonitorsFromString( | 27 vector<Monitor> CreateMonitorsFromString( |
28 const std::string specs) { | 28 const std::string specs) { |
29 vector<const aura::Monitor*> monitors; | 29 vector<Monitor> monitors; |
30 vector<string> parts; | 30 vector<string> parts; |
31 base::SplitString(specs, ',', &parts); | 31 base::SplitString(specs, ',', &parts); |
32 for (vector<string>::const_iterator iter = parts.begin(); | 32 for (vector<string>::const_iterator iter = parts.begin(); |
33 iter != parts.end(); ++iter) { | 33 iter != parts.end(); ++iter) { |
34 monitors.push_back(aura::MonitorManager::CreateMonitorFromSpec(*iter)); | 34 monitors.push_back(aura::MonitorManager::CreateMonitorFromSpec(*iter)); |
35 } | 35 } |
36 return monitors; | 36 return monitors; |
37 } | 37 } |
38 | 38 |
39 } // namespace | 39 } // namespace |
(...skipping 15 matching lines...) Expand all Loading... |
55 } | 55 } |
56 virtual void TearDown() OVERRIDE { | 56 virtual void TearDown() OVERRIDE { |
57 Shell::GetRootWindow()->RemoveObserver(this); | 57 Shell::GetRootWindow()->RemoveObserver(this); |
58 monitor_manager()->RemoveObserver(this); | 58 monitor_manager()->RemoveObserver(this); |
59 AshTestBase::TearDown(); | 59 AshTestBase::TearDown(); |
60 } | 60 } |
61 | 61 |
62 aura::MonitorManager* monitor_manager() { | 62 aura::MonitorManager* monitor_manager() { |
63 return aura::Env::GetInstance()->monitor_manager(); | 63 return aura::Env::GetInstance()->monitor_manager(); |
64 } | 64 } |
65 const vector<const Monitor*>& changed() const { return changed_; } | 65 const vector<Monitor>& changed() const { return changed_; } |
66 const vector<const Monitor*>& added() const { return added_; } | 66 const vector<Monitor>& added() const { return added_; } |
67 | 67 |
68 string GetCountSummary() const { | 68 string GetCountSummary() const { |
69 return StringPrintf("%"PRIuS" %"PRIuS" %"PRIuS, | 69 return StringPrintf("%"PRIuS" %"PRIuS" %"PRIuS, |
70 changed_.size(), added_.size(), removed_count_); | 70 changed_.size(), added_.size(), removed_count_); |
71 } | 71 } |
72 | 72 |
73 void reset() { | 73 void reset() { |
74 changed_.clear(); | 74 changed_.clear(); |
75 added_.clear(); | 75 added_.clear(); |
76 removed_count_ = 0U; | 76 removed_count_ = 0U; |
77 root_window_destroyed_ = false; | 77 root_window_destroyed_ = false; |
78 } | 78 } |
79 | 79 |
80 bool root_window_destroyed() const { | 80 bool root_window_destroyed() const { |
81 return root_window_destroyed_; | 81 return root_window_destroyed_; |
82 } | 82 } |
83 | 83 |
84 // aura::MonitorObserver overrides: | 84 // aura::MonitorObserver overrides: |
85 virtual void OnMonitorBoundsChanged(const Monitor* monitor) OVERRIDE { | 85 virtual void OnMonitorBoundsChanged(const Monitor& monitor) OVERRIDE { |
86 changed_.push_back(monitor); | 86 changed_.push_back(monitor); |
87 } | 87 } |
88 virtual void OnMonitorAdded(Monitor* new_monitor) OVERRIDE { | 88 virtual void OnMonitorAdded(const Monitor& new_monitor) OVERRIDE { |
89 added_.push_back(new_monitor); | 89 added_.push_back(new_monitor); |
90 } | 90 } |
91 virtual void OnMonitorRemoved(const Monitor* old_monitor) OVERRIDE { | 91 virtual void OnMonitorRemoved(const Monitor& old_monitor) OVERRIDE { |
92 ++removed_count_; | 92 ++removed_count_; |
93 } | 93 } |
94 | 94 |
95 // aura::WindowObserver overrides: | 95 // aura::WindowObserver overrides: |
96 virtual void OnWindowDestroying(aura::Window* window) { | 96 virtual void OnWindowDestroying(aura::Window* window) { |
97 ASSERT_EQ(Shell::GetRootWindow(), window); | 97 ASSERT_EQ(Shell::GetRootWindow(), window); |
98 root_window_destroyed_ = true; | 98 root_window_destroyed_ = true; |
99 } | 99 } |
100 | 100 |
101 void UpdateMonitor(const std::string str) { | 101 void UpdateMonitor(const std::string str) { |
102 vector<const aura::Monitor*> monitors = CreateMonitorsFromString(str); | 102 vector<Monitor> monitors = CreateMonitorsFromString(str); |
103 monitor_manager()->OnNativeMonitorsChanged(monitors); | 103 monitor_manager()->OnNativeMonitorsChanged(monitors); |
104 STLDeleteContainerPointers(monitors.begin(), monitors.end()); | |
105 } | 104 } |
106 | 105 |
107 private: | 106 private: |
108 vector<const Monitor*> changed_; | 107 vector<Monitor> changed_; |
109 vector<const Monitor*> added_; | 108 vector<Monitor> added_; |
110 size_t removed_count_; | 109 size_t removed_count_; |
111 bool root_window_destroyed_; | 110 bool root_window_destroyed_; |
112 | 111 |
113 DISALLOW_COPY_AND_ASSIGN(MultiMonitorManagerTest); | 112 DISALLOW_COPY_AND_ASSIGN(MultiMonitorManagerTest); |
114 }; | 113 }; |
115 | 114 |
116 TEST_F(MultiMonitorManagerTest, NativeMonitorTest) { | 115 TEST_F(MultiMonitorManagerTest, NativeMonitorTest) { |
117 aura::MonitorManager::set_use_fullscreen_host_window(true); | 116 aura::MonitorManager::set_use_fullscreen_host_window(true); |
118 | 117 |
119 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); | 118 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); |
120 | 119 |
121 // Update primary and add seconary. | 120 // Update primary and add seconary. |
122 UpdateMonitor("0+0-500x500,0+501-400x400"); | 121 UpdateMonitor("0+0-500x500,0+501-400x400"); |
123 EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); | 122 EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); |
124 EXPECT_EQ("1 1 0", GetCountSummary()); | 123 EXPECT_EQ("1 1 0", GetCountSummary()); |
125 EXPECT_EQ(monitor_manager()->GetMonitorAt(0), changed()[0]); | 124 EXPECT_EQ(monitor_manager()->GetMonitorAt(0).id(), changed()[0].id()); |
126 EXPECT_EQ(monitor_manager()->GetMonitorAt(1), added()[0]); | 125 EXPECT_EQ(monitor_manager()->GetMonitorAt(1).id(), added()[0].id()); |
127 EXPECT_EQ("0,0 500x500", changed()[0]->bounds().ToString()); | 126 EXPECT_EQ("0,0 500x500", changed()[0].bounds().ToString()); |
128 EXPECT_EQ("0,501 400x400", added()[0]->bounds().ToString()); | 127 EXPECT_EQ("0,501 400x400", added()[0].bounds().ToString()); |
129 reset(); | 128 reset(); |
130 | 129 |
131 // Delete secondary. | 130 // Delete secondary. |
132 UpdateMonitor("0+0-500x500"); | 131 UpdateMonitor("0+0-500x500"); |
133 EXPECT_EQ("0 0 1", GetCountSummary()); | 132 EXPECT_EQ("0 0 1", GetCountSummary()); |
134 reset(); | 133 reset(); |
135 | 134 |
136 // Change primary. | 135 // Change primary. |
137 UpdateMonitor("0+0-1000x600"); | 136 UpdateMonitor("0+0-1000x600"); |
138 EXPECT_EQ("1 0 0", GetCountSummary()); | 137 EXPECT_EQ("1 0 0", GetCountSummary()); |
139 EXPECT_EQ(monitor_manager()->GetMonitorAt(0), changed()[0]); | 138 EXPECT_EQ(monitor_manager()->GetMonitorAt(0).id(), changed()[0].id()); |
140 EXPECT_EQ("0,0 1000x600", changed()[0]->bounds().ToString()); | 139 EXPECT_EQ("0,0 1000x600", changed()[0].bounds().ToString()); |
141 reset(); | 140 reset(); |
142 | 141 |
143 // Add secondary. | 142 // Add secondary. |
144 UpdateMonitor("0+0-1000x600,1001+0-600x400"); | 143 UpdateMonitor("0+0-1000x600,1001+0-600x400"); |
145 EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); | 144 EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); |
146 EXPECT_EQ("0 1 0", GetCountSummary()); | 145 EXPECT_EQ("0 1 0", GetCountSummary()); |
147 EXPECT_EQ(monitor_manager()->GetMonitorAt(1), added()[0]); | 146 EXPECT_EQ(monitor_manager()->GetMonitorAt(1).id(), added()[0].id()); |
148 EXPECT_EQ("1001,0 600x400", added()[0]->bounds().ToString()); | 147 EXPECT_EQ("1001,0 600x400", added()[0].bounds().ToString()); |
149 reset(); | 148 reset(); |
150 | 149 |
151 // Secondary removed, primary changed. | 150 // Secondary removed, primary changed. |
152 UpdateMonitor("0+0-800x300"); | 151 UpdateMonitor("0+0-800x300"); |
153 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); | 152 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); |
154 EXPECT_EQ("1 0 1", GetCountSummary()); | 153 EXPECT_EQ("1 0 1", GetCountSummary()); |
155 EXPECT_EQ(monitor_manager()->GetMonitorAt(0), changed()[0]); | 154 EXPECT_EQ(monitor_manager()->GetMonitorAt(0).id(), changed()[0].id()); |
156 EXPECT_EQ("0,0 800x300", changed()[0]->bounds().ToString()); | 155 EXPECT_EQ("0,0 800x300", changed()[0].bounds().ToString()); |
157 reset(); | 156 reset(); |
158 | 157 |
159 // # of monitor can go to zero when screen is off. | 158 // # of monitor can go to zero when screen is off. |
160 const vector<const Monitor*> empty; | 159 const vector<Monitor> empty; |
161 monitor_manager()->OnNativeMonitorsChanged(empty); | 160 monitor_manager()->OnNativeMonitorsChanged(empty); |
162 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); | 161 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); |
163 EXPECT_EQ("0 0 0", GetCountSummary()); | 162 EXPECT_EQ("0 0 0", GetCountSummary()); |
164 EXPECT_FALSE(root_window_destroyed()); | 163 EXPECT_FALSE(root_window_destroyed()); |
165 // Monitor configuration stays the same | 164 // Monitor configuration stays the same |
166 EXPECT_EQ("0,0 800x300", | 165 EXPECT_EQ("0,0 800x300", |
167 monitor_manager()->GetMonitorAt(0)->bounds().ToString()); | 166 monitor_manager()->GetMonitorAt(0).bounds().ToString()); |
168 reset(); | 167 reset(); |
169 | 168 |
170 // Connect to monitor again | 169 // Connect to monitor again |
171 UpdateMonitor("100+100-500x400"); | 170 UpdateMonitor("100+100-500x400"); |
172 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); | 171 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); |
173 EXPECT_EQ("1 0 0", GetCountSummary()); | 172 EXPECT_EQ("1 0 0", GetCountSummary()); |
174 EXPECT_FALSE(root_window_destroyed()); | 173 EXPECT_FALSE(root_window_destroyed()); |
175 EXPECT_EQ("100,100 500x400", changed()[0]->bounds().ToString()); | 174 EXPECT_EQ("100,100 500x400", changed()[0].bounds().ToString()); |
176 reset(); | 175 reset(); |
177 | 176 |
178 // Go back to zero and wake up with multiple monitors. | 177 // Go back to zero and wake up with multiple monitors. |
179 monitor_manager()->OnNativeMonitorsChanged(empty); | 178 monitor_manager()->OnNativeMonitorsChanged(empty); |
180 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); | 179 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); |
181 EXPECT_FALSE(root_window_destroyed()); | 180 EXPECT_FALSE(root_window_destroyed()); |
182 reset(); | 181 reset(); |
183 | 182 |
184 // Add secondary. | 183 // Add secondary. |
185 UpdateMonitor("0+0-1000x600,1000+0-600x400"); | 184 UpdateMonitor("0+0-1000x600,1000+0-600x400"); |
186 EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); | 185 EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); |
187 EXPECT_EQ("0,0 1000x600", | 186 EXPECT_EQ("0,0 1000x600", |
188 monitor_manager()->GetMonitorAt(0)->bounds().ToString()); | 187 monitor_manager()->GetMonitorAt(0).bounds().ToString()); |
189 EXPECT_EQ("1000,0 600x400", | 188 EXPECT_EQ("1000,0 600x400", |
190 monitor_manager()->GetMonitorAt(1)->bounds().ToString()); | 189 monitor_manager()->GetMonitorAt(1).bounds().ToString()); |
191 reset(); | 190 reset(); |
192 | 191 |
193 aura::MonitorManager::set_use_fullscreen_host_window(false); | 192 aura::MonitorManager::set_use_fullscreen_host_window(false); |
194 } | 193 } |
195 | 194 |
196 // Test in emulation mode (use_fullscreen_host_window=false) | 195 // Test in emulation mode (use_fullscreen_host_window=false) |
197 TEST_F(MultiMonitorManagerTest, EmulatorTest) { | 196 TEST_F(MultiMonitorManagerTest, EmulatorTest) { |
198 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); | 197 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); |
199 | 198 |
200 internal::MultiMonitorManager::AddRemoveMonitor(); | 199 internal::MultiMonitorManager::AddRemoveMonitor(); |
(...skipping 22 matching lines...) Expand all Loading... |
223 reset(); | 222 reset(); |
224 | 223 |
225 internal::MultiMonitorManager::CycleMonitor(); | 224 internal::MultiMonitorManager::CycleMonitor(); |
226 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); | 225 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); |
227 EXPECT_EQ("0 0 0", GetCountSummary()); | 226 EXPECT_EQ("0 0 0", GetCountSummary()); |
228 reset(); | 227 reset(); |
229 } | 228 } |
230 | 229 |
231 } // namespace test | 230 } // namespace test |
232 } // namespace ash | 231 } // namespace ash |
OLD | NEW |