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

Unified Diff: components/password_manager/core/browser/password_store_unittest.cc

Issue 2899083004: Implement PasswordStore::GetLoginsForSameOrganizationName. (Closed)
Patch Set: Pacify MSVC++. Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: components/password_manager/core/browser/password_store_unittest.cc
diff --git a/components/password_manager/core/browser/password_store_unittest.cc b/components/password_manager/core/browser/password_store_unittest.cc
index c47de36416f424e801517330dbc33d1750378122..2d79704e2ff06343e72b4d72235c4c286505a0b9 100644
--- a/components/password_manager/core/browser/password_store_unittest.cc
+++ b/components/password_manager/core/browser/password_store_unittest.cc
@@ -59,6 +59,9 @@ const char kTestPSLMatchingWebRealm[] = "https://psl.example.com/";
const char kTestPSLMatchingWebOrigin[] = "https://psl.example.com/origin";
const char kTestUnrelatedWebRealm[] = "https://notexample.com/";
const char kTestUnrelatedWebOrigin[] = "https:/notexample.com/origin";
+const char kTestSameOrganizationNameWebRealm[] = "https://example.appspot.com/";
+const char kTestSameOrganizationNameWebOrigin[] =
vasilii 2017/05/26 12:47:55 Optionally: convert everything to constexpr.
engedy 2017/05/29 08:41:09 Done.
+ "https://example.appspot.com/origin";
const char kTestInsecureWebRealm[] = "http://one.example.com/";
const char kTestInsecureWebOrigin[] = "http://one.example.com/origin";
const char kTestAndroidRealm1[] = "android://hash@com.example.android/";
@@ -851,6 +854,61 @@ TEST_F(PasswordStoreTest, GetLoginsWithAffiliatedRealms) {
}
}
+TEST_F(PasswordStoreTest, GetLoginsForSameOrganizationName) {
+ static const PasswordFormData kSameOrganizationCredentials[] = {
vasilii 2017/05/26 12:47:55 constexpr here and below
engedy 2017/05/29 08:41:09 Done.
+ // Credential that is an exact match of the observed form.
+ {PasswordForm::SCHEME_HTML, kTestWebRealm1, kTestWebOrigin1, "", L"", L"",
+ L"", L"username_value_1", L"", true, 1},
+ // Credential that is a PSL match of the observed form.
+ {PasswordForm::SCHEME_HTML, kTestPSLMatchingWebRealm,
+ kTestPSLMatchingWebOrigin, "", L"", L"", L"", L"username_value_2", L"",
+ true, 1},
+ // Credential for the HTTP version of the observed form. (Should not be
+ // filled, but returned as part of same-organization-name matches).
+ {PasswordForm::SCHEME_HTML, kTestInsecureWebRealm, kTestInsecureWebOrigin,
+ "", L"", L"", L"", L"username_value_3", L"", true, 1},
+ // Credential for a signon realm with a different TLD, but same
+ // organization identifying name.
+ {PasswordForm::SCHEME_HTML, kTestSameOrganizationNameWebRealm,
+ kTestSameOrganizationNameWebOrigin, "", L"", L"", L"",
+ L"username_value_4", L"", true, 1},
+ };
+
+ static const PasswordFormData kNotSameOrganizationCredentials[] = {
+ // Unrelated Web credential.
+ {PasswordForm::SCHEME_HTML, kTestUnrelatedWebRealm,
+ kTestUnrelatedWebOrigin, "", L"", L"", L"", L"username_value_5", L"",
+ true, 1},
+ // Credential for an affiliated Android application.
+ {PasswordForm::SCHEME_HTML, kTestAndroidRealm1, "", "", L"", L"", L"",
+ L"username_value_6", L"", true, 1}};
+
+ scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault(
+ base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(),
+ base::MakeUnique<LoginDatabase>(test_login_db_file_path())));
+ store->Init(syncer::SyncableService::StartSyncFlare(), nullptr);
+
+ std::vector<std::unique_ptr<PasswordForm>> expected_results;
+ for (const auto& form_data : kSameOrganizationCredentials) {
+ expected_results.push_back(CreatePasswordFormFromDataForTesting(form_data));
+ store->AddLogin(*expected_results.back());
+ }
+
+ for (const auto& form_data : kNotSameOrganizationCredentials) {
+ store->AddLogin(*CreatePasswordFormFromDataForTesting(form_data));
+ }
+
+ const std::string observed_form_realm = kTestWebRealm1;
+ MockPasswordStoreConsumer mock_consumer;
+ EXPECT_CALL(mock_consumer,
+ OnGetPasswordStoreResultsConstRef(
+ UnorderedPasswordFormElementsAre(&expected_results)));
+ store->GetLoginsForSameOrganizationName(observed_form_realm, &mock_consumer);
+ base::RunLoop().RunUntilIdle();
+ store->ShutdownOnUIThread();
+ base::RunLoop().RunUntilIdle();
+}
+
// TODO(crbug.com/706392): Fix password reuse detection for Android.
#if !defined(OS_ANDROID) && !defined(OS_IOS)
TEST_F(PasswordStoreTest, CheckPasswordReuse) {

Powered by Google App Engine
This is Rietveld 408576698