1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 GEN_INCLUDE(['downloads_ui_browsertest_base.js']);
6 GEN('#include "chrome/browser/ui/webui/downloads_ui_browsertest.h"');
8 // Test UI when removing entries is allowed.
9 TEST_F('BaseDownloadsWebUITest', 'DeleteAllowed', function() {
10 this.expectDeleteControlsVisible(true);
11 // TODO(pamg): Mock out the back-end calls, so we can also test removing a
15 TEST_F('BaseDownloadsWebUITest', 'NoResultsHiddenWhenDownloads', function() {
16 assertNotEquals(0, downloads
.Manager
.size());
17 expectFalse($('downloads-display').hidden
);
18 expectTrue($('no-downloads-or-results').hidden
);
21 TEST_F('BaseDownloadsWebUITest', 'NoSearchResultsShown', function() {
22 expectFalse($('downloads-display').hidden
);
23 var noResults
= $('no-downloads-or-results');
24 expectTrue(noResults
.hidden
);
26 downloads
.Manager
.setSearchText('just try to search for me!');
29 expectTrue($('downloads-display').hidden
);
30 this.checkShowing(noResults
, loadTimeData
.getString('noSearchResults'));
33 TEST_F('BaseDownloadsWebUITest', 'NoDownloadsAfterClearAll', function() {
34 expectFalse($('downloads-display').hidden
);
35 var noResults
= $('no-downloads-or-results');
36 expectTrue(noResults
.hidden
);
38 $('clear-all').click();
41 expectTrue($('downloads-display').hidden
);
42 this.checkShowing(noResults
, loadTimeData
.getString('noDownloads'));
45 TEST_F('BaseDownloadsWebUITest', 'PauseResumeFocus', function() {
46 assertGE(downloads
.Manager
.size(), 0);
48 var freshestDownload
= this.createdDownloads
[0];
49 freshestDownload
.state
= downloads
.States
.IN_PROGRESS
;
50 freshestDownload
.resume
= false;
51 downloads
.Manager
.updateItem(freshestDownload
);
53 var manager
= downloads
.Manager
.getInstance();
54 var node
= manager
.idMap_
[freshestDownload
.id
].node
;
55 var pause
= node
.querySelector('.pause');
56 var resume
= node
.querySelector('.resume');
58 expectFalse(pause
.hidden
);
59 expectTrue(resume
.hidden
);
60 // Move the focus to "Pause" then pretend the download was resumed. The focus
61 // should move to the equivalent button ("Resume" in this case).
63 assertEquals(document
.activeElement
, pause
);
65 freshestDownload
.state
= downloads
.States
.PAUSED
;
66 freshestDownload
.resume
= true;
67 downloads
.Manager
.updateItem(freshestDownload
);
69 expectTrue(pause
.hidden
);
70 expectFalse(resume
.hidden
);
71 expectEquals(document
.activeElement
, resume
);
74 TEST_F('BaseDownloadsWebUITest', 'DatesCollapse', function() {
75 function datesShowing() {
76 var displayDiv
= $('downloads-display');
77 return displayDiv
.querySelectorAll('.date-container:not([hidden])').length
;
80 var numDownloads
= downloads
.Manager
.size();
81 assertGE(numDownloads
, 2);
83 expectEquals(1, datesShowing());
85 var freshestId
= this.createdDownloads
[0].id
;
86 this.createDangerousDownload(freshestId
+ 1, Date
.now());
87 downloads
.Manager
.updateAll(this.createdDownloads
);
89 expectEquals(numDownloads
+ 1, downloads
.Manager
.size());
90 expectEquals(1, datesShowing());
92 var firstContainer
= document
.querySelector('.date-container');
93 assertFalse(firstContainer
.hidden
);
94 expectGT(firstContainer
.querySelector('.since').textContent
.trim().length
, 0);
95 expectGT(firstContainer
.querySelector('.date').textContent
.trim().length
, 0);
98 TEST_F('BaseDownloadsWebUITest', 'EmptyProgressStatusText', function() {
99 this.createdDownloads
[0].state
= downloads
.States
.PAUSED
;
100 this.createdDownloads
[0].progress_status_text
= '';
101 downloads
.Manager
.updateItem(this.createdDownloads
[0]); // Might assert().
104 TEST_F('BaseDownloadsWebUITest', 'EmptyLastStatusText', function() {
105 this.createdDownloads
[0].state
= downloads
.States
.INTERRUPTED
;
106 this.createdDownloads
[0].last_reason_text
= '';
107 downloads
.Manager
.updateItem(this.createdDownloads
[0]); // Might assert().
112 * @extends {BaseDownloadsWebUITest}
114 function EmptyDownloadsWebUITest() {}
116 EmptyDownloadsWebUITest
.prototype = {
117 __proto__
: BaseDownloadsWebUITest
.prototype,
121 // Doesn't create any fake downloads.
122 assertEquals(0, downloads
.Manager
.size());
126 TEST_F('EmptyDownloadsWebUITest', 'NoDownloadsMessageShowing', function() {
127 expectTrue($('downloads-display').hidden
);
128 var noResults
= $('no-downloads-or-results');
129 this.checkShowing(noResults
, loadTimeData
.getString('noDownloads'));
132 TEST_F('EmptyDownloadsWebUITest', 'NoSearchResultsWithNoDownloads', function() {
133 downloads
.Manager
.setSearchText('bananas');
134 this.sendEmptyList();
136 expectTrue($('downloads-display').hidden
);
137 var noResults
= $('no-downloads-or-results');
138 this.checkShowing(noResults
, loadTimeData
.getString('noSearchResults'));
142 * Fixture for Downloads WebUI testing when deletions are prohibited.
143 * @extends {BaseDownloadsWebUITest}
146 function DownloadsWebUIDeleteProhibitedTest() {}
148 DownloadsWebUIDeleteProhibitedTest
.prototype = {
149 __proto__
: BaseDownloadsWebUITest
.prototype,
152 testGenPreamble: function() {
153 GEN(' SetDeleteAllowed(false);');
157 // Test UI when removing entries is prohibited.
158 TEST_F('DownloadsWebUIDeleteProhibitedTest', 'DeleteProhibited', function() {
159 this.expectDeleteControlsVisible(false);
160 // TODO(pamg): Mock out the back-end calls, so we can also test removing a
164 TEST_F('DownloadsWebUIDeleteProhibitedTest', 'ClearLeavesSearch', function() {
165 downloads
.Manager
.setSearchText('muhahaha');
166 $('clear-all').click();
167 expectGE(downloads
.Manager
.getInstance().searchText_
.length
, 0);