| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 // Syncer unit tests. Unfortunately a lot of these tests | 5 // Syncer unit tests. Unfortunately a lot of these tests |
| 6 // are outdated and need to be reworked and updated. | 6 // are outdated and need to be reworked and updated. |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <list> | 10 #include <list> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
| 17 #include "base/callback.h" | 17 #include "base/callback.h" |
| 18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
| 19 #include "base/location.h" | 19 #include "base/location.h" |
| 20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
| 22 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/test/histogram_tester.h" |
| 23 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| 24 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 25 #include "sync/engine/backoff_delay_provider.h" | 26 #include "sync/engine/backoff_delay_provider.h" |
| 26 #include "sync/engine/get_commit_ids.h" | 27 #include "sync/engine/get_commit_ids.h" |
| 27 #include "sync/engine/net/server_connection_manager.h" | 28 #include "sync/engine/net/server_connection_manager.h" |
| 28 #include "sync/engine/sync_scheduler_impl.h" | 29 #include "sync/engine/sync_scheduler_impl.h" |
| 29 #include "sync/engine/syncer.h" | 30 #include "sync/engine/syncer.h" |
| 30 #include "sync/engine/syncer_proto_util.h" | 31 #include "sync/engine/syncer_proto_util.h" |
| 31 #include "sync/internal_api/public/base/cancelation_signal.h" | 32 #include "sync/internal_api/public/base/cancelation_signal.h" |
| 32 #include "sync/internal_api/public/base/model_type.h" | 33 #include "sync/internal_api/public/base/model_type.h" |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 EXPECT_TRUE(SyncShareNudge()); | 660 EXPECT_TRUE(SyncShareNudge()); |
| 660 { | 661 { |
| 661 // It should have been committed. | 662 // It should have been committed. |
| 662 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 663 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
| 663 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); | 664 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); |
| 664 ASSERT_TRUE(entryA.good()); | 665 ASSERT_TRUE(entryA.good()); |
| 665 EXPECT_FALSE(entryA.GetIsUnsynced()); | 666 EXPECT_FALSE(entryA.GetIsUnsynced()); |
| 666 } | 667 } |
| 667 } | 668 } |
| 668 | 669 |
| 670 // This test has three steps. In the first step, a BOOKMARK update is received. |
| 671 // In the next step, syncing BOOKMARKS is disabled, so no BOOKMARK is sent or |
| 672 // received. In the last step, a BOOKMARK update is committed. |
| 673 TEST_F(SyncerTest, DataUseHistogramsTest) { |
| 674 base::HistogramTester histogram_tester; |
| 675 sync_pb::EntitySpecifics bookmark_data; |
| 676 AddDefaultFieldValue(BOOKMARKS, &bookmark_data); |
| 677 |
| 678 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(), |
| 679 "-1"); |
| 680 int download_bytes_bookmark = 0; |
| 681 vector<unsigned int> progress_bookmark = {0, 0, 0}; |
| 682 vector<unsigned int> progress_all = {0, 0, 0}; |
| 683 vector<base::Bucket> samples; |
| 684 EXPECT_TRUE(SyncShareNudge()); |
| 685 { |
| 686 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Count", 0); |
| 687 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Bytes", 0); |
| 688 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Count", 1); |
| 689 histogram_tester.ExpectUniqueSample("DataUse.Sync.Download.Count", |
| 690 BOOKMARKS, 1); |
| 691 samples = histogram_tester.GetAllSamples("DataUse.Sync.Download.Bytes"); |
| 692 EXPECT_EQ(samples.size(), 1u); |
| 693 EXPECT_EQ(samples.at(0).min, BOOKMARKS); |
| 694 EXPECT_GE(samples.at(0).count, 0); |
| 695 download_bytes_bookmark = samples.at(0).count; |
| 696 |
| 697 samples = |
| 698 histogram_tester.GetAllSamples("DataUse.Sync.ProgressMarker.Bytes"); |
| 699 |
| 700 for (const base::Bucket& bucket : samples) { |
| 701 if (bucket.min == BOOKMARKS) |
| 702 progress_bookmark.at(0) += bucket.count; |
| 703 progress_all.at(0) += bucket.count; |
| 704 } |
| 705 EXPECT_GT(progress_bookmark.at(0), 0u); |
| 706 EXPECT_GT(progress_all.at(0), 0u); |
| 707 |
| 708 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 709 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
| 710 A.PutIsUnsynced(true); |
| 711 A.PutSpecifics(bookmark_data); |
| 712 A.PutNonUniqueName("bookmark"); |
| 713 } |
| 714 |
| 715 // Now sync without enabling bookmarks. |
| 716 mock_server_->ExpectGetUpdatesRequestTypes( |
| 717 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS))); |
| 718 ResetSession(); |
| 719 syncer_->NormalSyncShare( |
| 720 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS)), |
| 721 &nudge_tracker_, session_.get()); |
| 722 |
| 723 { |
| 724 // Nothing should have been committed as bookmarks is throttled. |
| 725 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Count", 0); |
| 726 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Bytes", 0); |
| 727 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Count", 1); |
| 728 histogram_tester.ExpectUniqueSample("DataUse.Sync.Download.Count", |
| 729 BOOKMARKS, 1); |
| 730 |
| 731 samples = histogram_tester.GetAllSamples("DataUse.Sync.Download.Bytes"); |
| 732 EXPECT_EQ(samples.size(), 1u); |
| 733 EXPECT_EQ(samples.at(0).min, BOOKMARKS); |
| 734 EXPECT_EQ(samples.at(0).count, download_bytes_bookmark); |
| 735 |
| 736 samples = |
| 737 histogram_tester.GetAllSamples("DataUse.Sync.ProgressMarker.Bytes"); |
| 738 for (const base::Bucket& bucket : samples) { |
| 739 if (bucket.min == BOOKMARKS) |
| 740 progress_bookmark.at(1) += bucket.count; |
| 741 progress_all.at(1) += bucket.count; |
| 742 } |
| 743 EXPECT_EQ(progress_bookmark.at(1), progress_bookmark.at(0)); |
| 744 EXPECT_GT(progress_all.at(1), progress_all.at(0)); |
| 745 } |
| 746 |
| 747 // Sync again with bookmarks enabled. |
| 748 mock_server_->ExpectGetUpdatesRequestTypes(context_->GetEnabledTypes()); |
| 749 EXPECT_TRUE(SyncShareNudge()); |
| 750 { |
| 751 // It should have been committed. |
| 752 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Count", 1); |
| 753 histogram_tester.ExpectUniqueSample("DataUse.Sync.Upload.Count", BOOKMARKS, |
| 754 1); |
| 755 samples = histogram_tester.GetAllSamples("DataUse.Sync.Upload.Bytes"); |
| 756 EXPECT_EQ(samples.size(), 1u); |
| 757 EXPECT_EQ(samples.at(0).min, BOOKMARKS); |
| 758 EXPECT_GE(samples.at(0).count, 0); |
| 759 |
| 760 samples = histogram_tester.GetAllSamples("DataUse.Sync.Download.Bytes"); |
| 761 EXPECT_EQ(samples.size(), 1u); |
| 762 EXPECT_EQ(samples.at(0).min, BOOKMARKS); |
| 763 EXPECT_EQ(samples.at(0).count, download_bytes_bookmark); |
| 764 |
| 765 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Count", 1); |
| 766 |
| 767 samples = |
| 768 histogram_tester.GetAllSamples("DataUse.Sync.ProgressMarker.Bytes"); |
| 769 for (const base::Bucket& bucket : samples) { |
| 770 if (bucket.min == BOOKMARKS) |
| 771 progress_bookmark.at(2) += bucket.count; |
| 772 progress_all.at(2) += bucket.count; |
| 773 } |
| 774 EXPECT_GT(progress_bookmark.at(2), progress_bookmark.at(1)); |
| 775 EXPECT_GT(progress_all.at(2), progress_all.at(1)); |
| 776 } |
| 777 } |
| 778 |
| 669 // We use a macro so we can preserve the error location. | 779 // We use a macro so we can preserve the error location. |
| 670 #define VERIFY_ENTRY(id, is_unapplied, is_unsynced, prev_initialized, \ | 780 #define VERIFY_ENTRY(id, is_unapplied, is_unsynced, prev_initialized, \ |
| 671 parent_id, version, server_version, id_fac, rtrans) \ | 781 parent_id, version, server_version, id_fac, rtrans) \ |
| 672 do { \ | 782 do { \ |
| 673 Entry entryA(rtrans, syncable::GET_BY_ID, id_fac.FromNumber(id)); \ | 783 Entry entryA(rtrans, syncable::GET_BY_ID, id_fac.FromNumber(id)); \ |
| 674 ASSERT_TRUE(entryA.good()); \ | 784 ASSERT_TRUE(entryA.good()); \ |
| 675 /* We don't use EXPECT_EQ here because when the left side param is false, | 785 /* We don't use EXPECT_EQ here because when the left side param is false, |
| 676 gcc 4.6 warns about converting 'false' to pointer type for argument 1. */ \ | 786 gcc 4.6 warns about converting 'false' to pointer type for argument 1. */ \ |
| 677 EXPECT_TRUE(is_unsynced == entryA.GetIsUnsynced()); \ | 787 EXPECT_TRUE(is_unsynced == entryA.GetIsUnsynced()); \ |
| 678 EXPECT_TRUE(is_unapplied == entryA.GetIsUnappliedUpdate()); \ | 788 EXPECT_TRUE(is_unapplied == entryA.GetIsUnappliedUpdate()); \ |
| (...skipping 4808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5487 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 5597 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
| 5488 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 5598 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
| 5489 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 5599 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
| 5490 } else { | 5600 } else { |
| 5491 EXPECT_TRUE(final_monitor_records.empty()) | 5601 EXPECT_TRUE(final_monitor_records.empty()) |
| 5492 << "Should not restore records after successful bookmark commit."; | 5602 << "Should not restore records after successful bookmark commit."; |
| 5493 } | 5603 } |
| 5494 } | 5604 } |
| 5495 | 5605 |
| 5496 } // namespace syncer | 5606 } // namespace syncer |
| OLD | NEW |