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/bookmarks/bookmark_model.h" | 5 #include "chrome/browser/bookmarks/bookmark_model.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 22 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
23 #include "chrome/browser/bookmarks/bookmark_model_observer.h" | 23 #include "chrome/browser/bookmarks/bookmark_model_observer.h" |
24 #include "chrome/browser/bookmarks/bookmark_model_test_utils.h" | |
25 #include "chrome/browser/bookmarks/bookmark_test_helpers.h" | 24 #include "chrome/browser/bookmarks/bookmark_test_helpers.h" |
26 #include "chrome/browser/bookmarks/bookmark_utils.h" | 25 #include "chrome/browser/bookmarks/bookmark_utils.h" |
27 #include "chrome/test/base/testing_profile.h" | 26 #include "chrome/test/base/testing_profile.h" |
28 #include "content/public/test/test_browser_thread_bundle.h" | 27 #include "content/public/test/test_browser_thread_bundle.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
30 #include "ui/base/models/tree_node_iterator.h" | 29 #include "ui/base/models/tree_node_iterator.h" |
31 #include "ui/base/models/tree_node_model.h" | 30 #include "ui/base/models/tree_node_model.h" |
32 #include "url/gurl.h" | 31 #include "url/gurl.h" |
33 | 32 |
34 using base::Time; | 33 using base::Time; |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 // Since |node| is already at the index 0 of |root|, this is no-op. | 587 // Since |node| is already at the index 0 of |root|, this is no-op. |
589 model_.Move(node, root, 0); | 588 model_.Move(node, root, 0); |
590 | 589 |
591 // Check that the modification date is kept untouched. | 590 // Check that the modification date is kept untouched. |
592 EXPECT_EQ(old_date, root->date_folder_modified()); | 591 EXPECT_EQ(old_date, root->date_folder_modified()); |
593 } | 592 } |
594 | 593 |
595 TEST_F(BookmarkModelTest, Copy) { | 594 TEST_F(BookmarkModelTest, Copy) { |
596 const BookmarkNode* root = model_.bookmark_bar_node(); | 595 const BookmarkNode* root = model_.bookmark_bar_node(); |
597 static const std::string model_string("a 1:[ b c ] d 2:[ e f g ] h "); | 596 static const std::string model_string("a 1:[ b c ] d 2:[ e f g ] h "); |
598 BookmarkModelTestUtils::AddNodesFromModelString(&model_, root, model_string); | 597 test::AddNodesFromModelString(&model_, root, model_string); |
599 | 598 |
600 // Validate initial model. | 599 // Validate initial model. |
601 std::string actual_model_string = | 600 std::string actual_model_string = test::ModelStringFromNode(root); |
602 BookmarkModelTestUtils::ModelStringFromNode(root); | |
603 EXPECT_EQ(model_string, actual_model_string); | 601 EXPECT_EQ(model_string, actual_model_string); |
604 | 602 |
605 // Copy 'd' to be after '1:b': URL item from bar to folder. | 603 // Copy 'd' to be after '1:b': URL item from bar to folder. |
606 const BookmarkNode* node_to_copy = root->GetChild(2); | 604 const BookmarkNode* node_to_copy = root->GetChild(2); |
607 const BookmarkNode* destination = root->GetChild(1); | 605 const BookmarkNode* destination = root->GetChild(1); |
608 model_.Copy(node_to_copy, destination, 1); | 606 model_.Copy(node_to_copy, destination, 1); |
609 actual_model_string = BookmarkModelTestUtils::ModelStringFromNode(root); | 607 actual_model_string = test::ModelStringFromNode(root); |
610 EXPECT_EQ("a 1:[ b d c ] d 2:[ e f g ] h ", actual_model_string); | 608 EXPECT_EQ("a 1:[ b d c ] d 2:[ e f g ] h ", actual_model_string); |
611 | 609 |
612 // Copy '1:d' to be after 'a': URL item from folder to bar. | 610 // Copy '1:d' to be after 'a': URL item from folder to bar. |
613 const BookmarkNode* folder = root->GetChild(1); | 611 const BookmarkNode* folder = root->GetChild(1); |
614 node_to_copy = folder->GetChild(1); | 612 node_to_copy = folder->GetChild(1); |
615 model_.Copy(node_to_copy, root, 1); | 613 model_.Copy(node_to_copy, root, 1); |
616 actual_model_string = BookmarkModelTestUtils::ModelStringFromNode(root); | 614 actual_model_string = test::ModelStringFromNode(root); |
617 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e f g ] h ", actual_model_string); | 615 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e f g ] h ", actual_model_string); |
618 | 616 |
619 // Copy '1' to be after '2:e': Folder from bar to folder. | 617 // Copy '1' to be after '2:e': Folder from bar to folder. |
620 node_to_copy = root->GetChild(2); | 618 node_to_copy = root->GetChild(2); |
621 destination = root->GetChild(4); | 619 destination = root->GetChild(4); |
622 model_.Copy(node_to_copy, destination, 1); | 620 model_.Copy(node_to_copy, destination, 1); |
623 actual_model_string = BookmarkModelTestUtils::ModelStringFromNode(root); | 621 actual_model_string = test::ModelStringFromNode(root); |
624 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e 1:[ b d c ] f g ] h ", | 622 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e 1:[ b d c ] f g ] h ", |
625 actual_model_string); | 623 actual_model_string); |
626 | 624 |
627 // Copy '2:1' to be after '2:f': Folder within same folder. | 625 // Copy '2:1' to be after '2:f': Folder within same folder. |
628 folder = root->GetChild(4); | 626 folder = root->GetChild(4); |
629 node_to_copy = folder->GetChild(1); | 627 node_to_copy = folder->GetChild(1); |
630 model_.Copy(node_to_copy, folder, 3); | 628 model_.Copy(node_to_copy, folder, 3); |
631 actual_model_string = BookmarkModelTestUtils::ModelStringFromNode(root); | 629 actual_model_string = test::ModelStringFromNode(root); |
632 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] h ", | 630 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] h ", |
633 actual_model_string); | 631 actual_model_string); |
634 | 632 |
635 // Copy first 'd' to be after 'h': URL item within the bar. | 633 // Copy first 'd' to be after 'h': URL item within the bar. |
636 node_to_copy = root->GetChild(1); | 634 node_to_copy = root->GetChild(1); |
637 model_.Copy(node_to_copy, root, 6); | 635 model_.Copy(node_to_copy, root, 6); |
638 actual_model_string = BookmarkModelTestUtils::ModelStringFromNode(root); | 636 actual_model_string = test::ModelStringFromNode(root); |
639 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] h d ", | 637 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] h d ", |
640 actual_model_string); | 638 actual_model_string); |
641 | 639 |
642 // Copy '2' to be after 'a': Folder within the bar. | 640 // Copy '2' to be after 'a': Folder within the bar. |
643 node_to_copy = root->GetChild(4); | 641 node_to_copy = root->GetChild(4); |
644 model_.Copy(node_to_copy, root, 1); | 642 model_.Copy(node_to_copy, root, 1); |
645 actual_model_string = BookmarkModelTestUtils::ModelStringFromNode(root); | 643 actual_model_string = test::ModelStringFromNode(root); |
646 EXPECT_EQ("a 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] d 1:[ b d c ] " | 644 EXPECT_EQ("a 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] d 1:[ b d c ] " |
647 "d 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] h d ", | 645 "d 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] h d ", |
648 actual_model_string); | 646 actual_model_string); |
649 } | 647 } |
650 | 648 |
651 // Tests that adding a URL to a folder updates the last modified time. | 649 // Tests that adding a URL to a folder updates the last modified time. |
652 TEST_F(BookmarkModelTest, ParentForNewNodes) { | 650 TEST_F(BookmarkModelTest, ParentForNewNodes) { |
653 ASSERT_EQ(model_.bookmark_bar_node(), model_.GetParentForNewNodes()); | 651 ASSERT_EQ(model_.bookmark_bar_node(), model_.GetParentForNewNodes()); |
654 | 652 |
655 const string16 title(ASCIIToUTF16("foo")); | 653 const string16 title(ASCIIToUTF16("foo")); |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 EXPECT_TRUE(node.DeleteMetaInfo("key2.subkey2.leaf")); | 1114 EXPECT_TRUE(node.DeleteMetaInfo("key2.subkey2.leaf")); |
1117 EXPECT_FALSE(node.DeleteMetaInfo("key3")); | 1115 EXPECT_FALSE(node.DeleteMetaInfo("key3")); |
1118 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); | 1116 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); |
1119 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); | 1117 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); |
1120 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); | 1118 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); |
1121 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); | 1119 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); |
1122 EXPECT_TRUE(node.meta_info_str().empty()); | 1120 EXPECT_TRUE(node.meta_info_str().empty()); |
1123 } | 1121 } |
1124 | 1122 |
1125 } // namespace | 1123 } // namespace |
OLD | NEW |