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 this.createdDownloads = [];
52 // The entries will begin at 1:00 AM on Sept 2, 2008, and will be spaced
54 var timestamp = new Date(2008, 9, 2, 1, 0).getTime();
55 for (var i = 0; i < TOTAL_RESULT_COUNT; ++i) {
56 this.createDownload(i, timestamp);
57 timestamp += 2 * 60 * 1000; // Next visit is two minutes later.
59 downloads.Manager.updateAll(this.createdDownloads);
60 expectEquals(downloads.Manager.size(), TOTAL_RESULT_COUNT);
64 * Creates a download object to be passed to the page, following the expected
65 * backend format (see downloads_dom_handler.cc).
66 * @param {number} id A unique ID for the download.
67 * @param {number} timestamp The time the download purportedly started.
68 * @return {!Object} A fake download object.
70 createDownload: function(id, timestamp) {
71 this.createdDownloads.unshift({
75 state: downloads.States.COMPLETE,
77 file_path: '/path/to/file',
78 file_url: 'http://google.com/' + timestamp,
79 file_name: 'download_' + timestamp,
80 url: 'http://google.com/' + timestamp,
81 file_externally_removed: false,
82 danger_type: downloads.DangerType.NOT_DANGEROUS,
84 since_string: 'today',
87 progress_status_text: 'done',
90 return this.createdDownloads[0];
94 * Creates a dangerous download object. See downloads_dom_handler.cc.
95 * @param {number} id The ID of the download.
96 * @param {number} timestamp The time this download started.
97 * @return {!Object} A fake, dangerous download object.
99 createDangerousDownload: function(id, timestamp) {
100 this.createdDownloads.unshift({
104 state: downloads.States.DANGEROUS,
106 file_path: '/oh/noes.jpg.exe',
107 file_url: 'http://evil.com/cute/kittens' + timestamp,
108 file_name: 'evil.' + timestamp + '.jar',
109 file_url: 'http://evil.com/cute/kittens' + timestamp,
110 file_externally_removed: false,
111 danger_type: downloads.DangerType.DANGEROUS_FILE,
112 last_reason_text: '',
113 since_string: 'today',
114 date_string: 'today',
116 progress_status_text: '',
119 return this.createdDownloads[0];
123 * Simulates getting no results from C++.
125 sendEmptyList: function() {
126 downloads.Manager.updateAll([]);
127 assertEquals(0, downloads.Manager.size());
131 * Check that |element| is showing and contains |text|.
132 * @param {Element} element
133 * @param {string} text
135 checkShowing: function(element, text) {
136 expectFalse(element.hidden);
137 expectNotEquals(-1, element.textContent.indexOf(text));
141 * Asserts the correctness of the state of the UI elements that delete the
143 * @param {boolean} visible True if download deletion UI should be visible.
145 expectDeleteControlsVisible: function(visible) {
146 // "Clear all" should only be showing when deletions are allowed.
147 expectEquals(!visible, $('clear-all').hidden);
149 // "Remove from list" links should only exist when deletions are allowed.
150 var query = '#downloads-display .safe .remove';
153 expectEquals(TOTAL_RESULT_COUNT, document.querySelectorAll(query).length);