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