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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 int result = -1; | 251 int result = -1; |
252 if (!base::StringToInt(temp, &result)) | 252 if (!base::StringToInt(temp, &result)) |
253 return -1; | 253 return -1; |
254 return result; | 254 return result; |
255 } | 255 } |
256 | 256 |
257 } // namespace | 257 } // namespace |
258 | 258 |
259 class SyncFaviconCacheTest : public testing::Test { | 259 class SyncFaviconCacheTest : public testing::Test { |
260 public: | 260 public: |
261 SyncFaviconCacheTest(); | 261 SyncFaviconCacheTest() |
| 262 : scoped_task_environment_( |
| 263 base::test::ScopedTaskEnvironment::MainThreadType::UI) {} |
262 ~SyncFaviconCacheTest() override {} | 264 ~SyncFaviconCacheTest() override {} |
263 | 265 |
264 void SetUpInitialSync(const syncer::SyncDataList& initial_image_data, | 266 void SetUpInitialSync(const syncer::SyncDataList& initial_image_data, |
265 const syncer::SyncDataList& initial_tracking_data); | 267 const syncer::SyncDataList& initial_tracking_data); |
266 | 268 |
267 size_t GetFaviconCount() const; | 269 size_t GetFaviconCount() const; |
268 size_t GetTaskCount() const; | 270 size_t GetTaskCount() const; |
269 | 271 |
270 testing::AssertionResult ExpectFaviconEquals( | 272 testing::AssertionResult ExpectFaviconEquals( |
271 const std::string& page_url, | 273 const std::string& page_url, |
(...skipping 13 matching lines...) Expand all Loading... |
285 void OnCustomFaviconDataAvailable(const TestFaviconData& test_data); | 287 void OnCustomFaviconDataAvailable(const TestFaviconData& test_data); |
286 | 288 |
287 // Helper method to run the message loop after invoking | 289 // Helper method to run the message loop after invoking |
288 // OnReceivedSyncFavicon, which posts an internal task. | 290 // OnReceivedSyncFavicon, which posts an internal task. |
289 void TriggerSyncFaviconReceived(const GURL& page_url, | 291 void TriggerSyncFaviconReceived(const GURL& page_url, |
290 const GURL& icon_url, | 292 const GURL& icon_url, |
291 const std::string& icon_bytes, | 293 const std::string& icon_bytes, |
292 int64_t last_visit_time_ms); | 294 int64_t last_visit_time_ms); |
293 | 295 |
294 private: | 296 private: |
295 base::MessageLoopForUI message_loop_; | 297 base::test::ScopedTaskEnvironment scoped_task_environment_; |
296 FaviconCache cache_; | 298 FaviconCache cache_; |
297 | 299 |
298 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. | 300 // Our dummy ChangeProcessor used to inspect changes pushed to Sync. |
299 std::unique_ptr<TestChangeProcessor> sync_processor_; | 301 std::unique_ptr<TestChangeProcessor> sync_processor_; |
300 std::unique_ptr<syncer::SyncChangeProcessorWrapperForTest> | 302 std::unique_ptr<syncer::SyncChangeProcessorWrapperForTest> |
301 sync_processor_wrapper_; | 303 sync_processor_wrapper_; |
302 }; | 304 }; |
303 | 305 |
304 SyncFaviconCacheTest::SyncFaviconCacheTest() | 306 SyncFaviconCacheTest::SyncFaviconCacheTest() |
305 : cache_(nullptr, nullptr, kMaxSyncFavicons), | 307 : cache_(nullptr, nullptr, kMaxSyncFavicons), |
(...skipping 1619 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 |