-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
autofill_snackbar_controller_impl_unittest.cc
103 lines (87 loc) · 4.2 KB
/
autofill_snackbar_controller_impl_unittest.cc
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
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/autofill/payments/autofill_snackbar_controller_impl.h"
#include "base/memory/raw_ptr.h"
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/autofill/manual_filling_controller_impl.h"
#include "chrome/browser/autofill/mock_address_accessory_controller.h"
#include "chrome/browser/autofill/mock_credit_card_accessory_controller.h"
#include "chrome/browser/autofill/mock_manual_filling_view.h"
#include "chrome/browser/autofill/mock_password_accessory_controller.h"
#include "chrome/browser/ui/autofill/payments/autofill_snackbar_view.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::NiceMock;
namespace autofill {
class AutofillSnackbarControllerImplTest
: public ChromeRenderViewHostTestHarness {
public:
AutofillSnackbarControllerImplTest() = default;
void SetUp() override {
ChromeRenderViewHostTestHarness::SetUp();
ManualFillingControllerImpl::CreateForWebContentsForTesting(
web_contents(), mock_pwd_controller_.AsWeakPtr(),
mock_address_controller_.AsWeakPtr(), mock_cc_controller_.AsWeakPtr(),
std::make_unique<NiceMock<MockManualFillingView>>());
}
AutofillSnackbarControllerImpl* controller() {
if (!controller_)
controller_ = new AutofillSnackbarControllerImpl(web_contents());
return controller_;
}
private:
raw_ptr<AutofillSnackbarControllerImpl> controller_ = nullptr;
NiceMock<MockPasswordAccessoryController> mock_pwd_controller_;
NiceMock<MockAddressAccessoryController> mock_address_controller_;
NiceMock<MockCreditCardAccessoryController> mock_cc_controller_;
};
TEST_F(AutofillSnackbarControllerImplTest, VirtualCardTypeMetricsTest) {
base::HistogramTester histogram_tester;
controller()->Show(AutofillSnackbarType::kVirtualCard);
// Verify that the count for Shown is incremented and ActionClicked hasn't
// changed.
histogram_tester.ExpectUniqueSample("Autofill.Snackbar.VirtualCard.Shown", 1,
1);
histogram_tester.ExpectUniqueSample(
"Autofill.Snackbar.VirtualCard.ActionClicked", 1, 0);
controller()->OnDismissed();
controller()->Show(AutofillSnackbarType::kVirtualCard);
controller()->OnActionClicked();
// Verify that the count for both Shown and ActionClicked is incremented.
histogram_tester.ExpectUniqueSample("Autofill.Snackbar.VirtualCard.Shown", 1,
2);
histogram_tester.ExpectUniqueSample(
"Autofill.Snackbar.VirtualCard.ActionClicked", 1, 1);
}
TEST_F(AutofillSnackbarControllerImplTest,
AttemptToShowDialogWhileAlreadyShowing) {
base::HistogramTester histogram_tester;
controller()->Show(AutofillSnackbarType::kVirtualCard);
// Verify that the count for Shown is incremented and ActionClicked hasn't
// changed.
histogram_tester.ExpectUniqueSample("Autofill.Snackbar.VirtualCard.Shown", 1,
1);
histogram_tester.ExpectUniqueSample(
"Autofill.Snackbar.VirtualCard.ActionClicked", 1, 0);
// Attempt to show another dialog without dismissing the previous one.
controller()->Show(AutofillSnackbarType::kVirtualCard);
// Verify that the count for both Shown is not incremented.
histogram_tester.ExpectUniqueSample("Autofill.Snackbar.VirtualCard.Shown", 1,
1);
}
TEST_F(AutofillSnackbarControllerImplTest, MandatoryReauthTypeMetricsTest) {
base::HistogramTester histogram_tester;
controller()->Show(AutofillSnackbarType::kMandatoryReauth);
// Verify that the count for Shown is incremented and ActionClicked hasn't
// changed.
histogram_tester.ExpectUniqueSample("Autofill.Snackbar.MandatoryReauth.Shown",
1, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.Snackbar.MandatoryReauth.ActionClicked", 1, 0);
controller()->OnDismissed();
// TODO(https://crbug.com/831123): Figure out how to mock
// ShowAutofillCreditCardSettings to test ActionClicked metric.
}
} // namespace autofill