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" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // |node_type| whose titles match |title|. | 147 // |node_type| whose titles match |title|. |
148 int count = 0; | 148 int count = 0; |
149 while (iterator.has_next()) { | 149 while (iterator.has_next()) { |
150 const BookmarkNode* node = iterator.Next(); | 150 const BookmarkNode* node = iterator.Next(); |
151 if ((node->type() == node_type) && (node->GetTitle() == title)) | 151 if ((node->type() == node_type) && (node->GetTitle() == title)) |
152 ++count; | 152 ++count; |
153 } | 153 } |
154 return count; | 154 return count; |
155 } | 155 } |
156 | 156 |
| 157 // Returns the number of nodes of node type |node_type| in |model|. |
| 158 int CountNodes(BookmarkModel* model, BookmarkNode::Type node_type) { |
| 159 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node()); |
| 160 // Walk through the model tree looking for bookmark nodes of node type |
| 161 // |node_type|. |
| 162 int count = 0; |
| 163 while (iterator.has_next()) { |
| 164 const BookmarkNode* node = iterator.Next(); |
| 165 if (node->type() == node_type) |
| 166 ++count; |
| 167 } |
| 168 return count; |
| 169 } |
| 170 |
157 // Checks if the favicon data in |bitmap_a| and |bitmap_b| are equivalent. | 171 // Checks if the favicon data in |bitmap_a| and |bitmap_b| are equivalent. |
158 // Returns true if they match. | 172 // Returns true if they match. |
159 bool FaviconRawBitmapsMatch(const SkBitmap& bitmap_a, | 173 bool FaviconRawBitmapsMatch(const SkBitmap& bitmap_a, |
160 const SkBitmap& bitmap_b) { | 174 const SkBitmap& bitmap_b) { |
161 if (bitmap_a.getSize() == 0U && bitmap_b.getSize() == 0U) | 175 if (bitmap_a.getSize() == 0U && bitmap_b.getSize() == 0U) |
162 return true; | 176 return true; |
163 if ((bitmap_a.getSize() != bitmap_b.getSize()) || | 177 if ((bitmap_a.getSize() != bitmap_b.getSize()) || |
164 (bitmap_a.width() != bitmap_b.width()) || | 178 (bitmap_a.width() != bitmap_b.width()) || |
165 (bitmap_a.height() != bitmap_b.height())) { | 179 (bitmap_a.height() != bitmap_b.height())) { |
166 LOG(ERROR) << "Favicon size mismatch: " << bitmap_a.getSize() << " (" | 180 LOG(ERROR) << "Favicon size mismatch: " << bitmap_a.getSize() << " (" |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 | 781 |
768 const BookmarkNode* GetUniqueNodeByURL(int profile, const GURL& url) { | 782 const BookmarkNode* GetUniqueNodeByURL(int profile, const GURL& url) { |
769 std::vector<const BookmarkNode*> nodes; | 783 std::vector<const BookmarkNode*> nodes; |
770 GetBookmarkModel(profile)->GetNodesByURL(url, &nodes); | 784 GetBookmarkModel(profile)->GetNodesByURL(url, &nodes); |
771 EXPECT_EQ(1U, nodes.size()); | 785 EXPECT_EQ(1U, nodes.size()); |
772 if (nodes.empty()) | 786 if (nodes.empty()) |
773 return NULL; | 787 return NULL; |
774 return nodes[0]; | 788 return nodes[0]; |
775 } | 789 } |
776 | 790 |
| 791 int CountAllBookmarks(int profile) { |
| 792 return CountNodes(GetBookmarkModel(profile), BookmarkNode::URL); |
| 793 } |
| 794 |
777 int CountBookmarksWithTitlesMatching(int profile, const std::string& title) { | 795 int CountBookmarksWithTitlesMatching(int profile, const std::string& title) { |
778 return CountNodesWithTitlesMatching(GetBookmarkModel(profile), | 796 return CountNodesWithTitlesMatching(GetBookmarkModel(profile), |
779 BookmarkNode::URL, | 797 BookmarkNode::URL, |
780 base::UTF8ToUTF16(title)); | 798 base::UTF8ToUTF16(title)); |
781 } | 799 } |
782 | 800 |
783 int CountFoldersWithTitlesMatching(int profile, const std::string& title) { | 801 int CountFoldersWithTitlesMatching(int profile, const std::string& title) { |
784 return CountNodesWithTitlesMatching(GetBookmarkModel(profile), | 802 return CountNodesWithTitlesMatching(GetBookmarkModel(profile), |
785 BookmarkNode::FOLDER, | 803 BookmarkNode::FOLDER, |
786 base::UTF8ToUTF16(title)); | 804 base::UTF8ToUTF16(title)); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 | 851 |
834 std::string IndexedSubfolderName(int i) { | 852 std::string IndexedSubfolderName(int i) { |
835 return base::StringPrintf("Subfolder Name %d", i); | 853 return base::StringPrintf("Subfolder Name %d", i); |
836 } | 854 } |
837 | 855 |
838 std::string IndexedSubsubfolderName(int i) { | 856 std::string IndexedSubsubfolderName(int i) { |
839 return base::StringPrintf("Subsubfolder Name %d", i); | 857 return base::StringPrintf("Subsubfolder Name %d", i); |
840 } | 858 } |
841 | 859 |
842 } // namespace bookmarks_helper | 860 } // namespace bookmarks_helper |
OLD | NEW |