OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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_TEST_LIVE_SYNC_BOOKMARKS_HELPER_H_ |
| 6 #define CHROME_TEST_LIVE_SYNC_BOOKMARKS_HELPER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <set> |
| 10 #include <string> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/compiler_specific.h" |
| 14 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 15 #include "chrome/test/live_sync/sync_datatype_helper.h" |
| 16 #include "googleurl/src/gurl.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 19 |
| 20 class GURL; |
| 21 class Profile; |
| 22 |
| 23 class BookmarksHelper : public SyncDatatypeHelper { |
| 24 public: |
| 25 // Used to access the bookmark model within a particular sync profile. |
| 26 static BookmarkModel* GetBookmarkModel(int index) WARN_UNUSED_RESULT; |
| 27 |
| 28 // Used to access the bookmark bar within a particular sync profile. |
| 29 static const BookmarkNode* GetBookmarkBarNode(int index) WARN_UNUSED_RESULT; |
| 30 |
| 31 // Used to access the "other bookmarks" node within a particular sync profile. |
| 32 static const BookmarkNode* GetOtherNode(int index) WARN_UNUSED_RESULT; |
| 33 |
| 34 // Used to access the bookmarks within the verifier sync profile. |
| 35 static BookmarkModel* GetVerifierBookmarkModel() WARN_UNUSED_RESULT; |
| 36 |
| 37 // Encrypt Bookmarks datatype. |
| 38 static bool EnableEncryption(int index); |
| 39 |
| 40 // Check if Bookmarks are encrypted. |
| 41 static bool IsEncrypted(int index); |
| 42 |
| 43 // Adds a URL with address |url| and title |title| to the bookmark bar of |
| 44 // profile |profile|. Returns a pointer to the node that was added. |
| 45 static const BookmarkNode* AddURL( |
| 46 int profile, |
| 47 const std::wstring& title, |
| 48 const GURL& url) WARN_UNUSED_RESULT; |
| 49 |
| 50 // Adds a URL with address |url| and title |title| to the bookmark bar of |
| 51 // profile |profile| at position |index|. Returns a pointer to the node that |
| 52 // was added. |
| 53 static const BookmarkNode* AddURL( |
| 54 int profile, |
| 55 int index, |
| 56 const std::wstring& title, |
| 57 const GURL& url) WARN_UNUSED_RESULT; |
| 58 |
| 59 // Adds a URL with address |url| and title |title| under the node |parent| of |
| 60 // profile |profile| at position |index|. Returns a pointer to the node that |
| 61 // was added. |
| 62 static const BookmarkNode* AddURL( |
| 63 int profile, |
| 64 const BookmarkNode* parent, |
| 65 int index, |
| 66 const std::wstring& title, |
| 67 const GURL& url) WARN_UNUSED_RESULT; |
| 68 |
| 69 // Adds a folder named |title| to the bookmark bar of profile |profile|. |
| 70 // Returns a pointer to the folder that was added. |
| 71 static const BookmarkNode* AddFolder( |
| 72 int profile, |
| 73 const std::wstring& title) WARN_UNUSED_RESULT; |
| 74 |
| 75 // Adds a folder named |title| to the bookmark bar of profile |profile| at |
| 76 // position |index|. Returns a pointer to the folder that was added. |
| 77 static const BookmarkNode* AddFolder( |
| 78 int profile, |
| 79 int index, |
| 80 const std::wstring& title) WARN_UNUSED_RESULT; |
| 81 |
| 82 // Adds a folder named |title| to the node |parent| in the bookmark model of |
| 83 // profile |profile| at position |index|. Returns a pointer to the node that |
| 84 // was added. |
| 85 static const BookmarkNode* AddFolder( |
| 86 int profile, |
| 87 const BookmarkNode* parent, |
| 88 int index, |
| 89 const std::wstring& title) WARN_UNUSED_RESULT; |
| 90 |
| 91 // Changes the title of the node |node| in the bookmark model of profile |
| 92 // |profile| to |new_title|. |
| 93 static void SetTitle(int profile, |
| 94 const BookmarkNode* node, |
| 95 const std::wstring& new_title); |
| 96 |
| 97 // Sets the favicon of the node |node| (of type BookmarkNode::URL) in the |
| 98 // bookmark model of profile |profile| using the data in |icon_bytes_vector|. |
| 99 static void SetFavicon( |
| 100 int profile, |
| 101 const BookmarkNode* node, |
| 102 const std::vector<unsigned char>& icon_bytes_vector); |
| 103 |
| 104 // Changes the url of the node |node| in the bookmark model of profile |
| 105 // |profile| to |new_url|. Returns a pointer to the node with the changed url. |
| 106 static const BookmarkNode* SetURL( |
| 107 int profile, |
| 108 const BookmarkNode* node, |
| 109 const GURL& new_url) WARN_UNUSED_RESULT; |
| 110 |
| 111 // Moves the node |node| in the bookmark model of profile |profile| so it ends |
| 112 // up under the node |new_parent| at position |index|. |
| 113 static void Move( |
| 114 int profile, |
| 115 const BookmarkNode* node, |
| 116 const BookmarkNode* new_parent, |
| 117 int index); |
| 118 |
| 119 // Removes the node in the bookmark model of profile |profile| under the node |
| 120 // |parent| at position |index|. |
| 121 static void Remove(int profile, const BookmarkNode* parent, int index); |
| 122 |
| 123 // Sorts the children of the node |parent| in the bookmark model of profile |
| 124 // |profile|. |
| 125 static void SortChildren(int profile, const BookmarkNode* parent); |
| 126 |
| 127 // Reverses the order of the children of the node |parent| in the bookmark |
| 128 // model of profile |profile|. |
| 129 static void ReverseChildOrder(int profile, const BookmarkNode* parent); |
| 130 |
| 131 // Checks if the bookmark model of profile |profile| matches the verifier |
| 132 // bookmark model. Returns true if they match. |
| 133 static bool ModelMatchesVerifier(int profile) WARN_UNUSED_RESULT; |
| 134 |
| 135 // Checks if the bookmark models of all sync profiles match the verifier |
| 136 // bookmark model. Returns true if they match. |
| 137 static bool AllModelsMatchVerifier() WARN_UNUSED_RESULT; |
| 138 |
| 139 // Checks if the bookmark models of |profile_a| and |profile_b| match each |
| 140 // other. Returns true if they match. |
| 141 static bool ModelsMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT; |
| 142 |
| 143 // Checks if the bookmark models of all sync profiles match each other. Does |
| 144 // not compare them with the verifier bookmark model. Returns true if they |
| 145 // match. |
| 146 static bool AllModelsMatch() WARN_UNUSED_RESULT; |
| 147 |
| 148 // Checks if the bookmark model of profile |profile| contains any instances of |
| 149 // two bookmarks with the same URL under the same parent folder. Returns true |
| 150 // if even one instance is found. |
| 151 static bool ContainsDuplicateBookmarks(int profile); |
| 152 |
| 153 // Gets the node in the bookmark model of profile |profile| that has the url |
| 154 // |url|. Note: Only one instance of |url| is assumed to be present. |
| 155 static const BookmarkNode* GetUniqueNodeByURL( |
| 156 int profile, |
| 157 const GURL& url) WARN_UNUSED_RESULT; |
| 158 |
| 159 // Returns the number of bookmarks in bookmark model of profile |profile| |
| 160 // whose titles match the string |title|. |
| 161 static int CountBookmarksWithTitlesMatching( |
| 162 int profile, |
| 163 const std::wstring& title) WARN_UNUSED_RESULT; |
| 164 |
| 165 // Returns the number of bookmark folders in the bookmark model of profile |
| 166 // |profile| whose titles contain the query string |title|. |
| 167 static int CountFoldersWithTitlesMatching( |
| 168 int profile, |
| 169 const std::wstring& title) WARN_UNUSED_RESULT; |
| 170 |
| 171 // Creates a unique favicon using |seed|. |
| 172 static std::vector<unsigned char> CreateFavicon(int seed); |
| 173 |
| 174 // Returns a URL identifiable by |i|. |
| 175 static std::string IndexedURL(int i); |
| 176 |
| 177 // Returns a URL title identifiable by |i|. |
| 178 static std::wstring IndexedURLTitle(int i); |
| 179 |
| 180 // Returns a folder name identifiable by |i|. |
| 181 static std::wstring IndexedFolderName(int i); |
| 182 |
| 183 // Returns a subfolder name identifiable by |i|. |
| 184 static std::wstring IndexedSubfolderName(int i); |
| 185 |
| 186 // Returns a subsubfolder name identifiable by |i|. |
| 187 static std::wstring IndexedSubsubfolderName(int i); |
| 188 |
| 189 protected: |
| 190 BookmarksHelper(); |
| 191 virtual ~BookmarksHelper(); |
| 192 |
| 193 private: |
| 194 // Finds the node in the verifier bookmark model that corresponds to |
| 195 // |foreign_node| in |foreign_model| and stores its address in |result|. |
| 196 static void FindNodeInVerifier(BookmarkModel* foreign_model, |
| 197 const BookmarkNode* foreign_node, |
| 198 const BookmarkNode** result); |
| 199 |
| 200 // Returns the number of nodes of node type |node_type| in |model| whose |
| 201 // titles match the string |title|. |
| 202 static int CountNodesWithTitlesMatching(BookmarkModel* model, |
| 203 BookmarkNode::Type node_type, |
| 204 const string16& title); |
| 205 |
| 206 // Checks if the hierarchies in |model_a| and |model_b| are equivalent in |
| 207 // terms of the data model and favicon. Returns true if they both match. |
| 208 // Note: Some peripheral fields like creation times are allowed to mismatch. |
| 209 static bool BookmarkModelsMatch(BookmarkModel* model_a, |
| 210 BookmarkModel* model_b) WARN_UNUSED_RESULT; |
| 211 |
| 212 // Does a deep comparison of BookmarkNode fields in |model_a| and |model_b|. |
| 213 // Returns true if they are all equal. |
| 214 static bool NodesMatch(const BookmarkNode* model_a, |
| 215 const BookmarkNode* model_b); |
| 216 |
| 217 // Checks if the favicon in |node_a| from |model_a| matches that of |node_b| |
| 218 // from |model_b|. Returns true if they match. |
| 219 static bool FaviconsMatch(BookmarkModel* model_a, |
| 220 BookmarkModel* model_b, |
| 221 const BookmarkNode* node_a, |
| 222 const BookmarkNode* node_b); |
| 223 |
| 224 // Checks if the favicon data in |bitmap_a| and |bitmap_b| are equivalent. |
| 225 // Returns true if they match. |
| 226 static bool FaviconBitmapsMatch(const SkBitmap& bitmap_a, |
| 227 const SkBitmap& bitmap_b); |
| 228 |
| 229 // Gets the favicon associated with |node| in |model|. |
| 230 static const SkBitmap& GetFavicon(BookmarkModel* model, |
| 231 const BookmarkNode* node); |
| 232 |
| 233 // A collection of URLs for which we have added favicons. Since loading a |
| 234 // favicon is an asynchronous operation and doesn't necessarily invoke a |
| 235 // callback, this collection is used to determine if we must wait for a URL's |
| 236 // favicon to load or not. |
| 237 static std::set<GURL>* urls_with_favicons_; |
| 238 |
| 239 DISALLOW_COPY_AND_ASSIGN(BookmarksHelper); |
| 240 }; |
| 241 |
| 242 #endif // CHROME_TEST_LIVE_SYNC_BOOKMARKS_HELPER_H_ |
OLD | NEW |