| 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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 class BookmarkContextMenuControllerTest : public testing::Test { | 42 class BookmarkContextMenuControllerTest : public testing::Test { |
| 43 public: | 43 public: |
| 44 BookmarkContextMenuControllerTest() | 44 BookmarkContextMenuControllerTest() |
| 45 : ui_thread_(BrowserThread::UI, &message_loop_), | 45 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 46 file_thread_(BrowserThread::FILE, &message_loop_), | 46 file_thread_(BrowserThread::FILE, &message_loop_), |
| 47 model_(NULL) { | 47 model_(NULL) { |
| 48 } | 48 } |
| 49 | 49 |
| 50 virtual void SetUp() OVERRIDE { | 50 virtual void SetUp() OVERRIDE { |
| 51 Reset(false); | |
| 52 } | |
| 53 void Reset(bool incognito) { | |
| 54 TestingProfile::Builder builder; | 51 TestingProfile::Builder builder; |
| 55 if (incognito) | |
| 56 builder.SetIncognito(); | |
| 57 profile_ = builder.Build(); | 52 profile_ = builder.Build(); |
| 58 profile_->CreateBookmarkModel(true); | 53 profile_->CreateBookmarkModel(true); |
| 59 | |
| 60 model_ = BookmarkModelFactory::GetForProfile(profile_.get()); | 54 model_ = BookmarkModelFactory::GetForProfile(profile_.get()); |
| 61 test::WaitForBookmarkModelToLoad(model_); | 55 test::WaitForBookmarkModelToLoad(model_); |
| 62 | 56 AddTestData(model_); |
| 63 AddTestData(); | |
| 64 } | 57 } |
| 65 | 58 |
| 66 virtual void TearDown() OVERRIDE { | 59 virtual void TearDown() OVERRIDE { |
| 67 ui::Clipboard::DestroyClipboardForCurrentThread(); | 60 ui::Clipboard::DestroyClipboardForCurrentThread(); |
| 68 | 61 |
| 69 // Flush the message loop to make application verifiers happy. | 62 // Flush the message loop to make application verifiers happy. |
| 70 message_loop_.RunUntilIdle(); | 63 message_loop_.RunUntilIdle(); |
| 71 } | 64 } |
| 72 | 65 |
| 73 protected: | |
| 74 base::MessageLoopForUI message_loop_; | |
| 75 content::TestBrowserThread ui_thread_; | |
| 76 content::TestBrowserThread file_thread_; | |
| 77 scoped_ptr<TestingProfile> profile_; | |
| 78 BookmarkModel* model_; | |
| 79 TestingPageNavigator navigator_; | |
| 80 | |
| 81 private: | |
| 82 // Creates the following structure: | 66 // Creates the following structure: |
| 83 // a | 67 // a |
| 84 // F1 | 68 // F1 |
| 85 // f1a | 69 // f1a |
| 86 // F11 | 70 // F11 |
| 87 // f11a | 71 // f11a |
| 88 // F2 | 72 // F2 |
| 89 // F3 | 73 // F3 |
| 90 // F4 | 74 // F4 |
| 91 // f4a | 75 // f4a |
| 92 void AddTestData() { | 76 static void AddTestData(BookmarkModel* model) { |
| 93 const BookmarkNode* bb_node = model_->bookmark_bar_node(); | 77 const BookmarkNode* bb_node = model->bookmark_bar_node(); |
| 94 std::string test_base = "file:///c:/tmp/"; | 78 std::string test_base = "file:///c:/tmp/"; |
| 95 model_->AddURL(bb_node, 0, ASCIIToUTF16("a"), GURL(test_base + "a")); | 79 model->AddURL(bb_node, 0, ASCIIToUTF16("a"), GURL(test_base + "a")); |
| 96 const BookmarkNode* f1 = model_->AddFolder(bb_node, 1, ASCIIToUTF16("F1")); | 80 const BookmarkNode* f1 = model->AddFolder(bb_node, 1, ASCIIToUTF16("F1")); |
| 97 model_->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a")); | 81 model->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a")); |
| 98 const BookmarkNode* f11 = model_->AddFolder(f1, 1, ASCIIToUTF16("F11")); | 82 const BookmarkNode* f11 = model->AddFolder(f1, 1, ASCIIToUTF16("F11")); |
| 99 model_->AddURL(f11, 0, ASCIIToUTF16("f11a"), GURL(test_base + "f11a")); | 83 model->AddURL(f11, 0, ASCIIToUTF16("f11a"), GURL(test_base + "f11a")); |
| 100 model_->AddFolder(bb_node, 2, ASCIIToUTF16("F2")); | 84 model->AddFolder(bb_node, 2, ASCIIToUTF16("F2")); |
| 101 model_->AddFolder(bb_node, 3, ASCIIToUTF16("F3")); | 85 model->AddFolder(bb_node, 3, ASCIIToUTF16("F3")); |
| 102 const BookmarkNode* f4 = model_->AddFolder(bb_node, 4, ASCIIToUTF16("F4")); | 86 const BookmarkNode* f4 = model->AddFolder(bb_node, 4, ASCIIToUTF16("F4")); |
| 103 model_->AddURL(f4, 0, ASCIIToUTF16("f4a"), GURL(test_base + "f4a")); | 87 model->AddURL(f4, 0, ASCIIToUTF16("f4a"), GURL(test_base + "f4a")); |
| 104 } | 88 } |
| 89 |
| 90 protected: |
| 91 base::MessageLoopForUI message_loop_; |
| 92 content::TestBrowserThread ui_thread_; |
| 93 content::TestBrowserThread file_thread_; |
| 94 scoped_ptr<TestingProfile> profile_; |
| 95 BookmarkModel* model_; |
| 96 TestingPageNavigator navigator_; |
| 105 }; | 97 }; |
| 106 | 98 |
| 107 // Tests Deleting from the menu. | 99 // Tests Deleting from the menu. |
| 108 TEST_F(BookmarkContextMenuControllerTest, DeleteURL) { | 100 TEST_F(BookmarkContextMenuControllerTest, DeleteURL) { |
| 109 std::vector<const BookmarkNode*> nodes; | 101 std::vector<const BookmarkNode*> nodes; |
| 110 nodes.push_back(model_->bookmark_bar_node()->GetChild(0)); | 102 nodes.push_back(model_->bookmark_bar_node()->GetChild(0)); |
| 111 BookmarkContextMenuController controller( | 103 BookmarkContextMenuController controller( |
| 112 NULL, NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes); | 104 NULL, NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes); |
| 113 GURL url = model_->bookmark_bar_node()->GetChild(0)->url(); | 105 GURL url = model_->bookmark_bar_node()->GetChild(0)->url(); |
| 114 ASSERT_TRUE(controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_REMOVE)); | 106 ASSERT_TRUE(controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_REMOVE)); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO)); | 230 controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO)); |
| 239 EXPECT_TRUE(controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_REMOVE)); | 231 EXPECT_TRUE(controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_REMOVE)); |
| 240 EXPECT_TRUE( | 232 EXPECT_TRUE( |
| 241 controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK)); | 233 controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK)); |
| 242 EXPECT_TRUE( | 234 EXPECT_TRUE( |
| 243 controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER)); | 235 controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER)); |
| 244 } | 236 } |
| 245 | 237 |
| 246 // Tests the enabled state of open incognito. | 238 // Tests the enabled state of open incognito. |
| 247 TEST_F(BookmarkContextMenuControllerTest, DisableIncognito) { | 239 TEST_F(BookmarkContextMenuControllerTest, DisableIncognito) { |
| 248 // Create a new incognito profile. | 240 // Create an incognito Profile. It must be associated with the original |
| 249 Reset(true); | 241 // Profile, so that GetOriginalProfile() works as expected. |
| 242 TestingProfile::Builder builder; |
| 243 builder.SetIncognito(); |
| 244 scoped_ptr<TestingProfile> testing_incognito = builder.Build(); |
| 245 testing_incognito->SetOriginalProfile(profile_.get()); |
| 246 TestingProfile* incognito = testing_incognito.get(); |
| 247 profile_->SetOffTheRecordProfile(testing_incognito.PassAs<Profile>()); |
| 248 |
| 249 incognito->CreateBookmarkModel(true); |
| 250 BookmarkModel* model = BookmarkModelFactory::GetForProfile(incognito); |
| 251 test::WaitForBookmarkModelToLoad(model); |
| 252 AddTestData(model); |
| 253 |
| 250 std::vector<const BookmarkNode*> nodes; | 254 std::vector<const BookmarkNode*> nodes; |
| 251 nodes.push_back(model_->bookmark_bar_node()->GetChild(0)); | 255 nodes.push_back(model->bookmark_bar_node()->GetChild(0)); |
| 252 BookmarkContextMenuController controller( | 256 BookmarkContextMenuController controller( |
| 253 NULL, NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes); | 257 NULL, NULL, NULL, incognito, NULL, nodes[0]->parent(), nodes); |
| 254 EXPECT_FALSE(controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_OPEN_INCOGNITO)); | 258 EXPECT_FALSE(controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_OPEN_INCOGNITO)); |
| 255 EXPECT_FALSE( | 259 EXPECT_FALSE( |
| 256 controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO)); | 260 controller.IsCommandIdEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO)); |
| 257 } | 261 } |
| 258 | 262 |
| 259 // Tests that you can't remove/edit when showing the other node. | 263 // Tests that you can't remove/edit when showing the other node. |
| 260 TEST_F(BookmarkContextMenuControllerTest, DisabledItemsWithOtherNode) { | 264 TEST_F(BookmarkContextMenuControllerTest, DisabledItemsWithOtherNode) { |
| 261 std::vector<const BookmarkNode*> nodes; | 265 std::vector<const BookmarkNode*> nodes; |
| 262 nodes.push_back(model_->other_node()); | 266 nodes.push_back(model_->other_node()); |
| 263 BookmarkContextMenuController controller( | 267 BookmarkContextMenuController controller( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 ASSERT_EQ(bb_node->GetChild(0)->url(), bb_node->GetChild(1)->url()); | 330 ASSERT_EQ(bb_node->GetChild(0)->url(), bb_node->GetChild(1)->url()); |
| 327 | 331 |
| 328 controller.reset(new BookmarkContextMenuController( | 332 controller.reset(new BookmarkContextMenuController( |
| 329 NULL, NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes)); | 333 NULL, NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes)); |
| 330 // Cut the URL. | 334 // Cut the URL. |
| 331 controller->ExecuteCommand(IDC_CUT, 0); | 335 controller->ExecuteCommand(IDC_CUT, 0); |
| 332 ASSERT_TRUE(bb_node->GetChild(0)->is_url()); | 336 ASSERT_TRUE(bb_node->GetChild(0)->is_url()); |
| 333 ASSERT_TRUE(bb_node->GetChild(1)->is_folder()); | 337 ASSERT_TRUE(bb_node->GetChild(1)->is_folder()); |
| 334 ASSERT_EQ(old_count, bb_node->child_count()); | 338 ASSERT_EQ(old_count, bb_node->child_count()); |
| 335 } | 339 } |
| OLD | NEW |