~mandel/ubuntu-download-manager/use-apparmor

« back to all changes in this revision

Viewing changes to ubuntu-download-manager-tests/test_download.cpp

  • Committer: Manuel de la Pena
  • Date: 2013-09-09 16:05:49 UTC
  • Revision ID: manuel@canonical.com-20130909160549-6h8v9iza3dfeuxmq
Changed download factory to use apparmor to build the dbus paths.

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
    QFETCH(QUrl, url);
113
113
 
114
114
    SingleDownload* download = new SingleDownload(id, path, url, _metadata,
115
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
115
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
116
        QSharedPointer<RequestFactory>(_reqFactory),
 
117
        QSharedPointer<ProcessFactory>(_processFactory));
116
118
 
117
119
    // assert that we did set the intial state correctly
118
120
    // gets for internal state
158
160
    QFETCH(int, algo);
159
161
 
160
162
    SingleDownload* download = new SingleDownload(id, path, url, hash,
161
 
        (QCryptographicHash::Algorithm)algo, _metadata, _headers, _networkInfo,
162
 
        _reqFactory, _processFactory);
 
163
        (QCryptographicHash::Algorithm)algo, _metadata, _headers,
 
164
        QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
165
        QSharedPointer<RequestFactory>(_reqFactory),
 
166
        QSharedPointer<ProcessFactory>(_processFactory));
163
167
 
164
168
    QCOMPARE(download->downloadId(), id);
165
169
    QCOMPARE(download->path(), path);
189
193
    // create an app download and assert that the returned data is correct
190
194
    QFETCH(QString, path);
191
195
    SingleDownload* download = new SingleDownload(_id, path, _url, _metadata,
192
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
196
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
197
        QSharedPointer<RequestFactory>(_reqFactory),
 
198
        QSharedPointer<ProcessFactory>(_processFactory));
193
199
    QCOMPARE(download->path(), path);
194
200
}
195
201
 
209
215
    // create an app download and assert that the returned data is correct
210
216
    QFETCH(QUrl, url);
211
217
    SingleDownload* download = new SingleDownload(_id, _path, url, _metadata,
212
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
218
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
219
        QSharedPointer<RequestFactory>(_reqFactory),
 
220
        QSharedPointer<ProcessFactory>(_processFactory));
213
221
    QCOMPARE(download->url(), url);
214
222
    delete download;
215
223
}
234
242
 
235
243
    _reqFactory->record();
236
244
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
237
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
245
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
246
        QSharedPointer<RequestFactory>(_reqFactory),
 
247
        QSharedPointer<ProcessFactory>(_processFactory));
238
248
    QSignalSpy spy(download , SIGNAL(progress(qulonglong, qulonglong)));
239
249
 
240
250
    // start the download so that we do have access to the reply
278
288
 
279
289
    _reqFactory->record();
280
290
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
281
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
291
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
292
        QSharedPointer<RequestFactory>(_reqFactory),
 
293
        QSharedPointer<ProcessFactory>(_processFactory));
282
294
    QSignalSpy spy(download , SIGNAL(progress(qulonglong, qulonglong)));
283
295
 
284
296
    // start the download so that we do have access to the reply
310
322
    // by emitting two signals with diff sizes
311
323
    _reqFactory->record();
312
324
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
313
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
325
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
326
        QSharedPointer<RequestFactory>(_reqFactory),
 
327
        QSharedPointer<ProcessFactory>(_processFactory));
314
328
    QSignalSpy spy(download , SIGNAL(progress(qulonglong, qulonglong)));
315
329
 
316
330
    // start the download so that we do have access to the reply
331
345
void
332
346
TestDownload::testTotalSizeNoProgress() {
333
347
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
334
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
348
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
349
        QSharedPointer<RequestFactory>(_reqFactory),
 
350
        QSharedPointer<ProcessFactory>(_processFactory));
335
351
    QCOMPARE(0ULL, download->totalSize());
336
352
    delete download;
337
353
}
350
366
TestDownload::testSetThrottleNoReply() {
351
367
    QFETCH(qulonglong, speed);
352
368
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
353
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
369
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
370
        QSharedPointer<RequestFactory>(_reqFactory),
 
371
        QSharedPointer<ProcessFactory>(_processFactory));
354
372
    download->setThrottle(speed);
355
373
    QCOMPARE(speed, download->throttle());
356
374
}
371
389
 
372
390
    _reqFactory->record();
373
391
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
374
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
392
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
393
        QSharedPointer<RequestFactory>(_reqFactory),
 
394
        QSharedPointer<ProcessFactory>(_processFactory));
375
395
    download->setThrottle(speed);
376
396
 
377
397
    download->start();  // change state
402
422
    QFETCH(bool, value);
403
423
 
404
424
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
405
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
425
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
426
        QSharedPointer<RequestFactory>(_reqFactory),
 
427
        QSharedPointer<ProcessFactory>(_processFactory));
406
428
    download->allowGSMDownload(value);
407
429
    QSignalSpy spy(download , SIGNAL(stateChanged()));
408
430
 
425
447
    QFETCH(bool, newValue);
426
448
 
427
449
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
428
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
450
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
451
        QSharedPointer<RequestFactory>(_reqFactory),
 
452
        QSharedPointer<ProcessFactory>(_processFactory));
429
453
    download->allowGSMDownload(oldValue);
430
454
    QSignalSpy spy(download , SIGNAL(stateChanged()));
431
455
 
468
492
    _networkInfo->record();
469
493
 
470
494
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
471
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
495
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
496
        QSharedPointer<RequestFactory>(_reqFactory),
 
497
        QSharedPointer<ProcessFactory>(_processFactory));
472
498
    download->allowGSMDownload(true);
473
499
    QVERIFY(download->canDownload());
474
500
    QList<MethodData> calledMethods = _networkInfo->calledMethods();
514
540
    _networkInfo->record();
515
541
 
516
542
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
517
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
543
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
544
        QSharedPointer<RequestFactory>(_reqFactory),
 
545
        QSharedPointer<ProcessFactory>(_processFactory));
518
546
    download->allowGSMDownload(false);
519
547
 
520
548
    QCOMPARE(result, download->canDownload());
525
553
void
526
554
TestDownload::testCancel() {
527
555
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
528
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
556
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
557
        QSharedPointer<RequestFactory>(_reqFactory),
 
558
        QSharedPointer<ProcessFactory>(_processFactory));
529
559
    QSignalSpy spy(download , SIGNAL(stateChanged()));
530
560
    download->cancel();
531
561
 
537
567
void
538
568
TestDownload::testPause() {
539
569
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
540
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
570
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
571
        QSharedPointer<RequestFactory>(_reqFactory),
 
572
        QSharedPointer<ProcessFactory>(_processFactory));
541
573
    QSignalSpy spy(download , SIGNAL(stateChanged()));
542
574
    download->pause();
543
575
 
549
581
void
550
582
TestDownload::testResume() {
551
583
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
552
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
584
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
585
        QSharedPointer<RequestFactory>(_reqFactory),
 
586
        QSharedPointer<ProcessFactory>(_processFactory));
553
587
    QSignalSpy spy(download , SIGNAL(stateChanged()));
554
588
    download->resume();
555
589
 
561
595
void
562
596
TestDownload::testStart() {
563
597
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
564
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
598
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
599
        QSharedPointer<RequestFactory>(_reqFactory),
 
600
        QSharedPointer<ProcessFactory>(_processFactory));
565
601
    QSignalSpy spy(download , SIGNAL(stateChanged()));
566
602
    download->start();
567
603
 
576
612
 
577
613
    _reqFactory->record();
578
614
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
579
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
615
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
616
        QSharedPointer<RequestFactory>(_reqFactory),
 
617
        QSharedPointer<ProcessFactory>(_processFactory));
580
618
    QSignalSpy spy(download,
581
619
        SIGNAL(canceled(bool)));  // NOLINT(readability/function)
582
620
 
608
646
TestDownload::testCancelDownloadNotStarted() {
609
647
    _reqFactory->record();
610
648
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
611
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
649
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
650
        QSharedPointer<RequestFactory>(_reqFactory),
 
651
        QSharedPointer<ProcessFactory>(_processFactory));
612
652
    QSignalSpy spy(download,
613
653
        SIGNAL(canceled(bool)));  // NOLINT(readability/function)
614
654
 
629
669
TestDownload::testPauseDownload() {
630
670
    _reqFactory->record();
631
671
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
632
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
672
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
673
        QSharedPointer<RequestFactory>(_reqFactory),
 
674
        QSharedPointer<ProcessFactory>(_processFactory));
633
675
    QSignalSpy spy(download,
634
676
        SIGNAL(paused(bool)));  // NOLINT(readability/function)
635
677
 
666
708
void
667
709
TestDownload::testPauseDownloadNotStarted() {
668
710
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
669
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
711
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
712
        QSharedPointer<RequestFactory>(_reqFactory),
 
713
        QSharedPointer<ProcessFactory>(_processFactory));
670
714
    QSignalSpy spy(download,
671
715
        SIGNAL(paused(bool)));  // NOLINT(readability/function)
672
716
 
683
727
void
684
728
TestDownload::testResumeRunning() {
685
729
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
686
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
730
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
731
        QSharedPointer<RequestFactory>(_reqFactory),
 
732
        QSharedPointer<ProcessFactory>(_processFactory));
687
733
    QSignalSpy spy(download,
688
734
        SIGNAL(resumed(bool)));  // NOLINT(readability/function)
689
735
 
703
749
TestDownload::testResumeDownload() {
704
750
    _reqFactory->record();
705
751
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
706
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
752
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
753
        QSharedPointer<RequestFactory>(_reqFactory),
 
754
        QSharedPointer<ProcessFactory>(_processFactory));
707
755
    QSignalSpy spy(download , SIGNAL(paused(bool result)));
708
756
 
709
757
    download->start();  // change state
741
789
TestDownload::testStartDownload() {
742
790
    _reqFactory->record();
743
791
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
744
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
792
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
793
        QSharedPointer<RequestFactory>(_reqFactory),
 
794
        QSharedPointer<ProcessFactory>(_processFactory));
745
795
    QSignalSpy spy(download,
746
796
        SIGNAL(started(bool)));  // NOLINT(readability/function)
747
797
 
763
813
TestDownload::testStartDownloadAlreadyStarted() {
764
814
    _reqFactory->record();
765
815
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
766
 
        _headers, _networkInfo, _reqFactory, _processFactory);
 
816
        _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
817
        QSharedPointer<RequestFactory>(_reqFactory),
 
818
        QSharedPointer<ProcessFactory>(_processFactory));
767
819
    QSignalSpy spy(download,
768
820
        SIGNAL(started(bool)));  // NOLINT(readability/function)
769
821
 
787
839
TestDownload::testOnSuccessNoHash() {
788
840
    _reqFactory->record();
789
841
    SingleDownload* download = new SingleDownload(_id, _path, _url,
790
 
        _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
 
842
        _metadata, _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
843
        QSharedPointer<RequestFactory>(_reqFactory),
 
844
        QSharedPointer<ProcessFactory>(_processFactory));
791
845
    QSignalSpy spy(download , SIGNAL(finished(QString)));
792
846
 
793
847
    download->start();  // change state
809
863
    _reqFactory->record();
810
864
    SingleDownload* download = new SingleDownload(_id, _path, _url,
811
865
        "imposible-hash-is-not-hex", _algo, _metadata, _headers,
812
 
        _networkInfo, _reqFactory, _processFactory);
 
866
        QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
867
        QSharedPointer<RequestFactory>(_reqFactory),
 
868
        QSharedPointer<ProcessFactory>(_processFactory));
813
869
    QSignalSpy spy(download , SIGNAL(error(QString)));
814
870
 
815
871
    download->start();  // change state
869
925
 
870
926
    _reqFactory->record();
871
927
    SingleDownload* download = new SingleDownload(_id, _path, _url, hash, _algo,
872
 
        _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
 
928
        _metadata, _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
929
        QSharedPointer<RequestFactory>(_reqFactory),
 
930
        QSharedPointer<ProcessFactory>(_processFactory));
873
931
    QSignalSpy spy(download , SIGNAL(finished(QString)));
874
932
 
875
933
    download->start();  // change state
906
964
TestDownload::testOnHttpError() {
907
965
    _reqFactory->record();
908
966
    SingleDownload* download = new SingleDownload(_id, _path, _url,
909
 
        _metadata, _headers, _networkInfo, _reqFactory, _processFactory);
 
967
        _metadata, _headers,
 
968
        QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
969
        QSharedPointer<RequestFactory>(_reqFactory),
 
970
        QSharedPointer<ProcessFactory>(_processFactory));
910
971
    QSignalSpy spy(download , SIGNAL(error(QString)));
911
972
 
912
973
    download->start();  // change state
956
1017
    QFETCH(StringMap, headers);
957
1018
    _reqFactory->record();
958
1019
    SingleDownload* download = new SingleDownload(_id, _path, _url,
959
 
        _metadata, headers, _networkInfo, _reqFactory, _processFactory);
 
1020
        _metadata, headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
1021
        QSharedPointer<RequestFactory>(_reqFactory),
 
1022
        QSharedPointer<ProcessFactory>(_processFactory));
960
1023
 
961
1024
    download->start();  // change state
962
1025
    download->startDownload();
1010
1073
    QFETCH(StringMap, headers);
1011
1074
    _reqFactory->record();
1012
1075
    SingleDownload* download = new SingleDownload(_id, _path, _url,
1013
 
        _metadata, headers, _networkInfo, _reqFactory, _processFactory);
 
1076
        _metadata, headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
1077
        QSharedPointer<RequestFactory>(_reqFactory),
 
1078
        QSharedPointer<ProcessFactory>(_processFactory));
1014
1079
 
1015
1080
    download->start();  // change state
1016
1081
    download->startDownload();
1059
1124
 
1060
1125
    _reqFactory->record();
1061
1126
    SingleDownload* download = new SingleDownload(_id, _path, _url,
1062
 
        _metadata, headers, _networkInfo, _reqFactory, _processFactory);
 
1127
        _metadata, headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
1128
        QSharedPointer<RequestFactory>(_reqFactory),
 
1129
        QSharedPointer<ProcessFactory>(_processFactory));
1063
1130
    QSignalSpy spy(download , SIGNAL(paused(bool result)));
1064
1131
 
1065
1132
    download->start();  // change state
1137
1204
 
1138
1205
    _reqFactory->record();
1139
1206
    SingleDownload* download = new SingleDownload(_id, _path, _url, _metadata,
1140
 
        headers, _networkInfo, _reqFactory, _processFactory);
 
1207
        headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
1208
        QSharedPointer<RequestFactory>(_reqFactory),
 
1209
        QSharedPointer<ProcessFactory>(_processFactory));
1141
1210
    QSignalSpy spy(download , SIGNAL(paused(bool result)));
1142
1211
 
1143
1212
    download->start();  // change state
1203
1272
    _processFactory->record();
1204
1273
    _reqFactory->record();
1205
1274
    SingleDownload* download = new SingleDownload(_id, _path, _url,
1206
 
        metadata, _headers, _networkInfo, _reqFactory, _processFactory);
 
1275
        metadata, _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
1276
        QSharedPointer<RequestFactory>(_reqFactory),
 
1277
        QSharedPointer<ProcessFactory>(_processFactory));
1207
1278
 
1208
1279
    download->start();  // change state
1209
1280
    download->startDownload();
1264
1335
    _processFactory->record();
1265
1336
    _reqFactory->record();
1266
1337
    SingleDownload* download = new SingleDownload(_id, _path, _url,
1267
 
        metadata, _headers, _networkInfo, _reqFactory, _processFactory);
 
1338
        metadata, _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
1339
        QSharedPointer<RequestFactory>(_reqFactory),
 
1340
        QSharedPointer<ProcessFactory>(_processFactory));
1268
1341
 
1269
1342
    download->start();  // change state
1270
1343
    download->startDownload();
1325
1398
    _processFactory->record();
1326
1399
    _reqFactory->record();
1327
1400
    SingleDownload* download = new SingleDownload(_id, _path, _url,
1328
 
        metadata, _headers, _networkInfo, _reqFactory, _processFactory);
 
1401
        metadata, _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
1402
        QSharedPointer<RequestFactory>(_reqFactory),
 
1403
        QSharedPointer<ProcessFactory>(_processFactory));
1329
1404
 
1330
1405
    download->start();  // change state
1331
1406
    download->startDownload();
1365
1440
    _processFactory->record();
1366
1441
    _reqFactory->record();
1367
1442
    SingleDownload* download = new SingleDownload(_id, _path, _url,
1368
 
        metadata, _headers, _networkInfo, _reqFactory, _processFactory);
 
1443
        metadata, _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
1444
        QSharedPointer<RequestFactory>(_reqFactory),
 
1445
        QSharedPointer<ProcessFactory>(_processFactory));
1369
1446
    QSignalSpy spy(download , SIGNAL(finished(QString)));
1370
1447
 
1371
1448
    download->start();  // change state
1400
1477
    _processFactory->record();
1401
1478
    _reqFactory->record();
1402
1479
    SingleDownload* download = new SingleDownload(_id, _path, _url,
1403
 
        metadata, _headers, _networkInfo, _reqFactory, _processFactory);
 
1480
        metadata, _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
1481
        QSharedPointer<RequestFactory>(_reqFactory),
 
1482
        QSharedPointer<ProcessFactory>(_processFactory));
1404
1483
    QSignalSpy spy(download , SIGNAL(error(QString)));
1405
1484
 
1406
1485
    download->start();  // change state
1435
1514
    _processFactory->record();
1436
1515
    _reqFactory->record();
1437
1516
    SingleDownload* download = new SingleDownload(_id, _path, _url,
1438
 
        metadata, _headers, _networkInfo, _reqFactory, _processFactory);
 
1517
        metadata, _headers, QSharedPointer<SystemNetworkInfo>(_networkInfo),
 
1518
        QSharedPointer<RequestFactory>(_reqFactory),
 
1519
        QSharedPointer<ProcessFactory>(_processFactory));
1439
1520
    QSignalSpy spy(download , SIGNAL(error(QString)));
1440
1521
 
1441
1522
    download->start();  // change state