| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <X11/extensions/Xrandr.h> | 6 #include <X11/extensions/Xrandr.h> |
| 7 | 7 |
| 8 #undef Bool | 8 #undef Bool |
| 9 #undef None | 9 #undef None |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/test/simple_test_tick_clock.h" | 12 #include "base/test/simple_test_tick_clock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/display/chromeos/x11/display_mode_x11.h" | 14 #include "ui/display/manager/chromeos/x11/display_mode_x11.h" |
| 15 #include "ui/display/chromeos/x11/display_snapshot_x11.h" | 15 #include "ui/display/manager/chromeos/x11/display_snapshot_x11.h" |
| 16 #include "ui/display/chromeos/x11/native_display_delegate_x11.h" | 16 #include "ui/display/manager/chromeos/x11/native_display_delegate_x11.h" |
| 17 #include "ui/display/chromeos/x11/native_display_event_dispatcher_x11.h" | 17 #include "ui/display/manager/chromeos/x11/native_display_event_dispatcher_x11.h" |
| 18 | 18 |
| 19 namespace ui { | 19 namespace ui { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 DisplaySnapshotX11* CreateOutput(int64_t id, | 23 DisplaySnapshotX11* CreateOutput(int64_t id, |
| 24 DisplayConnectionType type, | 24 DisplayConnectionType type, |
| 25 RROutput output, | 25 RROutput output, |
| 26 RRCrtc crtc) { | 26 RRCrtc crtc) { |
| 27 static const DisplayModeX11 kDefaultDisplayMode(gfx::Size(1, 1), | 27 static const DisplayModeX11 kDefaultDisplayMode(gfx::Size(1, 1), false, 60.0f, |
| 28 false, | |
| 29 60.0f, | |
| 30 20); | 28 20); |
| 31 std::vector<std::unique_ptr<const DisplayMode>> modes; | 29 std::vector<std::unique_ptr<const DisplayMode>> modes; |
| 32 const DisplayMode* mode; | 30 const DisplayMode* mode; |
| 33 | 31 |
| 34 modes.push_back(kDefaultDisplayMode.Clone()); | 32 modes.push_back(kDefaultDisplayMode.Clone()); |
| 35 mode = modes.front().get(); | 33 mode = modes.front().get(); |
| 36 | 34 |
| 37 DisplaySnapshotX11* snapshot = new DisplaySnapshotX11( | 35 DisplaySnapshotX11* snapshot = new DisplaySnapshotX11( |
| 38 id, | 36 id, gfx::Point(0, 0), gfx::Size(0, 0), type, false, false, std::string(), |
| 39 gfx::Point(0, 0), | 37 std::move(modes), std::vector<uint8_t>(), mode, NULL, output, crtc, 0); |
| 40 gfx::Size(0, 0), | |
| 41 type, | |
| 42 false, | |
| 43 false, | |
| 44 std::string(), | |
| 45 std::move(modes), | |
| 46 std::vector<uint8_t>(), | |
| 47 mode, | |
| 48 NULL, | |
| 49 output, | |
| 50 crtc, | |
| 51 0); | |
| 52 | 38 |
| 53 return snapshot; | 39 return snapshot; |
| 54 } | 40 } |
| 55 | 41 |
| 56 DisplaySnapshotX11* CreateExternalOutput(RROutput output, RRCrtc crtc) { | 42 DisplaySnapshotX11* CreateExternalOutput(RROutput output, RRCrtc crtc) { |
| 57 return CreateOutput(static_cast<int64_t>(output), | 43 return CreateOutput(static_cast<int64_t>(output), |
| 58 DISPLAY_CONNECTION_TYPE_UNKNOWN, | 44 DISPLAY_CONNECTION_TYPE_UNKNOWN, output, crtc); |
| 59 output, | |
| 60 crtc); | |
| 61 } | 45 } |
| 62 | 46 |
| 63 DisplaySnapshotX11* CreateInternalOutput(RROutput output, RRCrtc crtc) { | 47 DisplaySnapshotX11* CreateInternalOutput(RROutput output, RRCrtc crtc) { |
| 64 return CreateOutput(0, | 48 return CreateOutput(0, DISPLAY_CONNECTION_TYPE_INTERNAL, output, crtc); |
| 65 DISPLAY_CONNECTION_TYPE_INTERNAL, | |
| 66 output, | |
| 67 crtc); | |
| 68 } | 49 } |
| 69 | 50 |
| 70 class TestHelperDelegate : public NativeDisplayDelegateX11::HelperDelegate { | 51 class TestHelperDelegate : public NativeDisplayDelegateX11::HelperDelegate { |
| 71 public: | 52 public: |
| 72 TestHelperDelegate(); | 53 TestHelperDelegate(); |
| 73 ~TestHelperDelegate() override; | 54 ~TestHelperDelegate() override; |
| 74 | 55 |
| 75 int num_calls_update_xrandr_config() const { | 56 int num_calls_update_xrandr_config() const { |
| 76 return num_calls_update_xrandr_config_; | 57 return num_calls_update_xrandr_config_; |
| 77 } | 58 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); | 240 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); |
| 260 | 241 |
| 261 // Simulate removal of second output from cached output list. | 242 // Simulate removal of second output from cached output list. |
| 262 outputs.erase(outputs.begin() + 1); | 243 outputs.erase(outputs.begin() + 1); |
| 263 helper_delegate_->set_cached_outputs(outputs.get()); | 244 helper_delegate_->set_cached_outputs(outputs.get()); |
| 264 | 245 |
| 265 DispatchOutputChangeEvent(2, 11, 20, false); | 246 DispatchOutputChangeEvent(2, 11, 20, false); |
| 266 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); | 247 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); |
| 267 } | 248 } |
| 268 | 249 |
| 269 TEST_F(NativeDisplayEventDispatcherX11Test, | 250 TEST_F(NativeDisplayEventDispatcherX11Test, ForceUpdateAfterCacheExpiration) { |
| 270 ForceUpdateAfterCacheExpiration) { | |
| 271 // +1 to compenstate a possible rounding error. | 251 // +1 to compenstate a possible rounding error. |
| 272 const int kHalfOfExpirationMs = | 252 const int kHalfOfExpirationMs = |
| 273 NativeDisplayEventDispatcherX11::kUseCacheAfterStartupMs / 2 + 1; | 253 NativeDisplayEventDispatcherX11::kUseCacheAfterStartupMs / 2 + 1; |
| 274 | 254 |
| 275 ScopedVector<DisplaySnapshot> outputs; | 255 ScopedVector<DisplaySnapshot> outputs; |
| 276 outputs.push_back(CreateExternalOutput(1, 10)); | 256 outputs.push_back(CreateExternalOutput(1, 10)); |
| 277 outputs.push_back(CreateExternalOutput(2, 11)); | 257 outputs.push_back(CreateExternalOutput(2, 11)); |
| 278 helper_delegate_->set_cached_outputs(outputs.get()); | 258 helper_delegate_->set_cached_outputs(outputs.get()); |
| 279 | 259 |
| 280 EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers()); | 260 EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers()); |
| 281 | 261 |
| 282 // Duplicated event will be ignored during the startup. | 262 // Duplicated event will be ignored during the startup. |
| 283 DispatchOutputChangeEvent(2, 11, 20, true); | 263 DispatchOutputChangeEvent(2, 11, 20, true); |
| 284 EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers()); | 264 EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers()); |
| 285 | 265 |
| 286 test_tick_clock_->Advance(base::TimeDelta::FromMilliseconds( | 266 test_tick_clock_->Advance( |
| 287 kHalfOfExpirationMs)); | 267 base::TimeDelta::FromMilliseconds(kHalfOfExpirationMs)); |
| 288 | 268 |
| 289 // Duplicated event will still be ignored. | 269 // Duplicated event will still be ignored. |
| 290 DispatchOutputChangeEvent(2, 11, 20, true); | 270 DispatchOutputChangeEvent(2, 11, 20, true); |
| 291 EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers()); | 271 EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers()); |
| 292 | 272 |
| 293 // The startup timeout has been elapsed. Duplicated event | 273 // The startup timeout has been elapsed. Duplicated event |
| 294 // should not be ignored. | 274 // should not be ignored. |
| 295 test_tick_clock_->Advance( | 275 test_tick_clock_->Advance( |
| 296 base::TimeDelta::FromMilliseconds(kHalfOfExpirationMs)); | 276 base::TimeDelta::FromMilliseconds(kHalfOfExpirationMs)); |
| 297 DispatchOutputChangeEvent(2, 11, 20, true); | 277 DispatchOutputChangeEvent(2, 11, 20, true); |
| 298 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); | 278 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); |
| 299 | 279 |
| 300 // Sending the same event immediately shoudldn't be ignored. | 280 // Sending the same event immediately shoudldn't be ignored. |
| 301 DispatchOutputChangeEvent(2, 11, 20, true); | 281 DispatchOutputChangeEvent(2, 11, 20, true); |
| 302 EXPECT_EQ(2, helper_delegate_->num_calls_notify_observers()); | 282 EXPECT_EQ(2, helper_delegate_->num_calls_notify_observers()); |
| 303 | 283 |
| 304 // Advancing time further should not change the behavior. | 284 // Advancing time further should not change the behavior. |
| 305 test_tick_clock_->Advance(base::TimeDelta::FromMilliseconds( | 285 test_tick_clock_->Advance( |
| 306 kHalfOfExpirationMs)); | 286 base::TimeDelta::FromMilliseconds(kHalfOfExpirationMs)); |
| 307 DispatchOutputChangeEvent(2, 11, 20, true); | 287 DispatchOutputChangeEvent(2, 11, 20, true); |
| 308 EXPECT_EQ(3, helper_delegate_->num_calls_notify_observers()); | 288 EXPECT_EQ(3, helper_delegate_->num_calls_notify_observers()); |
| 309 | 289 |
| 310 test_tick_clock_->Advance( | 290 test_tick_clock_->Advance( |
| 311 base::TimeDelta::FromMilliseconds(kHalfOfExpirationMs)); | 291 base::TimeDelta::FromMilliseconds(kHalfOfExpirationMs)); |
| 312 DispatchOutputChangeEvent(2, 11, 20, true); | 292 DispatchOutputChangeEvent(2, 11, 20, true); |
| 313 EXPECT_EQ(4, helper_delegate_->num_calls_notify_observers()); | 293 EXPECT_EQ(4, helper_delegate_->num_calls_notify_observers()); |
| 314 } | 294 } |
| 315 | 295 |
| 316 TEST_F(NativeDisplayEventDispatcherX11Test, | 296 TEST_F(NativeDisplayEventDispatcherX11Test, UpdateMissingExternalDisplayId) { |
| 317 UpdateMissingExternalDisplayId) { | |
| 318 ScopedVector<DisplaySnapshot> outputs; | 297 ScopedVector<DisplaySnapshot> outputs; |
| 319 outputs.push_back(CreateInternalOutput(1, 10)); | 298 outputs.push_back(CreateInternalOutput(1, 10)); |
| 320 helper_delegate_->set_cached_outputs(outputs.get()); | 299 helper_delegate_->set_cached_outputs(outputs.get()); |
| 321 | 300 |
| 322 ASSERT_EQ(0, helper_delegate_->num_calls_notify_observers()); | 301 ASSERT_EQ(0, helper_delegate_->num_calls_notify_observers()); |
| 323 | 302 |
| 324 // Internal display's ID can be zero and not updated. | 303 // Internal display's ID can be zero and not updated. |
| 325 DispatchOutputChangeEvent(1, 10, 20, true); | 304 DispatchOutputChangeEvent(1, 10, 20, true); |
| 326 EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers()); | 305 EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers()); |
| 327 | 306 |
| 328 outputs.clear(); | 307 outputs.clear(); |
| 329 outputs.push_back(CreateOutput(0, DISPLAY_CONNECTION_TYPE_UNKNOWN, 2, 11)); | 308 outputs.push_back(CreateOutput(0, DISPLAY_CONNECTION_TYPE_UNKNOWN, 2, 11)); |
| 330 helper_delegate_->set_cached_outputs(outputs.get()); | 309 helper_delegate_->set_cached_outputs(outputs.get()); |
| 331 | 310 |
| 332 // External display should be updated if the id is zero. | 311 // External display should be updated if the id is zero. |
| 333 DispatchOutputChangeEvent(2, 11, 20, true); | 312 DispatchOutputChangeEvent(2, 11, 20, true); |
| 334 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); | 313 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); |
| 335 } | 314 } |
| 336 | 315 |
| 337 } // namespace ui | 316 } // namespace ui |
| OLD | NEW |