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.
5 #ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_BOOKMARKS_HELPER_H_
6 #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_BOOKMARKS_HELPER_H_
12 #include "base/compiler_specific.h"
13 #include "chrome/browser/bookmarks/bookmark_model.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/skia/include/core/SkBitmap.h"
20 namespace bookmarks_helper
{
22 // Used to access the bookmark model within a particular sync profile.
23 BookmarkModel
* GetBookmarkModel(int index
) WARN_UNUSED_RESULT
;
25 // Used to access the bookmark bar within a particular sync profile.
26 const BookmarkNode
* GetBookmarkBarNode(int index
) WARN_UNUSED_RESULT
;
28 // Used to access the "other bookmarks" node within a particular sync profile.
29 const BookmarkNode
* GetOtherNode(int index
) WARN_UNUSED_RESULT
;
31 // Used to access the "Synced Bookmarks" node within a particular sync profile.
32 const BookmarkNode
* GetSyncedBookmarksNode(int index
) WARN_UNUSED_RESULT
;
34 // Used to access the bookmarks within the verifier sync profile.
35 BookmarkModel
* GetVerifierBookmarkModel() WARN_UNUSED_RESULT
;
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.
39 const BookmarkNode
* AddURL(
41 const std::wstring
& title
,
42 const GURL
& url
) WARN_UNUSED_RESULT
;
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
47 const BookmarkNode
* AddURL(
50 const std::wstring
& title
,
51 const GURL
& url
) WARN_UNUSED_RESULT
;
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
56 const BookmarkNode
* AddURL(
58 const BookmarkNode
* parent
,
60 const std::wstring
& title
,
61 const GURL
& url
) WARN_UNUSED_RESULT
;
63 // Adds a folder named |title| to the bookmark bar of profile |profile|.
64 // Returns a pointer to the folder that was added.
65 const BookmarkNode
* AddFolder(
67 const std::wstring
& title
) WARN_UNUSED_RESULT
;
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.
71 const BookmarkNode
* AddFolder(
74 const std::wstring
& title
) WARN_UNUSED_RESULT
;
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
79 const BookmarkNode
* AddFolder(
81 const BookmarkNode
* parent
,
83 const std::wstring
& title
) WARN_UNUSED_RESULT
;
85 // Changes the title of the node |node| in the bookmark model of profile
86 // |profile| to |new_title|.
87 void SetTitle(int profile
,
88 const BookmarkNode
* node
,
89 const std::wstring
& new_title
);
91 // The source of the favicon.
97 // Sets the |icon_url| and |image| data for the favicon for |node| in the
98 // bookmark model for |profile|.
99 void SetFavicon(int profile
,
100 const BookmarkNode
* node
,
101 const GURL
& icon_url
,
102 const gfx::Image
& image
,
103 FaviconSource source
);
105 // Changes the url of the node |node| in the bookmark model of profile
106 // |profile| to |new_url|. Returns a pointer to the node with the changed url.
107 const BookmarkNode
* SetURL(
109 const BookmarkNode
* node
,
110 const GURL
& new_url
) WARN_UNUSED_RESULT
;
112 // Moves the node |node| in the bookmark model of profile |profile| so it ends
113 // up under the node |new_parent| at position |index|.
116 const BookmarkNode
* node
,
117 const BookmarkNode
* new_parent
,
120 // Removes the node in the bookmark model of profile |profile| under the node
121 // |parent| at position |index|.
122 void Remove(int profile
, const BookmarkNode
* parent
, int index
);
124 // Removes all non-permanent nodes in the bookmark model of profile |profile|.
125 void RemoveAll(int profile
);
127 // Sorts the children of the node |parent| in the bookmark model of profile
129 void SortChildren(int profile
, const BookmarkNode
* parent
);
131 // Reverses the order of the children of the node |parent| in the bookmark
132 // model of profile |profile|.
133 void ReverseChildOrder(int profile
, const BookmarkNode
* parent
);
135 // Checks if the bookmark model of profile |profile| matches the verifier
136 // bookmark model. Returns true if they match.
137 bool ModelMatchesVerifier(int profile
) WARN_UNUSED_RESULT
;
139 // Checks if the bookmark models of all sync profiles match the verifier
140 // bookmark model. Returns true if they match.
141 bool AllModelsMatchVerifier() WARN_UNUSED_RESULT
;
143 // Checks if the bookmark models of |profile_a| and |profile_b| match each
144 // other. Returns true if they match.
145 bool ModelsMatch(int profile_a
, int profile_b
) WARN_UNUSED_RESULT
;
147 // Checks if the bookmark models of all sync profiles match each other. Does
148 // not compare them with the verifier bookmark model. Returns true if they
150 bool AllModelsMatch() WARN_UNUSED_RESULT
;
152 // Checks if the bookmark model of profile |profile| contains any instances of
153 // two bookmarks with the same URL under the same parent folder. Returns true
154 // if even one instance is found.
155 bool ContainsDuplicateBookmarks(int profile
);
157 // Returns whether a node exists with the specified url.
158 bool HasNodeWithURL(int profile
, const GURL
& url
);
160 // Gets the node in the bookmark model of profile |profile| that has the url
161 // |url|. Note: Only one instance of |url| is assumed to be present.
162 const BookmarkNode
* GetUniqueNodeByURL(
164 const GURL
& url
) WARN_UNUSED_RESULT
;
166 // Returns the number of bookmarks in bookmark model of profile |profile|
167 // whose titles match the string |title|.
168 int CountBookmarksWithTitlesMatching(
170 const std::wstring
& title
) WARN_UNUSED_RESULT
;
172 // Returns the number of bookmark folders in the bookmark model of profile
173 // |profile| whose titles contain the query string |title|.
174 int CountFoldersWithTitlesMatching(
176 const std::wstring
& title
) WARN_UNUSED_RESULT
;
178 // Creates a favicon of |color| with image reps of the platform's supported
179 // scale factors (eg MacOS) in addition to 1x.
180 gfx::Image
CreateFavicon(SkColor color
);
182 // Creates a 1x only favicon from the PNG file at |path|.
183 gfx::Image
Create1xFaviconFromPNGFile(const std::string
& path
);
185 // Returns a URL identifiable by |i|.
186 std::string
IndexedURL(int i
);
188 // Returns a URL title identifiable by |i|.
189 std::wstring
IndexedURLTitle(int i
);
191 // Returns a folder name identifiable by |i|.
192 std::wstring
IndexedFolderName(int i
);
194 // Returns a subfolder name identifiable by |i|.
195 std::wstring
IndexedSubfolderName(int i
);
197 // Returns a subsubfolder name identifiable by |i|.
198 std::wstring
IndexedSubsubfolderName(int i
);
200 } // namespace bookmarks_helper
202 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_BOOKMARKS_HELPER_H_