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"
9 #include "ash/display/display_info.h"
10 #include "ash/display/display_manager.h"
11 #include "ash/shell.h"
12 #include "base/strings/string_split.h"
13 #include "ui/aura/window_event_dispatcher.h"
14 #include "ui/gfx/display.h"
18 typedef std::vector
<gfx::Display
> DisplayList
;
19 typedef DisplayInfo DisplayInfo
;
20 typedef std::vector
<DisplayInfo
> DisplayInfoList
;
24 std::vector
<DisplayInfo
> CreateDisplayInfoListFromString(
25 const std::string specs
,
26 DisplayManager
* display_manager
) {
27 std::vector
<DisplayInfo
> display_info_list
;
28 std::vector
<std::string
> parts
;
29 base::SplitString(specs
, ',', &parts
);
31 for (std::vector
<std::string
>::const_iterator iter
= parts
.begin();
32 iter
!= parts
.end(); ++iter
, ++index
) {
33 int64 id
= index
< display_manager
->GetNumDisplays() ?
34 display_manager
->GetDisplayAt(index
).id() :
35 gfx::Display::kInvalidDisplayID
;
36 display_info_list
.push_back(
37 DisplayInfo::CreateFromSpecWithID(*iter
, id
));
39 return display_info_list
;
44 DisplayManagerTestApi::DisplayManagerTestApi(DisplayManager
* display_manager
)
45 : display_manager_(display_manager
) {}
47 DisplayManagerTestApi::~DisplayManagerTestApi() {}
49 void DisplayManagerTestApi::UpdateDisplay(
50 const std::string
& display_specs
) {
51 std::vector
<DisplayInfo
> display_info_list
=
52 CreateDisplayInfoListFromString(display_specs
, display_manager_
);
53 bool is_host_origin_set
= false;
54 for (size_t i
= 0; i
< display_info_list
.size(); ++i
) {
55 const DisplayInfo
& display_info
= display_info_list
[i
];
56 if (display_info
.bounds_in_native().origin() != gfx::Point(0, 0)) {
57 is_host_origin_set
= true;
62 // On non-testing environment, when a secondary display is connected, a new
63 // native (i.e. X) window for the display is always created below the
64 // previous one for GPU performance reasons. Try to emulate the behavior
65 // unless host origins are explicitly set.
66 if (!is_host_origin_set
) {
67 // Sart from (1,1) so that windows won't overlap with native mouse cursor.
68 // See |AshTestBase::SetUp()|.
70 for (std::vector
<DisplayInfo
>::iterator iter
= display_info_list
.begin();
71 iter
!= display_info_list
.end(); ++iter
) {
72 gfx::Rect
bounds(iter
->bounds_in_native().size());
75 next_y
+= bounds
.height();
76 iter
->SetBounds(bounds
);
80 display_manager_
->OnNativeDisplaysChanged(display_info_list
);
81 display_manager_
->UpdateInternalDisplayModeListForTest();
84 int64
DisplayManagerTestApi::SetFirstDisplayAsInternalDisplay() {
85 const gfx::Display
& internal
= display_manager_
->displays_
[0];
86 SetInternalDisplayId(internal
.id());
87 return gfx::Display::InternalDisplayId();
90 void DisplayManagerTestApi::SetInternalDisplayId(int64 id
) {
91 gfx::Display::SetInternalDisplayId(id
);
92 display_manager_
->UpdateInternalDisplayModeListForTest();
95 void DisplayManagerTestApi::DisableChangeDisplayUponHostResize() {
96 display_manager_
->set_change_display_upon_host_resize(false);
99 void DisplayManagerTestApi::SetAvailableColorProfiles(
101 const std::vector
<ui::ColorCalibrationProfile
>& profiles
) {
102 display_manager_
->display_info_
[display_id
].set_available_color_profiles(