OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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. | |
4 | |
5 #include "ash/login/ui/login_password_view.h" | |
6 | |
7 #include "ash/login/ui/login_test_base.h" | |
8 #include "ash/public/cpp/config.h" | |
9 #include "ash/shell.h" | |
10 #include "base/strings/utf_string_conversions.h" | |
11 #include "ui/events/test/event_generator.h" | |
12 | |
13 namespace ash { | |
14 | |
15 namespace { | |
James Cook
2017/06/08 17:26:31
Hooray for everything in anonymous namespace!
jdufault
2017/06/08 23:12:33
Acknowledged.
| |
16 | |
17 class LoginPasswordViewTest : public LoginTestBase { | |
18 protected: | |
19 LoginPasswordViewTest() = default; | |
20 ~LoginPasswordViewTest() override = default; | |
21 | |
22 // LoginScreenTest: | |
23 void SetUp() override { | |
24 LoginTestBase::SetUp(); | |
25 | |
26 view_ = new LoginPasswordView(base::Bind( | |
27 &LoginPasswordViewTest::OnPasswordSubmit, base::Unretained(this))); | |
28 ShowWidgetWithContent(view_); | |
29 } | |
30 | |
31 // Called when a password is submitted. | |
32 void OnPasswordSubmit(const base::string16& password) { | |
33 password_ = password; | |
34 } | |
35 | |
36 LoginPasswordView* view_ = nullptr; | |
37 base::Optional<base::string16> password_; | |
38 | |
39 private: | |
40 DISALLOW_COPY_AND_ASSIGN(LoginPasswordViewTest); | |
41 }; | |
42 | |
43 } // namespace | |
44 | |
45 // Verifies that password submit works with 'Enter'. | |
46 TEST_F(LoginPasswordViewTest, PasswordSubmitIncludesPasswordText) { | |
47 // TODO: Renable in mash once crbug.com/725257 is fixed. | |
48 if (Shell::GetAshConfig() == Config::MASH) | |
49 return; | |
50 | |
51 LoginPasswordView::TestApi test_api(view_); | |
52 | |
53 ui::test::EventGenerator& generator = GetEventGenerator(); | |
54 generator.PressKey(ui::KeyboardCode::VKEY_A, 0); | |
55 generator.PressKey(ui::KeyboardCode::VKEY_B, 0); | |
56 generator.PressKey(ui::KeyboardCode::VKEY_C, 0); | |
57 generator.PressKey(ui::KeyboardCode::VKEY_1, 0); | |
58 generator.PressKey(ui::KeyboardCode::VKEY_RETURN, 0); | |
59 | |
60 EXPECT_TRUE(password_.has_value()); | |
61 EXPECT_EQ(base::ASCIIToUTF16("abc1"), *password_); | |
62 } | |
63 | |
64 // Verifies that password submit works when clicking the submit button. | |
65 TEST_F(LoginPasswordViewTest, PasswordSubmitViaButton) { | |
66 // TODO: Renable in mash once crbug.com/725257 is fixed. | |
67 if (Shell::GetAshConfig() == Config::MASH) | |
68 return; | |
69 | |
70 LoginPasswordView::TestApi test_api(view_); | |
71 | |
72 ui::test::EventGenerator& generator = GetEventGenerator(); | |
73 generator.PressKey(ui::KeyboardCode::VKEY_A, 0); | |
74 generator.PressKey(ui::KeyboardCode::VKEY_B, 0); | |
75 generator.PressKey(ui::KeyboardCode::VKEY_C, 0); | |
76 generator.PressKey(ui::KeyboardCode::VKEY_1, 0); | |
77 generator.MoveMouseTo( | |
78 test_api.submit_button()->GetBoundsInScreen().CenterPoint()); | |
79 generator.ClickLeftButton(); | |
80 | |
81 EXPECT_TRUE(password_.has_value()); | |
82 EXPECT_EQ(base::ASCIIToUTF16("abc1"), *password_); | |
83 } | |
84 | |
85 // Verifies that text is cleared after submitting a password. | |
86 TEST_F(LoginPasswordViewTest, PasswordSubmitClearsPassword) { | |
87 // TODO: Renable in mash once crbug.com/725257 is fixed. | |
88 if (Shell::GetAshConfig() == Config::MASH) | |
89 return; | |
90 | |
91 LoginPasswordView::TestApi test_api(view_); | |
92 ui::test::EventGenerator& generator = GetEventGenerator(); | |
93 | |
94 // Submit 'a' password. | |
95 generator.PressKey(ui::KeyboardCode::VKEY_A, 0); | |
96 generator.PressKey(ui::KeyboardCode::VKEY_RETURN, 0); | |
97 EXPECT_TRUE(password_.has_value()); | |
98 EXPECT_EQ(base::ASCIIToUTF16("a"), *password_); | |
99 | |
100 password_.reset(); | |
101 | |
102 // Submit 'b' password | |
103 generator.PressKey(ui::KeyboardCode::VKEY_B, 0); | |
104 generator.PressKey(ui::KeyboardCode::VKEY_RETURN, 0); | |
105 EXPECT_TRUE(password_.has_value()); | |
106 EXPECT_EQ(base::ASCIIToUTF16("b"), *password_); | |
107 } | |
108 } // namespace ash | |
James Cook
2017/06/08 17:26:31
nit: blank line above
Also, nice tests!
jdufault
2017/06/08 23:12:33
Done.
| |
OLD | NEW |