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); | |
sclittle
2015/08/14 19:10:59
Instead of ExpectTotalCount, could you use ExpectU
amohammadkhan
2015/08/17 17:56:16
Done.
| |
684 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Bytes", 0); | |
685 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Count", 1); | |
686 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Bytes", 63); | |
687 histogram_tester.ExpectTotalCount("DataUse.Sync.ProgressMarker.Bytes", 84); | |
688 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | |
689 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | |
690 A.PutIsUnsynced(true); | |
691 A.PutSpecifics(bookmark_data); | |
692 A.PutNonUniqueName("bookmark"); | |
693 } | |
694 | |
695 // Now sync without enabling bookmarks. | |
696 mock_server_->ExpectGetUpdatesRequestTypes( | |
697 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS))); | |
698 ResetSession(); | |
699 syncer_->NormalSyncShare( | |
700 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS)), | |
701 &nudge_tracker_, session_.get()); | |
702 | |
703 { | |
704 // Nothing should have been committed as bookmarks is throttled. | |
705 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Count", 0); | |
706 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Bytes", 0); | |
707 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Count", 1); | |
708 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Bytes", 63); | |
709 histogram_tester.ExpectTotalCount("DataUse.Sync.ProgressMarker.Bytes", 140); | |
710 } | |
711 | |
712 // Sync again with bookmarks enabled. | |
713 mock_server_->ExpectGetUpdatesRequestTypes(context_->GetEnabledTypes()); | |
714 EXPECT_TRUE(SyncShareNudge()); | |
715 { | |
716 // It should have been committed. | |
717 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Count", 1); | |
718 histogram_tester.ExpectTotalCount("DataUse.Sync.Upload.Bytes", 91); | |
719 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Count", 1); | |
720 histogram_tester.ExpectTotalCount("DataUse.Sync.Download.Bytes", 63); | |
721 histogram_tester.ExpectTotalCount("DataUse.Sync.ProgressMarker.Bytes", 224); | |
722 } | |
723 } | |
724 | |
669 // We use a macro so we can preserve the error location. | 725 // We use a macro so we can preserve the error location. |
670 #define VERIFY_ENTRY(id, is_unapplied, is_unsynced, prev_initialized, \ | 726 #define VERIFY_ENTRY(id, is_unapplied, is_unsynced, prev_initialized, \ |
671 parent_id, version, server_version, id_fac, rtrans) \ | 727 parent_id, version, server_version, id_fac, rtrans) \ |
672 do { \ | 728 do { \ |
673 Entry entryA(rtrans, syncable::GET_BY_ID, id_fac.FromNumber(id)); \ | 729 Entry entryA(rtrans, syncable::GET_BY_ID, id_fac.FromNumber(id)); \ |
674 ASSERT_TRUE(entryA.good()); \ | 730 ASSERT_TRUE(entryA.good()); \ |
675 /* We don't use EXPECT_EQ here because when the left side param is false, | 731 /* 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. */ \ | 732 gcc 4.6 warns about converting 'false' to pointer type for argument 1. */ \ |
677 EXPECT_TRUE(is_unsynced == entryA.GetIsUnsynced()); \ | 733 EXPECT_TRUE(is_unsynced == entryA.GetIsUnsynced()); \ |
678 EXPECT_TRUE(is_unapplied == entryA.GetIsUnappliedUpdate()); \ | 734 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); | 5543 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
5488 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 5544 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
5489 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 5545 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
5490 } else { | 5546 } else { |
5491 EXPECT_TRUE(final_monitor_records.empty()) | 5547 EXPECT_TRUE(final_monitor_records.empty()) |
5492 << "Should not restore records after successful bookmark commit."; | 5548 << "Should not restore records after successful bookmark commit."; |
5493 } | 5549 } |
5494 } | 5550 } |
5495 | 5551 |
5496 } // namespace syncer | 5552 } // namespace syncer |
OLD | NEW |