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.h" | 7 #include "base/message_loop.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "chrome/browser/history/history_notifications.h" | 9 #include "chrome/browser/history/history_notifications.h" |
10 #include "chrome/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.h" |
(...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1475 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); | 1475 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
1476 EXPECT_EQ(test_data.icon_url.spec(), | 1476 EXPECT_EQ(test_data.icon_url.spec(), |
1477 changes[0].sync_data().GetSpecifics().favicon_tracking(). | 1477 changes[0].sync_data().GetSpecifics().favicon_tracking(). |
1478 favicon_url()); | 1478 favicon_url()); |
1479 EXPECT_NE(changes[0].sync_data().GetSpecifics().favicon_tracking(). | 1479 EXPECT_NE(changes[0].sync_data().GetSpecifics().favicon_tracking(). |
1480 last_visit_time_ms(), 0); | 1480 last_visit_time_ms(), 0); |
1481 } | 1481 } |
1482 EXPECT_EQ(0U, GetTaskCount()); | 1482 EXPECT_EQ(0U, GetTaskCount()); |
1483 } | 1483 } |
1484 | 1484 |
| 1485 // If we wind up with orphan image/tracking nodes, then receive an update |
| 1486 // for those favicons, we should lazily create the missing nodes. |
| 1487 TEST_F(SyncFaviconCacheTest, UpdatedOrphans) { |
| 1488 EXPECT_EQ(0U, GetFaviconCount()); |
| 1489 SetUpInitialSync(syncer::SyncDataList(), syncer::SyncDataList()); |
| 1490 |
| 1491 syncer::SyncChangeList initial_image_changes; |
| 1492 syncer::SyncChangeList initial_tracking_changes; |
| 1493 for (int i = 0; i < kFaviconBatchSize; ++i) { |
| 1494 TestFaviconData test_data = BuildFaviconData(i); |
| 1495 // Even favicons have image data but no tracking data. Odd favicons have |
| 1496 // tracking data but no image data. |
| 1497 if (i % 2 == 0) { |
| 1498 sync_pb::EntitySpecifics image_specifics; |
| 1499 FillImageSpecifics(BuildFaviconData(i), |
| 1500 image_specifics.mutable_favicon_image()); |
| 1501 initial_image_changes.push_back( |
| 1502 syncer::SyncChange(FROM_HERE, |
| 1503 syncer::SyncChange::ACTION_ADD, |
| 1504 syncer::SyncData::CreateRemoteData( |
| 1505 1, image_specifics))); |
| 1506 } else { |
| 1507 sync_pb::EntitySpecifics tracking_specifics; |
| 1508 FillTrackingSpecifics(BuildFaviconData(i), |
| 1509 tracking_specifics.mutable_favicon_tracking()); |
| 1510 initial_tracking_changes.push_back( |
| 1511 syncer::SyncChange(FROM_HERE, |
| 1512 syncer::SyncChange::ACTION_ADD, |
| 1513 syncer::SyncData::CreateRemoteData( |
| 1514 1, tracking_specifics))); |
| 1515 } |
| 1516 } |
| 1517 |
| 1518 cache()->ProcessSyncChanges(FROM_HERE, initial_image_changes); |
| 1519 cache()->ProcessSyncChanges(FROM_HERE, initial_tracking_changes); |
| 1520 EXPECT_EQ(0U, processor()->GetAndResetChangeList().size()); |
| 1521 EXPECT_EQ((unsigned long)kFaviconBatchSize, GetFaviconCount()); |
| 1522 |
| 1523 for (int i = 0; i < kFaviconBatchSize/2; ++i) { |
| 1524 TestFaviconData test_data = BuildFaviconData(i); |
| 1525 cache()->OnFaviconVisited(test_data.page_url, GURL()); |
| 1526 EXPECT_EQ(1U, GetTaskCount()); |
| 1527 OnCustomFaviconDataAvailable(test_data); |
| 1528 syncer::SyncChangeList changes = processor()->GetAndResetChangeList(); |
| 1529 |
| 1530 // Even favicons had image data, so should now receive new tracking data |
| 1531 // and updated image data (we allow one update after the initial add). |
| 1532 // Odd favicons had tracking so should now receive new image data and |
| 1533 // updated tracking data. |
| 1534 if (i % 2 == 0) { |
| 1535 ASSERT_EQ(2U, changes.size()); |
| 1536 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[0].change_type()); |
| 1537 EXPECT_TRUE( |
| 1538 CompareFaviconDataToSpecifics(test_data, |
| 1539 changes[0].sync_data().GetSpecifics())); |
| 1540 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, changes[1].change_type()); |
| 1541 EXPECT_EQ(test_data.icon_url.spec(), |
| 1542 changes[1].sync_data().GetSpecifics().favicon_tracking(). |
| 1543 favicon_url()); |
| 1544 EXPECT_NE(changes[1].sync_data().GetSpecifics().favicon_tracking(). |
| 1545 last_visit_time_ms(), 0); |
| 1546 } else { |
| 1547 ASSERT_EQ(2U, changes.size()); |
| 1548 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, changes[0].change_type()); |
| 1549 EXPECT_TRUE( |
| 1550 CompareFaviconDataToSpecifics(test_data, |
| 1551 changes[0].sync_data().GetSpecifics())); |
| 1552 EXPECT_EQ(syncer::SyncChange::ACTION_UPDATE, changes[1].change_type()); |
| 1553 EXPECT_EQ(test_data.icon_url.spec(), |
| 1554 changes[1].sync_data().GetSpecifics().favicon_tracking(). |
| 1555 favicon_url()); |
| 1556 EXPECT_NE(changes[1].sync_data().GetSpecifics().favicon_tracking(). |
| 1557 last_visit_time_ms(), 0); |
| 1558 } |
| 1559 } |
| 1560 |
| 1561 EXPECT_EQ(0U, GetTaskCount()); |
| 1562 EXPECT_EQ((unsigned long)kFaviconBatchSize, GetFaviconCount()); |
| 1563 } |
| 1564 |
1485 } // namespace browser_sync | 1565 } // namespace browser_sync |
OLD | NEW |