bookmarks_helper.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_BOOKMARKS_HELPER_H_ 6#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_BOOKMARKS_HELPER_H_ 7 8#include <set> 9#include <string> 10#include <vector> 11 12#include "base/compiler_specific.h" 13#include "chrome/browser/bookmarks/bookmark_model.h" 14#include "googleurl/src/gurl.h" 15#include "testing/gtest/include/gtest/gtest.h" 16#include "third_party/skia/include/core/SkBitmap.h" 17 18class GURL; 19 20namespace bookmarks_helper { 21 22// Used to access the bookmark model within a particular sync profile. 23BookmarkModel* GetBookmarkModel(int index) WARN_UNUSED_RESULT; 24 25// Used to access the bookmark bar within a particular sync profile. 26const BookmarkNode* GetBookmarkBarNode(int index) WARN_UNUSED_RESULT; 27 28// Used to access the "other bookmarks" node within a particular sync profile. 29const BookmarkNode* GetOtherNode(int index) WARN_UNUSED_RESULT; 30 31// Used to access the "Synced Bookmarks" node within a particular sync profile. 32const BookmarkNode* GetSyncedBookmarksNode(int index) WARN_UNUSED_RESULT; 33 34// Used to access the bookmarks within the verifier sync profile. 35BookmarkModel* GetVerifierBookmarkModel() WARN_UNUSED_RESULT; 36 37// Adds a URL with address |url| and title |title| to the bookmark bar of 38// profile |profile|. Returns a pointer to the node that was added. 39const BookmarkNode* AddURL( 40 int profile, 41 const std::wstring& title, 42 const GURL& url) WARN_UNUSED_RESULT; 43 44// Adds a URL with address |url| and title |title| to the bookmark bar of 45// profile |profile| at position |index|. Returns a pointer to the node that 46// was added. 47const BookmarkNode* AddURL( 48 int profile, 49 int index, 50 const std::wstring& title, 51 const GURL& url) WARN_UNUSED_RESULT; 52 53// Adds a URL with address |url| and title |title| under the node |parent| of 54// profile |profile| at position |index|. Returns a pointer to the node that 55// was added. 56const BookmarkNode* AddURL( 57 int profile, 58 const BookmarkNode* parent, 59 int index, 60 const std::wstring& title, 61 const GURL& url) WARN_UNUSED_RESULT; 62 63// Adds a folder named |title| to the bookmark bar of profile |profile|. 64// Returns a pointer to the folder that was added. 65const BookmarkNode* AddFolder( 66 int profile, 67 const std::wstring& title) WARN_UNUSED_RESULT; 68 69// Adds a folder named |title| to the bookmark bar of profile |profile| at 70// position |index|. Returns a pointer to the folder that was added. 71const BookmarkNode* AddFolder( 72 int profile, 73 int index, 74 const std::wstring& title) WARN_UNUSED_RESULT; 75 76// Adds a folder named |title| to the node |parent| in the bookmark model of 77// profile |profile| at position |index|. Returns a pointer to the node that 78// was added. 79const BookmarkNode* AddFolder( 80 int profile, 81 const BookmarkNode* parent, 82 int index, 83 const std::wstring& title) WARN_UNUSED_RESULT; 84 85// Changes the title of the node |node| in the bookmark model of profile 86// |profile| to |new_title|. 87void SetTitle(int profile, 88 const BookmarkNode* node, 89 const std::wstring& new_title); 90 91// Sets the favicon of the node |node| (of type BookmarkNode::URL) in the 92// bookmark model of profile |profile| using the data in |icon_bytes_vector|. 93void SetFavicon( 94 int profile, 95 const BookmarkNode* node, 96 const std::vector<unsigned char>& icon_bytes_vector); 97 98// Changes the url of the node |node| in the bookmark model of profile 99// |profile| to |new_url|. Returns a pointer to the node with the changed url. 100const BookmarkNode* SetURL( 101 int profile, 102 const BookmarkNode* node, 103 const GURL& new_url) WARN_UNUSED_RESULT; 104 105// Moves the node |node| in the bookmark model of profile |profile| so it ends 106// up under the node |new_parent| at position |index|. 107void Move( 108 int profile, 109 const BookmarkNode* node, 110 const BookmarkNode* new_parent, 111 int index); 112 113// Removes the node in the bookmark model of profile |profile| under the node 114// |parent| at position |index|. 115void Remove(int profile, const BookmarkNode* parent, int index); 116 117// Sorts the children of the node |parent| in the bookmark model of profile 118// |profile|. 119void SortChildren(int profile, const BookmarkNode* parent); 120 121// Reverses the order of the children of the node |parent| in the bookmark 122// model of profile |profile|. 123void ReverseChildOrder(int profile, const BookmarkNode* parent); 124 125// Checks if the bookmark model of profile |profile| matches the verifier 126// bookmark model. Returns true if they match. 127bool ModelMatchesVerifier(int profile) WARN_UNUSED_RESULT; 128 129// Checks if the bookmark models of all sync profiles match the verifier 130// bookmark model. Returns true if they match. 131bool AllModelsMatchVerifier() WARN_UNUSED_RESULT; 132 133// Checks if the bookmark models of |profile_a| and |profile_b| match each 134// other. Returns true if they match. 135bool ModelsMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT; 136 137// Checks if the bookmark models of all sync profiles match each other. Does 138// not compare them with the verifier bookmark model. Returns true if they 139// match. 140bool AllModelsMatch() WARN_UNUSED_RESULT; 141 142// Checks if the bookmark model of profile |profile| contains any instances of 143// two bookmarks with the same URL under the same parent folder. Returns true 144// if even one instance is found. 145bool ContainsDuplicateBookmarks(int profile); 146 147// Returns whether a node exists with the specified url. 148bool HasNodeWithURL(int profile, const GURL& url); 149 150// Gets the node in the bookmark model of profile |profile| that has the url 151// |url|. Note: Only one instance of |url| is assumed to be present. 152const BookmarkNode* GetUniqueNodeByURL( 153 int profile, 154 const GURL& url) WARN_UNUSED_RESULT; 155 156// Returns the number of bookmarks in bookmark model of profile |profile| 157// whose titles match the string |title|. 158int CountBookmarksWithTitlesMatching( 159 int profile, 160 const std::wstring& title) WARN_UNUSED_RESULT; 161 162// Returns the number of bookmark folders in the bookmark model of profile 163// |profile| whose titles contain the query string |title|. 164int CountFoldersWithTitlesMatching( 165 int profile, 166 const std::wstring& title) WARN_UNUSED_RESULT; 167 168// Creates a unique favicon using |seed|. 169std::vector<unsigned char> CreateFavicon(int seed); 170 171// Returns a URL identifiable by |i|. 172std::string IndexedURL(int i); 173 174// Returns a URL title identifiable by |i|. 175std::wstring IndexedURLTitle(int i); 176 177// Returns a folder name identifiable by |i|. 178std::wstring IndexedFolderName(int i); 179 180// Returns a subfolder name identifiable by |i|. 181std::wstring IndexedSubfolderName(int i); 182 183// Returns a subsubfolder name identifiable by |i|. 184std::wstring IndexedSubsubfolderName(int i); 185 186} // namespace bookmarks_helper 187 188#endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_BOOKMARKS_HELPER_H_ 189