Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: chrome/test/live_sync/live_bookmarks_sync_test.h

Issue 6462015: Cleanup more test code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: wtf windows is this me Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/test/live_sync/live_bookmarks_sync_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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 #ifndef CHROME_TEST_LIVE_SYNC_LIVE_BOOKMARKS_SYNC_TEST_H_ 5 #ifndef CHROME_TEST_LIVE_SYNC_LIVE_BOOKMARKS_SYNC_TEST_H_
6 #define CHROME_TEST_LIVE_SYNC_LIVE_BOOKMARKS_SYNC_TEST_H_ 6 #define CHROME_TEST_LIVE_SYNC_LIVE_BOOKMARKS_SYNC_TEST_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "chrome/browser/bookmarks/bookmark_model.h" 13 #include "chrome/browser/bookmarks/bookmark_model.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/test/live_sync/bookmark_model_verifier.h" 14 #include "chrome/test/live_sync/bookmark_model_verifier.h"
16 #include "chrome/test/live_sync/live_sync_test.h" 15 #include "chrome/test/live_sync/live_sync_test.h"
17 #include "chrome/test/ui_test_utils.h"
18 #include "googleurl/src/gurl.h"
19 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
20 #include "third_party/skia/include/core/SkBitmap.h" 17
21 #include "ui/gfx/codec/png_codec.h" 18 class GURL;
19 class Profile;
22 20
23 class LiveBookmarksSyncTest : public LiveSyncTest { 21 class LiveBookmarksSyncTest : public LiveSyncTest {
24 public: 22 public:
25 explicit LiveBookmarksSyncTest(TestType test_type) 23 explicit LiveBookmarksSyncTest(TestType test_type);
26 : LiveSyncTest(test_type) {} 24 virtual ~LiveBookmarksSyncTest();
27
28 virtual ~LiveBookmarksSyncTest() {}
29 25
30 // Sets up sync profiles and clients and initializes the bookmark verifier. 26 // Sets up sync profiles and clients and initializes the bookmark verifier.
31 virtual bool SetupClients() WARN_UNUSED_RESULT { 27 virtual bool SetupClients() WARN_UNUSED_RESULT;
32 if (!LiveSyncTest::SetupClients())
33 return false;
34 for (int i = 0; i < num_clients(); ++i) {
35 ui_test_utils::WaitForBookmarkModelToLoad(
36 GetProfile(i)->GetBookmarkModel());
37 }
38 verifier_helper_.reset(
39 new BookmarkModelVerifier(GetVerifierBookmarkModel()));
40 ui_test_utils::WaitForBookmarkModelToLoad(verifier()->GetBookmarkModel());
41 return true;
42 }
43 28
44 // Used to access the bookmark model within a particular sync profile. 29 // Used to access the bookmark model within a particular sync profile.
45 BookmarkModel* GetBookmarkModel(int index) WARN_UNUSED_RESULT { 30 BookmarkModel* GetBookmarkModel(int index) WARN_UNUSED_RESULT;
46 return GetProfile(index)->GetBookmarkModel();
47 }
48 31
49 // Used to access the bookmark bar within a particular sync profile. 32 // Used to access the bookmark bar within a particular sync profile.
50 const BookmarkNode* GetBookmarkBarNode(int index) WARN_UNUSED_RESULT { 33 const BookmarkNode* GetBookmarkBarNode(int index) WARN_UNUSED_RESULT;
51 return GetBookmarkModel(index)->GetBookmarkBarNode();
52 }
53 34
54 // Used to access the "other bookmarks" node within a particular sync profile. 35 // Used to access the "other bookmarks" node within a particular sync profile.
55 const BookmarkNode* GetOtherNode(int index) WARN_UNUSED_RESULT { 36 const BookmarkNode* GetOtherNode(int index) WARN_UNUSED_RESULT;
56 return GetBookmarkModel(index)->other_node();
57 }
58 37
59 // Used to access the bookmarks within the verifier sync profile. 38 // Used to access the bookmarks within the verifier sync profile.
60 BookmarkModel* GetVerifierBookmarkModel() WARN_UNUSED_RESULT { 39 BookmarkModel* GetVerifierBookmarkModel() WARN_UNUSED_RESULT;
61 return verifier()->GetBookmarkModel();
62 }
63 40
64 // After calling this method, changes made to a bookmark model will no longer 41 // After calling this method, changes made to a bookmark model will no longer
65 // be reflected in the verifier model. 42 // be reflected in the verifier model.
66 void DisableVerifier() { verifier_helper_->set_use_verifier_model(false); } 43 void DisableVerifier();
67 44
68 // Adds a URL with address |url| and title |title| to the bookmark bar of 45 // Adds a URL with address |url| and title |title| to the bookmark bar of
69 // profile |profile|. Returns a pointer to the node that was added. 46 // profile |profile|. Returns a pointer to the node that was added.
70 const BookmarkNode* AddURL(int profile, 47 const BookmarkNode* AddURL(int profile,
71 const std::wstring& title, 48 const std::wstring& title,
72 const GURL& url) WARN_UNUSED_RESULT { 49 const GURL& url) WARN_UNUSED_RESULT;
73 return verifier_helper_->AddURL(GetBookmarkModel(profile),
74 GetBookmarkBarNode(profile), 0, WideToUTF16(title), url);
75 }
76 50
77 // Adds a URL with address |url| and title |title| to the bookmark bar of 51 // Adds a URL with address |url| and title |title| to the bookmark bar of
78 // profile |profile| at position |index|. Returns a pointer to the node that 52 // profile |profile| at position |index|. Returns a pointer to the node that
79 // was added. 53 // was added.
80 const BookmarkNode* AddURL(int profile, 54 const BookmarkNode* AddURL(int profile,
81 int index, 55 int index,
82 const std::wstring& title, 56 const std::wstring& title,
83 const GURL& url) WARN_UNUSED_RESULT { 57 const GURL& url) WARN_UNUSED_RESULT;
84 return verifier_helper_->AddURL(GetBookmarkModel(profile),
85 GetBookmarkBarNode(profile), index, WideToUTF16(title), url);
86 }
87 58
88 // Adds a URL with address |url| and title |title| under the node |parent| of 59 // Adds a URL with address |url| and title |title| under the node |parent| of
89 // profile |profile| at position |index|. Returns a pointer to the node that 60 // profile |profile| at position |index|. Returns a pointer to the node that
90 // was added. 61 // was added.
91 const BookmarkNode* AddURL(int profile, 62 const BookmarkNode* AddURL(int profile,
92 const BookmarkNode* parent, 63 const BookmarkNode* parent,
93 int index, 64 int index,
94 const std::wstring& title, 65 const std::wstring& title,
95 const GURL& url) WARN_UNUSED_RESULT { 66 const GURL& url) WARN_UNUSED_RESULT;
96 EXPECT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent);
97 return verifier_helper_->AddURL(GetBookmarkModel(profile), parent, index,
98 WideToUTF16(title), url);
99 }
100 67
101 // Adds a group named |title| to the bookmark bar of profile |profile|. 68 // Adds a group named |title| to the bookmark bar of profile |profile|.
102 // Returns a pointer to the group that was added. 69 // Returns a pointer to the group that was added.
103 const BookmarkNode* AddGroup(int profile, 70 const BookmarkNode* AddGroup(int profile,
104 const std::wstring& title) WARN_UNUSED_RESULT { 71 const std::wstring& title) WARN_UNUSED_RESULT;
105 return verifier_helper_->AddGroup(GetBookmarkModel(profile),
106 GetBookmarkBarNode(profile), 0, WideToUTF16(title));
107 }
108 72
109 // Adds a group named |title| to the bookmark bar of profile |profile| at 73 // Adds a group named |title| to the bookmark bar of profile |profile| at
110 // position |index|. Returns a pointer to the group that was added. 74 // position |index|. Returns a pointer to the group that was added.
111 const BookmarkNode* AddGroup(int profile, 75 const BookmarkNode* AddGroup(int profile,
112 int index, 76 int index,
113 const std::wstring& title) WARN_UNUSED_RESULT { 77 const std::wstring& title) WARN_UNUSED_RESULT;
114 return verifier_helper_->AddGroup(GetBookmarkModel(profile),
115 GetBookmarkBarNode(profile), index, WideToUTF16(title));
116 }
117 78
118 // Adds a group named |title| to the node |parent| in the bookmark model of 79 // Adds a group named |title| to the node |parent| in the bookmark model of
119 // profile |profile| at position |index|. Returns a pointer to the node that 80 // profile |profile| at position |index|. Returns a pointer to the node that
120 // was added. 81 // was added.
121 const BookmarkNode* AddGroup(int profile, 82 const BookmarkNode* AddGroup(int profile,
122 const BookmarkNode* parent, 83 const BookmarkNode* parent,
123 int index, 84 int index,
124 const std::wstring& title) WARN_UNUSED_RESULT { 85 const std::wstring& title) WARN_UNUSED_RESULT;
125 if (GetBookmarkModel(profile)->GetNodeByID(parent->id()) != parent) {
126 LOG(ERROR) << "Node " << parent->GetTitle() << " does not belong to "
127 << "Profile " << profile;
128 return NULL;
129 }
130 return verifier_helper_->AddGroup(
131 GetBookmarkModel(profile), parent, index, WideToUTF16(title));
132 }
133 86
134 // Changes the title of the node |node| in the bookmark model of profile 87 // Changes the title of the node |node| in the bookmark model of profile
135 // |profile| to |new_title|. 88 // |profile| to |new_title|.
136 void SetTitle(int profile, 89 void SetTitle(int profile,
137 const BookmarkNode* node, 90 const BookmarkNode* node,
138 const std::wstring& new_title) { 91 const std::wstring& new_title);
139 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node)
140 << "Node " << node->GetTitle() << " does not belong to "
141 << "Profile " << profile;
142 verifier_helper_->SetTitle(
143 GetBookmarkModel(profile), node, WideToUTF16(new_title));
144 }
145 92
146 // Sets the favicon of the node |node| (of type BookmarkNode::URL) in the 93 // Sets the favicon of the node |node| (of type BookmarkNode::URL) in the
147 // bookmark model of profile |profile| using the data in |icon_bytes_vector|. 94 // bookmark model of profile |profile| using the data in |icon_bytes_vector|.
148 void SetFavicon(int profile, 95 void SetFavicon(int profile,
149 const BookmarkNode* node, 96 const BookmarkNode* node,
150 const std::vector<unsigned char>& icon_bytes_vector) { 97 const std::vector<unsigned char>& icon_bytes_vector);
151 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node)
152 << "Node " << node->GetTitle() << " does not belong to "
153 << "Profile " << profile;
154 ASSERT_EQ(BookmarkNode::URL, node->type())
155 << "Node " << node->GetTitle() << " must be a url.";
156 verifier_helper_->SetFavicon(
157 GetBookmarkModel(profile), node, icon_bytes_vector);
158 }
159 98
160 // Changes the url of the node |node| in the bookmark model of profile 99 // Changes the url of the node |node| in the bookmark model of profile
161 // |profile| to |new_url|. Returns a pointer to the node with the changed url. 100 // |profile| to |new_url|. Returns a pointer to the node with the changed url.
162 const BookmarkNode* SetURL(int profile, 101 const BookmarkNode* SetURL(int profile,
163 const BookmarkNode* node, 102 const BookmarkNode* node,
164 const GURL& new_url) WARN_UNUSED_RESULT { 103 const GURL& new_url) WARN_UNUSED_RESULT;
165 if (GetBookmarkModel(profile)->GetNodeByID(node->id()) != node) {
166 LOG(ERROR) << "Node " << node->GetTitle() << " does not belong to "
167 << "Profile " << profile;
168 return NULL;
169 }
170 return verifier_helper_->SetURL(GetBookmarkModel(profile), node, new_url);
171 }
172 104
173 // Moves the node |node| in the bookmark model of profile |profile| so it ends 105 // Moves the node |node| in the bookmark model of profile |profile| so it ends
174 // up under the node |new_parent| at position |index|. 106 // up under the node |new_parent| at position |index|.
175 void Move(int profile, 107 void Move(int profile,
176 const BookmarkNode* node, 108 const BookmarkNode* node,
177 const BookmarkNode* new_parent, 109 const BookmarkNode* new_parent,
178 int index) { 110 int index);
179 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node)
180 << "Node " << node->GetTitle() << " does not belong to "
181 << "Profile " << profile;
182 verifier_helper_->Move(
183 GetBookmarkModel(profile), node, new_parent, index);
184 }
185 111
186 // Removes the node in the bookmark model of profile |profile| under the node 112 // Removes the node in the bookmark model of profile |profile| under the node
187 // |parent| at position |index|. 113 // |parent| at position |index|.
188 void Remove(int profile, const BookmarkNode* parent, int index) { 114 void Remove(int profile, const BookmarkNode* parent, int index);
189 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent)
190 << "Node " << parent->GetTitle() << " does not belong to "
191 << "Profile " << profile;
192 verifier_helper_->Remove(GetBookmarkModel(profile), parent, index);
193 }
194 115
195 // Sorts the children of the node |parent| in the bookmark model of profile 116 // Sorts the children of the node |parent| in the bookmark model of profile
196 // |profile|. 117 // |profile|.
197 void SortChildren(int profile, const BookmarkNode* parent) { 118 void SortChildren(int profile, const BookmarkNode* parent);
198 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent)
199 << "Node " << parent->GetTitle() << " does not belong to "
200 << "Profile " << profile;
201 verifier_helper_->SortChildren(GetBookmarkModel(profile), parent);
202 }
203 119
204 // Reverses the order of the children of the node |parent| in the bookmark 120 // Reverses the order of the children of the node |parent| in the bookmark
205 // model of profile |profile|. 121 // model of profile |profile|.
206 void ReverseChildOrder(int profile, const BookmarkNode* parent) { 122 void ReverseChildOrder(int profile, const BookmarkNode* parent);
207 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent)
208 << "Node " << parent->GetTitle() << " does not belong to "
209 << "Profile " << profile;
210 verifier_helper_->ReverseChildOrder(GetBookmarkModel(profile), parent);
211 }
212 123
213 // Checks if the bookmark model of profile |profile| matches the verifier 124 // Checks if the bookmark model of profile |profile| matches the verifier
214 // bookmark model. Returns true if they match. 125 // bookmark model. Returns true if they match.
215 bool ModelMatchesVerifier(int profile) WARN_UNUSED_RESULT { 126 bool ModelMatchesVerifier(int profile) WARN_UNUSED_RESULT;
216 if (verifier_helper_->use_verifier_model() == false) {
217 LOG(ERROR) << "Illegal to call ModelMatchesVerifier() after "
218 << "DisableVerifier(). Use ModelsMatch() instead.";
219 return false;
220 }
221 return BookmarkModelVerifier::ModelsMatch(
222 GetVerifierBookmarkModel(), GetBookmarkModel(profile));
223 }
224 127
225 // Checks if the bookmark models of all sync profiles match the verifier 128 // Checks if the bookmark models of all sync profiles match the verifier
226 // bookmark model. Returns true if they match. 129 // bookmark model. Returns true if they match.
227 bool AllModelsMatchVerifier() WARN_UNUSED_RESULT { 130 bool AllModelsMatchVerifier() WARN_UNUSED_RESULT;
228 if (verifier_helper_->use_verifier_model() == false) {
229 LOG(ERROR) << "Illegal to call AllModelsMatchVerifier() after "
230 << "DisableVerifier(). Use AllModelsMatch() instead.";
231 return false;
232 }
233 for (int i = 0; i < num_clients(); ++i) {
234 if (!ModelMatchesVerifier(i)) {
235 LOG(ERROR) << "Model " << i << " does not match the verifier.";
236 return false;
237 }
238 }
239 return true;
240 }
241 131
242 // Checks if the bookmark models of |profile_a| and |profile_b| match each 132 // Checks if the bookmark models of |profile_a| and |profile_b| match each
243 // other. Returns true if they match. 133 // other. Returns true if they match.
244 bool ModelsMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT { 134 bool ModelsMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT;
245 return BookmarkModelVerifier::ModelsMatch(
246 GetBookmarkModel(profile_a), GetBookmarkModel(profile_b));
247 }
248 135
249 // Checks if the bookmark models of all sync profiles match each other. Does 136 // Checks if the bookmark models of all sync profiles match each other. Does
250 // not compare them with the verifier bookmark model. Returns true if they 137 // not compare them with the verifier bookmark model. Returns true if they
251 // match. 138 // match.
252 bool AllModelsMatch() WARN_UNUSED_RESULT { 139 bool AllModelsMatch() WARN_UNUSED_RESULT;
253 for (int i = 1; i < num_clients(); ++i) {
254 if (!ModelsMatch(0, i)) {
255 LOG(ERROR) << "Model " << i << " does not match Model 0.";
256 return false;
257 }
258 }
259 return true;
260 }
261 140
262 // Checks if the bookmark model of profile |profile| contains any instances of 141 // Checks if the bookmark model of profile |profile| contains any instances of
263 // two bookmarks with the same URL under the same parent folder. Returns true 142 // two bookmarks with the same URL under the same parent folder. Returns true
264 // if even one instance is found. 143 // if even one instance is found.
265 bool ContainsDuplicateBookmarks(int profile) { 144 bool ContainsDuplicateBookmarks(int profile);
266 return BookmarkModelVerifier::ContainsDuplicateBookmarks(
267 GetBookmarkModel(profile));
268 }
269 145
270 // Gets the node in the bookmark model of profile |profile| that has the url 146 // Gets the node in the bookmark model of profile |profile| that has the url
271 // |url|. Note: Only one instance of |url| is assumed to be present. 147 // |url|. Note: Only one instance of |url| is assumed to be present.
272 const BookmarkNode* GetUniqueNodeByURL(int profile, 148 const BookmarkNode* GetUniqueNodeByURL(int profile,
273 const GURL& url) WARN_UNUSED_RESULT { 149 const GURL& url) WARN_UNUSED_RESULT;
274 std::vector<const BookmarkNode*> nodes;
275 GetBookmarkModel(profile)->GetNodesByURL(url, &nodes);
276 EXPECT_EQ(1U, nodes.size());
277 if (nodes.empty())
278 return NULL;
279 return nodes[0];
280 }
281 150
282 // Returns the number of bookmarks in bookmark model of profile |profile| 151 // Returns the number of bookmarks in bookmark model of profile |profile|
283 // whose titles match the string |title|. 152 // whose titles match the string |title|.
284 int CountBookmarksWithTitlesMatching(int profile, const std::wstring& title) 153 int CountBookmarksWithTitlesMatching(int profile, const std::wstring& title)
285 WARN_UNUSED_RESULT { 154 WARN_UNUSED_RESULT;
286 return verifier_helper_->CountNodesWithTitlesMatching(
287 GetBookmarkModel(profile), BookmarkNode::URL, WideToUTF16(title));
288 }
289 155
290 // Returns the number of bookmark folders in the bookmark model of profile 156 // Returns the number of bookmark folders in the bookmark model of profile
291 // |profile| whose titles contain the query string |title|. 157 // |profile| whose titles contain the query string |title|.
292 int CountFoldersWithTitlesMatching(int profile, 158 int CountFoldersWithTitlesMatching(
293 const std::wstring& title) WARN_UNUSED_RESULT { 159 int profile,
294 return verifier_helper_->CountNodesWithTitlesMatching( 160 const std::wstring& title) WARN_UNUSED_RESULT;
295 GetBookmarkModel(profile), BookmarkNode::FOLDER, WideToUTF16(title));
296 }
297 161
298 // Creates a unique favicon using |seed|. 162 // Creates a unique favicon using |seed|.
299 static std::vector<unsigned char> CreateFavicon(int seed) { 163 static std::vector<unsigned char> CreateFavicon(int seed);
300 const int w = 16;
301 const int h = 16;
302 SkBitmap bmp;
303 bmp.setConfig(SkBitmap::kARGB_8888_Config, w, h);
304 bmp.allocPixels();
305 uint32_t* src_data = bmp.getAddr32(0, 0);
306 for (int i = 0; i < w * h; ++i) {
307 src_data[i] = SkPreMultiplyARGB((seed + i) % 255,
308 (seed + i) % 250,
309 (seed + i) % 245,
310 (seed + i) % 240);
311 }
312 std::vector<unsigned char> favicon;
313 gfx::PNGCodec::EncodeBGRASkBitmap(bmp, false, &favicon);
314 return favicon;
315 }
316 164
317 private: 165 private:
318 // Helper object that has the functionality to verify changes made to the 166 // Helper object that has the functionality to verify changes made to the
319 // bookmarks of individual profiles. 167 // bookmarks of individual profiles.
320 scoped_ptr<BookmarkModelVerifier> verifier_helper_; 168 scoped_ptr<BookmarkModelVerifier> verifier_helper_;
321 169
322 DISALLOW_COPY_AND_ASSIGN(LiveBookmarksSyncTest); 170 DISALLOW_COPY_AND_ASSIGN(LiveBookmarksSyncTest);
323 }; 171 };
324 172
325 class SingleClientLiveBookmarksSyncTest : public LiveBookmarksSyncTest { 173 class SingleClientLiveBookmarksSyncTest : public LiveBookmarksSyncTest {
(...skipping 30 matching lines...) Expand all
356 public: 204 public:
357 ManyClientLiveBookmarksSyncTest() 205 ManyClientLiveBookmarksSyncTest()
358 : LiveBookmarksSyncTest(MANY_CLIENT) {} 206 : LiveBookmarksSyncTest(MANY_CLIENT) {}
359 ~ManyClientLiveBookmarksSyncTest() {} 207 ~ManyClientLiveBookmarksSyncTest() {}
360 208
361 private: 209 private:
362 DISALLOW_COPY_AND_ASSIGN(ManyClientLiveBookmarksSyncTest); 210 DISALLOW_COPY_AND_ASSIGN(ManyClientLiveBookmarksSyncTest);
363 }; 211 };
364 212
365 #endif // CHROME_TEST_LIVE_SYNC_LIVE_BOOKMARKS_SYNC_TEST_H_ 213 #endif // CHROME_TEST_LIVE_SYNC_LIVE_BOOKMARKS_SYNC_TEST_H_
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/test/live_sync/live_bookmarks_sync_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698