Changeset View
Changeset View
Standalone View
Standalone View
autotests/kurlcomboboxtest.cpp
Show All 39 Lines | 38 | { | |||
---|---|---|---|---|---|
40 | QFETCH(QString, expectedText); | 40 | QFETCH(QString, expectedText); | ||
41 | 41 | | |||
42 | KUrlComboBox combo(KUrlComboBox::Directories); | 42 | KUrlComboBox combo(KUrlComboBox::Directories); | ||
43 | combo.setUrl(QUrl(url)); | 43 | combo.setUrl(QUrl(url)); | ||
44 | 44 | | |||
45 | QCOMPARE(combo.itemText(0), expectedText); | 45 | QCOMPARE(combo.itemText(0), expectedText); | ||
46 | 46 | | |||
47 | } | 47 | } | ||
48 | | ||||
49 | void KUrlComboBoxTest::testSetUrlMultipleTimes() | ||||
50 | { | ||||
51 | KUrlComboBox combo(KUrlComboBox::Directories); | ||||
52 | combo.setUrl(QUrl("http://kde.org")); | ||||
53 | combo.setUrl(QUrl("http://www.kde.org")); | ||||
54 | } | ||||
55 | | ||||
56 | void KUrlComboBoxTest::testRemoveUrl() | ||||
57 | { | ||||
58 | KUrlComboBox combo(KUrlComboBox::Both); | ||||
59 | combo.addDefaultUrl(QUrl("http://kde.org")); | ||||
60 | combo.addDefaultUrl(QUrl("http://www.kde.org")); | ||||
61 | | ||||
62 | QStringList urls{"http://foo.org", "http://bar.org"}; | ||||
63 | combo.setUrls(urls); | ||||
64 | | ||||
65 | QCOMPARE(combo.urls(), urls); | ||||
66 | QCOMPARE(combo.count(), 4); | ||||
67 | QCOMPARE(combo.itemText(0), "http://kde.org"); | ||||
68 | QCOMPARE(combo.itemText(1), "http://www.kde.org"); | ||||
69 | QCOMPARE(combo.itemText(2), "http://foo.org"); | ||||
70 | QCOMPARE(combo.itemText(3), "http://bar.org"); | ||||
71 | | ||||
72 | // Remove a url | ||||
73 | combo.removeUrl(QUrl("http://foo.org")); | ||||
74 | QCOMPARE(combo.count(), 3); | ||||
75 | QCOMPARE(combo.urls(), QStringList{"http://bar.org"}); | ||||
76 | QCOMPARE(combo.itemText(0), "http://kde.org"); | ||||
77 | QCOMPARE(combo.itemText(1), "http://www.kde.org"); | ||||
78 | QCOMPARE(combo.itemText(2), "http://bar.org"); | ||||
79 | | ||||
80 | // Removing a default url with checkDefaultURLs=true removes the url | ||||
81 | combo.removeUrl(QUrl("http://kde.org")); | ||||
82 | QCOMPARE(combo.count(), 2); | ||||
83 | QCOMPARE(combo.urls(), QStringList{"http://bar.org"}); | ||||
84 | QCOMPARE(combo.itemText(0), "http://www.kde.org"); | ||||
85 | QCOMPARE(combo.itemText(1), "http://bar.org"); | ||||
86 | | ||||
87 | // Removing a default url with checkDefaultURLs=false does not remove the url | ||||
88 | combo.removeUrl(QUrl("http://www.kde.org"), false); | ||||
89 | QCOMPARE(combo.count(), 2); | ||||
90 | QCOMPARE(combo.urls(), QStringList{"http://bar.org"}); | ||||
91 | QCOMPARE(combo.itemText(0), "http://www.kde.org"); | ||||
92 | QCOMPARE(combo.itemText(1), "http://bar.org"); | ||||
93 | | ||||
94 | // Removing a non-existing url is a no-op | ||||
95 | combo.removeUrl(QUrl("http://www.foo.org")); | ||||
96 | QCOMPARE(combo.count(), 2); | ||||
97 | QCOMPARE(combo.urls(), QStringList{"http://bar.org"}); | ||||
98 | QCOMPARE(combo.itemText(0), "http://www.kde.org"); | ||||
99 | QCOMPARE(combo.itemText(1), "http://bar.org"); | ||||
100 | | ||||
101 | // Remove the last user provided url | ||||
102 | combo.removeUrl(QUrl("http://bar.org")); | ||||
103 | QCOMPARE(combo.count(), 1); | ||||
104 | QCOMPARE(combo.urls(), QStringList{}); | ||||
105 | QCOMPARE(combo.itemText(0), "http://www.kde.org"); | ||||
106 | | ||||
107 | // Remove the last url | ||||
108 | combo.removeUrl(QUrl("http://www.kde.org")); | ||||
109 | QCOMPARE(combo.count(), 0); | ||||
110 | QCOMPARE(combo.urls(), QStringList{}); | ||||
111 | QCOMPARE(combo.itemText(0), ""); | ||||
112 | } |