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();
54 for (var i = 0; i < TOTAL_RESULT_COUNT; ++i) {
55 list.push(this.createDownload(i, timestamp));
56 timestamp += 2 * 60 * 1000; // Next visit is two minutes later.
58 downloads.Manager.updateAll(list);
59 expectEquals(downloads.Manager.size(), TOTAL_RESULT_COUNT);
63 * Creates a download object to be passed to the page, following the expected
64 * backend format (see downloads_dom_handler.cc).
65 * @param {number} A unique ID for the download.
66 * @param {number} The time the download purportedly started.
67 * @return {!Object} A fake download object.
69 createDownload: function(id, timestamp) {
74 state: downloads.Item.States.COMPLETE,
76 file_path: '/path/to/file',
77 file_url: 'http://google.com/' + timestamp,
78 file_name: 'download_' + timestamp,
79 url: 'http://google.com/' + timestamp,
80 file_externally_removed: false,
81 danger_type: downloads.Item.DangerType.NOT_DANGEROUS,
83 since_string: 'today',
86 progress_status_text: 'done',
92 * Simulates getting no results from C++.
94 sendEmptyList: function() {
95 downloads.Manager.updateAll([]);
96 assertEquals(0, downloads.Manager.size());
100 * Check that |element| is showing and contains |text|.
101 * @param {Element} element
102 * @param {string} text
104 checkShowing: function(element, text) {
105 expectFalse(element.hidden);
106 expectNotEquals(-1, element.textContent.indexOf(text));
110 * Asserts the correctness of the state of the UI elements that delete the
112 * @param {boolean} visible True if download deletion UI should be visible.
114 expectDeleteControlsVisible: function(visible) {
115 // "Clear all" should only be showing when deletions are allowed.
116 expectEquals(!visible, $('clear-all').hidden);
118 // "Remove from list" links should only exist when deletions are allowed.
119 var query = '#downloads-display .safe .remove';
122 expectEquals(TOTAL_RESULT_COUNT, document.querySelectorAll(query).length);