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

Side by Side Diff: components/password_manager/core/browser/suppressed_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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/password_manager/core/browser/suppressed_https_form_fetcher .h" 5 #include "components/password_manager/core/browser/suppressed_form_fetcher.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "components/password_manager/core/browser/mock_password_store.h" 10 #include "components/password_manager/core/browser/mock_password_store.h"
11 #include "components/password_manager/core/browser/password_manager_test_utils.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" 12 #include "components/password_manager/core/browser/stub_password_manager_client. h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace password_manager { 16 namespace password_manager {
17 namespace { 17 namespace {
18 18
19 using autofill::PasswordForm; 19 using autofill::PasswordForm;
20 using testing::_; 20 using testing::_;
21 21
22 constexpr const char kTestHttpURL[] = "http://one.example.com/"; 22 constexpr const char kTestHttpURL[] = "http://one.example.com/";
23 constexpr const char kTestHttpsURL[] = "https://one.example.com/"; 23 constexpr const char kTestHttpsURL[] = "https://one.example.com/";
24 constexpr const char kTestPSLMatchingHttpURL[] = "http://psl.example.com/"; 24 constexpr const char kTestPSLMatchingHttpURL[] = "http://psl.example.com/";
25 constexpr const char kTestPSLMatchingHttpsURL[] = "https://psl.example.com/"; 25 constexpr const char kTestPSLMatchingHttpsURL[] = "https://psl.example.com/";
26 constexpr const char kTestHttpSameOrgNameURL[] = "http://login.example.co.uk/"; 26 constexpr const char kTestHttpSameOrgNameURL[] = "http://login.example.co.uk/";
27 constexpr const char kTestHttpsSameOrgNameURL[] = 27 constexpr const char kTestHttpsSameOrgNameURL[] =
28 "https://login.example.co.uk/"; 28 "https://login.example.co.uk/";
29 29
30 class MockConsumer : public SuppressedHTTPSFormFetcher::Consumer { 30 class MockConsumer : public SuppressedFormFetcher::Consumer {
31 public: 31 public:
32 MockConsumer() = default; 32 MockConsumer() = default;
33 ~MockConsumer() = default; 33 ~MockConsumer() = default;
34 34
35 // GMock still cannot mock methods with move-only args. 35 // GMock still cannot mock methods with move-only args.
36 MOCK_METHOD1(ProcessSuppressedHTTPSFormsConstRef, 36 MOCK_METHOD1(ProcessSuppressedHTTPSFormsConstRef,
37 void(const std::vector<std::unique_ptr<PasswordForm>>&)); 37 void(const std::vector<std::unique_ptr<PasswordForm>>&));
38 38
39 protected: 39 protected:
40 // SuppressedHTTPSFormFetcher::Consumer: 40 // SuppressedFormFetcher::Consumer:
41 void ProcessSuppressedHTTPSForms( 41 void ProcessSuppressedForms(
42 std::vector<std::unique_ptr<PasswordForm>> forms) override { 42 std::vector<std::unique_ptr<PasswordForm>> forms) override {
43 ProcessSuppressedHTTPSFormsConstRef(forms); 43 ProcessSuppressedHTTPSFormsConstRef(forms);
44 } 44 }
45 45
46 private: 46 private:
47 DISALLOW_COPY_AND_ASSIGN(MockConsumer); 47 DISALLOW_COPY_AND_ASSIGN(MockConsumer);
48 }; 48 };
49 49
50 class PasswordManagerClientWithMockStore : public StubPasswordManagerClient { 50 class PasswordManagerClientWithMockStore : public StubPasswordManagerClient {
51 public: 51 public:
(...skipping 10 matching lines...) Expand all
62 PasswordStore* GetPasswordStore() const override { return mock_store_.get(); } 62 PasswordStore* GetPasswordStore() const override { return mock_store_.get(); }
63 63
64 private: 64 private:
65 scoped_refptr<MockPasswordStore> mock_store_; 65 scoped_refptr<MockPasswordStore> mock_store_;
66 66
67 DISALLOW_COPY_AND_ASSIGN(PasswordManagerClientWithMockStore); 67 DISALLOW_COPY_AND_ASSIGN(PasswordManagerClientWithMockStore);
68 }; 68 };
69 69
70 } // namespace 70 } // namespace
71 71
72 class SuppressedHTTPSFormFetcherTest : public testing::Test { 72 class SuppressedFormFetcherTest : public testing::Test {
73 public: 73 public:
74 SuppressedHTTPSFormFetcherTest() = default; 74 SuppressedFormFetcherTest() = default;
75 ~SuppressedHTTPSFormFetcherTest() override = default; 75 ~SuppressedFormFetcherTest() override = default;
76 76
77 MockConsumer* mock_consumer() { return &consumer_; } 77 MockConsumer* mock_consumer() { return &consumer_; }
78 MockPasswordStore* mock_store() { return &client_.mock_password_store(); } 78 MockPasswordStore* mock_store() { return &client_.mock_password_store(); }
79 PasswordManagerClientWithMockStore* mock_client() { return &client_; } 79 PasswordManagerClientWithMockStore* mock_client() { return &client_; }
80 80
81 private: 81 private:
82 base::MessageLoop message_loop_; // Needed by the MockPasswordStore. 82 base::MessageLoop message_loop_; // Needed by the MockPasswordStore.
83 83
84 MockConsumer consumer_; 84 MockConsumer consumer_;
85 PasswordManagerClientWithMockStore client_; 85 PasswordManagerClientWithMockStore client_;
86 86
87 DISALLOW_COPY_AND_ASSIGN(SuppressedHTTPSFormFetcherTest); 87 DISALLOW_COPY_AND_ASSIGN(SuppressedFormFetcherTest);
88 }; 88 };
89 89
90 TEST_F(SuppressedHTTPSFormFetcherTest, EmptyStore) { 90 TEST_F(SuppressedFormFetcherTest, EmptyStore) {
91 EXPECT_CALL(*mock_store(), GetLoginsForSameOrganizationName(kTestHttpURL, _)); 91 EXPECT_CALL(*mock_store(), GetLoginsForSameOrganizationName(kTestHttpURL, _));
92 SuppressedHTTPSFormFetcher suppressed_form_fetcher( 92 SuppressedFormFetcher suppressed_form_fetcher(kTestHttpURL, mock_client(),
93 kTestHttpURL, mock_client(), mock_consumer()); 93 mock_consumer());
94 EXPECT_CALL(*mock_consumer(), 94 EXPECT_CALL(*mock_consumer(),
95 ProcessSuppressedHTTPSFormsConstRef(::testing::IsEmpty())); 95 ProcessSuppressedHTTPSFormsConstRef(::testing::IsEmpty()));
96 suppressed_form_fetcher.OnGetPasswordStoreResults( 96 suppressed_form_fetcher.OnGetPasswordStoreResults(
97 std::vector<std::unique_ptr<PasswordForm>>()); 97 std::vector<std::unique_ptr<PasswordForm>>());
98 } 98 }
99 99
100 TEST_F(SuppressedHTTPSFormFetcherTest, FullStore) { 100 TEST_F(SuppressedFormFetcherTest, FullStore) {
101 static constexpr const PasswordFormData kSuppressedHTTPSCredentials[] = { 101 static constexpr const PasswordFormData kSuppressedCredentials[] = {
102 // Credential that is for the HTTPS counterpart of the observed form. 102 // Credential that is for the HTTPS counterpart of the observed form.
103 {PasswordForm::SCHEME_HTML, kTestHttpsURL, kTestHttpsURL, "", L"", L"", 103 {PasswordForm::SCHEME_HTML, kTestHttpsURL, kTestHttpsURL, "", L"", L"",
104 L"", L"username_value_1", L"password_value_1", true, 1}, 104 L"", L"username_value_1", L"password_value_1", true, 1},
105 // Once again, but with a different username/password. 105 // Once again, but with a different username/password.
106 {PasswordForm::SCHEME_HTML, kTestHttpsURL, kTestHttpsURL, "", L"", L"", 106 {PasswordForm::SCHEME_HTML, kTestHttpsURL, kTestHttpsURL, "", L"", L"",
107 L"", L"username_value_2", L"password_value_2", true, 1}, 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. 108 // A PSL match to the observed form.
115 {PasswordForm::SCHEME_HTML, kTestPSLMatchingHttpURL, 109 {PasswordForm::SCHEME_HTML, kTestPSLMatchingHttpURL,
116 kTestPSLMatchingHttpURL, "", L"", L"", L"", L"username_value_2", 110 kTestPSLMatchingHttpURL, "", L"", L"", L"", L"username_value_2",
117 L"password_value_2", true, 1}, 111 L"password_value_2", true, 1},
118 // A PSL match to the HTTPS counterpart of the observed form. 112 // A PSL match to the HTTPS counterpart of the observed form. Note that
113 // this is *not* a PSL match to the observed form, but a same organization
114 // name match.
119 {PasswordForm::SCHEME_HTML, kTestPSLMatchingHttpsURL, 115 {PasswordForm::SCHEME_HTML, kTestPSLMatchingHttpsURL,
120 kTestPSLMatchingHttpsURL, "", L"", L"", L"", L"username_value_3", 116 kTestPSLMatchingHttpsURL, "", L"", L"", L"", L"username_value_3",
121 L"password_value_3", true, 1}, 117 L"password_value_3", true, 1},
122 // Credentials for a HTTP origin with the same organization 118 // Credentials for a HTTP origin with the same organization
123 // identifying name. 119 // identifying name.
124 {PasswordForm::SCHEME_HTML, kTestHttpSameOrgNameURL, 120 {PasswordForm::SCHEME_HTML, kTestHttpSameOrgNameURL,
125 kTestHttpSameOrgNameURL, "", L"", L"", L"", L"username_value_4", 121 kTestHttpSameOrgNameURL, "", L"", L"", L"", L"username_value_4",
126 L"password_value_4", true, 1}, 122 L"password_value_4", true, 1},
127 // Credentials for a HTTPS origin with the same organization 123 // Credentials for a HTTPS origin with the same organization
128 // identifying name. 124 // identifying name.
129 {PasswordForm::SCHEME_HTML, kTestHttpsSameOrgNameURL, 125 {PasswordForm::SCHEME_HTML, kTestHttpsSameOrgNameURL,
130 kTestHttpsSameOrgNameURL, "", L"", L"", L"", L"username_value_5", 126 kTestHttpsSameOrgNameURL, "", L"", L"", L"", L"username_value_5",
131 L"password_value_5", true, 1}}; 127 L"password_value_5", true, 1}};
132 128
129 static const PasswordFormData kNotSuppressedCredentials[] = {
130 // Credential exactly matching the observed form.
131 {PasswordForm::SCHEME_HTML, kTestHttpURL, kTestHttpURL, "", L"", L"", L"",
132 L"username_value_1", L"password_value_1", true, 1},
133 };
134
133 std::vector<std::unique_ptr<PasswordForm>> simulated_store_results; 135 std::vector<std::unique_ptr<PasswordForm>> simulated_store_results;
134 std::vector<std::unique_ptr<PasswordForm>> expected_results; 136 std::vector<std::unique_ptr<PasswordForm>> expected_results;
135 for (const auto& form_data : kSuppressedHTTPSCredentials) { 137 for (const auto& form_data : kSuppressedCredentials) {
136 expected_results.push_back(CreatePasswordFormFromDataForTesting(form_data)); 138 expected_results.push_back(CreatePasswordFormFromDataForTesting(form_data));
137 simulated_store_results.push_back( 139 simulated_store_results.push_back(
138 CreatePasswordFormFromDataForTesting(form_data)); 140 CreatePasswordFormFromDataForTesting(form_data));
139 } 141 }
140 for (const auto& form_data : kOtherCredentials) { 142 for (const auto& form_data : kNotSuppressedCredentials) {
141 simulated_store_results.push_back( 143 simulated_store_results.push_back(
142 CreatePasswordFormFromDataForTesting(form_data)); 144 CreatePasswordFormFromDataForTesting(form_data));
143 } 145 }
144 146
145 EXPECT_CALL(*mock_store(), GetLoginsForSameOrganizationName(kTestHttpURL, _)); 147 EXPECT_CALL(*mock_store(), GetLoginsForSameOrganizationName(kTestHttpURL, _));
146 SuppressedHTTPSFormFetcher suppressed_form_fetcher( 148 SuppressedFormFetcher suppressed_form_fetcher(kTestHttpURL, mock_client(),
147 kTestHttpURL, mock_client(), mock_consumer()); 149 mock_consumer());
148 EXPECT_CALL(*mock_consumer(), 150 EXPECT_CALL(*mock_consumer(),
149 ProcessSuppressedHTTPSFormsConstRef( 151 ProcessSuppressedHTTPSFormsConstRef(
150 UnorderedPasswordFormElementsAre(&expected_results))); 152 UnorderedPasswordFormElementsAre(&expected_results)));
151 suppressed_form_fetcher.OnGetPasswordStoreResults( 153 suppressed_form_fetcher.OnGetPasswordStoreResults(
152 std::move(simulated_store_results)); 154 std::move(simulated_store_results));
153 } 155 }
154 156
155 } // namespace password_manager 157 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698