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

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

Issue 23851007: Hide the "downloads" page policy disabled UI elements from supervised users (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: .. Created 7 years, 3 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
« no previous file with comments | « chrome/browser/ui/webui/downloads_ui_browsertest.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/ui/webui/downloads_ui_browsertest.h"'); 5 GEN('#include "chrome/browser/ui/webui/downloads_ui_browsertest.h"');
6 6
7 /** @const */ var TOTAL_RESULT_COUNT = 25; 7 /** @const */ var TOTAL_RESULT_COUNT = 25;
8 8
9 /** 9 /**
10 * Test C++ fixture for downloads WebUI testing. 10 * Test C++ fixture for downloads WebUI testing.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 download.danger_type = Download.DangerType.NOT_DANGEROUS; 74 download.danger_type = Download.DangerType.NOT_DANGEROUS;
75 download.last_reason_text = ''; 75 download.last_reason_text = '';
76 download.since_string = 'today'; 76 download.since_string = 'today';
77 download.date_string = 'today'; 77 download.date_string = 'today';
78 download.percent = 100; 78 download.percent = 100;
79 download.progress_status_text = 'done'; 79 download.progress_status_text = 'done';
80 download.received = 128; 80 download.received = 128;
81 81
82 return download; 82 return download;
83 }, 83 },
84
85 /**
86 * Asserts the correctness of the state of the UI elements
87 * that delete the download history.
88 * @param {boolean} allowDelete True if download history deletion is
89 * allowed and false otherwise.
90 * @param {boolean} expectControlsHidden True if the controls to delete
91 * download history are expected to be hidden and false otherwise.
92 */
93 testHelper: function(allowDelete, expectControlsHidden) {
94 var clearAllElements = document.getElementsByClassName('clear-all-link');
95 var disabledElements = document.getElementsByClassName('disabled-link');
96 var removeLinkElements = document.getElementsByClassName(
Bernhard Bauer 2013/09/06 17:12:20 Nit: breaking after the equals sign might make it
ibra 2013/09/09 09:40:20 Done.
97 'control-remove-link');
98 if (allowDelete) {
99 // "Clear all" should be a link.
100 expectEquals(1, clearAllElements.length);
101 // "Clear all" should not be hidden.
Bernhard Bauer 2013/09/06 17:12:20 Nit: empty lines before comments please.
ibra 2013/09/09 09:40:20 Done.
102 expectEquals(expectControlsHidden, clearAllElements[0].hidden);
Bernhard Bauer 2013/09/06 17:12:20 You're passing in a flag that says whether you exp
ibra 2013/09/09 09:40:20 Done.
103 // There should be no disabled "links".
104 expectEquals(0, disabledElements.length);
105 // All "Remove from list" items should be links.
106 expectEquals(TOTAL_RESULT_COUNT, removeLinkElements.length);
107 // All "Remove from list" items should not be hidden.
108 expectEquals(expectControlsHidden, removeLinkElements[0].hidden);
109 // The model is updated synchronously, even though the actual
110 // back-end removal (tested elsewhere) is asynchronous.
111 clearAll();
112 expectEquals(0, downloads.size());
113 } else {
114 // "Clear all" should not be a link.
115 expectEquals(0, clearAllElements.length);
Bernhard Bauer 2013/09/06 17:12:20 You could maybe pull some more expectations out (i
ibra 2013/09/09 09:40:20 Done.
116 // "Clear all" and all "Remove from list" links should be disabled.
117 expectEquals(TOTAL_RESULT_COUNT + 1, disabledElements.length);
118 expectEquals(expectControlsHidden, disabledElements[0].hidden);
119 // All "Remove from list" should not be links; just text.
120 expectEquals(0, removeLinkElements.length);
121 // Attempting to remove items anyway should fail.
122 // The model would have been cleared synchronously, even though the actual
123 // back-end removal (also disabled, but tested elsewhere) is asynchronous.
124 clearAll();
125 expectEquals(TOTAL_RESULT_COUNT, downloads.size());
126 }
127 },
84 }; 128 };
85 129
86 // Test UI when removing entries is allowed. 130 // Test UI when removing entries is allowed.
87 TEST_F('BaseDownloadsWebUITest', 'deleteAllowed', function() { 131 TEST_F('BaseDownloadsWebUITest', 'DeleteAllowed', function() {
88 // "Clear all" should be a link. 132 this.testHelper(true, false);
89 var clearAllHolder = document.querySelectorAll('#clear-all-holder > a');
90 expectEquals(clearAllHolder.length, 1);
91
92 // All the "Remove from list" items should be links.
93 var removeLinks = document.querySelectorAll(
94 '.controls > a.control-remove-link');
95 expectEquals(removeLinks.length, TOTAL_RESULT_COUNT);
96
97 // There should be no disabled text "links".
98 var disabledLinks = document.querySelectorAll('.disabled-link');
99 expectEquals(disabledLinks.length, 0);
100
101 // The model is updated synchronously, even though the actual back-end removal
102 // (tested elsewhere) is asynchronous.
103 clearAll();
104 expectEquals(downloads.size(), 0);
105
106 // TODO(pamg): Mock out the back-end calls, so we can also test removing a 133 // TODO(pamg): Mock out the back-end calls, so we can also test removing a
107 // single item. 134 // single item.
108 testDone(); 135 testDone();
109 }); 136 });
110 137
111 /** 138 /**
112 * Fixture for Downloads WebUI testing when deletions are prohibited. 139 * Fixture for Downloads WebUI testing when deletions are prohibited.
113 * @extends {BaseDownloadsWebUITest} 140 * @extends {BaseDownloadsWebUITest}
114 * @constructor 141 * @constructor
115 */ 142 */
116 function DownloadsWebUIDeleteProhibitedTest() {} 143 function DownloadsWebUIDeleteProhibitedTest() {}
117 144
118 DownloadsWebUIDeleteProhibitedTest.prototype = { 145 DownloadsWebUIDeleteProhibitedTest.prototype = {
119 __proto__: BaseDownloadsWebUITest.prototype, 146 __proto__: BaseDownloadsWebUITest.prototype,
120 147
121 /** @override */ 148 /** @override */
122 testGenPreamble: function() { 149 testGenPreamble: function() {
123 GEN(' SetDeleteAllowed(false);'); 150 GEN(' SetDeleteAllowed(false);');
124 }, 151 },
125 }; 152 };
126 153
127 // Test UI when removing entries is prohibited. 154 // Test UI when removing entries is prohibited.
128 TEST_F('DownloadsWebUIDeleteProhibitedTest', 'deleteProhibited', function() { 155 TEST_F('DownloadsWebUIDeleteProhibitedTest', 'DeleteProhibited', function() {
129 // "Clear all" should not be a link. 156 this.testHelper(false, false);
130 var clearAllText = document.querySelectorAll(
131 '#clear-all-holder.disabled-link');
132 expectEquals(clearAllText.length, 1);
133 expectEquals(clearAllText[0].nodeName, 'SPAN');
134
135 // There should be no "Clear all" link.
136 var clearAllLinks = document.querySelectorAll('clear-all-link');
137 expectEquals(clearAllLinks.length, 0);
138
139 // All the "Remove from list" items should be text. Check only one, to avoid
140 // spam in case of failure.
141 var removeTexts = document.querySelectorAll('.controls > .disabled-link');
142 expectEquals(removeTexts.length, TOTAL_RESULT_COUNT);
143 expectEquals(removeTexts[0].nodeName, 'SPAN');
144
145 // There should be no "Remove from list" links.
146 var removeLinks = document.querySelectorAll('control-remove-link');
147 expectEquals(removeLinks.length, 0);
148
149 // Attempting to remove items anyway should fail.
150 // The model would have been cleared synchronously, even though the actual
151 // back-end removal (also disabled, but tested elsewhere) is asynchronous.
152 clearAll();
153 expectEquals(downloads.size(), TOTAL_RESULT_COUNT);
154
155 // TODO(pamg): Mock out the back-end calls, so we can also test removing a 157 // TODO(pamg): Mock out the back-end calls, so we can also test removing a
156 // single item. 158 // single item.
157 testDone(); 159 testDone();
158 }); 160 });
161
162 /**
163 * Fixture for Downloads WebUI testing for a supervised user.
164 * @extends {DownloadsWebUIDeleteProhibitedTest}
165 * @constructor
166 */
167 function DownloadsWebUIForSupervisedUsersTest() {}
168
169 DownloadsWebUIForSupervisedUsersTest.prototype = {
170 __proto__: DownloadsWebUIDeleteProhibitedTest.prototype,
171
172 /** @override */
173 testGenPreamble: function() {
174 GEN(' ChangeProfileToSupervised();');
175 },
176 };
177
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();
183 });
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/downloads_ui_browsertest.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698