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('no_search_results'));
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('no_downloads'));
45 TEST_F('BaseDownloadsWebUITest', 'PauseResumeFocus', function() {
46 var manager = downloads.Manager.getInstance();
47 assertGE(manager.size(), 0);
49 var freshestDownload = this.createdDownloads[0];
50 freshestDownload.state = downloads.Item.States.IN_PROGRESS;
51 freshestDownload.resume = false;
52 downloads.Manager.updateItem(freshestDownload);
54 var node = manager.idMap_[freshestDownload.id].view.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.Item.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 manager = downloads.Manager.getInstance();
81 var numDownloads = manager.size();
82 assertGE(numDownloads, 2);
84 expectEquals(1, datesShowing());
86 var freshestId = this.createdDownloads[0].id;
87 this.createDangerousDownload(freshestId + 1, Date.now());
88 manager.updateAll(this.createdDownloads);
90 expectEquals(numDownloads + 1, manager.size());
91 expectEquals(1, datesShowing());
93 var firstContainer = document.querySelector('.date-container');
94 assertFalse(firstContainer.hidden);
95 expectGT(firstContainer.querySelector('.since').textContent.trim().length, 0);
96 expectGT(firstContainer.querySelector('.date').textContent.trim().length, 0);
99 TEST_F('BaseDownloadsWebUITest', 'EmptyProgressStatusText', function() {
100 this.createdDownloads[0].state = downloads.Item.States.PAUSED;
101 this.createdDownloads[0].progress_status_text = '';
102 downloads.Manager.updateItem(this.createdDownloads[0]); // Might assert().
105 TEST_F('BaseDownloadsWebUITest', 'EmptyLastStatusText', function() {
106 this.createdDownloads[0].state = downloads.Item.States.INTERRUPTED;
107 this.createdDownloads[0].last_reason_text = '';
108 downloads.Manager.updateItem(this.createdDownloads[0]); // Might assert().
113 * @extends {BaseDownloadsWebUITest}
115 function EmptyDownloadsWebUITest() {}
117 EmptyDownloadsWebUITest.prototype = {
118 __proto__: BaseDownloadsWebUITest.prototype,
122 // Doesn't create any fake downloads.
123 assertEquals(0, downloads.Manager.size());
127 TEST_F('EmptyDownloadsWebUITest', 'NoDownloadsMessageShowing', function() {
128 expectTrue($('downloads-display').hidden);
129 var noResults = $('no-downloads-or-results');
130 this.checkShowing(noResults, loadTimeData.getString('no_downloads'));
133 TEST_F('EmptyDownloadsWebUITest', 'NoSearchResultsWithNoDownloads', function() {
134 downloads.Manager.setSearchText('bananas');
135 this.sendEmptyList();
137 expectTrue($('downloads-display').hidden);
138 var noResults = $('no-downloads-or-results');
139 this.checkShowing(noResults, loadTimeData.getString('no_search_results'));
143 * Fixture for Downloads WebUI testing when deletions are prohibited.
144 * @extends {BaseDownloadsWebUITest}
147 function DownloadsWebUIDeleteProhibitedTest() {}
149 DownloadsWebUIDeleteProhibitedTest.prototype = {
150 __proto__: BaseDownloadsWebUITest.prototype,
153 testGenPreamble: function() {
154 GEN(' SetDeleteAllowed(false);');
158 // Test UI when removing entries is prohibited.
159 TEST_F('DownloadsWebUIDeleteProhibitedTest', 'DeleteProhibited', function() {
160 this.expectDeleteControlsVisible(false);
161 // TODO(pamg): Mock out the back-end calls, so we can also test removing a
165 TEST_F('DownloadsWebUIDeleteProhibitedTest', 'ClearLeavesSearch', function() {
166 downloads.Manager.setSearchText('muhahaha');
167 $('clear-all').click();
168 expectGE(downloads.Manager.getInstance().searchText_.length, 0);