Chromium Code Reviews| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 = | |
| 97 document.getElementsByClassName('control-remove-link'); | |
| 98 | |
| 99 // "Clear all" should be a link only when deletions are allowed. | |
| 100 expectEquals(allowDelete ? 1 : 0, clearAllElements.length); | |
| 101 | |
| 102 // There should be no disabled links when deletions are allowed. | |
| 103 // On the other hand, when deletions are not allowed, "Clear All" | |
| 104 // and all "Remove from list" links should be disabled. | |
| 105 expectEquals(allowDelete ? 0 : TOTAL_RESULT_COUNT + 1, | |
| 106 disabledElements.length); | |
| 107 | |
| 108 // All "Remove from list" items should be links when deletions are allowed. | |
| 109 // On the other hand, when deletions are not allowed, all | |
| 110 // "Remove from list" items should be text. | |
| 111 expectEquals(allowDelete ? TOTAL_RESULT_COUNT : 0, | |
| 112 removeLinkElements.length); | |
| 113 | |
| 114 if (allowDelete) { | |
| 115 // "Clear all" should not be hidden. | |
| 116 expectFalse(clearAllElements[0].hidden); | |
| 117 | |
| 118 // All "Remove from list" items should not be hidden. | |
|
Bernhard Bauer
2013/09/09 13:49:52
Nit: This would read better as "No [...] items sho
ibra
2013/09/09 14:57:00
Done.
| |
| 119 expectFalse(removeLinkElements[0].hidden); | |
| 120 } else { | |
| 121 expectEquals(expectControlsHidden, disabledElements[0].hidden); | |
| 122 } | |
| 123 | |
| 124 // The model is updated synchronously, even though the actual | |
| 125 // back-end removal (tested elsewhere) is asynchronous. | |
| 126 clearAll(); | |
| 127 expectEquals(allowDelete ? 0 : TOTAL_RESULT_COUNT, downloads.size()); | |
| 128 }, | |
| 84 }; | 129 }; |
| 85 | 130 |
| 86 // Test UI when removing entries is allowed. | 131 // Test UI when removing entries is allowed. |
| 87 TEST_F('BaseDownloadsWebUITest', 'deleteAllowed', function() { | 132 TEST_F('BaseDownloadsWebUITest', 'DeleteAllowed', function() { |
| 88 // "Clear all" should be a link. | 133 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 | 134 // TODO(pamg): Mock out the back-end calls, so we can also test removing a |
| 107 // single item. | 135 // single item. |
| 108 testDone(); | 136 testDone(); |
| 109 }); | 137 }); |
| 110 | 138 |
| 111 /** | 139 /** |
| 112 * Fixture for Downloads WebUI testing when deletions are prohibited. | 140 * Fixture for Downloads WebUI testing when deletions are prohibited. |
| 113 * @extends {BaseDownloadsWebUITest} | 141 * @extends {BaseDownloadsWebUITest} |
| 114 * @constructor | 142 * @constructor |
| 115 */ | 143 */ |
| 116 function DownloadsWebUIDeleteProhibitedTest() {} | 144 function DownloadsWebUIDeleteProhibitedTest() {} |
| 117 | 145 |
| 118 DownloadsWebUIDeleteProhibitedTest.prototype = { | 146 DownloadsWebUIDeleteProhibitedTest.prototype = { |
| 119 __proto__: BaseDownloadsWebUITest.prototype, | 147 __proto__: BaseDownloadsWebUITest.prototype, |
| 120 | 148 |
| 121 /** @override */ | 149 /** @override */ |
| 122 testGenPreamble: function() { | 150 testGenPreamble: function() { |
| 123 GEN(' SetDeleteAllowed(false);'); | 151 GEN(' SetDeleteAllowed(false);'); |
| 124 }, | 152 }, |
| 125 }; | 153 }; |
| 126 | 154 |
| 127 // Test UI when removing entries is prohibited. | 155 // Test UI when removing entries is prohibited. |
| 128 TEST_F('DownloadsWebUIDeleteProhibitedTest', 'deleteProhibited', function() { | 156 TEST_F('DownloadsWebUIDeleteProhibitedTest', 'DeleteProhibited', function() { |
| 129 // "Clear all" should not be a link. | 157 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 | 158 // TODO(pamg): Mock out the back-end calls, so we can also test removing a |
| 156 // single item. | 159 // single item. |
| 157 testDone(); | 160 testDone(); |
| 158 }); | 161 }); |
| 162 | |
| 163 /** | |
| 164 * Fixture for Downloads WebUI testing for a supervised user. | |
| 165 * @extends {BaseDownloadsWebUITest} | |
| 166 * @constructor | |
| 167 */ | |
| 168 function DownloadsWebUIForSupervisedUsersTest() {} | |
| 169 | |
| 170 DownloadsWebUIForSupervisedUsersTest.prototype = { | |
| 171 __proto__: BaseDownloadsWebUITest.prototype, | |
| 172 | |
| 173 /** @override */ | |
| 174 testGenPreamble: function() { | |
| 175 GEN(' ChangeProfileToSupervised();'); | |
| 176 }, | |
| 177 }; | |
| 178 | |
| 179 // Test UI for supervised users, removing entries should be disabled | |
| 180 // and removal controls should be hidden. | |
| 181 TEST_F('DownloadsWebUIForSupervisedUsersTest', 'SupervisedUsers', function() { | |
| 182 this.testHelper(false, true); | |
| 183 testDone(); | |
| 184 }); | |
| OLD | NEW |