Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: components/password_manager/core/browser/suppressed_https_form_fetcher_unittest.cc

Issue 2912783002: Measure how often PSL and same-organization name credentials are suppressed. (Closed)
Patch Set: Addressed comments from kolos@. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 "components/password_manager/core/browser/suppressed_https_form_fetcher .h"
6
7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h"
9 #include "base/message_loop/message_loop.h"
10 #include "components/password_manager/core/browser/mock_password_store.h"
11 #include "components/password_manager/core/browser/password_manager_test_utils.h "
12 #include "components/password_manager/core/browser/stub_password_manager_client. h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace password_manager {
17 namespace {
18
19 using autofill::PasswordForm;
20 using testing::_;
21
22 constexpr const char kTestHttpURL[] = "http://one.example.com/";
23 constexpr const char kTestHttpsURL[] = "https://one.example.com/";
24 constexpr const char kTestPSLMatchingHttpURL[] = "http://psl.example.com/";
25 constexpr const char kTestPSLMatchingHttpsURL[] = "https://psl.example.com/";
26 constexpr const char kTestHttpSameOrgNameURL[] = "http://login.example.co.uk/";
27 constexpr const char kTestHttpsSameOrgNameURL[] =
28 "https://login.example.co.uk/";
29
30 class MockConsumer : public SuppressedHTTPSFormFetcher::Consumer {
31 public:
32 MockConsumer() = default;
33 ~MockConsumer() = default;
34
35 // GMock still cannot mock methods with move-only args.
36 MOCK_METHOD1(ProcessSuppressedHTTPSFormsConstRef,
37 void(const std::vector<std::unique_ptr<PasswordForm>>&));
38
39 protected:
40 // SuppressedHTTPSFormFetcher::Consumer:
41 void ProcessSuppressedHTTPSForms(
42 std::vector<std::unique_ptr<PasswordForm>> forms) override {
43 ProcessSuppressedHTTPSFormsConstRef(forms);
44 }
45
46 private:
47 DISALLOW_COPY_AND_ASSIGN(MockConsumer);
48 };
49
50 class PasswordManagerClientWithMockStore : public StubPasswordManagerClient {
51 public:
52 PasswordManagerClientWithMockStore()
53 : mock_store_(new ::testing::StrictMock<MockPasswordStore>()) {}
54 ~PasswordManagerClientWithMockStore() override {
55 mock_store_->ShutdownOnUIThread();
56 }
57
58 MockPasswordStore& mock_password_store() const { return *mock_store_.get(); }
59
60 protected:
61 // StubPasswordManagerClient:
62 PasswordStore* GetPasswordStore() const override { return mock_store_.get(); }
63
64 private:
65 scoped_refptr<MockPasswordStore> mock_store_;
66
67 DISALLOW_COPY_AND_ASSIGN(PasswordManagerClientWithMockStore);
68 };
69
70 } // namespace
71
72 class SuppressedHTTPSFormFetcherTest : public testing::Test {
73 public:
74 SuppressedHTTPSFormFetcherTest() = default;
75 ~SuppressedHTTPSFormFetcherTest() override = default;
76
77 MockConsumer* mock_consumer() { return &consumer_; }
78 MockPasswordStore* mock_store() { return &client_.mock_password_store(); }
79 PasswordManagerClientWithMockStore* mock_client() { return &client_; }
80
81 private:
82 base::MessageLoop message_loop_; // Needed by the MockPasswordStore.
83
84 MockConsumer consumer_;
85 PasswordManagerClientWithMockStore client_;
86
87 DISALLOW_COPY_AND_ASSIGN(SuppressedHTTPSFormFetcherTest);
88 };
89
90 TEST_F(SuppressedHTTPSFormFetcherTest, EmptyStore) {
91 EXPECT_CALL(*mock_store(), GetLoginsForSameOrganizationName(kTestHttpURL, _));
92 SuppressedHTTPSFormFetcher suppressed_form_fetcher(
93 kTestHttpURL, mock_client(), mock_consumer());
94 EXPECT_CALL(*mock_consumer(),
95 ProcessSuppressedHTTPSFormsConstRef(::testing::IsEmpty()));
96 suppressed_form_fetcher.OnGetPasswordStoreResults(
97 std::vector<std::unique_ptr<PasswordForm>>());
98 }
99
100 TEST_F(SuppressedHTTPSFormFetcherTest, FullStore) {
101 static constexpr const PasswordFormData kSuppressedHTTPSCredentials[] = {
102 // Credential that is for the HTTPS counterpart of the observed form.
103 {PasswordForm::SCHEME_HTML, kTestHttpsURL, kTestHttpsURL, "", L"", L"",
104 L"", L"username_value_1", L"password_value_1", true, 1},
105 // Once again, but with a different username/password.
106 {PasswordForm::SCHEME_HTML, kTestHttpsURL, kTestHttpsURL, "", L"", L"",
107 L"", L"username_value_2", L"password_value_2", true, 1},
108 };
109
110 static constexpr const PasswordFormData kOtherCredentials[] = {
111 // Credential exactly matching the observed form.
112 {PasswordForm::SCHEME_HTML, kTestHttpURL, kTestHttpURL, "", L"", L"", L"",
113 L"username_value_1", L"password_value_1", true, 1},
114 // A PSL match to the observed form.
115 {PasswordForm::SCHEME_HTML, kTestPSLMatchingHttpURL,
116 kTestPSLMatchingHttpURL, "", L"", L"", L"", L"username_value_2",
117 L"password_value_2", true, 1},
118 // A PSL match to the HTTPS counterpart of the observed form.
119 {PasswordForm::SCHEME_HTML, kTestPSLMatchingHttpsURL,
120 kTestPSLMatchingHttpsURL, "", L"", L"", L"", L"username_value_3",
121 L"password_value_3", true, 1},
122 // Credentials for a HTTP origin with the same organization
123 // identifying name.
124 {PasswordForm::SCHEME_HTML, kTestHttpSameOrgNameURL,
125 kTestHttpSameOrgNameURL, "", L"", L"", L"", L"username_value_4",
126 L"password_value_4", true, 1},
127 // Credentials for a HTTPS origin with the same organization
128 // identifying name.
129 {PasswordForm::SCHEME_HTML, kTestHttpsSameOrgNameURL,
130 kTestHttpsSameOrgNameURL, "", L"", L"", L"", L"username_value_5",
131 L"password_value_5", true, 1}};
132
133 std::vector<std::unique_ptr<PasswordForm>> simulated_store_results;
134 std::vector<std::unique_ptr<PasswordForm>> expected_results;
135 for (const auto& form_data : kSuppressedHTTPSCredentials) {
136 expected_results.push_back(CreatePasswordFormFromDataForTesting(form_data));
137 simulated_store_results.push_back(
138 CreatePasswordFormFromDataForTesting(form_data));
139 }
140 for (const auto& form_data : kOtherCredentials) {
141 simulated_store_results.push_back(
142 CreatePasswordFormFromDataForTesting(form_data));
143 }
144
145 EXPECT_CALL(*mock_store(), GetLoginsForSameOrganizationName(kTestHttpURL, _));
146 SuppressedHTTPSFormFetcher suppressed_form_fetcher(
147 kTestHttpURL, mock_client(), mock_consumer());
148 EXPECT_CALL(*mock_consumer(),
149 ProcessSuppressedHTTPSFormsConstRef(
150 UnorderedPasswordFormElementsAre(&expected_results)));
151 suppressed_form_fetcher.OnGetPasswordStoreResults(
152 std::move(simulated_store_results));
153 }
154
155 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698