Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(766)

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_context_menu_unittest.cc

Issue 2809003002: Making bookmark folder context menu display the number of bookmarks that will be opened by Open All (Closed)
Patch Set: Fixing compilation issues Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory>
10 #include <string> 10 #include <string>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 using content::PageNavigator; 47 using content::PageNavigator;
48 using content::WebContents; 48 using content::WebContents;
49 49
50 namespace { 50 namespace {
51 51
52 // PageNavigator implementation that records the URL. 52 // PageNavigator implementation that records the URL.
53 class TestingPageNavigator : public PageNavigator { 53 class TestingPageNavigator : public PageNavigator {
54 public: 54 public:
55 WebContents* OpenURL(const OpenURLParams& params) override { 55 WebContents* OpenURL(const OpenURLParams& params) override {
56 urls_.push_back(params.url); 56 urls_.push_back(params.url);
57 return NULL; 57 return nullptr;
58 } 58 }
59 59
60 std::vector<GURL> urls_; 60 std::vector<GURL> urls_;
61 }; 61 };
62 62
63 } // namespace 63 } // namespace
64 64
65 class BookmarkContextMenuTest : public testing::Test { 65 class BookmarkContextMenuTest : public testing::Test {
66 public: 66 public:
67 BookmarkContextMenuTest() : model_(nullptr) {} 67 BookmarkContextMenuTest() : model_(nullptr) {}
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 model_->AddFolder(bb_node, 3, ASCIIToUTF16("F3")); 113 model_->AddFolder(bb_node, 3, ASCIIToUTF16("F3"));
114 const BookmarkNode* f4 = model_->AddFolder(bb_node, 4, ASCIIToUTF16("F4")); 114 const BookmarkNode* f4 = model_->AddFolder(bb_node, 4, ASCIIToUTF16("F4"));
115 model_->AddURL(f4, 0, ASCIIToUTF16("f4a"), GURL(test_base + "f4a")); 115 model_->AddURL(f4, 0, ASCIIToUTF16("f4a"), GURL(test_base + "f4a"));
116 } 116 }
117 }; 117 };
118 118
119 // Tests Deleting from the menu. 119 // Tests Deleting from the menu.
120 TEST_F(BookmarkContextMenuTest, DeleteURL) { 120 TEST_F(BookmarkContextMenuTest, DeleteURL) {
121 std::vector<const BookmarkNode*> nodes; 121 std::vector<const BookmarkNode*> nodes;
122 nodes.push_back(model_->bookmark_bar_node()->GetChild(0)); 122 nodes.push_back(model_->bookmark_bar_node()->GetChild(0));
123 BookmarkContextMenu controller( 123 BookmarkContextMenu controller(nullptr, nullptr, profile_.get(), nullptr,
124 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false); 124 nodes[0]->parent(), nodes, false);
125 GURL url = model_->bookmark_bar_node()->GetChild(0)->url(); 125 GURL url = model_->bookmark_bar_node()->GetChild(0)->url();
126 ASSERT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE)); 126 ASSERT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE));
127 // Delete the URL. 127 // Delete the URL.
128 controller.ExecuteCommand(IDC_BOOKMARK_BAR_REMOVE, 0); 128 controller.ExecuteCommand(IDC_BOOKMARK_BAR_REMOVE, 0);
129 // Model shouldn't have URL anymore. 129 // Model shouldn't have URL anymore.
130 ASSERT_FALSE(model_->IsBookmarked(url)); 130 ASSERT_FALSE(model_->IsBookmarked(url));
131 } 131 }
132 132
133 // Tests open all on a folder with a couple of bookmarks. 133 // Tests open all on a folder with a couple of bookmarks.
134 TEST_F(BookmarkContextMenuTest, OpenAll) { 134 TEST_F(BookmarkContextMenuTest, OpenAll) {
135 const BookmarkNode* folder = model_->bookmark_bar_node()->GetChild(1); 135 const BookmarkNode* folder = model_->bookmark_bar_node()->GetChild(1);
136 chrome::OpenAll(NULL, &navigator_, folder, 136 chrome::OpenAll(nullptr, &navigator_, folder,
137 WindowOpenDisposition::NEW_FOREGROUND_TAB, NULL); 137 WindowOpenDisposition::NEW_FOREGROUND_TAB, nullptr);
138 138
139 // Should have navigated to F1's child but not F11's child. 139 // Should have navigated to F1's child but not F11's child.
140 ASSERT_EQ(static_cast<size_t>(2), navigator_.urls_.size()); 140 ASSERT_EQ(static_cast<size_t>(2), navigator_.urls_.size());
141 ASSERT_TRUE(folder->GetChild(0)->url() == navigator_.urls_[0]); 141 ASSERT_TRUE(folder->GetChild(0)->url() == navigator_.urls_[0]);
142 } 142 }
143 143
144 // Tests open all on a folder with a couple of bookmarks in incognito window. 144 // Tests open all on a folder with a couple of bookmarks in incognito window.
145 TEST_F(BookmarkContextMenuTest, OpenAllIncognito) { 145 TEST_F(BookmarkContextMenuTest, OpenAllIncognito) {
146 const BookmarkNode* folder = model_->bookmark_bar_node()->GetChild(1); 146 const BookmarkNode* folder = model_->bookmark_bar_node()->GetChild(1);
147 chrome::OpenAll(NULL, &navigator_, folder, 147 chrome::OpenAll(nullptr, &navigator_, folder,
148 WindowOpenDisposition::OFF_THE_RECORD, profile_.get()); 148 WindowOpenDisposition::OFF_THE_RECORD, profile_.get());
149 149
150 // Should have navigated to only f1a but not f2a. 150 // Should have navigated to only f1a but not f2a.
151 ASSERT_EQ(static_cast<size_t>(1), navigator_.urls_.size()); 151 ASSERT_EQ(static_cast<size_t>(1), navigator_.urls_.size());
152 ASSERT_TRUE(folder->GetChild(0)->url() == navigator_.urls_[0]); 152 ASSERT_TRUE(folder->GetChild(0)->url() == navigator_.urls_[0]);
153 } 153 }
154 154
155 // Tests counting tabs for 'open all' on a folder with a couple of bookmarks.
156 TEST_F(BookmarkContextMenuTest, OpenCount) {
157 const BookmarkNode* folder = model_->bookmark_bar_node()->GetChild(1);
158
159 // Should count F1's child but not F11's child, as that's what OpenAll would
160 // open.
161 EXPECT_EQ(2, chrome::OpenCount(nullptr, folder));
162 }
163
164 // Same as above, but for counting bookmarks that would be opened in an
165 // incognito window.
166 TEST_F(BookmarkContextMenuTest, OpenCountIncognito) {
167 const BookmarkNode* folder = model_->bookmark_bar_node()->GetChild(1);
168
169 // Should count f1a but not f2a, as that's what OpenAll would open.
170 EXPECT_EQ(1, chrome::OpenCount(nullptr, folder, profile_.get()));
171 }
172
155 // Tests the enabled state of the menus when supplied an empty vector. 173 // Tests the enabled state of the menus when supplied an empty vector.
156 TEST_F(BookmarkContextMenuTest, EmptyNodes) { 174 TEST_F(BookmarkContextMenuTest, EmptyNodes) {
157 BookmarkContextMenu controller( 175 BookmarkContextMenu controller(nullptr, nullptr, profile_.get(), nullptr,
158 NULL, NULL, profile_.get(), NULL, model_->other_node(), 176 model_->other_node(),
159 std::vector<const BookmarkNode*>(), false); 177 std::vector<const BookmarkNode*>(), false);
160 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL)); 178 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL));
161 EXPECT_FALSE( 179 EXPECT_FALSE(
162 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW)); 180 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW));
163 EXPECT_FALSE( 181 EXPECT_FALSE(
164 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO)); 182 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO));
165 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE)); 183 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE));
166 EXPECT_TRUE( 184 EXPECT_TRUE(
167 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK)); 185 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK));
168 EXPECT_TRUE( 186 EXPECT_TRUE(
169 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER)); 187 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER));
170 } 188 }
171 189
172 // Tests the enabled state of the menus when supplied a vector with a single 190 // Tests the enabled state of the menus when supplied a vector with a single
173 // url. 191 // url.
174 TEST_F(BookmarkContextMenuTest, SingleURL) { 192 TEST_F(BookmarkContextMenuTest, SingleURL) {
175 std::vector<const BookmarkNode*> nodes; 193 std::vector<const BookmarkNode*> nodes;
176 nodes.push_back(model_->bookmark_bar_node()->GetChild(0)); 194 nodes.push_back(model_->bookmark_bar_node()->GetChild(0));
177 BookmarkContextMenu controller( 195 BookmarkContextMenu controller(nullptr, nullptr, profile_.get(), nullptr,
178 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false); 196 nodes[0]->parent(), nodes, false);
179 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL)); 197 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL));
180 EXPECT_TRUE( 198 EXPECT_TRUE(
181 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW)); 199 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW));
182 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO)); 200 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO));
183 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE)); 201 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE));
184 EXPECT_TRUE( 202 EXPECT_TRUE(
185 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK)); 203 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK));
186 EXPECT_TRUE( 204 EXPECT_TRUE(
187 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER)); 205 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER));
188 } 206 }
189 207
190 // Tests the enabled state of the menus when supplied a vector with multiple 208 // Tests the enabled state of the menus when supplied a vector with multiple
191 // urls. 209 // urls.
192 TEST_F(BookmarkContextMenuTest, MultipleURLs) { 210 TEST_F(BookmarkContextMenuTest, MultipleURLs) {
193 std::vector<const BookmarkNode*> nodes; 211 std::vector<const BookmarkNode*> nodes;
194 nodes.push_back(model_->bookmark_bar_node()->GetChild(0)); 212 nodes.push_back(model_->bookmark_bar_node()->GetChild(0));
195 nodes.push_back(model_->bookmark_bar_node()->GetChild(1)->GetChild(0)); 213 nodes.push_back(model_->bookmark_bar_node()->GetChild(1)->GetChild(0));
196 BookmarkContextMenu controller( 214 BookmarkContextMenu controller(nullptr, nullptr, profile_.get(), nullptr,
197 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false); 215 nodes[0]->parent(), nodes, false);
198 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL)); 216 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL));
199 EXPECT_TRUE( 217 EXPECT_TRUE(
200 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW)); 218 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW));
201 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO)); 219 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO));
202 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE)); 220 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE));
203 EXPECT_TRUE( 221 EXPECT_TRUE(
204 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK)); 222 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK));
205 EXPECT_TRUE( 223 EXPECT_TRUE(
206 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER)); 224 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER));
207 } 225 }
208 226
209 // Tests the enabled state of the menus when supplied an vector with a single 227 // Tests the enabled state of the menus when supplied an vector with a single
210 // folder. 228 // folder.
211 TEST_F(BookmarkContextMenuTest, SingleFolder) { 229 TEST_F(BookmarkContextMenuTest, SingleFolder) {
212 std::vector<const BookmarkNode*> nodes; 230 std::vector<const BookmarkNode*> nodes;
213 nodes.push_back(model_->bookmark_bar_node()->GetChild(2)); 231 nodes.push_back(model_->bookmark_bar_node()->GetChild(2));
214 BookmarkContextMenu controller( 232 BookmarkContextMenu controller(nullptr, nullptr, profile_.get(), nullptr,
215 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false); 233 nodes[0]->parent(), nodes, false);
216 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL)); 234 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL));
217 EXPECT_FALSE( 235 EXPECT_FALSE(
218 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW)); 236 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW));
219 EXPECT_FALSE( 237 EXPECT_FALSE(
220 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO)); 238 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO));
221 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE)); 239 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE));
222 EXPECT_TRUE( 240 EXPECT_TRUE(
223 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK)); 241 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK));
224 EXPECT_TRUE( 242 EXPECT_TRUE(
225 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER)); 243 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER));
226 } 244 }
227 245
228 // Tests the enabled state of the menus when supplied a vector with multiple 246 // Tests the enabled state of the menus when supplied a vector with multiple
229 // folders, all of which are empty. 247 // folders, all of which are empty.
230 TEST_F(BookmarkContextMenuTest, MultipleEmptyFolders) { 248 TEST_F(BookmarkContextMenuTest, MultipleEmptyFolders) {
231 std::vector<const BookmarkNode*> nodes; 249 std::vector<const BookmarkNode*> nodes;
232 nodes.push_back(model_->bookmark_bar_node()->GetChild(2)); 250 nodes.push_back(model_->bookmark_bar_node()->GetChild(2));
233 nodes.push_back(model_->bookmark_bar_node()->GetChild(3)); 251 nodes.push_back(model_->bookmark_bar_node()->GetChild(3));
234 BookmarkContextMenu controller( 252 BookmarkContextMenu controller(nullptr, nullptr, profile_.get(), nullptr,
235 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false); 253 nodes[0]->parent(), nodes, false);
236 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL)); 254 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL));
237 EXPECT_FALSE( 255 EXPECT_FALSE(
238 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW)); 256 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW));
239 EXPECT_FALSE( 257 EXPECT_FALSE(
240 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO)); 258 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO));
241 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE)); 259 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE));
242 EXPECT_TRUE( 260 EXPECT_TRUE(
243 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK)); 261 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK));
244 EXPECT_TRUE( 262 EXPECT_TRUE(
245 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER)); 263 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER));
246 } 264 }
247 265
248 // Tests the enabled state of the menus when supplied a vector with multiple 266 // Tests the enabled state of the menus when supplied a vector with multiple
249 // folders, some of which contain URLs. 267 // folders, some of which contain URLs.
250 TEST_F(BookmarkContextMenuTest, MultipleFoldersWithURLs) { 268 TEST_F(BookmarkContextMenuTest, MultipleFoldersWithURLs) {
251 std::vector<const BookmarkNode*> nodes; 269 std::vector<const BookmarkNode*> nodes;
252 nodes.push_back(model_->bookmark_bar_node()->GetChild(3)); 270 nodes.push_back(model_->bookmark_bar_node()->GetChild(3));
253 nodes.push_back(model_->bookmark_bar_node()->GetChild(4)); 271 nodes.push_back(model_->bookmark_bar_node()->GetChild(4));
254 BookmarkContextMenu controller( 272 BookmarkContextMenu controller(nullptr, nullptr, profile_.get(), nullptr,
255 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false); 273 nodes[0]->parent(), nodes, false);
256 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL)); 274 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL));
257 EXPECT_TRUE( 275 EXPECT_TRUE(
258 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW)); 276 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW));
259 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO)); 277 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO));
260 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE)); 278 EXPECT_TRUE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE));
261 EXPECT_TRUE( 279 EXPECT_TRUE(
262 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK)); 280 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK));
263 EXPECT_TRUE( 281 EXPECT_TRUE(
264 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER)); 282 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER));
265 } 283 }
266 284
267 // Tests the enabled state of open incognito. 285 // Tests the enabled state of open incognito.
268 TEST_F(BookmarkContextMenuTest, DisableIncognito) { 286 TEST_F(BookmarkContextMenuTest, DisableIncognito) {
269 std::vector<const BookmarkNode*> nodes; 287 std::vector<const BookmarkNode*> nodes;
270 nodes.push_back(model_->bookmark_bar_node()->GetChild(0)); 288 nodes.push_back(model_->bookmark_bar_node()->GetChild(0));
271 Profile* incognito = profile_->GetOffTheRecordProfile(); 289 Profile* incognito = profile_->GetOffTheRecordProfile();
272 BookmarkContextMenu controller( 290 BookmarkContextMenu controller(nullptr, nullptr, incognito, nullptr,
273 NULL, NULL, incognito, NULL, nodes[0]->parent(), nodes, false); 291 nodes[0]->parent(), nodes, false);
274 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_INCOGNITO)); 292 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_INCOGNITO));
275 EXPECT_FALSE( 293 EXPECT_FALSE(
276 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO)); 294 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO));
277 } 295 }
278 296
279 // Tests that you can't remove/edit when showing the other node. 297 // Tests that you can't remove/edit when showing the other node.
280 TEST_F(BookmarkContextMenuTest, DisabledItemsWithOtherNode) { 298 TEST_F(BookmarkContextMenuTest, DisabledItemsWithOtherNode) {
281 std::vector<const BookmarkNode*> nodes; 299 std::vector<const BookmarkNode*> nodes;
282 nodes.push_back(model_->other_node()); 300 nodes.push_back(model_->other_node());
283 BookmarkContextMenu controller( 301 BookmarkContextMenu controller(nullptr, nullptr, profile_.get(), nullptr,
284 NULL, NULL, profile_.get(), NULL, nodes[0], nodes, false); 302 nodes[0], nodes, false);
285 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_EDIT)); 303 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_EDIT));
286 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE)); 304 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE));
287 } 305 }
288 306
289 // Tests the enabled state of the menus when supplied an empty vector and null 307 // Tests the enabled state of the menus when supplied an empty vector and null
290 // parent. 308 // parent.
291 TEST_F(BookmarkContextMenuTest, EmptyNodesNullParent) { 309 TEST_F(BookmarkContextMenuTest, EmptyNodesNullParent) {
292 BookmarkContextMenu controller( 310 BookmarkContextMenu controller(nullptr, nullptr, profile_.get(), nullptr,
293 NULL, NULL, profile_.get(), NULL, NULL, 311 nullptr, std::vector<const BookmarkNode*>(),
294 std::vector<const BookmarkNode*>(), false); 312 false);
295 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL)); 313 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL));
296 EXPECT_FALSE( 314 EXPECT_FALSE(
297 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW)); 315 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW));
298 EXPECT_FALSE( 316 EXPECT_FALSE(
299 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO)); 317 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO));
300 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE)); 318 EXPECT_FALSE(controller.IsCommandEnabled(IDC_BOOKMARK_BAR_REMOVE));
301 EXPECT_FALSE( 319 EXPECT_FALSE(
302 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK)); 320 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_ADD_NEW_BOOKMARK));
303 EXPECT_FALSE( 321 EXPECT_FALSE(
304 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER)); 322 controller.IsCommandEnabled(IDC_BOOKMARK_BAR_NEW_FOLDER));
305 } 323 }
306 324
307 TEST_F(BookmarkContextMenuTest, CutCopyPasteNode) { 325 TEST_F(BookmarkContextMenuTest, CutCopyPasteNode) {
308 const BookmarkNode* bb_node = model_->bookmark_bar_node(); 326 const BookmarkNode* bb_node = model_->bookmark_bar_node();
309 std::vector<const BookmarkNode*> nodes; 327 std::vector<const BookmarkNode*> nodes;
310 nodes.push_back(bb_node->GetChild(0)); 328 nodes.push_back(bb_node->GetChild(0));
311 std::unique_ptr<BookmarkContextMenu> controller(new BookmarkContextMenu( 329 std::unique_ptr<BookmarkContextMenu> controller(
312 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); 330 new BookmarkContextMenu(nullptr, nullptr, profile_.get(), nullptr,
331 nodes[0]->parent(), nodes, false));
313 EXPECT_TRUE(controller->IsCommandEnabled(IDC_COPY)); 332 EXPECT_TRUE(controller->IsCommandEnabled(IDC_COPY));
314 EXPECT_TRUE(controller->IsCommandEnabled(IDC_CUT)); 333 EXPECT_TRUE(controller->IsCommandEnabled(IDC_CUT));
315 334
316 // Copy the URL. 335 // Copy the URL.
317 controller->ExecuteCommand(IDC_COPY, 0); 336 controller->ExecuteCommand(IDC_COPY, 0);
318 337
319 controller.reset(new BookmarkContextMenu( 338 controller.reset(new BookmarkContextMenu(nullptr, nullptr, profile_.get(),
320 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); 339 nullptr, nodes[0]->parent(), nodes,
340 false));
321 int old_count = bb_node->child_count(); 341 int old_count = bb_node->child_count();
322 controller->ExecuteCommand(IDC_PASTE, 0); 342 controller->ExecuteCommand(IDC_PASTE, 0);
323 343
324 ASSERT_TRUE(bb_node->GetChild(1)->is_url()); 344 ASSERT_TRUE(bb_node->GetChild(1)->is_url());
325 ASSERT_EQ(old_count + 1, bb_node->child_count()); 345 ASSERT_EQ(old_count + 1, bb_node->child_count());
326 ASSERT_EQ(bb_node->GetChild(0)->url(), bb_node->GetChild(1)->url()); 346 ASSERT_EQ(bb_node->GetChild(0)->url(), bb_node->GetChild(1)->url());
327 347
328 controller.reset(new BookmarkContextMenu( 348 controller.reset(new BookmarkContextMenu(nullptr, nullptr, profile_.get(),
329 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); 349 nullptr, nodes[0]->parent(), nodes,
350 false));
330 // Cut the URL. 351 // Cut the URL.
331 controller->ExecuteCommand(IDC_CUT, 0); 352 controller->ExecuteCommand(IDC_CUT, 0);
332 ASSERT_TRUE(bb_node->GetChild(0)->is_url()); 353 ASSERT_TRUE(bb_node->GetChild(0)->is_url());
333 ASSERT_TRUE(bb_node->GetChild(1)->is_folder()); 354 ASSERT_TRUE(bb_node->GetChild(1)->is_folder());
334 ASSERT_EQ(old_count, bb_node->child_count()); 355 ASSERT_EQ(old_count, bb_node->child_count());
335 } 356 }
336 357
337 // Tests that the "Show managed bookmarks" option in the context menu is only 358 // Tests that the "Show managed bookmarks" option in the context menu is only
338 // visible if the policy is set. 359 // visible if the policy is set.
339 TEST_F(BookmarkContextMenuTest, ShowManagedBookmarks) { 360 TEST_F(BookmarkContextMenuTest, ShowManagedBookmarks) {
340 // Create a BookmarkContextMenu for the bookmarks bar. 361 // Create a BookmarkContextMenu for the bookmarks bar.
341 const BookmarkNode* bb_node = model_->bookmark_bar_node(); 362 const BookmarkNode* bb_node = model_->bookmark_bar_node();
342 std::vector<const BookmarkNode*> nodes; 363 std::vector<const BookmarkNode*> nodes;
343 nodes.push_back(bb_node->GetChild(0)); 364 nodes.push_back(bb_node->GetChild(0));
344 std::unique_ptr<BookmarkContextMenu> controller(new BookmarkContextMenu( 365 std::unique_ptr<BookmarkContextMenu> controller(
345 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); 366 new BookmarkContextMenu(nullptr, nullptr, profile_.get(), nullptr,
367 nodes[0]->parent(), nodes, false));
346 368
347 // Verify that there are no managed nodes yet. 369 // Verify that there are no managed nodes yet.
348 bookmarks::ManagedBookmarkService* managed = 370 bookmarks::ManagedBookmarkService* managed =
349 ManagedBookmarkServiceFactory::GetForProfile(profile_.get()); 371 ManagedBookmarkServiceFactory::GetForProfile(profile_.get());
350 EXPECT_TRUE(managed->managed_node()->empty()); 372 EXPECT_TRUE(managed->managed_node()->empty());
351 373
352 // The context menu should not show the option to "Show managed bookmarks". 374 // The context menu should not show the option to "Show managed bookmarks".
353 EXPECT_FALSE( 375 EXPECT_FALSE(
354 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)); 376 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS));
355 views::MenuItemView* menu = controller->menu(); 377 views::MenuItemView* menu = controller->menu();
356 EXPECT_FALSE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS) 378 EXPECT_FALSE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)
357 ->visible()); 379 ->visible());
358 380
359 // Other options are not affected. 381 // Other options are not affected.
360 EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER)); 382 EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER));
361 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible()); 383 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible());
362 384
363 // Now set the managed bookmarks policy. 385 // Now set the managed bookmarks policy.
364 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 386 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
365 dict->SetString("name", "Google"); 387 dict->SetString("name", "Google");
366 dict->SetString("url", "http://google.com"); 388 dict->SetString("url", "http://google.com");
367 base::ListValue list; 389 base::ListValue list;
368 list.Append(std::move(dict)); 390 list.Append(std::move(dict));
369 EXPECT_TRUE(managed->managed_node()->empty()); 391 EXPECT_TRUE(managed->managed_node()->empty());
370 profile_->GetPrefs()->Set(bookmarks::prefs::kManagedBookmarks, list); 392 profile_->GetPrefs()->Set(bookmarks::prefs::kManagedBookmarks, list);
371 EXPECT_FALSE(managed->managed_node()->empty()); 393 EXPECT_FALSE(managed->managed_node()->empty());
372 394
373 // New context menus now show the "Show managed bookmarks" option. 395 // New context menus now show the "Show managed bookmarks" option.
374 controller.reset(new BookmarkContextMenu( 396 controller.reset(new BookmarkContextMenu(nullptr, nullptr, profile_.get(),
375 NULL, NULL, profile_.get(), NULL, nodes[0]->parent(), nodes, false)); 397 nullptr, nodes[0]->parent(), nodes,
398 false));
376 EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER)); 399 EXPECT_TRUE(controller->IsCommandVisible(IDC_BOOKMARK_BAR_NEW_FOLDER));
377 EXPECT_TRUE( 400 EXPECT_TRUE(
378 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)); 401 controller->IsCommandVisible(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS));
379 menu = controller->menu(); 402 menu = controller->menu();
380 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible()); 403 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_NEW_FOLDER)->visible());
381 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS) 404 EXPECT_TRUE(menu->GetMenuItemByID(IDC_BOOKMARK_BAR_SHOW_MANAGED_BOOKMARKS)
382 ->visible()); 405 ->visible());
383 } 406 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698