File: manage_passwords_test.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (129 lines) | stat: -rw-r--r-- 5,258 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_TEST_H_
#define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_TEST_H_

#include <memory>
#include <vector>

#include "base/metrics/histogram_samples.h"
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/optimization_guide/mock_optimization_guide_keyed_service.h"
#include "chrome/test/interaction/interactive_browser_test.h"
#include "components/affiliations/core/browser/mock_affiliation_service.h"
#include "components/autofill/core/common/form_data.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/password_manager/core/browser/fake_form_fetcher.h"
#include "components/password_manager/core/browser/password_form.h"
#include "components/password_manager/core/browser/stub_password_manager_client.h"
#include "components/password_manager/core/browser/stub_password_manager_driver.h"
#include "components/password_manager/core/common/credential_manager_types.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"

class ManagePasswordsUIController;

enum class SyncConfiguration {
  // There is no sync consent and no sync types are synced.
  kNotSyncing = 0,
  // There is sync consent.
  kSyncing = 1,
  // There is no sync consent, but passwords are saved in the account storage.
  kAccountStorageOnly = 2,
  kMaxValue = kAccountStorageOnly,
};

// Test class for the various password management view bits and pieces. Provides
// some helper methods to poke at the bubble, icon, and controller's state.
class ManagePasswordsTest : public InteractiveBrowserTest {
 public:
  ManagePasswordsTest();

  ManagePasswordsTest(const ManagePasswordsTest&) = delete;
  ManagePasswordsTest& operator=(const ManagePasswordsTest&) = delete;

  ~ManagePasswordsTest() override;

  // InteractiveBrowserTest:
  void SetUpOnMainThread() override;
  void TearDownOnMainThread() override;
  void SetUpInProcessBrowserTestFixture() override;

  // Execute the browser command to open the manage passwords bubble.
  void ExecuteManagePasswordsCommand();

  // Put the controller, icon, and bubble into a managing-password state.
  // TODO(crbug.com/41491760): Make password form url stable without having to
  // override it.
  void SetupManagingPasswords(const GURL& password_form_url = GURL());

  // Put the controller, icon, and bubble into password_change state.
  void SetupPasswordChange();

  // Put the controller, icon, and bubble into the confirmation state.
  void SetupAutomaticPassword();

  // Put the controller, icon, and bubble into a pending-password state.
  void SetupPendingPassword();

  // Put the controller, icon, and bubble into an auto sign-in state.
  void SetupAutoSignin(
      std::vector<std::unique_ptr<password_manager::PasswordForm>>
          local_credentials);

  // Put the controller, icon, and bubble into the state with 0 compromised
  // passwords saved.
  void SetupSafeState();

  // Put the controller, icon, and bubble into the "More problems to fix" state.
  void SetupMoreToFixState();

  // Put the controller, icon, and bubble into a moving-password state.
  void SetupMovingPasswords();

  // Always configures a signed-in user, and when |is_enabled| is true, it also
  // configures the Sync service to sync passwords. |is_account_storage_enabled|
  // enables account storage for the user.
  void ConfigurePasswordSync(SyncConfiguration configuration);

  // Get samples for |histogram|.
  std::unique_ptr<base::HistogramSamples> GetSamples(const char* histogram);

  password_manager::PasswordForm* test_form() { return &password_form_; }

  // Get the UI controller for the current WebContents.
  ManagePasswordsUIController* GetController();

 protected:
  // Creates a form manager using the given password password stores.
  // If |profile_store| is nullptr, password_manager::StubFormSaver is used for
  // the profile store. If |account_store| is nullptr, a nullptr
  // password_manager::FormSaver is used for the account store.
  std::unique_ptr<password_manager::PasswordFormManager> CreateFormManager(
      password_manager::PasswordStoreInterface* profile_store = nullptr,
      password_manager::PasswordStoreInterface* account_store = nullptr);

  auto CheckHistogramUniqueSample(const std::string& name,
                                  int sample,
                                  int expected_count) {
    return Do([=, this]() {
      histogram_tester_.ExpectUniqueSample(name, sample, expected_count);
    });
  }

 private:
  password_manager::PasswordForm password_form_;
  password_manager::PasswordForm insecure_credential_;
  base::HistogramTester histogram_tester_;
  password_manager::StubPasswordManagerClient client_;
  password_manager::StubPasswordManagerDriver driver_;
  password_manager::FakeFormFetcher fetcher_;
  std::unique_ptr<testing::NiceMock<MockOptimizationGuideKeyedService>>
      mock_optimization_service_;

  base::CallbackListSubscription create_services_subscription_;
};

#endif  // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_TEST_H_