| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bookmarks/bookmark_context_menu_controller.h" | 5 #include "chrome/browser/ui/bookmarks/bookmark_context_menu_controller.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 class BookmarkContextMenuControllerTest : public testing::Test { | 40 class BookmarkContextMenuControllerTest : public testing::Test { |
| 41 public: | 41 public: |
| 42 BookmarkContextMenuControllerTest() | 42 BookmarkContextMenuControllerTest() |
| 43 : ui_thread_(BrowserThread::UI, &message_loop_), | 43 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 44 file_thread_(BrowserThread::FILE, &message_loop_), | 44 file_thread_(BrowserThread::FILE, &message_loop_), |
| 45 model_(NULL) { | 45 model_(NULL) { |
| 46 } | 46 } |
| 47 | 47 |
| 48 virtual void SetUp() OVERRIDE { | 48 virtual void SetUp() OVERRIDE { |
| 49 profile_.reset(new TestingProfile()); | 49 Reset(false); |
| 50 } |
| 51 void Reset(bool incognito) { |
| 52 TestingProfile::Builder builder; |
| 53 if (incognito) |
| 54 builder.SetIncognito(); |
| 55 profile_ = builder.Build(); |
| 50 profile_->CreateBookmarkModel(true); | 56 profile_->CreateBookmarkModel(true); |
| 51 | 57 |
| 52 model_ = BookmarkModelFactory::GetForProfile(profile_.get()); | 58 model_ = BookmarkModelFactory::GetForProfile(profile_.get()); |
| 53 ui_test_utils::WaitForBookmarkModelToLoad(model_); | 59 ui_test_utils::WaitForBookmarkModelToLoad(model_); |
| 54 | 60 |
| 55 AddTestData(); | 61 AddTestData(); |
| 56 } | 62 } |
| 57 | 63 |
| 58 virtual void TearDown() OVERRIDE { | 64 virtual void TearDown() OVERRIDE { |
| 59 ui::Clipboard::DestroyClipboardForCurrentThread(); | 65 ui::Clipboard::DestroyClipboardForCurrentThread(); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO)); | 236 controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO)); |
| 231 EXPECT_TRUE(controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_REMOVE)); | 237 EXPECT_TRUE(controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_REMOVE)); |
| 232 EXPECT_TRUE( | 238 EXPECT_TRUE( |
| 233 controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK)); | 239 controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK)); |
| 234 EXPECT_TRUE( | 240 EXPECT_TRUE( |
| 235 controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER)); | 241 controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER)); |
| 236 } | 242 } |
| 237 | 243 |
| 238 // Tests the enabled state of open incognito. | 244 // Tests the enabled state of open incognito. |
| 239 TEST_F(BookmarkContextMenuControllerTest, DisableIncognito) { | 245 TEST_F(BookmarkContextMenuControllerTest, DisableIncognito) { |
| 246 // Create a new incognito profile. |
| 247 Reset(true); |
| 240 std::vector<const BookmarkNode*> nodes; | 248 std::vector<const BookmarkNode*> nodes; |
| 241 nodes.push_back(model_->bookmark_bar_node()->GetChild(0)); | 249 nodes.push_back(model_->bookmark_bar_node()->GetChild(0)); |
| 242 BookmarkContextMenuController controller( | 250 BookmarkContextMenuController controller( |
| 243 NULL, NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes); | 251 NULL, NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes); |
| 244 profile_->set_incognito(true); | |
| 245 EXPECT_FALSE(controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_OPEN_INCOGNITO)); | 252 EXPECT_FALSE(controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_OPEN_INCOGNITO)); |
| 246 EXPECT_FALSE( | 253 EXPECT_FALSE( |
| 247 controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO)); | 254 controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO)); |
| 248 } | 255 } |
| 249 | 256 |
| 250 // Tests that you can't remove/edit when showing the other node. | 257 // Tests that you can't remove/edit when showing the other node. |
| 251 TEST_F(BookmarkContextMenuControllerTest, DisabledItemsWithOtherNode) { | 258 TEST_F(BookmarkContextMenuControllerTest, DisabledItemsWithOtherNode) { |
| 252 std::vector<const BookmarkNode*> nodes; | 259 std::vector<const BookmarkNode*> nodes; |
| 253 nodes.push_back(model_->other_node()); | 260 nodes.push_back(model_->other_node()); |
| 254 BookmarkContextMenuController controller( | 261 BookmarkContextMenuController controller( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 ASSERT_EQ(bb_node->GetChild(0)->url(), bb_node->GetChild(1)->url()); | 324 ASSERT_EQ(bb_node->GetChild(0)->url(), bb_node->GetChild(1)->url()); |
| 318 | 325 |
| 319 controller.reset(new BookmarkContextMenuController( | 326 controller.reset(new BookmarkContextMenuController( |
| 320 NULL, NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes)); | 327 NULL, NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes)); |
| 321 // Cut the URL. | 328 // Cut the URL. |
| 322 controller->ExecuteCommand(IDC_CUT, 0); | 329 controller->ExecuteCommand(IDC_CUT, 0); |
| 323 ASSERT_TRUE(bb_node->GetChild(0)->is_url()); | 330 ASSERT_TRUE(bb_node->GetChild(0)->is_url()); |
| 324 ASSERT_TRUE(bb_node->GetChild(1)->is_folder()); | 331 ASSERT_TRUE(bb_node->GetChild(1)->is_folder()); |
| 325 ASSERT_EQ(old_count, bb_node->child_count()); | 332 ASSERT_EQ(old_count, bb_node->child_count()); |
| 326 } | 333 } |
| OLD | NEW |