| 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" |
| 11 #include "components/mus/common/util.h" | 11 #include "components/mus/common/util.h" |
| 12 #include "components/mus/public/cpp/input_event_handler.h" | 12 #include "components/mus/public/cpp/input_event_handler.h" |
| 13 #include "components/mus/public/cpp/lib/window_private.h" | 13 #include "components/mus/public/cpp/lib/window_private.h" |
| 14 #include "components/mus/public/cpp/property_type_converters.h" | 14 #include "components/mus/public/cpp/property_type_converters.h" |
| 15 #include "components/mus/public/cpp/tests/test_window.h" | 15 #include "components/mus/public/cpp/tests/test_window.h" |
| 16 #include "components/mus/public/cpp/tests/test_window_tree.h" | 16 #include "components/mus/public/cpp/tests/test_window_tree.h" |
| 17 #include "components/mus/public/cpp/window.h" | 17 #include "components/mus/public/cpp/window.h" |
| 18 #include "components/mus/public/cpp/window_observer.h" | 18 #include "components/mus/public/cpp/window_observer.h" |
| 19 #include "components/mus/public/cpp/window_property.h" | 19 #include "components/mus/public/cpp/window_property.h" |
| 20 #include "components/mus/public/cpp/window_tracker.h" | 20 #include "components/mus/public/cpp/window_tracker.h" |
| 21 #include "components/mus/public/cpp/window_tree_delegate.h" | 21 #include "components/mus/public/cpp/window_tree_delegate.h" |
| 22 #include "mojo/common/common_type_converters.h" | 22 #include "mojo/common/common_type_converters.h" |
| 23 #include "mojo/converters/geometry/geometry_type_converters.h" | 23 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 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 { |
| 31 |
| 32 void DoNothingBool(bool result) {} |
| 33 |
| 34 } // namespace |
| 35 |
| 30 namespace mus { | 36 namespace mus { |
| 31 | 37 |
| 32 mojo::Array<uint8_t> Int32ToPropertyTransportValue(int32_t value) { | 38 mojo::Array<uint8_t> Int32ToPropertyTransportValue(int32_t value) { |
| 33 const std::vector<uint8_t> bytes = | 39 const std::vector<uint8_t> bytes = |
| 34 mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(value); | 40 mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(value); |
| 35 mojo::Array<uint8_t> transport_value; | 41 mojo::Array<uint8_t> transport_value; |
| 36 transport_value.resize(bytes.size()); | 42 transport_value.resize(bytes.size()); |
| 37 memcpy(&transport_value.front(), &(bytes.front()), bytes.size()); | 43 memcpy(&transport_value.front(), &(bytes.front()), bytes.size()); |
| 38 return transport_value; | 44 return transport_value; |
| 39 } | 45 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 public: | 121 public: |
| 116 TestInputEventHandler() | 122 TestInputEventHandler() |
| 117 : received_event_(false), should_manually_ack_(false) {} | 123 : received_event_(false), should_manually_ack_(false) {} |
| 118 ~TestInputEventHandler() override {} | 124 ~TestInputEventHandler() override {} |
| 119 | 125 |
| 120 void set_should_manually_ack() { should_manually_ack_ = true; } | 126 void set_should_manually_ack() { should_manually_ack_ = true; } |
| 121 | 127 |
| 122 void AckEvent() { | 128 void AckEvent() { |
| 123 DCHECK(should_manually_ack_); | 129 DCHECK(should_manually_ack_); |
| 124 DCHECK(!ack_callback_.is_null()); | 130 DCHECK(!ack_callback_.is_null()); |
| 125 ack_callback_.Run(); | 131 ack_callback_.Run(true); |
| 126 ack_callback_ = base::Closure(); | 132 ack_callback_ = base::Bind(&::DoNothingBool); |
| 127 } | 133 } |
| 128 | 134 |
| 129 void Reset() { | 135 void Reset() { |
| 130 received_event_ = false; | 136 received_event_ = false; |
| 131 ack_callback_ = base::Closure(); | 137 ack_callback_ = base::Bind(&::DoNothingBool); |
| 132 } | 138 } |
| 133 bool received_event() const { return received_event_; } | 139 bool received_event() const { return received_event_; } |
| 134 | 140 |
| 135 private: | 141 private: |
| 136 // InputEventHandler: | 142 // InputEventHandler: |
| 137 void OnWindowInputEvent(Window* target, | 143 void OnWindowInputEvent( |
| 138 mojom::EventPtr event, | 144 Window* target, |
| 139 scoped_ptr<base::Closure>* ack_callback) override { | 145 mojom::EventPtr event, |
| 146 scoped_ptr<base::Callback<void(bool)>>* ack_callback) override { |
| 140 EXPECT_FALSE(received_event_) | 147 EXPECT_FALSE(received_event_) |
| 141 << "Observer was not reset after receiving event."; | 148 << "Observer was not reset after receiving event."; |
| 142 received_event_ = true; | 149 received_event_ = true; |
| 143 if (should_manually_ack_) { | 150 if (should_manually_ack_) { |
| 144 ack_callback_ = *ack_callback->get(); | 151 ack_callback_ = *ack_callback->get(); |
| 145 ack_callback->reset(); | 152 ack_callback->reset(); |
| 146 } | 153 } |
| 147 } | 154 } |
| 148 | 155 |
| 149 bool received_event_; | 156 bool received_event_; |
| 150 bool should_manually_ack_; | 157 bool should_manually_ack_; |
| 151 base::Closure ack_callback_; | 158 base::Callback<void(bool)> ack_callback_; |
| 152 | 159 |
| 153 DISALLOW_COPY_AND_ASSIGN(TestInputEventHandler); | 160 DISALLOW_COPY_AND_ASSIGN(TestInputEventHandler); |
| 154 }; | 161 }; |
| 155 | 162 |
| 156 using WindowTreeClientImplTest = testing::Test; | 163 using WindowTreeClientImplTest = testing::Test; |
| 157 | 164 |
| 158 // Verifies bounds are reverted if the server replied that the change failed. | 165 // Verifies bounds are reverted if the server replied that the change failed. |
| 159 TEST_F(WindowTreeClientImplTest, SetBoundsFailed) { | 166 TEST_F(WindowTreeClientImplTest, SetBoundsFailed) { |
| 160 WindowTreeSetup setup; | 167 WindowTreeSetup setup; |
| 161 Window* root = setup.GetFirstRoot(); | 168 Window* root = setup.GetFirstRoot(); |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 | 806 |
| 800 setup.window_tree_client()->OnChangeCompleted(change_id2, false); | 807 setup.window_tree_client()->OnChangeCompleted(change_id2, false); |
| 801 EXPECT_FALSE(child->HasCapture()); | 808 EXPECT_FALSE(child->HasCapture()); |
| 802 EXPECT_TRUE(root->HasCapture()); | 809 EXPECT_TRUE(root->HasCapture()); |
| 803 | 810 |
| 804 setup.window_tree_client()->OnLostCapture(root->id()); | 811 setup.window_tree_client()->OnLostCapture(root->id()); |
| 805 EXPECT_FALSE(root->HasCapture()); | 812 EXPECT_FALSE(root->HasCapture()); |
| 806 } | 813 } |
| 807 | 814 |
| 808 } // namespace mus | 815 } // namespace mus |
| OLD | NEW |