Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: ash/login/ui/login_password_view_test.cc

Issue 2896533002: cros: Simple password view for lock. Adds test support. (Closed)
Patch Set: Initial upload Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/lock_contents_view.h"
8 #include "ash/login/ui/login_test_base.h"
9 #include "ash/public/cpp/config.h"
10 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h"
xiyuan 2017/05/24 20:11:02 nit: unused?
jdufault 2017/06/07 18:09:13 Done.
12 #include "base/strings/utf_string_conversions.h"
13 #include "ui/aura/window.h"
xiyuan 2017/05/24 20:11:02 nit: unused?
jdufault 2017/06/07 18:09:13 Done.
14 #include "ui/events/test/event_generator.h"
15 #include "ui/views/view.h"
xiyuan 2017/05/24 20:11:02 nit: unused?
jdufault 2017/06/07 18:09:13 Done.
16 #include "ui/views/widget/widget.h"
xiyuan 2017/05/24 20:11:02 nit: unused?
jdufault 2017/06/07 18:09:14 Done.
17
18 namespace ash {
19
20 namespace {
21
22 class LoginPasswordViewTest : public LoginTestBase {
23 public:
24 LoginPasswordViewTest() = default;
25 ~LoginPasswordViewTest() override = default;
26
27 // LoginScreenTest:
28 void SetUp() override {
29 LoginTestBase::SetUp();
30
31 view = new LoginPasswordView(base::Bind(
32 &LoginPasswordViewTest::OnPasswordSubmit, base::Unretained(this)));
33 ShowWidgetWithContent(view);
34 }
35
36 // Called when a password is submitted.
37 void OnPasswordSubmit(const base::string16& password) {
38 this->password = password;
39 }
40
41 LoginPasswordView* view = nullptr;
xiyuan 2017/05/24 20:11:02 Put member vars in protected. And view -> view_, p
jdufault 2017/06/07 18:09:13 Done.
42 base::Optional<base::string16> password;
43
44 private:
45 DISALLOW_COPY_AND_ASSIGN(LoginPasswordViewTest);
46 };
47
48 } // namespace
49
50 // Verifies that password submit works with 'Enter'.
51 TEST_F(LoginPasswordViewTest, PasswordSubmitIncludesPasswordText) {
52 // TODO: Renable in mash once crbug.com/725257 is fixed.
53 if (Shell::GetAshConfig() == Config::MASH)
54 return;
55
56 LoginPasswordView::TestApi test_api(view);
57
58 ui::test::EventGenerator& generator = GetEventGenerator();
59 generator.PressKey(ui::KeyboardCode::VKEY_A, 0);
60 generator.PressKey(ui::KeyboardCode::VKEY_B, 0);
61 generator.PressKey(ui::KeyboardCode::VKEY_C, 0);
62 generator.PressKey(ui::KeyboardCode::VKEY_1, 0);
63 generator.PressKey(ui::KeyboardCode::VKEY_RETURN, 0);
64
65 EXPECT_TRUE(password.has_value());
66 EXPECT_EQ(base::ASCIIToUTF16("abc1"), *password);
67 }
68
69 // Verifies that password submit works when clicking the submit button.
70 TEST_F(LoginPasswordViewTest, PasswordSubmitViaButton) {
71 // TODO: Renable in mash once crbug.com/725257 is fixed.
72 if (Shell::GetAshConfig() == Config::MASH)
73 return;
74
75 LoginPasswordView::TestApi test_api(view);
76
77 ui::test::EventGenerator& generator = GetEventGenerator();
78 generator.PressKey(ui::KeyboardCode::VKEY_A, 0);
79 generator.PressKey(ui::KeyboardCode::VKEY_B, 0);
80 generator.PressKey(ui::KeyboardCode::VKEY_C, 0);
81 generator.PressKey(ui::KeyboardCode::VKEY_1, 0);
82 generator.MoveMouseTo(
83 test_api.submit_button()->GetBoundsInScreen().CenterPoint());
84 generator.ClickLeftButton();
85
86 EXPECT_TRUE(password.has_value());
87 EXPECT_EQ(base::ASCIIToUTF16("abc1"), *password);
88 }
89
90 // Verifies that text is cleared after submitting a password.
91 TEST_F(LoginPasswordViewTest, PasswordSubmitClearsPassword) {
92 // TODO: Renable in mash once crbug.com/725257 is fixed.
93 if (Shell::GetAshConfig() == Config::MASH)
94 return;
95
96 LoginPasswordView::TestApi test_api(view);
97 ui::test::EventGenerator& generator = GetEventGenerator();
98
99 // Submit 'a' password.
100 generator.PressKey(ui::KeyboardCode::VKEY_A, 0);
101 generator.PressKey(ui::KeyboardCode::VKEY_RETURN, 0);
102 EXPECT_TRUE(password.has_value());
103 EXPECT_EQ(base::ASCIIToUTF16("a"), *password);
104
105 password.reset();
106
107 // Submit 'b' password
108 generator.PressKey(ui::KeyboardCode::VKEY_B, 0);
109 generator.PressKey(ui::KeyboardCode::VKEY_RETURN, 0);
110 EXPECT_TRUE(password.has_value());
111 EXPECT_EQ(base::ASCIIToUTF16("b"), *password);
112 }
113 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698