Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / ui / webui / downloads_ui_browsertest.js
blob1cd786a13bc26139bb8d223454e85ed99c0d0030
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;
9 /**
10 * Test C++ fixture for downloads WebUI testing.
11 * @constructor
12 * @extends {testing.Test}
14 function DownloadsUIBrowserTest() {}
16 /**
17 * Base fixture for Downloads WebUI testing.
18 * @extends {testing.Test}
19 * @constructor
21 function BaseDownloadsWebUITest() {}
23 BaseDownloadsWebUITest.prototype = {
24 __proto__: testing.Test.prototype,
26 /**
27 * Browse to the downloads page & call our preLoad().
29 browsePreload: 'chrome://downloads',
31 /** @override */
32 typedefCppFixture: 'DownloadsUIBrowserTest',
34 /** @override */
35 testGenPreamble: function() {
36 GEN(' SetDeleteAllowed(true);');
39 /**
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.
43 * @override
45 setUp: function() {
46 // The entries will begin at 1:00 AM on Sept 2, 2008, and will be spaced
47 // two minutes apart.
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);
56 /**
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.
62 * @private
64 createDownload_: function(id, timestamp) {
65 return {
66 id: id,
67 started: timestamp,
68 otr: false,
69 state: Download.States.COMPLETE,
70 retry: false,
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,
77 last_reason_text: '',
78 since_string: 'today',
79 date_string: 'today',
80 percent: 100,
81 progress_status_text: 'done',
82 received: 128,
86 /**
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);
115 if (allowDelete) {
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);
121 } else {
122 expectEquals(expectControlsHidden, disabledElements[0].hidden);
125 // The model is updated synchronously, even though the actual
126 // back-end removal (tested elsewhere) is asynchronous.
127 clearAll();
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
136 // single item.
137 testDone();
141 * Fixture for Downloads WebUI testing when deletions are prohibited.
142 * @extends {BaseDownloadsWebUITest}
143 * @constructor
145 function DownloadsWebUIDeleteProhibitedTest() {}
147 DownloadsWebUIDeleteProhibitedTest.prototype = {
148 __proto__: BaseDownloadsWebUITest.prototype,
150 /** @override */
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
160 // single item.
161 testDone();
165 * Fixture for Downloads WebUI testing for a supervised user.
166 * @extends {BaseDownloadsWebUITest}
167 * @constructor
169 function DownloadsWebUIForSupervisedUsersTest() {}
171 DownloadsWebUIForSupervisedUsersTest.prototype = {
172 __proto__: BaseDownloadsWebUITest.prototype,
174 /** @override */
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);
182 testDone();