1 // Copyright 2014 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 /** @const */ var TOTAL_RESULT_COUNT
= 25;
8 * Test C++ fixture for downloads WebUI testing.
10 * @extends {testing.Test}
12 function DownloadsUIBrowserTest() {}
15 * Base fixture for Downloads WebUI testing.
16 * @extends {testing.Test}
19 function BaseDownloadsWebUITest() {}
21 BaseDownloadsWebUITest
.prototype = {
22 __proto__
: testing
.Test
.prototype,
25 * Browse to the downloads page & call our preLoad().
27 browsePreload
: 'chrome://downloads/',
30 typedefCppFixture
: 'DownloadsUIBrowserTest',
33 testGenPreamble: function() {
34 GEN(' SetDeleteAllowed(true);');
38 runAccessibilityChecks
: true,
41 accessibilityIssuesAreErrors
: true,
44 * Sends TOTAL_RESULT_COUNT fake downloads to the page. This can't be called
45 * in the preLoad, because it requires the global Download object to have
46 * been created by the page.
50 // The entries will begin at 1:00 AM on Sept 2, 2008, and will be spaced
52 var timestamp
= new Date(2008, 9, 2, 1, 0).getTime();
53 for (var i
= 0; i
< TOTAL_RESULT_COUNT
; ++i
) {
54 downloads
.updated(this.createDownload_(i
, timestamp
));
55 timestamp
+= 2 * 60 * 1000; // Next visit is two minutes later.
57 expectEquals(downloads
.size(), TOTAL_RESULT_COUNT
);
61 * Creates a download object to be passed to the page, following the expected
62 * backend format (see downloads_dom_handler.cc).
63 * @param {number} A unique ID for the download.
64 * @param {number} The time the download purportedly started.
65 * @return {!Object} A fake download object.
68 createDownload_: function(id
, timestamp
) {
73 state
: Download
.States
.COMPLETE
,
75 file_path
: '/path/to/file',
76 file_url
: 'http://google.com/' + timestamp
,
77 file_name
: 'download_' + timestamp
,
78 url
: 'http://google.com/' + timestamp
,
79 file_externally_removed
: false,
80 danger_type
: Download
.DangerType
.NOT_DANGEROUS
,
82 since_string
: 'today',
85 progress_status_text
: 'done',
91 * Asserts the correctness of the state of the UI elements
92 * that delete the download history.
93 * @param {boolean} allowDelete True if download history deletion is
94 * allowed and false otherwise.
95 * @param {boolean} expectControlsHidden True if the controls to delete
96 * download history are expected to be hidden and false otherwise.
98 testHelper: function(allowDelete
, expectControlsHidden
) {
99 var clearAllElements
= document
.getElementsByClassName('clear-all-link');
100 var disabledElements
= document
.getElementsByClassName('disabled-link');
101 var removeLinkElements
=
102 document
.getElementsByClassName('control-remove-link');
104 // "Clear all" should be a link only when deletions are allowed.
105 expectEquals(allowDelete
? 1 : 0, clearAllElements
.length
);
107 // There should be no disabled links when deletions are allowed.
108 // On the other hand, when deletions are not allowed, "Clear All"
109 // and all "Remove from list" links should be disabled.
110 expectEquals(allowDelete
? 0 : TOTAL_RESULT_COUNT
+ 1,
111 disabledElements
.length
);
113 // All "Remove from list" items should be links when deletions are allowed.
114 // On the other hand, when deletions are not allowed, all
115 // "Remove from list" items should be text.
116 expectEquals(allowDelete
? TOTAL_RESULT_COUNT
: 0,
117 removeLinkElements
.length
);
120 // "Clear all" should not be hidden.
121 expectFalse(clearAllElements
[0].hidden
);
123 // No "Remove from list" items should be hidden.
124 expectFalse(removeLinkElements
[0].hidden
);
126 expectEquals(expectControlsHidden
, disabledElements
[0].hidden
);
129 // The model is updated synchronously, even though the actual
130 // back-end removal (tested elsewhere) is asynchronous.
132 expectEquals(allowDelete
? 0 : TOTAL_RESULT_COUNT
, downloads
.size());