| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/display/chromeos/configure_displays_task.h" | 12 #include "ui/display/chromeos/configure_displays_task.h" |
| 13 #include "ui/display/chromeos/test/action_logger_util.h" | 13 #include "ui/display/chromeos/test/action_logger_util.h" |
| 14 #include "ui/display/chromeos/test/test_display_snapshot.h" | |
| 15 #include "ui/display/chromeos/test/test_native_display_delegate.h" | 14 #include "ui/display/chromeos/test/test_native_display_delegate.h" |
| 15 #include "ui/display/fake_display_snapshot.h" |
| 16 | 16 |
| 17 namespace ui { | 17 namespace ui { |
| 18 namespace test { | 18 namespace test { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class ConfigureDisplaysTaskTest : public testing::Test { | 22 class ConfigureDisplaysTaskTest : public testing::Test { |
| 23 public: | 23 public: |
| 24 ConfigureDisplaysTaskTest() | 24 ConfigureDisplaysTaskTest() |
| 25 : delegate_(&log_), | 25 : delegate_(&log_), |
| 26 callback_called_(false), | 26 callback_called_(false), |
| 27 status_(ConfigureDisplaysTask::ERROR), | 27 status_(ConfigureDisplaysTask::ERROR), |
| 28 small_mode_(gfx::Size(1366, 768), false, 60.0f), | 28 small_mode_(gfx::Size(1366, 768), false, 60.0f), |
| 29 big_mode_(gfx::Size(2560, 1600), false, 60.0f) { | 29 big_mode_(gfx::Size(2560, 1600), false, 60.0f) { |
| 30 std::vector<std::unique_ptr<const DisplayMode>> modes; | 30 displays_[0] = display::FakeDisplaySnapshot::Builder() |
| 31 modes.push_back(small_mode_.Clone()); | 31 .SetId(123) |
| 32 displays_[0].set_current_mode(modes.front().get()); | 32 .SetNativeMode(small_mode_.Clone()) |
| 33 displays_[0].set_native_mode(modes.front().get()); | 33 .SetCurrentMode(small_mode_.Clone()) |
| 34 displays_[0].set_modes(std::move(modes)); | 34 .Build(); |
| 35 displays_[0].set_display_id(123); | |
| 36 | 35 |
| 37 modes.clear(); | 36 displays_[1] = display::FakeDisplaySnapshot::Builder() |
| 38 modes.push_back(small_mode_.Clone()); | 37 .SetId(456) |
| 39 modes.push_back(big_mode_.Clone()); | 38 .SetNativeMode(big_mode_.Clone()) |
| 40 displays_[1].set_current_mode(modes.back().get()); | 39 .SetCurrentMode(big_mode_.Clone()) |
| 41 displays_[1].set_native_mode(modes.back().get()); | 40 .AddMode(small_mode_.Clone()) |
| 42 displays_[1].set_modes(std::move(modes)); | 41 .Build(); |
| 43 displays_[1].set_display_id(456); | |
| 44 } | 42 } |
| 45 ~ConfigureDisplaysTaskTest() override {} | 43 ~ConfigureDisplaysTaskTest() override {} |
| 46 | 44 |
| 47 void ConfigureCallback(ConfigureDisplaysTask::Status status) { | 45 void ConfigureCallback(ConfigureDisplaysTask::Status status) { |
| 48 callback_called_ = true; | 46 callback_called_ = true; |
| 49 status_ = status; | 47 status_ = status; |
| 50 } | 48 } |
| 51 | 49 |
| 52 protected: | 50 protected: |
| 53 base::MessageLoop message_loop_; | 51 base::MessageLoop message_loop_; |
| 54 ActionLogger log_; | 52 ActionLogger log_; |
| 55 TestNativeDisplayDelegate delegate_; | 53 TestNativeDisplayDelegate delegate_; |
| 56 | 54 |
| 57 bool callback_called_; | 55 bool callback_called_; |
| 58 ConfigureDisplaysTask::Status status_; | 56 ConfigureDisplaysTask::Status status_; |
| 59 | 57 |
| 60 const DisplayMode small_mode_; | 58 const DisplayMode small_mode_; |
| 61 const DisplayMode big_mode_; | 59 const DisplayMode big_mode_; |
| 62 | 60 |
| 63 TestDisplaySnapshot displays_[2]; | 61 std::unique_ptr<DisplaySnapshot> displays_[2]; |
| 64 | 62 |
| 65 private: | 63 private: |
| 66 DISALLOW_COPY_AND_ASSIGN(ConfigureDisplaysTaskTest); | 64 DISALLOW_COPY_AND_ASSIGN(ConfigureDisplaysTaskTest); |
| 67 }; | 65 }; |
| 68 | 66 |
| 69 } // namespace | 67 } // namespace |
| 70 | 68 |
| 71 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithNoDisplays) { | 69 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithNoDisplays) { |
| 72 ConfigureDisplaysTask::ResponseCallback callback = base::Bind( | 70 ConfigureDisplaysTask::ResponseCallback callback = base::Bind( |
| 73 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this)); | 71 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this)); |
| 74 | 72 |
| 75 ConfigureDisplaysTask task(&delegate_, std::vector<DisplayConfigureRequest>(), | 73 ConfigureDisplaysTask task(&delegate_, std::vector<DisplayConfigureRequest>(), |
| 76 callback); | 74 callback); |
| 77 | 75 |
| 78 task.Run(); | 76 task.Run(); |
| 79 | 77 |
| 80 EXPECT_TRUE(callback_called_); | 78 EXPECT_TRUE(callback_called_); |
| 81 EXPECT_EQ(ConfigureDisplaysTask::SUCCESS, status_); | 79 EXPECT_EQ(ConfigureDisplaysTask::SUCCESS, status_); |
| 82 EXPECT_EQ(kNoActions, log_.GetActionsAndClear()); | 80 EXPECT_EQ(kNoActions, log_.GetActionsAndClear()); |
| 83 } | 81 } |
| 84 | 82 |
| 85 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithOneDisplay) { | 83 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithOneDisplay) { |
| 86 ConfigureDisplaysTask::ResponseCallback callback = base::Bind( | 84 ConfigureDisplaysTask::ResponseCallback callback = base::Bind( |
| 87 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this)); | 85 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this)); |
| 88 | 86 |
| 89 std::vector<DisplayConfigureRequest> requests( | 87 std::vector<DisplayConfigureRequest> requests( |
| 90 1, DisplayConfigureRequest(&displays_[0], &small_mode_, gfx::Point())); | 88 1, |
| 89 DisplayConfigureRequest(displays_[0].get(), &small_mode_, gfx::Point())); |
| 91 ConfigureDisplaysTask task(&delegate_, requests, callback); | 90 ConfigureDisplaysTask task(&delegate_, requests, callback); |
| 92 task.Run(); | 91 task.Run(); |
| 93 | 92 |
| 94 EXPECT_TRUE(callback_called_); | 93 EXPECT_TRUE(callback_called_); |
| 95 EXPECT_EQ(ConfigureDisplaysTask::SUCCESS, status_); | 94 EXPECT_EQ(ConfigureDisplaysTask::SUCCESS, status_); |
| 96 EXPECT_EQ(GetCrtcAction(displays_[0], &small_mode_, gfx::Point()), | 95 EXPECT_EQ(GetCrtcAction(*displays_[0], &small_mode_, gfx::Point()), |
| 97 log_.GetActionsAndClear()); | 96 log_.GetActionsAndClear()); |
| 98 } | 97 } |
| 99 | 98 |
| 100 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithTwoDisplay) { | 99 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithTwoDisplay) { |
| 101 ConfigureDisplaysTask::ResponseCallback callback = base::Bind( | 100 ConfigureDisplaysTask::ResponseCallback callback = base::Bind( |
| 102 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this)); | 101 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this)); |
| 103 | 102 |
| 104 std::vector<DisplayConfigureRequest> requests; | 103 std::vector<DisplayConfigureRequest> requests; |
| 105 for (size_t i = 0; i < arraysize(displays_); ++i) { | 104 for (size_t i = 0; i < arraysize(displays_); ++i) { |
| 106 requests.push_back(DisplayConfigureRequest( | 105 requests.push_back(DisplayConfigureRequest( |
| 107 &displays_[i], displays_[i].native_mode(), gfx::Point())); | 106 displays_[i].get(), displays_[i]->native_mode(), gfx::Point())); |
| 108 } | 107 } |
| 109 | 108 |
| 110 ConfigureDisplaysTask task(&delegate_, requests, callback); | 109 ConfigureDisplaysTask task(&delegate_, requests, callback); |
| 111 task.Run(); | 110 task.Run(); |
| 112 | 111 |
| 113 EXPECT_TRUE(callback_called_); | 112 EXPECT_TRUE(callback_called_); |
| 114 EXPECT_EQ(ConfigureDisplaysTask::SUCCESS, status_); | 113 EXPECT_EQ(ConfigureDisplaysTask::SUCCESS, status_); |
| 115 EXPECT_EQ( | 114 EXPECT_EQ( |
| 116 JoinActions( | 115 JoinActions( |
| 117 GetCrtcAction(displays_[0], &small_mode_, gfx::Point()).c_str(), | 116 GetCrtcAction(*displays_[0], &small_mode_, gfx::Point()).c_str(), |
| 118 GetCrtcAction(displays_[1], &big_mode_, gfx::Point()).c_str(), NULL), | 117 GetCrtcAction(*displays_[1], &big_mode_, gfx::Point()).c_str(), |
| 118 nullptr), |
| 119 log_.GetActionsAndClear()); | 119 log_.GetActionsAndClear()); |
| 120 } | 120 } |
| 121 | 121 |
| 122 TEST_F(ConfigureDisplaysTaskTest, DisableDisplayFails) { | 122 TEST_F(ConfigureDisplaysTaskTest, DisableDisplayFails) { |
| 123 ConfigureDisplaysTask::ResponseCallback callback = base::Bind( | 123 ConfigureDisplaysTask::ResponseCallback callback = base::Bind( |
| 124 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this)); | 124 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this)); |
| 125 | 125 |
| 126 delegate_.set_max_configurable_pixels(1); | 126 delegate_.set_max_configurable_pixels(1); |
| 127 | 127 |
| 128 std::vector<DisplayConfigureRequest> requests( | 128 std::vector<DisplayConfigureRequest> requests( |
| 129 1, DisplayConfigureRequest(&displays_[0], nullptr, gfx::Point())); | 129 1, DisplayConfigureRequest(displays_[0].get(), nullptr, gfx::Point())); |
| 130 ConfigureDisplaysTask task(&delegate_, requests, callback); | 130 ConfigureDisplaysTask task(&delegate_, requests, callback); |
| 131 task.Run(); | 131 task.Run(); |
| 132 | 132 |
| 133 EXPECT_TRUE(callback_called_); | 133 EXPECT_TRUE(callback_called_); |
| 134 EXPECT_EQ(ConfigureDisplaysTask::ERROR, status_); | 134 EXPECT_EQ(ConfigureDisplaysTask::ERROR, status_); |
| 135 EXPECT_EQ(JoinActions( | 135 EXPECT_EQ( |
| 136 GetCrtcAction(displays_[0], nullptr, gfx::Point()).c_str(), | 136 JoinActions(GetCrtcAction(*displays_[0], nullptr, gfx::Point()).c_str(), |
| 137 NULL), | 137 nullptr), |
| 138 log_.GetActionsAndClear()); | 138 log_.GetActionsAndClear()); |
| 139 } | 139 } |
| 140 | 140 |
| 141 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithOneDisplayFails) { | 141 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithOneDisplayFails) { |
| 142 ConfigureDisplaysTask::ResponseCallback callback = base::Bind( | 142 ConfigureDisplaysTask::ResponseCallback callback = base::Bind( |
| 143 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this)); | 143 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this)); |
| 144 | 144 |
| 145 delegate_.set_max_configurable_pixels(1); | 145 delegate_.set_max_configurable_pixels(1); |
| 146 | 146 |
| 147 std::vector<DisplayConfigureRequest> requests( | 147 std::vector<DisplayConfigureRequest> requests( |
| 148 1, DisplayConfigureRequest(&displays_[1], &big_mode_, gfx::Point())); | 148 1, DisplayConfigureRequest(displays_[1].get(), &big_mode_, gfx::Point())); |
| 149 ConfigureDisplaysTask task(&delegate_, requests, callback); | 149 ConfigureDisplaysTask task(&delegate_, requests, callback); |
| 150 task.Run(); | 150 task.Run(); |
| 151 | 151 |
| 152 EXPECT_TRUE(callback_called_); | 152 EXPECT_TRUE(callback_called_); |
| 153 EXPECT_EQ(ConfigureDisplaysTask::ERROR, status_); | 153 EXPECT_EQ(ConfigureDisplaysTask::ERROR, status_); |
| 154 EXPECT_EQ(JoinActions( | 154 EXPECT_EQ( |
| 155 GetCrtcAction(displays_[1], &big_mode_, gfx::Point()).c_str(), | 155 JoinActions( |
| 156 GetCrtcAction(displays_[1], &small_mode_, gfx::Point()).c_str(), | 156 GetCrtcAction(*displays_[1], &big_mode_, gfx::Point()).c_str(), |
| 157 NULL), | 157 GetCrtcAction(*displays_[1], &small_mode_, gfx::Point()).c_str(), |
| 158 log_.GetActionsAndClear()); | 158 nullptr), |
| 159 log_.GetActionsAndClear()); |
| 159 } | 160 } |
| 160 | 161 |
| 161 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithTwoDisplayFails) { | 162 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithTwoDisplayFails) { |
| 162 ConfigureDisplaysTask::ResponseCallback callback = base::Bind( | 163 ConfigureDisplaysTask::ResponseCallback callback = base::Bind( |
| 163 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this)); | 164 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this)); |
| 164 | 165 |
| 165 delegate_.set_max_configurable_pixels(1); | 166 delegate_.set_max_configurable_pixels(1); |
| 166 | 167 |
| 167 std::vector<DisplayConfigureRequest> requests; | 168 std::vector<DisplayConfigureRequest> requests; |
| 168 for (size_t i = 0; i < arraysize(displays_); ++i) { | 169 for (size_t i = 0; i < arraysize(displays_); ++i) { |
| 169 requests.push_back(DisplayConfigureRequest( | 170 requests.push_back(DisplayConfigureRequest( |
| 170 &displays_[i], displays_[i].native_mode(), gfx::Point())); | 171 displays_[i].get(), displays_[i]->native_mode(), gfx::Point())); |
| 171 } | 172 } |
| 172 | 173 |
| 173 ConfigureDisplaysTask task(&delegate_, requests, callback); | 174 ConfigureDisplaysTask task(&delegate_, requests, callback); |
| 174 task.Run(); | 175 task.Run(); |
| 175 | 176 |
| 176 EXPECT_TRUE(callback_called_); | 177 EXPECT_TRUE(callback_called_); |
| 177 EXPECT_EQ(ConfigureDisplaysTask::ERROR, status_); | 178 EXPECT_EQ(ConfigureDisplaysTask::ERROR, status_); |
| 178 EXPECT_EQ(JoinActions( | 179 EXPECT_EQ( |
| 179 GetCrtcAction(displays_[0], &small_mode_, gfx::Point()).c_str(), | 180 JoinActions( |
| 180 GetCrtcAction(displays_[1], &big_mode_, gfx::Point()).c_str(), | 181 GetCrtcAction(*displays_[0], &small_mode_, gfx::Point()).c_str(), |
| 181 GetCrtcAction(displays_[1], &small_mode_, gfx::Point()).c_str(), | 182 GetCrtcAction(*displays_[1], &big_mode_, gfx::Point()).c_str(), |
| 182 NULL), | 183 GetCrtcAction(*displays_[1], &small_mode_, gfx::Point()).c_str(), |
| 183 log_.GetActionsAndClear()); | 184 nullptr), |
| 185 log_.GetActionsAndClear()); |
| 184 } | 186 } |
| 185 | 187 |
| 186 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithTwoDisplaysPartialSuccess) { | 188 TEST_F(ConfigureDisplaysTaskTest, ConfigureWithTwoDisplaysPartialSuccess) { |
| 187 ConfigureDisplaysTask::ResponseCallback callback = base::Bind( | 189 ConfigureDisplaysTask::ResponseCallback callback = base::Bind( |
| 188 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this)); | 190 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this)); |
| 189 | 191 |
| 190 delegate_.set_max_configurable_pixels(small_mode_.size().GetArea()); | 192 delegate_.set_max_configurable_pixels(small_mode_.size().GetArea()); |
| 191 | 193 |
| 192 std::vector<DisplayConfigureRequest> requests; | 194 std::vector<DisplayConfigureRequest> requests; |
| 193 for (size_t i = 0; i < arraysize(displays_); ++i) { | 195 for (size_t i = 0; i < arraysize(displays_); ++i) { |
| 194 requests.push_back(DisplayConfigureRequest( | 196 requests.push_back(DisplayConfigureRequest( |
| 195 &displays_[i], displays_[i].native_mode(), gfx::Point())); | 197 displays_[i].get(), displays_[i]->native_mode(), gfx::Point())); |
| 196 } | 198 } |
| 197 | 199 |
| 198 ConfigureDisplaysTask task(&delegate_, requests, callback); | 200 ConfigureDisplaysTask task(&delegate_, requests, callback); |
| 199 task.Run(); | 201 task.Run(); |
| 200 | 202 |
| 201 EXPECT_TRUE(callback_called_); | 203 EXPECT_TRUE(callback_called_); |
| 202 EXPECT_EQ(ConfigureDisplaysTask::PARTIAL_SUCCESS, status_); | 204 EXPECT_EQ(ConfigureDisplaysTask::PARTIAL_SUCCESS, status_); |
| 203 EXPECT_EQ(JoinActions( | 205 EXPECT_EQ( |
| 204 GetCrtcAction(displays_[0], &small_mode_, gfx::Point()).c_str(), | 206 JoinActions( |
| 205 GetCrtcAction(displays_[1], &big_mode_, gfx::Point()).c_str(), | 207 GetCrtcAction(*displays_[0], &small_mode_, gfx::Point()).c_str(), |
| 206 GetCrtcAction(displays_[1], &small_mode_, gfx::Point()).c_str(), | 208 GetCrtcAction(*displays_[1], &big_mode_, gfx::Point()).c_str(), |
| 207 NULL), | 209 GetCrtcAction(*displays_[1], &small_mode_, gfx::Point()).c_str(), |
| 208 log_.GetActionsAndClear()); | 210 nullptr), |
| 211 log_.GetActionsAndClear()); |
| 209 } | 212 } |
| 210 | 213 |
| 211 TEST_F(ConfigureDisplaysTaskTest, AsyncConfigureWithTwoDisplaysPartialSuccess) { | 214 TEST_F(ConfigureDisplaysTaskTest, AsyncConfigureWithTwoDisplaysPartialSuccess) { |
| 212 ConfigureDisplaysTask::ResponseCallback callback = base::Bind( | 215 ConfigureDisplaysTask::ResponseCallback callback = base::Bind( |
| 213 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this)); | 216 &ConfigureDisplaysTaskTest::ConfigureCallback, base::Unretained(this)); |
| 214 | 217 |
| 215 delegate_.set_run_async(true); | 218 delegate_.set_run_async(true); |
| 216 delegate_.set_max_configurable_pixels(small_mode_.size().GetArea()); | 219 delegate_.set_max_configurable_pixels(small_mode_.size().GetArea()); |
| 217 | 220 |
| 218 std::vector<DisplayConfigureRequest> requests; | 221 std::vector<DisplayConfigureRequest> requests; |
| 219 for (size_t i = 0; i < arraysize(displays_); ++i) { | 222 for (size_t i = 0; i < arraysize(displays_); ++i) { |
| 220 requests.push_back(DisplayConfigureRequest( | 223 requests.push_back(DisplayConfigureRequest( |
| 221 &displays_[i], displays_[i].native_mode(), gfx::Point())); | 224 displays_[i].get(), displays_[i]->native_mode(), gfx::Point())); |
| 222 } | 225 } |
| 223 | 226 |
| 224 ConfigureDisplaysTask task(&delegate_, requests, callback); | 227 ConfigureDisplaysTask task(&delegate_, requests, callback); |
| 225 task.Run(); | 228 task.Run(); |
| 226 | 229 |
| 227 EXPECT_FALSE(callback_called_); | 230 EXPECT_FALSE(callback_called_); |
| 228 base::RunLoop().RunUntilIdle(); | 231 base::RunLoop().RunUntilIdle(); |
| 229 | 232 |
| 230 EXPECT_TRUE(callback_called_); | 233 EXPECT_TRUE(callback_called_); |
| 231 EXPECT_EQ(ConfigureDisplaysTask::PARTIAL_SUCCESS, status_); | 234 EXPECT_EQ(ConfigureDisplaysTask::PARTIAL_SUCCESS, status_); |
| 232 EXPECT_EQ(JoinActions( | 235 EXPECT_EQ( |
| 233 GetCrtcAction(displays_[0], &small_mode_, gfx::Point()).c_str(), | 236 JoinActions( |
| 234 GetCrtcAction(displays_[1], &big_mode_, gfx::Point()).c_str(), | 237 GetCrtcAction(*displays_[0], &small_mode_, gfx::Point()).c_str(), |
| 235 GetCrtcAction(displays_[1], &small_mode_, gfx::Point()).c_str(), | 238 GetCrtcAction(*displays_[1], &big_mode_, gfx::Point()).c_str(), |
| 236 NULL), | 239 GetCrtcAction(*displays_[1], &small_mode_, gfx::Point()).c_str(), |
| 237 log_.GetActionsAndClear()); | 240 nullptr), |
| 241 log_.GetActionsAndClear()); |
| 238 } | 242 } |
| 239 | 243 |
| 240 } // namespace test | 244 } // namespace test |
| 241 } // namespace ui | 245 } // namespace ui |
| OLD | NEW |