Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/browser/ui/webui/downloads_ui_browsertest.js

Issue 355233002: Fix build when ENABLE_MANAGED_USERS is not defined (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Include missing browsertest .js file in chrome_tests.gypi Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 GEN_INCLUDE(['downloads_ui_browsertest_base.js']);
5 GEN('#include "chrome/browser/ui/webui/downloads_ui_browsertest.h"'); 6 GEN('#include "chrome/browser/ui/webui/downloads_ui_browsertest.h"');
6 7
7 /** @const */ var TOTAL_RESULT_COUNT = 25;
8
9 /**
10 * Test C++ fixture for downloads WebUI testing.
11 * @constructor
12 * @extends {testing.Test}
13 */
14 function DownloadsUIBrowserTest() {}
15
16 /**
17 * Base fixture for Downloads WebUI testing.
18 * @extends {testing.Test}
19 * @constructor
20 */
21 function BaseDownloadsWebUITest() {}
22
23 BaseDownloadsWebUITest.prototype = {
24 __proto__: testing.Test.prototype,
25
26 /**
27 * Browse to the downloads page & call our preLoad().
28 */
29 browsePreload: 'chrome://downloads/',
30
31 /** @override */
32 typedefCppFixture: 'DownloadsUIBrowserTest',
33
34 /** @override */
35 testGenPreamble: function() {
36 GEN(' SetDeleteAllowed(true);');
37 },
38
39 /** @override */
40 runAccessibilityChecks: true,
41
42 /** @override */
43 accessibilityIssuesAreErrors: true,
44
45 /**
46 * Sends TOTAL_RESULT_COUNT fake downloads to the page. This can't be called
47 * in the preLoad, because it requires the global Download object to have
48 * been created by the page.
49 * @override
50 */
51 setUp: function() {
52 // The entries will begin at 1:00 AM on Sept 2, 2008, and will be spaced
53 // two minutes apart.
54 var timestamp = new Date(2008, 9, 2, 1, 0).getTime();
55 for (var i = 0; i < TOTAL_RESULT_COUNT; ++i) {
56 downloads.updated(this.createDownload_(i, timestamp));
57 timestamp += 2 * 60 * 1000; // Next visit is two minutes later.
58 }
59 expectEquals(downloads.size(), TOTAL_RESULT_COUNT);
60 },
61
62 /**
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.
68 * @private
69 */
70 createDownload_: function(id, timestamp) {
71 return {
72 id: id,
73 started: timestamp,
74 otr: false,
75 state: Download.States.COMPLETE,
76 retry: false,
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: Download.DangerType.NOT_DANGEROUS,
83 last_reason_text: '',
84 since_string: 'today',
85 date_string: 'today',
86 percent: 100,
87 progress_status_text: 'done',
88 received: 128,
89 };
90 },
91
92 /**
93 * Asserts the correctness of the state of the UI elements
94 * that delete the download history.
95 * @param {boolean} allowDelete True if download history deletion is
96 * allowed and false otherwise.
97 * @param {boolean} expectControlsHidden True if the controls to delete
98 * download history are expected to be hidden and false otherwise.
99 */
100 testHelper: function(allowDelete, expectControlsHidden) {
101 var clearAllElements = document.getElementsByClassName('clear-all-link');
102 var disabledElements = document.getElementsByClassName('disabled-link');
103 var removeLinkElements =
104 document.getElementsByClassName('control-remove-link');
105
106 // "Clear all" should be a link only when deletions are allowed.
107 expectEquals(allowDelete ? 1 : 0, clearAllElements.length);
108
109 // There should be no disabled links when deletions are allowed.
110 // On the other hand, when deletions are not allowed, "Clear All"
111 // and all "Remove from list" links should be disabled.
112 expectEquals(allowDelete ? 0 : TOTAL_RESULT_COUNT + 1,
113 disabledElements.length);
114
115 // All "Remove from list" items should be links when deletions are allowed.
116 // On the other hand, when deletions are not allowed, all
117 // "Remove from list" items should be text.
118 expectEquals(allowDelete ? TOTAL_RESULT_COUNT : 0,
119 removeLinkElements.length);
120
121 if (allowDelete) {
122 // "Clear all" should not be hidden.
123 expectFalse(clearAllElements[0].hidden);
124
125 // No "Remove from list" items should be hidden.
126 expectFalse(removeLinkElements[0].hidden);
127 } else {
128 expectEquals(expectControlsHidden, disabledElements[0].hidden);
129 }
130
131 // The model is updated synchronously, even though the actual
132 // back-end removal (tested elsewhere) is asynchronous.
133 clearAll();
134 expectEquals(allowDelete ? 0 : TOTAL_RESULT_COUNT, downloads.size());
135 },
136 };
137
138 // Test UI when removing entries is allowed. 8 // Test UI when removing entries is allowed.
139 TEST_F('BaseDownloadsWebUITest', 'DeleteAllowed', function() { 9 TEST_F('BaseDownloadsWebUITest', 'DeleteAllowed', function() {
140 this.testHelper(true, false); 10 this.testHelper(true, false);
141 // TODO(pamg): Mock out the back-end calls, so we can also test removing a 11 // TODO(pamg): Mock out the back-end calls, so we can also test removing a
142 // single item. 12 // single item.
143 testDone(); 13 testDone();
144 }); 14 });
145 15
146 // Test that clicking <a href=#> doesn't actually go to #. 16 // Test that clicking <a href=#> doesn't actually go to #.
147 TEST_F('BaseDownloadsWebUITest', 'PoundLinkClicksDontChangeUrl', function() { 17 TEST_F('BaseDownloadsWebUITest', 'PoundLinkClicksDontChangeUrl', function() {
(...skipping 19 matching lines...) Expand all
167 }, 37 },
168 }; 38 };
169 39
170 // Test UI when removing entries is prohibited. 40 // Test UI when removing entries is prohibited.
171 TEST_F('DownloadsWebUIDeleteProhibitedTest', 'DeleteProhibited', function() { 41 TEST_F('DownloadsWebUIDeleteProhibitedTest', 'DeleteProhibited', function() {
172 this.testHelper(false, false); 42 this.testHelper(false, false);
173 // TODO(pamg): Mock out the back-end calls, so we can also test removing a 43 // TODO(pamg): Mock out the back-end calls, so we can also test removing a
174 // single item. 44 // single item.
175 testDone(); 45 testDone();
176 }); 46 });
177
178 /**
179 * Fixture for Downloads WebUI testing for a supervised user.
180 * @extends {BaseDownloadsWebUITest}
181 * @constructor
182 */
183 function DownloadsWebUIForSupervisedUsersTest() {}
184
185 DownloadsWebUIForSupervisedUsersTest.prototype = {
186 __proto__: BaseDownloadsWebUITest.prototype,
187
188 /** @override */
189 typedefCppFixture: 'DownloadsWebUIForSupervisedUsersTest',
190 };
191
192 // Test UI for supervised users, removing entries should be disabled
193 // and removal controls should be hidden.
194 TEST_F('DownloadsWebUIForSupervisedUsersTest', 'SupervisedUsers', function() {
195 this.testHelper(false, true);
196 testDone();
197 });
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/downloads_ui_browsertest.cc ('k') | chrome/browser/ui/webui/downloads_ui_browsertest_base.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698