| 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" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 WindowManagerState* display1_wms = | 291 WindowManagerState* display1_wms = |
| 292 display1->GetWindowManagerDisplayRootForUser(kTestId1) | 292 display1->GetWindowManagerDisplayRootForUser(kTestId1) |
| 293 ->window_manager_state(); | 293 ->window_manager_state(); |
| 294 Display* display2 = tree->GetDisplay(root2); | 294 Display* display2 = tree->GetDisplay(root2); |
| 295 WindowManagerState* display2_wms = | 295 WindowManagerState* display2_wms = |
| 296 display2->GetWindowManagerDisplayRootForUser(kTestId1) | 296 display2->GetWindowManagerDisplayRootForUser(kTestId1) |
| 297 ->window_manager_state(); | 297 ->window_manager_state(); |
| 298 EXPECT_EQ(display1_wms->window_tree(), display2_wms->window_tree()); | 298 EXPECT_EQ(display1_wms->window_tree(), display2_wms->window_tree()); |
| 299 } | 299 } |
| 300 | 300 |
| 301 namespace { |
| 302 |
| 303 // Returns the first non-primary display. |
| 304 Display* GetSecondaryDisplay(DisplayManager* display_manager) { |
| 305 for (Display* display : display_manager->displays()) { |
| 306 if (!display->platform_display()->IsPrimaryDisplay()) |
| 307 return display; |
| 308 } |
| 309 return nullptr; |
| 310 } |
| 311 |
| 312 // Returns the root ServerWindow for the specified Display. |
| 313 ServerWindow* GetRootOnDisplay(WindowTree* tree, Display* display) { |
| 314 for (const ServerWindow* root : tree->roots()) { |
| 315 if (tree->GetDisplay(root) == display) |
| 316 return const_cast<ServerWindow*>(root); |
| 317 } |
| 318 return nullptr; |
| 319 } |
| 320 |
| 321 // Tracks destruction of a ServerWindow, setting a bool* to true when |
| 322 // OnWindowDestroyed() is called |
| 323 class ServerWindowDestructionObserver : public ServerWindowObserver { |
| 324 public: |
| 325 ServerWindowDestructionObserver(ServerWindow* window, bool* destroyed) |
| 326 : window_(window), destroyed_(destroyed) { |
| 327 window_->AddObserver(this); |
| 328 } |
| 329 ~ServerWindowDestructionObserver() override { |
| 330 if (window_) |
| 331 window_->RemoveObserver(this); |
| 332 } |
| 333 |
| 334 // ServerWindowObserver: |
| 335 void OnWindowDestroyed(ServerWindow* window) override { |
| 336 *destroyed_ = true; |
| 337 window_->RemoveObserver(this); |
| 338 window_ = nullptr; |
| 339 } |
| 340 |
| 341 private: |
| 342 ServerWindow* window_; |
| 343 bool* destroyed_; |
| 344 |
| 345 DISALLOW_COPY_AND_ASSIGN(ServerWindowDestructionObserver); |
| 346 }; |
| 347 |
| 348 } // namespace |
| 349 |
| 350 // Assertions around destroying a secondary display. |
| 351 TEST_F(DisplayTest, DestroyingDisplayDoesntDelete) { |
| 352 window_server_delegate()->set_num_displays_to_create(2); |
| 353 WindowManagerWindowTreeFactorySetTestApi( |
| 354 window_server()->window_manager_window_tree_factory_set()) |
| 355 .Add(kTestId1); |
| 356 window_server()->user_id_tracker()->SetActiveUserId(kTestId1); |
| 357 ASSERT_EQ(1u, window_server_delegate()->bindings()->size()); |
| 358 WindowTree* tree = (*window_server_delegate()->bindings())[0]->tree(); |
| 359 ASSERT_EQ(2u, tree->roots().size()); |
| 360 Display* secondary_display = |
| 361 GetSecondaryDisplay(window_server()->display_manager()); |
| 362 ASSERT_TRUE(secondary_display); |
| 363 bool secondary_root_destroyed = false; |
| 364 ServerWindow* secondary_root = GetRootOnDisplay(tree, secondary_display); |
| 365 ASSERT_TRUE(secondary_root); |
| 366 ServerWindowDestructionObserver observer(secondary_root, |
| 367 &secondary_root_destroyed); |
| 368 ClientWindowId secondary_root_id = |
| 369 ClientWindowIdForWindow(tree, secondary_root); |
| 370 const int64_t secondary_display_id = secondary_display->GetId(); |
| 371 TestWindowTreeClient* tree_client = |
| 372 static_cast<TestWindowTreeClient*>(tree->client()); |
| 373 tree_client->tracker()->changes()->clear(); |
| 374 TestWindowManager* test_window_manager = |
| 375 window_server_delegate()->last_binding()->window_manager(); |
| 376 EXPECT_FALSE(test_window_manager->got_display_removed()); |
| 377 window_server()->display_manager()->DestroyDisplay(secondary_display); |
| 378 |
| 379 // Destroying the display should result in the following: |
| 380 // . The WindowManager should be told it was removed with the right id. |
| 381 EXPECT_TRUE(test_window_manager->got_display_removed()); |
| 382 EXPECT_EQ(secondary_display_id, test_window_manager->display_removed_id()); |
| 383 EXPECT_FALSE(secondary_root_destroyed); |
| 384 // The window should still be valid on the server side. |
| 385 ASSERT_TRUE(tree->GetWindowByClientId(secondary_root_id)); |
| 386 // No changes. |
| 387 ASSERT_EQ(0u, tree_client->tracker()->changes()->size()); |
| 388 |
| 389 // The window should be destroyed when the client says so. |
| 390 ASSERT_TRUE(tree->DeleteWindow(secondary_root_id)); |
| 391 EXPECT_TRUE(secondary_root_destroyed); |
| 392 } |
| 393 |
| 301 } // namespace test | 394 } // namespace test |
| 302 } // namespace ws | 395 } // namespace ws |
| 303 } // namespace ui | 396 } // namespace ui |
| OLD | NEW |