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

Side by Side Diff: chrome/browser/sync/glue/favicon_cache_unittest.cc

Issue 217063005: Separate SyncData methods into three groups, local, remote, and common. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@syncapi
Patch Set: Reorganize Local and Remote based on offline feedback. Created 6 years, 8 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "chrome/browser/sync/glue/favicon_cache.h" 5 #include "chrome/browser/sync/glue/favicon_cache.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 DCHECK_EQ(expected_change_types.size(), expected_icons.size()); 213 DCHECK_EQ(expected_change_types.size(), expected_icons.size());
214 if (change_list.size() != expected_icons.size()) 214 if (change_list.size() != expected_icons.size())
215 return testing::AssertionFailure() << "Change list size doesn't match."; 215 return testing::AssertionFailure() << "Change list size doesn't match.";
216 for (size_t i = 0; i < expected_icons.size(); ++i) { 216 for (size_t i = 0; i < expected_icons.size(); ++i) {
217 TestFaviconData data = BuildFaviconData(expected_icons[i]); 217 TestFaviconData data = BuildFaviconData(expected_icons[i]);
218 if (change_list[i].sync_data().GetDataType() != expected_model_type) 218 if (change_list[i].sync_data().GetDataType() != expected_model_type)
219 return testing::AssertionFailure() << "Change datatype doesn't match."; 219 return testing::AssertionFailure() << "Change datatype doesn't match.";
220 if (change_list[i].change_type() != expected_change_types[i]) 220 if (change_list[i].change_type() != expected_change_types[i])
221 return testing::AssertionFailure() << "Change type doesn't match."; 221 return testing::AssertionFailure() << "Change type doesn't match.";
222 if (change_list[i].change_type() == syncer::SyncChange::ACTION_DELETE) { 222 if (change_list[i].change_type() == syncer::SyncChange::ACTION_DELETE) {
223 if (change_list[i].sync_data().GetTag() != data.icon_url.spec()) 223 if (change_list[i].sync_data().AsLocal().GetTag() != data.icon_url.spec())
224 return testing::AssertionFailure() << "Deletion url does not match."; 224 return testing::AssertionFailure() << "Deletion url does not match.";
225 } else { 225 } else {
226 testing::AssertionResult compare_result = 226 testing::AssertionResult compare_result =
227 CompareFaviconDataToSpecifics( 227 CompareFaviconDataToSpecifics(
228 data, 228 data,
229 change_list[i].sync_data().GetSpecifics()); 229 change_list[i].sync_data().GetSpecifics());
230 if (!compare_result) 230 if (!compare_result)
231 return compare_result; 231 return compare_result;
232 } 232 }
233 } 233 }
234 return testing::AssertionSuccess(); 234 return testing::AssertionSuccess();
235 } 235 }
236 236
237 // Helper to extract the favicon id embedded in the tag of a sync 237 // Helper to extract the favicon id embedded in the tag of a sync
238 // change. 238 // change.
239 int GetFaviconId(const syncer::SyncChange change) { 239 int GetFaviconId(const syncer::SyncChange change) {
240 std::string tag = change.sync_data().GetTag(); 240 std::string tag = change.sync_data().AsLocal().GetTag();
241 const std::string kPrefix = "http://bla.com/"; 241 const std::string kPrefix = "http://bla.com/";
242 const std::string kSuffix = ".ico"; 242 const std::string kSuffix = ".ico";
243 if (tag.find(kPrefix) != 0) 243 if (tag.find(kPrefix) != 0)
244 return -1; 244 return -1;
245 std::string temp = tag.substr(kPrefix.length()); 245 std::string temp = tag.substr(kPrefix.length());
246 if (temp.rfind(kSuffix) <= 0) 246 if (temp.rfind(kSuffix) <= 0)
247 return -1; 247 return -1;
248 temp = temp.substr(0, temp.rfind(kSuffix)); 248 temp = temp.substr(0, temp.rfind(kSuffix));
249 int result = -1; 249 int result = -1;
250 if (!base::StringToInt(temp, &result)) 250 if (!base::StringToInt(temp, &result))
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 cache()->OnFaviconVisited(test_data.page_url, test_data.icon_url); 1339 cache()->OnFaviconVisited(test_data.page_url, test_data.icon_url);
1340 OnCustomFaviconDataAvailable(test_data); 1340 OnCustomFaviconDataAvailable(test_data);
1341 1341
1342 syncer::SyncChangeList changes = processor()->GetAndResetChangeList(); 1342 syncer::SyncChangeList changes = processor()->GetAndResetChangeList();
1343 ASSERT_EQ(4U, changes.size()); 1343 ASSERT_EQ(4U, changes.size());
1344 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, changes[0].change_type()); 1344 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, changes[0].change_type());
1345 EXPECT_TRUE( 1345 EXPECT_TRUE(
1346 CompareFaviconDataToSpecifics(test_data, 1346 CompareFaviconDataToSpecifics(test_data,
1347 changes[0].sync_data().GetSpecifics())); 1347 changes[0].sync_data().GetSpecifics()));
1348 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[1].change_type()); 1348 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[1].change_type());
1349 EXPECT_EQ(old_favicon.icon_url.spec(), changes[1].sync_data().GetTag()); 1349 EXPECT_EQ(old_favicon.icon_url.spec(),
1350 changes[1].sync_data().AsLocal().GetTag());
1350 1351
1351 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, changes[2].change_type()); 1352 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, changes[2].change_type());
1352 EXPECT_EQ(test_data.icon_url.spec(), 1353 EXPECT_EQ(test_data.icon_url.spec(),
1353 changes[2].sync_data().GetSpecifics().favicon_tracking(). 1354 changes[2].sync_data().GetSpecifics().favicon_tracking().
1354 favicon_url()); 1355 favicon_url());
1355 EXPECT_NE(changes[2].sync_data().GetSpecifics().favicon_tracking(). 1356 EXPECT_NE(changes[2].sync_data().GetSpecifics().favicon_tracking().
1356 last_visit_time_ms(), 0); 1357 last_visit_time_ms(), 0);
1357 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[3].change_type()); 1358 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, changes[3].change_type());
1358 EXPECT_EQ(old_favicon.icon_url.spec(), changes[3].sync_data().GetTag()); 1359 EXPECT_EQ(old_favicon.icon_url.spec(),
1360 changes[3].sync_data().AsLocal().GetTag());
1359 } 1361 }
1360 1362
1361 EXPECT_EQ(0U, GetTaskCount()); 1363 EXPECT_EQ(0U, GetTaskCount());
1362 EXPECT_EQ((unsigned long)kMaxSyncFavicons, GetFaviconCount()); 1364 EXPECT_EQ((unsigned long)kMaxSyncFavicons, GetFaviconCount());
1363 } 1365 }
1364 1366
1365 // A full history clear notification should result in all synced favicons being 1367 // A full history clear notification should result in all synced favicons being
1366 // deleted. 1368 // deleted.
1367 TEST_F(SyncFaviconCacheTest, HistoryFullClear) { 1369 TEST_F(SyncFaviconCacheTest, HistoryFullClear) {
1368 syncer::SyncDataList initial_image_data, initial_tracking_data; 1370 syncer::SyncDataList initial_image_data, initial_tracking_data;
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1827 EXPECT_EQ(changes[4].change_type(), syncer::SyncChange::ACTION_ADD); 1829 EXPECT_EQ(changes[4].change_type(), syncer::SyncChange::ACTION_ADD);
1828 EXPECT_EQ(changes[4].sync_data().GetDataType(), syncer::FAVICON_TRACKING); 1830 EXPECT_EQ(changes[4].sync_data().GetDataType(), syncer::FAVICON_TRACKING);
1829 EXPECT_EQ(kMaxSyncFavicons, GetFaviconId(changes[4])); 1831 EXPECT_EQ(kMaxSyncFavicons, GetFaviconId(changes[4]));
1830 // Expire tracking for favicon[0]. 1832 // Expire tracking for favicon[0].
1831 EXPECT_EQ(changes[5].change_type(), syncer::SyncChange::ACTION_DELETE); 1833 EXPECT_EQ(changes[5].change_type(), syncer::SyncChange::ACTION_DELETE);
1832 EXPECT_EQ(changes[5].sync_data().GetDataType(), syncer::FAVICON_TRACKING); 1834 EXPECT_EQ(changes[5].sync_data().GetDataType(), syncer::FAVICON_TRACKING);
1833 EXPECT_EQ(0, GetFaviconId(changes[5])); 1835 EXPECT_EQ(0, GetFaviconId(changes[5]));
1834 } 1836 }
1835 1837
1836 } // namespace browser_sync 1838 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698