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 "chrome/browser/ui/webui/downloads_ui_browsertest.h"');
7 /** @const */ var TOTAL_RESULT_COUNT
= 25;
10 * Test C++ fixture for downloads WebUI testing.
12 * @extends {testing.Test}
14 function DownloadsUIBrowserTest() {}
17 * Base fixture for Downloads WebUI testing.
18 * @extends {testing.Test}
21 function BaseDownloadsWebUITest() {}
23 BaseDownloadsWebUITest
.prototype = {
24 __proto__
: testing
.Test
.prototype,
27 * Browse to the downloads page & call our preLoad().
29 browsePreload
: 'chrome://downloads',
32 typedefCppFixture
: 'DownloadsUIBrowserTest',
35 testGenPreamble: function() {
36 GEN(' SetDeleteAllowed(true);');
40 * Sends TOTAL_RESULT_COUNT fake downloads to the page. This can't be called
41 * in the preLoad, because it requires the global Download object to have
42 * been created by the page.
46 // The entries will begin at 1:00 AM on Sept 2, 2008, and will be spaced
48 var timestamp
= new Date(2008, 9, 2, 1, 0).getTime();
49 for (var i
= 0; i
< TOTAL_RESULT_COUNT
; ++i
) {
50 downloads
.updated(this.createDownload_(i
, timestamp
));
51 timestamp
+= 2 * 60 * 1000; // Next visit is two minutes later.
53 expectEquals(downloads
.size(), TOTAL_RESULT_COUNT
);
57 * Creates a download object to be passed to the page, following the expected
58 * backend format (see downloads_dom_handler.cc).
59 * @param {number} A unique ID for the download.
60 * @param {number} The time the download purportedly started.
61 * @return {!Object} A fake download object.
64 createDownload_: function(id
, timestamp
) {
69 state
: Download
.States
.COMPLETE
,
71 file_path
: '/path/to/file',
72 file_url
: 'http://google.com/' + timestamp
,
73 file_name
: 'download_' + timestamp
,
74 url
: 'http://google.com/' + timestamp
,
75 file_externally_removed
: false,
76 danger_type
: Download
.DangerType
.NOT_DANGEROUS
,
78 since_string
: 'today',
81 progress_status_text
: 'done',
87 * Asserts the correctness of the state of the UI elements
88 * that delete the download history.
89 * @param {boolean} allowDelete True if download history deletion is
90 * allowed and false otherwise.
91 * @param {boolean} expectControlsHidden True if the controls to delete
92 * download history are expected to be hidden and false otherwise.
94 testHelper: function(allowDelete
, expectControlsHidden
) {
95 var clearAllElements
= document
.getElementsByClassName('clear-all-link');
96 var disabledElements
= document
.getElementsByClassName('disabled-link');
97 var removeLinkElements
=
98 document
.getElementsByClassName('control-remove-link');
100 // "Clear all" should be a link only when deletions are allowed.
101 expectEquals(allowDelete
? 1 : 0, clearAllElements
.length
);
103 // There should be no disabled links when deletions are allowed.
104 // On the other hand, when deletions are not allowed, "Clear All"
105 // and all "Remove from list" links should be disabled.
106 expectEquals(allowDelete
? 0 : TOTAL_RESULT_COUNT
+ 1,
107 disabledElements
.length
);
109 // All "Remove from list" items should be links when deletions are allowed.
110 // On the other hand, when deletions are not allowed, all
111 // "Remove from list" items should be text.
112 expectEquals(allowDelete
? TOTAL_RESULT_COUNT
: 0,
113 removeLinkElements
.length
);
116 // "Clear all" should not be hidden.
117 expectFalse(clearAllElements
[0].hidden
);
119 // No "Remove from list" items should be hidden.
120 expectFalse(removeLinkElements
[0].hidden
);
122 expectEquals(expectControlsHidden
, disabledElements
[0].hidden
);
125 // The model is updated synchronously, even though the actual
126 // back-end removal (tested elsewhere) is asynchronous.
128 expectEquals(allowDelete
? 0 : TOTAL_RESULT_COUNT
, downloads
.size());
132 // Test UI when removing entries is allowed.
133 TEST_F('BaseDownloadsWebUITest', 'DeleteAllowed', function() {
134 this.testHelper(true, false);
135 // TODO(pamg): Mock out the back-end calls, so we can also test removing a
141 * Fixture for Downloads WebUI testing when deletions are prohibited.
142 * @extends {BaseDownloadsWebUITest}
145 function DownloadsWebUIDeleteProhibitedTest() {}
147 DownloadsWebUIDeleteProhibitedTest
.prototype = {
148 __proto__
: BaseDownloadsWebUITest
.prototype,
151 testGenPreamble: function() {
152 GEN(' SetDeleteAllowed(false);');
156 // Test UI when removing entries is prohibited.
157 TEST_F('DownloadsWebUIDeleteProhibitedTest', 'DeleteProhibited', function() {
158 this.testHelper(false, false);
159 // TODO(pamg): Mock out the back-end calls, so we can also test removing a
165 * Fixture for Downloads WebUI testing for a supervised user.
166 * @extends {BaseDownloadsWebUITest}
169 function DownloadsWebUIForSupervisedUsersTest() {}
171 DownloadsWebUIForSupervisedUsersTest
.prototype = {
172 __proto__
: BaseDownloadsWebUITest
.prototype,
175 typedefCppFixture
: 'DownloadsWebUIForSupervisedUsersTest',
178 // Test UI for supervised users, removing entries should be disabled
179 // and removal controls should be hidden.
180 TEST_F('DownloadsWebUIForSupervisedUsersTest', 'SupervisedUsers', function() {
181 this.testHelper(false, true);