Debian Codegraph @

autotests/kpasswordlineedittest.cpp

raw symbols SCIP
1 /*
2 SPDX-FileCopyrightText: 2017 Montel Laurent <[email protected]>
3
4 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6
7 #include "kpasswordlineedittest.h"
8 #include "kpasswordlineedit.h"
9 #include <QAction>
10 #include <QHBoxLayout>
11 #include <QLineEdit>
12 #include <QSignalSpy>
13 #include <QTest>
14
15 #include "windowscheck.h"
16
17 PasswordLineEditTest::PasswordLineEditTest(QObject *parent)
18 : QObject(parent)
19 {
20 }
21
22 void PasswordLineEditTest::shouldHaveDefaultValue()
23 {
24 KPasswordLineEdit lineEdit;
25 QVERIFY(lineEdit.password().isEmpty());
26
27 QHBoxLayout *mainLayout = lineEdit.findChild<QHBoxLayout *>(QStringLiteral("mainlayout"));
28 QVERIFY(mainLayout);
29 QCOMPARE(mainLayout->contentsMargins(), QMargins(0, 0, 0, 0));
30
31 QLineEdit *edit = lineEdit.findChild<QLineEdit *>(QStringLiteral("passwordlineedit"));
32 QVERIFY(edit);
33 QVERIFY(edit->text().isEmpty());
34 QCOMPARE(edit->echoMode(), QLineEdit::Password);
35
36 QVERIFY(lineEdit.toggleEchoModeAction());
37 QVERIFY(!lineEdit.toggleEchoModeAction()->isVisible());
38 }
39
40 void PasswordLineEditTest::shouldShowTogglePassword()
41 {
42 if (isWindowsCI()) {
43 QSKIP("GUI Tests on Windows CI are not supported");
44 }
45
46 KPasswordLineEdit lineEdit;
47 lineEdit.show();
48 QVERIFY(QTest::qWaitForWindowExposed(&lineEdit));
49
50 QLineEdit *edit = lineEdit.findChild<QLineEdit *>(QStringLiteral("passwordlineedit"));
51 edit->setText(QStringLiteral("FOO"));
52 QVERIFY(lineEdit.toggleEchoModeAction()->isVisible());
53
54 edit->clear();
55 QVERIFY(!lineEdit.toggleEchoModeAction()->isVisible());
56 }
57
58 void PasswordLineEditTest::shouldNotShowToggleWhenSetPassword()
59 {
60 if (isWindowsCI()) {
61 QSKIP("GUI Tests on Windows CI are not supported");
62 }
63
64 KPasswordLineEdit lineEdit;
65 lineEdit.show();
66 QVERIFY(QTest::qWaitForWindowExposed(&lineEdit));
67 lineEdit.setPassword(QStringLiteral("foo"));
68 QVERIFY(!lineEdit.toggleEchoModeAction()->isVisible());
69 }
70
71 void PasswordLineEditTest::shouldShowRevealPassword()
72 {
73 if (isWindowsCI()) {
74 QSKIP("GUI Tests on Windows CI are not supported");
75 }
76
77 KPasswordLineEdit lineEdit;
78 lineEdit.show();
79 QVERIFY(QTest::qWaitForWindowExposed(&lineEdit));
80
81 QLineEdit *edit = lineEdit.findChild<QLineEdit *>(QStringLiteral("passwordlineedit"));
82 edit->setText(QStringLiteral("FOO"));
83 QVERIFY(lineEdit.toggleEchoModeAction()->isVisible());
84
85 lineEdit.setRevealPasswordMode(KPassword::RevealMode::Never);
86 QVERIFY(!lineEdit.toggleEchoModeAction()->isVisible());
87
88 lineEdit.setRevealPasswordMode(KPassword::RevealMode::Always);
89 QVERIFY(lineEdit.toggleEchoModeAction()->isVisible());
90
91 lineEdit.setRevealPasswordMode(KPassword::RevealMode::OnlyNew);
92 QVERIFY(lineEdit.toggleEchoModeAction()->isVisible());
93
94 lineEdit.setPassword(QStringLiteral("FOO2"));
95 QVERIFY(!lineEdit.toggleEchoModeAction()->isVisible());
96
97 edit->clear();
98 QVERIFY(!lineEdit.toggleEchoModeAction()->isVisible());
99 }
100
101 void PasswordLineEditTest::shouldEmitSignalPasswordChanged()
102 {
103 KPasswordLineEdit lineEdit;
104 lineEdit.show();
105 QSignalSpy spy(&lineEdit, &KPasswordLineEdit::passwordChanged);
106 lineEdit.setPassword(QStringLiteral("foo"));
107 QCOMPARE(spy.count(), 1);
108 }
109
110 void PasswordLineEditTest::testReadOnly()
111 {
112 KPasswordLineEdit lineEdit;
113 lineEdit.show();
114 lineEdit.setReadOnly(true);
115 QSignalSpy spy(&lineEdit, &KPasswordLineEdit::passwordChanged);
116 lineEdit.setPassword(QStringLiteral("foo"));
117 QCOMPARE(spy.count(), 1);
118 QTest::keyClick(&lineEdit, Qt::Key_A);
119 QCOMPARE(spy.count(), 1);
120 QCOMPARE(lineEdit.password(), QStringLiteral("foo"));
121 }
122
123 QTEST_MAIN(PasswordLineEditTest)
124
125 #include "moc_kpasswordlineedittest.cpp"