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

Side by Side Diff: ash/mus/test/wm_test_helper.cc

Issue 2840043003: chromeos: Makes mushrome use simplified display management (Closed)
Patch Set: merge Created 3 years, 7 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 | « ash/mus/test/wm_test_base.cc ('k') | ash/mus/window_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 "ash/mus/test/wm_test_helper.h" 5 #include "ash/mus/test/wm_test_helper.h"
6 6
7 #include "ash/mus/screen_mus.h" 7 #include "ash/mus/screen_mus.h"
8 #include "ash/mus/window_manager.h" 8 #include "ash/mus/window_manager.h"
9 #include "ash/mus/window_manager_application.h" 9 #include "ash/mus/window_manager_application.h"
10 #include "ash/public/cpp/config.h" 10 #include "ash/public/cpp/config.h"
11 #include "ash/shell.h"
11 #include "ash/test/test_shell_delegate.h" 12 #include "ash/test/test_shell_delegate.h"
12 #include "ash/wm_window.h" 13 #include "ash/wm_window.h"
13 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
14 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
15 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_split.h" 17 #include "base/strings/string_split.h"
17 #include "base/test/sequenced_worker_pool_owner.h" 18 #include "base/test/sequenced_worker_pool_owner.h"
18 #include "services/ui/public/cpp/input_devices/input_device_client.h" 19 #include "services/ui/public/cpp/input_devices/input_device_client.h"
19 #include "services/ui/public/cpp/property_type_converters.h" 20 #include "services/ui/public/cpp/property_type_converters.h"
20 #include "ui/aura/mus/window_tree_client.h" 21 #include "ui/aura/mus/window_tree_client.h"
21 #include "ui/aura/test/env_test_helper.h" 22 #include "ui/aura/test/env_test_helper.h"
22 #include "ui/aura/test/mus/window_tree_client_private.h" 23 #include "ui/aura/test/mus/window_tree_client_private.h"
23 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
24 #include "ui/base/material_design/material_design_controller.h" 25 #include "ui/base/material_design/material_design_controller.h"
25 #include "ui/base/test/material_design_controller_test_api.h" 26 #include "ui/base/test/material_design_controller_test_api.h"
26 #include "ui/display/display.h" 27 #include "ui/display/display.h"
27 #include "ui/display/display_list.h" 28 #include "ui/display/display_list.h"
28 #include "ui/display/screen_base.h" 29 #include "ui/display/screen_base.h"
30 #include "ui/display/test/display_manager_test_api.h"
29 #include "ui/views/test/test_views_delegate.h" 31 #include "ui/views/test/test_views_delegate.h"
30 32
31 namespace ash { 33 namespace ash {
32 namespace mus { 34 namespace mus {
33 namespace { 35 namespace {
34 36
35 bool CompareByDisplayId(RootWindowController* root1, 37 bool CompareByDisplayId(RootWindowController* root1,
36 RootWindowController* root2) { 38 RootWindowController* root2) {
37 return root1->GetWindow()->GetDisplayNearestWindow().id() < 39 return root1->GetWindow()->GetDisplayNearestWindow().id() <
38 root2->GetWindow()->GetDisplayNearestWindow().id(); 40 root2->GetWindow()->GetDisplayNearestWindow().id();
(...skipping 27 matching lines...) Expand all
66 CHECK(base::StringToInt(size_parts[1], &h)); 68 CHECK(base::StringToInt(size_parts[1], &h));
67 bounds.set_size(gfx::Size(w, h)); 69 bounds.set_size(gfx::Size(w, h));
68 return bounds; 70 return bounds;
69 } 71 }
70 72
71 } // namespace 73 } // namespace
72 74
73 WmTestHelper::WmTestHelper() {} 75 WmTestHelper::WmTestHelper() {}
74 76
75 WmTestHelper::~WmTestHelper() { 77 WmTestHelper::~WmTestHelper() {
78 // Flush the message loop so that any pending tasks are run. This ensures
79 // any delayed tasks, such as deleting RootWindowControllers, are processed
80 // before continuing.
81 base::RunLoop().RunUntilIdle();
82
76 // Needs to be destroyed before material design. 83 // Needs to be destroyed before material design.
77 window_manager_app_.reset(); 84 window_manager_app_.reset();
78 85
79 base::RunLoop().RunUntilIdle(); 86 base::RunLoop().RunUntilIdle();
80 blocking_pool_owner_.reset(); 87 blocking_pool_owner_.reset();
81 base::RunLoop().RunUntilIdle(); 88 base::RunLoop().RunUntilIdle();
82 89
83 ui::test::MaterialDesignControllerTestAPI::Uninitialize(); 90 ui::test::MaterialDesignControllerTestAPI::Uninitialize();
84 91
85 input_device_client_.reset(); 92 input_device_client_.reset();
86 } 93 }
87 94
88 void WmTestHelper::Init() { 95 void WmTestHelper::Init() {
89 const Config config = base::CommandLine::ForCurrentProcess()->HasSwitch("mus") 96 const Config config = base::CommandLine::ForCurrentProcess()->HasSwitch("mus")
90 ? Config::MUS 97 ? Config::MUS
91 : Config::MASH; 98 : Config::MASH;
92 if (config == Config::MUS) 99 if (config == Config::MUS)
93 input_device_client_ = base::MakeUnique<ui::InputDeviceClient>(); 100 input_device_client_ = base::MakeUnique<ui::InputDeviceClient>();
94 101
95 // MaterialDesignController may have already been initialized. To cover that 102 // MaterialDesignController may have already been initialized. To cover that
96 // case explicitly uninitialize before initializing. 103 // case explicitly uninitialize before initializing.
97 ui::test::MaterialDesignControllerTestAPI::Uninitialize(); 104 ui::test::MaterialDesignControllerTestAPI::Uninitialize();
98 ui::MaterialDesignController::Initialize(); 105 ui::MaterialDesignController::Initialize();
99 106
100 views_delegate_ = base::MakeUnique<views::TestViewsDelegate>(); 107 views_delegate_ = base::MakeUnique<views::TestViewsDelegate>();
101 108
102 window_manager_app_ = base::MakeUnique<WindowManagerApplication>(); 109 const bool show_primary_host_on_connect = false;
110 window_manager_app_ = base::MakeUnique<WindowManagerApplication>(
111 show_primary_host_on_connect, config);
103 112
104 message_loop_.reset(new base::MessageLoopForUI()); 113 message_loop_.reset(new base::MessageLoopForUI());
105 114
106 const size_t kMaxNumberThreads = 3u; // Matches that of content. 115 const size_t kMaxNumberThreads = 3u; // Matches that of content.
107 const char kThreadNamePrefix[] = "MashBlockingForTesting"; 116 const char kThreadNamePrefix[] = "MashBlockingForTesting";
108 blocking_pool_owner_ = base::MakeUnique<base::SequencedWorkerPoolOwner>( 117 blocking_pool_owner_ = base::MakeUnique<base::SequencedWorkerPoolOwner>(
109 kMaxNumberThreads, kThreadNamePrefix); 118 kMaxNumberThreads, kThreadNamePrefix);
110 119
111 window_manager_app_->window_manager_ = 120 window_manager_app_->window_manager_ = base::MakeUnique<WindowManager>(
112 base::MakeUnique<WindowManager>(nullptr, config); 121 nullptr, config, show_primary_host_on_connect);
113 window_manager_app_->window_manager()->shell_delegate_ = 122 window_manager_app_->window_manager()->shell_delegate_ =
114 base::MakeUnique<test::TestShellDelegate>(); 123 base::MakeUnique<test::TestShellDelegate>();
115 124
116 window_tree_client_setup_.InitForWindowManager( 125 window_tree_client_setup_.InitForWindowManager(
117 window_manager_app_->window_manager_.get(), 126 window_manager_app_->window_manager_.get(),
118 window_manager_app_->window_manager_.get()); 127 window_manager_app_->window_manager_.get());
119 aura::test::EnvTestHelper().SetWindowTreeClient( 128 aura::test::EnvTestHelper().SetWindowTreeClient(
120 window_tree_client_setup_.window_tree_client()); 129 window_tree_client_setup_.window_tree_client());
121 // See comment in AshTestHelper for details on why NetworkHandler is not 130 // See comment in AshTestHelper for details on why NetworkHandler is not
122 // initialized. 131 // initialized.
123 const bool init_network_handler = false; 132 const bool init_network_handler = false;
124 window_manager_app_->InitWindowManager( 133 window_manager_app_->InitWindowManager(
125 window_tree_client_setup_.OwnWindowTreeClient(), 134 window_tree_client_setup_.OwnWindowTreeClient(),
126 blocking_pool_owner_->pool(), init_network_handler); 135 blocking_pool_owner_->pool(), init_network_handler);
127 136
128 aura::WindowTreeClient* window_tree_client = 137 aura::WindowTreeClient* window_tree_client =
129 window_manager_app_->window_manager()->window_tree_client(); 138 window_manager_app_->window_manager()->window_tree_client();
130 window_tree_client_private_ = 139 window_tree_client_private_ =
131 base::MakeUnique<aura::WindowTreeClientPrivate>(window_tree_client); 140 base::MakeUnique<aura::WindowTreeClientPrivate>(window_tree_client);
132 int next_x = 0; 141 if (config == Config::MUS) {
133 CreateRootWindowController("800x600", &next_x); 142 window_tree_client_private_->CallOnConnect();
143 } else {
144 int next_x = 0;
145 CreateRootWindowController("800x600", &next_x);
146 }
134 } 147 }
135 148
136 std::vector<RootWindowController*> WmTestHelper::GetRootsOrderedByDisplayId() { 149 std::vector<RootWindowController*> WmTestHelper::GetRootsOrderedByDisplayId() {
137 std::set<RootWindowController*> roots = 150 std::set<RootWindowController*> roots =
138 window_manager_app_->window_manager()->GetRootWindowControllers(); 151 window_manager_app_->window_manager()->GetRootWindowControllers();
139 std::vector<RootWindowController*> ordered_roots; 152 std::vector<RootWindowController*> ordered_roots;
140 ordered_roots.insert(ordered_roots.begin(), roots.begin(), roots.end()); 153 ordered_roots.insert(ordered_roots.begin(), roots.begin(), roots.end());
141 std::sort(ordered_roots.begin(), ordered_roots.end(), &CompareByDisplayId); 154 std::sort(ordered_roots.begin(), ordered_roots.end(), &CompareByDisplayId);
142 return ordered_roots; 155 return ordered_roots;
143 } 156 }
144 157
145 void WmTestHelper::UpdateDisplay(const std::string& display_spec) { 158 void WmTestHelper::UpdateDisplay(const std::string& display_spec) {
159 if (Shell::GetAshConfig() == Config::MUS) {
160 display::test::DisplayManagerTestApi(Shell::Get()->display_manager())
161 .UpdateDisplay(display_spec);
162 return;
163 }
146 const std::vector<std::string> parts = base::SplitString( 164 const std::vector<std::string> parts = base::SplitString(
147 display_spec, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 165 display_spec, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
148 std::vector<RootWindowController*> root_window_controllers = 166 std::vector<RootWindowController*> root_window_controllers =
149 GetRootsOrderedByDisplayId(); 167 GetRootsOrderedByDisplayId();
150 int next_x = 0; 168 int next_x = 0;
151 for (size_t i = 0, 169 for (size_t i = 0,
152 end = std::min(parts.size(), root_window_controllers.size()); 170 end = std::min(parts.size(), root_window_controllers.size());
153 i < end; ++i) { 171 i < end; ++i) {
154 UpdateDisplay(root_window_controllers[i], parts[i], &next_x); 172 UpdateDisplay(root_window_controllers[i], parts[i], &next_x);
155 } 173 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 const bool is_primary = 215 const bool is_primary =
198 screen->display_list().FindDisplayById(updated_display.id()) == 216 screen->display_list().FindDisplayById(updated_display.id()) ==
199 screen->display_list().GetPrimaryDisplayIterator(); 217 screen->display_list().GetPrimaryDisplayIterator();
200 screen->display_list().UpdateDisplay( 218 screen->display_list().UpdateDisplay(
201 updated_display, is_primary ? display::DisplayList::Type::PRIMARY 219 updated_display, is_primary ? display::DisplayList::Type::PRIMARY
202 : display::DisplayList::Type::NOT_PRIMARY); 220 : display::DisplayList::Type::NOT_PRIMARY);
203 } 221 }
204 222
205 } // namespace mus 223 } // namespace mus
206 } // namespace ash 224 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/test/wm_test_base.cc ('k') | ash/mus/window_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698