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

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

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

Powered by Google App Engine
This is Rietveld 408576698