Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/string_number_conversions.h" | |
| 11 #include "services/ui/display/platform_screen.h" | 12 #include "services/ui/display/platform_screen.h" |
| 12 #include "services/ui/display/platform_screen_ozone.h" | 13 #include "services/ui/display/platform_screen_ozone.h" |
| 13 #include "services/ui/display/viewport_metrics.h" | 14 #include "services/ui/display/viewport_metrics.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "ui/display/chromeos/display_configurator.h" | |
| 17 #include "ui/display/display_switches.h" | 17 #include "ui/display/display_switches.h" |
| 18 #include "ui/display/fake_display_snapshot.h" | 18 #include "ui/display/fake_display_snapshot.h" |
| 19 #include "ui/display/types/display_constants.h" | 19 #include "ui/display/types/display_constants.h" |
| 20 #include "ui/display/types/display_mode.h" | 20 #include "ui/display/types/display_mode.h" |
| 21 #include "ui/display/types/display_snapshot.h" | 21 #include "ui/display/types/display_snapshot.h" |
| 22 #include "ui/ozone/public/ozone_platform.h" | 22 #include "ui/ozone/public/ozone_platform.h" |
| 23 | 23 |
| 24 namespace display { | 24 namespace display { |
| 25 | 25 |
| 26 using ui::DisplayConfigurator; | |
| 27 using ui::DisplayMode; | 26 using ui::DisplayMode; |
| 28 using ui::DisplaySnapshot; | 27 using ui::DisplaySnapshot; |
| 29 using ui::DisplaySnapshotVirtual; | |
| 30 using testing::IsEmpty; | 28 using testing::IsEmpty; |
| 31 using testing::SizeIs; | 29 using testing::SizeIs; |
| 32 | 30 |
| 33 namespace { | 31 namespace { |
| 34 | 32 |
| 35 // The ID of default "display" that gets added when running off device. | |
| 36 const int64_t kDefaultDisplayId = 1; | |
| 37 | |
| 38 // Holds info about the display state we want to test. | 33 // Holds info about the display state we want to test. |
| 39 struct DisplayState { | 34 struct DisplayState { |
| 40 int64_t id; | 35 int64_t id; |
| 41 ViewportMetrics metrics; | 36 ViewportMetrics metrics; |
| 42 }; | 37 }; |
| 43 | 38 |
| 44 // Matchers that operate on DisplayState. | 39 // Matchers that operate on DisplayState. |
| 45 MATCHER_P(DisplayId, display_id, "") { | 40 MATCHER_P(DisplayId, display_id, "") { |
| 46 *result_listener << "has id " << arg.id; | 41 *result_listener << "has id " << arg.id; |
| 47 return arg.id == display_id; | 42 return arg.id == display_id; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 67 .Build(); | 62 .Build(); |
| 68 } | 63 } |
| 69 | 64 |
| 70 // Test delegate to track what functions calls the delegate receives. | 65 // Test delegate to track what functions calls the delegate receives. |
| 71 class TestPlatformScreenDelegate : public PlatformScreenDelegate { | 66 class TestPlatformScreenDelegate : public PlatformScreenDelegate { |
| 72 public: | 67 public: |
| 73 TestPlatformScreenDelegate() {} | 68 TestPlatformScreenDelegate() {} |
| 74 ~TestPlatformScreenDelegate() override {} | 69 ~TestPlatformScreenDelegate() override {} |
| 75 | 70 |
| 76 std::vector<DisplayState> added() { return added_; } | 71 std::vector<DisplayState> added() { return added_; } |
| 77 std::vector<DisplayState> removed() { return removed_; } | |
| 78 std::vector<DisplayState> modified() { return modified_; } | 72 std::vector<DisplayState> modified() { return modified_; } |
| 73 std::string changes() { return changes_; } | |
|
sky
2016/10/28 17:08:47
const std::string& changes() const
Please also doc
kylechar
2016/10/28 19:40:36
Done.
| |
| 79 | 74 |
| 80 void Reset() { | 75 void Reset() { |
| 81 added_.clear(); | 76 added_.clear(); |
| 82 removed_.clear(); | |
| 83 modified_.clear(); | 77 modified_.clear(); |
| 78 changes_.clear(); | |
| 84 } | 79 } |
| 85 | 80 |
| 86 private: | 81 private: |
| 82 void AddChange(const std::string& name, const std::string& value) { | |
| 83 if (!changes_.empty()) | |
| 84 changes_ += ";"; | |
| 85 changes_ += name + "(" + value + ")"; | |
| 86 } | |
| 87 | |
| 87 void OnDisplayAdded(int64_t id, const ViewportMetrics& metrics) override { | 88 void OnDisplayAdded(int64_t id, const ViewportMetrics& metrics) override { |
| 88 added_.push_back({id, metrics}); | 89 added_.push_back({id, metrics}); |
| 90 AddChange("Added", base::Int64ToString(id)); | |
| 89 } | 91 } |
| 90 | 92 |
| 91 void OnDisplayRemoved(int64_t id) override { | 93 void OnDisplayRemoved(int64_t id) override { |
| 92 removed_.push_back({id, ViewportMetrics()}); | 94 AddChange("Removed", base::Int64ToString(id)); |
| 93 } | 95 } |
| 94 | 96 |
| 95 void OnDisplayModified(int64_t id, const ViewportMetrics& metrics) override { | 97 void OnDisplayModified(int64_t id, const ViewportMetrics& metrics) override { |
| 96 modified_.push_back({id, metrics}); | 98 modified_.push_back({id, metrics}); |
| 99 AddChange("Modified", base::Int64ToString(id)); | |
| 100 } | |
| 101 | |
| 102 void OnPrimaryDisplayChanged(int64_t primary_display_id) override { | |
| 103 AddChange("Primary", base::Int64ToString(primary_display_id)); | |
| 97 } | 104 } |
| 98 | 105 |
| 99 std::vector<DisplayState> added_; | 106 std::vector<DisplayState> added_; |
| 100 std::vector<DisplayState> removed_; | |
| 101 std::vector<DisplayState> modified_; | 107 std::vector<DisplayState> modified_; |
| 108 std::string changes_; | |
| 102 | 109 |
| 103 DISALLOW_COPY_AND_ASSIGN(TestPlatformScreenDelegate); | 110 DISALLOW_COPY_AND_ASSIGN(TestPlatformScreenDelegate); |
| 104 }; | 111 }; |
| 105 | 112 |
| 113 } // namespace | |
| 114 | |
| 106 // Test fixture with helpers to act like ui::DisplayConfigurator and send | 115 // Test fixture with helpers to act like ui::DisplayConfigurator and send |
| 107 // OnDisplayModeChanged() to PlatformScreenOzone. | 116 // OnDisplayModeChanged() to PlatformScreenOzone. |
| 108 class PlatformScreenOzoneTest : public testing::Test { | 117 class PlatformScreenOzoneTest : public testing::Test { |
| 109 public: | 118 public: |
| 110 PlatformScreenOzoneTest() {} | 119 PlatformScreenOzoneTest() {} |
| 111 ~PlatformScreenOzoneTest() override {} | 120 ~PlatformScreenOzoneTest() override {} |
| 112 | 121 |
| 113 PlatformScreen* platform_screen() { return platform_screen_.get(); } | 122 PlatformScreenOzone* platform_screen() { return platform_screen_.get(); } |
| 114 TestPlatformScreenDelegate* delegate() { return &delegate_; } | 123 TestPlatformScreenDelegate* delegate() { return &delegate_; } |
| 115 | 124 |
| 116 // Adds a display snapshot with specified ID and default size. | 125 // Adds a display snapshot with specified ID and default size. |
| 117 void AddDisplay(int64_t id) { return AddDisplay(id, gfx::Size(1024, 768)); } | 126 void AddDisplay(int64_t id) { return AddDisplay(id, gfx::Size(1024, 768)); } |
| 118 | 127 |
| 119 // Adds a display snapshot with specified ID and size to list of snapshots. | 128 // Adds a display snapshot with specified ID and size to list of snapshots. |
| 120 void AddDisplay(int64_t id, const gfx::Size& size) { | 129 void AddDisplay(int64_t id, const gfx::Size& size) { |
| 121 snapshots_.push_back(MakeSnapshot(id, size)); | 130 snapshots_.push_back(MakeSnapshot(id, size)); |
| 131 TriggerOnDisplayModeChanged(); | |
| 122 } | 132 } |
| 123 | 133 |
| 124 // Removes display snapshot with specified ID. | 134 // Removes display snapshot with specified ID. |
| 125 void RemoveDisplay(int64_t id) { | 135 void RemoveDisplay(int64_t id) { |
| 126 snapshots_.erase( | 136 snapshots_.erase( |
| 127 std::remove_if(snapshots_.begin(), snapshots_.end(), | 137 std::remove_if(snapshots_.begin(), snapshots_.end(), |
| 128 [id](std::unique_ptr<DisplaySnapshot>& snapshot) { | 138 [id](std::unique_ptr<DisplaySnapshot>& snapshot) { |
| 129 return snapshot->display_id() == id; | 139 return snapshot->display_id() == id; |
| 130 })); | 140 })); |
| 141 TriggerOnDisplayModeChanged(); | |
| 131 } | 142 } |
| 132 | 143 |
| 133 // Modify the size of the display snapshot with specified ID. | 144 // Modify the size of the display snapshot with specified ID. |
| 134 void ModifyDisplay(int64_t id, const gfx::Size& size) { | 145 void ModifyDisplay(int64_t id, const gfx::Size& size) { |
| 135 DisplaySnapshot* snapshot = GetSnapshotById(id); | 146 DisplaySnapshot* snapshot = GetSnapshotById(id); |
| 136 | 147 |
| 137 const DisplayMode* new_mode = nullptr; | 148 const DisplayMode* new_mode = nullptr; |
| 138 for (auto& mode : snapshot->modes()) { | 149 for (auto& mode : snapshot->modes()) { |
| 139 if (mode->size() == size) { | 150 if (mode->size() == size) { |
| 140 new_mode = mode.get(); | 151 new_mode = mode.get(); |
| 141 break; | 152 break; |
| 142 } | 153 } |
| 143 } | 154 } |
| 144 | 155 |
| 145 if (!new_mode) { | 156 if (!new_mode) { |
| 146 snapshot->add_mode(new DisplayMode(size, false, 30.0f)); | 157 snapshot->add_mode(new DisplayMode(size, false, 30.0f)); |
| 147 new_mode = snapshot->modes().back().get(); | 158 new_mode = snapshot->modes().back().get(); |
| 148 } | 159 } |
| 149 | 160 |
| 150 snapshot->set_current_mode(new_mode); | 161 snapshot->set_current_mode(new_mode); |
| 162 TriggerOnDisplayModeChanged(); | |
| 151 } | 163 } |
| 152 | 164 |
| 153 // Calls OnDisplayModeChanged with our list of display snapshots. | 165 // Calls OnDisplayModeChanged with our list of display snapshots. |
| 154 void TriggerOnDisplayModeChanged() { | 166 void TriggerOnDisplayModeChanged() { |
| 155 std::vector<DisplaySnapshot*> snapshots_ptrs; | 167 std::vector<DisplaySnapshot*> snapshots_ptrs; |
| 156 for (auto& snapshot : snapshots_) { | 168 for (auto& snapshot : snapshots_) { |
| 157 snapshots_ptrs.push_back(snapshot.get()); | 169 snapshots_ptrs.push_back(snapshot.get()); |
| 158 } | 170 } |
| 159 static_cast<DisplayConfigurator::Observer*>(platform_screen_.get()) | 171 platform_screen_->OnDisplayModeChanged(snapshots_ptrs); |
| 160 ->OnDisplayModeChanged(snapshots_ptrs); | |
| 161 } | 172 } |
| 162 | 173 |
| 163 private: | 174 private: |
| 164 DisplaySnapshot* GetSnapshotById(int64_t id) { | 175 DisplaySnapshot* GetSnapshotById(int64_t id) { |
| 165 for (auto& snapshot : snapshots_) { | 176 for (auto& snapshot : snapshots_) { |
| 166 if (snapshot->display_id() == id) | 177 if (snapshot->display_id() == id) |
| 167 return snapshot.get(); | 178 return snapshot.get(); |
| 168 } | 179 } |
| 169 return nullptr; | 180 return nullptr; |
| 170 } | 181 } |
| 171 | 182 |
| 172 // testing::Test: | 183 // testing::Test: |
| 173 void SetUp() override { | 184 void SetUp() override { |
| 174 base::CommandLine::ForCurrentProcess()->AppendSwitchNative( | 185 base::CommandLine::ForCurrentProcess()->AppendSwitchNative( |
| 175 switches::kScreenConfig, "none"); | 186 switches::kScreenConfig, "none"); |
| 176 | 187 |
| 177 testing::Test::SetUp(); | 188 testing::Test::SetUp(); |
| 178 ui::OzonePlatform::InitializeForUI(); | 189 ui::OzonePlatform::InitializeForUI(); |
| 179 platform_screen_ = base::MakeUnique<PlatformScreenOzone>(); | 190 platform_screen_ = base::MakeUnique<PlatformScreenOzone>(); |
| 180 platform_screen_->Init(&delegate_); | 191 platform_screen_->Init(&delegate_); |
| 181 | 192 |
| 182 // Have all tests start with a 1024x768 display by default. | 193 // Have all tests start with a 1024x768 display by default. |
| 183 AddDisplay(kDefaultDisplayId, gfx::Size(1024, 768)); | 194 AddDisplay(1, gfx::Size(1024, 768)); |
| 184 TriggerOnDisplayModeChanged(); | 195 TriggerOnDisplayModeChanged(); |
| 185 | 196 |
| 186 // Double check the expected display exists and clear counters. | 197 // Double check the expected display exists and clear counters. |
| 187 ASSERT_THAT(delegate()->added(), SizeIs(1)); | 198 ASSERT_THAT(delegate()->added(), SizeIs(1)); |
| 188 ASSERT_THAT(delegate_.added()[0], DisplayId(kDefaultDisplayId)); | 199 ASSERT_THAT(delegate_.added()[0], DisplayId(1)); |
| 189 ASSERT_THAT(delegate_.added()[0], DisplayOrigin("0,0")); | 200 ASSERT_THAT(delegate_.added()[0], DisplayOrigin("0,0")); |
| 190 ASSERT_THAT(delegate_.added()[0], DisplaySize("1024x768")); | 201 ASSERT_THAT(delegate_.added()[0], DisplaySize("1024x768")); |
| 202 ASSERT_EQ("Added(1);Primary(1)", delegate()->changes()); | |
| 191 delegate_.Reset(); | 203 delegate_.Reset(); |
| 192 } | 204 } |
| 193 | 205 |
| 194 void TearDown() override { | 206 void TearDown() override { |
| 195 snapshots_.clear(); | 207 snapshots_.clear(); |
| 196 delegate_.Reset(); | 208 delegate_.Reset(); |
| 197 platform_screen_.reset(); | 209 platform_screen_.reset(); |
| 198 } | 210 } |
| 199 | 211 |
| 200 TestPlatformScreenDelegate delegate_; | 212 TestPlatformScreenDelegate delegate_; |
| 201 std::unique_ptr<PlatformScreenOzone> platform_screen_; | 213 std::unique_ptr<PlatformScreenOzone> platform_screen_; |
| 202 std::vector<std::unique_ptr<DisplaySnapshot>> snapshots_; | 214 std::vector<std::unique_ptr<DisplaySnapshot>> snapshots_; |
| 203 }; | 215 }; |
| 204 | 216 |
| 205 } // namespace | |
| 206 | |
| 207 TEST_F(PlatformScreenOzoneTest, AddDisplay) { | 217 TEST_F(PlatformScreenOzoneTest, AddDisplay) { |
| 208 AddDisplay(2); | 218 AddDisplay(2); |
| 209 TriggerOnDisplayModeChanged(); | |
| 210 | 219 |
| 211 // Check that display 2 was added. | 220 // Check that display 2 was added. |
| 212 ASSERT_THAT(delegate()->added(), SizeIs(1)); | 221 EXPECT_EQ("Added(2)", delegate()->changes()); |
| 213 EXPECT_THAT(delegate()->added()[0], DisplayId(2)); | |
| 214 EXPECT_THAT(delegate()->removed(), IsEmpty()); | |
| 215 EXPECT_THAT(delegate()->modified(), IsEmpty()); | |
| 216 } | 222 } |
| 217 | 223 |
| 218 TEST_F(PlatformScreenOzoneTest, RemoveDisplay) { | 224 TEST_F(PlatformScreenOzoneTest, RemoveDisplay) { |
| 219 AddDisplay(2); | 225 AddDisplay(2); |
| 220 TriggerOnDisplayModeChanged(); | |
| 221 delegate()->Reset(); | 226 delegate()->Reset(); |
| 222 | 227 |
| 223 RemoveDisplay(2); | 228 RemoveDisplay(2); |
| 224 TriggerOnDisplayModeChanged(); | |
| 225 | 229 |
| 226 // Check that display 2 was removed. | 230 // Check that display 2 was removed. |
| 227 ASSERT_THAT(delegate()->removed(), SizeIs(1)); | 231 EXPECT_EQ("Removed(2)", delegate()->changes()); |
| 228 EXPECT_THAT(delegate()->removed()[0], DisplayId(2)); | |
| 229 EXPECT_THAT(delegate()->added(), IsEmpty()); | |
| 230 EXPECT_THAT(delegate()->modified(), IsEmpty()); | |
| 231 } | 232 } |
| 232 | 233 |
| 233 TEST_F(PlatformScreenOzoneTest, RemoveFirstDisplay) { | 234 TEST_F(PlatformScreenOzoneTest, RemoveFirstDisplay) { |
| 234 AddDisplay(2); | 235 AddDisplay(2); |
| 235 TriggerOnDisplayModeChanged(); | |
| 236 delegate()->Reset(); | 236 delegate()->Reset(); |
| 237 | 237 |
| 238 RemoveDisplay(kDefaultDisplayId); | 238 RemoveDisplay(1); |
| 239 TriggerOnDisplayModeChanged(); | |
| 240 | 239 |
| 241 // Check that the default display was removed and display 2 was modified due | 240 // Check that display 1 was removed and display 2 was modified due to the |
| 242 // to the origin changing. | 241 // origin changing. |
| 243 EXPECT_THAT(delegate()->added(), IsEmpty()); | 242 EXPECT_EQ("Primary(2);Removed(1);Modified(2)", delegate()->changes()); |
| 244 ASSERT_THAT(delegate()->removed(), SizeIs(1)); | |
| 245 EXPECT_THAT(delegate()->removed()[0], DisplayId(kDefaultDisplayId)); | |
| 246 | |
| 247 ASSERT_THAT(delegate()->modified(), SizeIs(1)); | 243 ASSERT_THAT(delegate()->modified(), SizeIs(1)); |
| 248 EXPECT_THAT(delegate()->modified()[0], DisplayId(2)); | 244 EXPECT_THAT(delegate()->modified()[0], DisplayId(2)); |
| 249 EXPECT_THAT(delegate()->modified()[0], DisplayOrigin("0,0")); | 245 EXPECT_THAT(delegate()->modified()[0], DisplayOrigin("0,0")); |
| 250 } | 246 } |
| 251 | 247 |
| 252 TEST_F(PlatformScreenOzoneTest, RemovePrimaryDisplay) { | |
| 253 EXPECT_EQ(kDefaultDisplayId, platform_screen()->GetPrimaryDisplayId()); | |
| 254 | |
| 255 AddDisplay(2); | |
| 256 RemoveDisplay(kDefaultDisplayId); | |
| 257 TriggerOnDisplayModeChanged(); | |
| 258 | |
| 259 // Check the primary display changed because the old primary was removed. | |
| 260 EXPECT_EQ(2, platform_screen()->GetPrimaryDisplayId()); | |
| 261 } | |
| 262 | |
| 263 TEST_F(PlatformScreenOzoneTest, RemoveMultipleDisplay) { | 248 TEST_F(PlatformScreenOzoneTest, RemoveMultipleDisplay) { |
| 264 AddDisplay(2); | 249 AddDisplay(2); |
| 265 AddDisplay(3); | 250 AddDisplay(3); |
| 266 TriggerOnDisplayModeChanged(); | |
| 267 delegate()->Reset(); | 251 delegate()->Reset(); |
| 268 | 252 |
| 269 RemoveDisplay(2); | 253 RemoveDisplay(2); |
| 270 TriggerOnDisplayModeChanged(); | 254 RemoveDisplay(3); |
| 271 | 255 |
| 272 // Check that display 2 was removed. | 256 // Check that display 2 was removed and display 3 is modifed (origin change), |
| 273 ASSERT_THAT(delegate()->removed(), SizeIs(1)); | 257 // then display 3 was removed. |
| 274 EXPECT_THAT(delegate()->removed()[0], DisplayId(2)); | 258 EXPECT_EQ("Removed(2);Modified(3);Removed(3)", delegate()->changes()); |
| 275 | |
| 276 delegate()->Reset(); | |
| 277 RemoveDisplay(3); | |
| 278 TriggerOnDisplayModeChanged(); | |
| 279 | |
| 280 // Check that display 3 was removed. | |
| 281 ASSERT_THAT(delegate()->removed(), SizeIs(1)); | |
| 282 EXPECT_THAT(delegate()->removed()[0], DisplayId(3)); | |
| 283 } | 259 } |
| 284 | 260 |
| 285 TEST_F(PlatformScreenOzoneTest, ModifyDisplaySize) { | 261 TEST_F(PlatformScreenOzoneTest, ModifyDisplaySize) { |
| 286 const gfx::Size size1(1920, 1200); | 262 const gfx::Size size1(1920, 1200); |
| 287 const gfx::Size size2(1680, 1050); | 263 const gfx::Size size2(1680, 1050); |
| 288 | 264 |
| 289 AddDisplay(2, size1); | 265 AddDisplay(2, size1); |
| 290 TriggerOnDisplayModeChanged(); | |
| 291 | 266 |
| 292 // Check that display 2 was added with expected size. | 267 // Check that display 2 was added with expected size. |
| 293 ASSERT_THAT(delegate()->added(), SizeIs(1)); | 268 ASSERT_THAT(delegate()->added(), SizeIs(1)); |
| 294 EXPECT_THAT(delegate()->added()[0], DisplayId(2)); | 269 EXPECT_THAT(delegate()->added()[0], DisplayId(2)); |
| 295 EXPECT_THAT(delegate()->added()[0], DisplaySize(size1.ToString())); | 270 EXPECT_THAT(delegate()->added()[0], DisplaySize(size1.ToString())); |
| 271 EXPECT_EQ("Added(2)", delegate()->changes()); | |
| 296 delegate()->Reset(); | 272 delegate()->Reset(); |
| 297 | 273 |
| 298 ModifyDisplay(2, size2); | 274 ModifyDisplay(2, size2); |
| 299 TriggerOnDisplayModeChanged(); | |
| 300 | 275 |
| 301 // Check that display 2 was modified to have the new expected size. | 276 // Check that display 2 was modified to have the new expected size. |
| 302 ASSERT_THAT(delegate()->modified(), SizeIs(1)); | 277 ASSERT_THAT(delegate()->modified(), SizeIs(1)); |
| 303 EXPECT_THAT(delegate()->modified()[0], DisplayId(2)); | 278 EXPECT_THAT(delegate()->modified()[0], DisplayId(2)); |
| 304 EXPECT_THAT(delegate()->modified()[0], DisplaySize(size2.ToString())); | 279 EXPECT_THAT(delegate()->modified()[0], DisplaySize(size2.ToString())); |
| 280 EXPECT_EQ("Modified(2)", delegate()->changes()); | |
| 305 } | 281 } |
| 306 | 282 |
| 307 TEST_F(PlatformScreenOzoneTest, ModifyFirstDisplaySize) { | 283 TEST_F(PlatformScreenOzoneTest, ModifyFirstDisplaySize) { |
| 308 const gfx::Size size(1920, 1200); | 284 const gfx::Size size(1920, 1200); |
| 309 | 285 |
| 310 AddDisplay(2, size); | 286 AddDisplay(2, size); |
| 311 TriggerOnDisplayModeChanged(); | |
| 312 | 287 |
| 313 // Check that display two has the expected initial origin. | 288 // Check that display 2 has the expected initial origin. |
| 289 EXPECT_EQ("Added(2)", delegate()->changes()); | |
| 314 ASSERT_THAT(delegate()->added(), SizeIs(1)); | 290 ASSERT_THAT(delegate()->added(), SizeIs(1)); |
| 315 EXPECT_THAT(delegate()->added()[0], DisplayOrigin("1024,0")); | 291 EXPECT_THAT(delegate()->added()[0], DisplayOrigin("1024,0")); |
| 316 delegate()->Reset(); | 292 delegate()->Reset(); |
| 317 | 293 |
| 318 ModifyDisplay(kDefaultDisplayId, size); | 294 ModifyDisplay(1, size); |
| 319 TriggerOnDisplayModeChanged(); | |
| 320 | 295 |
| 321 // Check that the default display was modified with a new size and display 2 | 296 // Check that display 1 was modified with a new size and display 2 origin was |
| 322 // was modified with a new origin. | 297 // modified after. |
| 298 EXPECT_EQ("Modified(1);Modified(2)", delegate()->changes()); | |
| 323 ASSERT_THAT(delegate()->modified(), SizeIs(2)); | 299 ASSERT_THAT(delegate()->modified(), SizeIs(2)); |
| 324 EXPECT_THAT(delegate()->modified()[0], DisplayId(kDefaultDisplayId)); | 300 EXPECT_THAT(delegate()->modified()[0], DisplayId(1)); |
| 325 EXPECT_THAT(delegate()->modified()[0], DisplaySize(size.ToString())); | 301 EXPECT_THAT(delegate()->modified()[0], DisplaySize(size.ToString())); |
| 326 EXPECT_THAT(delegate()->modified()[1], DisplayId(2)); | 302 EXPECT_THAT(delegate()->modified()[1], DisplayId(2)); |
| 327 EXPECT_THAT(delegate()->modified()[1], DisplayOrigin("1920,0")); | 303 EXPECT_THAT(delegate()->modified()[1], DisplayOrigin("1920,0")); |
| 328 } | 304 } |
| 329 | 305 |
| 306 TEST_F(PlatformScreenOzoneTest, RemovePrimaryDisplay) { | |
| 307 AddDisplay(2); | |
| 308 delegate()->Reset(); | |
| 309 | |
| 310 RemoveDisplay(1); | |
| 311 | |
| 312 // Check the primary display changed because the old primary was removed. | |
| 313 EXPECT_EQ("Primary(2);Removed(1);Modified(2)", delegate()->changes()); | |
| 314 } | |
| 315 | |
| 316 TEST_F(PlatformScreenOzoneTest, RemoveLastDisplay) { | |
| 317 RemoveDisplay(1); | |
| 318 | |
| 319 // Check that the primary display was set to kInvalidDisplay then display 1 | |
| 320 // was removed. | |
| 321 EXPECT_EQ("Primary(-1);Removed(1)", delegate()->changes()); | |
| 322 } | |
| 323 | |
| 324 TEST_F(PlatformScreenOzoneTest, SwapPrimaryDisplay) { | |
| 325 AddDisplay(2); | |
| 326 delegate()->Reset(); | |
| 327 | |
| 328 platform_screen()->SwapPrimaryDisplay(); | |
| 329 EXPECT_EQ("Primary(2)", delegate()->changes()); | |
| 330 } | |
| 331 | |
| 332 TEST_F(PlatformScreenOzoneTest, SwapPrimaryThreeDisplays) { | |
| 333 AddDisplay(2); | |
| 334 AddDisplay(3); | |
| 335 EXPECT_EQ("Added(2);Added(3)", delegate()->changes()); | |
| 336 delegate()->Reset(); | |
| 337 | |
| 338 platform_screen()->SwapPrimaryDisplay(); | |
| 339 platform_screen()->SwapPrimaryDisplay(); | |
| 340 platform_screen()->SwapPrimaryDisplay(); | |
| 341 EXPECT_EQ("Primary(2);Primary(3);Primary(1)", delegate()->changes()); | |
| 342 } | |
| 343 | |
| 330 } // namespace display | 344 } // namespace display |
| OLD | NEW |