| 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 <X11/extensions/Xrandr.h> | 5 #include <X11/extensions/Xrandr.h> |
| 6 | 6 |
| 7 #undef Bool | 7 #undef Bool |
| 8 #undef None | 8 #undef None |
| 9 | 9 |
| 10 #include "chromeos/display/native_display_delegate_x11.h" | |
| 11 #include "chromeos/display/native_display_event_dispatcher_x11.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/display/chromeos/x11/native_display_delegate_x11.h" |
| 12 #include "ui/display/chromeos/x11/native_display_event_dispatcher_x11.h" |
| 13 | 13 |
| 14 namespace chromeos { | 14 namespace ui { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 OutputConfigurator::OutputSnapshot CreateOutput( | 18 OutputConfigurator::OutputSnapshot CreateOutput(RROutput output, |
| 19 RROutput output, RRCrtc crtc, RRMode mode) { | 19 RRCrtc crtc, |
| 20 RRMode mode) { |
| 20 OutputConfigurator::OutputSnapshot snapshot; | 21 OutputConfigurator::OutputSnapshot snapshot; |
| 21 snapshot.output = output; | 22 snapshot.output = output; |
| 22 snapshot.crtc = crtc; | 23 snapshot.crtc = crtc; |
| 23 snapshot.current_mode = mode; | 24 snapshot.current_mode = mode; |
| 24 | 25 |
| 25 return snapshot; | 26 return snapshot; |
| 26 } | 27 } |
| 27 | 28 |
| 28 class TestHelperDelegate : public NativeDisplayDelegateX11::HelperDelegate { | 29 class TestHelperDelegate : public NativeDisplayDelegateX11::HelperDelegate { |
| 29 public: | 30 public: |
| 30 TestHelperDelegate(); | 31 TestHelperDelegate(); |
| 31 virtual ~TestHelperDelegate(); | 32 virtual ~TestHelperDelegate(); |
| 32 | 33 |
| 33 int num_calls_update_xrandr_config() const { | 34 int num_calls_update_xrandr_config() const { |
| 34 return num_calls_update_xrandr_config_; | 35 return num_calls_update_xrandr_config_; |
| 35 } | 36 } |
| 36 | 37 |
| 37 int num_calls_notify_observers() const { | 38 int num_calls_notify_observers() const { return num_calls_notify_observers_; } |
| 38 return num_calls_notify_observers_; | |
| 39 } | |
| 40 | 39 |
| 41 void set_cached_outputs( | 40 void set_cached_outputs( |
| 42 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) { | 41 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) { |
| 43 cached_outputs_ = outputs; | 42 cached_outputs_ = outputs; |
| 44 } | 43 } |
| 45 | 44 |
| 46 // NativeDisplayDelegateX11::HelperDelegate overrides: | 45 // NativeDisplayDelegateX11::HelperDelegate overrides: |
| 47 virtual void UpdateXRandRConfiguration( | 46 virtual void UpdateXRandRConfiguration(const base::NativeEvent& event) |
| 48 const base::NativeEvent& event) OVERRIDE; | 47 OVERRIDE; |
| 49 virtual const std::vector<OutputConfigurator::OutputSnapshot>& | 48 virtual const std::vector<OutputConfigurator::OutputSnapshot>& |
| 50 GetCachedOutputs() const OVERRIDE; | 49 GetCachedOutputs() const OVERRIDE; |
| 51 virtual void NotifyDisplayObservers() OVERRIDE; | 50 virtual void NotifyDisplayObservers() OVERRIDE; |
| 52 | 51 |
| 53 private: | 52 private: |
| 54 int num_calls_update_xrandr_config_; | 53 int num_calls_update_xrandr_config_; |
| 55 int num_calls_notify_observers_; | 54 int num_calls_notify_observers_; |
| 56 | 55 |
| 57 std::vector<OutputConfigurator::OutputSnapshot> cached_outputs_; | 56 std::vector<OutputConfigurator::OutputSnapshot> cached_outputs_; |
| 58 | 57 |
| 59 DISALLOW_COPY_AND_ASSIGN(TestHelperDelegate); | 58 DISALLOW_COPY_AND_ASSIGN(TestHelperDelegate); |
| 60 }; | 59 }; |
| 61 | 60 |
| 62 TestHelperDelegate::TestHelperDelegate() | 61 TestHelperDelegate::TestHelperDelegate() |
| 63 : num_calls_update_xrandr_config_(0), | 62 : num_calls_update_xrandr_config_(0), num_calls_notify_observers_(0) {} |
| 64 num_calls_notify_observers_(0) {} | |
| 65 | 63 |
| 66 TestHelperDelegate::~TestHelperDelegate() {} | 64 TestHelperDelegate::~TestHelperDelegate() {} |
| 67 | 65 |
| 68 void TestHelperDelegate::UpdateXRandRConfiguration( | 66 void TestHelperDelegate::UpdateXRandRConfiguration( |
| 69 const base::NativeEvent& event) { | 67 const base::NativeEvent& event) { |
| 70 ++num_calls_update_xrandr_config_; | 68 ++num_calls_update_xrandr_config_; |
| 71 } | 69 } |
| 72 | 70 |
| 73 const std::vector<OutputConfigurator::OutputSnapshot>& | 71 const std::vector<OutputConfigurator::OutputSnapshot>& |
| 74 TestHelperDelegate::GetCachedOutputs() const { | 72 TestHelperDelegate::GetCachedOutputs() const { |
| 75 return cached_outputs_; | 73 return cached_outputs_; |
| 76 } | 74 } |
| 77 | 75 |
| 78 void TestHelperDelegate::NotifyDisplayObservers() { | 76 void TestHelperDelegate::NotifyDisplayObservers() { |
| 79 ++num_calls_notify_observers_; | 77 ++num_calls_notify_observers_; |
| 80 } | 78 } |
| 81 | 79 |
| 82 //////////////////////////////////////////////////////////////////////////////// | 80 //////////////////////////////////////////////////////////////////////////////// |
| 83 // NativeDisplayEventDispatcherX11Test | 81 // NativeDisplayEventDispatcherX11Test |
| 84 | 82 |
| 85 class NativeDisplayEventDispatcherX11Test : public testing::Test { | 83 class NativeDisplayEventDispatcherX11Test : public testing::Test { |
| 86 public: | 84 public: |
| 87 NativeDisplayEventDispatcherX11Test(); | 85 NativeDisplayEventDispatcherX11Test(); |
| 88 virtual ~NativeDisplayEventDispatcherX11Test(); | 86 virtual ~NativeDisplayEventDispatcherX11Test(); |
| 89 | 87 |
| 90 protected: | 88 protected: |
| 91 void DispatchScreenChangeEvent(); | 89 void DispatchScreenChangeEvent(); |
| 92 void DispatchOutputChangeEvent( | 90 void DispatchOutputChangeEvent(RROutput output, |
| 93 RROutput output, RRCrtc crtc, RRMode mode, bool connected); | 91 RRCrtc crtc, |
| 92 RRMode mode, |
| 93 bool connected); |
| 94 | 94 |
| 95 int xrandr_event_base_; | 95 int xrandr_event_base_; |
| 96 scoped_ptr<TestHelperDelegate> helper_delegate_; | 96 scoped_ptr<TestHelperDelegate> helper_delegate_; |
| 97 scoped_ptr<NativeDisplayEventDispatcherX11> dispatcher_; | 97 scoped_ptr<NativeDisplayEventDispatcherX11> dispatcher_; |
| 98 | 98 |
| 99 private: | 99 private: |
| 100 DISALLOW_COPY_AND_ASSIGN(NativeDisplayEventDispatcherX11Test); | 100 DISALLOW_COPY_AND_ASSIGN(NativeDisplayEventDispatcherX11Test); |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 NativeDisplayEventDispatcherX11Test::NativeDisplayEventDispatcherX11Test() | 103 NativeDisplayEventDispatcherX11Test::NativeDisplayEventDispatcherX11Test() |
| 104 : xrandr_event_base_(10), | 104 : xrandr_event_base_(10), |
| 105 helper_delegate_(new TestHelperDelegate()), | 105 helper_delegate_(new TestHelperDelegate()), |
| 106 dispatcher_(new NativeDisplayEventDispatcherX11(helper_delegate_.get(), | 106 dispatcher_(new NativeDisplayEventDispatcherX11(helper_delegate_.get(), |
| 107 xrandr_event_base_)) { | 107 xrandr_event_base_)) {} |
| 108 } | |
| 109 | 108 |
| 110 NativeDisplayEventDispatcherX11Test::~NativeDisplayEventDispatcherX11Test() {} | 109 NativeDisplayEventDispatcherX11Test::~NativeDisplayEventDispatcherX11Test() {} |
| 111 | 110 |
| 112 void NativeDisplayEventDispatcherX11Test::DispatchScreenChangeEvent() { | 111 void NativeDisplayEventDispatcherX11Test::DispatchScreenChangeEvent() { |
| 113 XRRScreenChangeNotifyEvent event = {0}; | 112 XRRScreenChangeNotifyEvent event = {0}; |
| 114 event.type = xrandr_event_base_ + RRScreenChangeNotify; | 113 event.type = xrandr_event_base_ + RRScreenChangeNotify; |
| 115 | 114 |
| 116 dispatcher_->Dispatch(reinterpret_cast<const base::NativeEvent>(&event)); | 115 dispatcher_->Dispatch(reinterpret_cast<const base::NativeEvent>(&event)); |
| 117 } | 116 } |
| 118 | 117 |
| 119 void NativeDisplayEventDispatcherX11Test::DispatchOutputChangeEvent( | 118 void NativeDisplayEventDispatcherX11Test::DispatchOutputChangeEvent( |
| 120 RROutput output, RRCrtc crtc, RRMode mode, bool connected) { | 119 RROutput output, |
| 120 RRCrtc crtc, |
| 121 RRMode mode, |
| 122 bool connected) { |
| 121 XRROutputChangeNotifyEvent event = {0}; | 123 XRROutputChangeNotifyEvent event = {0}; |
| 122 event.type = xrandr_event_base_ + RRNotify; | 124 event.type = xrandr_event_base_ + RRNotify; |
| 123 event.subtype = RRNotify_OutputChange; | 125 event.subtype = RRNotify_OutputChange; |
| 124 event.output = output; | 126 event.output = output; |
| 125 event.crtc = crtc; | 127 event.crtc = crtc; |
| 126 event.mode = mode; | 128 event.mode = mode; |
| 127 event.connection = connected ? RR_Connected : RR_Disconnected; | 129 event.connection = connected ? RR_Connected : RR_Disconnected; |
| 128 | 130 |
| 129 dispatcher_->Dispatch(reinterpret_cast<const base::NativeEvent>(&event)); | 131 dispatcher_->Dispatch(reinterpret_cast<const base::NativeEvent>(&event)); |
| 130 } | 132 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); | 224 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); |
| 223 | 225 |
| 224 // Simulate removal of second output from cached output list. | 226 // Simulate removal of second output from cached output list. |
| 225 outputs.erase(outputs.begin() + 1); | 227 outputs.erase(outputs.begin() + 1); |
| 226 helper_delegate_->set_cached_outputs(outputs); | 228 helper_delegate_->set_cached_outputs(outputs); |
| 227 | 229 |
| 228 DispatchOutputChangeEvent(2, 11, 20, false); | 230 DispatchOutputChangeEvent(2, 11, 20, false); |
| 229 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); | 231 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); |
| 230 } | 232 } |
| 231 | 233 |
| 232 } // namespace chromeos | 234 } // namespace ui |
| OLD | NEW |