Changeset View
Changeset View
Standalone View
Standalone View
autotests/kfileplacesmodeltest.cpp
Show All 22 Lines | |||||
23 | 23 | | |||
24 | #include <kbookmarkmanager.h> | 24 | #include <kbookmarkmanager.h> | ||
25 | #include <kbookmark.h> | 25 | #include <kbookmark.h> | ||
26 | #include <QDebug> | 26 | #include <QDebug> | ||
27 | #include <kfileplacesmodel.h> | 27 | #include <kfileplacesmodel.h> | ||
28 | #include <solid/device.h> | 28 | #include <solid/device.h> | ||
29 | #include <kconfig.h> | 29 | #include <kconfig.h> | ||
30 | #include <kconfiggroup.h> | 30 | #include <kconfiggroup.h> | ||
31 | #include <KProtocolInfo> | ||||
31 | 32 | | |||
32 | #include <QtTest> | 33 | #include <QtTest> | ||
33 | 34 | | |||
34 | #include <stdlib.h> | 35 | #include <stdlib.h> | ||
35 | #include <qstandardpaths.h> | 36 | #include <qstandardpaths.h> | ||
36 | 37 | | |||
37 | Q_DECLARE_METATYPE(KFilePlacesModel::GroupType) | 38 | Q_DECLARE_METATYPE(KFilePlacesModel::GroupType) | ||
38 | 39 | | |||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 88 | private: | |||
91 | 92 | | |||
92 | KFilePlacesModel *m_places; | 93 | KFilePlacesModel *m_places; | ||
93 | KFilePlacesModel *m_places2; // To check that they always stay in sync | 94 | KFilePlacesModel *m_places2; // To check that they always stay in sync | ||
94 | // actually supposed to work across processes, | 95 | // actually supposed to work across processes, | ||
95 | // but much harder to test | 96 | // but much harder to test | ||
96 | 97 | | |||
97 | QMap<QString, QDBusInterface *> m_interfacesMap; | 98 | QMap<QString, QDBusInterface *> m_interfacesMap; | ||
98 | QTemporaryDir m_tmpHome; | 99 | QTemporaryDir m_tmpHome; | ||
100 | bool m_hasRecentlyUsedKio; | ||||
99 | }; | 101 | }; | ||
100 | 102 | | |||
101 | static QString bookmarksFile() | 103 | static QString bookmarksFile() | ||
102 | { | 104 | { | ||
103 | return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/user-places.xbel"); | 105 | return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/user-places.xbel"); | ||
104 | } | 106 | } | ||
105 | 107 | | |||
106 | void KFilePlacesModelTest::initTestCase() | 108 | void KFilePlacesModelTest::initTestCase() | ||
Show All 16 Lines | 109 | { | |||
123 | qRegisterMetaType<QModelIndex>(); | 125 | qRegisterMetaType<QModelIndex>(); | ||
124 | qRegisterMetaType<KFilePlacesModel::GroupType>(); | 126 | qRegisterMetaType<KFilePlacesModel::GroupType>(); | ||
125 | 127 | | |||
126 | const QString fakeHw = QFINDTESTDATA("fakecomputer.xml"); | 128 | const QString fakeHw = QFINDTESTDATA("fakecomputer.xml"); | ||
127 | QVERIFY(!fakeHw.isEmpty()); | 129 | QVERIFY(!fakeHw.isEmpty()); | ||
128 | qputenv("SOLID_FAKEHW", QFile::encodeName(fakeHw)); | 130 | qputenv("SOLID_FAKEHW", QFile::encodeName(fakeHw)); | ||
129 | m_places = new KFilePlacesModel(); | 131 | m_places = new KFilePlacesModel(); | ||
130 | m_places2 = new KFilePlacesModel(); | 132 | m_places2 = new KFilePlacesModel(); | ||
133 | | ||||
134 | m_hasRecentlyUsedKio = KProtocolInfo::isKnownProtocol(QStringLiteral("recentlyused")); | ||||
131 | } | 135 | } | ||
132 | 136 | | |||
133 | void KFilePlacesModelTest::cleanupTestCase() | 137 | void KFilePlacesModelTest::cleanupTestCase() | ||
134 | { | 138 | { | ||
135 | delete m_places; | 139 | delete m_places; | ||
136 | delete m_places2; | 140 | delete m_places2; | ||
137 | qDeleteAll(m_interfacesMap); | 141 | qDeleteAll(m_interfacesMap); | ||
138 | QFile::remove(bookmarksFile()); | 142 | QFile::remove(bookmarksFile()); | ||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 188 | { | |||
190 | QDBusInterface *iface = new QDBusInterface(QDBusConnection::sessionBus().baseService(), udi); | 194 | QDBusInterface *iface = new QDBusInterface(QDBusConnection::sessionBus().baseService(), udi); | ||
191 | m_interfacesMap[udi] = iface; | 195 | m_interfacesMap[udi] = iface; | ||
192 | 196 | | |||
193 | return iface; | 197 | return iface; | ||
194 | } | 198 | } | ||
195 | 199 | | |||
196 | void KFilePlacesModelTest::testInitialState() | 200 | void KFilePlacesModelTest::testInitialState() | ||
197 | { | 201 | { | ||
198 | QCOMPARE(m_places->rowCount(), 3); // when the xbel file is empty, KFilePlacesModel fills it with 3 default items | 202 | QCOMPARE(m_places->rowCount(), m_hasRecentlyUsedKio ? 4 : 3); // when the xbel file is empty, KFilePlacesModel fills it with 3 default items | ||
203 | // 4 when ioslave recentlyused:/ is installed | ||||
199 | QCoreApplication::processEvents(); // Devices have a delayed loading | 204 | QCoreApplication::processEvents(); // Devices have a delayed loading | ||
200 | QCOMPARE(m_places->rowCount(), 8); | 205 | QCOMPARE(m_places->rowCount(), m_hasRecentlyUsedKio ? 9 : 8); | ||
201 | } | 206 | } | ||
202 | 207 | | |||
203 | static const QStringList initialListOfPlaces() | 208 | static const QStringList initialListOfPlaces() | ||
204 | { | 209 | { | ||
205 | return QStringList() << QDir::homePath() << QStringLiteral("trash:/"); | 210 | return QStringList() << QDir::homePath() << QStringLiteral("trash:/"); | ||
206 | } | 211 | } | ||
207 | 212 | | |||
208 | static const QStringList initialListOfShared() | 213 | static const QStringList initialListOfShared() | ||
209 | { | 214 | { | ||
210 | return QStringList() << QStringLiteral("remote:/") << QStringLiteral("/media/nfs"); | 215 | return QStringList() << QStringLiteral("remote:/") << QStringLiteral("/media/nfs"); | ||
211 | } | 216 | } | ||
212 | 217 | | |||
218 | static const QStringList initialListOfRecent() | ||||
219 | { | ||||
220 | auto list = QStringList(); | ||||
221 | if (KProtocolInfo::isKnownProtocol(QStringLiteral("recentlyused"))) { | ||||
222 | list << QStringLiteral("recentlyused:/"); | ||||
223 | } | ||||
224 | return list; | ||||
225 | } | ||||
226 | | ||||
213 | static const QStringList initialListOfDevices() | 227 | static const QStringList initialListOfDevices() | ||
214 | { | 228 | { | ||
215 | return QStringList() << QStringLiteral("/foreign"); | 229 | return QStringList() << QStringLiteral("/foreign"); | ||
216 | } | 230 | } | ||
217 | 231 | | |||
218 | static const QStringList initialListOfRemovableDevices() | 232 | static const QStringList initialListOfRemovableDevices() | ||
219 | { | 233 | { | ||
220 | return QStringList() << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); | 234 | return QStringList() << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); | ||
221 | } | 235 | } | ||
222 | 236 | | |||
223 | static const QStringList initialListOfUrls() | 237 | static const QStringList initialListOfUrls() | ||
224 | { | 238 | { | ||
225 | return QStringList() << initialListOfPlaces() | 239 | return QStringList() << initialListOfPlaces() | ||
226 | << initialListOfShared() | 240 | << initialListOfShared() | ||
241 | << initialListOfRecent() | ||||
227 | << initialListOfDevices() | 242 | << initialListOfDevices() | ||
228 | << initialListOfRemovableDevices(); | 243 | << initialListOfRemovableDevices(); | ||
229 | } | 244 | } | ||
230 | 245 | | |||
231 | void KFilePlacesModelTest::testInitialList() | 246 | void KFilePlacesModelTest::testInitialList() | ||
232 | { | 247 | { | ||
233 | const QStringList urls = initialListOfUrls(); | 248 | const QStringList urls = initialListOfUrls(); | ||
234 | CHECK_PLACES_URLS(urls); | 249 | CHECK_PLACES_URLS(urls); | ||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Line(s) | 404 | while (!root.next(last).isNull()) { | |||
390 | last = root.next(last); | 405 | last = root.next(last); | ||
391 | } | 406 | } | ||
392 | root.moveBookmark(system_home, last); | 407 | root.moveBookmark(system_home, last); | ||
393 | bookmarkManager->emitChanged(root); | 408 | bookmarkManager->emitChanged(root); | ||
394 | 409 | | |||
395 | QStringList urls; | 410 | QStringList urls; | ||
396 | urls << QStringLiteral("trash:/") << QDir::homePath() | 411 | urls << QStringLiteral("trash:/") << QDir::homePath() | ||
397 | << initialListOfShared() | 412 | << initialListOfShared() | ||
413 | << initialListOfRecent() | ||||
398 | << initialListOfDevices() | 414 | << initialListOfDevices() | ||
399 | << initialListOfRemovableDevices(); | 415 | << initialListOfRemovableDevices(); | ||
400 | 416 | | |||
401 | CHECK_PLACES_URLS(urls); | 417 | CHECK_PLACES_URLS(urls); | ||
402 | QCOMPARE(spy_inserted.count(), 1); | 418 | QCOMPARE(spy_inserted.count(), 1); | ||
403 | args = spy_inserted.takeFirst(); | 419 | args = spy_inserted.takeFirst(); | ||
404 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 420 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
405 | QCOMPARE(args.at(1).toInt(), 1); | 421 | QCOMPARE(args.at(1).toInt(), 1); | ||
406 | QCOMPARE(args.at(2).toInt(), 1); | 422 | QCOMPARE(args.at(2).toInt(), 1); | ||
407 | QCOMPARE(spy_removed.count(), 1); | 423 | QCOMPARE(spy_removed.count(), 1); | ||
408 | args = spy_removed.takeFirst(); | 424 | args = spy_removed.takeFirst(); | ||
409 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 425 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
410 | QCOMPARE(args.at(1).toInt(), 0); | 426 | QCOMPARE(args.at(1).toInt(), 0); | ||
411 | QCOMPARE(args.at(2).toInt(), 0); | 427 | QCOMPARE(args.at(2).toInt(), 0); | ||
412 | 428 | | |||
413 | // Move home at the beginning of the list (at its original place) | 429 | // Move home at the beginning of the list (at its original place) | ||
414 | root.moveBookmark(system_home, KBookmark()); | 430 | root.moveBookmark(system_home, KBookmark()); | ||
415 | bookmarkManager->emitChanged(root); | 431 | bookmarkManager->emitChanged(root); | ||
416 | urls.clear(); | 432 | urls.clear(); | ||
417 | urls << initialListOfPlaces() | 433 | urls << initialListOfPlaces() | ||
418 | << initialListOfShared() | 434 | << initialListOfShared() | ||
435 | << initialListOfRecent() | ||||
419 | << initialListOfDevices() | 436 | << initialListOfDevices() | ||
420 | << initialListOfRemovableDevices(); | 437 | << initialListOfRemovableDevices(); | ||
421 | CHECK_PLACES_URLS(urls); | 438 | CHECK_PLACES_URLS(urls); | ||
422 | QCOMPARE(spy_inserted.count(), 1); | 439 | QCOMPARE(spy_inserted.count(), 1); | ||
423 | args = spy_inserted.takeFirst(); | 440 | args = spy_inserted.takeFirst(); | ||
424 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 441 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
425 | QCOMPARE(args.at(1).toInt(), 1); | 442 | QCOMPARE(args.at(1).toInt(), 1); | ||
426 | QCOMPARE(args.at(2).toInt(), 1); | 443 | QCOMPARE(args.at(2).toInt(), 1); | ||
Show All 20 Lines | 453 | { | |||
447 | QModelIndexList indexes; | 464 | QModelIndexList indexes; | ||
448 | indexes << m_places->index(0, 0); | 465 | indexes << m_places->index(0, 0); | ||
449 | QMimeData *mimeData = m_places->mimeData(indexes); | 466 | QMimeData *mimeData = m_places->mimeData(indexes); | ||
450 | QVERIFY(m_places->dropMimeData(mimeData, Qt::MoveAction, 2, 0, QModelIndex())); | 467 | QVERIFY(m_places->dropMimeData(mimeData, Qt::MoveAction, 2, 0, QModelIndex())); | ||
451 | 468 | | |||
452 | QStringList urls; | 469 | QStringList urls; | ||
453 | urls << QStringLiteral("trash:/") << QDir::homePath() | 470 | urls << QStringLiteral("trash:/") << QDir::homePath() | ||
454 | << initialListOfShared() | 471 | << initialListOfShared() | ||
472 | << initialListOfRecent() | ||||
455 | << initialListOfDevices() | 473 | << initialListOfDevices() | ||
456 | << initialListOfRemovableDevices(); | 474 | << initialListOfRemovableDevices(); | ||
457 | CHECK_PLACES_URLS(urls); | 475 | CHECK_PLACES_URLS(urls); | ||
458 | QCOMPARE(spy_inserted.count(), 0); | 476 | QCOMPARE(spy_inserted.count(), 0); | ||
459 | QCOMPARE(spy_removed.count(), 0); | 477 | QCOMPARE(spy_removed.count(), 0); | ||
460 | QCOMPARE(spy_moved.count(), 1); | 478 | QCOMPARE(spy_moved.count(), 1); | ||
461 | args = spy_moved.takeFirst(); | 479 | args = spy_moved.takeFirst(); | ||
462 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 480 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
463 | QCOMPARE(args.at(1).toInt(), 0); | 481 | QCOMPARE(args.at(1).toInt(), 0); | ||
464 | QCOMPARE(args.at(2).toInt(), 0); | 482 | QCOMPARE(args.at(2).toInt(), 0); | ||
465 | QCOMPARE(args.at(3).toModelIndex(), QModelIndex()); | 483 | QCOMPARE(args.at(3).toModelIndex(), QModelIndex()); | ||
466 | QCOMPARE(args.at(4).toInt(), 2); | 484 | QCOMPARE(args.at(4).toInt(), 2); | ||
467 | 485 | | |||
468 | // Move home back at the beginning of the list | 486 | // Move home back at the beginning of the list | ||
469 | indexes.clear(); | 487 | indexes.clear(); | ||
470 | indexes << m_places->index(1, 0); | 488 | indexes << m_places->index(1, 0); | ||
471 | mimeData = m_places->mimeData(indexes); | 489 | mimeData = m_places->mimeData(indexes); | ||
472 | QVERIFY(m_places->dropMimeData(mimeData, Qt::MoveAction, 0, 0, QModelIndex())); | 490 | QVERIFY(m_places->dropMimeData(mimeData, Qt::MoveAction, 0, 0, QModelIndex())); | ||
473 | 491 | | |||
474 | urls.clear(); | 492 | urls.clear(); | ||
475 | urls << QDir::homePath() << QStringLiteral("trash:/") | 493 | urls << QDir::homePath() << QStringLiteral("trash:/") | ||
476 | << initialListOfShared() | 494 | << initialListOfShared() | ||
495 | << initialListOfRecent() | ||||
477 | << initialListOfDevices() | 496 | << initialListOfDevices() | ||
478 | << initialListOfRemovableDevices(); | 497 | << initialListOfRemovableDevices(); | ||
479 | CHECK_PLACES_URLS(urls); | 498 | CHECK_PLACES_URLS(urls); | ||
480 | QCOMPARE(spy_inserted.count(), 0); | 499 | QCOMPARE(spy_inserted.count(), 0); | ||
481 | QCOMPARE(spy_removed.count(), 0); | 500 | QCOMPARE(spy_removed.count(), 0); | ||
482 | QCOMPARE(spy_moved.count(), 1); | 501 | QCOMPARE(spy_moved.count(), 1); | ||
483 | args = spy_moved.takeFirst(); | 502 | args = spy_moved.takeFirst(); | ||
484 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 503 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
Show All 20 Lines | 521 | { | |||
505 | QSignalSpy spy_removed(m_places, SIGNAL(rowsRemoved(QModelIndex,int,int))); | 524 | QSignalSpy spy_removed(m_places, SIGNAL(rowsRemoved(QModelIndex,int,int))); | ||
506 | QSignalSpy spy_changed(m_places, SIGNAL(dataChanged(QModelIndex,QModelIndex))); | 525 | QSignalSpy spy_changed(m_places, SIGNAL(dataChanged(QModelIndex,QModelIndex))); | ||
507 | 526 | | |||
508 | m_places->addPlace(QStringLiteral("Foo"), QUrl::fromLocalFile(QStringLiteral("/home/foo"))); | 527 | m_places->addPlace(QStringLiteral("Foo"), QUrl::fromLocalFile(QStringLiteral("/home/foo"))); | ||
509 | 528 | | |||
510 | QStringList urls; | 529 | QStringList urls; | ||
511 | urls << initialListOfPlaces() << QStringLiteral("/home/foo") | 530 | urls << initialListOfPlaces() << QStringLiteral("/home/foo") | ||
512 | << initialListOfShared() | 531 | << initialListOfShared() | ||
532 | << initialListOfRecent() | ||||
513 | << initialListOfDevices() | 533 | << initialListOfDevices() | ||
514 | << initialListOfRemovableDevices(); | 534 | << initialListOfRemovableDevices(); | ||
515 | CHECK_PLACES_URLS(urls); | 535 | CHECK_PLACES_URLS(urls); | ||
516 | QCOMPARE(spy_inserted.count(), 1); | 536 | QCOMPARE(spy_inserted.count(), 1); | ||
517 | args = spy_inserted.takeFirst(); | 537 | args = spy_inserted.takeFirst(); | ||
518 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 538 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
519 | QCOMPARE(args.at(1).toInt(), 2); | 539 | QCOMPARE(args.at(1).toInt(), 2); | ||
520 | QCOMPARE(args.at(2).toInt(), 2); | 540 | QCOMPARE(args.at(2).toInt(), 2); | ||
521 | QCOMPARE(spy_removed.count(), 0); | 541 | QCOMPARE(spy_removed.count(), 0); | ||
522 | 542 | | |||
523 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | 543 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | ||
524 | KBookmarkGroup root = bookmarkManager->root(); | 544 | KBookmarkGroup root = bookmarkManager->root(); | ||
525 | KBookmark before_trash = m_places->bookmarkForIndex(m_places->index(0, 0)); | 545 | KBookmark before_trash = m_places->bookmarkForIndex(m_places->index(0, 0)); | ||
526 | KBookmark foo = m_places->bookmarkForIndex(m_places->index(2, 0)); | 546 | KBookmark foo = m_places->bookmarkForIndex(m_places->index(2, 0)); | ||
527 | 547 | | |||
528 | root.moveBookmark(foo, before_trash); | 548 | root.moveBookmark(foo, before_trash); | ||
529 | bookmarkManager->emitChanged(root); | 549 | bookmarkManager->emitChanged(root); | ||
530 | 550 | | |||
531 | urls.clear(); | 551 | urls.clear(); | ||
532 | urls << QDir::homePath() << QStringLiteral("/home/foo") << QStringLiteral("trash:/") | 552 | urls << QDir::homePath() << QStringLiteral("/home/foo") << QStringLiteral("trash:/") | ||
533 | << initialListOfShared() | 553 | << initialListOfShared() | ||
554 | << initialListOfRecent() | ||||
534 | << initialListOfDevices() | 555 | << initialListOfDevices() | ||
535 | << initialListOfRemovableDevices(); | 556 | << initialListOfRemovableDevices(); | ||
536 | CHECK_PLACES_URLS(urls); | 557 | CHECK_PLACES_URLS(urls); | ||
537 | QCOMPARE(spy_inserted.count(), 1); | 558 | QCOMPARE(spy_inserted.count(), 1); | ||
538 | args = spy_inserted.takeFirst(); | 559 | args = spy_inserted.takeFirst(); | ||
539 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 560 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
540 | QCOMPARE(args.at(1).toInt(), 2); | 561 | QCOMPARE(args.at(1).toInt(), 2); | ||
541 | QCOMPARE(args.at(2).toInt(), 2); | 562 | QCOMPARE(args.at(2).toInt(), 2); | ||
542 | QCOMPARE(spy_removed.count(), 1); | 563 | QCOMPARE(spy_removed.count(), 1); | ||
543 | args = spy_removed.takeFirst(); | 564 | args = spy_removed.takeFirst(); | ||
544 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 565 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
545 | QCOMPARE(args.at(1).toInt(), 1); | 566 | QCOMPARE(args.at(1).toInt(), 1); | ||
546 | QCOMPARE(args.at(2).toInt(), 1); | 567 | QCOMPARE(args.at(2).toInt(), 1); | ||
547 | 568 | | |||
548 | m_places->editPlace(m_places->index(1, 0), QStringLiteral("Foo"), QUrl::fromLocalFile(QStringLiteral("/mnt/foo"))); | 569 | m_places->editPlace(m_places->index(1, 0), QStringLiteral("Foo"), QUrl::fromLocalFile(QStringLiteral("/mnt/foo"))); | ||
549 | 570 | | |||
550 | urls.clear(); | 571 | urls.clear(); | ||
551 | urls << QDir::homePath() << QStringLiteral("/mnt/foo") << QStringLiteral("trash:/") | 572 | urls << QDir::homePath() << QStringLiteral("/mnt/foo") << QStringLiteral("trash:/") | ||
552 | << initialListOfShared() | 573 | << initialListOfShared() | ||
574 | << initialListOfRecent() | ||||
553 | << initialListOfDevices() | 575 | << initialListOfDevices() | ||
554 | << initialListOfRemovableDevices(); | 576 | << initialListOfRemovableDevices(); | ||
555 | CHECK_PLACES_URLS(urls); | 577 | CHECK_PLACES_URLS(urls); | ||
556 | QCOMPARE(spy_inserted.count(), 0); | 578 | QCOMPARE(spy_inserted.count(), 0); | ||
557 | QCOMPARE(spy_removed.count(), 0); | 579 | QCOMPARE(spy_removed.count(), 0); | ||
558 | QCOMPARE(spy_changed.count(), 1); | 580 | QCOMPARE(spy_changed.count(), 1); | ||
559 | args = spy_changed.takeFirst(); | 581 | args = spy_changed.takeFirst(); | ||
560 | QCOMPARE(args.at(0).toModelIndex(), m_places->index(1, 0)); | 582 | QCOMPARE(args.at(0).toModelIndex(), m_places->index(1, 0)); | ||
561 | QCOMPARE(args.at(1).toModelIndex(), m_places->index(1, 0)); | 583 | QCOMPARE(args.at(1).toModelIndex(), m_places->index(1, 0)); | ||
562 | 584 | | |||
563 | foo = m_places->bookmarkForIndex(m_places->index(1, 0)); | 585 | foo = m_places->bookmarkForIndex(m_places->index(1, 0)); | ||
564 | foo.setFullText(QStringLiteral("Bar")); | 586 | foo.setFullText(QStringLiteral("Bar")); | ||
565 | bookmarkManager->notifyCompleteChange(QString()); | 587 | bookmarkManager->notifyCompleteChange(QString()); | ||
566 | 588 | | |||
567 | urls.clear(); | 589 | urls.clear(); | ||
568 | urls << QDir::homePath() << QStringLiteral("/mnt/foo") << QStringLiteral("trash:/") | 590 | urls << QDir::homePath() << QStringLiteral("/mnt/foo") << QStringLiteral("trash:/") | ||
569 | << initialListOfShared() | 591 | << initialListOfShared() | ||
592 | << initialListOfRecent() | ||||
570 | << initialListOfDevices() | 593 | << initialListOfDevices() | ||
571 | << initialListOfRemovableDevices(); | 594 | << initialListOfRemovableDevices(); | ||
572 | 595 | | |||
573 | CHECK_PLACES_URLS(urls); | 596 | CHECK_PLACES_URLS(urls); | ||
574 | QCOMPARE(spy_inserted.count(), 0); | 597 | QCOMPARE(spy_inserted.count(), 0); | ||
575 | QCOMPARE(spy_removed.count(), 0); | 598 | QCOMPARE(spy_removed.count(), 0); | ||
576 | QCOMPARE(spy_changed.count(), 9); | 599 | QCOMPARE(spy_changed.count(), m_hasRecentlyUsedKio ? 10 : 9); | ||
577 | args = spy_changed[2]; | 600 | args = spy_changed[2]; | ||
578 | QCOMPARE(args.at(0).toModelIndex(), m_places->index(2, 0)); | 601 | QCOMPARE(args.at(0).toModelIndex(), m_places->index(2, 0)); | ||
579 | QCOMPARE(args.at(1).toModelIndex(), m_places->index(2, 0)); | 602 | QCOMPARE(args.at(1).toModelIndex(), m_places->index(2, 0)); | ||
580 | spy_changed.clear(); | 603 | spy_changed.clear(); | ||
581 | 604 | | |||
582 | m_places->removePlace(m_places->index(1, 0)); | 605 | m_places->removePlace(m_places->index(1, 0)); | ||
583 | 606 | | |||
584 | urls.clear(); | 607 | urls.clear(); | ||
585 | urls << initialListOfPlaces() | 608 | urls << initialListOfPlaces() | ||
586 | << initialListOfShared() | 609 | << initialListOfShared() | ||
610 | << initialListOfRecent() | ||||
587 | << initialListOfDevices() | 611 | << initialListOfDevices() | ||
588 | << initialListOfRemovableDevices(); | 612 | << initialListOfRemovableDevices(); | ||
589 | CHECK_PLACES_URLS(urls); | 613 | CHECK_PLACES_URLS(urls); | ||
590 | QCOMPARE(spy_inserted.count(), 0); | 614 | QCOMPARE(spy_inserted.count(), 0); | ||
591 | QCOMPARE(spy_removed.count(), 1); | 615 | QCOMPARE(spy_removed.count(), 1); | ||
592 | args = spy_removed.takeFirst(); | 616 | args = spy_removed.takeFirst(); | ||
593 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 617 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
594 | QCOMPARE(args.at(1).toInt(), 1); | 618 | QCOMPARE(args.at(1).toInt(), 1); | ||
595 | QCOMPARE(args.at(2).toInt(), 1); | 619 | QCOMPARE(args.at(2).toInt(), 1); | ||
596 | 620 | | |||
597 | m_places->addPlace(QStringLiteral("Foo"), QUrl::fromLocalFile(QStringLiteral("/home/foo")), QString(), QString(), m_places->index(0, 0)); | 621 | m_places->addPlace(QStringLiteral("Foo"), QUrl::fromLocalFile(QStringLiteral("/home/foo")), QString(), QString(), m_places->index(0, 0)); | ||
598 | 622 | | |||
599 | urls.clear(); | 623 | urls.clear(); | ||
600 | urls << QDir::homePath() << QStringLiteral("/home/foo") << QStringLiteral("trash:/") | 624 | urls << QDir::homePath() << QStringLiteral("/home/foo") << QStringLiteral("trash:/") | ||
601 | << initialListOfShared() | 625 | << initialListOfShared() | ||
626 | << initialListOfRecent() | ||||
602 | << initialListOfDevices() | 627 | << initialListOfDevices() | ||
603 | << initialListOfRemovableDevices(); | 628 | << initialListOfRemovableDevices(); | ||
604 | CHECK_PLACES_URLS(urls); | 629 | CHECK_PLACES_URLS(urls); | ||
605 | QCOMPARE(spy_inserted.count(), 1); | 630 | QCOMPARE(spy_inserted.count(), 1); | ||
606 | args = spy_inserted.takeFirst(); | 631 | args = spy_inserted.takeFirst(); | ||
607 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 632 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
608 | QCOMPARE(args.at(1).toInt(), 1); | 633 | QCOMPARE(args.at(1).toInt(), 1); | ||
609 | QCOMPARE(args.at(2).toInt(), 1); | 634 | QCOMPARE(args.at(2).toInt(), 1); | ||
610 | QCOMPARE(spy_removed.count(), 0); | 635 | QCOMPARE(spy_removed.count(), 0); | ||
611 | 636 | | |||
612 | m_places->removePlace(m_places->index(1, 0)); | 637 | m_places->removePlace(m_places->index(1, 0)); | ||
613 | } | 638 | } | ||
614 | 639 | | |||
615 | void KFilePlacesModelTest::testDevicePlugging() | 640 | void KFilePlacesModelTest::testDevicePlugging() | ||
616 | { | 641 | { | ||
617 | QList<QVariant> args; | 642 | QList<QVariant> args; | ||
618 | QSignalSpy spy_inserted(m_places, SIGNAL(rowsInserted(QModelIndex,int,int))); | 643 | QSignalSpy spy_inserted(m_places, SIGNAL(rowsInserted(QModelIndex,int,int))); | ||
619 | QSignalSpy spy_removed(m_places, SIGNAL(rowsRemoved(QModelIndex,int,int))); | 644 | QSignalSpy spy_removed(m_places, SIGNAL(rowsRemoved(QModelIndex,int,int))); | ||
620 | 645 | | |||
621 | fakeManager()->call(QStringLiteral("unplug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | 646 | fakeManager()->call(QStringLiteral("unplug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | ||
622 | 647 | | |||
623 | QStringList urls; | 648 | QStringList urls; | ||
624 | urls << initialListOfPlaces() | 649 | urls << initialListOfPlaces() | ||
625 | << initialListOfShared() | 650 | << initialListOfShared() | ||
651 | << initialListOfRecent() | ||||
626 | << initialListOfDevices() | 652 | << initialListOfDevices() | ||
627 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | 653 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | ||
628 | CHECK_PLACES_URLS(urls); | 654 | CHECK_PLACES_URLS(urls); | ||
629 | QCOMPARE(spy_inserted.count(), 0); | 655 | QCOMPARE(spy_inserted.count(), 0); | ||
630 | QCOMPARE(spy_removed.count(), 1); | 656 | QCOMPARE(spy_removed.count(), 1); | ||
631 | args = spy_removed.takeFirst(); | 657 | args = spy_removed.takeFirst(); | ||
632 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 658 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
633 | QCOMPARE(args.at(1).toInt(), 6); | 659 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 7 : 6); | ||
634 | QCOMPARE(args.at(2).toInt(), 6); | 660 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 7 : 6); | ||
635 | 661 | | |||
636 | fakeManager()->call(QStringLiteral("plug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | 662 | fakeManager()->call(QStringLiteral("plug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | ||
637 | 663 | | |||
638 | urls.clear(); | 664 | urls.clear(); | ||
639 | urls << initialListOfPlaces() | 665 | urls << initialListOfPlaces() | ||
640 | << initialListOfShared() | 666 | << initialListOfShared() | ||
667 | << initialListOfRecent() | ||||
641 | << initialListOfDevices() | 668 | << initialListOfDevices() | ||
642 | << initialListOfRemovableDevices(); | 669 | << initialListOfRemovableDevices(); | ||
643 | CHECK_PLACES_URLS(urls); | 670 | CHECK_PLACES_URLS(urls); | ||
644 | QCOMPARE(spy_inserted.count(), 1); | 671 | QCOMPARE(spy_inserted.count(), 1); | ||
645 | args = spy_inserted.takeFirst(); | 672 | args = spy_inserted.takeFirst(); | ||
646 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 673 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
647 | QCOMPARE(args.at(1).toInt(), 6); | 674 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 7 : 6); | ||
648 | QCOMPARE(args.at(2).toInt(), 6); | 675 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 7 : 6); | ||
649 | QCOMPARE(spy_removed.count(), 0); | 676 | QCOMPARE(spy_removed.count(), 0); | ||
650 | 677 | | |||
651 | // Move the device in the list, and check that it memorizes the position across plug/unplug | 678 | // Move the device in the list, and check that it memorizes the position across plug/unplug | ||
652 | 679 | | |||
653 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | 680 | KBookmarkManager *bookmarkManager = KBookmarkManager::managerForFile(bookmarksFile(), QStringLiteral("kfilePlaces")); | ||
654 | KBookmarkGroup root = bookmarkManager->root(); | 681 | KBookmarkGroup root = bookmarkManager->root(); | ||
655 | KBookmark before_floppy; | 682 | KBookmark before_floppy; | ||
656 | 683 | | |||
657 | KBookmark device = root.first(); // The device we'll move is the 6th bookmark | 684 | KBookmark device = root.first(); // The device we'll move is the 6th bookmark | ||
658 | for (int i = 0; i < 5; i++) { | 685 | int stop = m_hasRecentlyUsedKio ? 6 : 5; | ||
686 | for (int i = 0; i < stop; i++) { | ||||
elvisangelaccio: `const`, and maybe a more descriptive name (`count` or similar?) | |||||
659 | if (i == 2) { | 687 | if (i == 2) { | ||
660 | // store item before to be able to move it back to original position | 688 | // store item before to be able to move it back to original position | ||
661 | device = before_floppy = root.next(device); | 689 | device = before_floppy = root.next(device); | ||
662 | } else { | 690 | } else { | ||
663 | device = root.next(device); | 691 | device = root.next(device); | ||
664 | } | 692 | } | ||
665 | } | 693 | } | ||
666 | 694 | | |||
667 | root.moveBookmark(device, before_floppy); | 695 | root.moveBookmark(device, before_floppy); | ||
668 | bookmarkManager->emitChanged(root); | 696 | bookmarkManager->emitChanged(root); | ||
669 | 697 | | |||
670 | urls.clear(); | 698 | urls.clear(); | ||
671 | urls << initialListOfPlaces() | 699 | urls << initialListOfPlaces() | ||
672 | << initialListOfShared() | 700 | << initialListOfShared() | ||
701 | << initialListOfRecent() | ||||
673 | << initialListOfDevices() | 702 | << initialListOfDevices() | ||
674 | << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | 703 | << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | ||
675 | CHECK_PLACES_URLS(urls); | 704 | CHECK_PLACES_URLS(urls); | ||
676 | QCOMPARE(spy_inserted.count(), 1); | 705 | QCOMPARE(spy_inserted.count(), 1); | ||
677 | args = spy_inserted.takeFirst(); | 706 | args = spy_inserted.takeFirst(); | ||
678 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 707 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
679 | QCOMPARE(args.at(1).toInt(), 6); | 708 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 7 : 6); | ||
680 | QCOMPARE(args.at(2).toInt(), 6); | 709 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 7 : 6); | ||
681 | QCOMPARE(spy_removed.count(), 1); | 710 | QCOMPARE(spy_removed.count(), 1); | ||
682 | args = spy_removed.takeFirst(); | 711 | args = spy_removed.takeFirst(); | ||
683 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 712 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
684 | QCOMPARE(args.at(1).toInt(), 5); | 713 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 6 : 5); | ||
685 | QCOMPARE(args.at(2).toInt(), 5); | 714 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 6 : 5); | ||
686 | 715 | | |||
687 | fakeManager()->call(QStringLiteral("unplug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | 716 | fakeManager()->call(QStringLiteral("unplug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | ||
688 | 717 | | |||
689 | urls.clear(); | 718 | urls.clear(); | ||
690 | urls << initialListOfPlaces() | 719 | urls << initialListOfPlaces() | ||
691 | << initialListOfShared() | 720 | << initialListOfShared() | ||
721 | << initialListOfRecent() | ||||
692 | << initialListOfDevices() | 722 | << initialListOfDevices() | ||
693 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | 723 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | ||
694 | CHECK_PLACES_URLS(urls); | 724 | CHECK_PLACES_URLS(urls); | ||
695 | QCOMPARE(spy_inserted.count(), 0); | 725 | QCOMPARE(spy_inserted.count(), 0); | ||
696 | QCOMPARE(spy_removed.count(), 1); | 726 | QCOMPARE(spy_removed.count(), 1); | ||
697 | args = spy_removed.takeFirst(); | 727 | args = spy_removed.takeFirst(); | ||
698 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 728 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
699 | QCOMPARE(args.at(1).toInt(), 5); | 729 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 6 : 5); | ||
700 | QCOMPARE(args.at(2).toInt(), 5); | 730 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 6 : 5); | ||
701 | 731 | | |||
702 | fakeManager()->call(QStringLiteral("plug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | 732 | fakeManager()->call(QStringLiteral("plug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); | ||
703 | 733 | | |||
704 | urls.clear(); | 734 | urls.clear(); | ||
705 | urls << initialListOfPlaces() | 735 | urls << initialListOfPlaces() | ||
706 | << initialListOfShared() | 736 | << initialListOfShared() | ||
737 | << initialListOfRecent() | ||||
707 | << initialListOfDevices() << QStringLiteral("/media/XO-Y4") | 738 | << initialListOfDevices() << QStringLiteral("/media/XO-Y4") | ||
708 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | 739 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); | ||
709 | CHECK_PLACES_URLS(urls); | 740 | CHECK_PLACES_URLS(urls); | ||
710 | QCOMPARE(spy_inserted.count(), 1); | 741 | QCOMPARE(spy_inserted.count(), 1); | ||
711 | args = spy_inserted.takeFirst(); | 742 | args = spy_inserted.takeFirst(); | ||
712 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 743 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
713 | QCOMPARE(args.at(1).toInt(), 5); | 744 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 6 : 5); | ||
714 | QCOMPARE(args.at(2).toInt(), 5); | 745 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 6 : 5); | ||
715 | QCOMPARE(spy_removed.count(), 0); | 746 | QCOMPARE(spy_removed.count(), 0); | ||
716 | 747 | | |||
717 | KBookmark sixth = root.first(); | 748 | KBookmark seventh = root.first(); | ||
718 | for (int i = 0; i < 5; i++) { | 749 | for (int i = 0; i < stop; i++) { | ||
719 | sixth = root.next(sixth); | 750 | seventh = root.next(seventh); | ||
720 | } | 751 | } | ||
721 | root.moveBookmark(device, sixth); | 752 | root.moveBookmark(device, seventh); | ||
722 | bookmarkManager->emitChanged(root); | 753 | bookmarkManager->emitChanged(root); | ||
723 | 754 | | |||
724 | urls.clear(); | 755 | urls.clear(); | ||
725 | urls << initialListOfPlaces() | 756 | urls << initialListOfPlaces() | ||
726 | << initialListOfShared() | 757 | << initialListOfShared() | ||
758 | << initialListOfRecent() | ||||
727 | << initialListOfDevices() | 759 | << initialListOfDevices() | ||
728 | << initialListOfRemovableDevices(); | 760 | << initialListOfRemovableDevices(); | ||
729 | CHECK_PLACES_URLS(urls); | 761 | CHECK_PLACES_URLS(urls); | ||
730 | QCOMPARE(spy_inserted.count(), 1); | 762 | QCOMPARE(spy_inserted.count(), 1); | ||
731 | args = spy_inserted.takeFirst(); | 763 | args = spy_inserted.takeFirst(); | ||
732 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 764 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
733 | QCOMPARE(args.at(1).toInt(), 6); | 765 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 7 : 6); | ||
734 | QCOMPARE(args.at(2).toInt(), 6); | 766 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 7 : 6); | ||
735 | QCOMPARE(spy_removed.count(), 1); | 767 | QCOMPARE(spy_removed.count(), 1); | ||
736 | args = spy_removed.takeFirst(); | 768 | args = spy_removed.takeFirst(); | ||
737 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 769 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
738 | QCOMPARE(args.at(1).toInt(), 5); | 770 | QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 6 : 5); | ||
739 | QCOMPARE(args.at(2).toInt(), 5); | 771 | QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 6 : 5); | ||
740 | } | 772 | } | ||
741 | 773 | | |||
742 | void KFilePlacesModelTest::testDeviceSetupTeardown() | 774 | void KFilePlacesModelTest::testDeviceSetupTeardown() | ||
743 | { | 775 | { | ||
744 | QList<QVariant> args; | 776 | QList<QVariant> args; | ||
745 | QSignalSpy spy_changed(m_places, SIGNAL(dataChanged(QModelIndex,QModelIndex))); | 777 | QSignalSpy spy_changed(m_places, SIGNAL(dataChanged(QModelIndex,QModelIndex))); | ||
746 | 778 | | |||
747 | fakeDevice(QStringLiteral("/org/kde/solid/fakehw/volume_part1_size_993284096/StorageAccess"))->call(QStringLiteral("teardown")); | 779 | fakeDevice(QStringLiteral("/org/kde/solid/fakehw/volume_part1_size_993284096/StorageAccess"))->call(QStringLiteral("teardown")); | ||
748 | 780 | | |||
749 | QCOMPARE(spy_changed.count(), 1); | 781 | QCOMPARE(spy_changed.count(), 1); | ||
750 | args = spy_changed.takeFirst(); | 782 | args = spy_changed.takeFirst(); | ||
751 | QCOMPARE(args.at(0).toModelIndex().row(), 6); | 783 | QCOMPARE(args.at(0).toModelIndex().row(), m_hasRecentlyUsedKio ? 7 : 6); | ||
752 | QCOMPARE(args.at(1).toModelIndex().row(), 6); | 784 | QCOMPARE(args.at(1).toModelIndex().row(), m_hasRecentlyUsedKio ? 7 : 6); | ||
753 | 785 | | |||
754 | fakeDevice(QStringLiteral("/org/kde/solid/fakehw/volume_part1_size_993284096/StorageAccess"))->call(QStringLiteral("setup")); | 786 | fakeDevice(QStringLiteral("/org/kde/solid/fakehw/volume_part1_size_993284096/StorageAccess"))->call(QStringLiteral("setup")); | ||
755 | 787 | | |||
756 | QCOMPARE(spy_changed.count(), 1); | 788 | QCOMPARE(spy_changed.count(), 1); | ||
757 | args = spy_changed.takeFirst(); | 789 | args = spy_changed.takeFirst(); | ||
758 | QCOMPARE(args.at(0).toModelIndex().row(), 6); | 790 | QCOMPARE(args.at(0).toModelIndex().row(), m_hasRecentlyUsedKio ? 7 : 6); | ||
759 | QCOMPARE(args.at(1).toModelIndex().row(), 6); | 791 | QCOMPARE(args.at(1).toModelIndex().row(), m_hasRecentlyUsedKio ? 7 : 6); | ||
760 | } | 792 | } | ||
761 | 793 | | |||
762 | void KFilePlacesModelTest::testEnableBaloo() | 794 | void KFilePlacesModelTest::testEnableBaloo() | ||
763 | { | 795 | { | ||
764 | KConfig config(QStringLiteral("baloofilerc")); | 796 | KConfig config(QStringLiteral("baloofilerc")); | ||
765 | KConfigGroup basicSettings = config.group("Basic Settings"); | 797 | KConfigGroup basicSettings = config.group("Basic Settings"); | ||
766 | basicSettings.writeEntry("Indexing-Enabled", true); | 798 | basicSettings.writeEntry("Indexing-Enabled", true); | ||
767 | config.sync(); | 799 | config.sync(); | ||
Show All 38 Lines | 831 | { | |||
806 | 838 | | |||
807 | // insert a new network url | 839 | // insert a new network url | ||
808 | m_places->addPlace(QStringLiteral("My Shared"), url, QString(), QString(), QModelIndex()); | 840 | m_places->addPlace(QStringLiteral("My Shared"), url, QString(), QString(), QModelIndex()); | ||
809 | 841 | | |||
810 | // check if url list is correct after insertion | 842 | // check if url list is correct after insertion | ||
811 | QStringList urls; | 843 | QStringList urls; | ||
812 | urls << QDir::homePath() << QStringLiteral("trash:/") // places | 844 | urls << QDir::homePath() << QStringLiteral("trash:/") // places | ||
813 | << QStringLiteral("remote:/") << QStringLiteral("/media/nfs") | 845 | << QStringLiteral("remote:/") << QStringLiteral("/media/nfs") | ||
814 | << url.toString() << QStringLiteral("/foreign") | 846 | << url.toString() | ||
847 | << initialListOfRecent() | ||||
848 | << QStringLiteral("/foreign") | ||||
815 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); | 849 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); | ||
816 | CHECK_PLACES_URLS(urls); | 850 | CHECK_PLACES_URLS(urls); | ||
817 | 851 | | |||
818 | // check if the new url was inserted in the right position (end of "Remote" section) | 852 | // check if the new url was inserted in the right position (end of "Remote" section) | ||
819 | QTRY_COMPARE(spy_inserted.count(), 1); | 853 | QTRY_COMPARE(spy_inserted.count(), 1); | ||
820 | args = spy_inserted.takeFirst(); | 854 | args = spy_inserted.takeFirst(); | ||
821 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 855 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
822 | QCOMPARE(args.at(1).toInt(), expectedRow); | 856 | QCOMPARE(args.at(1).toInt(), expectedRow); | ||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Line(s) | |||||
924 | } | 958 | } | ||
925 | 959 | | |||
926 | void KFilePlacesModelTest::testIconRole_data() | 960 | void KFilePlacesModelTest::testIconRole_data() | ||
927 | { | 961 | { | ||
928 | QTest::addColumn<QModelIndex>("index"); | 962 | QTest::addColumn<QModelIndex>("index"); | ||
929 | QTest::addColumn<QString>("expectedIconName"); | 963 | QTest::addColumn<QString>("expectedIconName"); | ||
930 | 964 | | |||
931 | // places | 965 | // places | ||
932 | QTest::newRow("Places - Home") << m_places->index(0, 0) | 966 | int idx = 0; | ||
967 | QTest::newRow("Places - Home") << m_places->index(idx++, 0) | ||||
elvisangelaccio: I'd avoid cryptic names. If we can't use `index`, maybe just `i`? | |||||
933 | << QStringLiteral("user-home"); | 968 | << QStringLiteral("user-home"); | ||
934 | QTest::newRow("Places - Trash") << m_places->index(1, 0) | 969 | QTest::newRow("Places - Trash") << m_places->index(idx++, 0) | ||
935 | << QStringLiteral("user-trash"); | 970 | << QStringLiteral("user-trash"); | ||
936 | QTest::newRow("Remote - Network") << m_places->index(2, 0) | 971 | | ||
972 | QTest::newRow("Remote - Network") << m_places->index(idx++, 0) | ||||
937 | << QStringLiteral("folder-network"); | 973 | << QStringLiteral("folder-network"); | ||
938 | QTest::newRow("Devices - Nfs") << m_places->index(3, 0) | 974 | QTest::newRow("Devices - Nfs") << m_places->index(idx++, 0) | ||
939 | << QStringLiteral("hwinfo"); | 975 | << QStringLiteral("hwinfo"); | ||
940 | QTest::newRow("Devices - foreign") << m_places->index(4, 0) | 976 | if (m_hasRecentlyUsedKio) { | ||
977 | QTest::newRow("Recently Used") << m_places->index(idx++, 0) | ||||
978 | << QStringLiteral("document-open-recent"); | ||||
979 | } | ||||
980 | QTest::newRow("Devices - foreign") << m_places->index(idx++, 0) | ||||
941 | << QStringLiteral("blockdevice"); | 981 | << QStringLiteral("blockdevice"); | ||
942 | QTest::newRow("Devices - Floppy") << m_places->index(5, 0) | 982 | QTest::newRow("Devices - Floppy") << m_places->index(idx++, 0) | ||
943 | << QStringLiteral("blockdevice"); | 983 | << QStringLiteral("blockdevice"); | ||
944 | QTest::newRow("Devices - cdrom") << m_places->index(6, 0) | 984 | QTest::newRow("Devices - cdrom") << m_places->index(idx++, 0) | ||
945 | << QStringLiteral("blockdevice"); | 985 | << QStringLiteral("blockdevice"); | ||
946 | } | 986 | } | ||
947 | 987 | | |||
948 | void KFilePlacesModelTest::testIconRole() | 988 | void KFilePlacesModelTest::testIconRole() | ||
949 | { | 989 | { | ||
950 | QFETCH(QModelIndex, index); | 990 | QFETCH(QModelIndex, index); | ||
951 | QFETCH(QString, expectedIconName); | 991 | QFETCH(QString, expectedIconName); | ||
952 | 992 | | |||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Line(s) | |||||
1035 | } | 1075 | } | ||
1036 | 1076 | | |||
1037 | void KFilePlacesModelTest::testPlaceGroupHidden() | 1077 | void KFilePlacesModelTest::testPlaceGroupHidden() | ||
1038 | { | 1078 | { | ||
1039 | // GIVEN | 1079 | // GIVEN | ||
1040 | QCOMPARE(m_places->hiddenCount(), 0); | 1080 | QCOMPARE(m_places->hiddenCount(), 0); | ||
1041 | 1081 | | |||
1042 | QStringList urls; | 1082 | QStringList urls; | ||
1043 | urls << initialListOfPlaces() << initialListOfShared() << initialListOfDevices() << initialListOfRemovableDevices(); | 1083 | urls << initialListOfPlaces() | ||
1084 | << initialListOfShared() | ||||
1085 | << initialListOfRecent() | ||||
1086 | << initialListOfDevices() | ||||
1087 | << initialListOfRemovableDevices(); | ||||
1044 | CHECK_PLACES_URLS(urls); | 1088 | CHECK_PLACES_URLS(urls); | ||
1045 | QVector<QModelIndex> indexesHidden; | 1089 | QVector<QModelIndex> indexesHidden; | ||
1046 | 1090 | | |||
1047 | // WHEN | 1091 | // WHEN | ||
1048 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, true); | 1092 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, true); | ||
1049 | 1093 | | |||
1050 | // THEN | 1094 | // THEN | ||
1051 | for (int row = 0; row < m_places->rowCount(); ++row) { | 1095 | for (int row = 0; row < m_places->rowCount(); ++row) { | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
1102 | } | 1146 | } | ||
1103 | 1147 | | |||
1104 | void KFilePlacesModelTest::testPlaceGroupHiddenAndShownWithHiddenChild() | 1148 | void KFilePlacesModelTest::testPlaceGroupHiddenAndShownWithHiddenChild() | ||
1105 | { | 1149 | { | ||
1106 | // GIVEN | 1150 | // GIVEN | ||
1107 | QCOMPARE(m_places->hiddenCount(), 0); | 1151 | QCOMPARE(m_places->hiddenCount(), 0); | ||
1108 | 1152 | | |||
1109 | QStringList urls; | 1153 | QStringList urls; | ||
1110 | urls << initialListOfPlaces() << initialListOfShared() << initialListOfDevices() << initialListOfRemovableDevices(); | 1154 | urls << initialListOfPlaces() | ||
1155 | << initialListOfShared() | ||||
1156 | << initialListOfRecent() | ||||
1157 | << initialListOfDevices() | ||||
1158 | << initialListOfRemovableDevices(); | ||||
1111 | CHECK_PLACES_URLS(urls); | 1159 | CHECK_PLACES_URLS(urls); | ||
1112 | 1160 | | |||
1113 | QModelIndex firstIndexHidden = m_places->index(0,0); | 1161 | QModelIndex firstIndexHidden = m_places->index(0,0); | ||
1114 | m_places->setPlaceHidden(firstIndexHidden, true); // first place index is hidden within an hidden parent | 1162 | m_places->setPlaceHidden(firstIndexHidden, true); // first place index is hidden within an hidden parent | ||
1115 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, true); | 1163 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, true); | ||
1116 | QCOMPARE(m_places->hiddenCount(), initialListOfPlaces().size()); | 1164 | QCOMPARE(m_places->hiddenCount(), initialListOfPlaces().size()); | ||
1117 | 1165 | | |||
1118 | // WHEN | 1166 | // WHEN | ||
Show All 21 Lines | |||||
1140 | 1188 | | |||
1141 | void KFilePlacesModelTest::testPlaceGroupHiddenGroupIndexesIntegrity() | 1189 | void KFilePlacesModelTest::testPlaceGroupHiddenGroupIndexesIntegrity() | ||
1142 | { | 1190 | { | ||
1143 | // GIVEN | 1191 | // GIVEN | ||
1144 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, true); | 1192 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, true); | ||
1145 | QVERIFY(m_places->groupIndexes(KFilePlacesModel::UnknownType).isEmpty()); | 1193 | QVERIFY(m_places->groupIndexes(KFilePlacesModel::UnknownType).isEmpty()); | ||
1146 | QVERIFY(m_places->isGroupHidden(KFilePlacesModel::PlacesType)); | 1194 | QVERIFY(m_places->isGroupHidden(KFilePlacesModel::PlacesType)); | ||
1147 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::PlacesType).count(), initialListOfPlaces().count()); | 1195 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::PlacesType).count(), initialListOfPlaces().count()); | ||
1148 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RecentlySavedType).count(), 0); | 1196 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RecentlySavedType).count(), m_hasRecentlyUsedKio ? 1 : 0); | ||
1149 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::SearchForType).count(), 0); | 1197 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::SearchForType).count(), 0); | ||
1150 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::DevicesType).count(), initialListOfDevices().count()); | 1198 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::DevicesType).count(), initialListOfDevices().count()); | ||
1151 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RemovableDevicesType).count(), initialListOfRemovableDevices().count()); | 1199 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RemovableDevicesType).count(), initialListOfRemovableDevices().count()); | ||
1152 | 1200 | | |||
1153 | //WHEN | 1201 | //WHEN | ||
1154 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, false); | 1202 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, false); | ||
1155 | 1203 | | |||
1156 | // THEN | 1204 | // THEN | ||
1157 | // Make sure that hidden place group doesn't change model | 1205 | // Make sure that hidden place group doesn't change model | ||
1158 | QVERIFY(!m_places->isGroupHidden(KFilePlacesModel::PlacesType)); | 1206 | QVERIFY(!m_places->isGroupHidden(KFilePlacesModel::PlacesType)); | ||
1159 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::PlacesType).count(), initialListOfPlaces().count()); | 1207 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::PlacesType).count(), initialListOfPlaces().count()); | ||
1160 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RecentlySavedType).count(), 0); | 1208 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RecentlySavedType).count(), m_hasRecentlyUsedKio ? 1 : 0); | ||
1161 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::SearchForType).count(), 0); | 1209 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::SearchForType).count(), 0); | ||
1162 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::DevicesType).count(), initialListOfDevices().count()); | 1210 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::DevicesType).count(), initialListOfDevices().count()); | ||
1163 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RemovableDevicesType).count(), initialListOfRemovableDevices().count()); | 1211 | QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RemovableDevicesType).count(), initialListOfRemovableDevices().count()); | ||
1164 | } | 1212 | } | ||
1165 | 1213 | | |||
1166 | void KFilePlacesModelTest::testPlaceGroupHiddenSignal() | 1214 | void KFilePlacesModelTest::testPlaceGroupHiddenSignal() | ||
1167 | { | 1215 | { | ||
1168 | QSignalSpy groupHiddenSignal(m_places, &KFilePlacesModel::groupHiddenChanged); | 1216 | QSignalSpy groupHiddenSignal(m_places, &KFilePlacesModel::groupHiddenChanged); | ||
▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines |
const, and maybe a more descriptive name (count or similar?)