Chromium Code Reviews| Index: chrome/browser/ui/webui/downloads_ui_browsertest.js |
| diff --git a/chrome/browser/ui/webui/downloads_ui_browsertest.js b/chrome/browser/ui/webui/downloads_ui_browsertest.js |
| index bf0c464f1d906ea79a8da2743d96f3b3ed2039b4..a050e16c4adb90700b6b979fc0ea2ab365294e40 100644 |
| --- a/chrome/browser/ui/webui/downloads_ui_browsertest.js |
| +++ b/chrome/browser/ui/webui/downloads_ui_browsertest.js |
| @@ -81,28 +81,55 @@ BaseDownloadsWebUITest.prototype = { |
| return download; |
| }, |
| + |
| + /** |
| + * Asserts the correctness of the state of the UI elements |
| + * that delete the download history. |
| + * @param {boolean} allowDelete True if download history deletion is |
| + * allowed and false otherwise. |
| + * @param {boolean} expectControlsHidden True if the controls to delete |
| + * download history are expected to be hidden and false otherwise. |
| + */ |
| + testHelper: function(allowDelete, expectControlsHidden) { |
| + var clearAllElements = document.getElementsByClassName('clear-all-link'); |
| + var disabledElements = document.getElementsByClassName('disabled-link'); |
| + 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.
|
| + 'control-remove-link'); |
| + if (allowDelete) { |
| + // "Clear all" should be a link. |
| + expectEquals(1, clearAllElements.length); |
| + // "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.
|
| + 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.
|
| + // There should be no disabled "links". |
| + expectEquals(0, disabledElements.length); |
| + // All "Remove from list" items should be links. |
| + expectEquals(TOTAL_RESULT_COUNT, removeLinkElements.length); |
| + // All "Remove from list" items should not be hidden. |
| + expectEquals(expectControlsHidden, removeLinkElements[0].hidden); |
| + // The model is updated synchronously, even though the actual |
| + // back-end removal (tested elsewhere) is asynchronous. |
| + clearAll(); |
| + expectEquals(0, downloads.size()); |
| + } else { |
| + // "Clear all" should not be a link. |
| + 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.
|
| + // "Clear all" and all "Remove from list" links should be disabled. |
| + expectEquals(TOTAL_RESULT_COUNT + 1, disabledElements.length); |
| + expectEquals(expectControlsHidden, disabledElements[0].hidden); |
| + // All "Remove from list" should not be links; just text. |
| + expectEquals(0, removeLinkElements.length); |
| + // Attempting to remove items anyway should fail. |
| + // The model would have been cleared synchronously, even though the actual |
| + // back-end removal (also disabled, but tested elsewhere) is asynchronous. |
| + clearAll(); |
| + expectEquals(TOTAL_RESULT_COUNT, downloads.size()); |
| + } |
| + }, |
| }; |
| // Test UI when removing entries is allowed. |
| -TEST_F('BaseDownloadsWebUITest', 'deleteAllowed', function() { |
| - // "Clear all" should be a link. |
| - var clearAllHolder = document.querySelectorAll('#clear-all-holder > a'); |
| - expectEquals(clearAllHolder.length, 1); |
| - |
| - // All the "Remove from list" items should be links. |
| - var removeLinks = document.querySelectorAll( |
| - '.controls > a.control-remove-link'); |
| - expectEquals(removeLinks.length, TOTAL_RESULT_COUNT); |
| - |
| - // There should be no disabled text "links". |
| - var disabledLinks = document.querySelectorAll('.disabled-link'); |
| - expectEquals(disabledLinks.length, 0); |
| - |
| - // The model is updated synchronously, even though the actual back-end removal |
| - // (tested elsewhere) is asynchronous. |
| - clearAll(); |
| - expectEquals(downloads.size(), 0); |
| - |
| +TEST_F('BaseDownloadsWebUITest', 'DeleteAllowed', function() { |
| + this.testHelper(true, false); |
| // TODO(pamg): Mock out the back-end calls, so we can also test removing a |
| // single item. |
| testDone(); |
| @@ -125,34 +152,32 @@ DownloadsWebUIDeleteProhibitedTest.prototype = { |
| }; |
| // Test UI when removing entries is prohibited. |
| -TEST_F('DownloadsWebUIDeleteProhibitedTest', 'deleteProhibited', function() { |
| - // "Clear all" should not be a link. |
| - var clearAllText = document.querySelectorAll( |
| - '#clear-all-holder.disabled-link'); |
| - expectEquals(clearAllText.length, 1); |
| - expectEquals(clearAllText[0].nodeName, 'SPAN'); |
| - |
| - // There should be no "Clear all" link. |
| - var clearAllLinks = document.querySelectorAll('clear-all-link'); |
| - expectEquals(clearAllLinks.length, 0); |
| - |
| - // All the "Remove from list" items should be text. Check only one, to avoid |
| - // spam in case of failure. |
| - var removeTexts = document.querySelectorAll('.controls > .disabled-link'); |
| - expectEquals(removeTexts.length, TOTAL_RESULT_COUNT); |
| - expectEquals(removeTexts[0].nodeName, 'SPAN'); |
| - |
| - // There should be no "Remove from list" links. |
| - var removeLinks = document.querySelectorAll('control-remove-link'); |
| - expectEquals(removeLinks.length, 0); |
| - |
| - // Attempting to remove items anyway should fail. |
| - // The model would have been cleared synchronously, even though the actual |
| - // back-end removal (also disabled, but tested elsewhere) is asynchronous. |
| - clearAll(); |
| - expectEquals(downloads.size(), TOTAL_RESULT_COUNT); |
| - |
| +TEST_F('DownloadsWebUIDeleteProhibitedTest', 'DeleteProhibited', function() { |
| + this.testHelper(false, false); |
| // TODO(pamg): Mock out the back-end calls, so we can also test removing a |
| // single item. |
| testDone(); |
| }); |
| + |
| +/** |
| + * Fixture for Downloads WebUI testing for a supervised user. |
| + * @extends {DownloadsWebUIDeleteProhibitedTest} |
| + * @constructor |
| + */ |
| +function DownloadsWebUIForSupervisedUsersTest() {} |
| + |
| +DownloadsWebUIForSupervisedUsersTest.prototype = { |
| + __proto__: DownloadsWebUIDeleteProhibitedTest.prototype, |
| + |
| + /** @override */ |
| + testGenPreamble: function() { |
| + GEN(' ChangeProfileToSupervised();'); |
| + }, |
| +}; |
| + |
| +// Test UI for supervised users, removing entries should be disabled |
| +// and removal controls should be hidden. |
| +TEST_F('DownloadsWebUIForSupervisedUsersTest', 'SupervisedUsers', function() { |
| + this.testHelper(false, true); |
| + testDone(); |
| +}); |