summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoribraaaa@chromium.org <ibraaaa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-09 17:47:50 +0000
committeribraaaa@chromium.org <ibraaaa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-09 17:47:50 +0000
commite3068b73720b0ef41de84299c70ed4501f89f0e8 (patch)
tree52d8cc4b085d235c8a075003792d528be9ba6d32
parent95b7531208f9577ce8e1f59bb5723154b078efa9 (diff)
downloadchromium_src-e3068b73720b0ef41de84299c70ed4501f89f0e8.zip
chromium_src-e3068b73720b0ef41de84299c70ed4501f89f0e8.tar.gz
chromium_src-e3068b73720b0ef41de84299c70ed4501f89f0e8.tar.bz2
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
-rw-r--r--chrome/browser/resources/downloads/downloads.js6
-rw-r--r--chrome/browser/ui/webui/downloads_ui.cc1
-rw-r--r--chrome/browser/ui/webui/downloads_ui_browsertest.cc9
-rw-r--r--chrome/browser/ui/webui/downloads_ui_browsertest.h2
-rw-r--r--chrome/browser/ui/webui/downloads_ui_browsertest.js118
-rw-r--r--chrome/chrome_tests.gypi3
6 files changed, 93 insertions, 46 deletions
diff --git a/chrome/browser/resources/downloads/downloads.js b/chrome/browser/resources/downloads/downloads.js
index d50f5eb..7522c5f 100644
--- a/chrome/browser/resources/downloads/downloads.js
+++ b/chrome/browser/resources/downloads/downloads.js
@@ -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; };
diff --git a/chrome/browser/ui/webui/downloads_ui.cc b/chrome/browser/ui/webui/downloads_ui.cc
index ebb01f3de..6b71ca3 100644
--- a/chrome/browser/ui/webui/downloads_ui.cc
+++ b/chrome/browser/ui/webui/downloads_ui.cc
@@ -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);
diff --git a/chrome/browser/ui/webui/downloads_ui_browsertest.cc b/chrome/browser/ui/webui/downloads_ui_browsertest.cc
index 7c6434b..1abeb5e 100644
--- a/chrome/browser/ui/webui/downloads_ui_browsertest.cc
+++ b/chrome/browser/ui/webui/downloads_ui_browsertest.cc
@@ -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();
+}
diff --git a/chrome/browser/ui/webui/downloads_ui_browsertest.h b/chrome/browser/ui/webui/downloads_ui_browsertest.h
index a325146..f5370c8 100644
--- a/chrome/browser/ui/webui/downloads_ui_browsertest.h
+++ b/chrome/browser/ui/webui/downloads_ui_browsertest.h
@@ -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);
};
diff --git a/chrome/browser/ui/webui/downloads_ui_browsertest.js b/chrome/browser/ui/webui/downloads_ui_browsertest.js
index bf0c464..c55ca6f 100644
--- a/chrome/browser/ui/webui/downloads_ui_browsertest.js
+++ b/chrome/browser/ui/webui/downloads_ui_browsertest.js
@@ -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();
+});
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index becc71e..864098d 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -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',