| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/mus/public/cpp/lib/window_tree_client_impl.h" | 5 #include "components/mus/public/cpp/lib/window_tree_client_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "mojo/converters/input_events/input_events_type_converters.h" | 24 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "ui/events/event.h" | 26 #include "ui/events/event.h" |
| 27 #include "ui/events/event_utils.h" | 27 #include "ui/events/event_utils.h" |
| 28 #include "ui/gfx/geometry/rect.h" | 28 #include "ui/gfx/geometry/rect.h" |
| 29 | 29 |
| 30 namespace mus { | 30 namespace mus { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 void DoNothingBool(bool result) {} | 34 void DoNothingWithEventResult(mojom::EventResult result) {} |
| 35 | 35 |
| 36 Id server_id(mus::Window* window) { | 36 Id server_id(mus::Window* window) { |
| 37 return WindowPrivate(window).server_id(); | 37 return WindowPrivate(window).server_id(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 mojo::Array<uint8_t> Int32ToPropertyTransportValue(int32_t value) { | 42 mojo::Array<uint8_t> Int32ToPropertyTransportValue(int32_t value) { |
| 43 const std::vector<uint8_t> bytes = | 43 const std::vector<uint8_t> bytes = |
| 44 mojo::ConvertTo<std::vector<uint8_t>>(value); | 44 mojo::ConvertTo<std::vector<uint8_t>>(value); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 public: | 123 public: |
| 124 TestInputEventHandler() | 124 TestInputEventHandler() |
| 125 : received_event_(false), should_manually_ack_(false) {} | 125 : received_event_(false), should_manually_ack_(false) {} |
| 126 ~TestInputEventHandler() override {} | 126 ~TestInputEventHandler() override {} |
| 127 | 127 |
| 128 void set_should_manually_ack() { should_manually_ack_ = true; } | 128 void set_should_manually_ack() { should_manually_ack_ = true; } |
| 129 | 129 |
| 130 void AckEvent() { | 130 void AckEvent() { |
| 131 DCHECK(should_manually_ack_); | 131 DCHECK(should_manually_ack_); |
| 132 DCHECK(!ack_callback_.is_null()); | 132 DCHECK(!ack_callback_.is_null()); |
| 133 ack_callback_.Run(true); | 133 ack_callback_.Run(mojom::EventResult::HANDLED); |
| 134 ack_callback_ = base::Bind(&DoNothingBool); | 134 ack_callback_ = base::Bind(&DoNothingWithEventResult); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void Reset() { | 137 void Reset() { |
| 138 received_event_ = false; | 138 received_event_ = false; |
| 139 ack_callback_ = base::Bind(&DoNothingBool); | 139 ack_callback_ = base::Bind(&DoNothingWithEventResult); |
| 140 } | 140 } |
| 141 bool received_event() const { return received_event_; } | 141 bool received_event() const { return received_event_; } |
| 142 | 142 |
| 143 private: | 143 private: |
| 144 // InputEventHandler: | 144 // InputEventHandler: |
| 145 void OnWindowInputEvent( | 145 void OnWindowInputEvent(Window* target, |
| 146 Window* target, | 146 const ui::Event& event, |
| 147 const ui::Event& event, | 147 scoped_ptr<base::Callback<void(mojom::EventResult)>>* |
| 148 scoped_ptr<base::Callback<void(bool)>>* ack_callback) override { | 148 ack_callback) override { |
| 149 EXPECT_FALSE(received_event_) | 149 EXPECT_FALSE(received_event_) |
| 150 << "Observer was not reset after receiving event."; | 150 << "Observer was not reset after receiving event."; |
| 151 received_event_ = true; | 151 received_event_ = true; |
| 152 if (should_manually_ack_) { | 152 if (should_manually_ack_) { |
| 153 ack_callback_ = *ack_callback->get(); | 153 ack_callback_ = *ack_callback->get(); |
| 154 ack_callback->reset(); | 154 ack_callback->reset(); |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 bool received_event_; | 158 bool received_event_; |
| 159 bool should_manually_ack_; | 159 bool should_manually_ack_; |
| 160 base::Callback<void(bool)> ack_callback_; | 160 base::Callback<void(mojom::EventResult)> ack_callback_; |
| 161 | 161 |
| 162 DISALLOW_COPY_AND_ASSIGN(TestInputEventHandler); | 162 DISALLOW_COPY_AND_ASSIGN(TestInputEventHandler); |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 using WindowTreeClientImplTest = testing::Test; | 165 using WindowTreeClientImplTest = testing::Test; |
| 166 | 166 |
| 167 // Verifies bounds are reverted if the server replied that the change failed. | 167 // Verifies bounds are reverted if the server replied that the change failed. |
| 168 TEST_F(WindowTreeClientImplTest, SetBoundsFailed) { | 168 TEST_F(WindowTreeClientImplTest, SetBoundsFailed) { |
| 169 WindowTreeSetup setup; | 169 WindowTreeSetup setup; |
| 170 Window* root = setup.GetFirstRoot(); | 170 Window* root = setup.GetFirstRoot(); |
| (...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 | 920 |
| 921 setup.window_tree_client()->OnChangeCompleted(change_id2, false); | 921 setup.window_tree_client()->OnChangeCompleted(change_id2, false); |
| 922 EXPECT_FALSE(child->HasCapture()); | 922 EXPECT_FALSE(child->HasCapture()); |
| 923 EXPECT_TRUE(root->HasCapture()); | 923 EXPECT_TRUE(root->HasCapture()); |
| 924 | 924 |
| 925 setup.window_tree_client()->OnLostCapture(server_id(root)); | 925 setup.window_tree_client()->OnLostCapture(server_id(root)); |
| 926 EXPECT_FALSE(root->HasCapture()); | 926 EXPECT_FALSE(root->HasCapture()); |
| 927 } | 927 } |
| 928 | 928 |
| 929 } // namespace mus | 929 } // namespace mus |
| OLD | NEW |