Chromium Code Reviews| Index: ash/mus/test/wm_test_helper.cc |
| diff --git a/ash/mus/test/wm_test_helper.cc b/ash/mus/test/wm_test_helper.cc |
| index 63a5c48093389013266ed71fa16f0b61267b663a..8d4c8182134bed841ff8b5f926e484fa0061bb77 100644 |
| --- a/ash/mus/test/wm_test_helper.cc |
| +++ b/ash/mus/test/wm_test_helper.cc |
| @@ -12,6 +12,8 @@ |
| #include "ash/mus/window_manager_application.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/message_loop/message_loop.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/strings/string_split.h" |
| #include "base/test/sequenced_worker_pool_owner.h" |
| #include "services/ui/public/cpp/property_type_converters.h" |
| #include "services/ui/public/cpp/tests/window_tree_client_private.h" |
| @@ -19,9 +21,48 @@ |
| #include "ui/base/material_design/material_design_controller.h" |
| #include "ui/base/test/material_design_controller_test_api.h" |
| #include "ui/display/display.h" |
| +#include "ui/display/display_list.h" |
| namespace ash { |
| namespace mus { |
| +namespace { |
| + |
| +bool CompareByDisplayId(const RootWindowController* root1, |
| + const RootWindowController* root2) { |
| + return root1->display().id() < root2->display().id(); |
| +} |
| + |
| +// TODO(sky): at some point this needs to support everything in DisplayInfo, |
| +// for now just the bare minimum, which is [x+y-]wxh. |
| +gfx::Rect ParseDisplayBounds(const std::string& spec) { |
| + gfx::Rect bounds; |
| + const std::vector<std::string> parts = |
| + base::SplitString(spec, "-", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| + std::string size_spec; |
| + if (parts.size() == 2u) { |
| + size_spec = parts[1]; |
| + const std::vector<std::string> origin_parts = base::SplitString( |
| + parts[0], "+", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| + CHECK_EQ(2u, origin_parts.size()); |
| + int x, y; |
| + CHECK(base::StringToInt(origin_parts[0], &x)); |
| + CHECK(base::StringToInt(origin_parts[1], &y)); |
| + bounds.set_origin(gfx::Point(x, y)); |
| + } else { |
| + CHECK_EQ(1u, parts.size()); |
| + size_spec = spec; |
| + } |
| + const std::vector<std::string> size_parts = base::SplitString( |
| + size_spec, "x", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| + CHECK_EQ(2u, size_parts.size()); |
| + int w, h; |
|
msw
2016/09/12 22:01:51
nit: = 0 ?
sky
2016/09/12 23:11:27
Done.
|
| + CHECK(base::StringToInt(size_parts[0], &w)); |
| + CHECK(base::StringToInt(size_parts[1], &h)); |
| + bounds.set_size(gfx::Size(w, h)); |
| + return bounds; |
| +} |
| + |
| +} // namespace |
| WmTestHelper::WmTestHelper() {} |
| @@ -55,7 +96,7 @@ void WmTestHelper::Init() { |
| window_manager_app_->window_manager_->screen_.reset(screen_); |
| // Need an id other than kInvalidDisplayID so the Display is considered valid. |
|
msw
2016/09/12 22:01:51
nit: could this call CreateRootWindowController wi
sky
2016/09/12 23:11:27
This resulted in a bit more changes, but it's wher
|
| - display::Display display(1); |
| + display::Display display(next_display_id_++); |
| const gfx::Rect display_bounds(0, 0, 800, 600); |
| display.set_bounds(display_bounds); |
| // Offset the height slightly to give a different work area. -20 is arbitrary, |
| @@ -76,8 +117,74 @@ void WmTestHelper::Init() { |
| screen_->display_list()->AddDisplay(display, |
| display::DisplayList::Type::PRIMARY); |
| - ui::WindowTreeClientPrivate(window_tree_client) |
| - .CallWmNewDisplayAdded(display); |
| + window_tree_client_private_ = |
| + base::MakeUnique<ui::WindowTreeClientPrivate>(window_tree_client); |
| + window_tree_client_private_->CallWmNewDisplayAdded(display); |
| +} |
| + |
| +std::vector<RootWindowController*> WmTestHelper::GetRootsOrderedByDisplayId() { |
| + std::set<RootWindowController*> roots = |
| + window_manager_app_->window_manager()->GetRootWindowControllers(); |
| + std::vector<RootWindowController*> ordered_roots; |
| + ordered_roots.insert(ordered_roots.begin(), roots.begin(), roots.end()); |
| + std::sort(ordered_roots.begin(), ordered_roots.end(), &CompareByDisplayId); |
| + return ordered_roots; |
| +} |
| + |
| +void WmTestHelper::UpdateDisplay(const std::string& display_spec) { |
| + const std::vector<std::string> parts = base::SplitString( |
| + display_spec, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| + std::vector<RootWindowController*> root_window_controllers = |
| + GetRootsOrderedByDisplayId(); |
| + for (size_t i = 0, |
| + end = std::min(parts.size(), root_window_controllers.size()); |
| + i < end; ++i) { |
| + UpdateDisplay(root_window_controllers[i], parts[i]); |
| + } |
| + for (size_t i = root_window_controllers.size(); i < parts.size(); ++i) |
| + root_window_controllers.push_back(CreateRootWindowController(parts[i])); |
| + while (root_window_controllers.size() > parts.size()) { |
| + DestroyRootWindowController(root_window_controllers.back()); |
| + root_window_controllers.pop_back(); |
| + } |
| +} |
| + |
| +RootWindowController* WmTestHelper::CreateRootWindowController( |
| + const std::string& display_spec) { |
| + display::Display display(next_display_id_++, |
| + ParseDisplayBounds(display_spec)); |
| + gfx::Rect work_area(display.bounds()); |
| + // Offset the height slightly to give a different work area. -2 is arbitrary, |
|
msw
2016/09/12 22:01:51
q: Why -2 here and below, but -20 above?
sky
2016/09/12 23:11:27
Fixed.
|
| + // it could be anything. |
| + work_area.set_height(std::max(0, work_area.height() - 2)); |
| + display.set_work_area(work_area); |
| + window_tree_client_private_->CallWmNewDisplayAdded(display); |
| + return GetRootsOrderedByDisplayId().back(); |
| +} |
| + |
| +void WmTestHelper::UpdateDisplay(RootWindowController* root_window_controller, |
| + const std::string& display_spec) { |
| + gfx::Rect bounds = ParseDisplayBounds(display_spec); |
| + root_window_controller->display_.set_bounds(bounds); |
| + gfx::Rect work_area(bounds); |
| + // Offset the height slightly to give a different work area. -2 is arbitrary, |
| + // it could be anything. |
| + work_area.set_height(std::max(0, work_area.height() - 2)); |
| + root_window_controller->display_.set_work_area(work_area); |
| + root_window_controller->root()->SetBounds(gfx::Rect(bounds.size())); |
| + const bool is_primary = screen_->display_list()->FindDisplayById( |
| + root_window_controller->display().id()) == |
| + screen_->display_list()->GetPrimaryDisplayIterator(); |
| + screen_->display_list()->UpdateDisplay( |
| + root_window_controller->display(), |
| + is_primary ? display::DisplayList::Type::PRIMARY |
| + : display::DisplayList::Type::NOT_PRIMARY); |
| +} |
| + |
| +void WmTestHelper::DestroyRootWindowController( |
| + RootWindowController* root_window_controller) { |
| + window_manager_app_->window_manager()->RemoveDisplay( |
| + root_window_controller->root()); |
| } |
| } // namespace mus |