| 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 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 ClientWindowId ClientWindowIdForWindow(WindowTreeImpl* tree, | 58 ClientWindowId ClientWindowIdForWindow(WindowTreeImpl* tree, |
| 59 const ServerWindow* window) { | 59 const ServerWindow* window) { |
| 60 ClientWindowId client_window_id; | 60 ClientWindowId client_window_id; |
| 61 // If window isn't known we'll return 0, which should then error out. | 61 // If window isn't known we'll return 0, which should then error out. |
| 62 tree->IsWindowKnown(window, &client_window_id); | 62 tree->IsWindowKnown(window, &client_window_id); |
| 63 return client_window_id; | 63 return client_window_id; |
| 64 } | 64 } |
| 65 | 65 |
| 66 class TestWindowManagerInternal : public mojom::WindowManagerInternal { | 66 class TestWindowManager : public mojom::WindowManager { |
| 67 public: | 67 public: |
| 68 TestWindowManagerInternal() | 68 TestWindowManager() : got_create_top_level_window_(false), change_id_(0u) {} |
| 69 : got_create_top_level_window_(false), change_id_(0u) {} | 69 ~TestWindowManager() override {} |
| 70 ~TestWindowManagerInternal() override {} | |
| 71 | 70 |
| 72 bool did_call_create_top_level_window(uint32_t* change_id) { | 71 bool did_call_create_top_level_window(uint32_t* change_id) { |
| 73 if (!got_create_top_level_window_) | 72 if (!got_create_top_level_window_) |
| 74 return false; | 73 return false; |
| 75 | 74 |
| 76 got_create_top_level_window_ = false; | 75 got_create_top_level_window_ = false; |
| 77 *change_id = change_id_; | 76 *change_id = change_id_; |
| 78 return true; | 77 return true; |
| 79 } | 78 } |
| 80 | 79 |
| 81 private: | 80 private: |
| 82 // WindowManagerInternal: | 81 // WindowManager: |
| 83 void WmSetBounds(uint32_t change_id, | 82 void WmSetBounds(uint32_t change_id, |
| 84 uint32_t window_id, | 83 uint32_t window_id, |
| 85 mojo::RectPtr bounds) override {} | 84 mojo::RectPtr bounds) override {} |
| 86 void WmSetProperty(uint32_t change_id, | 85 void WmSetProperty(uint32_t change_id, |
| 87 uint32_t window_id, | 86 uint32_t window_id, |
| 88 const mojo::String& name, | 87 const mojo::String& name, |
| 89 mojo::Array<uint8_t> value) override {} | 88 mojo::Array<uint8_t> value) override {} |
| 90 void WmCreateTopLevelWindow( | 89 void WmCreateTopLevelWindow( |
| 91 uint32_t change_id, | 90 uint32_t change_id, |
| 92 mojo::Map<mojo::String, mojo::Array<uint8_t>> properties) override { | 91 mojo::Map<mojo::String, mojo::Array<uint8_t>> properties) override { |
| 93 got_create_top_level_window_ = true; | 92 got_create_top_level_window_ = true; |
| 94 change_id_ = change_id; | 93 change_id_ = change_id; |
| 95 } | 94 } |
| 96 | 95 |
| 97 bool got_create_top_level_window_; | 96 bool got_create_top_level_window_; |
| 98 uint32_t change_id_; | 97 uint32_t change_id_; |
| 99 | 98 |
| 100 DISALLOW_COPY_AND_ASSIGN(TestWindowManagerInternal); | 99 DISALLOW_COPY_AND_ASSIGN(TestWindowManager); |
| 101 }; | 100 }; |
| 102 | 101 |
| 103 // ----------------------------------------------------------------------------- | 102 // ----------------------------------------------------------------------------- |
| 104 | 103 |
| 105 // WindowTreeClient implementation that logs all calls to a TestChangeTracker. | 104 // WindowTreeClient implementation that logs all calls to a TestChangeTracker. |
| 106 // TODO(sky): refactor so both this and WindowTreeAppTest share code. | 105 // TODO(sky): refactor so both this and WindowTreeAppTest share code. |
| 107 class TestWindowTreeClient : public mus::mojom::WindowTreeClient { | 106 class TestWindowTreeClient : public mus::mojom::WindowTreeClient { |
| 108 public: | 107 public: |
| 109 TestWindowTreeClient() : binding_(this), record_on_change_completed_(false) {} | 108 TestWindowTreeClient() : binding_(this), record_on_change_completed_(false) {} |
| 110 ~TestWindowTreeClient() override {} | 109 ~TestWindowTreeClient() override {} |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 } | 193 } |
| 195 void OnWindowPredefinedCursorChanged(uint32_t window_id, | 194 void OnWindowPredefinedCursorChanged(uint32_t window_id, |
| 196 mojom::Cursor cursor_id) override { | 195 mojom::Cursor cursor_id) override { |
| 197 tracker_.OnWindowPredefinedCursorChanged(window_id, cursor_id); | 196 tracker_.OnWindowPredefinedCursorChanged(window_id, cursor_id); |
| 198 } | 197 } |
| 199 void OnChangeCompleted(uint32_t change_id, bool success) override { | 198 void OnChangeCompleted(uint32_t change_id, bool success) override { |
| 200 if (record_on_change_completed_) | 199 if (record_on_change_completed_) |
| 201 tracker_.OnChangeCompleted(change_id, success); | 200 tracker_.OnChangeCompleted(change_id, success); |
| 202 } | 201 } |
| 203 void RequestClose(uint32_t window_id) override {} | 202 void RequestClose(uint32_t window_id) override {} |
| 204 void GetWindowManagerInternal( | 203 void GetWindowManager(mojo::AssociatedInterfaceRequest<mojom::WindowManager> |
| 205 mojo::AssociatedInterfaceRequest<mojom::WindowManagerInternal> internal) | 204 internal) override {} |
| 206 override {} | |
| 207 | 205 |
| 208 TestChangeTracker tracker_; | 206 TestChangeTracker tracker_; |
| 209 | 207 |
| 210 mojo::Binding<mojom::WindowTreeClient> binding_; | 208 mojo::Binding<mojom::WindowTreeClient> binding_; |
| 211 bool record_on_change_completed_; | 209 bool record_on_change_completed_; |
| 212 | 210 |
| 213 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeClient); | 211 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeClient); |
| 214 }; | 212 }; |
| 215 | 213 |
| 216 // ----------------------------------------------------------------------------- | 214 // ----------------------------------------------------------------------------- |
| 217 | 215 |
| 218 // ClientConnection implementation that vends TestWindowTreeClient. | 216 // ClientConnection implementation that vends TestWindowTreeClient. |
| 219 class TestClientConnection : public ClientConnection { | 217 class TestClientConnection : public ClientConnection { |
| 220 public: | 218 public: |
| 221 explicit TestClientConnection(scoped_ptr<WindowTreeImpl> service_impl) | 219 explicit TestClientConnection(scoped_ptr<WindowTreeImpl> service_impl) |
| 222 : ClientConnection(std::move(service_impl), &client_), | 220 : ClientConnection(std::move(service_impl), &client_), |
| 223 is_paused_(false) {} | 221 is_paused_(false) {} |
| 224 | 222 |
| 225 TestWindowTreeClient* client() { return &client_; } | 223 TestWindowTreeClient* client() { return &client_; } |
| 226 | 224 |
| 227 bool is_paused() const { return is_paused_; } | 225 bool is_paused() const { return is_paused_; } |
| 228 | 226 |
| 229 // ClientConnection: | 227 // ClientConnection: |
| 230 mojom::WindowManagerInternal* GetWindowManagerInternal() override { | 228 mojom::WindowManager* GetWindowManager() override { |
| 231 NOTREACHED(); | 229 NOTREACHED(); |
| 232 return nullptr; | 230 return nullptr; |
| 233 } | 231 } |
| 234 void SetIncomingMethodCallProcessingPaused(bool paused) override { | 232 void SetIncomingMethodCallProcessingPaused(bool paused) override { |
| 235 is_paused_ = paused; | 233 is_paused_ = paused; |
| 236 } | 234 } |
| 237 | 235 |
| 238 private: | 236 private: |
| 239 ~TestClientConnection() override {} | 237 ~TestClientConnection() override {} |
| 240 | 238 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 return static_cast<mus::mojom::Cursor>(cursor_id_); | 433 return static_cast<mus::mojom::Cursor>(cursor_id_); |
| 436 } | 434 } |
| 437 | 435 |
| 438 TestWindowTreeHostConnection* host_connection() { return host_connection_; } | 436 TestWindowTreeHostConnection* host_connection() { return host_connection_; } |
| 439 | 437 |
| 440 void DispatchEventWithoutAck(const ui::Event& event) { | 438 void DispatchEventWithoutAck(const ui::Event& event) { |
| 441 host_connection()->window_tree_host()->OnEvent(event); | 439 host_connection()->window_tree_host()->OnEvent(event); |
| 442 } | 440 } |
| 443 | 441 |
| 444 void set_window_manager_internal(WindowTreeImpl* connection, | 442 void set_window_manager_internal(WindowTreeImpl* connection, |
| 445 mojom::WindowManagerInternal* wm_internal) { | 443 mojom::WindowManager* wm_internal) { |
| 446 connection->window_manager_internal_ = wm_internal; | 444 connection->window_manager_internal_ = wm_internal; |
| 447 } | 445 } |
| 448 | 446 |
| 449 void AckPreviousEvent() { | 447 void AckPreviousEvent() { |
| 450 while (host_connection()->window_tree_host()->tree_awaiting_input_ack_) { | 448 while (host_connection()->window_tree_host()->tree_awaiting_input_ack_) { |
| 451 host_connection() | 449 host_connection() |
| 452 ->window_tree_host() | 450 ->window_tree_host() |
| 453 ->tree_awaiting_input_ack_->OnWindowInputEventAck(0); | 451 ->tree_awaiting_input_ack_->OnWindowInputEventAck(0); |
| 454 } | 452 } |
| 455 } | 453 } |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 // Ack the first event. That should trigger the dispatch of the second event. | 825 // Ack the first event. That should trigger the dispatch of the second event. |
| 828 AckPreviousEvent(); | 826 AckPreviousEvent(); |
| 829 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 827 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 830 EXPECT_EQ("InputEvent window=0,2 event_action=5", | 828 EXPECT_EQ("InputEvent window=0,2 event_action=5", |
| 831 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 829 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 832 } | 830 } |
| 833 | 831 |
| 834 // Establish connection, call NewTopLevelWindow(), make sure get id, and make | 832 // Establish connection, call NewTopLevelWindow(), make sure get id, and make |
| 835 // sure client paused. | 833 // sure client paused. |
| 836 TEST_F(WindowTreeTest, NewTopLevelWindow) { | 834 TEST_F(WindowTreeTest, NewTopLevelWindow) { |
| 837 TestWindowManagerInternal wm_internal; | 835 TestWindowManager wm_internal; |
| 838 set_window_manager_internal(wm_connection(), &wm_internal); | 836 set_window_manager_internal(wm_connection(), &wm_internal); |
| 839 TestWindowTreeClient* embed_connection = nullptr; | 837 TestWindowTreeClient* embed_connection = nullptr; |
| 840 WindowTreeImpl* window_tree_connection = nullptr; | 838 WindowTreeImpl* window_tree_connection = nullptr; |
| 841 ServerWindow* window = nullptr; | 839 ServerWindow* window = nullptr; |
| 842 ASSERT_NO_FATAL_FAILURE( | 840 ASSERT_NO_FATAL_FAILURE( |
| 843 SetupEventTargeting(&embed_connection, &window_tree_connection, &window)); | 841 SetupEventTargeting(&embed_connection, &window_tree_connection, &window)); |
| 844 embed_connection->tracker()->changes()->clear(); | 842 embed_connection->tracker()->changes()->clear(); |
| 845 embed_connection->set_record_on_change_completed(true); | 843 embed_connection->set_record_on_change_completed(true); |
| 846 | 844 |
| 847 // Create a new top level window. | 845 // Create a new top level window. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 861 | 859 |
| 862 // Create the window for |embed_window_id2_in_child|. | 860 // Create the window for |embed_window_id2_in_child|. |
| 863 const ClientWindowId embed_window_id2 = | 861 const ClientWindowId embed_window_id2 = |
| 864 BuildClientWindowId(wm_connection(), 2); | 862 BuildClientWindowId(wm_connection(), 2); |
| 865 EXPECT_TRUE( | 863 EXPECT_TRUE( |
| 866 wm_connection()->NewWindow(embed_window_id2, ServerWindow::Properties())); | 864 wm_connection()->NewWindow(embed_window_id2, ServerWindow::Properties())); |
| 867 EXPECT_TRUE(wm_connection()->AddWindow(FirstRootId(wm_connection()), | 865 EXPECT_TRUE(wm_connection()->AddWindow(FirstRootId(wm_connection()), |
| 868 embed_window_id2)); | 866 embed_window_id2)); |
| 869 | 867 |
| 870 // Ack the change, which should resume the binding. | 868 // Ack the change, which should resume the binding. |
| 871 static_cast<mojom::WindowManagerInternalClient*>(wm_connection()) | 869 static_cast<mojom::WindowManagerClient*>(wm_connection()) |
| 872 ->OnWmCreatedTopLevelWindow(wm_change_id, embed_window_id2.id); | 870 ->OnWmCreatedTopLevelWindow(wm_change_id, embed_window_id2.id); |
| 873 EXPECT_FALSE(last_client_connection()->is_paused()); | 871 EXPECT_FALSE(last_client_connection()->is_paused()); |
| 874 EXPECT_EQ("TopLevelCreated id=17 window_id=" + | 872 EXPECT_EQ("TopLevelCreated id=17 window_id=" + |
| 875 WindowIdToString( | 873 WindowIdToString( |
| 876 WindowIdFromTransportId(embed_window_id2_in_child.id)), | 874 WindowIdFromTransportId(embed_window_id2_in_child.id)), |
| 877 SingleChangeToDescription(*embed_connection->tracker()->changes())); | 875 SingleChangeToDescription(*embed_connection->tracker()->changes())); |
| 878 embed_connection->tracker()->changes()->clear(); | 876 embed_connection->tracker()->changes()->clear(); |
| 879 | 877 |
| 880 // Change the visibility of the window from the owner and make sure the | 878 // Change the visibility of the window from the owner and make sure the |
| 881 // client sees the right id. | 879 // client sees the right id. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 893 SingleChangeToDescription(*embed_connection->tracker()->changes())); | 891 SingleChangeToDescription(*embed_connection->tracker()->changes())); |
| 894 | 892 |
| 895 // Set the visibility from the child using the client assigned id. | 893 // Set the visibility from the child using the client assigned id. |
| 896 ASSERT_TRUE(window_tree_connection->SetWindowVisibility( | 894 ASSERT_TRUE(window_tree_connection->SetWindowVisibility( |
| 897 embed_window_id2_in_child, false)); | 895 embed_window_id2_in_child, false)); |
| 898 EXPECT_FALSE(embed_window->visible()); | 896 EXPECT_FALSE(embed_window->visible()); |
| 899 } | 897 } |
| 900 | 898 |
| 901 } // namespace ws | 899 } // namespace ws |
| 902 } // namespace mus | 900 } // namespace mus |
| OLD | NEW |