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 * Simulates getting no results from C++.
93 sendEmptyList: function() {
95 assertEquals(0, downloads.size());
99 * Check that |element| is showing and contains |text|.
100 * @param {Element} element
101 * @param {string} text
103 checkShowing: function(element, text) {
104 expectFalse(element.hidden);
105 expectNotEquals(-1, element.textContent.indexOf(text));
109 * Asserts the correctness of the state of the UI elements that delete the
111 * @param {boolean} visible True if download deletion UI should be visible.
113 expectDeleteControlsVisible: function(visible) {
114 // "Clear all" should only be showing when deletions are allowed.
115 expectEquals(!visible, $('clear-all').hidden);
117 // "Remove from list" links should only exist when deletions are allowed.
118 expectEquals(visible ? TOTAL_RESULT_COUNT : 0,
119 document.querySelectorAll('.control-remove-link').length);