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