Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 17 | #include <stddef.h> |
Tao Bao | 152e0eb | 2018-05-13 00:34:45 -0700 | [diff] [blame] | 18 | #include <stdio.h> |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 19 | |
Tao Bao | 6cd8168 | 2018-05-03 21:53:11 -0700 | [diff] [blame] | 20 | #include <functional> |
| 21 | #include <map> |
| 22 | #include <memory> |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 23 | #include <string> |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 24 | #include <vector> |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 25 | |
Tao Bao | 6cd8168 | 2018-05-03 21:53:11 -0700 | [diff] [blame] | 26 | #include <android-base/logging.h> |
Tao Bao | 152e0eb | 2018-05-13 00:34:45 -0700 | [diff] [blame] | 27 | #include <android-base/stringprintf.h> |
| 28 | #include <android-base/test_utils.h> |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 29 | #include <gtest/gtest.h> |
| 30 | |
Tao Bao | 6cd8168 | 2018-05-03 21:53:11 -0700 | [diff] [blame] | 31 | #include "common/test_constants.h" |
| 32 | #include "device.h" |
| 33 | #include "otautil/paths.h" |
| 34 | #include "private/resources.h" |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 35 | #include "screen_ui.h" |
| 36 | |
| 37 | static const std::vector<std::string> HEADERS{ "header" }; |
| 38 | static const std::vector<std::string> ITEMS{ "item1", "item2", "item3", "item4", "1234567890" }; |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 39 | |
| 40 | TEST(ScreenUITest, StartPhoneMenuSmoke) { |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 41 | Menu menu(false, 10, 20, HEADERS, ITEMS, 0); |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 42 | ASSERT_FALSE(menu.scrollable()); |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 43 | ASSERT_EQ(HEADERS[0], menu.text_headers()[0]); |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 44 | ASSERT_EQ(5u, menu.ItemsCount()); |
| 45 | |
| 46 | std::string message; |
| 47 | ASSERT_FALSE(menu.ItemsOverflow(&message)); |
| 48 | for (size_t i = 0; i < menu.ItemsCount(); i++) { |
| 49 | ASSERT_EQ(ITEMS[i], menu.TextItem(i)); |
| 50 | } |
| 51 | |
| 52 | ASSERT_EQ(0, menu.selection()); |
| 53 | } |
| 54 | |
| 55 | TEST(ScreenUITest, StartWearMenuSmoke) { |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 56 | Menu menu(true, 10, 8, HEADERS, ITEMS, 1); |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 57 | ASSERT_TRUE(menu.scrollable()); |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 58 | ASSERT_EQ(HEADERS[0], menu.text_headers()[0]); |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 59 | ASSERT_EQ(5u, menu.ItemsCount()); |
| 60 | |
| 61 | std::string message; |
| 62 | ASSERT_FALSE(menu.ItemsOverflow(&message)); |
| 63 | for (size_t i = 0; i < menu.ItemsCount() - 1; i++) { |
| 64 | ASSERT_EQ(ITEMS[i], menu.TextItem(i)); |
| 65 | } |
| 66 | // Test of the last item is truncated |
| 67 | ASSERT_EQ("12345678", menu.TextItem(4)); |
| 68 | ASSERT_EQ(1, menu.selection()); |
| 69 | } |
| 70 | |
| 71 | TEST(ScreenUITest, StartPhoneMenuItemsOverflow) { |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 72 | Menu menu(false, 1, 20, HEADERS, ITEMS, 0); |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 73 | ASSERT_FALSE(menu.scrollable()); |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 74 | ASSERT_EQ(1u, menu.ItemsCount()); |
| 75 | |
| 76 | std::string message; |
| 77 | ASSERT_FALSE(menu.ItemsOverflow(&message)); |
| 78 | for (size_t i = 0; i < menu.ItemsCount(); i++) { |
| 79 | ASSERT_EQ(ITEMS[i], menu.TextItem(i)); |
| 80 | } |
| 81 | |
| 82 | ASSERT_EQ(0u, menu.MenuStart()); |
| 83 | ASSERT_EQ(1u, menu.MenuEnd()); |
| 84 | } |
| 85 | |
| 86 | TEST(ScreenUITest, StartWearMenuItemsOverflow) { |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 87 | Menu menu(true, 1, 20, HEADERS, ITEMS, 0); |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 88 | ASSERT_TRUE(menu.scrollable()); |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 89 | ASSERT_EQ(5u, menu.ItemsCount()); |
| 90 | |
| 91 | std::string message; |
| 92 | ASSERT_TRUE(menu.ItemsOverflow(&message)); |
| 93 | ASSERT_EQ("Current item: 1/5", message); |
| 94 | |
| 95 | for (size_t i = 0; i < menu.ItemsCount(); i++) { |
| 96 | ASSERT_EQ(ITEMS[i], menu.TextItem(i)); |
| 97 | } |
| 98 | |
| 99 | ASSERT_EQ(0u, menu.MenuStart()); |
| 100 | ASSERT_EQ(1u, menu.MenuEnd()); |
| 101 | } |
| 102 | |
| 103 | TEST(ScreenUITest, PhoneMenuSelectSmoke) { |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 104 | int sel = 0; |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 105 | Menu menu(false, 10, 20, HEADERS, ITEMS, sel); |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 106 | // Mimic down button 10 times (2 * items size) |
| 107 | for (int i = 0; i < 10; i++) { |
| 108 | sel = menu.Select(++sel); |
| 109 | ASSERT_EQ(sel, menu.selection()); |
| 110 | |
| 111 | // Wraps the selection for unscrollable menu when it reaches the boundary. |
| 112 | int expected = (i + 1) % 5; |
| 113 | ASSERT_EQ(expected, menu.selection()); |
| 114 | |
| 115 | ASSERT_EQ(0u, menu.MenuStart()); |
| 116 | ASSERT_EQ(5u, menu.MenuEnd()); |
| 117 | } |
| 118 | |
| 119 | // Mimic up button 10 times |
| 120 | for (int i = 0; i < 10; i++) { |
| 121 | sel = menu.Select(--sel); |
| 122 | ASSERT_EQ(sel, menu.selection()); |
| 123 | |
| 124 | int expected = (9 - i) % 5; |
| 125 | ASSERT_EQ(expected, menu.selection()); |
| 126 | |
| 127 | ASSERT_EQ(0u, menu.MenuStart()); |
| 128 | ASSERT_EQ(5u, menu.MenuEnd()); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | TEST(ScreenUITest, WearMenuSelectSmoke) { |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 133 | int sel = 0; |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 134 | Menu menu(true, 10, 20, HEADERS, ITEMS, sel); |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 135 | // Mimic pressing down button 10 times (2 * items size) |
| 136 | for (int i = 0; i < 10; i++) { |
| 137 | sel = menu.Select(++sel); |
| 138 | ASSERT_EQ(sel, menu.selection()); |
| 139 | |
| 140 | // Stops the selection at the boundary if the menu is scrollable. |
| 141 | int expected = std::min(i + 1, 4); |
| 142 | ASSERT_EQ(expected, menu.selection()); |
| 143 | |
| 144 | ASSERT_EQ(0u, menu.MenuStart()); |
| 145 | ASSERT_EQ(5u, menu.MenuEnd()); |
| 146 | } |
| 147 | |
| 148 | // Mimic pressing up button 10 times |
| 149 | for (int i = 0; i < 10; i++) { |
| 150 | sel = menu.Select(--sel); |
| 151 | ASSERT_EQ(sel, menu.selection()); |
| 152 | |
| 153 | int expected = std::max(3 - i, 0); |
| 154 | ASSERT_EQ(expected, menu.selection()); |
| 155 | |
| 156 | ASSERT_EQ(0u, menu.MenuStart()); |
| 157 | ASSERT_EQ(5u, menu.MenuEnd()); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | TEST(ScreenUITest, WearMenuSelectItemsOverflow) { |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 162 | int sel = 1; |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 163 | Menu menu(true, 3, 20, HEADERS, ITEMS, sel); |
Tianjie Xu | 5fe5eb6 | 2018-03-20 16:07:39 -0700 | [diff] [blame] | 164 | ASSERT_EQ(5u, menu.ItemsCount()); |
| 165 | |
| 166 | // Scroll the menu to the end, and check the start & end of menu. |
| 167 | for (int i = 0; i < 3; i++) { |
| 168 | sel = menu.Select(++sel); |
| 169 | ASSERT_EQ(i + 2, sel); |
| 170 | ASSERT_EQ(static_cast<size_t>(i), menu.MenuStart()); |
| 171 | ASSERT_EQ(static_cast<size_t>(i + 3), menu.MenuEnd()); |
| 172 | } |
| 173 | |
| 174 | // Press down button one more time won't change the MenuStart() and MenuEnd(). |
| 175 | sel = menu.Select(++sel); |
| 176 | ASSERT_EQ(4, sel); |
| 177 | ASSERT_EQ(2u, menu.MenuStart()); |
| 178 | ASSERT_EQ(5u, menu.MenuEnd()); |
| 179 | |
| 180 | // Scroll the menu to the top. |
| 181 | // The expected menu sel, start & ends are: |
| 182 | // sel 3, start 2, end 5 |
| 183 | // sel 2, start 2, end 5 |
| 184 | // sel 1, start 1, end 4 |
| 185 | // sel 0, start 0, end 3 |
| 186 | for (int i = 0; i < 4; i++) { |
| 187 | sel = menu.Select(--sel); |
| 188 | ASSERT_EQ(3 - i, sel); |
| 189 | ASSERT_EQ(static_cast<size_t>(std::min(3 - i, 2)), menu.MenuStart()); |
| 190 | ASSERT_EQ(static_cast<size_t>(std::min(6 - i, 5)), menu.MenuEnd()); |
| 191 | } |
| 192 | |
| 193 | // Press up button one more time won't change the MenuStart() and MenuEnd(). |
| 194 | sel = menu.Select(--sel); |
| 195 | ASSERT_EQ(0, sel); |
| 196 | ASSERT_EQ(0u, menu.MenuStart()); |
| 197 | ASSERT_EQ(3u, menu.MenuEnd()); |
| 198 | } |
Tao Bao | 6cd8168 | 2018-05-03 21:53:11 -0700 | [diff] [blame] | 199 | |
| 200 | static constexpr int kMagicAction = 101; |
| 201 | |
| 202 | enum class KeyCode : int { |
| 203 | TIMEOUT = -1, |
| 204 | NO_OP = 0, |
| 205 | UP = 1, |
| 206 | DOWN = 2, |
| 207 | ENTER = 3, |
| 208 | MAGIC = 1001, |
| 209 | LAST, |
| 210 | }; |
| 211 | |
| 212 | static const std::map<KeyCode, int> kKeyMapping{ |
| 213 | // clang-format off |
| 214 | { KeyCode::NO_OP, Device::kNoAction }, |
| 215 | { KeyCode::UP, Device::kHighlightUp }, |
| 216 | { KeyCode::DOWN, Device::kHighlightDown }, |
| 217 | { KeyCode::ENTER, Device::kInvokeItem }, |
| 218 | { KeyCode::MAGIC, kMagicAction }, |
| 219 | // clang-format on |
| 220 | }; |
| 221 | |
| 222 | class TestableScreenRecoveryUI : public ScreenRecoveryUI { |
| 223 | public: |
| 224 | int WaitKey() override; |
| 225 | |
| 226 | void SetKeyBuffer(const std::vector<KeyCode>& buffer); |
| 227 | |
| 228 | int KeyHandler(int key, bool visible) const; |
| 229 | |
Tao Bao | 152e0eb | 2018-05-13 00:34:45 -0700 | [diff] [blame] | 230 | // The following functions expose the protected members for test purpose. |
| 231 | void RunLoadAnimation() { |
| 232 | LoadAnimation(); |
| 233 | } |
| 234 | |
| 235 | size_t GetLoopFrames() const { |
| 236 | return loop_frames; |
| 237 | } |
| 238 | |
| 239 | size_t GetIntroFrames() const { |
| 240 | return intro_frames; |
| 241 | } |
| 242 | |
Tao Bao | 6cd8168 | 2018-05-03 21:53:11 -0700 | [diff] [blame] | 243 | bool GetRtlLocale() const { |
| 244 | return rtl_locale_; |
| 245 | } |
| 246 | |
| 247 | private: |
| 248 | std::vector<KeyCode> key_buffer_; |
| 249 | size_t key_buffer_index_; |
| 250 | }; |
| 251 | |
| 252 | void TestableScreenRecoveryUI::SetKeyBuffer(const std::vector<KeyCode>& buffer) { |
| 253 | key_buffer_ = buffer; |
| 254 | key_buffer_index_ = 0; |
| 255 | } |
| 256 | |
| 257 | int TestableScreenRecoveryUI::KeyHandler(int key, bool) const { |
| 258 | KeyCode key_code = static_cast<KeyCode>(key); |
| 259 | if (kKeyMapping.find(key_code) != kKeyMapping.end()) { |
| 260 | return kKeyMapping.at(key_code); |
| 261 | } |
| 262 | return Device::kNoAction; |
| 263 | } |
| 264 | |
| 265 | int TestableScreenRecoveryUI::WaitKey() { |
| 266 | CHECK_LT(key_buffer_index_, key_buffer_.size()); |
| 267 | return static_cast<int>(key_buffer_[key_buffer_index_++]); |
| 268 | } |
| 269 | |
| 270 | class ScreenRecoveryUITest : public ::testing::Test { |
| 271 | protected: |
| 272 | const std::string kTestLocale = "en-US"; |
| 273 | const std::string kTestRtlLocale = "ar"; |
Tao Bao | 347a659 | 2018-05-08 15:58:29 -0700 | [diff] [blame] | 274 | const std::string kTestRtlLocaleWithSuffix = "ar-EG"; |
Tao Bao | 6cd8168 | 2018-05-03 21:53:11 -0700 | [diff] [blame] | 275 | |
| 276 | void SetUp() override { |
| 277 | ui_ = std::make_unique<TestableScreenRecoveryUI>(); |
| 278 | |
Tao Bao | 152e0eb | 2018-05-13 00:34:45 -0700 | [diff] [blame] | 279 | testdata_dir_ = from_testdata_base(""); |
| 280 | Paths::Get().set_resource_dir(testdata_dir_); |
| 281 | res_set_resource_dir(testdata_dir_); |
Tao Bao | 6cd8168 | 2018-05-03 21:53:11 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | std::unique_ptr<TestableScreenRecoveryUI> ui_; |
Tao Bao | 152e0eb | 2018-05-13 00:34:45 -0700 | [diff] [blame] | 285 | std::string testdata_dir_; |
Tao Bao | 6cd8168 | 2018-05-03 21:53:11 -0700 | [diff] [blame] | 286 | }; |
| 287 | |
| 288 | TEST_F(ScreenRecoveryUITest, Init) { |
Tao Bao | 26ea959 | 2018-05-09 16:32:02 -0700 | [diff] [blame^] | 289 | ASSERT_TRUE(ui_->Init(kTestLocale)); |
Tao Bao | 6cd8168 | 2018-05-03 21:53:11 -0700 | [diff] [blame] | 290 | ASSERT_EQ(kTestLocale, ui_->GetLocale()); |
| 291 | ASSERT_FALSE(ui_->GetRtlLocale()); |
| 292 | ASSERT_FALSE(ui_->IsTextVisible()); |
| 293 | ASSERT_FALSE(ui_->WasTextEverVisible()); |
| 294 | } |
| 295 | |
| 296 | TEST_F(ScreenRecoveryUITest, ShowText) { |
Tao Bao | 26ea959 | 2018-05-09 16:32:02 -0700 | [diff] [blame^] | 297 | ASSERT_TRUE(ui_->Init(kTestLocale)); |
Tao Bao | 6cd8168 | 2018-05-03 21:53:11 -0700 | [diff] [blame] | 298 | ASSERT_FALSE(ui_->IsTextVisible()); |
| 299 | ui_->ShowText(true); |
| 300 | ASSERT_TRUE(ui_->IsTextVisible()); |
| 301 | ASSERT_TRUE(ui_->WasTextEverVisible()); |
| 302 | |
| 303 | ui_->ShowText(false); |
| 304 | ASSERT_FALSE(ui_->IsTextVisible()); |
| 305 | ASSERT_TRUE(ui_->WasTextEverVisible()); |
| 306 | } |
| 307 | |
| 308 | TEST_F(ScreenRecoveryUITest, RtlLocale) { |
| 309 | ASSERT_TRUE(ui_->Init(kTestRtlLocale)); |
| 310 | ASSERT_TRUE(ui_->GetRtlLocale()); |
Tao Bao | 26ea959 | 2018-05-09 16:32:02 -0700 | [diff] [blame^] | 311 | } |
Tao Bao | 6cd8168 | 2018-05-03 21:53:11 -0700 | [diff] [blame] | 312 | |
Tao Bao | 26ea959 | 2018-05-09 16:32:02 -0700 | [diff] [blame^] | 313 | TEST_F(ScreenRecoveryUITest, RtlLocaleWithSuffix) { |
Tao Bao | 6cd8168 | 2018-05-03 21:53:11 -0700 | [diff] [blame] | 314 | ASSERT_TRUE(ui_->Init(kTestRtlLocaleWithSuffix)); |
| 315 | ASSERT_TRUE(ui_->GetRtlLocale()); |
| 316 | } |
| 317 | |
| 318 | TEST_F(ScreenRecoveryUITest, ShowMenu) { |
Tao Bao | 26ea959 | 2018-05-09 16:32:02 -0700 | [diff] [blame^] | 319 | ASSERT_TRUE(ui_->Init(kTestLocale)); |
Tao Bao | 6cd8168 | 2018-05-03 21:53:11 -0700 | [diff] [blame] | 320 | ui_->SetKeyBuffer({ |
| 321 | KeyCode::UP, |
| 322 | KeyCode::DOWN, |
| 323 | KeyCode::UP, |
| 324 | KeyCode::DOWN, |
| 325 | KeyCode::ENTER, |
| 326 | }); |
| 327 | ASSERT_EQ(3u, ui_->ShowMenu(HEADERS, ITEMS, 3, true, |
| 328 | std::bind(&TestableScreenRecoveryUI::KeyHandler, ui_.get(), |
| 329 | std::placeholders::_1, std::placeholders::_2))); |
| 330 | |
| 331 | ui_->SetKeyBuffer({ |
| 332 | KeyCode::UP, |
| 333 | KeyCode::UP, |
| 334 | KeyCode::NO_OP, |
| 335 | KeyCode::NO_OP, |
| 336 | KeyCode::UP, |
| 337 | KeyCode::ENTER, |
| 338 | }); |
| 339 | ASSERT_EQ(2u, ui_->ShowMenu(HEADERS, ITEMS, 0, true, |
| 340 | std::bind(&TestableScreenRecoveryUI::KeyHandler, ui_.get(), |
| 341 | std::placeholders::_1, std::placeholders::_2))); |
| 342 | } |
| 343 | |
| 344 | TEST_F(ScreenRecoveryUITest, ShowMenu_NotMenuOnly) { |
Tao Bao | 26ea959 | 2018-05-09 16:32:02 -0700 | [diff] [blame^] | 345 | ASSERT_TRUE(ui_->Init(kTestLocale)); |
Tao Bao | 6cd8168 | 2018-05-03 21:53:11 -0700 | [diff] [blame] | 346 | ui_->SetKeyBuffer({ |
| 347 | KeyCode::MAGIC, |
| 348 | }); |
| 349 | ASSERT_EQ(static_cast<size_t>(kMagicAction), |
| 350 | ui_->ShowMenu(HEADERS, ITEMS, 3, false, |
| 351 | std::bind(&TestableScreenRecoveryUI::KeyHandler, ui_.get(), |
| 352 | std::placeholders::_1, std::placeholders::_2))); |
| 353 | } |
| 354 | |
| 355 | TEST_F(ScreenRecoveryUITest, ShowMenu_TimedOut) { |
Tao Bao | 26ea959 | 2018-05-09 16:32:02 -0700 | [diff] [blame^] | 356 | ASSERT_TRUE(ui_->Init(kTestLocale)); |
Tao Bao | 6cd8168 | 2018-05-03 21:53:11 -0700 | [diff] [blame] | 357 | ui_->SetKeyBuffer({ |
| 358 | KeyCode::TIMEOUT, |
| 359 | }); |
| 360 | ASSERT_EQ(static_cast<size_t>(-1), ui_->ShowMenu(HEADERS, ITEMS, 3, true, nullptr)); |
| 361 | } |
| 362 | |
| 363 | TEST_F(ScreenRecoveryUITest, ShowMenu_TimedOut_TextWasEverVisible) { |
Tao Bao | 26ea959 | 2018-05-09 16:32:02 -0700 | [diff] [blame^] | 364 | ASSERT_TRUE(ui_->Init(kTestLocale)); |
Tao Bao | 6cd8168 | 2018-05-03 21:53:11 -0700 | [diff] [blame] | 365 | ui_->ShowText(true); |
| 366 | ui_->ShowText(false); |
| 367 | ASSERT_TRUE(ui_->WasTextEverVisible()); |
| 368 | |
| 369 | ui_->SetKeyBuffer({ |
| 370 | KeyCode::TIMEOUT, |
| 371 | KeyCode::DOWN, |
| 372 | KeyCode::ENTER, |
| 373 | }); |
| 374 | ASSERT_EQ(4u, ui_->ShowMenu(HEADERS, ITEMS, 3, true, |
| 375 | std::bind(&TestableScreenRecoveryUI::KeyHandler, ui_.get(), |
| 376 | std::placeholders::_1, std::placeholders::_2))); |
| 377 | } |
Tao Bao | 152e0eb | 2018-05-13 00:34:45 -0700 | [diff] [blame] | 378 | |
| 379 | TEST_F(ScreenRecoveryUITest, LoadAnimation) { |
Tao Bao | 26ea959 | 2018-05-09 16:32:02 -0700 | [diff] [blame^] | 380 | ASSERT_TRUE(ui_->Init(kTestLocale)); |
Tao Bao | 152e0eb | 2018-05-13 00:34:45 -0700 | [diff] [blame] | 381 | // Make a few copies of loop00000.png from testdata. |
| 382 | std::string image_data; |
| 383 | ASSERT_TRUE(android::base::ReadFileToString(testdata_dir_ + "/loop00000.png", &image_data)); |
| 384 | |
| 385 | std::vector<std::string> tempfiles; |
| 386 | TemporaryDir resource_dir; |
| 387 | for (const auto& name : { "00002", "00100", "00050" }) { |
| 388 | tempfiles.push_back(android::base::StringPrintf("%s/loop%s.png", resource_dir.path, name)); |
| 389 | ASSERT_TRUE(android::base::WriteStringToFile(image_data, tempfiles.back())); |
| 390 | } |
| 391 | for (const auto& name : { "00", "01" }) { |
| 392 | tempfiles.push_back(android::base::StringPrintf("%s/intro%s.png", resource_dir.path, name)); |
| 393 | ASSERT_TRUE(android::base::WriteStringToFile(image_data, tempfiles.back())); |
| 394 | } |
| 395 | Paths::Get().set_resource_dir(resource_dir.path); |
| 396 | |
| 397 | ui_->RunLoadAnimation(); |
| 398 | |
| 399 | ASSERT_EQ(2u, ui_->GetIntroFrames()); |
| 400 | ASSERT_EQ(3u, ui_->GetLoopFrames()); |
| 401 | |
| 402 | for (const auto& name : tempfiles) { |
| 403 | ASSERT_EQ(0, unlink(name.c_str())); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | TEST_F(ScreenRecoveryUITest, LoadAnimation_MissingAnimation) { |
Tao Bao | 26ea959 | 2018-05-09 16:32:02 -0700 | [diff] [blame^] | 408 | ASSERT_TRUE(ui_->Init(kTestLocale)); |
Tao Bao | 152e0eb | 2018-05-13 00:34:45 -0700 | [diff] [blame] | 409 | TemporaryDir resource_dir; |
| 410 | Paths::Get().set_resource_dir(resource_dir.path); |
| 411 | ASSERT_EXIT(ui_->RunLoadAnimation(), ::testing::KilledBySignal(SIGABRT), ""); |
| 412 | } |