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

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

Issue 7259005: Allow sync integration tests to operate on multiple datatypes: Preferences + Bookmarks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase (no code changes) Created 9 years, 4 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
OLDNEW
(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 #include "chrome/test/live_sync/live_bookmarks_sync_test.h"
6
7 #include "base/stringprintf.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sync/profile_sync_service_harness.h"
11 #include "chrome/test/ui_test_utils.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "ui/gfx/codec/png_codec.h"
14
15 LiveBookmarksSyncTest::LiveBookmarksSyncTest(TestType test_type)
16 : LiveSyncTest(test_type) {}
17
18 LiveBookmarksSyncTest::~LiveBookmarksSyncTest() {}
19
20 bool LiveBookmarksSyncTest::SetupClients() {
21 if (!LiveSyncTest::SetupClients())
22 return false;
23 for (int i = 0; i < num_clients(); ++i) {
24 ui_test_utils::WaitForBookmarkModelToLoad(
25 GetProfile(i)->GetBookmarkModel());
26 }
27 verifier_helper_.reset(
28 new BookmarkModelVerifier(GetVerifierBookmarkModel()));
29 ui_test_utils::WaitForBookmarkModelToLoad(verifier()->GetBookmarkModel());
30 return true;
31 }
32
33 BookmarkModel* LiveBookmarksSyncTest::GetBookmarkModel(int index) {
34 return GetProfile(index)->GetBookmarkModel();
35 }
36
37 const BookmarkNode* LiveBookmarksSyncTest::GetBookmarkBarNode(int index) {
38 return GetBookmarkModel(index)->bookmark_bar_node();
39 }
40
41 const BookmarkNode* LiveBookmarksSyncTest::GetOtherNode(int index) {
42 return GetBookmarkModel(index)->other_node();
43 }
44
45 BookmarkModel* LiveBookmarksSyncTest::GetVerifierBookmarkModel() {
46 return verifier()->GetBookmarkModel();
47 }
48
49 void LiveBookmarksSyncTest::DisableVerifier() {
50 verifier_helper_->set_use_verifier_model(false);
51 }
52
53 bool LiveBookmarksSyncTest::EnableEncryption(int index) {
54 return GetClient(index)->EnableEncryptionForType(syncable::BOOKMARKS);
55 }
56
57 bool LiveBookmarksSyncTest::IsEncrypted(int index) {
58 return GetClient(index)->IsTypeEncrypted(syncable::BOOKMARKS);
59 }
60
61 const BookmarkNode* LiveBookmarksSyncTest::AddURL(int profile,
62 const std::wstring& title,
63 const GURL& url) {
64 return verifier_helper_->AddURL(GetBookmarkModel(profile),
65 GetBookmarkBarNode(profile),
66 0, WideToUTF16(title), url);
67 }
68
69 const BookmarkNode* LiveBookmarksSyncTest::AddURL(int profile,
70 int index,
71 const std::wstring& title,
72 const GURL& url) {
73 return verifier_helper_->AddURL(GetBookmarkModel(profile),
74 GetBookmarkBarNode(profile),
75 index, WideToUTF16(title), url);
76 }
77
78 const BookmarkNode* LiveBookmarksSyncTest::AddURL(int profile,
79 const BookmarkNode* parent,
80 int index,
81 const std::wstring& title,
82 const GURL& url) {
83 EXPECT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent);
84 return verifier_helper_->AddURL(GetBookmarkModel(profile), parent, index,
85 WideToUTF16(title), url);
86 }
87
88 const BookmarkNode* LiveBookmarksSyncTest::AddFolder(
89 int profile,
90 const std::wstring& title) {
91 return verifier_helper_->AddFolder(GetBookmarkModel(profile),
92 GetBookmarkBarNode(profile),
93 0, WideToUTF16(title));
94 }
95
96 const BookmarkNode* LiveBookmarksSyncTest::AddFolder(
97 int profile,
98 int index,
99 const std::wstring& title) {
100 return verifier_helper_->AddFolder(GetBookmarkModel(profile),
101 GetBookmarkBarNode(profile),
102 index, WideToUTF16(title));
103 }
104
105 const BookmarkNode* LiveBookmarksSyncTest::AddFolder(
106 int profile,
107 const BookmarkNode* parent,
108 int index,
109 const std::wstring& title) {
110 if (GetBookmarkModel(profile)->GetNodeByID(parent->id()) != parent) {
111 LOG(ERROR) << "Node " << parent->GetTitle() << " does not belong to "
112 << "Profile " << profile;
113 return NULL;
114 }
115 return verifier_helper_->AddFolder(
116 GetBookmarkModel(profile), parent, index, WideToUTF16(title));
117 }
118
119 void LiveBookmarksSyncTest::SetTitle(int profile,
120 const BookmarkNode* node,
121 const std::wstring& new_title) {
122 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node)
123 << "Node " << node->GetTitle() << " does not belong to "
124 << "Profile " << profile;
125 verifier_helper_->SetTitle(
126 GetBookmarkModel(profile), node, WideToUTF16(new_title));
127 }
128
129 void LiveBookmarksSyncTest::SetFavicon(
130 int profile,
131 const BookmarkNode* node,
132 const std::vector<unsigned char>& icon_bytes_vector) {
133 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node)
134 << "Node " << node->GetTitle() << " does not belong to "
135 << "Profile " << profile;
136 ASSERT_EQ(BookmarkNode::URL, node->type())
137 << "Node " << node->GetTitle() << " must be a url.";
138 verifier_helper_->SetFavicon(
139 GetBookmarkModel(profile), node, icon_bytes_vector);
140 }
141
142 const BookmarkNode* LiveBookmarksSyncTest::SetURL(int profile,
143 const BookmarkNode* node,
144 const GURL& new_url) {
145 if (GetBookmarkModel(profile)->GetNodeByID(node->id()) != node) {
146 LOG(ERROR) << "Node " << node->GetTitle() << " does not belong to "
147 << "Profile " << profile;
148 return NULL;
149 }
150 return verifier_helper_->SetURL(GetBookmarkModel(profile), node, new_url);
151 }
152
153 void LiveBookmarksSyncTest::Move(int profile,
154 const BookmarkNode* node,
155 const BookmarkNode* new_parent,
156 int index) {
157 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node)
158 << "Node " << node->GetTitle() << " does not belong to "
159 << "Profile " << profile;
160 verifier_helper_->Move(
161 GetBookmarkModel(profile), node, new_parent, index);
162 }
163
164
165 void LiveBookmarksSyncTest::Remove(int profile, const BookmarkNode* parent,
166 int index) {
167 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent)
168 << "Node " << parent->GetTitle() << " does not belong to "
169 << "Profile " << profile;
170 verifier_helper_->Remove(GetBookmarkModel(profile), parent, index);
171 }
172
173 void LiveBookmarksSyncTest::SortChildren(int profile,
174 const BookmarkNode* parent) {
175 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent)
176 << "Node " << parent->GetTitle() << " does not belong to "
177 << "Profile " << profile;
178 verifier_helper_->SortChildren(GetBookmarkModel(profile), parent);
179 }
180
181 void LiveBookmarksSyncTest::ReverseChildOrder(int profile,
182 const BookmarkNode* parent) {
183 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent)
184 << "Node " << parent->GetTitle() << " does not belong to "
185 << "Profile " << profile;
186 verifier_helper_->ReverseChildOrder(GetBookmarkModel(profile), parent);
187 }
188
189 bool LiveBookmarksSyncTest::ModelMatchesVerifier(int profile) {
190 if (verifier_helper_->use_verifier_model() == false) {
191 LOG(ERROR) << "Illegal to call ModelMatchesVerifier() after "
192 << "DisableVerifier(). Use ModelsMatch() instead.";
193 return false;
194 }
195 return verifier_helper_->ModelsMatch(GetVerifierBookmarkModel(),
196 GetBookmarkModel(profile));
197 }
198
199 bool LiveBookmarksSyncTest::AllModelsMatchVerifier() {
200 if (verifier_helper_->use_verifier_model() == false) {
201 LOG(ERROR) << "Illegal to call AllModelsMatchVerifier() after "
202 << "DisableVerifier(). Use AllModelsMatch() instead.";
203 return false;
204 }
205 for (int i = 0; i < num_clients(); ++i) {
206 if (!ModelMatchesVerifier(i)) {
207 LOG(ERROR) << "Model " << i << " does not match the verifier.";
208 return false;
209 }
210 }
211 return true;
212 }
213
214 bool LiveBookmarksSyncTest::ModelsMatch(int profile_a, int profile_b) {
215 return verifier_helper_->ModelsMatch(GetBookmarkModel(profile_a),
216 GetBookmarkModel(profile_b));
217 }
218
219 bool LiveBookmarksSyncTest::AllModelsMatch() {
220 for (int i = 1; i < num_clients(); ++i) {
221 if (!ModelsMatch(0, i)) {
222 LOG(ERROR) << "Model " << i << " does not match Model 0.";
223 return false;
224 }
225 }
226 return true;
227 }
228
229 bool LiveBookmarksSyncTest::ContainsDuplicateBookmarks(int profile) {
230 return verifier_helper_->ContainsDuplicateBookmarks(
231 GetBookmarkModel(profile));
232 }
233
234 const BookmarkNode* LiveBookmarksSyncTest::GetUniqueNodeByURL(int profile,
235 const GURL& url) {
236 std::vector<const BookmarkNode*> nodes;
237 GetBookmarkModel(profile)->GetNodesByURL(url, &nodes);
238 EXPECT_EQ(1U, nodes.size());
239 if (nodes.empty())
240 return NULL;
241 return nodes[0];
242 }
243
244 int LiveBookmarksSyncTest::CountBookmarksWithTitlesMatching(
245 int profile,
246 const std::wstring& title) {
247 return verifier_helper_->CountNodesWithTitlesMatching(
248 GetBookmarkModel(profile), BookmarkNode::URL, WideToUTF16(title));
249 }
250
251 int LiveBookmarksSyncTest::CountFoldersWithTitlesMatching(
252 int profile,
253 const std::wstring& title) {
254 return verifier_helper_->CountNodesWithTitlesMatching(
255 GetBookmarkModel(profile), BookmarkNode::FOLDER, WideToUTF16(title));
256 }
257
258 // static
259 std::vector<unsigned char> LiveBookmarksSyncTest::CreateFavicon(int seed) {
260 const int w = 16;
261 const int h = 16;
262 SkBitmap bmp;
263 bmp.setConfig(SkBitmap::kARGB_8888_Config, w, h);
264 bmp.allocPixels();
265 uint32_t* src_data = bmp.getAddr32(0, 0);
266 for (int i = 0; i < w * h; ++i) {
267 src_data[i] = SkPreMultiplyARGB((seed + i) % 255,
268 (seed + i) % 250,
269 (seed + i) % 245,
270 (seed + i) % 240);
271 }
272 std::vector<unsigned char> favicon;
273 gfx::PNGCodec::EncodeBGRASkBitmap(bmp, false, &favicon);
274 return favicon;
275 }
276
277 std::string LiveBookmarksSyncTest::IndexedURL(int i) {
278 return StringPrintf("http://www.host.ext:1234/path/filename/%d", i);
279 }
280
281 std::wstring LiveBookmarksSyncTest::IndexedURLTitle(int i) {
282 return StringPrintf(L"URL Title %d", i);
283 }
284
285 std::wstring LiveBookmarksSyncTest::IndexedFolderName(int i) {
286 return StringPrintf(L"Folder Name %d", i);
287 }
288
289 std::wstring LiveBookmarksSyncTest::IndexedSubfolderName(int i) {
290 return StringPrintf(L"Subfolder Name %d", i);
291 }
292
293 std::wstring LiveBookmarksSyncTest::IndexedSubsubfolderName(int i) {
294 return StringPrintf(L"Subsubfolder Name %d", i);
295 }
OLDNEW
« no previous file with comments | « chrome/test/live_sync/live_bookmarks_sync_test.h ('k') | chrome/test/live_sync/live_preferences_sync_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698