| 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/stl_util.h" |
| 11 #include "base/string_split.h" |
| 12 #include "base/stringprintf.h" |
| 13 #include "ui/aura/env.h" |
| 14 #include "ui/aura/monitor.h" |
| 15 #include "ui/aura/root_window.h" |
| 16 |
| 17 namespace ash { |
| 18 namespace test { |
| 19 |
| 20 using std::vector; |
| 21 using std::string; |
| 22 using aura::Monitor; |
| 23 |
| 24 namespace { |
| 25 |
| 26 vector<const aura::Monitor*> CreateMonitorsFromString( |
| 27 const std::string specs) { |
| 28 vector<const aura::Monitor*> monitors; |
| 29 vector<string> parts; |
| 30 base::SplitString(specs, ',', &parts); |
| 31 for (vector<string>::const_iterator iter = parts.begin(); |
| 32 iter != parts.end(); ++iter) { |
| 33 monitors.push_back(aura::MonitorManager::CreateMonitorFromSpec(*iter)); |
| 34 } |
| 35 return monitors; |
| 36 } |
| 37 |
| 38 } // namespace |
| 39 |
| 40 class MultiMonitorManagerTest : public test::AshTestBase, |
| 41 public aura::MonitorObserver { |
| 42 public: |
| 43 MultiMonitorManagerTest() : removed_count_(0U) {} |
| 44 virtual ~MultiMonitorManagerTest() {} |
| 45 |
| 46 virtual void SetUp() OVERRIDE { |
| 47 AshTestBase::SetUp(); |
| 48 monitor_manager()->AddObserver(this); |
| 49 } |
| 50 virtual void TearDown() OVERRIDE { |
| 51 monitor_manager()->RemoveObserver(this); |
| 52 AshTestBase::TearDown(); |
| 53 } |
| 54 |
| 55 aura::MonitorManager* monitor_manager() { |
| 56 return aura::Env::GetInstance()->monitor_manager(); |
| 57 } |
| 58 const vector<const Monitor*>& changed() const { return changed_; } |
| 59 const vector<const Monitor*>& added() const { return added_; } |
| 60 |
| 61 string GetCountSummary() const { |
| 62 return StringPrintf("%"PRIuS" %"PRIuS" %"PRIuS, |
| 63 changed_.size(), added_.size(), removed_count_); |
| 64 } |
| 65 |
| 66 void reset() { |
| 67 changed_.clear(); |
| 68 added_.clear(); |
| 69 removed_count_ = 0U; |
| 70 } |
| 71 |
| 72 // aura::MonitorObserver overrides: |
| 73 virtual void OnMonitorBoundsChanged(const Monitor* monitor) OVERRIDE { |
| 74 changed_.push_back(monitor); |
| 75 } |
| 76 virtual void OnMonitorAdded(Monitor* new_monitor) OVERRIDE { |
| 77 added_.push_back(new_monitor); |
| 78 } |
| 79 virtual void OnMonitorRemoved(const Monitor* old_monitor) OVERRIDE { |
| 80 ++removed_count_; |
| 81 } |
| 82 |
| 83 void UpdateMonitor(const std::string str) { |
| 84 vector<const aura::Monitor*> monitors = CreateMonitorsFromString(str); |
| 85 monitor_manager()->OnNativeMonitorsChanged(monitors); |
| 86 STLDeleteContainerPointers(monitors.begin(), monitors.end()); |
| 87 } |
| 88 |
| 89 private: |
| 90 vector<const Monitor*> changed_; |
| 91 vector<const Monitor*> added_; |
| 92 size_t removed_count_; |
| 93 |
| 94 DISALLOW_COPY_AND_ASSIGN(MultiMonitorManagerTest); |
| 95 }; |
| 96 |
| 97 TEST_F(MultiMonitorManagerTest, NativeMonitorTest) { |
| 98 aura::MonitorManager::set_use_fullscreen_host_window(true); |
| 99 |
| 100 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); |
| 101 |
| 102 // Update primary and add seconary. |
| 103 UpdateMonitor("0+0-500x500,0+501-400x400"); |
| 104 EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); |
| 105 EXPECT_EQ("1 1 0", GetCountSummary()); |
| 106 EXPECT_EQ(monitor_manager()->GetMonitorAt(0), changed()[0]); |
| 107 EXPECT_EQ(monitor_manager()->GetMonitorAt(1), added()[0]); |
| 108 EXPECT_EQ("0,0 500x500", changed()[0]->bounds().ToString()); |
| 109 EXPECT_EQ("0,501 400x400", added()[0]->bounds().ToString()); |
| 110 reset(); |
| 111 |
| 112 // Delete secondary. |
| 113 UpdateMonitor("0+0-500x500"); |
| 114 EXPECT_EQ("0 0 1", GetCountSummary()); |
| 115 reset(); |
| 116 |
| 117 // Change primary. |
| 118 UpdateMonitor("0+0-1000x600"); |
| 119 EXPECT_EQ("1 0 0", GetCountSummary()); |
| 120 EXPECT_EQ(monitor_manager()->GetMonitorAt(0), changed()[0]); |
| 121 EXPECT_EQ("0,0 1000x600", changed()[0]->bounds().ToString()); |
| 122 reset(); |
| 123 |
| 124 // Add secondary. |
| 125 UpdateMonitor("0+0-1000x600,1001+0-600x400"); |
| 126 EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); |
| 127 EXPECT_EQ("0 1 0", GetCountSummary()); |
| 128 EXPECT_EQ(monitor_manager()->GetMonitorAt(1), added()[0]); |
| 129 EXPECT_EQ("1001,0 600x400", added()[0]->bounds().ToString()); |
| 130 reset(); |
| 131 |
| 132 // Secondary removed, primary changed. |
| 133 UpdateMonitor("0+0-800x300"); |
| 134 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); |
| 135 EXPECT_EQ("1 0 1", GetCountSummary()); |
| 136 EXPECT_EQ(monitor_manager()->GetMonitorAt(0), changed()[0]); |
| 137 EXPECT_EQ("0,0 800x300", changed()[0]->bounds().ToString()); |
| 138 |
| 139 aura::MonitorManager::set_use_fullscreen_host_window(false); |
| 140 } |
| 141 |
| 142 // Test in emulation mode (use_fullscreen_host_window=false) |
| 143 TEST_F(MultiMonitorManagerTest, EmulatorTest) { |
| 144 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); |
| 145 |
| 146 internal::MultiMonitorManager::AddRemoveMonitor(); |
| 147 // Update primary and add seconary. |
| 148 EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); |
| 149 #if defined(OS_WIN) |
| 150 // TODO(oshima): Windows receives resize event for some reason. |
| 151 EXPECT_EQ("1 1 0", GetCountSummary()); |
| 152 #else |
| 153 EXPECT_EQ("0 1 0", GetCountSummary()); |
| 154 #endif |
| 155 reset(); |
| 156 |
| 157 internal::MultiMonitorManager::CycleMonitor(); |
| 158 EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); |
| 159 // Observer gets called twice in this mode because |
| 160 // it gets notified both from |OnNativeMonitorChagned| |
| 161 // and from |RootWindowObserver|, which is the consequence of |
| 162 // |SetHostSize()|. |
| 163 EXPECT_EQ("4 0 0", GetCountSummary()); |
| 164 reset(); |
| 165 |
| 166 internal::MultiMonitorManager::AddRemoveMonitor(); |
| 167 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); |
| 168 EXPECT_EQ("0 0 1", GetCountSummary()); |
| 169 reset(); |
| 170 |
| 171 internal::MultiMonitorManager::CycleMonitor(); |
| 172 EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); |
| 173 EXPECT_EQ("0 0 0", GetCountSummary()); |
| 174 reset(); |
| 175 } |
| 176 |
| 177 } // namespace test |
| 178 } // namespace ash |
| OLD | NEW |