OLD | NEW |
---|---|
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 download.received = 128; | 80 download.received = 128; |
81 | 81 |
82 return download; | 82 return download; |
83 }, | 83 }, |
84 }; | 84 }; |
85 | 85 |
86 // Test UI when removing entries is allowed. | 86 // Test UI when removing entries is allowed. |
87 TEST_F('BaseDownloadsWebUITest', 'deleteAllowed', function() { | 87 TEST_F('BaseDownloadsWebUITest', 'deleteAllowed', function() { |
88 // "Clear all" should be a link. | 88 // "Clear all" should be a link. |
89 var clearAllHolder = document.querySelectorAll('#clear-all-holder > a'); | 89 var clearAllHolder = document.querySelectorAll('#clear-all-holder > a'); |
90 expectEquals(clearAllHolder.length, 1); | 90 expectEquals(1, clearAllHolder.length); |
91 | 91 |
92 // All the "Remove from list" items should be links. | 92 // All the "Remove from list" items should be links. |
93 var removeLinks = document.querySelectorAll( | 93 var removeLinks = document.querySelectorAll( |
94 '.controls > a.control-remove-link'); | 94 '.controls > a.control-remove-link'); |
95 expectEquals(removeLinks.length, TOTAL_RESULT_COUNT); | 95 expectEquals(TOTAL_RESULT_COUNT, removeLinks.length); |
96 | 96 |
97 // There should be no disabled text "links". | 97 // There should be no disabled text "links". |
98 var disabledLinks = document.querySelectorAll('.disabled-link'); | 98 var disabledLinks = document.querySelectorAll('.disabled-link'); |
99 expectEquals(disabledLinks.length, 0); | 99 expectEquals(0, disabledLinks.length); |
100 | 100 |
101 // The model is updated synchronously, even though the actual back-end removal | 101 // The model is updated synchronously, even though the actual back-end removal |
102 // (tested elsewhere) is asynchronous. | 102 // (tested elsewhere) is asynchronous. |
103 clearAll(); | 103 clearAll(); |
104 expectEquals(downloads.size(), 0); | 104 expectEquals(0, downloads.size()); |
105 | 105 |
106 // TODO(pamg): Mock out the back-end calls, so we can also test removing a | 106 // TODO(pamg): Mock out the back-end calls, so we can also test removing a |
107 // single item. | 107 // single item. |
108 testDone(); | 108 testDone(); |
109 }); | 109 }); |
110 | 110 |
111 /** | 111 /** |
112 * Fixture for Downloads WebUI testing when deletions are prohibited. | 112 * Fixture for Downloads WebUI testing when deletions are prohibited. |
113 * @extends {BaseDownloadsWebUITest} | 113 * @extends {BaseDownloadsWebUITest} |
114 * @constructor | 114 * @constructor |
115 */ | 115 */ |
116 function DownloadsWebUIDeleteProhibitedTest() {} | 116 function DownloadsWebUIDeleteProhibitedTest() {} |
117 | 117 |
118 DownloadsWebUIDeleteProhibitedTest.prototype = { | 118 DownloadsWebUIDeleteProhibitedTest.prototype = { |
119 __proto__: BaseDownloadsWebUITest.prototype, | 119 __proto__: BaseDownloadsWebUITest.prototype, |
120 | 120 |
121 /** @override */ | 121 /** @override */ |
122 testGenPreamble: function() { | 122 testGenPreamble: function() { |
123 GEN(' SetDeleteAllowed(false);'); | 123 GEN(' SetDeleteAllowed(false);'); |
124 }, | 124 }, |
125 | |
126 /** | |
127 * Asserts the correctness of the state of the UI elements | |
128 * that delete the download history when deletion is prohibited. | |
129 * @param expectControlsHidden True if the controls to delete download history | |
Bernhard Bauer
2013/09/06 11:23:26
Add the type?
ibra
2013/09/06 16:56:42
Done.
| |
130 * are expected to be hidden and false otherwise. | |
131 */ | |
132 deleteProhibitedTestHelper: function(expectControlsHidden) { | |
Bernhard Bauer
2013/09/06 11:23:26
This is not the best name for the function; does i
| |
133 // "Clear all" should not be a link. | |
134 var clearAllText = document.querySelectorAll( | |
135 '#clear-all-holder.disabled-link'); | |
136 expectEquals(1, clearAllText.length); | |
137 expectEquals('SPAN', clearAllText[0].nodeName); | |
138 expectEquals(expectControlsHidden, clearAllText[0].hidden); | |
139 | |
140 // There should be no "Clear all" link. | |
141 var clearAllLinks = document.querySelectorAll('clear-all-link'); | |
Bernhard Bauer
2013/09/06 11:23:26
This selects all <clear-all-link> elements, which
ibra
2013/09/06 14:18:46
As far as I understand the above test goes through
Bernhard Bauer
2013/09/06 15:12:36
No, it doesn't. This test selects all <clear-all-l
| |
142 expectEquals(0, clearAllLinks.length); | |
143 | |
144 // All the "Remove from list" items should be text. Check only one, to avoid | |
145 // spam in case of failure. | |
146 var removeTexts = document.querySelectorAll('.controls > .disabled-link'); | |
147 expectEquals(TOTAL_RESULT_COUNT, removeTexts.length); | |
148 expectEquals('SPAN', removeTexts[0].nodeName); | |
149 expectEquals(expectControlsHidden, removeTexts[0].hidden); | |
150 | |
151 // There should be no "Remove from list" links. | |
152 var removeLinks = document.querySelectorAll('control-remove-link'); | |
153 expectEquals(0, removeLinks.length); | |
154 | |
155 // Attempting to remove items anyway should fail. | |
156 // The model would have been cleared synchronously, even though the actual | |
157 // back-end removal (also disabled, but tested elsewhere) is asynchronous. | |
158 clearAll(); | |
159 expectEquals(TOTAL_RESULT_COUNT, downloads.size()); | |
160 } | |
125 }; | 161 }; |
126 | 162 |
127 // Test UI when removing entries is prohibited. | 163 // Test UI when removing entries is prohibited. |
128 TEST_F('DownloadsWebUIDeleteProhibitedTest', 'deleteProhibited', function() { | 164 TEST_F('DownloadsWebUIDeleteProhibitedTest', 'deleteProhibited', function() { |
129 // "Clear all" should not be a link. | 165 this.deleteProhibitedTestHelper(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 | 166 // TODO(pamg): Mock out the back-end calls, so we can also test removing a |
156 // single item. | 167 // single item. |
157 testDone(); | 168 testDone(); |
158 }); | 169 }); |
170 | |
171 /** | |
172 * Fixture for Downloads WebUI testing for a supervised user. | |
173 * @extends {DownloadsWebUIDeleteProhibitedTest} | |
174 * @constructor | |
175 */ | |
176 function DownloadsWebUIForSupervisedUsersTest() {} | |
177 | |
178 DownloadsWebUIForSupervisedUsersTest.prototype = { | |
179 __proto__: DownloadsWebUIDeleteProhibitedTest.prototype, | |
180 | |
181 /** @override */ | |
182 testGenPreamble: function() { | |
183 GEN(' ChangeProfileToSupervised();'); | |
184 }, | |
185 }; | |
186 | |
187 TEST_F('DownloadsWebUIForSupervisedUsersTest', 'supervisedUsers', function() { | |
Bernhard Bauer
2013/09/06 11:23:26
Test cases should start with an uppercase letter (
ibra
2013/09/06 16:56:42
Done.
| |
188 this.deleteProhibitedTestHelper(true); | |
189 testDone(); | |
190 }); | |
OLD | NEW |