| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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/stringprintf.h" | |
| 6 #include "chrome/browser/sync/profile_sync_service_harness.h" | |
| 7 #include "chrome/test/live_sync/live_extensions_sync_test.h" | |
| 8 #include "chrome/test/live_sync/live_sync_timing_helper.h" | |
| 9 | |
| 10 // TODO(braffert): Replicate these tests for apps. | |
| 11 | |
| 12 static const int kNumExtensions = 150; | |
| 13 | |
| 14 // TODO(braffert): Consider the range / resolution of these test points. | |
| 15 static const int kNumBenchmarkPoints = 18; | |
| 16 static const int kBenchmarkPoints[] = {1, 10, 20, 30, 40, 50, 75, 100, 125, | |
| 17 150, 175, 200, 225, 250, 300, 350, 400, | |
| 18 500}; | |
| 19 | |
| 20 // TODO(braffert): Move this class into its own .h/.cc files. What should the | |
| 21 // class files be named as opposed to the file containing the tests themselves? | |
| 22 class PerformanceLiveExtensionsSyncTest | |
| 23 : public TwoClientLiveExtensionsSyncTest { | |
| 24 public: | |
| 25 PerformanceLiveExtensionsSyncTest() : extension_number_(0) {} | |
| 26 | |
| 27 // Adds |num_extensions| new unique extensions to |profile|. | |
| 28 void AddExtensions(int profile, int num_extensions); | |
| 29 | |
| 30 // Updates the enabled/disabled state for all extensions in |profile|. | |
| 31 void UpdateExtensions(int profile); | |
| 32 | |
| 33 // Uninstalls all currently installed extensions from |profile|. | |
| 34 void RemoveExtensions(int profile); | |
| 35 | |
| 36 // Uninstalls all extensions from all profiles. Called between benchmark | |
| 37 // iterations. | |
| 38 void Cleanup(); | |
| 39 | |
| 40 private: | |
| 41 int extension_number_; | |
| 42 DISALLOW_COPY_AND_ASSIGN(PerformanceLiveExtensionsSyncTest); | |
| 43 }; | |
| 44 | |
| 45 void PerformanceLiveExtensionsSyncTest::AddExtensions(int profile, | |
| 46 int num_extensions) { | |
| 47 for (int i = 0; i < num_extensions; ++i) { | |
| 48 InstallExtension(GetProfile(profile), extension_number_++); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 void PerformanceLiveExtensionsSyncTest::UpdateExtensions(int profile) { | |
| 53 std::vector<int> extensions = GetInstalledExtensions(GetProfile(profile)); | |
| 54 for (std::vector<int>::iterator it = extensions.begin(); | |
| 55 it != extensions.end(); ++it) { | |
| 56 if (IsExtensionEnabled(GetProfile(profile), *it)) { | |
| 57 DisableExtension(GetProfile(profile), *it); | |
| 58 } else { | |
| 59 EnableExtension(GetProfile(profile), *it); | |
| 60 } | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 void PerformanceLiveExtensionsSyncTest::RemoveExtensions(int profile) { | |
| 65 std::vector<int> extensions = GetInstalledExtensions(GetProfile(profile)); | |
| 66 for (std::vector<int>::iterator it = extensions.begin(); | |
| 67 it != extensions.end(); ++it) { | |
| 68 UninstallExtension(GetProfile(profile), *it); | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 void PerformanceLiveExtensionsSyncTest::Cleanup() { | |
| 73 for (int i = 0; i < num_clients(); ++i) { | |
| 74 RemoveExtensions(i); | |
| 75 } | |
| 76 ASSERT_TRUE(AwaitQuiescence()); | |
| 77 ASSERT_TRUE(AllProfilesHaveSameExtensions()); | |
| 78 } | |
| 79 | |
| 80 // TCM ID - 7563874. | |
| 81 IN_PROC_BROWSER_TEST_F(PerformanceLiveExtensionsSyncTest, Add) { | |
| 82 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 83 | |
| 84 AddExtensions(0, kNumExtensions); | |
| 85 base::TimeDelta dt = | |
| 86 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 87 InstallExtensionsPendingForSync(GetProfile(1)); | |
| 88 ASSERT_TRUE(AllProfilesHaveSameExtensions()); | |
| 89 | |
| 90 // TODO(braffert): Compare timings against some target value. | |
| 91 VLOG(0) << std::endl << "dt: " << dt.InSecondsF() << " s"; | |
| 92 } | |
| 93 | |
| 94 // TCM ID - 7655397. | |
| 95 IN_PROC_BROWSER_TEST_F(PerformanceLiveExtensionsSyncTest, Update) { | |
| 96 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 97 | |
| 98 AddExtensions(0, kNumExtensions); | |
| 99 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 100 InstallExtensionsPendingForSync(GetProfile(1)); | |
| 101 | |
| 102 UpdateExtensions(0); | |
| 103 base::TimeDelta dt = | |
| 104 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 105 ASSERT_TRUE(AllProfilesHaveSameExtensions()); | |
| 106 | |
| 107 // TODO(braffert): Compare timings against some target value. | |
| 108 VLOG(0) << std::endl << "dt: " << dt.InSecondsF() << " s"; | |
| 109 } | |
| 110 | |
| 111 // TCM ID - 7567721. | |
| 112 IN_PROC_BROWSER_TEST_F(PerformanceLiveExtensionsSyncTest, Delete) { | |
| 113 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 114 | |
| 115 AddExtensions(0, kNumExtensions); | |
| 116 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 117 InstallExtensionsPendingForSync(GetProfile(1)); | |
| 118 | |
| 119 RemoveExtensions(0); | |
| 120 base::TimeDelta dt = | |
| 121 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 122 ASSERT_TRUE(AllProfilesHaveSameExtensions()); | |
| 123 | |
| 124 // TODO(braffert): Compare timings against some target value. | |
| 125 VLOG(0) << std::endl << "dt: " << dt.InSecondsF() << " s"; | |
| 126 } | |
| 127 | |
| 128 IN_PROC_BROWSER_TEST_F(PerformanceLiveExtensionsSyncTest, DISABLED_Benchmark) { | |
| 129 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 130 | |
| 131 for (int i = 0; i < kNumBenchmarkPoints; ++i) { | |
| 132 int num_extensions = kBenchmarkPoints[i]; | |
| 133 AddExtensions(0, num_extensions); | |
| 134 base::TimeDelta dt_add = | |
| 135 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 136 InstallExtensionsPendingForSync(GetProfile(1)); | |
| 137 VLOG(0) << std::endl << "Add: " << num_extensions << " " | |
| 138 << dt_add.InSecondsF(); | |
| 139 | |
| 140 UpdateExtensions(0); | |
| 141 base::TimeDelta dt_update = | |
| 142 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 143 VLOG(0) << std::endl << "Update: " << num_extensions << " " | |
| 144 << dt_update.InSecondsF(); | |
| 145 | |
| 146 RemoveExtensions(0); | |
| 147 base::TimeDelta dt_delete = | |
| 148 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 149 VLOG(0) << std::endl << "Delete: " << num_extensions << " " | |
| 150 << dt_delete.InSecondsF(); | |
| 151 | |
| 152 Cleanup(); | |
| 153 } | |
| 154 } | |
| OLD | NEW |