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

Side by Side 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, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h" 5 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/prefs/pref_service.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "base/threading/sequenced_worker_pool.h" 14 #include "base/threading/sequenced_worker_pool.h"
15 #include "base/values.h"
14 #include "chrome/app/chrome_command_ids.h" 16 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 17 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
18 #include "chrome/browser/bookmarks/chrome_bookmark_client.h"
19 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h"
16 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" 21 #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
22 #include "chrome/common/pref_names.h"
18 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
19 #include "components/bookmarks/browser/bookmark_model.h" 24 #include "components/bookmarks/browser/bookmark_model.h"
20 #include "components/bookmarks/test/bookmark_test_helpers.h" 25 #include "components/bookmarks/test/bookmark_test_helpers.h"
21 #include "content/public/browser/page_navigator.h" 26 #include "content/public/browser/page_navigator.h"
22 #include "content/public/test/test_browser_thread.h" 27 #include "content/public/test/test_browser_thread.h"
23 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
24 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
25 #include "ui/base/clipboard/clipboard.h" 30 #include "ui/base/clipboard/clipboard.h"
26 #include "ui/events/platform/platform_event_source.h" 31 #include "ui/events/platform/platform_event_source.h"
32 #include "ui/views/controls/menu/menu_item_view.h"
27 33
28 #if defined(OS_WIN) 34 #if defined(OS_WIN)
29 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" 35 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
30 #endif 36 #endif
31 37
32 using base::ASCIIToUTF16; 38 using base::ASCIIToUTF16;
33 using content::BrowserThread; 39 using content::BrowserThread;
34 using content::OpenURLParams; 40 using content::OpenURLParams;
35 using content::PageNavigator; 41 using content::PageNavigator;
36 using content::WebContents; 42 using content::WebContents;
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 ASSERT_EQ(bb_node->GetChild(0)->url(), bb_node->GetChild(1)->url()); 332 ASSERT_EQ(bb_node->GetChild(0)->url(), bb_node->GetChild(1)->url());
327 333
328 controller.reset(new BookmarkContextMenu( 334 controller.reset(new BookmarkContextMenu(
329 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); 335 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false));
330 // Cut the URL. 336 // Cut the URL.
331 controller->ExecuteCommand(IDC_CUT, 0); 337 controller->ExecuteCommand(IDC_CUT, 0);
332 ASSERT_TRUE(bb_node->GetChild(0)->is_url()); 338 ASSERT_TRUE(bb_node->GetChild(0)->is_url());
333 ASSERT_TRUE(bb_node->GetChild(1)->is_folder()); 339 ASSERT_TRUE(bb_node->GetChild(1)->is_folder());
334 ASSERT_EQ(old_count, bb_node->child_count()); 340 ASSERT_EQ(old_count, bb_node->child_count());
335 } 341 }
342
343 // Tests that the "Show managed bookmarks" option in the context menu is only
344 // visible if the policy is set.
345 TEST_F(BookmarkContextMenuTest, ShowManagedBookmarks) {
346 // Create a BookmarkContextMenu for the bookmarks bar.
347 const BookmarkNode* bb_node = model_->bookmark_bar_node();
348 std::vector<const BookmarkNode*> nodes;
349 nodes.push_back(bb_node->GetChild(0));
350 scoped_ptr<BookmarkContextMenu> controller(new BookmarkContextMenu(
351 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false));
352
353 // Verify that there are no managed nodes yet.
354 ChromeBookmarkClient* client = ChromeBookmarkClientFactory::GetForProfile(
355 profile_.get());
356 EXPECT_TRUE(client->managed_node()->empty());
357
358 // The context menu should not show the option to "Show managed bookmarks".
359 EXPECT_FALSE(
360 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS));
361 views::MenuItemView* menu = controller->menu();
362 EXPECT_FALSE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)
363 ->visible());
364
365 // Other options are not affected.
366 EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER));
367 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible());
368
369 // Now set the managed bookmarks policy.
370 base::DictionaryValue* dict = new base::DictionaryValue;
371 dict->SetString("name", "Google");
372 dict->SetString("url", "http://google.com");
373 base::ListValue list;
374 list.Append(dict);
375 EXPECT_TRUE(client->managed_node()->empty());
376 profile_->GetPrefs()->Set(prefs::kManagedBookmarks, list);
377 EXPECT_FALSE(client->managed_node()->empty());
378
379 // New context menus now show the "Show managed bookmarks" option.
380 controller.reset(new BookmarkContextMenu(
381 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false));
382 EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER));
383 EXPECT_TRUE(
384 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS));
385 menu = controller->menu();
386 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible());
387 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)
388 ->visible());
389 }
OLDNEW
« 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