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