| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "components/bookmarks/browser/base_bookmark_model_observer.h" | 16 #include "components/bookmarks/browser/base_bookmark_model_observer.h" |
| 16 #include "components/bookmarks/browser/bookmark_model.h" | 17 #include "components/bookmarks/browser/bookmark_model.h" |
| 17 #include "components/bookmarks/browser/bookmark_node_data.h" | 18 #include "components/bookmarks/browser/bookmark_node_data.h" |
| 18 #include "components/bookmarks/test/test_bookmark_client.h" | 19 #include "components/bookmarks/test/test_bookmark_client.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "ui/base/clipboard/clipboard.h" | 21 #include "ui/base/clipboard/clipboard.h" |
| 21 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 22 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 // Make sure observers were notified the set of changes should be grouped. | 411 // Make sure observers were notified the set of changes should be grouped. |
| 411 ExpectGroupedChangeCount(1, 1); | 412 ExpectGroupedChangeCount(1, 1); |
| 412 | 413 |
| 413 // And make sure we can paste from the clipboard. | 414 // And make sure we can paste from the clipboard. |
| 414 EXPECT_TRUE(CanPasteFromClipboard(model.get(), model->other_node())); | 415 EXPECT_TRUE(CanPasteFromClipboard(model.get(), model->other_node())); |
| 415 } | 416 } |
| 416 | 417 |
| 417 TEST_F(BookmarkUtilsTest, PasteNonEditableNodes) { | 418 TEST_F(BookmarkUtilsTest, PasteNonEditableNodes) { |
| 418 // Load a model with an extra node that is not editable. | 419 // Load a model with an extra node that is not editable. |
| 419 std::unique_ptr<TestBookmarkClient> client(new TestBookmarkClient()); | 420 std::unique_ptr<TestBookmarkClient> client(new TestBookmarkClient()); |
| 420 BookmarkPermanentNode* extra_node = new BookmarkPermanentNode(100); | |
| 421 BookmarkPermanentNodeList extra_nodes; | 421 BookmarkPermanentNodeList extra_nodes; |
| 422 extra_nodes.push_back(extra_node); | 422 extra_nodes.push_back(base::MakeUnique<BookmarkPermanentNode>(100)); |
| 423 BookmarkPermanentNode* extra_node = extra_nodes.back().get(); |
| 423 client->SetExtraNodesToLoad(std::move(extra_nodes)); | 424 client->SetExtraNodesToLoad(std::move(extra_nodes)); |
| 424 | 425 |
| 425 std::unique_ptr<BookmarkModel> model( | 426 std::unique_ptr<BookmarkModel> model( |
| 426 TestBookmarkClient::CreateModelWithClient(std::move(client))); | 427 TestBookmarkClient::CreateModelWithClient(std::move(client))); |
| 427 const BookmarkNode* node = model->AddURL(model->other_node(), | 428 const BookmarkNode* node = model->AddURL(model->other_node(), |
| 428 0, | 429 0, |
| 429 ASCIIToUTF16("foo bar"), | 430 ASCIIToUTF16("foo bar"), |
| 430 GURL("http://www.google.com")); | 431 GURL("http://www.google.com")); |
| 431 | 432 |
| 432 // Copy a node to the clipboard. | 433 // Copy a node to the clipboard. |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 EXPECT_FALSE(parent->GetChild(0)->GetMetaInfo("foo", &value)); | 562 EXPECT_FALSE(parent->GetChild(0)->GetMetaInfo("foo", &value)); |
| 562 | 563 |
| 563 // Other keys should still be cloned. | 564 // Other keys should still be cloned. |
| 564 EXPECT_TRUE(parent->GetChild(0)->GetMetaInfo("bar", &value)); | 565 EXPECT_TRUE(parent->GetChild(0)->GetMetaInfo("bar", &value)); |
| 565 EXPECT_EQ("kept value", value); | 566 EXPECT_EQ("kept value", value); |
| 566 } | 567 } |
| 567 | 568 |
| 568 TEST_F(BookmarkUtilsTest, RemoveAllBookmarks) { | 569 TEST_F(BookmarkUtilsTest, RemoveAllBookmarks) { |
| 569 // Load a model with an extra node that is not editable. | 570 // Load a model with an extra node that is not editable. |
| 570 std::unique_ptr<TestBookmarkClient> client(new TestBookmarkClient()); | 571 std::unique_ptr<TestBookmarkClient> client(new TestBookmarkClient()); |
| 571 BookmarkPermanentNode* extra_node = new BookmarkPermanentNode(100); | |
| 572 BookmarkPermanentNodeList extra_nodes; | 572 BookmarkPermanentNodeList extra_nodes; |
| 573 extra_nodes.push_back(extra_node); | 573 extra_nodes.push_back(base::MakeUnique<BookmarkPermanentNode>(100)); |
| 574 BookmarkPermanentNode* extra_node = extra_nodes.back().get(); |
| 574 client->SetExtraNodesToLoad(std::move(extra_nodes)); | 575 client->SetExtraNodesToLoad(std::move(extra_nodes)); |
| 575 | 576 |
| 576 std::unique_ptr<BookmarkModel> model( | 577 std::unique_ptr<BookmarkModel> model( |
| 577 TestBookmarkClient::CreateModelWithClient(std::move(client))); | 578 TestBookmarkClient::CreateModelWithClient(std::move(client))); |
| 578 EXPECT_TRUE(model->bookmark_bar_node()->empty()); | 579 EXPECT_TRUE(model->bookmark_bar_node()->empty()); |
| 579 EXPECT_TRUE(model->other_node()->empty()); | 580 EXPECT_TRUE(model->other_node()->empty()); |
| 580 EXPECT_TRUE(model->mobile_node()->empty()); | 581 EXPECT_TRUE(model->mobile_node()->empty()); |
| 581 EXPECT_TRUE(extra_node->empty()); | 582 EXPECT_TRUE(extra_node->empty()); |
| 582 | 583 |
| 583 const base::string16 title = base::ASCIIToUTF16("Title"); | 584 const base::string16 title = base::ASCIIToUTF16("Title"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 597 model->GetNodesByURL(url, &nodes); | 598 model->GetNodesByURL(url, &nodes); |
| 598 ASSERT_EQ(1u, nodes.size()); | 599 ASSERT_EQ(1u, nodes.size()); |
| 599 EXPECT_TRUE(model->bookmark_bar_node()->empty()); | 600 EXPECT_TRUE(model->bookmark_bar_node()->empty()); |
| 600 EXPECT_TRUE(model->other_node()->empty()); | 601 EXPECT_TRUE(model->other_node()->empty()); |
| 601 EXPECT_TRUE(model->mobile_node()->empty()); | 602 EXPECT_TRUE(model->mobile_node()->empty()); |
| 602 EXPECT_EQ(1, extra_node->child_count()); | 603 EXPECT_EQ(1, extra_node->child_count()); |
| 603 } | 604 } |
| 604 | 605 |
| 605 } // namespace | 606 } // namespace |
| 606 } // namespace bookmarks | 607 } // namespace bookmarks |
| OLD | NEW |