]>
cloud.milkyroute.net Git - dolphin.git/blob - src/tests/dolphinviewtest_allviewmodes.cpp
cac4c710249ae2a677f0be506c0a553d80a36070
1 /****************************************************************************
2 * Copyright (C) 2010-2011 by Frank Reininghaus (frank78ac@googlemail.com) *
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; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 *****************************************************************************/
22 #include "dolphinviewtest_allviewmodes.h"
24 #include <qtest_kde.h>
28 #include "views/dolphinview.h"
29 #include "views/dolphinmodel.h"
30 #include "views/dolphindirlister.h"
31 #include "views/dolphinsortfilterproxymodel.h"
32 #include "views/zoomlevelinfo.h"
36 #include <qtestmouse.h>
37 #include <qtestkeyboard.h>
39 DolphinViewTest_AllViewModes::DolphinViewTest_AllViewModes() {
40 // Need to register KFileItemList for use with QSignalSpy
41 qRegisterMetaType
<KFileItemList
>("KFileItemList");
45 * testSelection() checks the basic selection functionality of DolphinView, including:
48 * selectedItemsCount()
54 * and the signal selectionChanged(const KFileItemList& selection)
57 Q_DECLARE_METATYPE(KFileItemList
)
59 void DolphinViewTest_AllViewModes::testSelection() {
61 const int totalItems
= 50;
62 for (int i
= 0; i
< totalItems
; i
++) {
63 dir
.createFile(QString("%1").arg(i
));
66 DolphinView
view(dir
.url(), 0);
67 QAbstractItemView
* itemView
= initView(&view
);
69 // Start with an empty selection
70 view
.clearSelection();
72 QCOMPARE(view
.selectedItems().count(), 0);
73 QCOMPARE(view
.selectedItemsCount(), 0);
74 QVERIFY(!view
.hasSelection());
76 // First some simple tests where either all or no items are selected
78 verifySelectedItemsCount(&view
, totalItems
);
80 view
.invertSelection();
81 verifySelectedItemsCount(&view
, 0);
83 view
.invertSelection();
84 verifySelectedItemsCount(&view
, totalItems
);
86 view
.clearSelection();
87 verifySelectedItemsCount(&view
, 0);
89 // Now we select individual items using mouse clicks
90 QModelIndex index
= itemView
->model()->index(2, 0);
91 itemView
->scrollTo(index
);
92 QTest::mouseClick(itemView
->viewport(), Qt::LeftButton
, Qt::ControlModifier
, itemView
->visualRect(index
).center());
93 verifySelectedItemsCount(&view
, 1);
95 index
= itemView
->model()->index(totalItems
- 5, 0);
96 itemView
->scrollTo(index
);
97 QTest::mouseClick(itemView
->viewport(), Qt::LeftButton
, Qt::ControlModifier
, itemView
->visualRect(index
).center());
98 verifySelectedItemsCount(&view
, 2);
100 index
= itemView
->model()->index(totalItems
- 2, 0);
101 itemView
->scrollTo(index
);
102 QTest::mouseClick(itemView
->viewport(), Qt::LeftButton
, Qt::ShiftModifier
, itemView
->visualRect(index
).center());
103 verifySelectedItemsCount(&view
, 5);
105 view
.invertSelection();
106 verifySelectedItemsCount(&view
, totalItems
- 5);
108 // Pressing Esc should clear the selection
109 QTest::keyClick(itemView
->viewport(), Qt::Key_Escape
);
110 verifySelectedItemsCount(&view
, 0);
114 * Check that setting the directory view properties works.
117 void DolphinViewTest_AllViewModes::testViewPropertySettings()
119 // Create some files with different sizes and modification times to check the different sorting options
120 QDateTime now
= QDateTime::currentDateTime();
123 dir
.createFile("a", "A file", now
.addDays(-3));
124 dir
.createFile("b", "A larger file", now
.addDays(0));
125 dir
.createDir("c", now
.addDays(-2));
126 dir
.createFile("d", "The largest file in this directory", now
.addDays(-1));
127 dir
.createFile("e", "An even larger file", now
.addDays(-4));
128 dir
.createFile(".f");
130 DolphinView
view(dir
.url(), 0);
133 // First set all settings to the default.
134 view
.setSorting(DolphinView::SortByName
);
135 QCOMPARE(view
.sorting(), DolphinView::SortByName
);
137 view
.setSortOrder(Qt::AscendingOrder
);
138 QCOMPARE(view
.sortOrder(), Qt::AscendingOrder
);
140 view
.setSortFoldersFirst(true);
141 QVERIFY(view
.sortFoldersFirst());
143 view
.setShowPreview(false);
144 QVERIFY(!view
.showPreview());
146 if (view
.showHiddenFiles()) {
147 // Changing the "hidden files" setting triggers the dir lister
148 // -> we have to wait until loading the hidden files is finished
149 view
.setShowHiddenFiles(false);
150 waitForFinishedPathLoading(&view
);
152 QVERIFY(!view
.showHiddenFiles());
154 /** Check that the sort order is correct for different kinds of settings */
156 // Sort by Name, ascending
157 QCOMPARE(view
.sorting(), DolphinView::SortByName
);
158 QCOMPARE(view
.sortOrder(), Qt::AscendingOrder
);
159 QCOMPARE(viewItems(&view
), QStringList() << "c" << "a" << "b" << "d" << "e");
161 // Sort by Name, descending
162 view
.setSortOrder(Qt::DescendingOrder
);
163 QCOMPARE(view
.sorting(), DolphinView::SortByName
);
164 QCOMPARE(view
.sortOrder(), Qt::DescendingOrder
);
165 QCOMPARE(viewItems(&view
), QStringList() << "c" << "e" << "d" << "b" << "a");
167 // Sort by Size, descending
168 view
.setSorting(DolphinView::SortBySize
);
169 QCOMPARE(view
.sorting(), DolphinView::SortBySize
);
170 QCOMPARE(view
.sortOrder(), Qt::DescendingOrder
);
171 QCOMPARE(viewItems(&view
), QStringList() << "c" << "d" << "e" << "b" << "a");
173 // Sort by Size, ascending
174 view
.setSortOrder(Qt::AscendingOrder
);
175 QCOMPARE(view
.sorting(), DolphinView::SortBySize
);
176 QCOMPARE(view
.sortOrder(), Qt::AscendingOrder
);
177 QCOMPARE(viewItems(&view
), QStringList() << "c" << "a" << "b" << "e" << "d");
179 // Sort by Date, ascending
180 view
.setSorting(DolphinView::SortByDate
);
181 QCOMPARE(view
.sorting(), DolphinView::SortByDate
);
182 QCOMPARE(view
.sortOrder(), Qt::AscendingOrder
);
183 QCOMPARE(viewItems(&view
), QStringList() << "c" << "e" << "a" << "d" << "b");
185 // Sort by Date, descending
186 view
.setSortOrder(Qt::DescendingOrder
);
187 QCOMPARE(view
.sorting(), DolphinView::SortByDate
);
188 QCOMPARE(view
.sortOrder(), Qt::DescendingOrder
);
189 QCOMPARE(viewItems(&view
), QStringList() << "c" << "b" << "d" << "a" << "e");
191 // Disable "Sort Folders First"
192 view
.setSortFoldersFirst(false);
193 QVERIFY(!view
.sortFoldersFirst());
194 QCOMPARE(viewItems(&view
), QStringList()<< "b" << "d" << "c" << "a" << "e");
196 // Try again with Sort by Name, ascending
197 view
.setSorting(DolphinView::SortByName
);
198 view
.setSortOrder(Qt::AscendingOrder
);
199 QCOMPARE(view
.sorting(), DolphinView::SortByName
);
200 QCOMPARE(view
.sortOrder(), Qt::AscendingOrder
);
201 QCOMPARE(viewItems(&view
), QStringList() << "a" << "b" << "c" << "d" << "e");
203 // Show hidden files. This triggers the dir lister
204 // -> we have to wait until loading the hidden files is finished
205 view
.setShowHiddenFiles(true);
206 waitForFinishedPathLoading(&view
);
207 QVERIFY(view
.showHiddenFiles());
209 // Depending on the settings, a .directory file might have been created.
210 // Remove it from the list to get consistent results.
211 QStringList result
= viewItems(&view
);
212 result
.removeAll(".directory");
213 QCOMPARE(result
, QStringList() << ".f" << "a" << "b" << "c" << "d" << "e");
216 view
.setShowPreview(true);
217 QVERIFY(view
.showPreview());
219 // TODO: Check that the view properties are restored correctly when changing the folder and then going back.
223 * testZoomLevel() checks that setting the zoom level works, both using DolphinView's API and using Ctrl+mouse wheel.
226 void DolphinViewTest_AllViewModes::testZoomLevel()
229 dir
.createFiles(QStringList() << "a" << "b");
230 DolphinView
view(dir
.url(), 0);
231 QAbstractItemView
* itemView
= initView(&view
);
233 view
.setShowPreview(false);
234 QVERIFY(!view
.showPreview());
236 int zoomLevelBackup
= view
.zoomLevel();
238 int zoomLevel
= ZoomLevelInfo::minimumLevel();
239 view
.setZoomLevel(zoomLevel
);
240 QCOMPARE(view
.zoomLevel(), zoomLevel
);
242 // Increase the zoom level successively to the maximum.
243 while(zoomLevel
< ZoomLevelInfo::maximumLevel()) {
245 view
.setZoomLevel(zoomLevel
);
246 QCOMPARE(view
.zoomLevel(), zoomLevel
);
249 // Try setting a zoom level larger than the maximum
250 view
.setZoomLevel(ZoomLevelInfo::maximumLevel() + 1);
251 QCOMPARE(view
.zoomLevel(), ZoomLevelInfo::maximumLevel());
253 // Turn previews on and try setting a zoom level smaller than the minimum
254 view
.setShowPreview(true);
255 QVERIFY(view
.showPreview());
256 view
.setZoomLevel(ZoomLevelInfo::minimumLevel() - 1);
257 QCOMPARE(view
.zoomLevel(), ZoomLevelInfo::minimumLevel());
259 // Turn previews off again and check that the zoom level is restored
260 view
.setShowPreview(false);
261 QVERIFY(!view
.showPreview());
262 QCOMPARE(view
.zoomLevel(), ZoomLevelInfo::maximumLevel());
264 // Change the zoom level using Ctrl+mouse wheel
265 QModelIndex index
= itemView
->model()->index(0, 0);
266 itemView
->scrollTo(index
);
268 while (view
.zoomLevel() > ZoomLevelInfo::minimumLevel()) {
269 int oldZoomLevel
= view
.zoomLevel();
270 QWheelEvent
wheelEvent(itemView
->visualRect(index
).center(), -1, Qt::NoButton
, Qt::ControlModifier
);
271 bool wheelEventReceived
= qApp
->notify(itemView
->viewport(), &wheelEvent
);
272 QVERIFY(wheelEventReceived
);
273 QVERIFY(view
.zoomLevel() < oldZoomLevel
);
275 QCOMPARE(view
.zoomLevel(), ZoomLevelInfo::minimumLevel());
277 while (view
.zoomLevel() < ZoomLevelInfo::maximumLevel()) {
278 int oldZoomLevel
= view
.zoomLevel();
279 QWheelEvent
wheelEvent(itemView
->visualRect(index
).center(), 1, Qt::NoButton
, Qt::ControlModifier
);
280 bool wheelEventReceived
= qApp
->notify(itemView
->viewport(), &wheelEvent
);
281 QVERIFY(wheelEventReceived
);
282 QVERIFY(view
.zoomLevel() > oldZoomLevel
);
284 QCOMPARE(view
.zoomLevel(), ZoomLevelInfo::maximumLevel());
286 // Turn previews on again and check that the zoom level is restored
287 view
.setShowPreview(true);
288 QVERIFY(view
.showPreview());
289 QCOMPARE(view
.zoomLevel(), ZoomLevelInfo::minimumLevel());
291 // Restore the initial state
292 view
.setZoomLevel(zoomLevelBackup
);
293 view
.setShowPreview(false);
294 view
.setZoomLevel(zoomLevelBackup
);
298 * testSaveAndRestoreState() checks if saving and restoring the view state (current item, scroll position).
300 * Note that we call qApp->sendPostedEvents() every time the view's finishedPathLoading(const KUrl&) signal
301 * is received. The reason is that the scroll position is restored in the slot restoreContentsPosition(),
302 * which is been invoked using a queued connection in DolphinView::slotLoadingCompleted(). To make sure
303 * that this slot is really executed before we proceed, we have to empty the event queue using qApp->sendPostedEvents().
306 void DolphinViewTest_AllViewModes::testSaveAndRestoreState()
308 const int totalItems
= 50;
310 for (int i
= 0; i
< totalItems
; i
++) {
311 dir
.createFile(QString("%1").arg(i
));
314 DolphinView
view(dir
.url(), 0);
317 // Set sorting settings to the default to make sure that the item positions are reproducible.
318 view
.setSorting(DolphinView::SortByName
);
319 QCOMPARE(view
.sorting(), DolphinView::SortByName
);
320 view
.setSortOrder(Qt::AscendingOrder
);
321 QCOMPARE(view
.sortOrder(), Qt::AscendingOrder
);
323 // Make sure that previews are off and that the icon size does not depend on the preview setting.
324 // This is needed for the test for bug 270437, see below.
325 view
.setShowPreview(false);
326 int zoomLevel
= view
.zoomLevel();
327 view
.setShowPreview(true);
328 view
.setZoomLevel(zoomLevel
);
329 view
.setShowPreview(false);
332 const QModelIndex index45
= itemView(&view
)->model()->index(45, 0);
333 itemView(&view
)->scrollTo(index45
);
334 itemView(&view
)->setCurrentIndex(index45
);
335 const int scrollPosX
= itemView(&view
)->horizontalScrollBar()->value();
336 const int scrollPosY
= itemView(&view
)->verticalScrollBar()->value();
338 // Save the view state
339 QByteArray viewState
;
340 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
341 view
.saveState(saveStream
);
344 view
.setUrl(KUrl(dir
.name() + "51"));
345 waitForFinishedPathLoading(&view
);
346 qApp
->sendPostedEvents();
348 // Go back, but do not call DolphinView::restoreState()
349 view
.setUrl(dir
.url());
350 waitForFinishedPathLoading(&view
);
351 qApp
->sendPostedEvents();
353 // Verify that the view is scrolled to top-left corner and that item 45 is not the current item.
354 // Note that the vertical position of the columns view might not be zero -> skip that part
355 // of the check in this case.
356 QVERIFY(itemView(&view
)->currentIndex() != index45
);
357 QCOMPARE(itemView(&view
)->horizontalScrollBar()->value(), 0);
358 if (mode() != DolphinView::ColumnView
) {
359 QCOMPARE(itemView(&view
)->verticalScrollBar()->value(), 0);
362 // Change the URL again
363 view
.setUrl(KUrl(dir
.name() + "51"));
364 waitForFinishedPathLoading(&view
);
365 qApp
->sendPostedEvents();
367 // Check that the current item and scroll position are correct if DolphinView::restoreState()
368 // is called after the URL change
369 view
.setUrl(dir
.url());
370 QDataStream
restoreStream(viewState
);
371 view
.restoreState(restoreStream
);
372 waitForFinishedPathLoading(&view
);
373 qApp
->sendPostedEvents();
375 QCOMPARE(itemView(&view
)->currentIndex(), index45
);
376 QCOMPARE(itemView(&view
)->horizontalScrollBar()->value(), scrollPosX
);
377 QCOMPARE(itemView(&view
)->verticalScrollBar()->value(), scrollPosY
);
380 * Additionally, we verify the fix for the bug https://bugs.kde.org/show_bug.cgi?id=270437
381 * Actually, it's a bug in KFilePreviewGenerator, but it is easier to test it here.
385 view
.setShowPreview(true);
386 QVERIFY(view
.showPreview());
388 // We have to process all events in the queue to make sure that previews are really on.
389 qApp
->sendPostedEvents();
391 // Current item and scroll position should not change.
392 QCOMPARE(itemView(&view
)->currentIndex(), index45
);
393 QCOMPARE(itemView(&view
)->horizontalScrollBar()->value(), scrollPosX
);
394 QCOMPARE(itemView(&view
)->verticalScrollBar()->value(), scrollPosY
);
396 // Turn previews off again. Before bug 270437, this triggered the dir lister's openUrl() method
397 // -> we check that by listening to the view's startedPathLoading() signal and wait until the loading is finished in that case.
398 QSignalSpy
spy(&view
, SIGNAL(startedPathLoading(const KUrl
&)));
399 view
.setShowPreview(false);
400 QVERIFY(!view
.showPreview());
401 qApp
->sendPostedEvents();
402 if (!spy
.isEmpty()) {
403 // The dir lister reloads the directory. We wait until the loading is finished.
404 waitForFinishedPathLoading(&view
);
407 // Current item and scroll position should not change.
408 QCOMPARE(itemView(&view
)->currentIndex(), index45
);
409 QCOMPARE(itemView(&view
)->horizontalScrollBar()->value(), scrollPosX
);
410 QCOMPARE(itemView(&view
)->verticalScrollBar()->value(), scrollPosY
);
414 * testKeyboardFocus() checks whether a view grabs the keyboard focus.
416 * A view may never grab the keyboard focus itself and must respect the focus-state
417 * when switching the view mode, see
419 * https://bugs.kde.org/show_bug.cgi?id=261147
422 void DolphinViewTest_AllViewModes::testKeyboardFocus()
425 dir
.createFiles(QStringList() << "a" << "b");
426 DolphinView
view(dir
.url(), 0);
429 // Move the keyboard focus to another widget.
432 QTest::qWaitForWindowShown(&widget
);
435 QVERIFY(!view
.hasFocus());
437 // Switch view modes and verify that the view does not get the focus back
438 for (int i
= 0; i
<= DolphinView::MaxModeEnum
; ++i
) {
439 view
.setMode(static_cast<DolphinView::Mode
>(i
));
440 QVERIFY(!view
.hasFocus());
445 * testCutCopyPaste() checks if cutting or copying items in one view and pasting
446 * them in another one works.
449 void DolphinViewTest_AllViewModes::testCutCopyPaste()
452 dir1
.createFiles(QStringList() << "a" << "b" << "c" << "d");
453 DolphinView
view1(dir1
.url(), 0);
454 QAbstractItemView
* itemView1
= initView(&view1
);
457 dir2
.createFiles(QStringList() << "1" << "2" << "3" << "4");
458 dir2
.createDir("subfolder");
459 DolphinView
view2(dir2
.url(), 0);
460 QAbstractItemView
* itemView2
= initView(&view2
);
462 // Make sure that both views are sorted by name in ascending order
463 // TODO: Maybe that should be done in initView(), such all tests can rely on it...?
464 view1
.setSorting(DolphinView::SortByName
);
465 view1
.setSortOrder(Qt::AscendingOrder
);
466 view2
.setSorting(DolphinView::SortByName
);
467 view2
.setSortOrder(Qt::AscendingOrder
);
468 view2
.setSortFoldersFirst(true);
470 QCOMPARE(viewItems(&view1
), QStringList() << "a" << "b" << "c" << "d");
471 QCOMPARE(viewItems(&view2
), QStringList() << "subfolder" << "1" << "2" << "3" << "4");
473 /** Copy and paste */
474 // Select an item ("d") n view1, copy it and paste it in view2.
475 // Note that we have to wait for view2's finishedPathLoading() signal because the pasting is done in the background.
476 QModelIndex index
= itemView1
->model()->index(3, 0);
477 itemView1
->scrollTo(index
);
478 QTest::mouseClick(itemView1
->viewport(), Qt::LeftButton
, Qt::ControlModifier
, itemView1
->visualRect(index
).center());
479 verifySelectedItemsCount(&view1
, 1);
480 QCOMPARE(selectedItems(&view1
), QStringList() << "d");
481 view1
.copySelectedItems();
483 waitForFinishedPathLoading(&view2
);
484 QCOMPARE(viewItems(&view1
), QStringList() << "a" << "b" << "c" << "d");
485 QCOMPARE(viewItems(&view2
), QStringList() << "subfolder" << "1" << "2" << "3" << "4" << "d");
486 // The pasted item should be selected
487 QCOMPARE(selectedItems(&view2
), QStringList() << "d");
490 // Select two items ("3", "4") in view2, cut and paste in view1.
491 view2
.clearSelection();
492 index
= itemView2
->model()->index(3, 0);
493 itemView2
->scrollTo(index
);
494 QTest::mouseClick(itemView2
->viewport(), Qt::LeftButton
, Qt::ControlModifier
, itemView2
->visualRect(index
).center());
495 verifySelectedItemsCount(&view2
, 1);
496 index
= itemView2
->model()->index(4, 0);
497 itemView2
->scrollTo(index
);
498 QTest::mouseClick(itemView2
->viewport(), Qt::LeftButton
, Qt::ShiftModifier
, itemView2
->visualRect(index
).center());
499 verifySelectedItemsCount(&view2
, 2);
500 QCOMPARE(selectedItems(&view2
), QStringList() << "3" << "4");
501 view2
.cutSelectedItems();
502 // In view1, "d" is still selected
503 QCOMPARE(selectedItems(&view1
), QStringList() << "d");
506 waitForFinishedPathLoading(&view1
);
507 // In principle, KIO could implement copy&paste such that the pasted items are already there, but the cut items
508 // have not been removed yet. Therefore, we check the number of items in view2 and also wait for that view's
509 // finishedPathLoading() signal if the cut items are still there.
510 if (viewItems(&view2
).count() > 4) {
511 waitForFinishedPathLoading(&view2
);
513 QCOMPARE(viewItems(&view1
), QStringList() << "3" << "4" << "a" << "b" << "c" << "d");
514 QCOMPARE(viewItems(&view2
), QStringList() << "subfolder" << "1" << "2" << "d");
515 // The pasted items ("3", "4") should be selected now, and the previous selection ("d") should be cleared.
516 QCOMPARE(selectedItems(&view1
), QStringList() << "3" << "4");
518 /** Copy and paste into subfolder */
519 view1
.clearSelection();
520 index
= itemView1
->model()->index(3, 0);
521 itemView1
->scrollTo(index
);
522 QTest::mouseClick(itemView1
->viewport(), Qt::LeftButton
, Qt::ControlModifier
, itemView1
->visualRect(index
).center());
523 verifySelectedItemsCount(&view1
, 1);
524 QCOMPARE(selectedItems(&view1
), QStringList() << "b");
525 view1
.copySelectedItems();
526 // Now we use view1 to display the subfolder, which is still empty.
527 view1
.setUrl(KUrl(dir2
.name() + "subfolder"));
528 waitForFinishedPathLoading(&view1
);
529 QCOMPARE(viewItems(&view1
), QStringList());
530 // Select the subfolder.in view2
531 view2
.clearSelection();
532 index
= itemView2
->model()->index(0, 0);
533 itemView2
->scrollTo(index
);
534 QTest::mouseClick(itemView2
->viewport(), Qt::LeftButton
, Qt::ControlModifier
, itemView2
->visualRect(index
).center());
535 verifySelectedItemsCount(&view2
, 1);
536 // Paste into the subfolder
537 view2
.pasteIntoFolder();
538 waitForFinishedPathLoading(&view1
);
539 QCOMPARE(viewItems(&view1
), QStringList() << "b");
540 // The pasted items in view1 are *not* selected now (because the pasting was done indirectly using view2.pasteIntoFolder()).
543 // Private member functions which are used by the tests
546 * initView(DolphinView*) sets the correct view mode, shows the view on the screen, and waits until loading the
547 * folder in the view is finished.
549 * Many unit tests need access to DolphinView's internal item view (icons, details, or columns).
550 * Therefore, a pointer to the item view is returned by initView(DolphinView*).
553 QAbstractItemView
* DolphinViewTest_AllViewModes::initView(DolphinView
* view
) const
555 QSignalSpy
spyFinishedPathLoading(view
, SIGNAL(finishedPathLoading(const KUrl
&)));
556 view
->setMode(mode());
557 Q_ASSERT(verifyCorrectViewMode(view
));
558 view
->resize(200, 300);
560 QTest::qWaitForWindowShown(view
);
562 // If the DolphinView's finishedPathLoading(const KUrl&) signal has not been received yet,
563 // we have to wait a bit more.
564 // The reason why the if-statement is needed here is that the signal might have been emitted
565 // while we were waiting in QTest::qWaitForWindowShown(view)
566 // -> waitForFinishedPathLoading(view) would fail in that case.
567 if (spyFinishedPathLoading
.isEmpty()) {
568 waitForFinishedPathLoading(view
);
571 return itemView(view
);
575 * verifySelectedItemsCount(int) waits until the DolphinView's selectionChanged(const KFileItemList&)
576 * signal is received and checks that the selection state of the view is as expected.
579 void DolphinViewTest_AllViewModes::verifySelectedItemsCount(DolphinView
* view
, int itemsCount
) const
581 QSignalSpy
spySelectionChanged(view
, SIGNAL(selectionChanged(const KFileItemList
&)));
582 QVERIFY(QTest::kWaitForSignal(view
, SIGNAL(selectionChanged(const KFileItemList
&)), 2000));
584 QCOMPARE(view
->selectedItems().count(), itemsCount
);
585 QCOMPARE(view
->selectedItemsCount(), itemsCount
);
586 QCOMPARE(spySelectionChanged
.count(), 1);
587 QCOMPARE(qvariant_cast
<KFileItemList
>(spySelectionChanged
.at(0).at(0)).count(), itemsCount
);
589 QVERIFY(view
->hasSelection());
592 QVERIFY(!view
->hasSelection());
596 #include "dolphinviewtest_allviewmodes.moc"