OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <utility> |
5 #include <vector> | 6 #include <vector> |
6 | 7 |
7 #include "ash/common/session/session_controller.h" | 8 #include "ash/common/session/session_controller.h" |
8 #include "ash/common/shell_delegate.h" | 9 #include "ash/common/shell_delegate.h" |
9 #include "ash/common/system/tray/system_tray.h" | 10 #include "ash/common/system/tray/system_tray.h" |
10 #include "ash/common/system/tray/tray_constants.h" | 11 #include "ash/common/system/tray/tray_constants.h" |
| 12 #include "ash/common/system/user/rounded_image_view.h" |
11 #include "ash/common/system/user/tray_user.h" | 13 #include "ash/common/system/user/tray_user.h" |
12 #include "ash/common/system/user/user_view.h" | 14 #include "ash/common/system/user/user_view.h" |
13 #include "ash/common/test/test_session_controller_client.h" | 15 #include "ash/common/test/test_session_controller_client.h" |
14 #include "ash/common/wm_shell.h" | 16 #include "ash/common/wm_shell.h" |
15 #include "ash/shell.h" | 17 #include "ash/shell.h" |
16 #include "ash/test/ash_test_base.h" | 18 #include "ash/test/ash_test_base.h" |
17 #include "ash/test/test_shell_delegate.h" | 19 #include "ash/test/test_shell_delegate.h" |
18 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
19 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
20 #include "components/signin/core/account_id/account_id.h" | 22 #include "components/signin/core/account_id/account_id.h" |
| 23 #include "third_party/skia/include/core/SkBitmap.h" |
| 24 #include "third_party/skia/include/core/SkColor.h" |
21 #include "ui/accessibility/ax_node_data.h" | 25 #include "ui/accessibility/ax_node_data.h" |
22 #include "ui/events/test/event_generator.h" | 26 #include "ui/events/test/event_generator.h" |
23 #include "ui/gfx/animation/animation_container_element.h" | 27 #include "ui/gfx/animation/animation_container_element.h" |
| 28 #include "ui/gfx/image/image_skia.h" |
| 29 #include "ui/gfx/image/image_unittest_util.h" |
24 #include "ui/views/view.h" | 30 #include "ui/views/view.h" |
25 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
26 | 32 |
27 namespace ash { | 33 namespace ash { |
28 | 34 |
29 namespace { | 35 namespace { |
30 | 36 |
31 const char* kPredefinedUserEmails[] = { | 37 const char* kPredefinedUserEmails[] = { |
32 // This is intended to be capitalized. | 38 // This is intended to be capitalized. |
33 "First@tray", | 39 "First@tray", |
34 // This is intended to be capitalized. | 40 // This is intended to be capitalized. |
35 "Second@tray"}; | 41 "Second@tray"}; |
36 | 42 |
| 43 // Creates an ImageSkia with a 1x rep of the given dimensions and filled with |
| 44 // the given color. |
| 45 gfx::ImageSkia CreateImageSkiaWithColor(int width, int height, SkColor color) { |
| 46 SkBitmap bitmap = gfx::test::CreateBitmap(width, height); |
| 47 bitmap.eraseColor(color); |
| 48 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 49 } |
| 50 |
37 class TrayUserTest : public test::AshTestBase { | 51 class TrayUserTest : public test::AshTestBase { |
38 public: | 52 public: |
39 TrayUserTest() = default; | 53 TrayUserTest() = default; |
40 | 54 |
41 // testing::Test: | 55 // testing::Test: |
42 void SetUp() override; | 56 void SetUp() override; |
43 | 57 |
44 // This has to be called prior to first use with the proper configuration. | 58 // This has to be called prior to first use with the proper configuration. |
45 void InitializeParameters(int users_logged_in, bool multiprofile); | 59 void InitializeParameters(int users_logged_in, bool multiprofile); |
46 | 60 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 RunAllPendingInMessageLoop(); | 274 RunAllPendingInMessageLoop(); |
261 | 275 |
262 const mojom::UserSession* active_user = controller()->GetUserSession(0); | 276 const mojom::UserSession* active_user = controller()->GetUserSession(0); |
263 EXPECT_EQ(active_user->account_id, second_user->account_id); | 277 EXPECT_EQ(active_user->account_id, second_user->account_id); |
264 // Since the name is capitalized, the email should be different than the | 278 // Since the name is capitalized, the email should be different than the |
265 // user_id. | 279 // user_id. |
266 EXPECT_NE(active_user->account_id.GetUserEmail(), second_user->display_email); | 280 EXPECT_NE(active_user->account_id.GetUserEmail(), second_user->display_email); |
267 tray()->CloseSystemBubble(); | 281 tray()->CloseSystemBubble(); |
268 } | 282 } |
269 | 283 |
| 284 // Test SessionController updates avatar image. |
| 285 TEST_F(TrayUserTest, AvatarChange) { |
| 286 InitializeParameters(1, false); |
| 287 |
| 288 // Expect empty avatar initially (that is how the test sets up). |
| 289 EXPECT_TRUE(tray_user(0)->avatar_view_for_test()->image_for_test().isNull()); |
| 290 |
| 291 // Change user avatar via SessionController and verify. |
| 292 const gfx::ImageSkia red_icon = |
| 293 CreateImageSkiaWithColor(kTrayItemSize, kTrayItemSize, SK_ColorRED); |
| 294 mojom::UserSessionPtr user = controller()->GetUserSession(0)->Clone(); |
| 295 user->avatar = red_icon; |
| 296 controller()->UpdateUserSession(std::move(user)); |
| 297 EXPECT_TRUE(gfx::test::AreImagesEqual( |
| 298 gfx::Image(red_icon), |
| 299 gfx::Image(tray_user(0)->avatar_view_for_test()->image_for_test()))); |
| 300 } |
| 301 |
270 } // namespace ash | 302 } // namespace ash |
OLD | NEW |