OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/debug/scoped_thread_heap_usage.h" |
| 6 #include "base/logging.h" |
| 7 #include "build/build_config.h" |
| 8 #include "components/sync/protocol/app_list_specifics.pb.h" |
| 9 #include "components/sync/protocol/app_notification_specifics.pb.h" |
| 10 #include "components/sync/protocol/app_setting_specifics.pb.h" |
| 11 #include "components/sync/protocol/app_specifics.pb.h" |
| 12 #include "components/sync/protocol/arc_package_specifics.pb.h" |
| 13 #include "components/sync/protocol/autofill_specifics.pb.h" |
| 14 #include "components/sync/protocol/bookmark_specifics.pb.h" |
| 15 #include "components/sync/protocol/dictionary_specifics.pb.h" |
| 16 #include "components/sync/protocol/encryption.pb.h" |
| 17 #include "components/sync/protocol/entity_metadata.pb.h" |
| 18 #include "components/sync/protocol/experiments_specifics.pb.h" |
| 19 #include "components/sync/protocol/extension_setting_specifics.pb.h" |
| 20 #include "components/sync/protocol/extension_specifics.pb.h" |
| 21 #include "components/sync/protocol/favicon_image_specifics.pb.h" |
| 22 #include "components/sync/protocol/favicon_tracking_specifics.pb.h" |
| 23 #include "components/sync/protocol/history_delete_directive_specifics.pb.h" |
| 24 #include "components/sync/protocol/nigori_specifics.pb.h" |
| 25 #include "components/sync/protocol/password_specifics.pb.h" |
| 26 #include "components/sync/protocol/preference_specifics.pb.h" |
| 27 #include "components/sync/protocol/printer_specifics.pb.h" |
| 28 #include "components/sync/protocol/priority_preference_specifics.pb.h" |
| 29 #include "components/sync/protocol/proto_enum_conversions.h" |
| 30 #include "components/sync/protocol/proto_size_estimations.h" |
| 31 #include "components/sync/protocol/proto_unittest_serialized_data.h" |
| 32 #include "components/sync/protocol/reading_list_specifics.pb.h" |
| 33 #include "components/sync/protocol/search_engine_specifics.pb.h" |
| 34 #include "components/sync/protocol/session_specifics.pb.h" |
| 35 #include "components/sync/protocol/sync.pb.h" |
| 36 #include "components/sync/protocol/theme_specifics.pb.h" |
| 37 #include "components/sync/protocol/typed_url_specifics.pb.h" |
| 38 #include "components/sync/protocol/unique_position.pb.h" |
| 39 #include "testing/gtest/include/gtest/gtest.h" |
| 40 |
| 41 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) |
| 42 |
| 43 namespace syncer { |
| 44 namespace { |
| 45 |
| 46 using base::debug::ScopedThreadHeapUsage; |
| 47 |
| 48 class TestingScopedThreadHeapUsage : public ScopedThreadHeapUsage { |
| 49 public: |
| 50 using ScopedThreadHeapUsage::DisableHeapTrackingForTesting; |
| 51 }; |
| 52 |
| 53 class ProtoSizeEstimationsTest : public testing::Test { |
| 54 public: |
| 55 void SetUp() override { |
| 56 TestingScopedThreadHeapUsage::Initialize(); |
| 57 TestingScopedThreadHeapUsage::EnableHeapTracking(); |
| 58 } |
| 59 void TearDown() override { |
| 60 TestingScopedThreadHeapUsage::DisableHeapTrackingForTesting(); |
| 61 } |
| 62 }; |
| 63 |
| 64 #define IMPLEMENT_TEST(Proto) \ |
| 65 TEST_F(ProtoSizeEstimationsTest, Proto) { \ |
| 66 sync_pb::Proto proto; \ |
| 67 const auto& serialized_data = SerializedProto<sync_pb::Proto>::data; \ |
| 68 \ |
| 69 base::debug::ScopedThreadHeapUsage scoped_heap_usage; \ |
| 70 auto usage_before = ScopedThreadHeapUsage::CurrentUsage(); \ |
| 71 EXPECT_TRUE(proto.ParseFromArray(serialized_data, sizeof(serialized_data)));
\ |
| 72 auto usage_after = ScopedThreadHeapUsage::CurrentUsage(); \ |
| 73 \ |
| 74 size_t memory_usage = \ |
| 75 (usage_after.alloc_bytes - usage_before.alloc_bytes) - \ |
| 76 (usage_after.free_bytes - usage_before.free_bytes); \ |
| 77 size_t estimated_memory_usage = sync_pb::EstimateMemoryUsage(proto); \ |
| 78 \ |
| 79 EXPECT_EQ(memory_usage, estimated_memory_usage); \ |
| 80 } |
| 81 |
| 82 IMPLEMENT_TEST(EncryptedData) |
| 83 IMPLEMENT_TEST(AppListSpecifics) |
| 84 IMPLEMENT_TEST(AppNotificationSettings) |
| 85 IMPLEMENT_TEST(LinkedAppIconInfo) |
| 86 IMPLEMENT_TEST(ArcPackageSpecifics) |
| 87 IMPLEMENT_TEST(SessionHeader) |
| 88 IMPLEMENT_TEST(SessionTab) |
| 89 IMPLEMENT_TEST(SessionWindow) |
| 90 IMPLEMENT_TEST(TabNavigation) |
| 91 IMPLEMENT_TEST(NavigationRedirect) |
| 92 IMPLEMENT_TEST(PasswordSpecificsData) |
| 93 IMPLEMENT_TEST(GlobalIdDirective) |
| 94 IMPLEMENT_TEST(TimeRangeDirective) |
| 95 IMPLEMENT_TEST(SessionSpecifics) |
| 96 IMPLEMENT_TEST(PrinterPPDData) |
| 97 IMPLEMENT_TEST(AppNotification) |
| 98 IMPLEMENT_TEST(AppSettingSpecifics) |
| 99 IMPLEMENT_TEST(AppSpecifics) |
| 100 IMPLEMENT_TEST(ArticleSpecifics) |
| 101 IMPLEMENT_TEST(AutofillSpecifics) |
| 102 IMPLEMENT_TEST(AutofillProfileSpecifics) |
| 103 IMPLEMENT_TEST(WalletMetadataSpecifics) |
| 104 IMPLEMENT_TEST(AutofillWalletSpecifics) |
| 105 IMPLEMENT_TEST(BookmarkSpecifics) |
| 106 IMPLEMENT_TEST(DeviceInfoSpecifics) |
| 107 IMPLEMENT_TEST(DictionarySpecifics) |
| 108 IMPLEMENT_TEST(ExperimentsSpecifics) |
| 109 IMPLEMENT_TEST(PriorityPreferenceSpecifics) |
| 110 IMPLEMENT_TEST(ExtensionSettingSpecifics) |
| 111 IMPLEMENT_TEST(ExtensionSpecifics) |
| 112 IMPLEMENT_TEST(FaviconImageSpecifics) |
| 113 IMPLEMENT_TEST(FaviconTrackingSpecifics) |
| 114 IMPLEMENT_TEST(HistoryDeleteDirectiveSpecifics) |
| 115 IMPLEMENT_TEST(ManagedUserSettingSpecifics) |
| 116 IMPLEMENT_TEST(ManagedUserSpecifics) |
| 117 IMPLEMENT_TEST(ManagedUserSharedSettingSpecifics) |
| 118 IMPLEMENT_TEST(ManagedUserWhitelistSpecifics) |
| 119 IMPLEMENT_TEST(NigoriSpecifics) |
| 120 IMPLEMENT_TEST(PasswordSpecifics) |
| 121 IMPLEMENT_TEST(PreferenceSpecifics) |
| 122 IMPLEMENT_TEST(PrinterSpecifics) |
| 123 IMPLEMENT_TEST(ReadingListSpecifics) |
| 124 IMPLEMENT_TEST(SyncedNotificationAppInfoSpecifics) |
| 125 IMPLEMENT_TEST(SyncedNotificationSpecifics) |
| 126 IMPLEMENT_TEST(SearchEngineSpecifics) |
| 127 IMPLEMENT_TEST(ThemeSpecifics) |
| 128 IMPLEMENT_TEST(TypedUrlSpecifics) |
| 129 IMPLEMENT_TEST(WalletMaskedCreditCard) |
| 130 IMPLEMENT_TEST(WalletPostalAddress) |
| 131 IMPLEMENT_TEST(WifiCredentialSpecifics) |
| 132 IMPLEMENT_TEST(EntitySpecifics) |
| 133 IMPLEMENT_TEST(SyncEntity) |
| 134 // IMPLEMENT_TEST(ClientToServerMessage) |
| 135 // IMPLEMENT_TEST(ClientToServerResponse) |
| 136 IMPLEMENT_TEST(DatatypeAssociationStats) |
| 137 IMPLEMENT_TEST(DebugEventInfo) |
| 138 IMPLEMENT_TEST(DebugInfo) |
| 139 IMPLEMENT_TEST(SyncCycleCompletedEventInfo) |
| 140 IMPLEMENT_TEST(ClientConfigParams) |
| 141 IMPLEMENT_TEST(AttachmentIdProto) |
| 142 IMPLEMENT_TEST(EntityMetadata) |
| 143 |
| 144 } // namespace |
| 145 } // namespace syncer |
| 146 |
| 147 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) |
OLD | NEW |