Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: components/mus/ws/window_tree_unittest.cc

Issue 1677513002: mus Window Server: implement event capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 mus::mojom::WindowTreePtr tree, 125 mus::mojom::WindowTreePtr tree,
126 Id focused_window_id, 126 Id focused_window_id,
127 uint32_t access_policy) override { 127 uint32_t access_policy) override {
128 // TODO(sky): add test coverage of |focused_window_id|. 128 // TODO(sky): add test coverage of |focused_window_id|.
129 tracker_.OnEmbed(connection_id, std::move(root)); 129 tracker_.OnEmbed(connection_id, std::move(root));
130 } 130 }
131 void OnEmbeddedAppDisconnected(uint32_t window) override { 131 void OnEmbeddedAppDisconnected(uint32_t window) override {
132 tracker_.OnEmbeddedAppDisconnected(window); 132 tracker_.OnEmbeddedAppDisconnected(window);
133 } 133 }
134 void OnUnembed(Id window_id) override { tracker_.OnUnembed(window_id); } 134 void OnUnembed(Id window_id) override { tracker_.OnUnembed(window_id); }
135 void OnLostCapture(Id window_id) override {}
135 void OnTopLevelCreated(uint32_t change_id, 136 void OnTopLevelCreated(uint32_t change_id,
136 mojom::WindowDataPtr data) override { 137 mojom::WindowDataPtr data) override {
137 tracker_.OnTopLevelCreated(change_id, std::move(data)); 138 tracker_.OnTopLevelCreated(change_id, std::move(data));
138 } 139 }
139 void OnWindowBoundsChanged(uint32_t window, 140 void OnWindowBoundsChanged(uint32_t window,
140 mojo::RectPtr old_bounds, 141 mojo::RectPtr old_bounds,
141 mojo::RectPtr new_bounds) override { 142 mojo::RectPtr new_bounds) override {
142 tracker_.OnWindowBoundsChanged(window, std::move(old_bounds), 143 tracker_.OnWindowBoundsChanged(window, std::move(old_bounds),
143 std::move(new_bounds)); 144 std::move(new_bounds));
144 } 145 }
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // root-window is created). 316 // root-window is created).
316 mojom::ViewportMetrics metrics; 317 mojom::ViewportMetrics metrics;
317 metrics.size_in_pixels = mojo::Size::From(gfx::Size(400, 300)); 318 metrics.size_in_pixels = mojo::Size::From(gfx::Size(400, 300));
318 metrics.device_pixel_ratio = 1.f; 319 metrics.device_pixel_ratio = 1.f;
319 delegate->OnViewportMetricsChanged(mojom::ViewportMetrics(), metrics); 320 delegate->OnViewportMetricsChanged(mojom::ViewportMetrics(), metrics);
320 } 321 }
321 void SchedulePaint(const ServerWindow* window, 322 void SchedulePaint(const ServerWindow* window,
322 const gfx::Rect& bounds) override {} 323 const gfx::Rect& bounds) override {}
323 void SetViewportSize(const gfx::Size& size) override {} 324 void SetViewportSize(const gfx::Size& size) override {}
324 void SetTitle(const base::string16& title) override {} 325 void SetTitle(const base::string16& title) override {}
326 void SetCapture() override {}
327 void ReleaseCapture() override {}
325 void SetCursorById(int32_t cursor) override { *cursor_id_storage_ = cursor; } 328 void SetCursorById(int32_t cursor) override { *cursor_id_storage_ = cursor; }
326 mojom::Rotation GetRotation() override { return mojom::Rotation::VALUE_0; } 329 mojom::Rotation GetRotation() override { return mojom::Rotation::VALUE_0; }
327 const mojom::ViewportMetrics& GetViewportMetrics() override { 330 const mojom::ViewportMetrics& GetViewportMetrics() override {
328 return display_metrices_; 331 return display_metrices_;
329 } 332 }
330 void UpdateTextInputState(const ui::TextInputState& state) override {} 333 void UpdateTextInputState(const ui::TextInputState& state) override {}
331 void SetImeVisibility(bool visible) override {} 334 void SetImeVisibility(bool visible) override {}
332 bool IsFramePending() const override { return false; } 335 bool IsFramePending() const override { return false; }
333 336
334 private: 337 private:
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 WindowIdFromTransportId(embed_window_id2_in_child.id)) + 892 WindowIdFromTransportId(embed_window_id2_in_child.id)) +
890 " visible=true", 893 " visible=true",
891 SingleChangeToDescription(*embed_connection->tracker()->changes())); 894 SingleChangeToDescription(*embed_connection->tracker()->changes()));
892 895
893 // Set the visibility from the child using the client assigned id. 896 // Set the visibility from the child using the client assigned id.
894 ASSERT_TRUE(window_tree_connection->SetWindowVisibility( 897 ASSERT_TRUE(window_tree_connection->SetWindowVisibility(
895 embed_window_id2_in_child, false)); 898 embed_window_id2_in_child, false));
896 EXPECT_FALSE(embed_window->visible()); 899 EXPECT_FALSE(embed_window->visible());
897 } 900 }
898 901
902 // Tests that setting capture only works while an input event is being
903 // processed, and the only the capture window can release capture.
904 TEST_F(WindowTreeTest, ExplicitSetCapture) {
905 TestWindowTreeClient* embed_connection = nullptr;
906 WindowTreeImpl* window_tree_connection = nullptr;
907 ServerWindow* window = nullptr;
908 EXPECT_NO_FATAL_FAILURE(
909 SetupEventTargeting(&embed_connection, &window_tree_connection, &window));
910 const ServerWindow* root_window = *window_tree_connection->roots().begin();
911 window_tree_connection->AddWindow(
912 FirstRootId(window_tree_connection),
913 ClientWindowIdForWindow(window_tree_connection, window));
914 window->SetBounds(gfx::Rect(0, 0, 100, 100));
915 ASSERT_TRUE(window_tree_connection->GetHost(window));
916
917 // Setting capture should fail when there are no active events
918 mojom::WindowTree* mojom_window_tree =
919 static_cast<mojom::WindowTree*>(window_tree_connection);
920 uint32_t change_id = 42;
921 mojom_window_tree->SetCapture(change_id, WindowIdToTransportId(window->id()));
922 WindowTreeHostImpl* host = window_tree_connection->GetHost(window);
923 EXPECT_NE(window, host->GetCaptureWindow());
924
925 // Setting capture after the event is acknowledged should fail
926 DispatchEventAndAckImmediately(CreatePointerDownEvent(10, 10));
927 mojom_window_tree->SetCapture(++change_id,
928 WindowIdToTransportId(window->id()));
929 EXPECT_NE(window, host->GetCaptureWindow());
930
931 // Settings while the event is being process should pass
932 DispatchEventWithoutAck(CreatePointerDownEvent(10, 10));
933 mojom_window_tree->SetCapture(++change_id,
934 WindowIdToTransportId(window->id()));
935 EXPECT_EQ(window, host->GetCaptureWindow());
936 AckPreviousEvent();
937
938 // Only the capture window should be able to release capture
939 mojom_window_tree->ReleaseCapture(++change_id,
940 WindowIdToTransportId(root_window->id()));
941 EXPECT_EQ(window, host->GetCaptureWindow());
942 mojom_window_tree->ReleaseCapture(++change_id,
943 WindowIdToTransportId(window->id()));
944 EXPECT_EQ(nullptr, host->GetCaptureWindow());
945 }
946
899 } // namespace ws 947 } // namespace ws
900 } // namespace mus 948 } // namespace mus
OLDNEW
« components/mus/ws/window_tree_host_impl.cc ('K') | « components/mus/ws/window_tree_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698