Commit e3068b73 authored by ibraaaa@chromium.org's avatar ibraaaa@chromium.org

Hide the "downloads" page policy disabled UI elements from supervised users


Also, add a browser test for that, and add GYP rules for the downloads page browser tests.

BUG=264184

Review URL: https://chromiumcodereview.appspot.com/23851007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222054 0039d316-1c4b-4281-b951-d872f2087c98
parent 95b75312
......@@ -339,6 +339,9 @@ function Download(download) {
loadTimeData.getString('control_removefromlist'));
this.controlRemove_.appendChild(text);
}
if (!loadTimeData.getBoolean('show_delete_history'))
this.controlRemove_.hidden = true;
this.nodeControls_.appendChild(this.controlRemove_);
this.controlCancel_ = createLink(this.cancel_.bind(this),
......@@ -733,6 +736,9 @@ function load() {
loadTimeData.getString('clear_all'));
clearAllHolder.classList.add('disabled-link');
}
if (!loadTimeData.getBoolean('show_delete_history'))
clearAllHolder.hidden = true;
clearAllHolder.appendChild(clearAllElement);
clearAllElement.oncontextmenu = function() { return false; };
......
......@@ -81,6 +81,7 @@ content::WebUIDataSource* CreateDownloadsUIHTMLSource(Profile* profile) {
PrefService* prefs = profile->GetPrefs();
source->AddBoolean("allow_deleting_history",
prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory));
source->AddBoolean("show_delete_history", !profile->IsManaged());
source->SetJsonPath("strings.js");
source->AddResourcePath("downloads.css", IDR_DOWNLOADS_CSS);
......
......@@ -5,9 +5,12 @@
#include "chrome/browser/ui/webui/downloads_ui_browsertest.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/managed_mode/managed_user_service.h"
#include "chrome/browser/managed_mode/managed_user_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/pref_names.h"
#include "content/public/test/test_utils.h"
DownloadsUIBrowserTest::DownloadsUIBrowserTest() {
}
......@@ -19,3 +22,9 @@ void DownloadsUIBrowserTest::SetDeleteAllowed(bool allowed) {
browser()->profile()->GetPrefs()->
SetBoolean(prefs::kAllowDeletingBrowserHistory, allowed);
}
void DownloadsUIBrowserTest::ChangeProfileToSupervised() {
ManagedUserServiceFactory::GetForProfile(
browser()->profile())->InitForTesting();
content::RunAllPendingInMessageLoop();
}
......@@ -17,6 +17,8 @@ class DownloadsUIBrowserTest : public WebUIBrowserTest {
// Sets the pref to allow or prohibit deleting history entries.
void SetDeleteAllowed(bool allowed);
void ChangeProfileToSupervised();
private:
DISALLOW_COPY_AND_ASSIGN(DownloadsUIBrowserTest);
};
......
......@@ -81,28 +81,56 @@ BaseDownloadsWebUITest.prototype = {
return download;
},
};
// 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);
/**
* 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('control-remove-link');
// "Clear all" should be a link only when deletions are allowed.
expectEquals(allowDelete ? 1 : 0, clearAllElements.length);
// There should be no disabled links when deletions are allowed.
// On the other hand, when deletions are not allowed, "Clear All"
// and all "Remove from list" links should be disabled.
expectEquals(allowDelete ? 0 : TOTAL_RESULT_COUNT + 1,
disabledElements.length);
// All "Remove from list" items should be links when deletions are allowed.
// On the other hand, when deletions are not allowed, all
// "Remove from list" items should be text.
expectEquals(allowDelete ? TOTAL_RESULT_COUNT : 0,
removeLinkElements.length);
if (allowDelete) {
// "Clear all" should not be hidden.
expectFalse(clearAllElements[0].hidden);
// No "Remove from list" items should be hidden.
expectFalse(removeLinkElements[0].hidden);
} else {
expectEquals(expectControlsHidden, disabledElements[0].hidden);
}
// The model is updated synchronously, even though the actual back-end removal
// (tested elsewhere) is asynchronous.
clearAll();
expectEquals(downloads.size(), 0);
// The model is updated synchronously, even though the actual
// back-end removal (tested elsewhere) is asynchronous.
clearAll();
expectEquals(allowDelete ? 0 : TOTAL_RESULT_COUNT, downloads.size());
},
};
// Test UI when removing entries is allowed.
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 +153,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 {BaseDownloadsWebUITest}
* @constructor
*/
function DownloadsWebUIForSupervisedUsersTest() {}
DownloadsWebUIForSupervisedUsersTest.prototype = {
__proto__: BaseDownloadsWebUITest.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();
});
......@@ -1651,6 +1651,9 @@
'browser/ui/webui/chrome_url_data_manager_browsertest.cc',
'browser/ui/webui/constrained_web_dialog_ui_browsertest.cc',
'browser/ui/webui/downloads_dom_handler_browsertest.cc',
'browser/ui/webui/downloads_ui_browsertest.cc',
'browser/ui/webui/downloads_ui_browsertest.h',
'browser/ui/webui/downloads_ui_browsertest.js',
'browser/ui/webui/extensions/chromeos/kiosk_apps_browsertest.js',
'browser/ui/webui/extensions/extension_settings_browsertest.js',
'browser/ui/webui/help/help_browsertest.js',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment