| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "chrome/app/chrome_command_ids.h" | 18 #include "chrome/app/chrome_command_ids.h" |
| 19 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 19 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 20 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" | 20 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h" | 22 #include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h" |
| 23 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 76 } |
| 77 | 77 |
| 78 void TearDown() override { | 78 void TearDown() override { |
| 79 ui::Clipboard::DestroyClipboardForCurrentThread(); | 79 ui::Clipboard::DestroyClipboardForCurrentThread(); |
| 80 | 80 |
| 81 BrowserThread::GetBlockingPool()->FlushForTesting(); | 81 BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 protected: | 84 protected: |
| 85 content::TestBrowserThreadBundle thread_bundle_; | 85 content::TestBrowserThreadBundle thread_bundle_; |
| 86 scoped_ptr<TestingProfile> profile_; | 86 std::unique_ptr<TestingProfile> profile_; |
| 87 BookmarkModel* model_; | 87 BookmarkModel* model_; |
| 88 TestingPageNavigator navigator_; | 88 TestingPageNavigator navigator_; |
| 89 | 89 |
| 90 private: | 90 private: |
| 91 // Creates the following structure: | 91 // Creates the following structure: |
| 92 // a | 92 // a |
| 93 // F1 | 93 // F1 |
| 94 // f1a | 94 // f1a |
| 95 // -f1b as "chrome://settings" | 95 // -f1b as "chrome://settings" |
| 96 // F11 | 96 // F11 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 EXPECT_FALSE( | 298 EXPECT_FALSE( |
| 299 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK)); | 299 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK)); |
| 300 EXPECT_FALSE( | 300 EXPECT_FALSE( |
| 301 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER)); | 301 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER)); |
| 302 } | 302 } |
| 303 | 303 |
| 304 TEST_F(BookmarkContextMenuTest, CutCopyPasteNode) { | 304 TEST_F(BookmarkContextMenuTest, CutCopyPasteNode) { |
| 305 const BookmarkNode* bb_node = model_->bookmark_bar_node(); | 305 const BookmarkNode* bb_node = model_->bookmark_bar_node(); |
| 306 std::vector<const BookmarkNode*> nodes; | 306 std::vector<const BookmarkNode*> nodes; |
| 307 nodes.push_back(bb_node->GetChild(0)); | 307 nodes.push_back(bb_node->GetChild(0)); |
| 308 scoped_ptr<BookmarkContextMenu> controller(new BookmarkContextMenu( | 308 std::unique_ptr<BookmarkContextMenu> controller(new BookmarkContextMenu( |
| 309 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); | 309 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); |
| 310 EXPECT_TRUE(controller->IsCommandEnabled(IDC_COPY)); | 310 EXPECT_TRUE(controller->IsCommandEnabled(IDC_COPY)); |
| 311 EXPECT_TRUE(controller->IsCommandEnabled(IDC_CUT)); | 311 EXPECT_TRUE(controller->IsCommandEnabled(IDC_CUT)); |
| 312 | 312 |
| 313 // Copy the URL. | 313 // Copy the URL. |
| 314 controller->ExecuteCommand(IDC_COPY, 0); | 314 controller->ExecuteCommand(IDC_COPY, 0); |
| 315 | 315 |
| 316 controller.reset(new BookmarkContextMenu( | 316 controller.reset(new BookmarkContextMenu( |
| 317 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); | 317 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); |
| 318 int old_count = bb_node->child_count(); | 318 int old_count = bb_node->child_count(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 331 ASSERT_EQ(old_count, bb_node->child_count()); | 331 ASSERT_EQ(old_count, bb_node->child_count()); |
| 332 } | 332 } |
| 333 | 333 |
| 334 // Tests that the "Show managed bookmarks" option in the context menu is only | 334 // Tests that the "Show managed bookmarks" option in the context menu is only |
| 335 // visible if the policy is set. | 335 // visible if the policy is set. |
| 336 TEST_F(BookmarkContextMenuTest, ShowManagedBookmarks) { | 336 TEST_F(BookmarkContextMenuTest, ShowManagedBookmarks) { |
| 337 // Create a BookmarkContextMenu for the bookmarks bar. | 337 // Create a BookmarkContextMenu for the bookmarks bar. |
| 338 const BookmarkNode* bb_node = model_->bookmark_bar_node(); | 338 const BookmarkNode* bb_node = model_->bookmark_bar_node(); |
| 339 std::vector<const BookmarkNode*> nodes; | 339 std::vector<const BookmarkNode*> nodes; |
| 340 nodes.push_back(bb_node->GetChild(0)); | 340 nodes.push_back(bb_node->GetChild(0)); |
| 341 scoped_ptr<BookmarkContextMenu> controller(new BookmarkContextMenu( | 341 std::unique_ptr<BookmarkContextMenu> controller(new BookmarkContextMenu( |
| 342 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); | 342 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); |
| 343 | 343 |
| 344 // Verify that there are no managed nodes yet. | 344 // Verify that there are no managed nodes yet. |
| 345 bookmarks::ManagedBookmarkService* managed = | 345 bookmarks::ManagedBookmarkService* managed = |
| 346 ManagedBookmarkServiceFactory::GetForProfile(profile_.get()); | 346 ManagedBookmarkServiceFactory::GetForProfile(profile_.get()); |
| 347 EXPECT_TRUE(managed->managed_node()->empty()); | 347 EXPECT_TRUE(managed->managed_node()->empty()); |
| 348 | 348 |
| 349 // The context menu should not show the option to "Show managed bookmarks". | 349 // The context menu should not show the option to "Show managed bookmarks". |
| 350 EXPECT_FALSE( | 350 EXPECT_FALSE( |
| 351 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)); | 351 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 371 controller.reset(new BookmarkContextMenu( | 371 controller.reset(new BookmarkContextMenu( |
| 372 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); | 372 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); |
| 373 EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER)); | 373 EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER)); |
| 374 EXPECT_TRUE( | 374 EXPECT_TRUE( |
| 375 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)); | 375 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)); |
| 376 menu = controller->menu(); | 376 menu = controller->menu(); |
| 377 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible()); | 377 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible()); |
| 378 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS) | 378 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS) |
| 379 ->visible()); | 379 ->visible()); |
| 380 } | 380 } |
| OLD | NEW |