Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Unified Diff: chrome/browser/ui/views/bookmarks/bookmark_context_menu_unittest.cc

Issue 423833002: Check if the delegate changed the visibility of child MenuItemViews. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added MenuModelAdapter::IsCommandVisible Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_context_menu.cc ('k') | ui/views/controls/menu/menu_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/bookmarks/bookmark_context_menu_unittest.cc
diff --git a/chrome/browser/ui/views/bookmarks/bookmark_context_menu_unittest.cc b/chrome/browser/ui/views/bookmarks/bookmark_context_menu_unittest.cc
index c01e35f13e3d9bd3ebadeb11930c347dabc9622b..77b4e279be57933cf95f670063ccead3a23c7ec0 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_context_menu_unittest.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_context_menu_unittest.cc
@@ -9,12 +9,17 @@
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
+#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/sequenced_worker_pool.h"
+#include "base/values.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
+#include "chrome/browser/bookmarks/chrome_bookmark_client.h"
+#include "chrome/browser/bookmarks/chrome_bookmark_client_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_profile.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/test/bookmark_test_helpers.h"
@@ -24,6 +29,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/events/platform/platform_event_source.h"
+#include "ui/views/controls/menu/menu_item_view.h"
#if defined(OS_WIN)
#include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
@@ -333,3 +339,51 @@ TEST_F(BookmarkContextMenuTest, CutCopyPasteNode) {
ASSERT_TRUE(bb_node->GetChild(1)->is_folder());
ASSERT_EQ(old_count, bb_node->child_count());
}
+
+// Tests that the "Show managed bookmarks" option in the context menu is only
+// visible if the policy is set.
+TEST_F(BookmarkContextMenuTest, ShowManagedBookmarks) {
+ // Create a BookmarkContextMenu for the bookmarks bar.
+ const BookmarkNode* bb_node = model_->bookmark_bar_node();
+ std::vector<const BookmarkNode*> nodes;
+ nodes.push_back(bb_node->GetChild(0));
+ scoped_ptr<BookmarkContextMenu> controller(new BookmarkContextMenu(
+ NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false));
+
+ // Verify that there are no managed nodes yet.
+ ChromeBookmarkClient* client = ChromeBookmarkClientFactory::GetForProfile(
+ profile_.get());
+ EXPECT_TRUE(client->managed_node()->empty());
+
+ // The context menu should not show the option to "Show managed bookmarks".
+ EXPECT_FALSE(
+ controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS));
+ views::MenuItemView* menu = controller->menu();
+ EXPECT_FALSE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)
+ ->visible());
+
+ // Other options are not affected.
+ EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER));
+ EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible());
+
+ // Now set the managed bookmarks policy.
+ base::DictionaryValue* dict = new base::DictionaryValue;
+ dict->SetString("name", "Google");
+ dict->SetString("url", "http://google.com");
+ base::ListValue list;
+ list.Append(dict);
+ EXPECT_TRUE(client->managed_node()->empty());
+ profile_->GetPrefs()->Set(prefs::kManagedBookmarks, list);
+ EXPECT_FALSE(client->managed_node()->empty());
+
+ // New context menus now show the "Show managed bookmarks" option.
+ controller.reset(new BookmarkContextMenu(
+ NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false));
+ EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER));
+ EXPECT_TRUE(
+ controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS));
+ menu = controller->menu();
+ EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible());
+ EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)
+ ->visible());
+}
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_context_menu.cc ('k') | ui/views/controls/menu/menu_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698