Sort unlaunched apps on app list start page by apps grid order.
[chromium-blink-merge.git] / ui / display / chromeos / configure_displays_task_unittest.cc
blob49e41fda3bfb20abd9fd750c7093dd7882edd264
1 // Copyright 2014 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 "base/bind.h"
6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/display/chromeos/configure_displays_task.h"
10 #include "ui/display/chromeos/test/action_logger_util.h"
11 #include "ui/display/chromeos/test/test_display_snapshot.h"
12 #include "ui/display/chromeos/test/test_native_display_delegate.h"
14 namespace ui {
15 namespace test {
17 namespace {
19 class ConfigureDisplaysTaskTest : public testing::Test {
20 public:
21 ConfigureDisplaysTaskTest()
22 : delegate_(&log_),
23 callback_called_(false),
24 status_(ConfigureDisplaysTask::ERROR),
25 small_mode_(gfx::Size(1366, 768), false, 60.0f),
26 big_mode_(gfx::Size(2560, 1600), false, 60.0f) {
27 std::vector<const DisplayMode*> modes;
28 modes.push_back(&small_mode_);
29 displays_[0].set_current_mode(&small_mode_);
30 displays_[0].set_native_mode(&small_mode_);
31 displays_[0].set_modes(modes);
32 displays_[0].set_display_id(123);
34 modes.push_back(&big_mode_);
35 displays_[1].set_current_mode(&big_mode_);
36 displays_[1].set_native_mode(&big_mode_);
37 displays_[1].set_modes(modes);
38 displays_[1].set_display_id(456);
40 ~ConfigureDisplaysTaskTest() override {}
42 void ConfigureCallback(ConfigureDisplaysTask::Status status) {
43 callback_called_ = true;
44 status_ = status;
47 protected:
48 base::MessageLoop message_loop_;
49 ActionLogger log_;
50 TestNativeDisplayDelegate delegate_;
52 bool callback_called_;
53 ConfigureDisplaysTask::Status status_;
55 const DisplayMode small_mode_;
56 const DisplayMode big_mode_;
58 TestDisplaySnapshot displays_[2];
60 private:
61 DISALLOW_COPY_AND_ASSIGN(ConfigureDisplaysTaskTest);
64 } // namespace
66 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithNoDisplays) {
67 ConfigureDisplaysTask::ResponseCallback callback = base::Bind(
68 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this));
70 ConfigureDisplaysTask task(&delegate_, std::vector<DisplayConfigureRequest>(),
71 callback);
73 task.Run();
75 EXPECT_TRUE(callback_called_);
76 EXPECT_EQ(ConfigureDisplaysTask::SUCCESS, status_);
77 EXPECT_EQ(kNoActions, log_.GetActionsAndClear());
80 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithOneDisplay) {
81 ConfigureDisplaysTask::ResponseCallback callback = base::Bind(
82 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this));
84 std::vector<DisplayConfigureRequest> requests(
85 1, DisplayConfigureRequest(&displays_[0], &small_mode_, gfx::Point()));
86 ConfigureDisplaysTask task(&delegate_, requests, callback);
87 task.Run();
89 EXPECT_TRUE(callback_called_);
90 EXPECT_EQ(ConfigureDisplaysTask::SUCCESS, status_);
91 EXPECT_EQ(GetCrtcAction(displays_[0], &small_mode_, gfx::Point()),
92 log_.GetActionsAndClear());
95 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithTwoDisplay) {
96 ConfigureDisplaysTask::ResponseCallback callback = base::Bind(
97 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this));
99 std::vector<DisplayConfigureRequest> requests;
100 for (size_t i = 0; i < arraysize(displays_); ++i) {
101 requests.push_back(DisplayConfigureRequest(
102 &displays_[i], displays_[i].native_mode(), gfx::Point()));
105 ConfigureDisplaysTask task(&delegate_, requests, callback);
106 task.Run();
108 EXPECT_TRUE(callback_called_);
109 EXPECT_EQ(ConfigureDisplaysTask::SUCCESS, status_);
110 EXPECT_EQ(
111 JoinActions(
112 GetCrtcAction(displays_[0], &small_mode_, gfx::Point()).c_str(),
113 GetCrtcAction(displays_[1], &big_mode_, gfx::Point()).c_str(), NULL),
114 log_.GetActionsAndClear());
117 TEST_F(ConfigureDisplaysTaskTest, DisableDisplayFails) {
118 ConfigureDisplaysTask::ResponseCallback callback = base::Bind(
119 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this));
121 delegate_.set_max_configurable_pixels(1);
123 std::vector<DisplayConfigureRequest> requests(
124 1, DisplayConfigureRequest(&displays_[0], nullptr, gfx::Point()));
125 ConfigureDisplaysTask task(&delegate_, requests, callback);
126 task.Run();
128 EXPECT_TRUE(callback_called_);
129 EXPECT_EQ(ConfigureDisplaysTask::ERROR, status_);
130 EXPECT_EQ(JoinActions(
131 GetCrtcAction(displays_[0], nullptr, gfx::Point()).c_str(),
132 NULL),
133 log_.GetActionsAndClear());
136 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithOneDisplayFails) {
137 ConfigureDisplaysTask::ResponseCallback callback = base::Bind(
138 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this));
140 delegate_.set_max_configurable_pixels(1);
142 std::vector<DisplayConfigureRequest> requests(
143 1, DisplayConfigureRequest(&displays_[1], &big_mode_, gfx::Point()));
144 ConfigureDisplaysTask task(&delegate_, requests, callback);
145 task.Run();
147 EXPECT_TRUE(callback_called_);
148 EXPECT_EQ(ConfigureDisplaysTask::ERROR, status_);
149 EXPECT_EQ(JoinActions(
150 GetCrtcAction(displays_[1], &big_mode_, gfx::Point()).c_str(),
151 GetCrtcAction(displays_[1], &small_mode_, gfx::Point()).c_str(),
152 NULL),
153 log_.GetActionsAndClear());
156 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithTwoDisplayFails) {
157 ConfigureDisplaysTask::ResponseCallback callback = base::Bind(
158 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this));
160 delegate_.set_max_configurable_pixels(1);
162 std::vector<DisplayConfigureRequest> requests;
163 for (size_t i = 0; i < arraysize(displays_); ++i) {
164 requests.push_back(DisplayConfigureRequest(
165 &displays_[i], displays_[i].native_mode(), gfx::Point()));
168 ConfigureDisplaysTask task(&delegate_, requests, callback);
169 task.Run();
171 EXPECT_TRUE(callback_called_);
172 EXPECT_EQ(ConfigureDisplaysTask::ERROR, status_);
173 EXPECT_EQ(JoinActions(
174 GetCrtcAction(displays_[0], &small_mode_, gfx::Point()).c_str(),
175 GetCrtcAction(displays_[1], &big_mode_, gfx::Point()).c_str(),
176 GetCrtcAction(displays_[1], &small_mode_, gfx::Point()).c_str(),
177 NULL),
178 log_.GetActionsAndClear());
181 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithTwoDisplaysPartialSuccess) {
182 ConfigureDisplaysTask::ResponseCallback callback = base::Bind(
183 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this));
185 delegate_.set_max_configurable_pixels(small_mode_.size().GetArea());
187 std::vector<DisplayConfigureRequest> requests;
188 for (size_t i = 0; i < arraysize(displays_); ++i) {
189 requests.push_back(DisplayConfigureRequest(
190 &displays_[i], displays_[i].native_mode(), gfx::Point()));
193 ConfigureDisplaysTask task(&delegate_, requests, callback);
194 task.Run();
196 EXPECT_TRUE(callback_called_);
197 EXPECT_EQ(ConfigureDisplaysTask::PARTIAL_SUCCESS, status_);
198 EXPECT_EQ(JoinActions(
199 GetCrtcAction(displays_[0], &small_mode_, gfx::Point()).c_str(),
200 GetCrtcAction(displays_[1], &big_mode_, gfx::Point()).c_str(),
201 GetCrtcAction(displays_[1], &small_mode_, gfx::Point()).c_str(),
202 NULL),
203 log_.GetActionsAndClear());
206 TEST_F(ConfigureDisplaysTaskTest, AsyncConfigureWithTwoDisplaysPartialSuccess) {
207 ConfigureDisplaysTask::ResponseCallback callback = base::Bind(
208 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this));
210 delegate_.set_run_async(true);
211 delegate_.set_max_configurable_pixels(small_mode_.size().GetArea());
213 std::vector<DisplayConfigureRequest> requests;
214 for (size_t i = 0; i < arraysize(displays_); ++i) {
215 requests.push_back(DisplayConfigureRequest(
216 &displays_[i], displays_[i].native_mode(), gfx::Point()));
219 ConfigureDisplaysTask task(&delegate_, requests, callback);
220 task.Run();
222 EXPECT_FALSE(callback_called_);
223 base::RunLoop().RunUntilIdle();
225 EXPECT_TRUE(callback_called_);
226 EXPECT_EQ(ConfigureDisplaysTask::PARTIAL_SUCCESS, status_);
227 EXPECT_EQ(JoinActions(
228 GetCrtcAction(displays_[0], &small_mode_, gfx::Point()).c_str(),
229 GetCrtcAction(displays_[1], &big_mode_, gfx::Point()).c_str(),
230 GetCrtcAction(displays_[1], &small_mode_, gfx::Point()).c_str(),
231 NULL),
232 log_.GetActionsAndClear());
235 } // namespace test
236 } // namespace ui