[email protected] | 0568e6ca | 2010-05-06 21:06:48 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 1df533b | 2010-02-02 22:50:07 | [diff] [blame] | 5 | #include "base/scoped_ptr.h" |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 6 | #include "chrome/browser/bookmarks/bookmark_model.h" |
| 7 | #include "chrome/browser/bookmarks/bookmark_utils.h" |
[email protected] | 6fad263 | 2009-11-02 05:59:37 | [diff] [blame] | 8 | #include "chrome/browser/chrome_thread.h" |
[email protected] | 052313b | 2010-02-19 09:43:08 | [diff] [blame] | 9 | #include "chrome/browser/pref_service.h" |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 10 | #include "chrome/browser/profile.h" |
[email protected] | f3ec774 | 2009-01-15 00:59:16 | [diff] [blame] | 11 | #include "chrome/browser/tab_contents/page_navigator.h" |
[email protected] | 052313b | 2010-02-19 09:43:08 | [diff] [blame] | 12 | #include "chrome/browser/views/bookmark_context_menu.h" |
| 13 | #include "chrome/common/pref_names.h" |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 14 | #include "chrome/test/testing_profile.h" |
[email protected] | 34ac8f3 | 2009-02-22 23:03:27 | [diff] [blame] | 15 | #include "grit/generated_resources.h" |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 16 | #include "testing/gtest/include/gtest/gtest.h" |
| 17 | |
[email protected] | 66cb835 | 2009-04-22 00:12:29 | [diff] [blame] | 18 | #if defined(OS_WIN) |
| 19 | #include "chrome/browser/views/bookmark_bar_view.h" |
| 20 | #endif |
| 21 | |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 22 | namespace { |
| 23 | |
| 24 | // PageNavigator implementation that records the URL. |
| 25 | class TestingPageNavigator : public PageNavigator { |
| 26 | public: |
| 27 | virtual void OpenURL(const GURL& url, |
| 28 | const GURL& referrer, |
| 29 | WindowOpenDisposition disposition, |
| 30 | PageTransition::Type transition) { |
| 31 | urls_.push_back(url); |
| 32 | } |
| 33 | |
| 34 | std::vector<GURL> urls_; |
| 35 | }; |
| 36 | |
| 37 | } // namespace |
| 38 | |
| 39 | class BookmarkContextMenuTest : public testing::Test { |
| 40 | public: |
| 41 | BookmarkContextMenuTest() |
[email protected] | 6fad263 | 2009-11-02 05:59:37 | [diff] [blame] | 42 | : ui_thread_(ChromeThread::UI, &message_loop_), |
| 43 | file_thread_(ChromeThread::FILE, &message_loop_), |
| 44 | model_(NULL) { |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | virtual void SetUp() { |
[email protected] | 66cb835 | 2009-04-22 00:12:29 | [diff] [blame] | 48 | #if defined(OS_WIN) |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 49 | BookmarkBarView::testing_ = true; |
[email protected] | 66cb835 | 2009-04-22 00:12:29 | [diff] [blame] | 50 | #endif |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 51 | |
| 52 | profile_.reset(new TestingProfile()); |
| 53 | profile_->set_has_history_service(true); |
| 54 | profile_->CreateBookmarkModel(true); |
| 55 | profile_->BlockUntilBookmarkModelLoaded(); |
| 56 | |
| 57 | model_ = profile_->GetBookmarkModel(); |
| 58 | |
| 59 | AddTestData(); |
| 60 | } |
| 61 | |
| 62 | virtual void TearDown() { |
[email protected] | 66cb835 | 2009-04-22 00:12:29 | [diff] [blame] | 63 | #if defined(OS_WIN) |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 64 | BookmarkBarView::testing_ = false; |
[email protected] | 66cb835 | 2009-04-22 00:12:29 | [diff] [blame] | 65 | #endif |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 66 | |
| 67 | // Flush the message loop to make Purify happy. |
| 68 | message_loop_.RunAllPending(); |
| 69 | } |
| 70 | |
| 71 | protected: |
| 72 | MessageLoopForUI message_loop_; |
[email protected] | 6fad263 | 2009-11-02 05:59:37 | [diff] [blame] | 73 | ChromeThread ui_thread_; |
| 74 | ChromeThread file_thread_; |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 75 | scoped_ptr<TestingProfile> profile_; |
| 76 | BookmarkModel* model_; |
| 77 | TestingPageNavigator navigator_; |
| 78 | |
| 79 | private: |
| 80 | // Creates the following structure: |
| 81 | // a |
| 82 | // F1 |
| 83 | // f1a |
| 84 | // F11 |
| 85 | // f11a |
| 86 | // F2 |
| 87 | // F3 |
| 88 | // F4 |
| 89 | // f4a |
| 90 | void AddTestData() { |
| 91 | std::string test_base = "file:///c:/tmp/"; |
| 92 | |
| 93 | model_->AddURL(model_->GetBookmarkBarNode(), 0, L"a", |
| 94 | GURL(test_base + "a")); |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 95 | const BookmarkNode* f1 = |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 96 | model_->AddGroup(model_->GetBookmarkBarNode(), 1, L"F1"); |
| 97 | model_->AddURL(f1, 0, L"f1a", GURL(test_base + "f1a")); |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 98 | const BookmarkNode* f11 = model_->AddGroup(f1, 1, L"F11"); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 99 | model_->AddURL(f11, 0, L"f11a", GURL(test_base + "f11a")); |
| 100 | model_->AddGroup(model_->GetBookmarkBarNode(), 2, L"F2"); |
| 101 | model_->AddGroup(model_->GetBookmarkBarNode(), 3, L"F3"); |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 102 | const BookmarkNode* f4 = |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 103 | model_->AddGroup(model_->GetBookmarkBarNode(), 4, L"F4"); |
| 104 | model_->AddURL(f4, 0, L"f4a", GURL(test_base + "f4a")); |
| 105 | } |
| 106 | }; |
| 107 | |
| 108 | // Tests Deleting from the menu. |
| 109 | TEST_F(BookmarkContextMenuTest, DeleteURL) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 110 | std::vector<const BookmarkNode*> nodes; |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 111 | nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); |
| 112 | BookmarkContextMenu controller( |
[email protected] | 0568e6ca | 2010-05-06 21:06:48 | [diff] [blame] | 113 | NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 114 | GURL url = model_->GetBookmarkBarNode()->GetChild(0)->GetURL(); |
| 115 | ASSERT_TRUE(controller.IsCommandEnabled(IDS_BOOKMARK_BAR_REMOVE)); |
| 116 | // Delete the URL. |
| 117 | controller.ExecuteCommand(IDS_BOOKMARK_BAR_REMOVE); |
| 118 | // Model shouldn't have URL anymore. |
| 119 | ASSERT_FALSE(model_->IsBookmarked(url)); |
| 120 | } |
| 121 | |
| 122 | // Tests open all on a folder with a couple of bookmarks. |
| 123 | TEST_F(BookmarkContextMenuTest, OpenAll) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 124 | const BookmarkNode* folder = model_->GetBookmarkBarNode()->GetChild(1); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 125 | bookmark_utils::OpenAll( |
| 126 | NULL, profile_.get(), &navigator_, folder, NEW_FOREGROUND_TAB); |
| 127 | |
| 128 | // Should have navigated to F1's children. |
[email protected] | 66cb835 | 2009-04-22 00:12:29 | [diff] [blame] | 129 | ASSERT_EQ(static_cast<size_t>(2), navigator_.urls_.size()); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 130 | ASSERT_TRUE(folder->GetChild(0)->GetURL() == navigator_.urls_[0]); |
| 131 | ASSERT_TRUE(folder->GetChild(1)->GetChild(0)->GetURL() == |
| 132 | navigator_.urls_[1]); |
| 133 | } |
| 134 | |
| 135 | // Tests the enabled state of the menus when supplied an empty vector. |
| 136 | TEST_F(BookmarkContextMenuTest, EmptyNodes) { |
| 137 | BookmarkContextMenu controller( |
[email protected] | 5aa458fc | 2009-06-27 06:07:55 | [diff] [blame] | 138 | NULL, profile_.get(), NULL, model_->other_node(), |
[email protected] | 0568e6ca | 2010-05-06 21:06:48 | [diff] [blame] | 139 | std::vector<const BookmarkNode*>()); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 140 | EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); |
| 141 | EXPECT_FALSE( |
| 142 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); |
| 143 | EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO)); |
| 144 | EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOKMARK_BAR_REMOVE)); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 145 | EXPECT_TRUE( |
| 146 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK)); |
| 147 | EXPECT_TRUE( |
| 148 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_NEW_FOLDER)); |
| 149 | } |
| 150 | |
| 151 | // Tests the enabled state of the menus when supplied a vector with a single |
| 152 | // url. |
| 153 | TEST_F(BookmarkContextMenuTest, SingleURL) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 154 | std::vector<const BookmarkNode*> nodes; |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 155 | nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); |
| 156 | BookmarkContextMenu controller( |
[email protected] | 0568e6ca | 2010-05-06 21:06:48 | [diff] [blame] | 157 | NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 158 | EXPECT_TRUE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); |
| 159 | EXPECT_TRUE( |
| 160 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); |
| 161 | EXPECT_TRUE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO)); |
| 162 | EXPECT_TRUE(controller.IsCommandEnabled(IDS_BOOKMARK_BAR_REMOVE)); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 163 | EXPECT_TRUE( |
| 164 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK)); |
| 165 | EXPECT_TRUE( |
| 166 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_NEW_FOLDER)); |
| 167 | } |
| 168 | |
| 169 | // Tests the enabled state of the menus when supplied a vector with multiple |
| 170 | // urls. |
| 171 | TEST_F(BookmarkContextMenuTest, MultipleURLs) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 172 | std::vector<const BookmarkNode*> nodes; |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 173 | nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); |
| 174 | nodes.push_back(model_->GetBookmarkBarNode()->GetChild(1)->GetChild(0)); |
| 175 | BookmarkContextMenu controller( |
[email protected] | 0568e6ca | 2010-05-06 21:06:48 | [diff] [blame] | 176 | NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 177 | EXPECT_TRUE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); |
| 178 | EXPECT_TRUE( |
| 179 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); |
| 180 | EXPECT_TRUE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO)); |
| 181 | EXPECT_TRUE(controller.IsCommandEnabled(IDS_BOOKMARK_BAR_REMOVE)); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 182 | EXPECT_TRUE( |
| 183 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK)); |
| 184 | EXPECT_TRUE( |
| 185 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_NEW_FOLDER)); |
| 186 | } |
| 187 | |
| 188 | // Tests the enabled state of the menus when supplied an vector with a single |
| 189 | // folder. |
| 190 | TEST_F(BookmarkContextMenuTest, SingleFolder) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 191 | std::vector<const BookmarkNode*> nodes; |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 192 | nodes.push_back(model_->GetBookmarkBarNode()->GetChild(2)); |
| 193 | BookmarkContextMenu controller( |
[email protected] | 0568e6ca | 2010-05-06 21:06:48 | [diff] [blame] | 194 | NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 195 | EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); |
| 196 | EXPECT_FALSE( |
| 197 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); |
| 198 | EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO)); |
| 199 | EXPECT_TRUE(controller.IsCommandEnabled(IDS_BOOKMARK_BAR_REMOVE)); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 200 | EXPECT_TRUE( |
| 201 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK)); |
| 202 | EXPECT_TRUE( |
| 203 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_NEW_FOLDER)); |
| 204 | } |
| 205 | |
| 206 | // Tests the enabled state of the menus when supplied a vector with multiple |
| 207 | // folders, all of which are empty. |
| 208 | TEST_F(BookmarkContextMenuTest, MultipleEmptyFolders) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 209 | std::vector<const BookmarkNode*> nodes; |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 210 | nodes.push_back(model_->GetBookmarkBarNode()->GetChild(2)); |
| 211 | nodes.push_back(model_->GetBookmarkBarNode()->GetChild(3)); |
| 212 | BookmarkContextMenu controller( |
[email protected] | 0568e6ca | 2010-05-06 21:06:48 | [diff] [blame] | 213 | NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 214 | EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); |
| 215 | EXPECT_FALSE( |
| 216 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); |
| 217 | EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO)); |
| 218 | EXPECT_TRUE(controller.IsCommandEnabled(IDS_BOOKMARK_BAR_REMOVE)); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 219 | EXPECT_TRUE( |
| 220 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK)); |
| 221 | EXPECT_TRUE( |
| 222 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_NEW_FOLDER)); |
| 223 | } |
| 224 | |
| 225 | // Tests the enabled state of the menus when supplied a vector with multiple |
| 226 | // folders, some of which contain URLs. |
| 227 | TEST_F(BookmarkContextMenuTest, MultipleFoldersWithURLs) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 228 | std::vector<const BookmarkNode*> nodes; |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 229 | nodes.push_back(model_->GetBookmarkBarNode()->GetChild(3)); |
| 230 | nodes.push_back(model_->GetBookmarkBarNode()->GetChild(4)); |
| 231 | BookmarkContextMenu controller( |
[email protected] | 0568e6ca | 2010-05-06 21:06:48 | [diff] [blame] | 232 | NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 233 | EXPECT_TRUE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); |
| 234 | EXPECT_TRUE( |
| 235 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); |
| 236 | EXPECT_TRUE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO)); |
| 237 | EXPECT_TRUE(controller.IsCommandEnabled(IDS_BOOKMARK_BAR_REMOVE)); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 238 | EXPECT_TRUE( |
| 239 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK)); |
| 240 | EXPECT_TRUE( |
| 241 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_NEW_FOLDER)); |
| 242 | } |
| 243 | |
| 244 | // Tests the enabled state of open incognito. |
| 245 | TEST_F(BookmarkContextMenuTest, DisableIncognito) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 246 | std::vector<const BookmarkNode*> nodes; |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 247 | nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); |
| 248 | BookmarkContextMenu controller( |
[email protected] | 0568e6ca | 2010-05-06 21:06:48 | [diff] [blame] | 249 | NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 250 | profile_->set_off_the_record(true); |
| 251 | EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_INCOGNITO)); |
| 252 | EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO)); |
| 253 | } |
| 254 | |
| 255 | // Tests that you can't remove/edit when showing the other node. |
| 256 | TEST_F(BookmarkContextMenuTest, DisabledItemsWithOtherNode) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 257 | std::vector<const BookmarkNode*> nodes; |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 258 | nodes.push_back(model_->other_node()); |
| 259 | BookmarkContextMenu controller( |
[email protected] | 0568e6ca | 2010-05-06 21:06:48 | [diff] [blame] | 260 | NULL, profile_.get(), NULL, nodes[0], nodes); |
[email protected] | 7f856be | 2008-10-29 23:38:06 | [diff] [blame] | 261 | EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOKMARK_BAR_EDIT)); |
| 262 | EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOKMARK_BAR_REMOVE)); |
| 263 | } |
[email protected] | 5a43397 | 2008-11-05 15:39:44 | [diff] [blame] | 264 | |
| 265 | // Tests the enabled state of the menus when supplied an empty vector and null |
| 266 | // parent. |
| 267 | TEST_F(BookmarkContextMenuTest, EmptyNodesNullParent) { |
| 268 | BookmarkContextMenu controller( |
[email protected] | 0568e6ca | 2010-05-06 21:06:48 | [diff] [blame] | 269 | NULL, profile_.get(), NULL, NULL, std::vector<const BookmarkNode*>()); |
[email protected] | 5a43397 | 2008-11-05 15:39:44 | [diff] [blame] | 270 | EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); |
| 271 | EXPECT_FALSE( |
| 272 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); |
| 273 | EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO)); |
| 274 | EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOKMARK_BAR_REMOVE)); |
| 275 | EXPECT_FALSE( |
[email protected] | 5a43397 | 2008-11-05 15:39:44 | [diff] [blame] | 276 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK)); |
| 277 | EXPECT_FALSE( |
| 278 | controller.IsCommandEnabled(IDS_BOOMARK_BAR_NEW_FOLDER)); |
| 279 | } |
[email protected] | a5bf580 | 2010-02-02 21:24:55 | [diff] [blame] | 280 | |
| 281 | TEST_F(BookmarkContextMenuTest, CutCopyPasteNode) { |
| 282 | std::vector<const BookmarkNode*> nodes; |
| 283 | nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); |
[email protected] | 1df533b | 2010-02-02 22:50:07 | [diff] [blame] | 284 | scoped_ptr<BookmarkContextMenu> controller(new BookmarkContextMenu( |
[email protected] | 0568e6ca | 2010-05-06 21:06:48 | [diff] [blame] | 285 | NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes)); |
[email protected] | a5bf580 | 2010-02-02 21:24:55 | [diff] [blame] | 286 | EXPECT_TRUE(controller->IsCommandEnabled(IDS_COPY)); |
| 287 | EXPECT_TRUE(controller->IsCommandEnabled(IDS_CUT)); |
| 288 | |
| 289 | // Copy the URL. |
| 290 | controller->ExecuteCommand(IDS_COPY); |
| 291 | |
[email protected] | 1df533b | 2010-02-02 22:50:07 | [diff] [blame] | 292 | controller.reset(new BookmarkContextMenu( |
[email protected] | 0568e6ca | 2010-05-06 21:06:48 | [diff] [blame] | 293 | NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes)); |
[email protected] | a5bf580 | 2010-02-02 21:24:55 | [diff] [blame] | 294 | int old_count = model_->GetBookmarkBarNode()->GetChildCount(); |
| 295 | controller->ExecuteCommand(IDS_PASTE); |
| 296 | |
| 297 | ASSERT_TRUE(model_->GetBookmarkBarNode()->GetChild(1)->is_url()); |
| 298 | ASSERT_EQ(old_count + 1, model_->GetBookmarkBarNode()->GetChildCount()); |
| 299 | ASSERT_EQ(model_->GetBookmarkBarNode()->GetChild(0)->GetURL(), |
| 300 | model_->GetBookmarkBarNode()->GetChild(1)->GetURL()); |
| 301 | |
[email protected] | 1df533b | 2010-02-02 22:50:07 | [diff] [blame] | 302 | controller.reset(new BookmarkContextMenu( |
[email protected] | 0568e6ca | 2010-05-06 21:06:48 | [diff] [blame] | 303 | NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes)); |
[email protected] | a5bf580 | 2010-02-02 21:24:55 | [diff] [blame] | 304 | // Cut the URL. |
| 305 | controller->ExecuteCommand(IDS_CUT); |
| 306 | ASSERT_TRUE(model_->GetBookmarkBarNode()->GetChild(0)->is_url()); |
| 307 | ASSERT_TRUE(model_->GetBookmarkBarNode()->GetChild(1)->is_folder()); |
| 308 | ASSERT_EQ(old_count, model_->GetBookmarkBarNode()->GetChildCount()); |
[email protected] | a5bf580 | 2010-02-02 21:24:55 | [diff] [blame] | 309 | } |
| 310 | |