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 is based on SyncerTest.GetCommitIdsFiltersThrottledEntries. After |
| 671 // different steps in that test, the progress is verified against expected |
| 672 // progress. |
| 673 TEST_F(SyncerTest, DataUseHistogramsTest) { |
| 674 base::HistogramTester histogram_tester; |
| 675 const ModelTypeSet throttled_types(BOOKMARKS); |
| 676 sync_pb::EntitySpecifics bookmark_data; |
| 677 AddDefaultFieldValue(BOOKMARKS, &bookmark_data); |
| 678 |
| 679 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, |
| 680 foreign_cache_guid(), "-1"); |
| 681 EXPECT_TRUE(SyncShareNudge()); |
| 682 { |
| 683 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Count", 0); |
| 684 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Bytes", 0); |
| 685 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Count", 1); |
| 686 histogram_tester.ExpectUniqueSample("DataUse.Sync.Download.Count", |
| 687 BOOKMARKS, 1); |
| 688 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Bytes", 63); |
| 689 histogram_tester.ExpectUniqueSample("DataUse.Sync.Download.Bytes", |
| 690 BOOKMARKS, 63); |
| 691 histogram_tester.ExpectBucketCount("DataUse.Sync.ProgressMarker.Bytes", |
| 692 BOOKMARKS, 28); |
| 693 histogram_tester.ExpectTotalCount("DataUse.Sync.ProgressMarker.Bytes", 84); |
| 694 |
| 695 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 696 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
| 697 A.PutIsUnsynced(true); |
| 698 A.PutSpecifics(bookmark_data); |
| 699 A.PutNonUniqueName("bookmark"); |
| 700 } |
| 701 |
| 702 // Now sync without enabling bookmarks. |
| 703 mock_server_->ExpectGetUpdatesRequestTypes( |
| 704 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS))); |
| 705 ResetSession(); |
| 706 syncer_->NormalSyncShare( |
| 707 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS)), |
| 708 &nudge_tracker_, session_.get()); |
| 709 |
| 710 { |
| 711 // Nothing should have been committed as bookmarks is throttled. |
| 712 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Count", 0); |
| 713 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Bytes", 0); |
| 714 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Count", 1); |
| 715 histogram_tester.ExpectUniqueSample("DataUse.Sync.Download.Count", |
| 716 BOOKMARKS, 1); |
| 717 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Bytes", 63); |
| 718 histogram_tester.ExpectUniqueSample("DataUse.Sync.Download.Bytes", |
| 719 BOOKMARKS, 63); |
| 720 histogram_tester.ExpectBucketCount("DataUse.Sync.ProgressMarker.Bytes", |
| 721 BOOKMARKS, 28); |
| 722 histogram_tester.ExpectTotalCount("DataUse.Sync.ProgressMarker.Bytes", 140); |
| 723 |
| 724 } |
| 725 |
| 726 // Sync again with bookmarks enabled. |
| 727 mock_server_->ExpectGetUpdatesRequestTypes(context_->GetEnabledTypes()); |
| 728 EXPECT_TRUE(SyncShareNudge()); |
| 729 { |
| 730 // It should have been committed. |
| 731 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Count", 1); |
| 732 histogram_tester.ExpectUniqueSample("DataUse.Sync.Upload.Count", |
| 733 BOOKMARKS, 1); |
| 734 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Bytes", 91); |
| 735 histogram_tester.ExpectUniqueSample("DataUse.Sync.Upload.Bytes", |
| 736 BOOKMARKS, 91); |
| 737 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Count", 1); |
| 738 histogram_tester.ExpectUniqueSample("DataUse.Sync.Download.Count", |
| 739 BOOKMARKS, 1); |
| 740 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Bytes", 63); |
| 741 histogram_tester.ExpectUniqueSample("DataUse.Sync.Download.Bytes", |
| 742 BOOKMARKS, 63); |
| 743 histogram_tester.ExpectBucketCount("DataUse.Sync.ProgressMarker.Bytes", |
| 744 BOOKMARKS, 56); |
| 745 histogram_tester.ExpectTotalCount("DataUse.Sync.ProgressMarker.Bytes", 224); |
| 746 |
| 747 } |
| 748 } |
| 749 |
669 // We use a macro so we can preserve the error location. | 750 // We use a macro so we can preserve the error location. |
670 #define VERIFY_ENTRY(id, is_unapplied, is_unsynced, prev_initialized, \ | 751 #define VERIFY_ENTRY(id, is_unapplied, is_unsynced, prev_initialized, \ |
671 parent_id, version, server_version, id_fac, rtrans) \ | 752 parent_id, version, server_version, id_fac, rtrans) \ |
672 do { \ | 753 do { \ |
673 Entry entryA(rtrans, syncable::GET_BY_ID, id_fac.FromNumber(id)); \ | 754 Entry entryA(rtrans, syncable::GET_BY_ID, id_fac.FromNumber(id)); \ |
674 ASSERT_TRUE(entryA.good()); \ | 755 ASSERT_TRUE(entryA.good()); \ |
675 /* We don't use EXPECT_EQ here because when the left side param is false, | 756 /* 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. */ \ | 757 gcc 4.6 warns about converting 'false' to pointer type for argument 1. */ \ |
677 EXPECT_TRUE(is_unsynced == entryA.GetIsUnsynced()); \ | 758 EXPECT_TRUE(is_unsynced == entryA.GetIsUnsynced()); \ |
678 EXPECT_TRUE(is_unapplied == entryA.GetIsUnappliedUpdate()); \ | 759 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); | 5568 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
5488 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 5569 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
5489 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 5570 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
5490 } else { | 5571 } else { |
5491 EXPECT_TRUE(final_monitor_records.empty()) | 5572 EXPECT_TRUE(final_monitor_records.empty()) |
5492 << "Should not restore records after successful bookmark commit."; | 5573 << "Should not restore records after successful bookmark commit."; |
5493 } | 5574 } |
5494 } | 5575 } |
5495 | 5576 |
5496 } // namespace syncer | 5577 } // namespace syncer |
OLD | NEW |