Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / ash / test / display_manager_test_api.cc
blob9bad8917888e9360a067611362e96abc14066adf
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/test/display_manager_test_api.h"
7 #include <vector>
9 #include "ash/ash_switches.h"
10 #include "ash/display/display_info.h"
11 #include "ash/display/display_layout_store.h"
12 #include "ash/display/display_manager.h"
13 #include "ash/display/display_util.h"
14 #include "ash/display/extended_mouse_warp_controller.h"
15 #include "ash/display/mouse_cursor_event_filter.h"
16 #include "ash/display/unified_mouse_warp_controller.h"
17 #include "ash/shell.h"
18 #include "base/command_line.h"
19 #include "base/strings/string_split.h"
20 #include "ui/aura/env.h"
21 #include "ui/aura/window_event_dispatcher.h"
22 #include "ui/events/test/event_generator.h"
23 #include "ui/gfx/display.h"
25 namespace ash {
26 namespace test {
27 typedef std::vector<gfx::Display> DisplayList;
28 typedef DisplayInfo DisplayInfo;
29 typedef std::vector<DisplayInfo> DisplayInfoList;
31 namespace {
33 std::vector<DisplayInfo> CreateDisplayInfoListFromString(
34 const std::string specs,
35 DisplayManager* display_manager) {
36 std::vector<DisplayInfo> display_info_list;
37 std::vector<std::string> parts = base::SplitString(
38 specs, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
39 size_t index = 0;
41 DisplayManager::DisplayList list =
42 display_manager->IsInUnifiedMode()
43 ? display_manager->software_mirroring_display_list()
44 : display_manager->active_display_list();
46 for (std::vector<std::string>::const_iterator iter = parts.begin();
47 iter != parts.end(); ++iter, ++index) {
48 int64 id = (index < list.size()) ? list[index].id()
49 : gfx::Display::kInvalidDisplayID;
50 display_info_list.push_back(
51 DisplayInfo::CreateFromSpecWithID(*iter, id));
53 return display_info_list;
56 } // namespace
58 // static
59 bool DisplayManagerTestApi::TestIfMouseWarpsAt(
60 ui::test::EventGenerator& event_generator,
61 const gfx::Point& point_in_screen) {
62 aura::Window* context = Shell::GetAllRootWindows()[0];
63 DCHECK(!Shell::GetInstance()->display_manager()->IsInUnifiedMode());
64 static_cast<ExtendedMouseWarpController*>(
65 Shell::GetInstance()
66 ->mouse_cursor_filter()
67 ->mouse_warp_controller_for_test())
68 ->allow_non_native_event_for_test();
69 gfx::Screen* screen = gfx::Screen::GetScreenFor(context);
70 gfx::Display original_display =
71 screen->GetDisplayNearestPoint(point_in_screen);
72 event_generator.MoveMouseTo(point_in_screen);
73 return original_display.id() !=
74 screen->GetDisplayNearestPoint(
75 aura::Env::GetInstance()->last_mouse_location())
76 .id();
79 DisplayManagerTestApi::DisplayManagerTestApi()
80 : display_manager_(Shell::GetInstance()->display_manager()) {}
82 DisplayManagerTestApi::~DisplayManagerTestApi() {}
84 void DisplayManagerTestApi::UpdateDisplay(
85 const std::string& display_specs) {
86 std::vector<DisplayInfo> display_info_list =
87 CreateDisplayInfoListFromString(display_specs, display_manager_);
88 bool is_host_origin_set = false;
89 for (size_t i = 0; i < display_info_list.size(); ++i) {
90 const DisplayInfo& display_info = display_info_list[i];
91 if (display_info.bounds_in_native().origin() != gfx::Point(0, 0)) {
92 is_host_origin_set = true;
93 break;
97 // On non-testing environment, when a secondary display is connected, a new
98 // native (i.e. X) window for the display is always created below the
99 // previous one for GPU performance reasons. Try to emulate the behavior
100 // unless host origins are explicitly set.
101 if (!is_host_origin_set) {
102 // Sart from (1,1) so that windows won't overlap with native mouse cursor.
103 // See |AshTestBase::SetUp()|.
104 int next_y = 1;
105 for (std::vector<DisplayInfo>::iterator iter = display_info_list.begin();
106 iter != display_info_list.end(); ++iter) {
107 gfx::Rect bounds(iter->bounds_in_native().size());
108 bounds.set_x(1);
109 bounds.set_y(next_y);
110 next_y += bounds.height();
111 iter->SetBounds(bounds);
115 display_manager_->OnNativeDisplaysChanged(display_info_list);
116 display_manager_->UpdateInternalDisplayModeListForTest();
117 display_manager_->RunPendingTasksForTest();
120 int64 DisplayManagerTestApi::SetFirstDisplayAsInternalDisplay() {
121 const gfx::Display& internal = display_manager_->active_display_list_[0];
122 SetInternalDisplayId(internal.id());
123 return gfx::Display::InternalDisplayId();
126 void DisplayManagerTestApi::SetInternalDisplayId(int64 id) {
127 gfx::Display::SetInternalDisplayId(id);
128 display_manager_->UpdateInternalDisplayModeListForTest();
131 void DisplayManagerTestApi::DisableChangeDisplayUponHostResize() {
132 display_manager_->set_change_display_upon_host_resize(false);
135 void DisplayManagerTestApi::SetAvailableColorProfiles(
136 int64 display_id,
137 const std::vector<ui::ColorCalibrationProfile>& profiles) {
138 display_manager_->display_info_[display_id].set_available_color_profiles(
139 profiles);
142 ScopedDisable125DSFForUIScaling::ScopedDisable125DSFForUIScaling() {
143 DisplayInfo::SetUse125DSFForUIScalingForTest(false);
146 ScopedDisable125DSFForUIScaling::~ScopedDisable125DSFForUIScaling() {
147 DisplayInfo::SetUse125DSFForUIScalingForTest(true);
150 ScopedSetInternalDisplayId::ScopedSetInternalDisplayId(int64 id) {
151 DisplayManagerTestApi().SetInternalDisplayId(id);
154 ScopedSetInternalDisplayId::~ScopedSetInternalDisplayId() {
155 gfx::Display::SetInternalDisplayId(gfx::Display::kInvalidDisplayID);
158 bool SetDisplayResolution(int64 display_id, const gfx::Size& resolution) {
159 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
160 const DisplayInfo& info = display_manager->GetDisplayInfo(display_id);
161 DisplayMode mode;
162 if (!GetDisplayModeForResolution(info, resolution, &mode))
163 return false;
164 return display_manager->SetDisplayMode(display_id, mode);
167 } // namespace test
168 } // namespace ash