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

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

Issue 1203713002: Limit access to ChromeBookmarkClient to bookmarks code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup_bookmark_client
Patch Set: Rebase Created 5 years, 6 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"
19 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h"
20 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" 19 #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
22 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
23 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
24 #include "components/bookmarks/browser/bookmark_model.h" 22 #include "components/bookmarks/browser/bookmark_model.h"
25 #include "components/bookmarks/test/bookmark_test_helpers.h" 23 #include "components/bookmarks/test/bookmark_test_helpers.h"
26 #include "content/public/browser/page_navigator.h" 24 #include "content/public/browser/page_navigator.h"
27 #include "content/public/test/test_browser_thread.h" 25 #include "content/public/test/test_browser_thread.h"
28 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
29 #include "ui/base/clipboard/clipboard.h" 27 #include "ui/base/clipboard/clipboard.h"
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // visible if the policy is set. 340 // visible if the policy is set.
343 TEST_F(BookmarkContextMenuTest, ShowManagedBookmarks) { 341 TEST_F(BookmarkContextMenuTest, ShowManagedBookmarks) {
344 // Create a BookmarkContextMenu for the bookmarks bar. 342 // Create a BookmarkContextMenu for the bookmarks bar.
345 const BookmarkNode* bb_node = model_->bookmark_bar_node(); 343 const BookmarkNode* bb_node = model_->bookmark_bar_node();
346 std::vector<const BookmarkNode*> nodes; 344 std::vector<const BookmarkNode*> nodes;
347 nodes.push_back(bb_node->GetChild(0)); 345 nodes.push_back(bb_node->GetChild(0));
348 scoped_ptr<BookmarkContextMenu> controller(new BookmarkContextMenu( 346 scoped_ptr<BookmarkContextMenu> controller(new BookmarkContextMenu(
349 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); 347 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false));
350 348
351 // Verify that there are no managed nodes yet. 349 // Verify that there are no managed nodes yet.
352 ChromeBookmarkClient* client = ChromeBookmarkClientFactory::GetForProfile( 350 EXPECT_TRUE(model_->managed_node()->empty());
353 profile_.get());
354 EXPECT_TRUE(client->managed_node()->empty());
355 351
356 // The context menu should not show the option to "Show managed bookmarks". 352 // The context menu should not show the option to "Show managed bookmarks".
357 EXPECT_FALSE( 353 EXPECT_FALSE(
358 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)); 354 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS));
359 views::MenuItemView* menu = controller->menu(); 355 views::MenuItemView* menu = controller->menu();
360 EXPECT_FALSE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS) 356 EXPECT_FALSE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)
361 ->visible()); 357 ->visible());
362 358
363 // Other options are not affected. 359 // Other options are not affected.
364 EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER)); 360 EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER));
365 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible()); 361 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible());
366 362
367 // Now set the managed bookmarks policy. 363 // Now set the managed bookmarks policy.
368 base::DictionaryValue* dict = new base::DictionaryValue; 364 base::DictionaryValue* dict = new base::DictionaryValue;
369 dict->SetString("name", "Google"); 365 dict->SetString("name", "Google");
370 dict->SetString("url", "http://google.com"); 366 dict->SetString("url", "http://google.com");
371 base::ListValue list; 367 base::ListValue list;
372 list.Append(dict); 368 list.Append(dict);
373 EXPECT_TRUE(client->managed_node()->empty()); 369 EXPECT_TRUE(model_->managed_node()->empty());
374 profile_->GetPrefs()->Set(bookmarks::prefs::kManagedBookmarks, list); 370 profile_->GetPrefs()->Set(bookmarks::prefs::kManagedBookmarks, list);
375 EXPECT_FALSE(client->managed_node()->empty()); 371 EXPECT_FALSE(model_->managed_node()->empty());
376 372
377 // New context menus now show the "Show managed bookmarks" option. 373 // New context menus now show the "Show managed bookmarks" option.
378 controller.reset(new BookmarkContextMenu( 374 controller.reset(new BookmarkContextMenu(
379 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); 375 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false));
380 EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER)); 376 EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER));
381 EXPECT_TRUE( 377 EXPECT_TRUE(
382 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)); 378 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS));
383 menu = controller->menu(); 379 menu = controller->menu();
384 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible()); 380 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible());
385 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS) 381 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)
386 ->visible()); 382 ->visible());
387 } 383 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698