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 "base/utf_string_conversions.h" | |
7 #include "chrome/browser/password_manager/password_store.h" | |
8 #include "chrome/browser/sync/profile_sync_service_harness.h" | |
9 #include "chrome/test/live_sync/live_sync_test.h" | |
10 #include "chrome/test/live_sync/passwords_helper.h" | |
11 #include "chrome/test/live_sync/performance/sync_timing_helper.h" | |
12 | |
13 using passwords_helper::AddLogin; | |
14 using passwords_helper::CreateTestPasswordForm; | |
15 using passwords_helper::GetLogins; | |
16 using passwords_helper::GetPasswordCount; | |
17 using passwords_helper::GetPasswordStore; | |
18 using passwords_helper::UpdateLogin; | |
19 | |
20 static const int kNumPasswords = 150; | |
21 | |
22 class PasswordsSyncPerfTest : public LiveSyncTest { | |
23 public: | |
24 PasswordsSyncPerfTest() : LiveSyncTest(TWO_CLIENT), 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 private: | |
36 // Returns a new unique login. | |
37 webkit_glue::PasswordForm NextLogin(); | |
38 | |
39 // Returns a new unique password value. | |
40 std::string NextPassword(); | |
41 | |
42 int password_number_; | |
43 DISALLOW_COPY_AND_ASSIGN(PasswordsSyncPerfTest); | |
44 }; | |
45 | |
46 void PasswordsSyncPerfTest::AddLogins(int profile, int num_logins) { | |
47 for (int i = 0; i < num_logins; ++i) { | |
48 AddLogin(GetPasswordStore(profile), NextLogin()); | |
49 } | |
50 } | |
51 | |
52 void PasswordsSyncPerfTest::UpdateLogins(int profile) { | |
53 std::vector<webkit_glue::PasswordForm> logins; | |
54 GetLogins(GetPasswordStore(profile), logins); | |
55 for (std::vector<webkit_glue::PasswordForm>::iterator it = logins.begin(); | |
56 it != logins.end(); ++it) { | |
57 (*it).password_value = ASCIIToUTF16(NextPassword()); | |
58 UpdateLogin(GetPasswordStore(profile), (*it)); | |
59 } | |
60 } | |
61 | |
62 void PasswordsSyncPerfTest::RemoveLogins(int profile) { | |
63 passwords_helper::RemoveLogins(GetPasswordStore(profile)); | |
64 } | |
65 | |
66 webkit_glue::PasswordForm PasswordsSyncPerfTest::NextLogin() { | |
67 return CreateTestPasswordForm(password_number_++); | |
68 } | |
69 | |
70 std::string PasswordsSyncPerfTest::NextPassword() { | |
71 return base::StringPrintf("password%d", password_number_++); | |
72 } | |
73 | |
74 IN_PROC_BROWSER_TEST_F(PasswordsSyncPerfTest, P0) { | |
75 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
76 | |
77 // TCM ID - 7367749. | |
78 AddLogins(0, kNumPasswords); | |
79 base::TimeDelta dt = | |
80 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
81 ASSERT_EQ(kNumPasswords, GetPasswordCount(1)); | |
82 SyncTimingHelper::PrintResult("passwords", "add_passwords", dt); | |
83 | |
84 // TCM ID - 7365093. | |
85 UpdateLogins(0); | |
86 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
87 ASSERT_EQ(kNumPasswords, GetPasswordCount(1)); | |
88 SyncTimingHelper::PrintResult("passwords", "update_passwords", dt); | |
89 | |
90 // TCM ID - 7557852 | |
91 RemoveLogins(0); | |
92 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
93 ASSERT_EQ(0, GetPasswordCount(1)); | |
94 SyncTimingHelper::PrintResult("passwords", "delete_passwords", dt); | |
95 } | |
OLD | NEW |