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

Side by Side Diff: services/ui/ws/test_utils.cc

Issue 2326203002: services/ui: Add WindowServerTestHelper. (Closed)
Patch Set: self nit Created 4 years, 3 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
« no previous file with comments | « services/ui/ws/test_utils.h ('k') | services/ui/ws/user_display_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "services/ui/ws/test_utils.h" 5 #include "services/ui/ws/test_utils.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "cc/output/copy_output_request.h" 10 #include "cc/output/copy_output_request.h"
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 DCHECK(window_server_); 411 DCHECK(window_server_);
412 412
413 for (int i = 0; i < num_displays_to_create_; ++i) 413 for (int i = 0; i < num_displays_to_create_; ++i)
414 AddDisplay(); 414 AddDisplay();
415 } 415 }
416 416
417 bool TestWindowServerDelegate::IsTestConfig() const { 417 bool TestWindowServerDelegate::IsTestConfig() const {
418 return true; 418 return true;
419 } 419 }
420 420
421 // WindowServerTestHelper ---------------------------------------------------
422
423 WindowServerTestHelper::WindowServerTestHelper()
424 : cursor_id_(0), platform_display_factory_(&cursor_id_) {
425 PlatformDisplay::set_factory_for_testing(&platform_display_factory_);
426 window_server_.reset(new WindowServer(&window_server_delegate_));
427 window_server_delegate_.set_window_server(window_server_.get());
428 }
429
430 WindowServerTestHelper::~WindowServerTestHelper() {
431 // Destroy |window_server_| while the message-loop is still alive.
432 window_server_.reset();
433 }
434
421 // WindowEventTargetingHelper ------------------------------------------------ 435 // WindowEventTargetingHelper ------------------------------------------------
422 436
423 WindowEventTargetingHelper::WindowEventTargetingHelper() 437 WindowEventTargetingHelper::WindowEventTargetingHelper()
424 : wm_client_(nullptr), 438 : wm_client_(nullptr),
425 cursor_id_(0),
426 platform_display_factory_(&cursor_id_),
427 display_binding_(nullptr), 439 display_binding_(nullptr),
428 display_(nullptr), 440 display_(nullptr),
429 surfaces_state_(new SurfacesState()), 441 surfaces_state_(new SurfacesState()) {
430 window_server_(nullptr) {
431 PlatformDisplay::set_factory_for_testing(&platform_display_factory_);
432 window_server_.reset(new WindowServer(&window_server_delegate_));
433 PlatformDisplayInitParams display_init_params; 442 PlatformDisplayInitParams display_init_params;
434 display_init_params.surfaces_state = surfaces_state_; 443 display_init_params.surfaces_state = surfaces_state_;
435 display_ = new Display(window_server_.get(), display_init_params); 444 display_ = new Display(window_server(), display_init_params);
436 display_binding_ = new TestDisplayBinding(window_server_.get()); 445 display_binding_ = new TestDisplayBinding(window_server());
437 display_->Init(base::WrapUnique(display_binding_)); 446 display_->Init(base::WrapUnique(display_binding_));
438 wm_client_ = window_server_delegate_.last_client(); 447 wm_client_ = ws_test_helper_.window_server_delegate()->last_client();
439 wm_client_->tracker()->changes()->clear(); 448 wm_client_->tracker()->changes()->clear();
440 } 449 }
441 450
442 WindowEventTargetingHelper::~WindowEventTargetingHelper() {} 451 WindowEventTargetingHelper::~WindowEventTargetingHelper() {}
443 452
444 ServerWindow* WindowEventTargetingHelper::CreatePrimaryTree( 453 ServerWindow* WindowEventTargetingHelper::CreatePrimaryTree(
445 const gfx::Rect& root_window_bounds, 454 const gfx::Rect& root_window_bounds,
446 const gfx::Rect& window_bounds) { 455 const gfx::Rect& window_bounds) {
447 WindowTree* wm_tree = window_server_->GetTreeWithId(1); 456 WindowTree* wm_tree = window_server()->GetTreeWithId(1);
448 const ClientWindowId embed_window_id( 457 const ClientWindowId embed_window_id(
449 WindowIdToTransportId(WindowId(wm_tree->id(), 1))); 458 WindowIdToTransportId(WindowId(wm_tree->id(), 1)));
450 EXPECT_TRUE(wm_tree->NewWindow(embed_window_id, ServerWindow::Properties())); 459 EXPECT_TRUE(wm_tree->NewWindow(embed_window_id, ServerWindow::Properties()));
451 EXPECT_TRUE(wm_tree->SetWindowVisibility(embed_window_id, true)); 460 EXPECT_TRUE(wm_tree->SetWindowVisibility(embed_window_id, true));
452 EXPECT_TRUE(wm_tree->AddWindow(FirstRootId(wm_tree), embed_window_id)); 461 EXPECT_TRUE(wm_tree->AddWindow(FirstRootId(wm_tree), embed_window_id));
453 display_->root_window()->SetBounds(root_window_bounds); 462 display_->root_window()->SetBounds(root_window_bounds);
454 mojom::WindowTreeClientPtr client; 463 mojom::WindowTreeClientPtr client;
455 mojom::WindowTreeClientRequest client_request = GetProxy(&client); 464 mojom::WindowTreeClientRequest client_request = GetProxy(&client);
456 wm_client_->Bind(std::move(client_request)); 465 wm_client_->Bind(std::move(client_request));
457 const uint32_t embed_flags = 0; 466 const uint32_t embed_flags = 0;
458 wm_tree->Embed(embed_window_id, std::move(client), embed_flags); 467 wm_tree->Embed(embed_window_id, std::move(client), embed_flags);
459 ServerWindow* embed_window = wm_tree->GetWindowByClientId(embed_window_id); 468 ServerWindow* embed_window = wm_tree->GetWindowByClientId(embed_window_id);
460 WindowTree* tree1 = window_server_->GetTreeWithRoot(embed_window); 469 WindowTree* tree1 = window_server()->GetTreeWithRoot(embed_window);
461 EXPECT_NE(nullptr, tree1); 470 EXPECT_NE(nullptr, tree1);
462 EXPECT_NE(tree1, wm_tree); 471 EXPECT_NE(tree1, wm_tree);
463 WindowTreeTestApi(tree1).set_user_id(wm_tree->user_id()); 472 WindowTreeTestApi(tree1).set_user_id(wm_tree->user_id());
464 473
465 embed_window->SetBounds(window_bounds); 474 embed_window->SetBounds(window_bounds);
466 475
467 return embed_window; 476 return embed_window;
468 } 477 }
469 478
470 void WindowEventTargetingHelper::CreateSecondaryTree( 479 void WindowEventTargetingHelper::CreateSecondaryTree(
471 ServerWindow* embed_window, 480 ServerWindow* embed_window,
472 const gfx::Rect& window_bounds, 481 const gfx::Rect& window_bounds,
473 TestWindowTreeClient** out_client, 482 TestWindowTreeClient** out_client,
474 WindowTree** window_tree, 483 WindowTree** window_tree,
475 ServerWindow** window) { 484 ServerWindow** window) {
476 WindowTree* tree1 = window_server_->GetTreeWithRoot(embed_window); 485 WindowTree* tree1 = window_server()->GetTreeWithRoot(embed_window);
477 ASSERT_TRUE(tree1 != nullptr); 486 ASSERT_TRUE(tree1 != nullptr);
478 const ClientWindowId child1_id( 487 const ClientWindowId child1_id(
479 WindowIdToTransportId(WindowId(tree1->id(), 1))); 488 WindowIdToTransportId(WindowId(tree1->id(), 1)));
480 EXPECT_TRUE(tree1->NewWindow(child1_id, ServerWindow::Properties())); 489 EXPECT_TRUE(tree1->NewWindow(child1_id, ServerWindow::Properties()));
481 ServerWindow* child1 = tree1->GetWindowByClientId(child1_id); 490 ServerWindow* child1 = tree1->GetWindowByClientId(child1_id);
482 ASSERT_TRUE(child1); 491 ASSERT_TRUE(child1);
483 EXPECT_TRUE(tree1->AddWindow(ClientWindowIdForWindow(tree1, embed_window), 492 EXPECT_TRUE(tree1->AddWindow(ClientWindowIdForWindow(tree1, embed_window),
484 child1_id)); 493 child1_id));
485 tree1->GetDisplay(embed_window)->AddActivationParent(embed_window); 494 tree1->GetDisplay(embed_window)->AddActivationParent(embed_window);
486 495
487 child1->SetVisible(true); 496 child1->SetVisible(true);
488 child1->SetBounds(window_bounds); 497 child1->SetBounds(window_bounds);
489 EnableHitTest(child1); 498 EnableHitTest(child1);
490 499
491 TestWindowTreeClient* embed_client = 500 TestWindowTreeClient* embed_client =
492 window_server_delegate_.last_client(); 501 ws_test_helper_.window_server_delegate()->last_client();
493 embed_client->tracker()->changes()->clear(); 502 embed_client->tracker()->changes()->clear();
494 wm_client_->tracker()->changes()->clear(); 503 wm_client_->tracker()->changes()->clear();
495 504
496 *out_client = embed_client; 505 *out_client = embed_client;
497 *window_tree = tree1; 506 *window_tree = tree1;
498 *window = child1; 507 *window = child1;
499 } 508 }
500 509
501 void WindowEventTargetingHelper::SetTaskRunner( 510 void WindowEventTargetingHelper::SetTaskRunner(
502 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 511 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
503 message_loop_.SetTaskRunner(task_runner); 512 ws_test_helper_.message_loop()->SetTaskRunner(task_runner);
504 } 513 }
505 514
506 // ---------------------------------------------------------------------------- 515 // ----------------------------------------------------------------------------
507 516
508 ServerWindow* FirstRoot(WindowTree* tree) { 517 ServerWindow* FirstRoot(WindowTree* tree) {
509 return tree->roots().size() == 1u 518 return tree->roots().size() == 1u
510 ? tree->GetWindow((*tree->roots().begin())->id()) 519 ? tree->GetWindow((*tree->roots().begin())->id())
511 : nullptr; 520 : nullptr;
512 } 521 }
513 522
(...skipping 30 matching lines...) Expand all
544 return nullptr; 553 return nullptr;
545 if (!tree->AddWindow(parent_client_id, client_window_id)) 554 if (!tree->AddWindow(parent_client_id, client_window_id))
546 return nullptr; 555 return nullptr;
547 *client_id = client_window_id; 556 *client_id = client_window_id;
548 return tree->GetWindowByClientId(client_window_id); 557 return tree->GetWindowByClientId(client_window_id);
549 } 558 }
550 559
551 } // namespace test 560 } // namespace test
552 } // namespace ws 561 } // namespace ws
553 } // namespace ui 562 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/test_utils.h ('k') | services/ui/ws/user_display_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698