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/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" |
11 #include "chrome/browser/chrome_notification_types.h" | |
12 #include "chrome/browser/history/history_notifications.h" | |
13 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
14 #include "sync/api/attachments/attachment_id.h" | 12 #include "sync/api/attachments/attachment_id.h" |
15 #include "sync/api/sync_change_processor_wrapper_for_test.h" | 13 #include "sync/api/sync_change_processor_wrapper_for_test.h" |
16 #include "sync/api/sync_error_factory_mock.h" | 14 #include "sync/api/sync_error_factory_mock.h" |
17 #include "sync/api/time.h" | 15 #include "sync/api/time.h" |
18 #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test .h" | 16 #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test .h" |
19 #include "sync/protocol/favicon_image_specifics.pb.h" | 17 #include "sync/protocol/favicon_image_specifics.pb.h" |
20 #include "sync/protocol/favicon_tracking_specifics.pb.h" | 18 #include "sync/protocol/favicon_tracking_specifics.pb.h" |
21 #include "sync/protocol/sync.pb.h" | 19 #include "sync/protocol/sync.pb.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 1439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1462 tracking_specifics, | 1460 tracking_specifics, |
1463 base::Time(), | 1461 base::Time(), |
1464 syncer::AttachmentIdList(), | 1462 syncer::AttachmentIdList(), |
1465 syncer::AttachmentServiceProxyForTest::Create())); | 1463 syncer::AttachmentServiceProxyForTest::Create())); |
1466 } | 1464 } |
1467 | 1465 |
1468 SetUpInitialSync(initial_image_data, initial_tracking_data); | 1466 SetUpInitialSync(initial_image_data, initial_tracking_data); |
1469 syncer::SyncChangeList changes = processor()->GetAndResetChangeList(); | 1467 syncer::SyncChangeList changes = processor()->GetAndResetChangeList(); |
1470 EXPECT_TRUE(changes.empty()); | 1468 EXPECT_TRUE(changes.empty()); |
1471 | 1469 |
1472 history::URLsDeletedDetails deletions; | |
1473 deletions.all_history = true; | |
1474 EXPECT_EQ((unsigned long)kFaviconBatchSize, GetFaviconCount()); | 1470 EXPECT_EQ((unsigned long)kFaviconBatchSize, GetFaviconCount()); |
1475 content::NotificationService::current()->Notify( | 1471 cache()->OnURLsDeleted(nullptr, true, false, history::URLRows(), |
1476 chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 1472 std::set<GURL>()); |
1477 content::Source<Profile>(NULL), | |
1478 content::Details<history::URLsDeletedDetails>(&deletions)); | |
1479 EXPECT_EQ(0U, GetFaviconCount()); | 1473 EXPECT_EQ(0U, GetFaviconCount()); |
1480 changes = processor()->GetAndResetChangeList(); | 1474 changes = processor()->GetAndResetChangeList(); |
1481 ASSERT_EQ(changes.size(), (unsigned long)kFaviconBatchSize*2); | 1475 ASSERT_EQ(changes.size(), (unsigned long)kFaviconBatchSize*2); |
1482 syncer::SyncChangeList changes_1, changes_2; | 1476 syncer::SyncChangeList changes_1, changes_2; |
1483 for (int i = 0; i < kFaviconBatchSize; ++i) { | 1477 for (int i = 0; i < kFaviconBatchSize; ++i) { |
1484 changes_1.push_back(changes[i]); | 1478 changes_1.push_back(changes[i]); |
1485 changes_2.push_back(changes[i + kFaviconBatchSize]); | 1479 changes_2.push_back(changes[i + kFaviconBatchSize]); |
1486 } | 1480 } |
1487 VerifyChanges(syncer::FAVICON_IMAGES, | 1481 VerifyChanges(syncer::FAVICON_IMAGES, |
1488 expected_deletions, | 1482 expected_deletions, |
1489 expected_icons, | 1483 expected_icons, |
1490 changes_1); | 1484 changes_1); |
1491 VerifyChanges(syncer::FAVICON_TRACKING, | 1485 VerifyChanges(syncer::FAVICON_TRACKING, |
1492 expected_deletions, | 1486 expected_deletions, |
1493 expected_icons, | 1487 expected_icons, |
1494 changes_2); | 1488 changes_2); |
1495 } | 1489 } |
1496 | 1490 |
1497 // A partial history clear notification should result in the expired favicons | 1491 // A partial history clear notification should result in the expired favicons |
1498 // also being deleted from sync. | 1492 // also being deleted from sync. |
1499 TEST_F(SyncFaviconCacheTest, HistorySubsetClear) { | 1493 TEST_F(SyncFaviconCacheTest, HistorySubsetClear) { |
1500 syncer::SyncDataList initial_image_data, initial_tracking_data; | 1494 syncer::SyncDataList initial_image_data, initial_tracking_data; |
1501 std::vector<int> expected_icons; | 1495 std::vector<int> expected_icons; |
1502 std::vector<syncer::SyncChange::SyncChangeType> expected_deletions; | 1496 std::vector<syncer::SyncChange::SyncChangeType> expected_deletions; |
1503 history::URLsDeletedDetails deletions; | 1497 std::set<GURL> favicon_urls; |
pavely
2014/12/11 19:45:36
Could you rename this variable to favicon_urls_to_
nshaik
2014/12/12 05:40:56
Done.
| |
1504 for (int i = 0; i < kFaviconBatchSize; ++i) { | 1498 for (int i = 0; i < kFaviconBatchSize; ++i) { |
1505 TestFaviconData test_data = BuildFaviconData(i); | 1499 TestFaviconData test_data = BuildFaviconData(i); |
1506 if (i < kFaviconBatchSize/2) { | 1500 if (i < kFaviconBatchSize/2) { |
1507 expected_icons.push_back(i); | 1501 expected_icons.push_back(i); |
1508 expected_deletions.push_back(syncer::SyncChange::ACTION_DELETE); | 1502 expected_deletions.push_back(syncer::SyncChange::ACTION_DELETE); |
1509 deletions.favicon_urls.insert(test_data.icon_url); | 1503 favicon_urls.insert(test_data.icon_url); |
1510 } | 1504 } |
1511 sync_pb::EntitySpecifics image_specifics, tracking_specifics; | 1505 sync_pb::EntitySpecifics image_specifics, tracking_specifics; |
1512 FillImageSpecifics(test_data, | 1506 FillImageSpecifics(test_data, |
1513 image_specifics.mutable_favicon_image()); | 1507 image_specifics.mutable_favicon_image()); |
1514 initial_image_data.push_back(syncer::SyncData::CreateRemoteData( | 1508 initial_image_data.push_back(syncer::SyncData::CreateRemoteData( |
1515 1, | 1509 1, |
1516 image_specifics, | 1510 image_specifics, |
1517 base::Time(), | 1511 base::Time(), |
1518 syncer::AttachmentIdList(), | 1512 syncer::AttachmentIdList(), |
1519 syncer::AttachmentServiceProxyForTest::Create())); | 1513 syncer::AttachmentServiceProxyForTest::Create())); |
1520 FillTrackingSpecifics(BuildFaviconData(i), | 1514 FillTrackingSpecifics(BuildFaviconData(i), |
1521 tracking_specifics.mutable_favicon_tracking()); | 1515 tracking_specifics.mutable_favicon_tracking()); |
1522 initial_tracking_data.push_back(syncer::SyncData::CreateRemoteData( | 1516 initial_tracking_data.push_back(syncer::SyncData::CreateRemoteData( |
1523 1, | 1517 1, |
1524 tracking_specifics, | 1518 tracking_specifics, |
1525 base::Time(), | 1519 base::Time(), |
1526 syncer::AttachmentIdList(), | 1520 syncer::AttachmentIdList(), |
1527 syncer::AttachmentServiceProxyForTest::Create())); | 1521 syncer::AttachmentServiceProxyForTest::Create())); |
1528 } | 1522 } |
1529 | 1523 |
1530 SetUpInitialSync(initial_image_data, initial_tracking_data); | 1524 SetUpInitialSync(initial_image_data, initial_tracking_data); |
1531 syncer::SyncChangeList changes = processor()->GetAndResetChangeList(); | 1525 syncer::SyncChangeList changes = processor()->GetAndResetChangeList(); |
1532 EXPECT_TRUE(changes.empty()); | 1526 EXPECT_TRUE(changes.empty()); |
1533 | 1527 |
1534 EXPECT_EQ((unsigned long)kFaviconBatchSize, GetFaviconCount()); | 1528 EXPECT_EQ((unsigned long)kFaviconBatchSize, GetFaviconCount()); |
1535 content::NotificationService::current()->Notify( | 1529 cache()->OnURLsDeleted(nullptr, false, false, history::URLRows(), |
1536 chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 1530 favicon_urls); |
1537 content::Source<Profile>(NULL), | |
1538 content::Details<history::URLsDeletedDetails>(&deletions)); | |
1539 EXPECT_EQ((unsigned long)kFaviconBatchSize/2, GetFaviconCount()); | 1531 EXPECT_EQ((unsigned long)kFaviconBatchSize/2, GetFaviconCount()); |
1540 changes = processor()->GetAndResetChangeList(); | 1532 changes = processor()->GetAndResetChangeList(); |
1541 ASSERT_EQ(changes.size(), (unsigned long)kFaviconBatchSize); | 1533 ASSERT_EQ(changes.size(), (unsigned long)kFaviconBatchSize); |
1542 syncer::SyncChangeList changes_1, changes_2; | 1534 syncer::SyncChangeList changes_1, changes_2; |
1543 for (size_t i = 0; i < kFaviconBatchSize/2; ++i) { | 1535 for (size_t i = 0; i < kFaviconBatchSize/2; ++i) { |
1544 changes_1.push_back(changes[i]); | 1536 changes_1.push_back(changes[i]); |
1545 changes_2.push_back(changes[i + kFaviconBatchSize/2]); | 1537 changes_2.push_back(changes[i + kFaviconBatchSize/2]); |
1546 } | 1538 } |
1547 VerifyChanges(syncer::FAVICON_IMAGES, | 1539 VerifyChanges(syncer::FAVICON_IMAGES, |
1548 expected_deletions, | 1540 expected_deletions, |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1931 EXPECT_EQ(changes[4].change_type(), syncer::SyncChange::ACTION_ADD); | 1923 EXPECT_EQ(changes[4].change_type(), syncer::SyncChange::ACTION_ADD); |
1932 EXPECT_EQ(changes[4].sync_data().GetDataType(), syncer::FAVICON_TRACKING); | 1924 EXPECT_EQ(changes[4].sync_data().GetDataType(), syncer::FAVICON_TRACKING); |
1933 EXPECT_EQ(kMaxSyncFavicons, GetFaviconId(changes[4])); | 1925 EXPECT_EQ(kMaxSyncFavicons, GetFaviconId(changes[4])); |
1934 // Expire tracking for favicon[0]. | 1926 // Expire tracking for favicon[0]. |
1935 EXPECT_EQ(changes[5].change_type(), syncer::SyncChange::ACTION_DELETE); | 1927 EXPECT_EQ(changes[5].change_type(), syncer::SyncChange::ACTION_DELETE); |
1936 EXPECT_EQ(changes[5].sync_data().GetDataType(), syncer::FAVICON_TRACKING); | 1928 EXPECT_EQ(changes[5].sync_data().GetDataType(), syncer::FAVICON_TRACKING); |
1937 EXPECT_EQ(0, GetFaviconId(changes[5])); | 1929 EXPECT_EQ(0, GetFaviconId(changes[5])); |
1938 } | 1930 } |
1939 | 1931 |
1940 } // namespace browser_sync | 1932 } // namespace browser_sync |
OLD | NEW |