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 steps BOOKMARKS are sync and they are | |
Nicolas Zea
2015/08/18 21:55:18
nit: "BOOKMARKS are sync and they are downloaded"
amohammadkhan
2015/08/19 17:33:35
Done.
| |
671 // downloaded. In the next step, syncing BOOKMARKS is disabled, so no BOOKMARK | |
672 // is uploaded or downloaded. In the last step, BOOKMARKS are uploaded and | |
673 // committed to server. | |
674 TEST_F(SyncerTest, DataUseHistogramsTest) { | |
675 base::HistogramTester histogram_tester; | |
676 const ModelTypeSet throttled_types(BOOKMARKS); | |
Nicolas Zea
2015/08/18 21:55:18
throttled_types appears to be unused?
amohammadkhan
2015/08/19 17:33:36
Done.
| |
677 sync_pb::EntitySpecifics bookmark_data; | |
678 AddDefaultFieldValue(BOOKMARKS, &bookmark_data); | |
679 | |
680 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, | |
681 foreign_cache_guid(), "-1"); | |
682 EXPECT_TRUE(SyncShareNudge()); | |
683 { | |
684 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Count", 0); | |
685 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Bytes", 0); | |
686 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Count", 1); | |
687 histogram_tester.ExpectUniqueSample("DataUse.Sync.Download.Count", | |
688 BOOKMARKS, 1); | |
689 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Bytes", 63); | |
Nicolas Zea
2015/08/18 21:55:18
Where are these byte values from? It would be good
amohammadkhan
2015/08/19 17:33:35
I got those values by test and you are right, they
| |
690 histogram_tester.ExpectUniqueSample("DataUse.Sync.Download.Bytes", | |
691 BOOKMARKS, 63); | |
692 histogram_tester.ExpectBucketCount("DataUse.Sync.ProgressMarker.Bytes", | |
693 BOOKMARKS, 28); | |
694 histogram_tester.ExpectTotalCount("DataUse.Sync.ProgressMarker.Bytes", 84); | |
695 | |
696 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | |
697 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | |
698 A.PutIsUnsynced(true); | |
699 A.PutSpecifics(bookmark_data); | |
700 A.PutNonUniqueName("bookmark"); | |
701 } | |
702 | |
703 // Now sync without enabling bookmarks. | |
704 mock_server_->ExpectGetUpdatesRequestTypes( | |
705 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS))); | |
706 ResetSession(); | |
707 syncer_->NormalSyncShare( | |
708 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS)), | |
709 &nudge_tracker_, session_.get()); | |
710 | |
711 { | |
712 // Nothing should have been committed as bookmarks is throttled. | |
713 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Count", 0); | |
714 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Bytes", 0); | |
715 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Count", 1); | |
716 histogram_tester.ExpectUniqueSample("DataUse.Sync.Download.Count", | |
717 BOOKMARKS, 1); | |
718 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Bytes", 63); | |
719 histogram_tester.ExpectUniqueSample("DataUse.Sync.Download.Bytes", | |
720 BOOKMARKS, 63); | |
721 histogram_tester.ExpectBucketCount("DataUse.Sync.ProgressMarker.Bytes", | |
722 BOOKMARKS, 28); | |
723 histogram_tester.ExpectTotalCount("DataUse.Sync.ProgressMarker.Bytes", 140); | |
724 | |
725 } | |
726 | |
727 // Sync again with bookmarks enabled. | |
728 mock_server_->ExpectGetUpdatesRequestTypes(context_->GetEnabledTypes()); | |
729 EXPECT_TRUE(SyncShareNudge()); | |
730 { | |
731 // It should have been committed. | |
732 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Count", 1); | |
733 histogram_tester.ExpectUniqueSample("DataUse.Sync.Upload.Count", | |
734 BOOKMARKS, 1); | |
735 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Bytes", 91); | |
736 histogram_tester.ExpectUniqueSample("DataUse.Sync.Upload.Bytes", | |
737 BOOKMARKS, 91); | |
738 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Count", 1); | |
739 histogram_tester.ExpectUniqueSample("DataUse.Sync.Download.Count", | |
740 BOOKMARKS, 1); | |
741 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Bytes", 63); | |
742 histogram_tester.ExpectUniqueSample("DataUse.Sync.Download.Bytes", | |
743 BOOKMARKS, 63); | |
744 histogram_tester.ExpectBucketCount("DataUse.Sync.ProgressMarker.Bytes", | |
745 BOOKMARKS, 56); | |
746 histogram_tester.ExpectTotalCount("DataUse.Sync.ProgressMarker.Bytes", 224); | |
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 |