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 "components/bookmarks/browser/bookmark_model.h" 14#include "testing/gtest/include/gtest/gtest.h" 15#include "third_party/skia/include/core/SkBitmap.h" 16#include "url/gurl.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 "Managed Bookmarks" node for the given profile. 35const BookmarkNode* GetManagedNode(int index) WARN_UNUSED_RESULT; 36 37// Used to access the bookmarks within the verifier sync profile. 38BookmarkModel* GetVerifierBookmarkModel() WARN_UNUSED_RESULT; 39 40// Adds a URL with address |url| and title |title| to the bookmark bar of 41// profile |profile|. Returns a pointer to the node that was added. 42const BookmarkNode* AddURL( 43 int profile, 44 const std::string& title, 45 const GURL& url) WARN_UNUSED_RESULT; 46 47// Adds a URL with address |url| and title |title| to the bookmark bar of 48// profile |profile| at position |index|. Returns a pointer to the node that 49// was added. 50const BookmarkNode* AddURL( 51 int profile, 52 int index, 53 const std::string& title, 54 const GURL& url) WARN_UNUSED_RESULT; 55 56// Adds a URL with address |url| and title |title| under the node |parent| of 57// profile |profile| at position |index|. Returns a pointer to the node that 58// was added. 59const BookmarkNode* AddURL( 60 int profile, 61 const BookmarkNode* parent, 62 int index, 63 const std::string& title, 64 const GURL& url) WARN_UNUSED_RESULT; 65 66// Adds a folder named |title| to the bookmark bar of profile |profile|. 67// Returns a pointer to the folder that was added. 68const BookmarkNode* AddFolder( 69 int profile, 70 const std::string& title) WARN_UNUSED_RESULT; 71 72// Adds a folder named |title| to the bookmark bar of profile |profile| at 73// position |index|. Returns a pointer to the folder that was added. 74const BookmarkNode* AddFolder( 75 int profile, 76 int index, 77 const std::string& title) WARN_UNUSED_RESULT; 78 79// Adds a folder named |title| to the node |parent| in the bookmark model of 80// profile |profile| at position |index|. Returns a pointer to the node that 81// was added. 82const BookmarkNode* AddFolder( 83 int profile, 84 const BookmarkNode* parent, 85 int index, 86 const std::string& title) WARN_UNUSED_RESULT; 87 88// Changes the title of the node |node| in the bookmark model of profile 89// |profile| to |new_title|. 90void SetTitle(int profile, 91 const BookmarkNode* node, 92 const std::string& new_title); 93 94// The source of the favicon. 95enum FaviconSource { 96 FROM_UI, 97 FROM_SYNC 98}; 99 100// Sets the |icon_url| and |image| data for the favicon for |node| in the 101// bookmark model for |profile|. 102void SetFavicon(int profile, 103 const BookmarkNode* node, 104 const GURL& icon_url, 105 const gfx::Image& image, 106 FaviconSource source); 107 108// Changes the url of the node |node| in the bookmark model of profile 109// |profile| to |new_url|. Returns a pointer to the node with the changed url. 110const BookmarkNode* SetURL( 111 int profile, 112 const BookmarkNode* node, 113 const GURL& new_url) WARN_UNUSED_RESULT; 114 115// Moves the node |node| in the bookmark model of profile |profile| so it ends 116// up under the node |new_parent| at position |index|. 117void Move( 118 int profile, 119 const BookmarkNode* node, 120 const BookmarkNode* new_parent, 121 int index); 122 123// Removes the node in the bookmark model of profile |profile| under the node 124// |parent| at position |index|. 125void Remove(int profile, const BookmarkNode* parent, int index); 126 127// Removes all non-permanent nodes in the bookmark model of profile |profile|. 128void RemoveAll(int profile); 129 130// Sorts the children of the node |parent| in the bookmark model of profile 131// |profile|. 132void SortChildren(int profile, const BookmarkNode* parent); 133 134// Reverses the order of the children of the node |parent| in the bookmark 135// model of profile |profile|. 136void ReverseChildOrder(int profile, const BookmarkNode* parent); 137 138// Checks if the bookmark model of profile |profile| matches the verifier 139// bookmark model. Returns true if they match. 140bool ModelMatchesVerifier(int profile) WARN_UNUSED_RESULT; 141 142// Checks if the bookmark models of all sync profiles match the verifier 143// bookmark model. Returns true if they match. 144bool AllModelsMatchVerifier() WARN_UNUSED_RESULT; 145 146// Checks if the bookmark models of |profile_a| and |profile_b| match each 147// other. Returns true if they match. 148bool ModelsMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT; 149 150// Checks if the bookmark models of all sync profiles match each other. Does 151// not compare them with the verifier bookmark model. Returns true if they 152// match. 153bool AllModelsMatch() WARN_UNUSED_RESULT; 154 155// Check if the bookmarks models of all sync profiles match each other, using 156// AllModelsMatch. Returns true if bookmark models match and don't timeout 157// while checking. 158bool AwaitAllModelsMatch() WARN_UNUSED_RESULT; 159 160// Checks if the bookmark model of profile |profile| contains any instances of 161// two bookmarks with the same URL under the same parent folder. Returns true 162// if even one instance is found. 163bool ContainsDuplicateBookmarks(int profile); 164 165// Returns whether a node exists with the specified url. 166bool HasNodeWithURL(int profile, const GURL& url); 167 168// Gets the node in the bookmark model of profile |profile| that has the url 169// |url|. Note: Only one instance of |url| is assumed to be present. 170const BookmarkNode* GetUniqueNodeByURL( 171 int profile, 172 const GURL& url) WARN_UNUSED_RESULT; 173 174// Returns the number of bookmarks in bookmark model of profile |profile| 175// whose titles match the string |title|. 176int CountBookmarksWithTitlesMatching( 177 int profile, 178 const std::string& title) WARN_UNUSED_RESULT; 179 180// Returns the number of bookmark folders in the bookmark model of profile 181// |profile| whose titles contain the query string |title|. 182int CountFoldersWithTitlesMatching( 183 int profile, 184 const std::string& title) WARN_UNUSED_RESULT; 185 186// Creates a favicon of |color| with image reps of the platform's supported 187// scale factors (eg MacOS) in addition to 1x. 188gfx::Image CreateFavicon(SkColor color); 189 190// Creates a 1x only favicon from the PNG file at |path|. 191gfx::Image Create1xFaviconFromPNGFile(const std::string& path); 192 193// Returns a URL identifiable by |i|. 194std::string IndexedURL(int i); 195 196// Returns a URL title identifiable by |i|. 197std::string IndexedURLTitle(int i); 198 199// Returns a folder name identifiable by |i|. 200std::string IndexedFolderName(int i); 201 202// Returns a subfolder name identifiable by |i|. 203std::string IndexedSubfolderName(int i); 204 205// Returns a subsubfolder name identifiable by |i|. 206std::string IndexedSubsubfolderName(int i); 207 208} // namespace bookmarks_helper 209 210#endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_BOOKMARKS_HELPER_H_ 211