summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-04 14:33:47 +0000
committerjoaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-04 14:33:47 +0000
commitee37d41fdeba02e578149ae1269db9e89f7c9a51 (patch)
tree6d7295434af64834bb41aafda292c9e38d516c97
parentc8f68a8ca3948d1b5c247c5e24e95c6f9a6e79e3 (diff)
downloadchromium_src-ee37d41fdeba02e578149ae1269db9e89f7c9a51.zip
chromium_src-ee37d41fdeba02e578149ae1269db9e89f7c9a51.tar.gz
chromium_src-ee37d41fdeba02e578149ae1269db9e89f7c9a51.tar.bz2
Added a policy to control the visibility of the apps shortcut.
BUG=312716 Review URL: https://codereview.chromium.org/312673006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274822 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/policy/configuration_policy_handler_list_factory.cc3
-rw-r--r--chrome/browser/ui/bookmarks/bookmark_context_menu_controller_unittest.cc30
-rw-r--r--chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_unittest.mm19
-rw-r--r--chrome/browser/ui/views/bookmarks/bookmark_bar_view.h2
-rw-r--r--chrome/browser/ui/views/bookmarks/bookmark_bar_view_unittest.cc33
-rw-r--r--chrome/test/data/policy/policy_test_cases.json8
-rw-r--r--components/policy/resources/policy_templates.json20
-rw-r--r--tools/metrics/histograms/histograms.xml1
8 files changed, 114 insertions, 2 deletions
diff --git a/chrome/browser/policy/configuration_policy_handler_list_factory.cc b/chrome/browser/policy/configuration_policy_handler_list_factory.cc
index 6249a2c..6528aea 100644
--- a/chrome/browser/policy/configuration_policy_handler_list_factory.cc
+++ b/chrome/browser/policy/configuration_policy_handler_list_factory.cc
@@ -299,6 +299,9 @@ const PolicyToPreferenceMapEntry kSimplePolicyMap[] = {
{ key::kEditBookmarksEnabled,
prefs::kEditBookmarksEnabled,
base::Value::TYPE_BOOLEAN },
+ { key::kShowAppsShortcutInBookmarkBar,
+ prefs::kShowAppsShortcutInBookmarkBar,
+ base::Value::TYPE_BOOLEAN },
{ key::kAllowFileSelectionDialogs,
prefs::kAllowFileSelectionDialogs,
base::Value::TYPE_BOOLEAN },
diff --git a/chrome/browser/ui/bookmarks/bookmark_context_menu_controller_unittest.cc b/chrome/browser/ui/bookmarks/bookmark_context_menu_controller_unittest.cc
index 7393354..3102158 100644
--- a/chrome/browser/ui/bookmarks/bookmark_context_menu_controller_unittest.cc
+++ b/chrome/browser/ui/bookmarks/bookmark_context_menu_controller_unittest.cc
@@ -9,12 +9,16 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/values.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/bookmarks/bookmark_utils.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
#include "components/bookmarks/browser/bookmark_model.h"
+#include "components/bookmarks/browser/bookmark_node.h"
#include "components/bookmarks/test/bookmark_test_helpers.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/test/test_browser_thread.h"
@@ -333,3 +337,29 @@ TEST_F(BookmarkContextMenuControllerTest, CutCopyPasteNode) {
ASSERT_TRUE(bb_node->GetChild(1)->is_folder());
ASSERT_EQ(old_count, bb_node->child_count());
}
+
+TEST_F(BookmarkContextMenuControllerTest,
+ ManagedShowAppsShortcutInBookmarksBar) {
+ BookmarkContextMenuController controller(
+ NULL, NULL, NULL, profile_.get(), NULL, model_->bookmark_bar_node(),
+ std::vector<const BookmarkNode*>());
+
+ // By default, the pref is not managed and the command is enabled.
+ TestingPrefServiceSyncable* prefs = profile_->GetTestingPrefService();
+ EXPECT_FALSE(
+ prefs->IsManagedPreference(prefs::kShowAppsShortcutInBookmarkBar));
+ EXPECT_TRUE(
+ controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_SHOW_APPS_SHORTCUT));
+
+ // Disabling the shorcut by policy disables the command.
+ prefs->SetManagedPref(prefs::kShowAppsShortcutInBookmarkBar,
+ new base::FundamentalValue(false));
+ EXPECT_FALSE(
+ controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_SHOW_APPS_SHORTCUT));
+
+ // And enabling the shortcut by policy disables the command too.
+ prefs->SetManagedPref(prefs::kShowAppsShortcutInBookmarkBar,
+ new base::FundamentalValue(true));
+ EXPECT_FALSE(
+ controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_SHOW_APPS_SHORTCUT));
+}
diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_unittest.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_unittest.mm
index 0810bf6..aad3242 100644
--- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_unittest.mm
@@ -24,6 +24,7 @@
#import "chrome/browser/ui/cocoa/view_resizer_pong.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
+#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_utils.h"
@@ -1607,6 +1608,24 @@ TEST_F(BookmarkBarControllerTest, BookmarksWithoutAppsPageShortcut) {
NSMinX([[[bar_ buttonView] importBookmarksButton] frame]));
}
+TEST_F(BookmarkBarControllerTest, ManagedShowAppsShortcutInBookmarksBar) {
+ // By default the pref is not managed and the apps shortcut is shown.
+ TestingPrefServiceSyncable* prefs = profile()->GetTestingPrefService();
+ EXPECT_FALSE(
+ prefs->IsManagedPreference(prefs::kShowAppsShortcutInBookmarkBar));
+ EXPECT_FALSE([bar_ appsPageShortcutButtonIsHidden]);
+
+ // Hide the apps shortcut by policy, via the managed pref.
+ prefs->SetManagedPref(prefs::kShowAppsShortcutInBookmarkBar,
+ new base::FundamentalValue(false));
+ EXPECT_TRUE([bar_ appsPageShortcutButtonIsHidden]);
+
+ // And try showing it via policy too.
+ prefs->SetManagedPref(prefs::kShowAppsShortcutInBookmarkBar,
+ new base::FundamentalValue(true));
+ EXPECT_FALSE([bar_ appsPageShortcutButtonIsHidden]);
+}
+
class BookmarkBarControllerOpenAllTest : public BookmarkBarControllerTest {
public:
virtual void SetUp() {
diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.h b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.h
index 30b6925..b8e98b6b 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.h
+++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.h
@@ -260,7 +260,7 @@ class BookmarkBarView : public DetachableToolbarView,
friend class BookmarkBarViewEventTestBase;
FRIEND_TEST_ALL_PREFIXES(BookmarkBarViewTest, SwitchProfile);
FRIEND_TEST_ALL_PREFIXES(BookmarkBarViewTest,
- NoAppsShortcutWithoutInstantExtended);
+ ManagedShowAppsShortcutInBookmarksBar);
FRIEND_TEST_ALL_PREFIXES(BookmarkBarViewInstantExtendedTest,
AppsShortcutVisibility);
diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_unittest.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_unittest.cc
index f51d1db..f17ba97 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_unittest.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_unittest.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
#include "base/prefs/pref_service.h"
+#include "base/values.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service.h"
@@ -15,6 +16,7 @@
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
+#include "chrome/test/base/testing_pref_service_syncable.h"
#include "components/bookmarks/test/bookmark_test_helpers.h"
#include "ui/views/controls/button/text_button.h"
@@ -70,3 +72,34 @@ TEST_F(BookmarkBarViewInstantExtendedTest, AppsShortcutVisibility) {
prefs::kShowAppsShortcutInBookmarkBar, false);
EXPECT_FALSE(bookmark_bar_view.apps_page_shortcut_->visible());
}
+
+#if !defined(OS_CHROMEOS)
+typedef BrowserWithTestWindowTest BookmarkBarViewTest;
+
+// Verifies that the apps shortcut is shown or hidden following the policy
+// value. This policy (and the apps shortcut) isn't present on ChromeOS.
+TEST_F(BookmarkBarViewTest, ManagedShowAppsShortcutInBookmarksBar) {
+ ScopedTestingLocalState local_state(TestingBrowserProcess::GetGlobal());
+ profile()->CreateBookmarkModel(true);
+ test::WaitForBookmarkModelToLoad(
+ BookmarkModelFactory::GetForProfile(profile()));
+ BookmarkBarView bookmark_bar_view(browser(), NULL);
+ bookmark_bar_view.set_owned_by_client();
+
+ // By default, the pref is not managed and the apps shortcut is shown.
+ TestingPrefServiceSyncable* prefs = profile()->GetTestingPrefService();
+ EXPECT_FALSE(
+ prefs->IsManagedPreference(prefs::kShowAppsShortcutInBookmarkBar));
+ EXPECT_TRUE(bookmark_bar_view.apps_page_shortcut_->visible());
+
+ // Hide the apps shortcut by policy, via the managed pref.
+ prefs->SetManagedPref(prefs::kShowAppsShortcutInBookmarkBar,
+ new base::FundamentalValue(false));
+ EXPECT_FALSE(bookmark_bar_view.apps_page_shortcut_->visible());
+
+ // And try showing it via policy too.
+ prefs->SetManagedPref(prefs::kShowAppsShortcutInBookmarkBar,
+ new base::FundamentalValue(true));
+ EXPECT_TRUE(bookmark_bar_view.apps_page_shortcut_->visible());
+}
+#endif
diff --git a/chrome/test/data/policy/policy_test_cases.json b/chrome/test/data/policy/policy_test_cases.json
index cccdeed..c2e49c9 100644
--- a/chrome/test/data/policy/policy_test_cases.json
+++ b/chrome/test/data/policy/policy_test_cases.json
@@ -1369,6 +1369,14 @@
]
},
+ "ShowAppsShortcutInBookmarkBar": {
+ "os": ["win", "linux", "mac"],
+ "test_policy": { "ShowAppsShortcutInBookmarkBar": false },
+ "pref_mappings": [
+ { "pref": "bookmark_bar.show_apps_shortcut" }
+ ]
+ },
+
"AllowFileSelectionDialogs": {
"os": ["win", "mac", "linux"],
"test_policy": { "AllowFileSelectionDialogs": false },
diff --git a/components/policy/resources/policy_templates.json b/components/policy/resources/policy_templates.json
index 0b6e66b..c9a1405 100644
--- a/components/policy/resources/policy_templates.json
+++ b/components/policy/resources/policy_templates.json
@@ -118,7 +118,7 @@
# persistent IDs for all fields (but not for groups!) are needed. These are
# specified by the 'id' keys of each policy. NEVER CHANGE EXISTING IDs,
# because doing so would break the deployed wire format!
-# For your editing convenience: highest ID currently used: 266
+# For your editing convenience: highest ID currently used: 267
#
# Placeholders:
# The following placeholder strings are automatically substituted:
@@ -3213,6 +3213,24 @@
If you disable this setting, bookmarks can not be added, removed or modified. Existing bookmarks are still available.''',
},
{
+ 'name': 'ShowAppsShortcutInBookmarkBar',
+ 'type': 'main',
+ 'schema': { 'type': 'boolean' },
+ 'supported_on': ['chrome.*:37-'],
+ 'features': {
+ 'dynamic_refresh': True,
+ 'per_profile': True,
+ },
+ 'example_value': False,
+ 'id': 267,
+ 'caption': '''Show the apps shortcut in the bookmark bar''',
+ 'desc': '''Enables or disables the apps shortcut in the bookmark bar.
+
+ If this policy is not set then the user can choose to show or hide the apps shortcut from the bookmark bar context menu.
+
+ If this policy is configured then the user can't change it, and the apps shortcut is always shown or never shown.''',
+ },
+ {
'name': 'AllowFileSelectionDialogs',
'type': 'main',
'schema': { 'type': 'boolean' },
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index 87e6d1a..634c616 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -34755,6 +34755,7 @@ Therefore, the affected-histogram name has to have at least one dot in it.
label="Restrict the UDP port range used by the remote access host"/>
<int value="265" label="Enables the old web-based signin"/>
<int value="266" label="Block developer mode"/>
+ <int value="267" label="Show the apps shortcut in the bookmark bar"/>
</enum>
<enum name="EnterprisePolicyInvalidations" type="int">