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

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_context_menu_unittest.cc

Issue 1233673002: Fix componentization of chrome/browser/bookmarks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix "gn check" and compilation on Mac Created 5 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 unified diff | Download patch
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/prefs/pref_service.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/threading/sequenced_worker_pool.h" 14 #include "base/threading/sequenced_worker_pool.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/app/chrome_command_ids.h" 16 #include "chrome/app/chrome_command_ids.h"
17 #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" 18 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
19 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h"
20 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" 20 #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
22 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
23 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
24 #include "components/bookmarks/browser/bookmark_model.h" 23 #include "components/bookmarks/browser/bookmark_model.h"
24 #include "components/bookmarks/managed/managed_bookmark_service.h"
25 #include "components/bookmarks/test/bookmark_test_helpers.h" 25 #include "components/bookmarks/test/bookmark_test_helpers.h"
26 #include "content/public/browser/page_navigator.h" 26 #include "content/public/browser/page_navigator.h"
27 #include "content/public/test/test_browser_thread.h" 27 #include "content/public/test/test_browser_thread.h"
28 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 #include "ui/base/clipboard/clipboard.h" 29 #include "ui/base/clipboard/clipboard.h"
30 #include "ui/events/platform/platform_event_source.h" 30 #include "ui/events/platform/platform_event_source.h"
31 #include "ui/views/controls/menu/menu_item_view.h" 31 #include "ui/views/controls/menu/menu_item_view.h"
32 32
33 #if defined(OS_WIN) 33 #if defined(OS_WIN)
34 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" 34 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // visible if the policy is set. 342 // visible if the policy is set.
343 TEST_F(BookmarkContextMenuTest, ShowManagedBookmarks) { 343 TEST_F(BookmarkContextMenuTest, ShowManagedBookmarks) {
344 // Create a BookmarkContextMenu for the bookmarks bar. 344 // Create a BookmarkContextMenu for the bookmarks bar.
345 const BookmarkNode* bb_node = model_->bookmark_bar_node(); 345 const BookmarkNode* bb_node = model_->bookmark_bar_node();
346 std::vector<const BookmarkNode*> nodes; 346 std::vector<const BookmarkNode*> nodes;
347 nodes.push_back(bb_node->GetChild(0)); 347 nodes.push_back(bb_node->GetChild(0));
348 scoped_ptr<BookmarkContextMenu> controller(new BookmarkContextMenu( 348 scoped_ptr<BookmarkContextMenu> controller(new BookmarkContextMenu(
349 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); 349 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false));
350 350
351 // Verify that there are no managed nodes yet. 351 // Verify that there are no managed nodes yet.
352 ChromeBookmarkClient* client = ChromeBookmarkClientFactory::GetForProfile( 352 bookmarks::ManagedBookmarkService* managed =
353 profile_.get()); 353 ManagedBookmarkServiceFactory::GetForProfile(profile_.get());
354 EXPECT_TRUE(client->managed_node()->empty()); 354 EXPECT_TRUE(managed->managed_node()->empty());
355 355
356 // The context menu should not show the option to "Show managed bookmarks". 356 // The context menu should not show the option to "Show managed bookmarks".
357 EXPECT_FALSE( 357 EXPECT_FALSE(
358 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)); 358 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS));
359 views::MenuItemView* menu = controller->menu(); 359 views::MenuItemView* menu = controller->menu();
360 EXPECT_FALSE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS) 360 EXPECT_FALSE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)
361 ->visible()); 361 ->visible());
362 362
363 // Other options are not affected. 363 // Other options are not affected.
364 EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER)); 364 EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER));
365 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible()); 365 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible());
366 366
367 // Now set the managed bookmarks policy. 367 // Now set the managed bookmarks policy.
368 base::DictionaryValue* dict = new base::DictionaryValue; 368 base::DictionaryValue* dict = new base::DictionaryValue;
369 dict->SetString("name", "Google"); 369 dict->SetString("name", "Google");
370 dict->SetString("url", "http://google.com"); 370 dict->SetString("url", "http://google.com");
371 base::ListValue list; 371 base::ListValue list;
372 list.Append(dict); 372 list.Append(dict);
373 EXPECT_TRUE(client->managed_node()->empty()); 373 EXPECT_TRUE(managed->managed_node()->empty());
374 profile_->GetPrefs()->Set(bookmarks::prefs::kManagedBookmarks, list); 374 profile_->GetPrefs()->Set(bookmarks::prefs::kManagedBookmarks, list);
375 EXPECT_FALSE(client->managed_node()->empty()); 375 EXPECT_FALSE(managed->managed_node()->empty());
376 376
377 // New context menus now show the "Show managed bookmarks" option. 377 // New context menus now show the "Show managed bookmarks" option.
378 controller.reset(new BookmarkContextMenu( 378 controller.reset(new BookmarkContextMenu(
379 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); 379 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false));
380 EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER)); 380 EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER));
381 EXPECT_TRUE( 381 EXPECT_TRUE(
382 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)); 382 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS));
383 menu = controller->menu(); 383 menu = controller->menu();
384 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible()); 384 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible());
385 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS) 385 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)
386 ->visible()); 386 ->visible());
387 } 387 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc ('k') | chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698