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

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

Issue 2904993003: chromeos: changes how DisplayManagerObservers are notified (Closed)
Patch Set: cleanup Created 3 years, 6 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.h » ('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 "base/strings/string_number_conversions.h"
10 #include "cc/output/copy_output_request.h" 11 #include "cc/output/copy_output_request.h"
11 #include "gpu/ipc/client/gpu_channel_host.h" 12 #include "gpu/ipc/client/gpu_channel_host.h"
12 #include "services/service_manager/public/interfaces/connector.mojom.h" 13 #include "services/service_manager/public/interfaces/connector.mojom.h"
13 #include "services/ui/public/interfaces/cursor/cursor.mojom.h" 14 #include "services/ui/public/interfaces/cursor/cursor.mojom.h"
14 #include "services/ui/ws/display_binding.h" 15 #include "services/ui/ws/display_binding.h"
16 #include "services/ui/ws/display_creation_config.h"
15 #include "services/ui/ws/display_manager.h" 17 #include "services/ui/ws/display_manager.h"
16 #include "services/ui/ws/window_manager_access_policy.h" 18 #include "services/ui/ws/window_manager_access_policy.h"
17 #include "services/ui/ws/window_manager_window_tree_factory.h" 19 #include "services/ui/ws/window_manager_window_tree_factory.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/base/cursor/cursor.h" 21 #include "ui/base/cursor/cursor.h"
20 #include "ui/gfx/geometry/dip_util.h" 22 #include "ui/gfx/geometry/dip_util.h"
21 23
22 namespace ui { 24 namespace ui {
23 namespace ws { 25 namespace ws {
24 namespace test { 26 namespace test {
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 std::unique_ptr<TestWindowTreeBinding> binding = 519 std::unique_ptr<TestWindowTreeBinding> binding =
518 base::MakeUnique<TestWindowTreeBinding>(tree); 520 base::MakeUnique<TestWindowTreeBinding>(tree);
519 bindings_.push_back(binding.get()); 521 bindings_.push_back(binding.get());
520 return std::move(binding); 522 return std::move(binding);
521 } 523 }
522 524
523 bool TestWindowServerDelegate::IsTestConfig() const { 525 bool TestWindowServerDelegate::IsTestConfig() const {
524 return true; 526 return true;
525 } 527 }
526 528
529 void TestWindowServerDelegate::OnWillCreateTreeForWindowManager(
530 bool automatically_create_display_roots) {
531 if (window_server_->display_creation_config() !=
532 DisplayCreationConfig::UNKNOWN) {
533 return;
534 }
535 window_server_->SetDisplayCreationConfig(
536 automatically_create_display_roots ? DisplayCreationConfig::AUTOMATIC
537 : DisplayCreationConfig::MANUAL);
538 }
539
527 // WindowServerTestHelper --------------------------------------------------- 540 // WindowServerTestHelper ---------------------------------------------------
528 541
529 WindowServerTestHelper::WindowServerTestHelper() 542 WindowServerTestHelper::WindowServerTestHelper()
530 : cursor_(ui::CursorType::kNull), platform_display_factory_(&cursor_) { 543 : cursor_(ui::CursorType::kNull), platform_display_factory_(&cursor_) {
531 // Some tests create their own message loop, for example to add a task runner. 544 // Some tests create their own message loop, for example to add a task runner.
532 if (!base::MessageLoop::current()) 545 if (!base::MessageLoop::current())
533 message_loop_ = base::MakeUnique<base::MessageLoop>(); 546 message_loop_ = base::MakeUnique<base::MessageLoop>();
534 PlatformDisplay::set_factory_for_testing(&platform_display_factory_); 547 PlatformDisplay::set_factory_for_testing(&platform_display_factory_);
535 window_server_ = base::MakeUnique<WindowServer>(&window_server_delegate_); 548 window_server_ = base::MakeUnique<WindowServer>(&window_server_delegate_);
536 window_server_delegate_.set_window_server(window_server_.get()); 549 window_server_delegate_.set_window_server(window_server_.get());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 *window = child1; 627 *window = child1;
615 } 628 }
616 629
617 void WindowEventTargetingHelper::SetTaskRunner( 630 void WindowEventTargetingHelper::SetTaskRunner(
618 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 631 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
619 base::MessageLoop::current()->SetTaskRunner(task_runner); 632 base::MessageLoop::current()->SetTaskRunner(task_runner);
620 } 633 }
621 634
622 // ---------------------------------------------------------------------------- 635 // ----------------------------------------------------------------------------
623 636
637 TestDisplayManagerObserver::TestDisplayManagerObserver() : binding_(this) {}
638
639 TestDisplayManagerObserver::~TestDisplayManagerObserver() = default;
640
641 mojom::DisplayManagerObserverPtr TestDisplayManagerObserver::GetPtr() {
642 return binding_.CreateInterfacePtrAndBind();
643 }
644
645 std::string TestDisplayManagerObserver::GetAndClearObserverCalls() {
646 std::string result;
647 std::swap(observer_calls_, result);
648 return result;
649 }
650
651 std::string TestDisplayManagerObserver::DisplayIdsToString(
652 const std::vector<mojom::WsDisplayPtr>& wm_displays) {
653 std::string display_ids;
654 for (const auto& wm_display : wm_displays) {
655 if (!display_ids.empty())
656 display_ids += " ";
657 display_ids += base::Int64ToString(wm_display->display.id());
658 }
659 return display_ids;
660 }
661
662 void TestDisplayManagerObserver::OnDisplaysChanged(
663 std::vector<mojom::WsDisplayPtr> displays,
664 int64_t primary_display_id,
665 int64_t internal_display_id) {
666 if (!observer_calls_.empty())
667 observer_calls_ += "\n";
668 observer_calls_ += "OnDisplaysChanged " + DisplayIdsToString(displays);
669 }
670
671 // -----------------------------------------------------------------------------
672
624 void AddWindowManager(WindowServer* window_server, 673 void AddWindowManager(WindowServer* window_server,
625 const UserId& user_id, 674 const UserId& user_id,
626 bool automatically_create_display_roots) { 675 bool automatically_create_display_roots) {
627 window_server->window_manager_window_tree_factory_set() 676 window_server->window_manager_window_tree_factory_set()
628 ->Add(user_id, nullptr) 677 ->Add(user_id, nullptr)
629 ->CreateWindowTree(nullptr, nullptr, automatically_create_display_roots); 678 ->CreateWindowTree(nullptr, nullptr, automatically_create_display_roots);
630 } 679 }
631 680
632 display::Display MakeDisplay(int origin_x, 681 display::Display MakeDisplay(int origin_x,
633 int origin_y, 682 int origin_y,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 if (!tree->AddWindow(parent_client_id, client_window_id)) 734 if (!tree->AddWindow(parent_client_id, client_window_id))
686 return nullptr; 735 return nullptr;
687 if (client_id) 736 if (client_id)
688 *client_id = client_window_id; 737 *client_id = client_window_id;
689 return tree->GetWindowByClientId(client_window_id); 738 return tree->GetWindowByClientId(client_window_id);
690 } 739 }
691 740
692 } // namespace test 741 } // namespace test
693 } // namespace ws 742 } // namespace ws
694 } // namespace ui 743 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/test_utils.h ('k') | services/ui/ws/user_display_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698