+
+ // make sure that the new item will be removed later
+ removePlaceAfter(3);
+
+ PlacesItem *item = m_model->placesItem(3);
+ PlacesItem *sameItem = model->placesItem(3);
+ QCOMPARE(item->text(), sameItem->text());
+
+ // modify place text
+ item->setText(QStringLiteral("Renamed place"));
+
+ // item from another model is not affected at the moment
+ QVERIFY(item->text() != sameItem->text());
+
+ // propagate change
+ m_model->refresh();
+
+ // item must be equal
+ QTRY_COMPARE(item->text(), sameItem->text());
+}
+
+void PlacesItemModelTest::testIcons_data()
+{
+ QTest::addColumn<QUrl>("url");
+ QTest::addColumn<QString>("expectedIconName");
+
+ // places
+ QTest::newRow("Places - Home") << QUrl::fromLocalFile(QDir::homePath()) << QStringLiteral("user-home");
+
+ // baloo -search
+ QTest::newRow("Baloo - Documents") << QUrl("search:/documents") << QStringLiteral("folder-text");
+
+ // baloo - timeline
+ QTest::newRow("Baloo - Last Month") << QUrl("timeline:/lastmonth") << QStringLiteral("view-calendar-month");
+
+ // devices
+ QTest::newRow("Devices - Floppy") << QUrl("file:///media/floppy0") << QStringLiteral("blockdevice");
+}
+
+void PlacesItemModelTest::testIcons()
+{
+ QFETCH(QUrl, url);
+ QFETCH(QString, expectedIconName);
+
+ PlacesItem *item = m_model->placesItem(indexOf(url));
+ QCOMPARE(item->icon(), expectedIconName);
+
+ for (int r = 0; r < m_model->count(); r++) {
+ QVERIFY(!m_model->placesItem(r)->icon().isEmpty());
+ }
+}
+
+void PlacesItemModelTest::testDragAndDrop()
+{
+ QList<QVariant> args;
+ KItemRangeList range;
+ QStringList urls = initialUrls();
+ QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted);
+ QSignalSpy itemsRemovedSpy(m_model, &PlacesItemModel::itemsRemoved);
+
+ CHECK_PLACES_URLS(initialUrls());
+ // Move the KDE_ROOT_PATH at the end of the places list will case it to be moved to the end of the places group
+ QMimeData *dropData = createMimeData(QList<int>() << 1);
+ m_model->dropMimeDataBefore(m_model->count() - 1, dropData);
+ urls.move(1, 2);
+ delete dropData;
+
+ QTRY_COMPARE(itemsInsertedSpy.count(), 1);
+ QTRY_COMPARE(itemsRemovedSpy.count(), 1);
+
+ // remove item from actual position
+ args = itemsRemovedSpy.takeFirst();
+ range = args.at(0).value<KItemRangeList>();
+ QCOMPARE(range.size(), 1);
+ QCOMPARE(range.at(0).count, 1);
+ QCOMPARE(range.at(0).index, 1);
+
+ // insert intem in his group
+ args = itemsInsertedSpy.takeFirst();
+ range = args.at(0).value<KItemRangeList>();
+ QCOMPARE(range.size(), 1);
+ QCOMPARE(range.at(0).count, 1);
+ QCOMPARE(range.at(0).index, 2);
+
+ CHECK_PLACES_URLS(urls);
+
+ itemsInsertedSpy.clear();
+ itemsRemovedSpy.clear();
+
+ // Move the KDE_ROOT_PATH to his original position
+ dropData = createMimeData(QList<int>() << 2);
+ m_model->dropMimeDataBefore(1, dropData);
+ urls.move(2, 1);
+ delete dropData;
+
+ QTRY_COMPARE(itemsInsertedSpy.count(), 1);
+ QTRY_COMPARE(itemsRemovedSpy.count(), 1);
+
+ // remove item from actual position
+ args = itemsRemovedSpy.takeFirst();
+ range = args.at(0).value<KItemRangeList>();
+ QCOMPARE(range.size(), 1);
+ QCOMPARE(range.at(0).count, 1);
+ QCOMPARE(range.at(0).index, 2);
+
+ // insert intem in the requested position
+ args = itemsInsertedSpy.takeFirst();
+ range = args.at(0).value<KItemRangeList>();
+ QCOMPARE(range.size(), 1);
+ QCOMPARE(range.at(0).count, 1);
+ QCOMPARE(range.at(0).index, 1);
+
+ CHECK_PLACES_URLS(urls);