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