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/sync/test/integration/bookmarks_helper.h" | 5 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
17 #include "base/task/cancelable_task_tracker.h" | 17 #include "base/task/cancelable_task_tracker.h" |
18 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 18 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
19 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | 19 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" |
20 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" | 20 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" |
| 21 #include "chrome/browser/chrome_notification_types.h" |
21 #include "chrome/browser/favicon/favicon_service.h" | 22 #include "chrome/browser/favicon/favicon_service.h" |
22 #include "chrome/browser/favicon/favicon_service_factory.h" | 23 #include "chrome/browser/favicon/favicon_service_factory.h" |
23 #include "chrome/browser/history/history_db_task.h" | 24 #include "chrome/browser/history/history_db_task.h" |
24 #include "chrome/browser/history/history_service.h" | 25 #include "chrome/browser/history/history_service.h" |
25 #include "chrome/browser/history/history_service_factory.h" | 26 #include "chrome/browser/history/history_service_factory.h" |
26 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/sync/glue/bookmark_change_processor.h" | 28 #include "chrome/browser/sync/glue/bookmark_change_processor.h" |
28 #include "chrome/browser/sync/test/integration/multi_client_status_change_checke
r.h" | 29 #include "chrome/browser/sync/test/integration/multi_client_status_change_checke
r.h" |
29 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 30 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
30 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 31 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
31 #include "chrome/browser/sync/test/integration/sync_test.h" | 32 #include "chrome/browser/sync/test/integration/sync_test.h" |
32 #include "chrome/common/chrome_paths.h" | 33 #include "chrome/common/chrome_paths.h" |
33 #include "components/bookmarks/browser/bookmark_client.h" | 34 #include "components/bookmarks/browser/bookmark_client.h" |
34 #include "components/bookmarks/browser/bookmark_model.h" | 35 #include "components/bookmarks/browser/bookmark_model.h" |
35 #include "components/bookmarks/browser/bookmark_model_observer.h" | 36 #include "components/bookmarks/browser/bookmark_model_observer.h" |
36 #include "components/bookmarks/browser/bookmark_utils.h" | 37 #include "components/bookmarks/browser/bookmark_utils.h" |
37 #include "components/favicon_base/favicon_util.h" | 38 #include "components/favicon_base/favicon_util.h" |
38 #include "components/history/core/browser/history_types.h" | 39 #include "components/history/core/browser/history_types.h" |
| 40 #include "content/public/browser/notification_service.h" |
39 #include "content/public/test/test_utils.h" | 41 #include "content/public/test/test_utils.h" |
40 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
41 #include "third_party/skia/include/core/SkBitmap.h" | 43 #include "third_party/skia/include/core/SkBitmap.h" |
42 #include "ui/base/models/tree_node_iterator.h" | 44 #include "ui/base/models/tree_node_iterator.h" |
43 #include "ui/gfx/image/image_skia.h" | 45 #include "ui/gfx/image/image_skia.h" |
44 | 46 |
45 namespace { | 47 namespace { |
46 | 48 |
47 // History task which runs all pending tasks on the history thread and | 49 // History task which runs all pending tasks on the history thread and |
48 // signals when the tasks have completed. | 50 // signals when the tasks have completed. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // |node_type| whose titles match |title|. | 145 // |node_type| whose titles match |title|. |
144 int count = 0; | 146 int count = 0; |
145 while (iterator.has_next()) { | 147 while (iterator.has_next()) { |
146 const BookmarkNode* node = iterator.Next(); | 148 const BookmarkNode* node = iterator.Next(); |
147 if ((node->type() == node_type) && (node->GetTitle() == title)) | 149 if ((node->type() == node_type) && (node->GetTitle() == title)) |
148 ++count; | 150 ++count; |
149 } | 151 } |
150 return count; | 152 return count; |
151 } | 153 } |
152 | 154 |
| 155 // Returns the number of nodes of node type |node_type| in |model|. |
| 156 int CountNodes(BookmarkModel* model, BookmarkNode::Type node_type) { |
| 157 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node()); |
| 158 // Walk through the model tree looking for bookmark nodes of node type |
| 159 // |node_type|. |
| 160 int count = 0; |
| 161 while (iterator.has_next()) { |
| 162 const BookmarkNode* node = iterator.Next(); |
| 163 if (node->type() == node_type) |
| 164 ++count; |
| 165 } |
| 166 return count; |
| 167 } |
| 168 |
153 // Checks if the favicon data in |bitmap_a| and |bitmap_b| are equivalent. | 169 // Checks if the favicon data in |bitmap_a| and |bitmap_b| are equivalent. |
154 // Returns true if they match. | 170 // Returns true if they match. |
155 bool FaviconRawBitmapsMatch(const SkBitmap& bitmap_a, | 171 bool FaviconRawBitmapsMatch(const SkBitmap& bitmap_a, |
156 const SkBitmap& bitmap_b) { | 172 const SkBitmap& bitmap_b) { |
157 if (bitmap_a.getSize() == 0U && bitmap_b.getSize() == 0U) | 173 if (bitmap_a.getSize() == 0U && bitmap_b.getSize() == 0U) |
158 return true; | 174 return true; |
159 if ((bitmap_a.getSize() != bitmap_b.getSize()) || | 175 if ((bitmap_a.getSize() != bitmap_b.getSize()) || |
160 (bitmap_a.width() != bitmap_b.width()) || | 176 (bitmap_a.width() != bitmap_b.width()) || |
161 (bitmap_a.height() != bitmap_b.height())) { | 177 (bitmap_a.height() != bitmap_b.height())) { |
162 LOG(ERROR) << "Favicon size mismatch: " << bitmap_a.getSize() << " (" | 178 LOG(ERROR) << "Favicon size mismatch: " << bitmap_a.getSize() << " (" |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 << "Node " << parent->GetTitle() << " does not belong to " | 663 << "Node " << parent->GetTitle() << " does not belong to " |
648 << "Profile " << profile; | 664 << "Profile " << profile; |
649 int child_count = parent->child_count(); | 665 int child_count = parent->child_count(); |
650 if (child_count <= 0) | 666 if (child_count <= 0) |
651 return; | 667 return; |
652 for (int index = 0; index < child_count; ++index) { | 668 for (int index = 0; index < child_count; ++index) { |
653 Move(profile, parent->GetChild(index), parent, child_count - index); | 669 Move(profile, parent->GetChild(index), parent, child_count - index); |
654 } | 670 } |
655 } | 671 } |
656 | 672 |
| 673 void NotifyBookmarksSync(int profile) { |
| 674 const syncer::ModelTypeSet types(syncer::BOOKMARKS); |
| 675 content::NotificationService::current()->Notify( |
| 676 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
| 677 content::Source<Profile>( |
| 678 sync_datatype_helper::test()->GetProfile(profile)), |
| 679 content::Details<const syncer::ModelTypeSet>(&types)); |
| 680 } |
| 681 |
| 682 void NotifyBookmarksSyncToAllProfiles() { |
| 683 for (int i = 0; i < sync_datatype_helper::test()->num_clients(); ++i) { |
| 684 NotifyBookmarksSync(i); |
| 685 } |
| 686 } |
| 687 |
657 bool ModelMatchesVerifier(int profile) { | 688 bool ModelMatchesVerifier(int profile) { |
658 if (!sync_datatype_helper::test()->use_verifier()) { | 689 if (!sync_datatype_helper::test()->use_verifier()) { |
659 LOG(ERROR) << "Illegal to call ModelMatchesVerifier() after " | 690 LOG(ERROR) << "Illegal to call ModelMatchesVerifier() after " |
660 << "DisableVerifier(). Use ModelsMatch() instead."; | 691 << "DisableVerifier(). Use ModelsMatch() instead."; |
661 return false; | 692 return false; |
662 } | 693 } |
663 return BookmarkModelsMatch(GetVerifierBookmarkModel(), | 694 return BookmarkModelsMatch(GetVerifierBookmarkModel(), |
664 GetBookmarkModel(profile)); | 695 GetBookmarkModel(profile)); |
665 } | 696 } |
666 | 697 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 | 795 |
765 const BookmarkNode* GetUniqueNodeByURL(int profile, const GURL& url) { | 796 const BookmarkNode* GetUniqueNodeByURL(int profile, const GURL& url) { |
766 std::vector<const BookmarkNode*> nodes; | 797 std::vector<const BookmarkNode*> nodes; |
767 GetBookmarkModel(profile)->GetNodesByURL(url, &nodes); | 798 GetBookmarkModel(profile)->GetNodesByURL(url, &nodes); |
768 EXPECT_EQ(1U, nodes.size()); | 799 EXPECT_EQ(1U, nodes.size()); |
769 if (nodes.empty()) | 800 if (nodes.empty()) |
770 return NULL; | 801 return NULL; |
771 return nodes[0]; | 802 return nodes[0]; |
772 } | 803 } |
773 | 804 |
| 805 int CountAllBookmarks(int profile) { |
| 806 return CountNodes(GetBookmarkModel(profile), BookmarkNode::URL); |
| 807 } |
| 808 |
774 int CountBookmarksWithTitlesMatching(int profile, const std::string& title) { | 809 int CountBookmarksWithTitlesMatching(int profile, const std::string& title) { |
775 return CountNodesWithTitlesMatching(GetBookmarkModel(profile), | 810 return CountNodesWithTitlesMatching(GetBookmarkModel(profile), |
776 BookmarkNode::URL, | 811 BookmarkNode::URL, |
777 base::UTF8ToUTF16(title)); | 812 base::UTF8ToUTF16(title)); |
778 } | 813 } |
779 | 814 |
780 int CountFoldersWithTitlesMatching(int profile, const std::string& title) { | 815 int CountFoldersWithTitlesMatching(int profile, const std::string& title) { |
781 return CountNodesWithTitlesMatching(GetBookmarkModel(profile), | 816 return CountNodesWithTitlesMatching(GetBookmarkModel(profile), |
782 BookmarkNode::FOLDER, | 817 BookmarkNode::FOLDER, |
783 base::UTF8ToUTF16(title)); | 818 base::UTF8ToUTF16(title)); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 | 865 |
831 std::string IndexedSubfolderName(int i) { | 866 std::string IndexedSubfolderName(int i) { |
832 return base::StringPrintf("Subfolder Name %d", i); | 867 return base::StringPrintf("Subfolder Name %d", i); |
833 } | 868 } |
834 | 869 |
835 std::string IndexedSubsubfolderName(int i) { | 870 std::string IndexedSubsubfolderName(int i) { |
836 return base::StringPrintf("Subsubfolder Name %d", i); | 871 return base::StringPrintf("Subsubfolder Name %d", i); |
837 } | 872 } |
838 | 873 |
839 } // namespace bookmarks_helper | 874 } // namespace bookmarks_helper |
OLD | NEW |