| 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/password_manager/password_store.h" | |
| 7 #include "chrome/browser/sync/profile_sync_service_harness.h" | |
| 8 #include "chrome/test/live_sync/live_passwords_sync_test.h" | |
| 9 #include "chrome/test/live_sync/live_sync_timing_helper.h" | |
| 10 | |
| 11 static const int kNumPasswords = 150; | |
| 12 | |
| 13 // TODO(braffert): Consider the range / resolution of these test points. | |
| 14 static const int kNumBenchmarkPoints = 18; | |
| 15 static const int kBenchmarkPoints[] = {1, 10, 20, 30, 40, 50, 75, 100, 125, | |
| 16 150, 175, 200, 225, 250, 300, 350, 400, | |
| 17 500}; | |
| 18 | |
| 19 // TODO(braffert): Move this class into its own .h/.cc files. What should the | |
| 20 // class files be named as opposed to the file containing the tests themselves? | |
| 21 class PerformanceLivePasswordsSyncTest | |
| 22 : public TwoClientLivePasswordsSyncTest { | |
| 23 public: | |
| 24 PerformanceLivePasswordsSyncTest() : password_number_(0) {} | |
| 25 | |
| 26 // Adds |num_logins| new unique passwords to |profile|. | |
| 27 void AddLogins(int profile, int num_logins); | |
| 28 | |
| 29 // Updates the password for all logins for |profile|. | |
| 30 void UpdateLogins(int profile); | |
| 31 | |
| 32 // Removes all logins for |profile|. | |
| 33 void RemoveLogins(int profile); | |
| 34 | |
| 35 // Removes all logins for all profiles. Called between benchmark iterations. | |
| 36 void Cleanup(); | |
| 37 | |
| 38 private: | |
| 39 // Returns a new unique login. | |
| 40 webkit_glue::PasswordForm NextLogin(); | |
| 41 | |
| 42 // Returns a new unique password value. | |
| 43 std::string NextPassword(); | |
| 44 | |
| 45 int password_number_; | |
| 46 DISALLOW_COPY_AND_ASSIGN(PerformanceLivePasswordsSyncTest); | |
| 47 }; | |
| 48 | |
| 49 void PerformanceLivePasswordsSyncTest::AddLogins(int profile, int num_logins) { | |
| 50 for (int i = 0; i < num_logins; ++i) { | |
| 51 AddLogin(GetPasswordStore(profile), NextLogin()); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 void PerformanceLivePasswordsSyncTest::UpdateLogins(int profile) { | |
| 56 std::vector<webkit_glue::PasswordForm> logins; | |
| 57 GetLogins(GetPasswordStore(profile), logins); | |
| 58 for (std::vector<webkit_glue::PasswordForm>::iterator it = logins.begin(); | |
| 59 it != logins.end(); ++it) { | |
| 60 (*it).password_value = ASCIIToUTF16(NextPassword()); | |
| 61 UpdateLogin(GetPasswordStore(profile), (*it)); | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 void PerformanceLivePasswordsSyncTest::RemoveLogins(int profile) { | |
| 66 LivePasswordsSyncTest::RemoveLogins(GetPasswordStore(profile)); | |
| 67 } | |
| 68 | |
| 69 void PerformanceLivePasswordsSyncTest::Cleanup() { | |
| 70 for (int i = 0; i < num_clients(); ++i) { | |
| 71 RemoveLogins(i); | |
| 72 } | |
| 73 ASSERT_TRUE(AwaitQuiescence()); | |
| 74 ASSERT_EQ(0, GetPasswordCount(0)); | |
| 75 ASSERT_TRUE(AllProfilesContainSamePasswordForms()); | |
| 76 } | |
| 77 | |
| 78 webkit_glue::PasswordForm PerformanceLivePasswordsSyncTest::NextLogin() { | |
| 79 return CreateTestPasswordForm(password_number_++); | |
| 80 } | |
| 81 | |
| 82 std::string PerformanceLivePasswordsSyncTest::NextPassword() { | |
| 83 return base::StringPrintf("password%d", password_number_++); | |
| 84 } | |
| 85 | |
| 86 // TCM ID - 7567749. | |
| 87 IN_PROC_BROWSER_TEST_F(PerformanceLivePasswordsSyncTest, Add) { | |
| 88 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 89 | |
| 90 AddLogins(0, kNumPasswords); | |
| 91 base::TimeDelta dt = | |
| 92 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 93 ASSERT_EQ(kNumPasswords, GetPasswordCount(0)); | |
| 94 ASSERT_TRUE(AllProfilesContainSamePasswordForms()); | |
| 95 | |
| 96 // TODO(braffert): Compare timings against some target value. | |
| 97 VLOG(0) << std::endl << "dt: " << dt.InSecondsF() << " s"; | |
| 98 } | |
| 99 | |
| 100 // TCM ID - 7365093. | |
| 101 IN_PROC_BROWSER_TEST_F(PerformanceLivePasswordsSyncTest, Update) { | |
| 102 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 103 | |
| 104 AddLogins(0, kNumPasswords); | |
| 105 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 106 | |
| 107 UpdateLogins(0); | |
| 108 base::TimeDelta dt = | |
| 109 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 110 ASSERT_EQ(kNumPasswords, GetPasswordCount(0)); | |
| 111 ASSERT_TRUE(AllProfilesContainSamePasswordForms()); | |
| 112 | |
| 113 // TODO(braffert): Compare timings against some target value. | |
| 114 VLOG(0) << std::endl << "dt: " << dt.InSecondsF() << " s"; | |
| 115 } | |
| 116 | |
| 117 // TCM ID - 7557852. | |
| 118 IN_PROC_BROWSER_TEST_F(PerformanceLivePasswordsSyncTest, Delete) { | |
| 119 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 120 | |
| 121 AddLogins(0, kNumPasswords); | |
| 122 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
| 123 | |
| 124 RemoveLogins(0); | |
| 125 base::TimeDelta dt = | |
| 126 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 127 ASSERT_EQ(0, GetPasswordCount(0)); | |
| 128 ASSERT_TRUE(AllProfilesContainSamePasswordForms()); | |
| 129 | |
| 130 // TODO(braffert): Compare timings against some target value. | |
| 131 VLOG(0) << std::endl << "dt: " << dt.InSecondsF() << " s"; | |
| 132 } | |
| 133 | |
| 134 IN_PROC_BROWSER_TEST_F(PerformanceLivePasswordsSyncTest, DISABLED_Benchmark) { | |
| 135 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
| 136 | |
| 137 for (int i = 0; i < kNumBenchmarkPoints; ++i) { | |
| 138 int num_passwords = kBenchmarkPoints[i]; | |
| 139 AddLogins(0, num_passwords); | |
| 140 base::TimeDelta dt_add = | |
| 141 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 142 ASSERT_EQ(num_passwords, GetPasswordCount(0)); | |
| 143 ASSERT_TRUE(AllProfilesContainSamePasswordForms()); | |
| 144 VLOG(0) << std::endl << "Add: " << num_passwords << " " | |
| 145 << dt_add.InSecondsF(); | |
| 146 | |
| 147 UpdateLogins(0); | |
| 148 base::TimeDelta dt_update = | |
| 149 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 150 ASSERT_EQ(num_passwords, GetPasswordCount(0)); | |
| 151 ASSERT_TRUE(AllProfilesContainSamePasswordForms()); | |
| 152 VLOG(0) << std::endl << "Update: " << num_passwords << " " | |
| 153 << dt_update.InSecondsF(); | |
| 154 | |
| 155 RemoveLogins(0); | |
| 156 base::TimeDelta dt_delete = | |
| 157 LiveSyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
| 158 ASSERT_EQ(0, GetPasswordCount(0)); | |
| 159 ASSERT_TRUE(AllProfilesContainSamePasswordForms()); | |
| 160 VLOG(0) << std::endl << "Delete: " << num_passwords << " " | |
| 161 << dt_delete.InSecondsF(); | |
| 162 | |
| 163 Cleanup(); | |
| 164 } | |
| 165 } | |
| OLD | NEW |