QMediaNetworkPlaylistProvider: Upon error parsing, stop parsing.
authorAndres Gomez <agomez@igalia.com>
Wed, 30 Jul 2014 14:34:16 +0000 (17:34 +0300)
committerYoann Lopes <yoann.lopes@digia.com>
Tue, 9 Sep 2014 11:46:31 +0000 (13:46 +0200)
When an error is found parsing a playlist, stop
parsing. This will also prevent the emission of
the "loaded" signal when the parser finishes.

Task-number: QTBUG-40513
Change-Id: Ia814864d0d546806219993f0b727761d5d4e7903
Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
src/multimedia/playback/qmedianetworkplaylistprovider.cpp
tests/auto/unit/qmediaplaylist/testdata/test.pls [new file with mode: 0644]
tests/auto/unit/qmediaplaylist/testdata/totem-pl-example.pls [new file with mode: 0644]
tests/auto/unit/qmediaplaylist/testdata/trash.pls [new file with mode: 0644]
tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp

index a8d8c4b..9bbd7f3 100644 (file)
@@ -90,6 +90,8 @@ void QMediaNetworkPlaylistProviderPrivate::_q_handleParserError(QPlaylistFilePar
         break;
     }
 
+    parser.stop();
+
     emit q->loadFailed(playlistError, errorMessage);
 }
 
diff --git a/tests/auto/unit/qmediaplaylist/testdata/test.pls b/tests/auto/unit/qmediaplaylist/testdata/test.pls
new file mode 100644 (file)
index 0000000..1b66c3a
--- /dev/null
@@ -0,0 +1,10 @@
+[playlist]
+
+File1=http://test.host/path
+Title1=First
+Length1=-1
+File2= http://test.host/path
+Title2=Second
+Length2=-1
+
+NumberOfEntries=2
diff --git a/tests/auto/unit/qmediaplaylist/testdata/totem-pl-example.pls b/tests/auto/unit/qmediaplaylist/testdata/totem-pl-example.pls
new file mode 100644 (file)
index 0000000..385fe2a
--- /dev/null
@@ -0,0 +1,5 @@
+[playlist]
+X-GNOME-Title=totem-pl-file-example
+NumberOfEntries=1
+File1=http://test.host/path
+Title1=Silence
diff --git a/tests/auto/unit/qmediaplaylist/testdata/trash.pls b/tests/auto/unit/qmediaplaylist/testdata/trash.pls
new file mode 100644 (file)
index 0000000..639c22b
--- /dev/null
@@ -0,0 +1,2 @@
+[playlist]
+NumberOfEntries=100
index 7aa8d7a..63b84b5 100644 (file)
@@ -86,6 +86,7 @@ private slots:
     void currentItem();
     void saveAndLoad();
     void loadM3uFile();
+    void loadPLSFile();
     void playbackMode();
     void playbackMode_data();
     void shuffle();
@@ -356,8 +357,10 @@ void tst_QMediaPlaylist::saveAndLoad()
     QVERIFY(playlist.error() == QMediaPlaylist::FormatNotSupportedError);
     QVERIFY(!playlist.errorString().isEmpty());
 
+    QSignalSpy loadedSignal(&playlist, SIGNAL(loaded()));
     QSignalSpy errorSignal(&playlist, SIGNAL(loadFailed()));
     playlist.load(&buffer, "unsupported_format");
+    QTRY_VERIFY(loadedSignal.isEmpty());
     QCOMPARE(errorSignal.size(), 1);
     QVERIFY(playlist.error() != QMediaPlaylist::NoError);
     QVERIFY(!playlist.errorString().isEmpty());
@@ -367,8 +370,10 @@ void tst_QMediaPlaylist::saveAndLoad()
     QVERIFY(playlist.error() != QMediaPlaylist::NoError);
     QVERIFY(!playlist.errorString().isEmpty());
 
+    loadedSignal.clear();
     errorSignal.clear();
     playlist.load(QUrl::fromLocalFile(QLatin1String("tmp.unsupported_format")), "unsupported_format");
+    QTRY_VERIFY(loadedSignal.isEmpty());
     QCOMPARE(errorSignal.size(), 1);
     QVERIFY(playlist.error() == QMediaPlaylist::FormatNotSupportedError);
     QVERIFY(!playlist.errorString().isEmpty());
@@ -380,7 +385,11 @@ void tst_QMediaPlaylist::saveAndLoad()
     buffer.seek(0);
 
     QMediaPlaylist playlist2;
+    QSignalSpy loadedSignal2(&playlist2, SIGNAL(loaded()));
+    QSignalSpy errorSignal2(&playlist2, SIGNAL(loadFailed()));
     playlist2.load(&buffer, "m3u");
+    QCOMPARE(loadedSignal2.size(), 1);
+    QTRY_VERIFY(errorSignal2.isEmpty());
     QCOMPARE(playlist.error(), QMediaPlaylist::NoError);
 
     QCOMPARE(playlist.mediaCount(), playlist2.mediaCount());
@@ -390,9 +399,13 @@ void tst_QMediaPlaylist::saveAndLoad()
     res = playlist.save(QUrl::fromLocalFile(QLatin1String("tmp.m3u")), "m3u");
     QVERIFY(res);
 
+    loadedSignal2.clear();
+    errorSignal2.clear();
     playlist2.clear();
     QVERIFY(playlist2.isEmpty());
     playlist2.load(QUrl::fromLocalFile(QLatin1String("tmp.m3u")), "m3u");
+    QCOMPARE(loadedSignal2.size(), 1);
+    QTRY_VERIFY(errorSignal2.isEmpty());
     QCOMPARE(playlist.error(), QMediaPlaylist::NoError);
 
     QCOMPARE(playlist.mediaCount(), playlist2.mediaCount());
@@ -406,12 +419,20 @@ void tst_QMediaPlaylist::loadM3uFile()
     QMediaPlaylist playlist;
 
     // Try to load playlist that does not exist in the testdata folder
+    QSignalSpy loadSpy(&playlist, SIGNAL(loaded()));
+    QSignalSpy loadFailedSpy(&playlist, SIGNAL(loadFailed()));
     QString testFileName = QFINDTESTDATA("testdata");
     playlist.load(QUrl::fromLocalFile(testFileName + "/missing_file.m3u"));
+    QTRY_VERIFY(loadSpy.isEmpty());
+    QVERIFY(!loadFailedSpy.isEmpty());
     QVERIFY(playlist.error() != QMediaPlaylist::NoError);
 
+    loadSpy.clear();
+    loadFailedSpy.clear();
     testFileName = QFINDTESTDATA("testdata/test.m3u");
     playlist.load(QUrl::fromLocalFile(testFileName));
+    QTRY_VERIFY(!loadSpy.isEmpty());
+    QVERIFY(loadFailedSpy.isEmpty());
     QCOMPARE(playlist.error(), QMediaPlaylist::NoError);
     QCOMPARE(playlist.mediaCount(), 7);
 
@@ -428,10 +449,62 @@ void tst_QMediaPlaylist::loadM3uFile()
     //ensure #2 suffix is not stripped from path
     testFileName = QFINDTESTDATA("testdata/testfile2#suffix");
     QCOMPARE(playlist.media(6).canonicalUrl(), QUrl::fromLocalFile(testFileName));
+
     // check ability to load from QNetworkRequest
+    loadSpy.clear();
+    loadFailedSpy.clear();
+    playlist.load(QNetworkRequest(QUrl::fromLocalFile(QFINDTESTDATA("testdata/test.m3u"))));
+    QTRY_VERIFY(!loadSpy.isEmpty());
+    QVERIFY(loadFailedSpy.isEmpty());
+}
+
+void tst_QMediaPlaylist::loadPLSFile()
+{
+    QMediaPlaylist playlist;
+
+    // Try to load playlist that does not exist in the testdata folder
     QSignalSpy loadSpy(&playlist, SIGNAL(loaded()));
     QSignalSpy loadFailedSpy(&playlist, SIGNAL(loadFailed()));
-    playlist.load(QNetworkRequest(QUrl::fromLocalFile(QFINDTESTDATA("testdata/test.m3u"))));
+    QString testFileName = QFINDTESTDATA("testdata");
+    playlist.load(QUrl::fromLocalFile(testFileName + "/missing_file.pls"));
+    QTRY_VERIFY(loadSpy.isEmpty());
+    QVERIFY(!loadFailedSpy.isEmpty());
+    QVERIFY(playlist.error() != QMediaPlaylist::NoError);
+
+    // Try to load bogus playlist
+    loadSpy.clear();
+    loadFailedSpy.clear();
+    testFileName = QFINDTESTDATA("testdata/trash.pls");
+    playlist.load(QUrl::fromLocalFile(testFileName));
+    QTRY_VERIFY(loadSpy.isEmpty());
+    QVERIFY(!loadFailedSpy.isEmpty());
+    QVERIFY(playlist.error() == QMediaPlaylist::FormatError);
+
+    // Try to load regular playlist
+    loadSpy.clear();
+    loadFailedSpy.clear();
+    testFileName = QFINDTESTDATA("testdata/test.pls");
+    playlist.load(QUrl::fromLocalFile(testFileName));
+    QTRY_VERIFY(!loadSpy.isEmpty());
+    QVERIFY(loadFailedSpy.isEmpty());
+    QCOMPARE(playlist.error(), QMediaPlaylist::NoError);
+    QCOMPARE(playlist.mediaCount(), 2);
+    QCOMPARE(playlist.media(0).canonicalUrl(), QUrl(QLatin1String("http://test.host/path")));
+    QCOMPARE(playlist.media(1).canonicalUrl(), QUrl(QLatin1String("http://test.host/path")));
+
+    // Try to load a totem-pl generated playlist
+    loadSpy.clear();
+    loadFailedSpy.clear();
+    testFileName = QFINDTESTDATA("testdata/totem-pl-example.pls");
+    playlist.load(QUrl::fromLocalFile(testFileName));
+    QTRY_VERIFY(loadSpy.isEmpty());
+    QVERIFY(!loadFailedSpy.isEmpty());
+    QVERIFY(playlist.error() == QMediaPlaylist::FormatError);
+
+    // check ability to load from QNetworkRequest
+    loadSpy.clear();
+    loadFailedSpy.clear();
+    playlist.load(QNetworkRequest(QUrl::fromLocalFile(QFINDTESTDATA("testdata/test.pls"))));
     QTRY_VERIFY(!loadSpy.isEmpty());
     QVERIFY(loadFailedSpy.isEmpty());
 }