OLD | NEW |
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/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/history/history_notifications.h" | 11 #include "chrome/browser/history/history_notifications.h" |
12 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
| 13 #include "sync/api/sync_change_processor_wrapper_for_test.h" |
13 #include "sync/api/sync_error_factory_mock.h" | 14 #include "sync/api/sync_error_factory_mock.h" |
14 #include "sync/api/time.h" | 15 #include "sync/api/time.h" |
15 #include "sync/protocol/favicon_image_specifics.pb.h" | 16 #include "sync/protocol/favicon_image_specifics.pb.h" |
16 #include "sync/protocol/favicon_tracking_specifics.pb.h" | 17 #include "sync/protocol/favicon_tracking_specifics.pb.h" |
17 #include "sync/protocol/sync.pb.h" | 18 #include "sync/protocol/sync.pb.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 namespace browser_sync { | 21 namespace browser_sync { |
21 | 22 |
22 namespace { | 23 namespace { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 change_list.begin(), | 95 change_list.begin(), |
95 change_list.end()); | 96 change_list.end()); |
96 change_map_.erase(change_map_.begin(), change_map_.end()); | 97 change_map_.erase(change_map_.begin(), change_map_.end()); |
97 for (syncer::SyncChangeList::const_iterator iter = change_list.begin(); | 98 for (syncer::SyncChangeList::const_iterator iter = change_list.begin(); |
98 iter != change_list.end(); ++iter) { | 99 iter != change_list.end(); ++iter) { |
99 change_map_[iter->sync_data().GetTitle()] = *iter; | 100 change_map_[iter->sync_data().GetTitle()] = *iter; |
100 } | 101 } |
101 return syncer::SyncError(); | 102 return syncer::SyncError(); |
102 } | 103 } |
103 | 104 |
104 | |
105 // SyncChangeProcessorDelegate ------------------------------------------------ | |
106 | |
107 class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor { | |
108 public: | |
109 explicit SyncChangeProcessorDelegate(syncer::SyncChangeProcessor* recipient); | |
110 virtual ~SyncChangeProcessorDelegate(); | |
111 | |
112 // syncer::SyncChangeProcessor implementation. | |
113 virtual syncer::SyncError ProcessSyncChanges( | |
114 const tracked_objects::Location& from_here, | |
115 const syncer::SyncChangeList& change_list) OVERRIDE; | |
116 | |
117 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const | |
118 OVERRIDE { | |
119 return recipient_->GetAllSyncData(type); | |
120 } | |
121 | |
122 private: | |
123 // The recipient of all sync changes. | |
124 syncer::SyncChangeProcessor* recipient_; | |
125 | |
126 DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate); | |
127 }; | |
128 | |
129 SyncChangeProcessorDelegate::SyncChangeProcessorDelegate( | |
130 syncer::SyncChangeProcessor* recipient) | |
131 : recipient_(recipient) { | |
132 DCHECK(recipient_); | |
133 } | |
134 | |
135 SyncChangeProcessorDelegate::~SyncChangeProcessorDelegate() { | |
136 } | |
137 | |
138 syncer::SyncError SyncChangeProcessorDelegate::ProcessSyncChanges( | |
139 const tracked_objects::Location& from_here, | |
140 const syncer::SyncChangeList& change_list) { | |
141 return recipient_->ProcessSyncChanges(from_here, change_list); | |
142 } | |
143 | |
144 // TestFaviconData ------------------------------------------------------------ | 105 // TestFaviconData ------------------------------------------------------------ |
145 struct TestFaviconData { | 106 struct TestFaviconData { |
146 TestFaviconData() : last_visit_time(0), is_bookmarked(false) {} | 107 TestFaviconData() : last_visit_time(0), is_bookmarked(false) {} |
147 GURL page_url; | 108 GURL page_url; |
148 GURL icon_url; | 109 GURL icon_url; |
149 std::string image_16; | 110 std::string image_16; |
150 std::string image_32; | 111 std::string image_32; |
151 std::string image_64; | 112 std::string image_64; |
152 int64 last_visit_time; | 113 int64 last_visit_time; |
153 bool is_bookmarked; | 114 bool is_bookmarked; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 const GURL& icon_url, | 269 const GURL& icon_url, |
309 const std::string& icon_bytes, | 270 const std::string& icon_bytes, |
310 int64 last_visit_time_ms); | 271 int64 last_visit_time_ms); |
311 | 272 |
312 private: | 273 private: |
313 base::MessageLoopForUI message_loop_; | 274 base::MessageLoopForUI message_loop_; |
314 FaviconCache cache_; | 275 FaviconCache cache_; |
315 | 276 |
316 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. | 277 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. |
317 scoped_ptr<TestChangeProcessor> sync_processor_; | 278 scoped_ptr<TestChangeProcessor> sync_processor_; |
318 scoped_ptr<SyncChangeProcessorDelegate> sync_processor_delegate_; | 279 scoped_ptr<syncer::SyncChangeProcessorWrapperForTest> sync_processor_wrapper_; |
319 }; | 280 }; |
320 | 281 |
321 SyncFaviconCacheTest::SyncFaviconCacheTest() | 282 SyncFaviconCacheTest::SyncFaviconCacheTest() |
322 : cache_(NULL, kMaxSyncFavicons), | 283 : cache_(NULL, kMaxSyncFavicons), |
323 sync_processor_(new TestChangeProcessor), | 284 sync_processor_(new TestChangeProcessor), |
324 sync_processor_delegate_(new SyncChangeProcessorDelegate( | 285 sync_processor_wrapper_(new syncer::SyncChangeProcessorWrapperForTest( |
325 sync_processor_.get())) { | 286 sync_processor_.get())) {} |
326 } | |
327 | 287 |
328 void SyncFaviconCacheTest::SetUpInitialSync( | 288 void SyncFaviconCacheTest::SetUpInitialSync( |
329 const syncer::SyncDataList& initial_image_data, | 289 const syncer::SyncDataList& initial_image_data, |
330 const syncer::SyncDataList& initial_tracking_data) { | 290 const syncer::SyncDataList& initial_tracking_data) { |
331 cache()->MergeDataAndStartSyncing(syncer::FAVICON_IMAGES, | 291 cache()->MergeDataAndStartSyncing(syncer::FAVICON_IMAGES, |
332 initial_image_data, | 292 initial_image_data, |
333 CreateAndPassProcessor(), | 293 CreateAndPassProcessor(), |
334 CreateAndPassSyncErrorFactory()); | 294 CreateAndPassSyncErrorFactory()); |
335 ASSERT_EQ(0U, processor()->GetAndResetChangeList().size()); | 295 ASSERT_EQ(0U, processor()->GetAndResetChangeList().size()); |
336 cache()->MergeDataAndStartSyncing(syncer::FAVICON_TRACKING, | 296 cache()->MergeDataAndStartSyncing(syncer::FAVICON_TRACKING, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 } | 371 } |
412 if (!found_match) | 372 if (!found_match) |
413 return testing::AssertionFailure() << "Could not find favicon."; | 373 return testing::AssertionFailure() << "Could not find favicon."; |
414 } | 374 } |
415 return testing::AssertionSuccess(); | 375 return testing::AssertionSuccess(); |
416 } | 376 } |
417 | 377 |
418 scoped_ptr<syncer::SyncChangeProcessor> | 378 scoped_ptr<syncer::SyncChangeProcessor> |
419 SyncFaviconCacheTest::CreateAndPassProcessor() { | 379 SyncFaviconCacheTest::CreateAndPassProcessor() { |
420 return scoped_ptr<syncer::SyncChangeProcessor>( | 380 return scoped_ptr<syncer::SyncChangeProcessor>( |
421 new SyncChangeProcessorDelegate(sync_processor_.get())); | 381 new syncer::SyncChangeProcessorWrapperForTest(sync_processor_.get())); |
422 } | 382 } |
423 | 383 |
424 scoped_ptr<syncer::SyncErrorFactory> SyncFaviconCacheTest:: | 384 scoped_ptr<syncer::SyncErrorFactory> SyncFaviconCacheTest:: |
425 CreateAndPassSyncErrorFactory() { | 385 CreateAndPassSyncErrorFactory() { |
426 return scoped_ptr<syncer::SyncErrorFactory>( | 386 return scoped_ptr<syncer::SyncErrorFactory>( |
427 new syncer::SyncErrorFactoryMock()); | 387 new syncer::SyncErrorFactoryMock()); |
428 } | 388 } |
429 | 389 |
430 void SyncFaviconCacheTest::OnCustomFaviconDataAvailable( | 390 void SyncFaviconCacheTest::OnCustomFaviconDataAvailable( |
431 const TestFaviconData& test_data) { | 391 const TestFaviconData& test_data) { |
(...skipping 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1766 ASSERT_EQ(changes[2].change_type(), syncer::SyncChange::ACTION_ADD); | 1726 ASSERT_EQ(changes[2].change_type(), syncer::SyncChange::ACTION_ADD); |
1767 ASSERT_EQ(changes[2].sync_data().GetDataType(), syncer::FAVICON_TRACKING); | 1727 ASSERT_EQ(changes[2].sync_data().GetDataType(), syncer::FAVICON_TRACKING); |
1768 ASSERT_EQ(changes[3].change_type(), syncer::SyncChange::ACTION_DELETE); | 1728 ASSERT_EQ(changes[3].change_type(), syncer::SyncChange::ACTION_DELETE); |
1769 ASSERT_EQ(changes[3].sync_data().GetDataType(), syncer::FAVICON_TRACKING); | 1729 ASSERT_EQ(changes[3].sync_data().GetDataType(), syncer::FAVICON_TRACKING); |
1770 } | 1730 } |
1771 EXPECT_EQ(0U, GetTaskCount()); | 1731 EXPECT_EQ(0U, GetTaskCount()); |
1772 EXPECT_EQ((unsigned long)kMaxSyncFavicons, GetFaviconCount()); | 1732 EXPECT_EQ((unsigned long)kMaxSyncFavicons, GetFaviconCount()); |
1773 } | 1733 } |
1774 | 1734 |
1775 } // namespace browser_sync | 1735 } // namespace browser_sync |
OLD | NEW |