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

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

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

Powered by Google App Engine
This is Rietveld 408576698