2 * Copyright (C) 2015 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18#include "PromptsModel.h"
22class GreeterPromptsModelTest : public QObject
29 PromptInfo(PromptsModel::PromptType t, const QString &p)
31 PromptsModel::PromptType type;
35 void selectUser(const QString &user)
37 Greeter::instance()->authenticate(user);
38 QCOMPARE(Greeter::instance()->authenticationUser(), user);
41 void respond(const QString &response, bool authenticated)
43 Greeter::instance()->respond(response);
44 QCOMPARE(Greeter::instance()->isAuthenticated(), authenticated);
47 void comparePrompts(const QList<PromptInfo> &expected)
49 QTRY_COMPARE(prompts->rowCount(), expected.size());
50 for (int i = 0; i < prompts->rowCount(); i++) {
51 QCOMPARE(prompts->data(prompts->index(i, 0), PromptsModel::TypeRole).toInt(), (int)expected[i].type);
52 QCOMPARE(prompts->data(prompts->index(i, 0), PromptsModel::TextRole).toString(), expected[i].text);
60 prompts = Greeter::instance()->promptsModel();
66 QCOMPARE(prompts->rowCount(), 0);
74 void testSimpleFailure()
76 selectUser("has-password");
77 comparePrompts({{PromptsModel::Secret, ""}});
78 respond("nope", false);
79 comparePrompts({{PromptsModel::Secret, ""}}); // prompts don't change immediately
80 selectUser("has-password");
81 comparePrompts({{PromptsModel::Error, "Invalid password, please try again"},
82 {PromptsModel::Secret, ""}});
85 void testSimpleSuccess()
87 selectUser("has-password");
88 comparePrompts({{PromptsModel::Secret, ""}});
89 respond("password", true);
90 comparePrompts({{PromptsModel::Secret, ""}}); // prompts don't change
93 void testHasPassword()
95 selectUser("has-password");
96 comparePrompts({{PromptsModel::Secret, ""}});
99 void testDifferentPrompt()
101 selectUser("different-prompt");
102 comparePrompts({{PromptsModel::Secret, "Secret word"}});
105 void testNoPassword()
107 selectUser("no-password");
108 comparePrompts({{PromptsModel::Button, "Log In"}});
113 selectUser("auth-error");
114 comparePrompts({{PromptsModel::Error, "Failed to authenticate"},
115 {PromptsModel::Button, "Retry"}});
120 selectUser("two-factor");
121 comparePrompts({{PromptsModel::Secret, ""}});
122 respond("password", false);
123 comparePrompts({{PromptsModel::Question, "otp"}});
126 void testTwoPrompts()
128 selectUser("two-prompts");
129 comparePrompts({{PromptsModel::Question, "Favorite Color (blue)"},
130 {PromptsModel::Secret, ""}});
133 void testWackyPrompts()
135 selectUser("wacky-prompts");
136 comparePrompts({{PromptsModel::Message, "First message"},
137 {PromptsModel::Question, "Favorite Color (blue)"},
138 {PromptsModel::Error, "Second message"},
139 {PromptsModel::Secret, ""},
140 {PromptsModel::Message, "Last message"}});
143 void testHtmlInfoPrompts()
145 selectUser("html-info-prompt");
146 comparePrompts({{PromptsModel::Message, "<b>&</b>"},
147 {PromptsModel::Secret, ""}});
150 void testInfoAfterLogin()
152 selectUser("info-after-login");
153 comparePrompts({{PromptsModel::Secret, ""}});
154 respond("password", true);
155 comparePrompts({{PromptsModel::Message, "Congratulations on logging in!"},
156 {PromptsModel::Button, "Log In"}});
161 selectUser("locked");
162 comparePrompts({{PromptsModel::Secret, ""}});
163 respond("nope", false);
164 selectUser("locked");
165 comparePrompts({{PromptsModel::Error, "Account is locked"},
166 {PromptsModel::Secret, ""}});
170 PromptsModel *prompts;
173QTEST_GUILESS_MAIN(GreeterPromptsModelTest)
175#include "promptsmodel.moc"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list