videocollection/videofiledetailsview/tsrc/testplugin/src/testvideofiledetails.cpp
changeset 34 bbb98528c666
parent 30 4f111d64a341
child 35 3738fe97f027
equal deleted inserted replaced
33:48e74db5d516 34:bbb98528c666
    20 
    20 
    21 #include <QtTest/QtTest>
    21 #include <QtTest/QtTest>
    22 #include <qdebug.h>
    22 #include <qdebug.h>
    23 #include <hbinstance.h>
    23 #include <hbinstance.h>
    24 #include <hbwidget.h>
    24 #include <hbwidget.h>
       
    25 #include <hblistwidget.h>
       
    26 #include <hblistwidgetitem.h>
    25 #include <hbpushbutton.h>
    27 #include <hbpushbutton.h>
    26 #include <hblabel.h>
    28 #include <hblabel.h>
    27 #include <hbaction.h>
    29 #include <hbaction.h>
    28 #include <hbapplication.h>
    30 #include <hbapplication.h>
    29 #include <hbscrollarea.h>
       
    30 #include <hbmarqueeitem.h>
    31 #include <hbmarqueeitem.h>
    31 
    32 #include <hbstackedwidget.h>
       
    33 
       
    34 #include "videodetailslabel.h"
    32 #include "hbmessagebox.h"
    35 #include "hbmessagebox.h"
    33 #include "thumbnailmanager_qt.h"
    36 #include "thumbnailmanager_qt.h"
    34 #include "videocollectioncommon.h"
    37 #include "videocollectioncommon.h"
    35 #include "mpxhbvideocommondefs.h"
    38 #include "mpxhbvideocommondefs.h"
    36 #include "videocollectionwrapper.h"
    39 #include "videocollectionwrapper.h"
    42 #include "videofiledetailsviewplugin.h"
    45 #include "videofiledetailsviewplugin.h"
    43 #undef private
    46 #undef private
    44 
    47 
    45 const char *TEST_VIDEO_DETAILS_VIEW = "videofiledetailsview";
    48 const char *TEST_VIDEO_DETAILS_VIEW = "videofiledetailsview";
    46 const char *TEST_VIDEO_DETAILS_WIDGET = "mContent";
    49 const char *TEST_VIDEO_DETAILS_WIDGET = "mContent";
    47 
       
    48 const char *TEST_VIDEO_DETAILS_TITLE = "mLblTitle";
    50 const char *TEST_VIDEO_DETAILS_TITLE = "mLblTitle";
    49 const char *TEST_VIDEO_DETAILS_ITEM = "mLblDetail";
    51 const char *TEST_VIDEO_DETAILS_LISTWIDGET ="mDetailsList";
    50 const char *TEST_VIDEO_DETAILS_BUTTON_PLAY = "mBtnPlay";
    52 const char* const VIDEO_DETAILS_THUMBNAIL = "mDetailsLabel";
    51 const char* const VIDEO_DETAILS_BUTTON_ATTACH = "mBtnAttach";
    53 const char* const VIDEO_DETAILS_BUTTON = "mButton";
    52 const char *TEST_VIDEO_DETAILS_MENUACTION_SHARE = "mOptionsShare";
       
    53 const char *TEST_VIDEO_DETAILS_MENUACTION_DELETE = "mOptionsDelete";
    54 const char *TEST_VIDEO_DETAILS_MENUACTION_DELETE = "mOptionsDelete";
    54 
    55 
    55 const char *TEST_VIDEO_DETAILS_SCROLLAREA = "mDetailScrollArea";
       
    56 
       
    57 // ---------------------------------------------------------------------------
    56 // ---------------------------------------------------------------------------
    58 // initTestCase
    57 // initTestCase
    59 // ---------------------------------------------------------------------------
    58 // ---------------------------------------------------------------------------
    60 //
    59 //
    61 void TestVideoFileDetails::initTestCase()
    60 void TestVideoFileDetails::initTestCase()
    62 {
    61 {
    63    mWrapper = VideoCollectionWrapper::instance();
       
    64    mDummyModel = 0;
    62    mDummyModel = 0;
    65    mDummyModel = new VideoSortFilterProxyModel();
    63    mDummyModel = new VideoSortFilterProxyModel();
    66    
    64    
    67    connect(this, SIGNAL(shortDetailsReady(int)), mDummyModel, SIGNAL(shortDetailsReady(int)));
    65    connect(this, SIGNAL(shortDetailsReady(TMPXItemId)), mDummyModel, SIGNAL(shortDetailsReady(TMPXItemId)));
    68    connect(this, SIGNAL(fullDetailsReady(int)), mDummyModel, SIGNAL(fullDetailsReady(int)));
    66    connect(this, SIGNAL(fullDetailsReady(TMPXItemId)), mDummyModel, SIGNAL(fullDetailsReady(TMPXItemId)));
    69 
    67 
    70    connect(this, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), 
    68    connect(this, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), 
    71            mDummyModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)));
    69            mDummyModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)));
    72    
    70    
    73    connect(this, SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
    71    connect(this, SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
    74            mDummyModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int)));
    72            mDummyModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int)));
    75    
    73    
    76    mWrapper->setModel(mDummyModel);
    74    VideoCollectionWrapper::instance().setModel(mDummyModel);
    77 }
    75 }
    78 
    76 
    79 // ---------------------------------------------------------------------------
    77 // ---------------------------------------------------------------------------
    80 // cleanupTestCase
    78 // cleanupTestCase
    81 // ---------------------------------------------------------------------------
    79 // ---------------------------------------------------------------------------
    88             mDummyModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)));
    86             mDummyModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)));
    89     disconnect(this, SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
    87     disconnect(this, SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
    90             mDummyModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int)));
    88             mDummyModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int)));
    91     delete mDummyModel; mDummyModel = 0;
    89     delete mDummyModel; mDummyModel = 0;
    92     delete mPlugin; mPlugin = 0;
    90     delete mPlugin; mPlugin = 0;
    93     mWrapper->decreaseReferenceCount();
       
    94     QCOMPARE(mWrapper->mReferenceCount, 0);
       
    95 }
    91 }
    96 
    92 
    97 // ---------------------------------------------------------------------------
    93 // ---------------------------------------------------------------------------
    98 // init before every test function
    94 // init before every test function
    99 // ---------------------------------------------------------------------------
    95 // ---------------------------------------------------------------------------
   138 
   134 
   139 // ---------------------------------------------------------------------------
   135 // ---------------------------------------------------------------------------
   140 // Helper function that populates a qmap with dummy data.
   136 // Helper function that populates a qmap with dummy data.
   141 // ---------------------------------------------------------------------------
   137 // ---------------------------------------------------------------------------
   142 //
   138 //
   143 QMap<QString, QVariant> TestVideoFileDetails::createDummyMetadata(int ratingStartCount)
   139 QMap<QString, QVariant> TestVideoFileDetails::createDummyMetadata()
   144 {
   140 {
   145     using namespace VideoCollectionCommon;
   141     using namespace VideoCollectionCommon;
   146     
   142     
   147     QMap<QString, QVariant> map;
   143     QMap<QString, QVariant> map;
   148     
   144     
   158         {
   154         {
   159             txt.append(QString("test test test test test test test test test test test test test test test test test test test"));
   155             txt.append(QString("test test test test test test test test test test test test test test test test test test test"));
   160             map[VideoDetailLabelKeys[i]] = txt;
   156             map[VideoDetailLabelKeys[i]] = txt;
   161         }
   157         }
   162     }
   158     }
   163     if(ratingStartCount > -1)
       
   164     {
       
   165         map[MetaKeyStarRating] = ratingStartCount;
       
   166     }
       
   167     return map;
   159     return map;
   168 }
   160 }
   169 
   161 
   170 // ---------------------------------------------------------------------------
   162 // ---------------------------------------------------------------------------
   171 // One round for the activate view test
   163 // One round for the activate view test
   173 //
   165 //
   174 inline void TestVideoFileDetails::activateViewTestRound()
   166 inline void TestVideoFileDetails::activateViewTestRound()
   175     {
   167     {
   176     init();
   168     init();
   177     
   169     
   178     HbScrollArea* area = findWidget<HbScrollArea>(TEST_VIDEO_DETAILS_SCROLLAREA);
       
   179     
       
   180     // won't scroll without these
       
   181     area->contentWidget()->adjustSize();
       
   182     area->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAutoHide);
       
   183     
       
   184     area->scrollContentsTo(QPointF(0, 200));
       
   185     
       
   186     QSignalSpy spy(area, SIGNAL(scrollPositionChanged(const QPointF)));
       
   187     
       
   188     activateView();
   170     activateView();
   189     
   171     
   190     QVERIFY( mPlugin->getView() != 0 );
   172     QVERIFY( mPlugin->getView() != 0 );
   191     QVERIFY( mPlugin->viewPlugin() == mPlugin );
   173     QVERIFY( mPlugin->viewPlugin() == mPlugin );
   192     QCOMPARE( mPlugin->mVideoIndex, -1 );
   174     QCOMPARE( mPlugin->mVideoId, TMPXItemId::InvalidId() );
   193     
       
   194     verifyOrientation();
       
   195     
   175     
   196     // verify that actions are currently disabled.
   176     // verify that actions are currently disabled.
   197     HbPushButton* playBtn = findWidget<HbPushButton>(TEST_VIDEO_DETAILS_BUTTON_PLAY);
   177     HbStackedWidget* thumbWidget = findWidget<HbStackedWidget>(VIDEO_DETAILS_THUMBNAIL);
   198     HbAction* shareAction = findObject<HbAction>(TEST_VIDEO_DETAILS_MENUACTION_SHARE);
   178     VideoDetailsLabel* thumbLabel = (VideoDetailsLabel*)thumbWidget->widgetAt(0);
   199     HbAction* deleteAction = findObject<HbAction>(TEST_VIDEO_DETAILS_MENUACTION_DELETE);
   179     HbAction* deleteAction = findObject<HbAction>(TEST_VIDEO_DETAILS_MENUACTION_DELETE);
   200     
   180     
   201     QVERIFY( playBtn != 0 );
   181     HbPushButton* button = findWidget<HbPushButton>(VIDEO_DETAILS_BUTTON);
   202     QVERIFY( shareAction != 0 );
   182     
       
   183     QVERIFY( button != 0 );
       
   184     QVERIFY( thumbLabel != 0 );
   203     QVERIFY( deleteAction != 0 );
   185     QVERIFY( deleteAction != 0 );
   204     QVERIFY( playBtn->isEnabled() );
       
   205     QVERIFY( shareAction->isEnabled() );
       
   206     QVERIFY( deleteAction->isEnabled() );
   186     QVERIFY( deleteAction->isEnabled() );
   207     
       
   208     // verify that the scroll area has been scrolled to the top.
       
   209     QCOMPARE( spy.count(), 1 );
       
   210     QPointF scrollPoint = spy.takeFirst().at(0).toPointF();
       
   211     QCOMPARE( scrollPoint, QPointF(0, 0) );
       
   212     
   187     
   213     QVERIFY(mPlugin->mActivated);    
   188     QVERIFY(mPlugin->mActivated);    
   214      // second activation should not affect
   189      // second activation should not affect
   215     activateView();
   190     activateView();
   216     QVERIFY(mPlugin->mActivated);
   191     QVERIFY(mPlugin->mActivated);
   217     QVERIFY( playBtn != 0 );
   192     QVERIFY( button != 0 );
   218     QVERIFY( shareAction != 0 );
   193     QVERIFY( thumbLabel != 0 );
   219     QVERIFY( deleteAction != 0 );
   194     QVERIFY( deleteAction != 0 );
   220     QVERIFY( playBtn->isEnabled() );
       
   221     QVERIFY( shareAction->isEnabled() );
       
   222     QVERIFY( deleteAction->isEnabled() );
   195     QVERIFY( deleteAction->isEnabled() );
   223         
       
   224     
   196     
   225     cleanup();
   197     cleanup();
   226     }
   198     }
   227 
       
   228 // ---------------------------------------------------------------------------
       
   229 // Verifies that correct orientation is loaded from xml
       
   230 // ---------------------------------------------------------------------------
       
   231 //
       
   232 inline void TestVideoFileDetails::verifyOrientation()
       
   233 {
       
   234     HbWidget* info = findWidget<HbWidget>(TEST_VIDEO_DETAILS_SCROLLAREA);
       
   235     
       
   236     // this verifies that we have correct orientation loaded from the xml.
       
   237     if (hbInstance->allMainWindows().at(0)->orientation() == Qt::Vertical)
       
   238     {
       
   239         QVERIFY( info->pos().x() < 300 );
       
   240         QVERIFY( info->pos().x() > 0 );
       
   241     } else {
       
   242         QVERIFY( info->pos().x() > 300 );
       
   243         QVERIFY( info->pos().x() < 640 );
       
   244     }
       
   245 }
       
   246 
   199 
   247 // ---------------------------------------------------------------------------
   200 // ---------------------------------------------------------------------------
   248 // Slot: create view
   201 // Slot: create view
   249 // ---------------------------------------------------------------------------
   202 // ---------------------------------------------------------------------------
   250 //
   203 //
   265     QVERIFY( mPlugin->mModel == mDummyModel );
   218     QVERIFY( mPlugin->mModel == mDummyModel );
   266     QVERIFY( mPlugin->mIsService == false);
   219     QVERIFY( mPlugin->mIsService == false);
   267     QVERIFY( mPlugin->mVideoServices == 0);
   220     QVERIFY( mPlugin->mVideoServices == 0);
   268     // testing the special case where the model is null.
   221     // testing the special case where the model is null.
   269     cleanup();
   222     cleanup();
   270     mWrapper->setModel(0);
   223     VideoCollectionWrapper::instance().setModel(0);
   271     init();
   224     init();
   272     QVERIFY( mPlugin->mModel == 0 );
   225     QVERIFY( mPlugin->mModel == 0 );
   273     QVERIFY( mPlugin->mIsService == false);
   226     QVERIFY( mPlugin->mIsService == false);
   274     QVERIFY( mPlugin->mVideoServices == 0);
   227     QVERIFY( mPlugin->mVideoServices == 0);
   275     // TODO if the plugin is changed to throw exception in case of null model,
   228     // TODO if the plugin is changed to throw exception in case of null model,
   276     //      then it needs to be added here.
   229     //      then it needs to be added here.
   277     
   230     
   278     // restoring the proper model.
   231     // restoring the proper model.
   279     mWrapper->setModel(mDummyModel);
   232     VideoCollectionWrapper::instance().setModel(mDummyModel);
   280     cleanup();
   233     cleanup();
   281 }
   234 }
   282 
   235 
   283 // ---------------------------------------------------------------------------
   236 // ---------------------------------------------------------------------------
   284 // Slot: destroy view
   237 // Slot: destroy view
   325 {
   278 {
   326     init();
   279     init();
   327     activateView();
   280     activateView();
   328     mPlugin->deactivateView();
   281     mPlugin->deactivateView();
   329     QVERIFY( mPlugin->mActivated == false );
   282     QVERIFY( mPlugin->mActivated == false );
   330     QCOMPARE( mPlugin->mVideoIndex, -1 );
   283     QCOMPARE( mPlugin->mVideoId, TMPXItemId::InvalidId() );
   331     mPlugin->deactivateView();
   284     mPlugin->deactivateView();
   332     QVERIFY( mPlugin->mActivated == false );
   285     QVERIFY( mPlugin->mActivated == false );
   333     QCOMPARE( mPlugin->mVideoIndex, -1 );
   286     QCOMPARE( mPlugin->mVideoId, TMPXItemId::InvalidId() );
   334     cleanup();
   287     cleanup();
   335 }
   288 }
   336 
   289 
   337 // ---------------------------------------------------------------------------
   290 // ---------------------------------------------------------------------------
   338 // Slot: data for orientation change test
   291 // Slot: data for orientation change test
   369     // without this the view doesn't have the correct geometry.
   322     // without this the view doesn't have the correct geometry.
   370     mPlugin->getView()->setGeometry(hbInstance->allMainWindows().at(0)->rect());
   323     mPlugin->getView()->setGeometry(hbInstance->allMainWindows().at(0)->rect());
   371     // give fw some time to update content
   324     // give fw some time to update content
   372     QTest::qWait(100);
   325     QTest::qWait(100);
   373     
   326     
   374     verifyOrientation();
       
   375     
       
   376     cleanup();
   327     cleanup();
   377 }
   328 }
   378 
   329 
   379 // ---------------------------------------------------------------------------
   330 // ---------------------------------------------------------------------------
   380 // Slot: test for the back slot
   331 // Slot: test for the back slot
   429 // Slot: test for the shortDetailsReadySlot
   380 // Slot: test for the shortDetailsReadySlot
   430 // ---------------------------------------------------------------------------
   381 // ---------------------------------------------------------------------------
   431 //
   382 //
   432 void TestVideoFileDetails::testShortDetailsReadySlot()
   383 void TestVideoFileDetails::testShortDetailsReadySlot()
   433 {
   384 {
   434     const int testIndex = 5;
   385     TMPXItemId testIndex(5,0);
   435     QStringList display;
   386     QStringList display;
   436     display.append("first row");
   387     display.append("first row");
   437     display.append("second row");
   388     display.append("second row");
   438     QString filepath("filepath");
   389     QString filepath("filepath");
   439     
   390     
   443     activateView();
   394     activateView();
   444     
   395     
   445      // no data 
   396      // no data 
   446     emit shortDetailsReady(testIndex);
   397     emit shortDetailsReady(testIndex);
   447     
   398     
   448     QCOMPARE( mPlugin->mVideoIndex, testIndex );
   399     QCOMPARE( mPlugin->mVideoId, testIndex );
   449     QVERIFY( mPlugin->mTitleAnim->text().isEmpty() );
   400     QVERIFY( mPlugin->mTitleAnim->text().isEmpty() );
   450     QCOMPARE( mPlugin->mThumbnailManager->mRequests.count(), 0 );
   401     QCOMPARE( mPlugin->mThumbnailManager->mRequests.count(), 0 );
   451     QVERIFY( findWidget<HbPushButton>(TEST_VIDEO_DETAILS_BUTTON_PLAY)->primitive(HbStyle::P_PushButton_background)->isVisible() == false );
       
   452     
   402     
   453     mDummyModel->setData(Qt::DisplayRole, display);
   403     mDummyModel->setData(Qt::DisplayRole, display);
   454     mDummyModel->setData(VideoCollectionCommon::KeyFilePath, filepath);
   404     mDummyModel->setData(VideoCollectionCommon::KeyFilePath, filepath);
   455     
   405     
   456     // no tn manager
   406     // no tn manager
   457     ThumbnailManager *tmpTnManager = mPlugin->mThumbnailManager;
   407     ThumbnailManager *tmpTnManager = mPlugin->mThumbnailManager;
   458     mPlugin->mThumbnailManager = 0;
   408     mPlugin->mThumbnailManager = 0;
   459     emit shortDetailsReady(testIndex);
   409     emit shortDetailsReady(testIndex);
   460     QCOMPARE( mPlugin->mVideoIndex, testIndex );
   410     QCOMPARE( mPlugin->mVideoId, testIndex );
   461     QCOMPARE( mPlugin->mTitleAnim->text(), display.at(0) );
   411     QCOMPARE( mPlugin->mTitleAnim->text(), display.at(0) );
   462     QVERIFY( findWidget<HbPushButton>(TEST_VIDEO_DETAILS_BUTTON_PLAY)->primitive(HbStyle::P_PushButton_background)->isVisible() == false );    
       
   463     mPlugin->mThumbnailManager = tmpTnManager;
   412     mPlugin->mThumbnailManager = tmpTnManager;
   464 
   413 
   465     // data exists
   414     // data exists
   466     emit shortDetailsReady(testIndex);
   415     emit shortDetailsReady(testIndex);
   467     
   416     
   468     QCOMPARE( mDummyModel->lastIndex().row(), testIndex );
   417     QCOMPARE( mPlugin->mVideoId, testIndex );
       
   418     QCOMPARE( mDummyModel->lastId(), testIndex );
   469     QCOMPARE( mPlugin->mTitleAnim->text(), display.at(0) );
   419     QCOMPARE( mPlugin->mTitleAnim->text(), display.at(0) );
   470     QVERIFY( ThumbnailManager::mRequests.contains(0) );
   420     QVERIFY( ThumbnailManager::mRequests.contains(0) );
   471     ThumbnailManager::TnRequest request = ThumbnailManager::mRequests[0];
   421     ThumbnailManager::TnRequest request = ThumbnailManager::mRequests[0];
   472     QCOMPARE( request.name, filepath );
   422     QCOMPARE( request.name, filepath );
   473     // 20 == priorityHight in this case
   423     // 20 == priorityHight in this case
   474     QCOMPARE( request.priority, 5000 );
   424     QCOMPARE( request.priority, 5000 );
   475     QVERIFY( findWidget<HbPushButton>(TEST_VIDEO_DETAILS_BUTTON_PLAY)->primitive(HbStyle::P_PushButton_background)->isVisible() == false );
       
   476 
   425 
   477     
   426     
   478     mDummyModel->setData(VideoCollectionCommon::KeyMetaData, createDummyMetadata() );
   427     mDummyModel->setData(VideoCollectionCommon::KeyMetaData, createDummyMetadata() );
   479     emit fullDetailsReady(testIndex);
   428     emit fullDetailsReady(testIndex);
   480              
   429              
   481     emit shortDetailsReady(testIndex);
   430     emit shortDetailsReady(testIndex);
   482     QVERIFY( findWidget<HbPushButton>(TEST_VIDEO_DETAILS_BUTTON_PLAY)->primitive(HbStyle::P_PushButton_background)->isVisible() == false );
       
   483     
   431     
   484    int detailCount = sizeof(VideoCollectionCommon::VideoDetailLabelKeys) / sizeof(int);
   432    int detailCount = sizeof(VideoCollectionCommon::VideoDetailLabelKeys) / sizeof(int);
   485     for(int i = 1; i<=detailCount; i++) {
   433 
   486         HbLabel* detail = findWidget<HbLabel>(TEST_VIDEO_DETAILS_ITEM + QString::number(i));
   434    HbListWidget* list = findWidget<HbListWidget>(TEST_VIDEO_DETAILS_LISTWIDGET);
   487         QVERIFY( detail->text().isEmpty() );
       
   488     }
       
   489    
   435    
   490     QVERIFY( findWidget<HbPushButton>(TEST_VIDEO_DETAILS_BUTTON_PLAY)->icon().isNull() );
   436    QVERIFY(list);
   491             
   437    QVERIFY(list->count() == 0);
   492     cleanup();
   438 
       
   439    cleanup();
   493 }
   440 }
   494 
   441 
   495 // ---------------------------------------------------------------------------
   442 // ---------------------------------------------------------------------------
   496 // Slot: test for the fullDetailsReadySlot
   443 // Slot: test for the fullDetailsReadySlot
   497 // ---------------------------------------------------------------------------
   444 // ---------------------------------------------------------------------------
   498 //
   445 //
   499 void TestVideoFileDetails::testFullDetailsReadySlot()
   446 void TestVideoFileDetails::testFullDetailsReadySlot()
   500 {
   447 {
   501     const int testIndex = 6;
   448     TMPXItemId testIndex(6,0);
   502     init();
   449     init();
   503     activateView();
   450     activateView();
   504     
   451     
   505     int detailCount = sizeof(VideoCollectionCommon::VideoDetailLabelKeys) / sizeof(int);
   452     int detailCount = sizeof(VideoCollectionCommon::VideoDetailLabelKeys) / sizeof(int);
   506     for(int i = 1; i<=detailCount; i++) {
   453 
   507         HbLabel* detail = findWidget<HbLabel>(TEST_VIDEO_DETAILS_ITEM + QString::number(i));
   454     HbListWidget* list = findWidget<HbListWidget>(TEST_VIDEO_DETAILS_LISTWIDGET);
   508         if(detail == 0)
   455     QVERIFY(list);
   509         {
   456     QVERIFY(list->count() == 0);
   510             QFAIL(QString("Found a null label at %1, check that the xml is "
       
   511                 "correct, and that the resource files have been regenerated (by running abld "
       
   512                 "reallyclean before build)").arg(TEST_VIDEO_DETAILS_ITEM + QString::number(i)).
       
   513                 toStdString().data());
       
   514         }
       
   515     }
       
   516     
   457     
   517     mDummyModel->setData(VideoCollectionCommon::KeyMetaData, createDummyMetadata() );
   458     mDummyModel->setData(VideoCollectionCommon::KeyMetaData, createDummyMetadata() );
   518        
   459        
   519     emit fullDetailsReady(testIndex);
   460     emit fullDetailsReady(testIndex);
   520     
   461     
   521     // verify that actions are currently enabled.
   462     // verify that actions are currently enabled.
   522     HbPushButton* playBtn = findWidget<HbPushButton>(TEST_VIDEO_DETAILS_BUTTON_PLAY);
   463     HbStackedWidget* thumbWidget = findWidget<HbStackedWidget>(VIDEO_DETAILS_THUMBNAIL);
   523     HbAction* shareAction = findObject<HbAction>(TEST_VIDEO_DETAILS_MENUACTION_SHARE);
   464     VideoDetailsLabel* thumbLabel = (VideoDetailsLabel*)thumbWidget->widgetAt(0);
   524     HbAction* deleteAction = findObject<HbAction>(TEST_VIDEO_DETAILS_MENUACTION_DELETE);
   465     HbAction* deleteAction = findObject<HbAction>(TEST_VIDEO_DETAILS_MENUACTION_DELETE);
   525     
   466     
   526     QVERIFY( playBtn != 0 );
   467     QVERIFY( thumbLabel != 0 );
   527     QVERIFY( shareAction != 0 );
       
   528     QVERIFY( deleteAction != 0 );
   468     QVERIFY( deleteAction != 0 );
   529     QVERIFY( playBtn->isEnabled() );
       
   530     QVERIFY( shareAction->isEnabled() );
       
   531     QVERIFY( deleteAction->isEnabled() );
   469     QVERIFY( deleteAction->isEnabled() );
   532     
   470     
   533     for(int i = 0; i<detailCount; i++) {        
   471     QVERIFY(list->count() == detailCount);
       
   472 
       
   473     for(int i = 0; i<detailCount; i++) 
       
   474     {        
   534         QString expected = tr(VideoCollectionCommon::VideoDetailLabels[i]).arg(
   475         QString expected = tr(VideoCollectionCommon::VideoDetailLabels[i]).arg(
   535                 VideoCollectionCommon::VideoDetailLabelKeys[i]);
   476                 VideoCollectionCommon::VideoDetailLabelKeys[i]);
   536         HbLabel* detail = findWidget<HbLabel>(TEST_VIDEO_DETAILS_ITEM + QString::number(i+1));
   477         HbListWidgetItem* detail = list->item(i);
   537         QVERIFY( detail != 0 );
   478         QVERIFY( detail != 0 );
   538         QVERIFY( detail->text().contains(expected) );
   479         QVERIFY( detail->text().contains(expected) );
   539     }
   480     }
   540     
   481     
   541     // for coverity sake, retest without star-rating
   482     // for coverity sake, retest without star-rating
   542     mDummyModel->reset();
   483     mDummyModel->reset();
   543     mDummyModel->setData(VideoCollectionCommon::KeyMetaData, createDummyMetadata(1) );
   484     mDummyModel->setData(VideoCollectionCommon::KeyMetaData, createDummyMetadata() );
   544     emit fullDetailsReady(testIndex);
   485     emit fullDetailsReady(testIndex);
       
   486 
       
   487     int ii = 0;
   545     for(int i = 0; i<detailCount; i++) 
   488     for(int i = 0; i<detailCount; i++) 
   546     {   
   489     {        
   547         if(VideoCollectionCommon::VideoDetailLabelKeys[i] != VideoCollectionCommon::MetaKeyStarRating)
   490         if(VideoCollectionCommon::VideoDetailLabelKeys[i] != VideoCollectionCommon::MetaKeyStarRating)
   548         {
   491         {
   549             QString expected = tr(VideoCollectionCommon::VideoDetailLabels[i]).arg(
   492             QString expected = tr(VideoCollectionCommon::VideoDetailLabels[i]).arg(
   550                     VideoCollectionCommon::VideoDetailLabelKeys[i]);
   493                     VideoCollectionCommon::VideoDetailLabelKeys[i]);
   551             HbLabel* detail = findWidget<HbLabel>(TEST_VIDEO_DETAILS_ITEM + QString::number(i+1));
   494             HbListWidgetItem* detail = list->item(ii);
   552             QVERIFY( detail != 0 );
   495             QVERIFY( detail != 0 );
   553             QVERIFY( detail->text().contains(expected) );
   496             QVERIFY( detail->text().contains(expected) );
   554         }
   497         }
       
   498         ++ii;
   555     }
   499     }
   556     
   500 
   557     cleanup();
   501     cleanup();
   558 }
   502 }
   559 
   503 
   560 // ---------------------------------------------------------------------------
   504 // ---------------------------------------------------------------------------
   561 // Slot: test for the testStartPlaybackSlot
   505 // Slot: test for the testStartPlaybackSlot
   562 // ---------------------------------------------------------------------------
   506 // ---------------------------------------------------------------------------
   563 //
   507 //
   564 void TestVideoFileDetails::testStartPlaybackSlot()
   508 void TestVideoFileDetails::testStartPlaybackSlot()
   565 {
   509 {
   566     const int testIndex = 6;
   510     TMPXItemId testIndex(6,0);
   567     mDummyModel->reset();
   511     mDummyModel->reset();
   568     init();
   512     init();
   569     activateView();
   513     activateView();
   570     
   514     
   571     // Note that if the details view has not received signal in it's 
   515     // Note that if the details view has not received signal in it's 
   572     // fullDetailsReadySlot, the button is disabled and should not do anything.
   516     // fullDetailsReadySlot, the button is disabled and should not do anything.
   573     
   517     
   574     HbPushButton* playBtn = findWidget<HbPushButton>(TEST_VIDEO_DETAILS_BUTTON_PLAY);
   518     HbStackedWidget* thumbWidget = findWidget<HbStackedWidget>(VIDEO_DETAILS_THUMBNAIL);
   575     QVERIFY( playBtn != 0 );
   519     VideoDetailsLabel* thumbLabel = (VideoDetailsLabel*)thumbWidget->widgetAt(0);
   576     playBtn->click();
   520     QVERIFY( thumbLabel != 0 );
   577     
   521     thumbLabel->click();
   578     QCOMPARE( mDummyModel->startPlaybackIndex(), -1 );
   522     
       
   523     QCOMPARE( mDummyModel->startPlaybackIndex(), TMPXItemId::InvalidId() );
   579     
   524     
   580     emit fullDetailsReady(testIndex);
   525     emit fullDetailsReady(testIndex);
   581     mPlugin->mVideoIndex = testIndex;
   526     mPlugin->mVideoId = testIndex;
   582     
   527     
   583     playBtn->click();
   528     thumbLabel->click();
   584     
   529     
   585     QCOMPARE( mDummyModel->startPlaybackIndex(), testIndex );
   530     QCOMPARE( mDummyModel->startPlaybackIndex(), testIndex );
   586     
   531     
   587     // invalid index
   532     // invalid index
   588     mPlugin->mVideoIndex = -1;
   533     mPlugin->mVideoId = TMPXItemId::InvalidId();
   589     playBtn->click();
   534     thumbLabel->click();
   590     // startplayback index has not changed since previous
   535     // startplayback index has not changed since previous
   591     QCOMPARE( mDummyModel->startPlaybackIndex(), testIndex );
   536     QCOMPARE( mDummyModel->startPlaybackIndex(), testIndex );
   592     
   537     
   593     cleanup();
   538     cleanup();
   594 }
   539 }
   614     HbAction* deleteAction = findObject<HbAction>(TEST_VIDEO_DETAILS_MENUACTION_DELETE);
   559     HbAction* deleteAction = findObject<HbAction>(TEST_VIDEO_DETAILS_MENUACTION_DELETE);
   615     
   560     
   616     QVERIFY( deleteAction != 0 ); 
   561     QVERIFY( deleteAction != 0 ); 
   617     deleteAction->trigger();
   562     deleteAction->trigger();
   618     QCOMPARE( mDummyModel->dataAccessCount(), 0 );    
   563     QCOMPARE( mDummyModel->dataAccessCount(), 0 );    
   619     mPlugin->mVideoIndex = 0;
   564     mPlugin->mVideoId = (0,0);
   620     
   565 
   621     mDummyModel->setDataReturnInvalid(true);
   566     mDummyModel->setDataReturnInvalid(true);
   622     QModelIndex expected = mDummyModel->index(0, 0);
   567     QModelIndex expected = mDummyModel->index(0, 0);
   623     deleteAction->trigger();
   568     deleteAction->trigger();
   624     QCOMPARE( mDummyModel->dataAccessCount(), 1 );
   569     QCOMPARE( mDummyModel->dataAccessCount(), 1 );
   625     QVERIFY( mDummyModel->lastIndex() == expected );
   570     QVERIFY( mDummyModel->lastIndex() == expected );
   626     QCOMPARE( mDummyModel->deleteFileIndex(), -1 ); // verify that no file was deleted.
   571     QCOMPARE( mDummyModel->deleteFileIndex(), -1 ); // verify that no file was deleted.
   627     mDummyModel->setDataReturnInvalid(false);
   572     mDummyModel->setDataReturnInvalid(false);
   628 
   573 
   629     mPlugin->mVideoIndex = 0;
   574     mPlugin->mVideoId = (0,0);
   630     expected = mDummyModel->index(0, 0);
   575     expected = mDummyModel->index(0, 0);
   631     deleteAction->trigger();
   576     deleteAction->trigger();
   632     QCOMPARE( mDummyModel->dataAccessCount(), 2 );
   577     QCOMPARE( mDummyModel->dataAccessCount(), 2 );
   633     QVERIFY( mDummyModel->lastIndex() == expected );
   578     QVERIFY( mDummyModel->lastIndex() == expected );
   634     QCOMPARE( mDummyModel->deleteFileIndex(), -1 ); // verify that no file was deleted.
   579     QCOMPARE( mDummyModel->deleteFileIndex(), -1 ); // verify that no file was deleted.
   672 // ---------------------------------------------------------------------------
   617 // ---------------------------------------------------------------------------
   673 //
   618 //
   674 void TestVideoFileDetails::testRowsRemovedSlot()
   619 void TestVideoFileDetails::testRowsRemovedSlot()
   675 {
   620 {
   676     const int testIndex = 9;
   621     const int testIndex = 9;
       
   622     TMPXItemId testID(9,0);
   677     init();
   623     init();
   678     connect(mPlugin, SIGNAL(command(int)), this, SLOT(handleCommand(int)));
   624     connect(mPlugin, SIGNAL(command(int)), this, SLOT(handleCommand(int)));
   679     
   625     
   680     emit rowsRemoved(QModelIndex(), testIndex, testIndex);
   626     emit rowsRemoved(QModelIndex(), testIndex, testIndex);
   681     QCOMPARE( mCommandReceived, false );
   627     QCOMPARE( mCommandReceived, false );
   685     
   631     
   686     emit rowsRemoved(QModelIndex(), testIndex, testIndex);
   632     emit rowsRemoved(QModelIndex(), testIndex, testIndex);
   687     QCOMPARE( mCommandReceived, false );
   633     QCOMPARE( mCommandReceived, false );
   688     QCOMPARE( mReceivedCommand, -1 );
   634     QCOMPARE( mReceivedCommand, -1 );
   689     
   635     
   690     emit fullDetailsReady(testIndex);
   636     emit fullDetailsReady(testID);
   691     mPlugin->mVideoIndex = testIndex;
   637     mPlugin->mVideoId = testID;
       
   638     mPlugin->mDeletedIndex = testIndex;
   692     
   639     
   693     emit rowsRemoved(QModelIndex(), testIndex+1, testIndex-1);
   640     emit rowsRemoved(QModelIndex(), testIndex+1, testIndex-1);
   694     QCOMPARE( mCommandReceived, false );
   641     QCOMPARE( mCommandReceived, false );
   695     QCOMPARE( mReceivedCommand, -1 );
   642     QCOMPARE( mReceivedCommand, -1 );
   696 
   643 
   752 // Slot: test for the testThumbnailReadySlot
   699 // Slot: test for the testThumbnailReadySlot
   753 // ---------------------------------------------------------------------------
   700 // ---------------------------------------------------------------------------
   754 //
   701 //
   755 void TestVideoFileDetails::testThumbnailReadySlot()
   702 void TestVideoFileDetails::testThumbnailReadySlot()
   756 {
   703 {
   757     int testIndex = 9;
   704     TMPXItemId testIndex(9,0);
   758     QStringList display;
   705     QStringList display;
   759     display.append("first row");
   706     display.append("first row");
   760     display.append("second row");
   707     display.append("second row");
   761     QString filepath("filepath");
   708     QString filepath("filepath");
   762     
   709     
   769     emit shortDetailsReady(testIndex);
   716     emit shortDetailsReady(testIndex);
   770     
   717     
   771     mPlugin->mThumbnailManager->mThumbnailReadyError = -1;
   718     mPlugin->mThumbnailManager->mThumbnailReadyError = -1;
   772     mPlugin->mThumbnailManager->emitThumbnailReady(0);
   719     mPlugin->mThumbnailManager->emitThumbnailReady(0);
   773     
   720     
   774     QVERIFY( findWidget<HbPushButton>(TEST_VIDEO_DETAILS_BUTTON_PLAY)->icon().qicon().isNull() == false );
   721     HbStackedWidget* thumbWidget = findWidget<HbStackedWidget>(VIDEO_DETAILS_THUMBNAIL);
   775     
   722     VideoDetailsLabel* thumbLabel = (VideoDetailsLabel*)thumbWidget->widgetAt(0);
       
   723     QVERIFY( thumbLabel->icon().qicon().isNull() == false );
       
   724 
   776     mPlugin->mThumbnailManager->mThumbnailReadyError = 0;
   725     mPlugin->mThumbnailManager->mThumbnailReadyError = 0;
   777     emit shortDetailsReady(testIndex);
   726     emit shortDetailsReady(testIndex);
   778     mPlugin->mThumbnailManager->emitThumbnailReady(0);
   727     mPlugin->mThumbnailManager->emitThumbnailReady(0);
   779     
   728     
   780     QVERIFY( findWidget<HbPushButton>(TEST_VIDEO_DETAILS_BUTTON_PLAY)->icon().qicon().isNull() == false );
   729     QVERIFY( thumbLabel->icon().qicon().isNull() == false );
   781     
   730     
   782     cleanup();
   731     cleanup();
   783 }
   732 }
   784 
   733 
   785 
   734