OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/sync_sessions/favicon_cache.h" | 5 #include "components/sync_sessions/favicon_cache.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/message_loop/message_loop.h" | |
9 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
10 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/test/scoped_task_environment.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "components/sync/model/attachments/attachment_id.h" | 14 #include "components/sync/model/attachments/attachment_id.h" |
15 #include "components/sync/model/attachments/attachment_service_proxy_for_test.h" | 15 #include "components/sync/model/attachments/attachment_service_proxy_for_test.h" |
16 #include "components/sync/model/sync_change_processor_wrapper_for_test.h" | 16 #include "components/sync/model/sync_change_processor_wrapper_for_test.h" |
17 #include "components/sync/model/sync_error_factory_mock.h" | 17 #include "components/sync/model/sync_error_factory_mock.h" |
18 #include "components/sync/model/time.h" | 18 #include "components/sync/model/time.h" |
19 #include "components/sync/protocol/favicon_image_specifics.pb.h" | 19 #include "components/sync/protocol/favicon_image_specifics.pb.h" |
20 #include "components/sync/protocol/favicon_tracking_specifics.pb.h" | 20 #include "components/sync/protocol/favicon_tracking_specifics.pb.h" |
21 #include "components/sync/protocol/sync.pb.h" | 21 #include "components/sync/protocol/sync.pb.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 void OnCustomFaviconDataAvailable(const TestFaviconData& test_data); | 285 void OnCustomFaviconDataAvailable(const TestFaviconData& test_data); |
286 | 286 |
287 // Helper method to run the message loop after invoking | 287 // Helper method to run the message loop after invoking |
288 // OnReceivedSyncFavicon, which posts an internal task. | 288 // OnReceivedSyncFavicon, which posts an internal task. |
289 void TriggerSyncFaviconReceived(const GURL& page_url, | 289 void TriggerSyncFaviconReceived(const GURL& page_url, |
290 const GURL& icon_url, | 290 const GURL& icon_url, |
291 const std::string& icon_bytes, | 291 const std::string& icon_bytes, |
292 int64_t last_visit_time_ms); | 292 int64_t last_visit_time_ms); |
293 | 293 |
294 private: | 294 private: |
295 base::MessageLoopForUI message_loop_; | 295 base::test::ScopedTaskEnvironment scoped_task_environment_; |
296 FaviconCache cache_; | 296 FaviconCache cache_; |
297 | 297 |
298 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. | 298 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. |
299 std::unique_ptr<TestChangeProcessor> sync_processor_; | 299 std::unique_ptr<TestChangeProcessor> sync_processor_; |
300 std::unique_ptr<syncer::SyncChangeProcessorWrapperForTest> | 300 std::unique_ptr<syncer::SyncChangeProcessorWrapperForTest> |
301 sync_processor_wrapper_; | 301 sync_processor_wrapper_; |
302 }; | 302 }; |
303 | 303 |
304 SyncFaviconCacheTest::SyncFaviconCacheTest() | 304 SyncFaviconCacheTest::SyncFaviconCacheTest() |
305 : cache_(nullptr, nullptr, kMaxSyncFavicons), | 305 : scoped_task_environment_( |
| 306 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 307 cache_(nullptr, nullptr, kMaxSyncFavicons), |
306 sync_processor_(new TestChangeProcessor), | 308 sync_processor_(new TestChangeProcessor), |
307 sync_processor_wrapper_(new syncer::SyncChangeProcessorWrapperForTest( | 309 sync_processor_wrapper_(new syncer::SyncChangeProcessorWrapperForTest( |
308 sync_processor_.get())) {} | 310 sync_processor_.get())) {} |
309 | 311 |
310 void SyncFaviconCacheTest::SetUpInitialSync( | 312 void SyncFaviconCacheTest::SetUpInitialSync( |
311 const syncer::SyncDataList& initial_image_data, | 313 const syncer::SyncDataList& initial_image_data, |
312 const syncer::SyncDataList& initial_tracking_data) { | 314 const syncer::SyncDataList& initial_tracking_data) { |
313 cache()->MergeDataAndStartSyncing(syncer::FAVICON_IMAGES, | 315 cache()->MergeDataAndStartSyncing(syncer::FAVICON_IMAGES, |
314 initial_image_data, | 316 initial_image_data, |
315 CreateAndPassProcessor(), | 317 CreateAndPassProcessor(), |
(...skipping 1609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1925 EXPECT_EQ(changes[4].change_type(), syncer::SyncChange::ACTION_ADD); | 1927 EXPECT_EQ(changes[4].change_type(), syncer::SyncChange::ACTION_ADD); |
1926 EXPECT_EQ(changes[4].sync_data().GetDataType(), syncer::FAVICON_TRACKING); | 1928 EXPECT_EQ(changes[4].sync_data().GetDataType(), syncer::FAVICON_TRACKING); |
1927 EXPECT_EQ(kMaxSyncFavicons, GetFaviconId(changes[4])); | 1929 EXPECT_EQ(kMaxSyncFavicons, GetFaviconId(changes[4])); |
1928 // Expire tracking for favicon[0]. | 1930 // Expire tracking for favicon[0]. |
1929 EXPECT_EQ(changes[5].change_type(), syncer::SyncChange::ACTION_DELETE); | 1931 EXPECT_EQ(changes[5].change_type(), syncer::SyncChange::ACTION_DELETE); |
1930 EXPECT_EQ(changes[5].sync_data().GetDataType(), syncer::FAVICON_TRACKING); | 1932 EXPECT_EQ(changes[5].sync_data().GetDataType(), syncer::FAVICON_TRACKING); |
1931 EXPECT_EQ(0, GetFaviconId(changes[5])); | 1933 EXPECT_EQ(0, GetFaviconId(changes[5])); |
1932 } | 1934 } |
1933 | 1935 |
1934 } // namespace sync_sessions | 1936 } // namespace sync_sessions |
OLD | NEW |