passwords_sync_perf_test.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1// Copyright (c) 2012 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/strings/stringprintf.h"
6#include "base/strings/utf_string_conversions.h"
7#include "chrome/browser/sync/test/integration/passwords_helper.h"
8#include "chrome/browser/sync/test/integration/performance/sync_timing_helper.h"
9#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
10#include "chrome/browser/sync/test/integration/sync_test.h"
11#include "components/password_manager/core/browser/password_store.h"
12
13using passwords_helper::AddLogin;
14using passwords_helper::CreateTestPasswordForm;
15using passwords_helper::GetLogins;
16using passwords_helper::GetPasswordCount;
17using passwords_helper::GetPasswordStore;
18using passwords_helper::UpdateLogin;
19
20static const int kNumPasswords = 150;
21
22class PasswordsSyncPerfTest : public SyncTest {
23 public:
24  PasswordsSyncPerfTest() : SyncTest(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  autofill::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
46void PasswordsSyncPerfTest::AddLogins(int profile, int num_logins) {
47  for (int i = 0; i < num_logins; ++i) {
48    AddLogin(GetPasswordStore(profile), NextLogin());
49  }
50}
51
52void PasswordsSyncPerfTest::UpdateLogins(int profile) {
53  std::vector<autofill::PasswordForm> logins;
54  GetLogins(GetPasswordStore(profile), logins);
55  for (std::vector<autofill::PasswordForm>::iterator it = logins.begin();
56       it != logins.end(); ++it) {
57    (*it).password_value = base::ASCIIToUTF16(NextPassword());
58    UpdateLogin(GetPasswordStore(profile), (*it));
59  }
60}
61
62void PasswordsSyncPerfTest::RemoveLogins(int profile) {
63  passwords_helper::RemoveLogins(GetPasswordStore(profile));
64}
65
66autofill::PasswordForm PasswordsSyncPerfTest::NextLogin() {
67  return CreateTestPasswordForm(password_number_++);
68}
69
70std::string PasswordsSyncPerfTest::NextPassword() {
71  return base::StringPrintf("password%d", password_number_++);
72}
73
74// Flaky on Windows, see http://crbug.com/105999
75#if defined(OS_WIN)
76#define MAYBE_P0 DISABLED_P0
77#else
78#define MAYBE_P0 P0
79#endif
80
81IN_PROC_BROWSER_TEST_F(PasswordsSyncPerfTest, MAYBE_P0) {
82  ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
83
84  // TCM ID - 7367749.
85  AddLogins(0, kNumPasswords);
86  base::TimeDelta dt = SyncTimingHelper::TimeUntilQuiescence(clients());
87  ASSERT_EQ(kNumPasswords, GetPasswordCount(1));
88  SyncTimingHelper::PrintResult("passwords", "add_passwords", dt);
89
90  // TCM ID - 7365093.
91  UpdateLogins(0);
92  dt = SyncTimingHelper::TimeUntilQuiescence(clients());
93  ASSERT_EQ(kNumPasswords, GetPasswordCount(1));
94  SyncTimingHelper::PrintResult("passwords", "update_passwords", dt);
95
96  // TCM ID - 7557852
97  RemoveLogins(0);
98  dt = SyncTimingHelper::TimeUntilQuiescence(clients());
99  ASSERT_EQ(0, GetPasswordCount(1));
100  SyncTimingHelper::PrintResult("passwords", "delete_passwords", dt);
101}
102