1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/memory/ref_counted.h"
#include "base/path_service.h"
#include "base/scoped_temp_dir.h"
#include "base/stringprintf.h"
#include "base/stl_util.h"
#include "base/test/test_file_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/download/download_crx_util.h"
#include "chrome/browser/download/download_history.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/download/download_service.h"
#include "chrome/browser/download/download_service_factory.h"
#include "chrome/browser/download/download_shelf.h"
#include "chrome/browser/download/download_test_observer.h"
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/extensions/extension_install_ui.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/net/url_request_mock_util.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/webui/active_downloads_ui.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/browser/cancelable_request.h"
#include "content/browser/download/download_file_manager.h"
#include "content/browser/download/download_item.h"
#include "content/browser/download/download_manager.h"
#include "content/browser/download/download_persistent_store_info.h"
#include "content/browser/net/url_request_mock_http_job.h"
#include "content/browser/renderer_host/resource_dispatcher_host.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/browser/net/url_request_slow_download_job.h"
#include "content/public/common/page_transition_types.h"
#include "net/base/net_util.h"
#include "testing/gtest/include/gtest/gtest.h"
using content::BrowserThread;
namespace {
// IDs and paths of CRX files used in tests.
const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx"));
const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf";
const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx"));
// Action a test should take if a dangerous download is encountered.
enum DangerousDownloadAction {
ON_DANGEROUS_DOWNLOAD_ACCEPT, // Accept the download
ON_DANGEROUS_DOWNLOAD_DENY, // Deny the download
ON_DANGEROUS_DOWNLOAD_FAIL // Fail if a dangerous download is seen
};
// Fake user click on "Accept".
void AcceptDangerousDownload(scoped_refptr<DownloadManager> download_manager,
int32 download_id) {
DownloadItem* download = download_manager->GetDownloadItem(download_id);
download->DangerousDownloadValidated();
}
// Fake user click on "Deny".
void DenyDangerousDownload(scoped_refptr<DownloadManager> download_manager,
int32 download_id) {
DownloadItem* download = download_manager->GetDownloadItem(download_id);
ASSERT_TRUE(download->IsPartialDownload());
download->Cancel(true);
download->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
}
// Collect the information from FILE and IO threads needed for the Cancel
// Test, specifically the number of outstanding requests on the
// ResourceDispatcherHost and the number of pending downloads on the
// DownloadFileManager.
class CancelTestDataCollector
: public base::RefCountedThreadSafe<CancelTestDataCollector> {
public:
CancelTestDataCollector()
: resource_dispatcher_host_(
g_browser_process->resource_dispatcher_host()),
slow_download_job_pending_requests_(0),
dfm_pending_downloads_(0) { }
void WaitForDataCollected() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&CancelTestDataCollector::IOInfoCollector, this));
ui_test_utils::RunMessageLoop();
}
int slow_download_job_pending_requests() const {
return slow_download_job_pending_requests_;
}
int dfm_pending_downloads() const { return dfm_pending_downloads_; }
protected:
friend class base::RefCountedThreadSafe<CancelTestDataCollector>;
virtual ~CancelTestDataCollector() {}
private:
void IOInfoCollector() {
download_file_manager_ = resource_dispatcher_host_->download_file_manager();
slow_download_job_pending_requests_ =
URLRequestSlowDownloadJob::NumberOutstandingRequests();
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&CancelTestDataCollector::FileInfoCollector, this));
}
void FileInfoCollector() {
dfm_pending_downloads_ = download_file_manager_->NumberOfActiveDownloads();
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, new MessageLoop::QuitTask());
}
ResourceDispatcherHost* resource_dispatcher_host_;
DownloadFileManager* download_file_manager_;
int slow_download_job_pending_requests_;
int dfm_pending_downloads_;
DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector);
};
class PickSuggestedFileDelegate : public ChromeDownloadManagerDelegate {
public:
explicit PickSuggestedFileDelegate(Profile* profile)
: ChromeDownloadManagerDelegate(profile) {
SetDownloadManager(
DownloadServiceFactory::GetForProfile(profile)->GetDownloadManager());
}
virtual void ChooseDownloadPath(TabContents* tab_contents,
const FilePath& suggested_path,
void* data) OVERRIDE {
if (download_manager_)
download_manager_->FileSelected(suggested_path, data);
}
};
// Get History Information.
class DownloadsHistoryDataCollector {
public:
DownloadsHistoryDataCollector(int64 download_db_handle,
DownloadManager* manager)
: result_valid_(false),
download_db_handle_(download_db_handle) {
HistoryService* hs =
Profile::FromBrowserContext(manager->BrowserContext())->
GetHistoryService(Profile::EXPLICIT_ACCESS);
DCHECK(hs);
hs->QueryDownloads(
&callback_consumer_,
base::Bind(&DownloadsHistoryDataCollector::OnQueryDownloadsComplete,
base::Unretained(this)));
// TODO(rdsmith): Move message loop out of constructor.
// Cannot complete immediately because the history backend runs on a
// separate thread, so we can assume that the RunMessageLoop below will
// be exited by the Quit in OnQueryDownloadsComplete.
ui_test_utils::RunMessageLoop();
}
bool GetDownloadsHistoryEntry(DownloadPersistentStoreInfo* result) {
DCHECK(result);
*result = result_;
return result_valid_;
}
private:
void OnQueryDownloadsComplete(
std::vector<DownloadPersistentStoreInfo>* entries) {
result_valid_ = false;
for (std::vector<DownloadPersistentStoreInfo>::const_iterator it =
entries->begin();
it != entries->end(); ++it) {
if (it->db_handle == download_db_handle_) {
result_ = *it;
result_valid_ = true;
}
}
MessageLoopForUI::current()->Quit();
}
DownloadPersistentStoreInfo result_;
bool result_valid_;
int64 download_db_handle_;
CancelableRequestConsumer callback_consumer_;
DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector);
};
// Mock that simulates a permissions dialog where the user denies
// permission to install. TODO(skerner): This could be shared with
// extensions tests. Find a common place for this class.
class MockAbortExtensionInstallUI : public ExtensionInstallUI {
public:
MockAbortExtensionInstallUI() : ExtensionInstallUI(NULL) {}
// Simulate a user abort on an extension installation.
virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) {
delegate->InstallUIAbort(true);
MessageLoopForUI::current()->Quit();
}
virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon) {}
virtual void OnInstallFailure(const std::string& error) {}
};
// Mock that simulates a permissions dialog where the user allows
// installation.
class MockAutoConfirmExtensionInstallUI : public ExtensionInstallUI {
public:
explicit MockAutoConfirmExtensionInstallUI(Profile* profile)
: ExtensionInstallUI(profile) {}
// Proceed without confirmation prompt.
virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) {
delegate->InstallUIProceed();
}
virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon) {}
virtual void OnInstallFailure(const std::string& error) {}
};
static DownloadManager* DownloadManagerForBrowser(Browser* browser) {
return DownloadServiceFactory::GetForProfile(browser->profile())
->GetDownloadManager();
}
} // namespace
// While an object of this class exists, it will mock out download
// opening for all downloads created on the specified download manager.
class MockDownloadOpeningObserver : public DownloadManager::Observer {
public:
explicit MockDownloadOpeningObserver(DownloadManager* manager)
: download_manager_(manager) {
download_manager_->AddObserver(this);
}
~MockDownloadOpeningObserver() {
download_manager_->RemoveObserver(this);
}
// DownloadManager::Observer
virtual void ModelChanged() {
std::vector<DownloadItem*> downloads;
download_manager_->SearchDownloads(string16(), &downloads);
for (std::vector<DownloadItem*>::iterator it = downloads.begin();
it != downloads.end(); ++it) {
(*it)->MockDownloadOpenForTesting();
}
}
private:
DownloadManager* download_manager_;
DISALLOW_COPY_AND_ASSIGN(MockDownloadOpeningObserver);
};
class DownloadTest : public InProcessBrowserTest {
public:
enum SelectExpectation {
EXPECT_NO_SELECT_DIALOG = -1,
EXPECT_NOTHING,
EXPECT_SELECT_DIALOG
};
DownloadTest() {
EnableDOMAutomation();
}
void SetUpOnMainThread() OVERRIDE {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
}
// Returning false indicates a failure of the setup, and should be asserted
// in the caller.
virtual bool InitialSetup(bool prompt_for_download) {
bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_);
EXPECT_TRUE(have_test_dir);
if (!have_test_dir)
return false;
// Sanity check default values for window / tab count and shelf visibility.
int window_count = BrowserList::size();
EXPECT_EQ(1, window_count);
EXPECT_EQ(1, browser()->tab_count());
EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
// Set up the temporary download folder.
bool created_downloads_dir = CreateAndSetDownloadsDirectory(browser());
EXPECT_TRUE(created_downloads_dir);
if (!created_downloads_dir)
return false;
browser()->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload,
prompt_for_download);
DownloadManager* manager = DownloadManagerForBrowser(browser());
DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen();
manager->RemoveAllDownloads();
return true;
}
protected:
enum SizeTestType {
SIZE_TEST_TYPE_KNOWN,
SIZE_TEST_TYPE_UNKNOWN,
};
// Location of the file source (the place from which it is downloaded).
FilePath OriginFile(FilePath file) {
return test_dir_.Append(file);
}
// Location of the file destination (place to which it is downloaded).
FilePath DestinationFile(Browser* browser, FilePath file) {
return GetDownloadDirectory(browser).Append(file);
}
// Must be called after browser creation. Creates a temporary
// directory for downloads that is auto-deleted on destruction.
// Returning false indicates a failure of the function, and should be asserted
// in the caller.
bool CreateAndSetDownloadsDirectory(Browser* browser) {
if (!browser)
return false;
if (!downloads_directory_.CreateUniqueTempDir())
return false;
browser->profile()->GetPrefs()->SetFilePath(
prefs::kDownloadDefaultDirectory,
downloads_directory_.path());
return true;
}
DownloadPrefs* GetDownloadPrefs(Browser* browser) {
return DownloadPrefs::FromDownloadManager(
DownloadManagerForBrowser(browser));
}
FilePath GetDownloadDirectory(Browser* browser) {
return GetDownloadPrefs(browser)->download_path();
}
// Create a DownloadTestObserver that will wait for the
// specified number of downloads to finish.
DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) {
DownloadManager* download_manager = DownloadManagerForBrowser(browser);
return new DownloadTestObserver(
download_manager, num_downloads,
DownloadItem::COMPLETE, // Really done
true, // Bail on select file
DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
}
// Create a DownloadTestObserver that will wait for the
// specified number of downloads to start.
DownloadTestObserver* CreateInProgressWaiter(Browser* browser,
int num_downloads) {
DownloadManager* download_manager = DownloadManagerForBrowser(browser);
return new DownloadTestObserver(
download_manager, num_downloads,
DownloadItem::IN_PROGRESS, // Has started
true, // Bail on select file
DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
}
// Create a DownloadTestObserver that will wait for the
// specified number of downloads to finish, or for
// a dangerous download warning to be shown.
DownloadTestObserver* DangerousInstallWaiter(
Browser* browser,
int num_downloads,
DownloadItem::DownloadState final_state,
DownloadTestObserver::DangerousDownloadAction dangerous_download_action) {
DownloadManager* download_manager = DownloadManagerForBrowser(browser);
return new DownloadTestObserver(
download_manager, num_downloads,
final_state,
true, // Bail on select file
dangerous_download_action);
}
// Download |url|, then wait for the download to finish.
// |disposition| indicates where the navigation occurs (current tab, new
// foreground tab, etc).
// |expectation| indicates whether or not a Select File dialog should be
// open when the download is finished, or if we don't care.
// If the dialog appears, the routine exits. The only effect |expectation|
// has is whether or not the test succeeds.
// |browser_test_flags| indicate what to wait for, and is an OR of 0 or more
// values in the ui_test_utils::BrowserTestWaitFlags enum.
void DownloadAndWaitWithDisposition(Browser* browser,
const GURL& url,
WindowOpenDisposition disposition,
SelectExpectation expectation,
int browser_test_flags) {
// Setup notification, navigate, and block.
scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1));
// This call will block until the condition specified by
// |browser_test_flags|, but will not wait for the download to finish.
ui_test_utils::NavigateToURLWithDisposition(browser,
url,
disposition,
browser_test_flags);
// Waits for the download to complete.
observer->WaitForFinished();
// If specified, check the state of the select file dialog.
if (expectation != EXPECT_NOTHING) {
EXPECT_EQ(expectation == EXPECT_SELECT_DIALOG,
observer->select_file_dialog_seen());
}
}
// Download a file in the current tab, then wait for the download to finish.
void DownloadAndWait(Browser* browser,
const GURL& url,
SelectExpectation expectation) {
DownloadAndWaitWithDisposition(
browser,
url,
CURRENT_TAB,
expectation,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
}
// Should only be called when the download is known to have finished
// (in error or not).
// Returning false indicates a failure of the function, and should be asserted
// in the caller.
bool CheckDownload(Browser* browser,
const FilePath& downloaded_filename,
const FilePath& origin_filename) {
// Find the path to which the data will be downloaded.
FilePath downloaded_file(DestinationFile(browser, downloaded_filename));
// Find the origin path (from which the data comes).
FilePath origin_file(OriginFile(origin_filename));
bool origin_file_exists = file_util::PathExists(origin_file);
EXPECT_TRUE(origin_file_exists);
if (!origin_file_exists)
return false;
// Confirm the downloaded data file exists.
bool downloaded_file_exists = file_util::PathExists(downloaded_file);
EXPECT_TRUE(downloaded_file_exists);
if (!downloaded_file_exists)
return false;
int64 origin_file_size = 0;
EXPECT_TRUE(file_util::GetFileSize(origin_file, &origin_file_size));
std::string original_file_contents;
EXPECT_TRUE(
file_util::ReadFileToString(origin_file, &original_file_contents));
EXPECT_TRUE(
VerifyFile(downloaded_file, original_file_contents, origin_file_size));
// Delete the downloaded copy of the file.
bool downloaded_file_deleted =
file_util::DieFileDie(downloaded_file, false);
EXPECT_TRUE(downloaded_file_deleted);
return downloaded_file_deleted;
}
bool RunSizeTest(Browser* browser,
SizeTestType type,
const std::string& partial_indication,
const std::string& total_indication) {
if (!InitialSetup(false))
return false;
EXPECT_TRUE(type == SIZE_TEST_TYPE_UNKNOWN || type == SIZE_TEST_TYPE_KNOWN);
if (type != SIZE_TEST_TYPE_KNOWN && type != SIZE_TEST_TYPE_UNKNOWN)
return false;
GURL url(type == SIZE_TEST_TYPE_KNOWN ?
URLRequestSlowDownloadJob::kKnownSizeUrl :
URLRequestSlowDownloadJob::kUnknownSizeUrl);
// TODO(ahendrickson) -- |expected_title_in_progress| and
// |expected_title_finished| need to be checked.
FilePath filename;
net::FileURLToFilePath(url, &filename);
string16 expected_title_in_progress(
ASCIIToUTF16(partial_indication) + filename.LossyDisplayName());
string16 expected_title_finished(
ASCIIToUTF16(total_indication) + filename.LossyDisplayName());
// Download a partial web page in a background tab and wait.
// The mock system will not complete until it gets a special URL.
scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1));
ui_test_utils::NavigateToURL(browser, url);
// TODO(ahendrickson): check download status text before downloading.
// Need to:
// - Add a member function to the |DownloadShelf| interface class, that
// indicates how many members it has.
// - Add a member function to |DownloadShelf| to get the status text
// of a given member (for example, via the name in |DownloadItemView|'s
// GetAccessibleState() member function), by index.
// - Iterate over browser->window()->GetDownloadShelf()'s members
// to see if any match the status text we want. Start with the last one.
// Allow the request to finish. We do this by loading a second URL in a
// separate tab.
GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl);
ui_test_utils::NavigateToURLWithDisposition(
browser,
finish_url,
NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
observer->WaitForFinished();
EXPECT_EQ(2, browser->tab_count());
// TODO(ahendrickson): check download status text after downloading.
FilePath basefilename(filename.BaseName());
net::FileURLToFilePath(url, &filename);
FilePath download_path = downloads_directory_.path().Append(basefilename);
CheckDownloadUI(browser, true, true, basefilename);
bool downloaded_path_exists = file_util::PathExists(download_path);
EXPECT_TRUE(downloaded_path_exists);
if (!downloaded_path_exists)
return false;
// Check the file contents.
size_t file_size = URLRequestSlowDownloadJob::kFirstDownloadSize +
URLRequestSlowDownloadJob::kSecondDownloadSize;
std::string expected_contents(file_size, '*');
EXPECT_TRUE(VerifyFile(download_path, expected_contents, file_size));
// Delete the file we just downloaded.
EXPECT_TRUE(file_util::DieFileDie(download_path, true));
EXPECT_FALSE(file_util::PathExists(download_path));
return true;
}
void GetDownloads(Browser* browser, std::vector<DownloadItem*>* downloads) {
DCHECK(downloads);
DownloadManager* manager = DownloadManagerForBrowser(browser);
manager->SearchDownloads(string16(), downloads);
}
// Check that the download UI (shelf on non-chromeos or panel on chromeos)
// is visible or not as expected. Additionally, check that the filename
// is present in the UI (currently only on chromeos).
void CheckDownloadUI(Browser* browser, bool expected_non_cros,
bool expected_cros, const FilePath& filename) {
#if defined(OS_CHROMEOS) && !defined(USE_AURA)
Browser* popup = ActiveDownloadsUI::GetPopup();
EXPECT_EQ(expected_cros, popup != NULL);
if (!popup || filename.empty())
return;
ActiveDownloadsUI* downloads_ui = static_cast<ActiveDownloadsUI*>(
popup->GetSelectedTabContents()->web_ui());
ASSERT_TRUE(downloads_ui);
const ActiveDownloadsUI::DownloadList& downloads =
downloads_ui->GetDownloads();
EXPECT_EQ(downloads.size(), 1U);
FilePath full_path(DestinationFile(browser, filename));
bool exists = false;
for (size_t i = 0; i < downloads.size(); ++i) {
if (downloads[i]->GetFullPath() == full_path) {
exists = true;
break;
}
}
EXPECT_TRUE(exists);
#else
EXPECT_EQ(expected_non_cros, browser->window()->IsDownloadShelfVisible());
// TODO: Check for filename match in download shelf.
#endif
}
static void ExpectWindowCountAfterDownload(size_t expected) {
#if defined(OS_CHROMEOS) && !defined(USE_AURA)
// On ChromeOS, a download panel is created to display
// download information, and this counts as a window.
expected++;
#endif
EXPECT_EQ(expected, BrowserList::size());
}
// Arrange for select file calls on the given browser from the
// download manager to always choose the suggested file.
void NullSelectFile(Browser* browser) {
PickSuggestedFileDelegate* new_delegate =
new PickSuggestedFileDelegate(browser->profile());
// Gives ownership to DownloadService.
DownloadServiceFactory::GetForProfile(
browser->profile())->SetDownloadManagerDelegateForTesting(new_delegate);
}
// Checks that |path| is has |file_size| bytes, and matches the |value|
// string.
bool VerifyFile(const FilePath& path,
const std::string& value,
const int64 file_size) {
std::string file_contents;
bool read = file_util::ReadFileToString(path, &file_contents);
EXPECT_TRUE(read) << "Failed reading file: " << path.value() << std::endl;
if (!read)
return false; // Couldn't read the file.
// Note: we don't handle really large files (more than size_t can hold)
// so we will fail in that case.
size_t expected_size = static_cast<size_t>(file_size);
// Check the size.
EXPECT_EQ(expected_size, file_contents.size());
if (expected_size != file_contents.size())
return false;
// Check the contents.
EXPECT_EQ(value, file_contents);
if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0)
return false;
return true;
}
private:
// Location of the test data.
FilePath test_dir_;
// Location of the downloads directory for these tests
ScopedTempDir downloads_directory_;
};
// NOTES:
//
// Files for these tests are found in DIR_TEST_DATA (currently
// "chrome\test\data\", see chrome_paths.cc).
// Mock responses have extension .mock-http-headers appended to the file name.
// Download a file due to the associated MIME type.
IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) {
ASSERT_TRUE(InitialSetup(false));
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
// Download the file and wait. We do not expect the Select File dialog.
DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
// Check state.
EXPECT_EQ(1, browser()->tab_count());
CheckDownload(browser(), file, file);
CheckDownloadUI(browser(), true, true, file);
}
#if defined(OS_WIN)
// Download a file and confirm that the zone identifier (on windows)
// is set to internet.
IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) {
ASSERT_TRUE(InitialSetup(false));
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
// Download the file and wait. We do not expect the Select File dialog.
DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
// Check state. Special file state must be checked before CheckDownload,
// as CheckDownload will delete the output file.
EXPECT_EQ(1, browser()->tab_count());
FilePath downloaded_file(DestinationFile(browser(), file));
if (file_util::VolumeSupportsADS(downloaded_file))
EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file));
CheckDownload(browser(), file, file);
CheckDownloadUI(browser(), true, true, file);
}
#endif
// Put up a Select File dialog when the file is downloaded, due to
// downloads preferences settings.
IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) {
ASSERT_TRUE(InitialSetup(true));
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
NullSelectFile(browser());
// Download the file and wait. We expect the Select File dialog to appear
// due to the MIME type, but we still wait until the download completes.
scoped_ptr<DownloadTestObserver> observer(
new DownloadTestObserver(
DownloadManagerForBrowser(browser()),
1,
DownloadItem::COMPLETE, // Really done
false, // Continue on select file.
DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
ui_test_utils::NavigateToURLWithDisposition(
browser(), url, CURRENT_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
observer->WaitForFinished();
EXPECT_TRUE(observer->select_file_dialog_seen());
// Check state.
EXPECT_EQ(1, browser()->tab_count());
CheckDownload(browser(), file, file);
CheckDownloadUI(browser(), true, true, file);
}
// Access a file with a viewable mime-type, verify that a download
// did not initiate.
IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) {
ASSERT_TRUE(InitialSetup(false));
FilePath file(FILE_PATH_LITERAL("download-test2.html"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
FilePath file_path(DestinationFile(browser(), file));
// Open a web page and wait.
ui_test_utils::NavigateToURL(browser(), url);
// Check that we did not download the web page.
EXPECT_FALSE(file_util::PathExists(file_path));
// Check state.
EXPECT_EQ(1, browser()->tab_count());
CheckDownloadUI(browser(), false, false, FilePath());
}
// Download a 0-size file with a content-disposition header, verify that the
// download tab opened and the file exists as the filename specified in the
// header. This also ensures we properly handle empty file downloads.
// The download shelf should be visible in the current tab.
IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) {
ASSERT_TRUE(InitialSetup(false));
FilePath file(FILE_PATH_LITERAL("download-test3.gif"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif"));
// Download a file and wait.
DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
CheckDownload(browser(), download_file, file);
// Check state.
EXPECT_EQ(1, browser()->tab_count());
CheckDownloadUI(browser(), true, true, download_file);
}
#if !defined(OS_CHROMEOS) || defined(USE_AURA)
// Download shelf is not per-window on ChromeOS.
// Test that the download shelf is per-window by starting a download in one
// tab, opening a second tab, closing the shelf, going back to the first tab,
// and checking that the shelf is closed.
IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) {
ASSERT_TRUE(InitialSetup(false));
FilePath file(FILE_PATH_LITERAL("download-test3.gif"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif"));
// Download a file and wait.
DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
CheckDownload(browser(), download_file, file);
// Check state.
EXPECT_EQ(1, browser()->tab_count());
CheckDownloadUI(browser(), true, true, download_file);
// Open a second tab and wait.
EXPECT_NE(static_cast<TabContentsWrapper*>(NULL),
browser()->AddSelectedTabWithURL(
GURL(), content::PAGE_TRANSITION_TYPED));
EXPECT_EQ(2, browser()->tab_count());
CheckDownloadUI(browser(), true, true, download_file);
// Hide the download shelf.
browser()->window()->GetDownloadShelf()->Close();
CheckDownloadUI(browser(), false, false, FilePath());
// Go to the first tab.
browser()->ActivateTabAt(0, true);
EXPECT_EQ(2, browser()->tab_count());
// The download shelf should not be visible.
CheckDownloadUI(browser(), false, false, FilePath());
}
#endif // !OS_CHROMEOS
// UnknownSize and KnownSize are tests which depend on
// URLRequestSlowDownloadJob to serve content in a certain way. Data will be
// sent in two chunks where the first chunk is 35K and the second chunk is 10K.
// The test will first attempt to download a file; but the server will "pause"
// in the middle until the server receives a second request for
// "download-finish". At that time, the download will finish.
// These tests don't currently test much due to holes in |RunSizeTest()|. See
// comments in that routine for details.
IN_PROC_BROWSER_TEST_F(DownloadTest, UnknownSize) {
ASSERT_TRUE(RunSizeTest(browser(), SIZE_TEST_TYPE_UNKNOWN,
"32.0 KB - ", "100% - "));
}
IN_PROC_BROWSER_TEST_F(DownloadTest, KnownSize) {
ASSERT_TRUE(RunSizeTest(browser(), SIZE_TEST_TYPE_KNOWN,
"71% - ", "100% - "));
}
// Test that when downloading an item in Incognito mode, we don't crash when
// closing the last Incognito window (http://crbug.com/13983).
// Also check that the download shelf is not visible after closing the
// Incognito window.
IN_PROC_BROWSER_TEST_F(DownloadTest, IncognitoDownload) {
ASSERT_TRUE(InitialSetup(false));
// Open an Incognito window.
Browser* incognito = CreateIncognitoBrowser(); // Waits.
ASSERT_TRUE(incognito);
int window_count = BrowserList::size();
EXPECT_EQ(2, window_count);
// Download a file in the Incognito window and wait.
CreateAndSetDownloadsDirectory(incognito);
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
// Since |incognito| is a separate browser, we have to set it up explicitly.
incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload,
false);
DownloadAndWait(incognito, url, EXPECT_NO_SELECT_DIALOG);
// We should still have 2 windows.
ExpectWindowCountAfterDownload(2);
// Verify that the download shelf is showing for the Incognito window.
CheckDownloadUI(incognito, true, true, file);
#if !defined(OS_MACOSX)
// On Mac OS X, the UI window close is delayed until the outermost
// message loop runs. So it isn't possible to get a BROWSER_CLOSED
// notification inside of a test.
ui_test_utils::WindowedNotificationObserver signal(
chrome::NOTIFICATION_BROWSER_CLOSED,
content::Source<Browser>(incognito));
#endif
// Close the Incognito window and don't crash.
incognito->CloseWindow();
#if !defined(OS_MACOSX)
signal.Wait();
ExpectWindowCountAfterDownload(1);
#endif
// Verify that the regular window does not have a download shelf.
// On ChromeOS, the download panel is common to both profiles, so
// it is still visible.
CheckDownloadUI(browser(), false, true, file);
CheckDownload(browser(), file, file);
}
// Navigate to a new background page, but don't download. Confirm that the
// download shelf is not visible and that we have two tabs.
IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) {
ASSERT_TRUE(InitialSetup(false));
// Because it's an HTML link, it should open a web page rather than
// downloading.
FilePath file1(FILE_PATH_LITERAL("download-test2.html"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file1));
// Open a web page and wait.
ui_test_utils::NavigateToURLWithDisposition(
browser(),
url,
NEW_BACKGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
// We should have two tabs now.
EXPECT_EQ(2, browser()->tab_count());
CheckDownloadUI(browser(), false, false, FilePath());
}
// Download a file in a background tab. Verify that the tab is closed
// automatically, and that the download shelf is visible in the current tab.
IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) {
ASSERT_TRUE(InitialSetup(false));
// Download a file in a new background tab and wait. The tab is automatically
// closed when the download begins.
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
DownloadAndWaitWithDisposition(
browser(),
url,
NEW_BACKGROUND_TAB,
EXPECT_NO_SELECT_DIALOG,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
// When the download finishes, we should still have one tab.
CheckDownloadUI(browser(), true, true, file);
EXPECT_EQ(1, browser()->tab_count());
CheckDownload(browser(), file, file);
}
// Open a web page in the current tab, then download a file in another tab via
// a Javascript call.
// Verify that we have 2 tabs, and the download shelf is visible in the current
// tab.
//
// The download_page1.html page contains an openNew() function that opens a
// tab and then downloads download-test1.lib.
IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab2) {
ASSERT_TRUE(InitialSetup(false));
// Because it's an HTML link, it should open a web page rather than
// downloading.
FilePath file1(FILE_PATH_LITERAL("download_page1.html"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file1));
// Open a web page and wait.
ui_test_utils::NavigateToURL(browser(), url);
// Download a file in a new tab and wait (via Javascript).
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
DownloadAndWaitWithDisposition(browser(),
GURL("javascript:openNew()"),
CURRENT_TAB,
EXPECT_NO_SELECT_DIALOG,
ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
// When the download finishes, we should have two tabs.
CheckDownloadUI(browser(), true, true, file);
EXPECT_EQ(2, browser()->tab_count());
CheckDownload(browser(), file, file);
}
// Open a web page in the current tab, open another tab via a Javascript call,
// then download a file in the new tab.
// Verify that we have 2 tabs, and the download shelf is visible in the current
// tab.
//
// The download_page2.html page contains an openNew() function that opens a
// tab.
IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab3) {
ASSERT_TRUE(InitialSetup(false));
// Because it's an HTML link, it should open a web page rather than
// downloading.
FilePath file1(FILE_PATH_LITERAL("download_page2.html"));
GURL url1(URLRequestMockHTTPJob::GetMockUrl(file1));
// Open a web page and wait.
ui_test_utils::NavigateToURL(browser(), url1);
// Open a new tab and wait.
ui_test_utils::NavigateToURLWithDisposition(
browser(),
GURL("javascript:openNew()"),
CURRENT_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
EXPECT_EQ(2, browser()->tab_count());
// Download a file and wait.
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
DownloadAndWaitWithDisposition(browser(),
url,
CURRENT_TAB,
EXPECT_NO_SELECT_DIALOG,
ui_test_utils::BROWSER_TEST_NONE);
// When the download finishes, we should have two tabs.
CheckDownloadUI(browser(), true, true, file);
EXPECT_EQ(2, browser()->tab_count());
CheckDownload(browser(), file, file);
}
// Open a web page in the current tab, then download a file via Javascript,
// which will do so in a temporary tab.
// Verify that we have 1 tab, and the download shelf is visible.
//
// The download_page3.html page contains an openNew() function that opens a
// tab with download-test1.lib in the URL. When the URL is determined to be
// a download, the tab is closed automatically.
IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab2) {
ASSERT_TRUE(InitialSetup(false));
// Because it's an HTML link, it should open a web page rather than
// downloading.
FilePath file1(FILE_PATH_LITERAL("download_page3.html"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file1));
// Open a web page and wait.
ui_test_utils::NavigateToURL(browser(), url);
// Download a file and wait.
// The file to download is "download-test1.lib".
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
DownloadAndWaitWithDisposition(browser(),
GURL("javascript:openNew()"),
CURRENT_TAB,
EXPECT_NO_SELECT_DIALOG,
ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
// When the download finishes, we should still have one tab.
CheckDownloadUI(browser(), true, true, file);
EXPECT_EQ(1, browser()->tab_count());
CheckDownload(browser(), file, file);
}
// Open a web page in the current tab, then call Javascript via a button to
// download a file in a new tab, which is closed automatically when the
// download begins.
// Verify that we have 1 tab, and the download shelf is visible.
//
// The download_page4.html page contains a form with download-test1.lib as the
// action.
IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab3) {
ASSERT_TRUE(InitialSetup(false));
// Because it's an HTML link, it should open a web page rather than
// downloading.
FilePath file1(FILE_PATH_LITERAL("download_page4.html"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file1));
// Open a web page and wait.
ui_test_utils::NavigateToURL(browser(), url);
// Download a file in a new tab and wait. The tab will automatically close
// when the download begins.
// The file to download is "download-test1.lib".
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
DownloadAndWaitWithDisposition(
browser(),
GURL("javascript:document.getElementById('form').submit()"),
CURRENT_TAB,
EXPECT_NO_SELECT_DIALOG,
ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
// When the download finishes, we should still have one tab.
CheckDownloadUI(browser(), true, true, file);
EXPECT_EQ(1, browser()->tab_count());
CheckDownload(browser(), file, file);
}
// Download a file in a new window.
// Verify that we have 2 windows, and the download shelf is not visible in the
// first window, but is visible in the second window.
// Close the new window.
// Verify that we have 1 window, and the download shelf is not visible.
//
// Regression test for http://crbug.com/44454
IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) {
ASSERT_TRUE(InitialSetup(false));
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
#if !defined(OS_MACOSX)
// See below.
Browser* first_browser = browser();
#endif
// Download a file in a new window and wait.
DownloadAndWaitWithDisposition(browser(),
url,
NEW_WINDOW,
EXPECT_NO_SELECT_DIALOG,
ui_test_utils::BROWSER_TEST_NONE);
// When the download finishes, the download shelf SHOULD NOT be visible in
// the first window.
ExpectWindowCountAfterDownload(2);
EXPECT_EQ(1, browser()->tab_count());
// Download shelf should close. Download panel stays open on ChromeOS.
CheckDownloadUI(browser(), false, true, file);
// The download shelf SHOULD be visible in the second window.
std::set<Browser*> original_browsers;
original_browsers.insert(browser());
Browser* download_browser =
ui_test_utils::GetBrowserNotInSet(original_browsers);
ASSERT_TRUE(download_browser != NULL);
EXPECT_NE(download_browser, browser());
EXPECT_EQ(1, download_browser->tab_count());
CheckDownloadUI(download_browser, true, true, file);
#if !defined(OS_MACOSX)
// On Mac OS X, the UI window close is delayed until the outermost
// message loop runs. So it isn't possible to get a BROWSER_CLOSED
// notification inside of a test.
ui_test_utils::WindowedNotificationObserver signal(
chrome::NOTIFICATION_BROWSER_CLOSED,
content::Source<Browser>(download_browser));
#endif
// Close the new window.
download_browser->CloseWindow();
#if !defined(OS_MACOSX)
signal.Wait();
EXPECT_EQ(first_browser, browser());
ExpectWindowCountAfterDownload(1);
#endif
EXPECT_EQ(1, browser()->tab_count());
// Download shelf should close. Download panel stays open on ChromeOS.
CheckDownloadUI(browser(), false, true, file);
CheckDownload(browser(), file, file);
}
// Check that downloading multiple (in this case, 2) files does not result in
// corrupted files.
IN_PROC_BROWSER_TEST_F(DownloadTest, MultiDownload) {
ASSERT_TRUE(InitialSetup(false));
EXPECT_EQ(1, browser()->tab_count());
// Create a download, wait until it's started, and confirm
// we're in the expected state.
scoped_ptr<DownloadTestObserver> observer1(
CreateInProgressWaiter(browser(), 1));
ui_test_utils::NavigateToURL(
browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl));
observer1->WaitForFinished();
std::vector<DownloadItem*> downloads;
browser()->profile()->GetDownloadManager()->SearchDownloads(
string16(), &downloads);
ASSERT_EQ(1u, downloads.size());
ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState());
CheckDownloadUI(browser(), true, true, FilePath());
DownloadItem* download1 = downloads[0]; // The only download.
// Start the second download and wait until it's done.
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
// Download the file and wait. We do not expect the Select File dialog.
DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
// Should now have 2 items on the download shelf.
downloads.clear();
browser()->profile()->GetDownloadManager()->SearchDownloads(
string16(), &downloads);
ASSERT_EQ(2u, downloads.size());
// We don't know the order of the downloads.
DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0];
ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState());
ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState());
// The download shelf should be open.
CheckDownloadUI(browser(), true, true, FilePath());
// Allow the first request to finish. We do this by loading a third URL
// in a separate tab.
scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(browser(), 1));
GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl);
ui_test_utils::NavigateToURLWithDisposition(
browser(),
finish_url,
NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
observer2->WaitForFinished(); // Wait for the third request.
// Get the important info from other threads and check it.
scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector());
info->WaitForDataCollected();
EXPECT_EQ(0, info->dfm_pending_downloads());
CheckDownloadUI(browser(), true, true, FilePath());
// The |DownloadItem|s should now be done and have the final file names.
// Verify that the files have the expected data and size.
// |file1| should be full of '*'s, and |file2| should be the same as the
// source file.
FilePath file1(download1->GetFullPath());
size_t file_size1 = URLRequestSlowDownloadJob::kFirstDownloadSize +
URLRequestSlowDownloadJob::kSecondDownloadSize;
std::string expected_contents(file_size1, '*');
ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1));
FilePath file2(download2->GetFullPath());
ASSERT_TRUE(file_util::ContentsEqual(OriginFile(file), file2));
}
IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) {
ASSERT_TRUE(InitialSetup(false));
EXPECT_EQ(1, browser()->tab_count());
// TODO(rdsmith): Fragile code warning! The code below relies on the
// DownloadTestObserver only finishing when the new download has reached
// the state of being entered into the history and being user-visible
// (that's what's required for the Remove to be valid and for the
// download shelf to be visible). By the pure semantics of
// DownloadTestObserver, that's not guaranteed; DownloadItems are created
// in the IN_PROGRESS state and made known to the DownloadManager
// immediately, so any ModelChanged event on the DownloadManager after
// navigation would allow the observer to return. However, the only
// ModelChanged() event the code will currently fire is in
// OnCreateDownloadEntryComplete, at which point the download item will
// be in the state we need.
// The right way to fix this is to create finer grained states on the
// DownloadItem, and wait for the state that indicates the item has been
// entered in the history and made visible in the UI.
// Create a download, wait until it's started, and confirm
// we're in the expected state.
scoped_ptr<DownloadTestObserver> observer(
CreateInProgressWaiter(browser(), 1));
ui_test_utils::NavigateToURL(
browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl));
observer->WaitForFinished();
std::vector<DownloadItem*> downloads;
DownloadManagerForBrowser(browser())->SearchDownloads(
string16(), &downloads);
ASSERT_EQ(1u, downloads.size());
ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState());
CheckDownloadUI(browser(), true, true, FilePath());
// Cancel the download and wait for download system quiesce.
downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
scoped_refptr<DownloadTestFlushObserver> flush_observer(
new DownloadTestFlushObserver(
DownloadManagerForBrowser(browser())));
flush_observer->WaitForFlush();
// Get the important info from other threads and check it.
scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector());
info->WaitForDataCollected();
EXPECT_EQ(0, info->slow_download_job_pending_requests());
EXPECT_EQ(0, info->dfm_pending_downloads());
// Using "DownloadItem::Remove" follows the discard dangerous download path,
// which completely removes the browser from the shelf and closes the shelf
// if it was there. Download panel stays open on ChromeOS.
CheckDownloadUI(browser(), false, true, FilePath());
}
// Confirm a download makes it into the history properly.
IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) {
ASSERT_TRUE(InitialSetup(false));
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
FilePath origin_file(OriginFile(file));
int64 origin_size;
file_util::GetFileSize(origin_file, &origin_size);
// Download the file and wait. We do not expect the Select File dialog.
DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
// Get details of what downloads have just happened.
std::vector<DownloadItem*> downloads;
GetDownloads(browser(), &downloads);
ASSERT_EQ(1u, downloads.size());
int64 db_handle = downloads[0]->GetDbHandle();
// Check state.
EXPECT_EQ(1, browser()->tab_count());
CheckDownload(browser(), file, file);
CheckDownloadUI(browser(), true, true, file);
// Check history results.
DownloadsHistoryDataCollector history_collector(
db_handle,
DownloadManagerForBrowser(browser()));
DownloadPersistentStoreInfo info;
EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle;
EXPECT_EQ(file, info.path.BaseName());
EXPECT_EQ(url, info.url);
// Ignore start_time.
EXPECT_EQ(origin_size, info.received_bytes);
EXPECT_EQ(origin_size, info.total_bytes);
EXPECT_EQ(DownloadItem::COMPLETE, info.state);
}
// Test for crbug.com/14505. This tests that chrome:// urls are still functional
// after download of a file while viewing another chrome://.
IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) {
ASSERT_TRUE(InitialSetup(false));
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file));
GURL flags_url(chrome::kChromeUIFlagsURL);
GURL extensions_url(GURL(std::string(chrome::kChromeUISettingsURL) +
chrome::kExtensionsSubPage));
ui_test_utils::NavigateToURL(browser(), flags_url);
DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG);
ui_test_utils::NavigateToURL(browser(), extensions_url);
TabContents* contents = browser()->GetSelectedTabContents();
ASSERT_TRUE(contents);
bool webui_responded = false;
EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
contents->render_view_host(),
L"",
L"window.domAutomationController.send(window.webui_responded_);",
&webui_responded));
EXPECT_TRUE(webui_responded);
}
// Test for crbug.com/12745. This tests that if a download is initiated from
// a chrome:// page that has registered and onunload handler, the browser
// will be able to close.
IN_PROC_BROWSER_TEST_F(DownloadTest, BrowserCloseAfterDownload) {
ASSERT_TRUE(InitialSetup(false));
GURL downloads_url(chrome::kChromeUIFlagsURL);
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file));
ui_test_utils::NavigateToURL(browser(), downloads_url);
TabContents* contents = browser()->GetSelectedTabContents();
ASSERT_TRUE(contents);
bool result = false;
EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
contents->render_view_host(),
L"",
L"window.onunload = function() { var do_nothing = 0; }; "
L"window.domAutomationController.send(true);",
&result));
EXPECT_TRUE(result);
DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG);
ui_test_utils::WindowedNotificationObserver signal(
chrome::NOTIFICATION_BROWSER_CLOSED,
content::Source<Browser>(browser()));
browser()->CloseWindow();
signal.Wait();
}
// Test to make sure the 'download' attribute in anchor tag is respected.
IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) {
ASSERT_TRUE(InitialSetup(false));
FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
// Create a download, wait until it's complete, and confirm
// we're in the expected state.
scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser(), 1));
ui_test_utils::NavigateToURL(browser(), url);
observer->WaitForFinished();
// Confirm the downloaded data exists.
FilePath downloaded_file = GetDownloadDirectory(browser());
downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png"));
EXPECT_TRUE(file_util::PathExists(downloaded_file));
}
// Test to make sure auto-open works.
IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) {
ASSERT_TRUE(InitialSetup(false));
FilePath file(FILE_PATH_LITERAL("download-autoopen.txt"));
GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
ASSERT_TRUE(
GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file));
// Mock out external opening on all downloads until end of test.
MockDownloadOpeningObserver observer(
DownloadManagerForBrowser(browser()));
DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
// Find the download and confirm it was opened.
std::vector<DownloadItem*> downloads;
DownloadManagerForBrowser(browser())->SearchDownloads(
string16(), &downloads);
ASSERT_EQ(1u, downloads.size());
EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState());
EXPECT_TRUE(downloads[0]->GetOpened());
// As long as we're here, confirmed everything else is good.
EXPECT_EQ(1, browser()->tab_count());
CheckDownload(browser(), file, file);
// Download shelf should close. Download panel stays open on ChromeOS.
CheckDownloadUI(browser(), false, true, FilePath());
}
// Download an extension. Expect a dangerous download warning.
// Deny the download.
IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) {
ASSERT_TRUE(InitialSetup(false));
GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
scoped_ptr<DownloadTestObserver> observer(
DangerousInstallWaiter(
browser(), 1, DownloadItem::CANCELLED,
DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
ui_test_utils::NavigateToURL(browser(), extension_url);
observer->WaitForFinished();
EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
// Download shelf should close. Download panel stays open on ChromeOS.
CheckDownloadUI(browser(), false, true, FilePath());
// Check that the CRX is not installed.
ExtensionService* extension_service =
browser()->profile()->GetExtensionService();
ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
}
// Download an extension. Expect a dangerous download warning.
// Allow the download, deny the install.
IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) {
ASSERT_TRUE(InitialSetup(false));
GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
// Install a mock install UI that simulates a user denying permission to
// finish the install.
download_crx_util::SetMockInstallUIForTesting(
new MockAbortExtensionInstallUI());
scoped_ptr<DownloadTestObserver> observer(
DangerousInstallWaiter(
browser(), 1, DownloadItem::COMPLETE,
DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
ui_test_utils::NavigateToURL(browser(), extension_url);
observer->WaitForFinished();
EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
// Download shelf should close. Download panel stays open on ChromeOS.
CheckDownloadUI(browser(), false, true, FilePath());
// Check that the extension was not installed.
ExtensionService* extension_service =
browser()->profile()->GetExtensionService();
ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
}
// Download an extension. Expect a dangerous download warning.
// Allow the download, and the install.
IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) {
ASSERT_TRUE(InitialSetup(false));
GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
// Install a mock install UI that simulates a user allowing permission to
// finish the install.
download_crx_util::SetMockInstallUIForTesting(
new MockAutoConfirmExtensionInstallUI(browser()->profile()));
scoped_ptr<DownloadTestObserver> observer(
DangerousInstallWaiter(
browser(), 1, DownloadItem::COMPLETE,
DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
ui_test_utils::NavigateToURL(browser(), extension_url);
observer->WaitForFinished();
EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
// Download shelf should close. Download panel stays open on ChromeOS.
CheckDownloadUI(browser(), false, true, FilePath());
// Check that the extension was installed.
ExtensionService* extension_service =
browser()->profile()->GetExtensionService();
ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false));
}
// Test installing a CRX that fails integrity checks.
IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) {
ASSERT_TRUE(InitialSetup(false));
FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx"));
GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file));
// Install a mock install UI that simulates a user allowing permission to
// finish the install, and dismisses any error message. We check that the
// install failed below.
download_crx_util::SetMockInstallUIForTesting(
new MockAutoConfirmExtensionInstallUI(browser()->profile()));
scoped_ptr<DownloadTestObserver> observer(
DangerousInstallWaiter(
browser(), 1, DownloadItem::COMPLETE,
DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
ui_test_utils::NavigateToURL(browser(), extension_url);
observer->WaitForFinished();
// Check that the extension was not installed.
ExtensionService* extension_service =
browser()->profile()->GetExtensionService();
ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
}
// Install a large (100kb) theme.
IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) {
ASSERT_TRUE(InitialSetup(false));
GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath));
// Install a mock install UI that simulates a user allowing permission to
// finish the install.
download_crx_util::SetMockInstallUIForTesting(
new MockAutoConfirmExtensionInstallUI(browser()->profile()));
scoped_ptr<DownloadTestObserver> observer(
DangerousInstallWaiter(
browser(), 1, DownloadItem::COMPLETE,
DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
ui_test_utils::NavigateToURL(browser(), extension_url);
observer->WaitForFinished();
EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
// Download shelf should close. Download panel stays open on ChromeOS.
CheckDownloadUI(browser(), false, true, FilePath());
// Check that the extension was installed.
ExtensionService* extension_service =
browser()->profile()->GetExtensionService();
ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false));
}
// Sort download items by db_handle.
static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) {
return d1->GetDbHandle() < d2->GetDbHandle();
}
// Confirm that searching through the history works properly
IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) {
ASSERT_TRUE(InitialSetup(false));
// Downloads to populate history with.
base::Time current(base::Time::Now());
DownloadPersistentStoreInfo population_entries[] = {
DownloadPersistentStoreInfo(
FilePath(FILE_PATH_LITERAL("/path/to/file")),
GURL("http://www.google.com/fantasy_download"),
GURL(""),
current - base::TimeDelta::FromMinutes(5),
current,
128,
128,
DownloadItem::COMPLETE,
1,
false),
DownloadPersistentStoreInfo(
FilePath(FILE_PATH_LITERAL("/path/to/another_file")),
GURL("http://www.google.com/reality_download"),
GURL(""),
current - base::TimeDelta::FromMinutes(10),
current,
256,
256,
DownloadItem::COMPLETE,
2,
false),
DownloadPersistentStoreInfo(
FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")),
GURL("http://www.izzle.com/not_really_a_download"),
GURL(""),
current - base::TimeDelta::FromMinutes(15),
current,
512,
512,
DownloadItem::COMPLETE,
3,
true)
};
std::vector<DownloadPersistentStoreInfo> entries(
population_entries, population_entries + arraysize(population_entries));
// Populate the manager.
DownloadManager* manager = DownloadManagerForBrowser(browser());
manager->OnPersistentStoreQueryComplete(&entries);
// Do some searches and check the results.
std::vector<DownloadItem*> search_results;
manager->SearchDownloads(string16(), &search_results);
ASSERT_EQ(3u, search_results.size());
std::sort(search_results.begin(), search_results.end(),
DownloadItemSorter);
// We do a full check only once to protect against the data
// somehow getting scrambled on its way into the DownloadItems.
{
DownloadItem* d1 = search_results[0];
DownloadItem* d2 = search_results[1];
DownloadItem* d3 = search_results[2];
EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/file")), d1->GetFullPath());
EXPECT_EQ(GURL("http://www.google.com/fantasy_download"),
d1->GetOriginalUrl());
EXPECT_EQ(current - base::TimeDelta::FromMinutes(5),
d1->GetStartTime());
EXPECT_EQ(current, d1->GetEndTime());
EXPECT_EQ(128, d1->GetReceivedBytes());
EXPECT_EQ(128, d1->GetTotalBytes());
EXPECT_EQ(DownloadItem::COMPLETE, d1->GetState());
EXPECT_EQ(1, d1->GetDbHandle());
EXPECT_FALSE(d1->GetOpened());
EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/another_file")),
d2->GetFullPath());
EXPECT_EQ(GURL("http://www.google.com/reality_download"),
d2->GetOriginalUrl());
EXPECT_EQ(current - base::TimeDelta::FromMinutes(10),
d2->GetStartTime());
EXPECT_EQ(current, d2->GetEndTime());
EXPECT_EQ(256, d2->GetReceivedBytes());
EXPECT_EQ(256, d2->GetTotalBytes());
EXPECT_EQ(DownloadItem::COMPLETE, d2->GetState());
EXPECT_EQ(2, d2->GetDbHandle());
EXPECT_FALSE(d2->GetOpened());
EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")),
d3->GetFullPath());
EXPECT_EQ(GURL("http://www.izzle.com/not_really_a_download"),
d3->GetOriginalUrl());
EXPECT_EQ(current - base::TimeDelta::FromMinutes(15),
d3->GetStartTime());
EXPECT_EQ(current, d3->GetEndTime());
EXPECT_EQ(512, d3->GetReceivedBytes());
EXPECT_EQ(512, d3->GetTotalBytes());
EXPECT_EQ(DownloadItem::COMPLETE, d3->GetState());
EXPECT_EQ(3, d3->GetDbHandle());
EXPECT_TRUE(d3->GetOpened());
}
search_results.clear();
string16 search_input;
manager->SearchDownloads(UTF8ToUTF16("www.google.com"), &search_results);
ASSERT_EQ(2u, search_results.size());
std::sort(search_results.begin(), search_results.end(),
DownloadItemSorter);
EXPECT_EQ(1, search_results[0]->GetDbHandle());
EXPECT_EQ(2, search_results[1]->GetDbHandle());
search_results.clear();
manager->SearchDownloads(UTF8ToUTF16("real"), &search_results);
ASSERT_EQ(2u, search_results.size());
std::sort(search_results.begin(), search_results.end(),
DownloadItemSorter);
EXPECT_EQ(2, search_results[0]->GetDbHandle());
EXPECT_EQ(3, search_results[1]->GetDbHandle());
search_results.clear();
manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results);
ASSERT_EQ(2u, search_results.size());
std::sort(search_results.begin(), search_results.end(),
DownloadItemSorter);
EXPECT_EQ(2, search_results[0]->GetDbHandle());
EXPECT_EQ(3, search_results[1]->GetDbHandle());
search_results.clear();
}
|