| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "components/mus/common/types.h" | 11 #include "components/mus/common/types.h" |
| 12 #include "components/mus/common/util.h" | 12 #include "components/mus/common/util.h" |
| 13 #include "components/mus/public/interfaces/window_tree.mojom.h" | 13 #include "components/mus/public/interfaces/window_tree.mojom.h" |
| 14 #include "components/mus/surfaces/surfaces_state.h" | 14 #include "components/mus/surfaces/surfaces_state.h" |
| 15 #include "components/mus/ws/connection_manager.h" | 15 #include "components/mus/ws/connection_manager.h" |
| 16 #include "components/mus/ws/connection_manager_delegate.h" | 16 #include "components/mus/ws/connection_manager_delegate.h" |
| 17 #include "components/mus/ws/display_manager.h" | 17 #include "components/mus/ws/display_manager.h" |
| 18 #include "components/mus/ws/ids.h" | 18 #include "components/mus/ws/ids.h" |
| 19 #include "components/mus/ws/platform_display.h" | 19 #include "components/mus/ws/platform_display.h" |
| 20 #include "components/mus/ws/platform_display_factory.h" | 20 #include "components/mus/ws/platform_display_factory.h" |
| 21 #include "components/mus/ws/server_window.h" | 21 #include "components/mus/ws/server_window.h" |
| 22 #include "components/mus/ws/test_utils.h" | 22 #include "components/mus/ws/test_utils.h" |
| 23 #include "components/mus/ws/window_manager_state.h" | 23 #include "components/mus/ws/window_manager_state.h" |
| 24 #include "components/mus/ws/window_tree.h" | 24 #include "components/mus/ws/window_tree.h" |
| 25 #include "components/mus/ws/window_tree_binding.h" | 25 #include "components/mus/ws/window_tree_binding.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "ui/events/event.h" |
| 27 #include "ui/gfx/geometry/rect.h" | 28 #include "ui/gfx/geometry/rect.h" |
| 28 | 29 |
| 29 namespace mus { | 30 namespace mus { |
| 30 namespace ws { | 31 namespace ws { |
| 31 namespace test { | 32 namespace test { |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 class TestWindowManagerFactory : public mojom::WindowManagerFactory { | 35 class TestWindowManagerFactory : public mojom::WindowManagerFactory { |
| 35 public: | 36 public: |
| 36 TestWindowManagerFactory() {} | 37 TestWindowManagerFactory() {} |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 EXPECT_EQ(1u, connection_manager_->num_trees()); | 147 EXPECT_EQ(1u, connection_manager_->num_trees()); |
| 147 } | 148 } |
| 148 | 149 |
| 149 EXPECT_FALSE(connection_manager_delegate_.got_on_no_more_displays()); | 150 EXPECT_FALSE(connection_manager_delegate_.got_on_no_more_displays()); |
| 150 // Destroy the Display, which should shutdown the trees. | 151 // Destroy the Display, which should shutdown the trees. |
| 151 connection_manager_->display_manager()->DestroyDisplay(display); | 152 connection_manager_->display_manager()->DestroyDisplay(display); |
| 152 EXPECT_EQ(0u, connection_manager_->num_trees()); | 153 EXPECT_EQ(0u, connection_manager_->num_trees()); |
| 153 EXPECT_TRUE(connection_manager_delegate_.got_on_no_more_displays()); | 154 EXPECT_TRUE(connection_manager_delegate_.got_on_no_more_displays()); |
| 154 } | 155 } |
| 155 | 156 |
| 157 TEST_F(DisplayTest, EventStateResetOnUserSwitch) { |
| 158 connection_manager_delegate_.set_num_displays_to_create(1); |
| 159 |
| 160 const UserId kTestId1 = "20"; |
| 161 const UserId kTestId2 = "201"; |
| 162 WindowManagerFactoryRegistryTestApi( |
| 163 connection_manager_->window_manager_factory_registry()) |
| 164 .AddService(kTestId1, &test_window_manager_factory_); |
| 165 WindowManagerFactoryRegistryTestApi( |
| 166 connection_manager_->window_manager_factory_registry()) |
| 167 .AddService(kTestId2, &test_window_manager_factory_); |
| 168 |
| 169 connection_manager_->user_id_tracker()->SetActiveUserId(kTestId1); |
| 170 |
| 171 DisplayManager* display_manager = connection_manager_->display_manager(); |
| 172 ASSERT_EQ(1u, display_manager->displays().size()); |
| 173 Display* display = *display_manager->displays().begin(); |
| 174 WindowManagerState* active_wms = display->GetActiveWindowManagerState(); |
| 175 ASSERT_TRUE(active_wms); |
| 176 EXPECT_EQ(kTestId1, active_wms->user_id()); |
| 177 |
| 178 static_cast<PlatformDisplayDelegate*>(display)->OnEvent(ui::PointerEvent( |
| 179 ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), |
| 180 gfx::Point(20, 25), base::TimeDelta(), |
| 181 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON))); |
| 182 |
| 183 EXPECT_TRUE(EventDispatcherTestApi(active_wms->event_dispatcher()) |
| 184 .AreAnyPointersDown()); |
| 185 EXPECT_EQ(gfx::Point(20, 25), |
| 186 active_wms->event_dispatcher()->mouse_pointer_last_location()); |
| 187 |
| 188 // Switch the user. Should trigger resetting state in old event dispatcher |
| 189 // and update state in new event dispatcher. |
| 190 connection_manager_->user_id_tracker()->SetActiveUserId(kTestId2); |
| 191 EXPECT_NE(active_wms, display->GetActiveWindowManagerState()); |
| 192 EXPECT_FALSE(EventDispatcherTestApi(active_wms->event_dispatcher()) |
| 193 .AreAnyPointersDown()); |
| 194 active_wms = display->GetActiveWindowManagerState(); |
| 195 EXPECT_EQ(kTestId2, active_wms->user_id()); |
| 196 EXPECT_EQ(gfx::Point(20, 25), |
| 197 active_wms->event_dispatcher()->mouse_pointer_last_location()); |
| 198 EXPECT_FALSE(EventDispatcherTestApi(active_wms->event_dispatcher()) |
| 199 .AreAnyPointersDown()); |
| 200 } |
| 201 |
| 202 // Verifies capture fails when wm is inactive and succeeds when wm is active. |
| 203 TEST_F(DisplayTest, SetCaptureFromWindowManager) { |
| 204 connection_manager_delegate_.set_num_displays_to_create(1); |
| 205 const UserId kTestId1 = "20"; |
| 206 const UserId kTestId2 = "201"; |
| 207 WindowManagerFactoryRegistryTestApi( |
| 208 connection_manager_->window_manager_factory_registry()) |
| 209 .AddService(kTestId1, &test_window_manager_factory_); |
| 210 WindowManagerFactoryRegistryTestApi( |
| 211 connection_manager_->window_manager_factory_registry()) |
| 212 .AddService(kTestId2, &test_window_manager_factory_); |
| 213 connection_manager_->user_id_tracker()->SetActiveUserId(kTestId1); |
| 214 DisplayManager* display_manager = connection_manager_->display_manager(); |
| 215 ASSERT_EQ(1u, display_manager->displays().size()); |
| 216 Display* display = *display_manager->displays().begin(); |
| 217 WindowManagerState* wms_for_id2 = |
| 218 display->GetWindowManagerStateForUser(kTestId2); |
| 219 ASSERT_TRUE(wms_for_id2); |
| 220 EXPECT_FALSE(wms_for_id2->IsActive()); |
| 221 ClientWindowId root_client_id; |
| 222 |
| 223 // Create a child of the root that we can set capture on. |
| 224 WindowTree* tree = wms_for_id2->tree(); |
| 225 const ServerWindow* root = *tree->roots().begin(); |
| 226 ASSERT_TRUE(tree->IsWindowKnown(root, &root_client_id)); |
| 227 ClientWindowId child_window_id( |
| 228 WindowIdToTransportId(WindowId(tree->id(), 101))); |
| 229 ASSERT_TRUE(tree->NewWindow(child_window_id, ServerWindow::Properties())); |
| 230 ASSERT_TRUE(tree->SetWindowVisibility(child_window_id, true)); |
| 231 ASSERT_TRUE(tree->AddWindow(root_client_id, child_window_id)); |
| 232 |
| 233 WindowTreeTestApi(tree).EnableCapture(); |
| 234 |
| 235 // SetCapture() should fail for user id2 as it is inactive. |
| 236 EXPECT_FALSE(tree->SetCapture(child_window_id)); |
| 237 |
| 238 // Make the second user active and verify capture works. |
| 239 connection_manager_->user_id_tracker()->SetActiveUserId(kTestId2); |
| 240 EXPECT_TRUE(wms_for_id2->IsActive()); |
| 241 EXPECT_TRUE(tree->SetCapture(child_window_id)); |
| 242 } |
| 243 |
| 156 } // namespace test | 244 } // namespace test |
| 157 } // namespace ws | 245 } // namespace ws |
| 158 } // namespace mus | 246 } // namespace mus |
| OLD | NEW |