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

Side by Side Diff: components/bookmarks/browser/bookmark_utils_unittest.cc

Issue 302313005: Show the Managed Bookmarks folder in the views UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased on model changes Created 6 years, 6 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 | Annotate | Revision Log
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 "components/bookmarks/browser/bookmark_utils.h" 5 #include "components/bookmarks/browser/bookmark_utils.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 0, 264 0,
265 ASCIIToUTF16("foo bar"), 265 ASCIIToUTF16("foo bar"),
266 GURL("http://www.google.com")); 266 GURL("http://www.google.com"));
267 267
268 // Copy a node to the clipboard. 268 // Copy a node to the clipboard.
269 std::vector<const BookmarkNode*> nodes; 269 std::vector<const BookmarkNode*> nodes;
270 nodes.push_back(node); 270 nodes.push_back(node);
271 CopyToClipboard(model.get(), nodes, false); 271 CopyToClipboard(model.get(), nodes, false);
272 272
273 // And make sure we can paste a bookmark from the clipboard. 273 // And make sure we can paste a bookmark from the clipboard.
274 EXPECT_TRUE(CanPasteFromClipboard(model->bookmark_bar_node())); 274 EXPECT_TRUE(CanPasteFromClipboard(model.get(), model->bookmark_bar_node()));
275 275
276 // Write some text to the clipboard. 276 // Write some text to the clipboard.
277 { 277 {
278 ui::ScopedClipboardWriter clipboard_writer( 278 ui::ScopedClipboardWriter clipboard_writer(
279 ui::Clipboard::GetForCurrentThread(), 279 ui::Clipboard::GetForCurrentThread(),
280 ui::CLIPBOARD_TYPE_COPY_PASTE); 280 ui::CLIPBOARD_TYPE_COPY_PASTE);
281 clipboard_writer.WriteText(ASCIIToUTF16("foo")); 281 clipboard_writer.WriteText(ASCIIToUTF16("foo"));
282 } 282 }
283 283
284 // Now we shouldn't be able to paste from the clipboard. 284 // Now we shouldn't be able to paste from the clipboard.
285 EXPECT_FALSE(CanPasteFromClipboard(model->bookmark_bar_node())); 285 EXPECT_FALSE(CanPasteFromClipboard(model.get(), model->bookmark_bar_node()));
286 } 286 }
287 287
288 TEST_F(BookmarkUtilsTest, CutToClipboard) { 288 TEST_F(BookmarkUtilsTest, CutToClipboard) {
289 test::TestBookmarkClient client; 289 test::TestBookmarkClient client;
290 scoped_ptr<BookmarkModel> model(client.CreateModel(false)); 290 scoped_ptr<BookmarkModel> model(client.CreateModel(false));
291 model->AddObserver(this); 291 model->AddObserver(this);
292 292
293 base::string16 title(ASCIIToUTF16("foo")); 293 base::string16 title(ASCIIToUTF16("foo"));
294 GURL url("http://foo.com"); 294 GURL url("http://foo.com");
295 const BookmarkNode* n1 = model->AddURL(model->other_node(), 0, title, url); 295 const BookmarkNode* n1 = model->AddURL(model->other_node(), 0, title, url);
296 const BookmarkNode* n2 = model->AddURL(model->other_node(), 1, title, url); 296 const BookmarkNode* n2 = model->AddURL(model->other_node(), 1, title, url);
297 297
298 // Cut the nodes to the clipboard. 298 // Cut the nodes to the clipboard.
299 std::vector<const BookmarkNode*> nodes; 299 std::vector<const BookmarkNode*> nodes;
300 nodes.push_back(n1); 300 nodes.push_back(n1);
301 nodes.push_back(n2); 301 nodes.push_back(n2);
302 CopyToClipboard(model.get(), nodes, true); 302 CopyToClipboard(model.get(), nodes, true);
303 303
304 // Make sure the nodes were removed. 304 // Make sure the nodes were removed.
305 EXPECT_EQ(0, model->other_node()->child_count()); 305 EXPECT_EQ(0, model->other_node()->child_count());
306 306
307 // Make sure observers were notified the set of changes should be grouped. 307 // Make sure observers were notified the set of changes should be grouped.
308 ExpectGroupedChangeCount(1, 1); 308 ExpectGroupedChangeCount(1, 1);
309 309
310 // And make sure we can paste from the clipboard. 310 // And make sure we can paste from the clipboard.
311 EXPECT_TRUE(CanPasteFromClipboard(model->other_node())); 311 EXPECT_TRUE(CanPasteFromClipboard(model.get(), model->other_node()));
312 }
313
314 TEST_F(BookmarkUtilsTest, PasteNonEditableNodes) {
315 test::TestBookmarkClient client;
316 // Load a model with an extra node that is not editable.
317 BookmarkPermanentNode* extra_node = new BookmarkPermanentNode(100);
318 bookmarks::BookmarkPermanentNodeList extra_nodes;
319 extra_nodes.push_back(extra_node);
320 client.SetExtraNodesToLoad(extra_nodes.Pass());
321
322 scoped_ptr<BookmarkModel> model(client.CreateModel(false));
323 const BookmarkNode* node = model->AddURL(model->other_node(),
324 0,
325 ASCIIToUTF16("foo bar"),
326 GURL("http://www.google.com"));
327
328 // Copy a node to the clipboard.
329 std::vector<const BookmarkNode*> nodes;
330 nodes.push_back(node);
331 CopyToClipboard(model.get(), nodes, false);
332
333 // And make sure we can paste a bookmark from the clipboard.
334 EXPECT_TRUE(CanPasteFromClipboard(model.get(), model->bookmark_bar_node()));
335
336 // But it can't be pasted into a non-editable folder.
337 BookmarkClient* upcast = &client;
338 EXPECT_FALSE(upcast->CanBeEditedByUser(extra_node));
339 EXPECT_FALSE(CanPasteFromClipboard(model.get(), extra_node));
312 } 340 }
313 #endif // !defined(OS_IOS) 341 #endif // !defined(OS_IOS)
314 342
315 TEST_F(BookmarkUtilsTest, GetParentForNewNodes) { 343 TEST_F(BookmarkUtilsTest, GetParentForNewNodes) {
316 test::TestBookmarkClient client; 344 test::TestBookmarkClient client;
317 scoped_ptr<BookmarkModel> model(client.CreateModel(false)); 345 scoped_ptr<BookmarkModel> model(client.CreateModel(false));
318 // This tests the case where selection contains one item and that item is a 346 // This tests the case where selection contains one item and that item is a
319 // folder. 347 // folder.
320 std::vector<const BookmarkNode*> nodes; 348 std::vector<const BookmarkNode*> nodes;
321 nodes.push_back(model->bookmark_bar_node()); 349 nodes.push_back(model->bookmark_bar_node());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 EXPECT_EQ(2u, clone->GetMetaInfoMap()->size()); 409 EXPECT_EQ(2u, clone->GetMetaInfoMap()->size());
382 std::string value; 410 std::string value;
383 EXPECT_TRUE(clone->GetMetaInfo("somekey", &value)); 411 EXPECT_TRUE(clone->GetMetaInfo("somekey", &value));
384 EXPECT_EQ("somevalue", value); 412 EXPECT_EQ("somevalue", value);
385 EXPECT_TRUE(clone->GetMetaInfo("someotherkey", &value)); 413 EXPECT_TRUE(clone->GetMetaInfo("someotherkey", &value));
386 EXPECT_EQ("someothervalue", value); 414 EXPECT_EQ("someothervalue", value);
387 } 415 }
388 416
389 } // namespace 417 } // namespace
390 } // namespace bookmark_utils 418 } // namespace bookmark_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698