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

Unified Diff: chrome/browser/password_manager/account_chooser_dialog_android_unittest.cc

Issue 2126353003: [CM API] Account Chooser with Sign in button for single account (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove unnssary checks Created 4 years, 5 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
« no previous file with comments | « chrome/browser/password_manager/account_chooser_dialog_android.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/password_manager/account_chooser_dialog_android_unittest.cc
diff --git a/chrome/browser/password_manager/account_chooser_dialog_android_unittest.cc b/chrome/browser/password_manager/account_chooser_dialog_android_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bb12485eaea58de39ce8d2b5a5bab4dc8885d533
--- /dev/null
+++ b/chrome/browser/password_manager/account_chooser_dialog_android_unittest.cc
@@ -0,0 +1,152 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/password_manager/account_chooser_dialog_android.h"
+
+#include "base/macros.h"
+#include "base/test/histogram_tester.h"
+#include "chrome/browser/password_manager/chrome_password_manager_client.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/test/base/chrome_render_view_host_test_harness.h"
+#include "components/autofill/core/common/password_form.h"
+#include "components/password_manager/core/browser/password_manager_metrics_util.h"
+#include "components/password_manager/core/browser/password_manager_test_utils.h"
+#include "components/password_manager/core/common/password_manager_pref_names.h"
+#include "content/public/browser/web_contents.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+password_manager::PasswordFormData kFormData = {
+ autofill::PasswordForm::SCHEME_HTML,
+ "http://example.com/",
+ "http://example.com/origin",
+ "http://example.com/action",
+ L"submit_element",
+ L"username_element",
+ L"password_element",
+ L"",
+ L"",
+ true,
+ false,
+ 1,
+};
+
+} // namespace
+
+class AccountChooserDialogAndroidTest : public ChromeRenderViewHostTestHarness {
+ public:
+ AccountChooserDialogAndroidTest() {}
+ ~AccountChooserDialogAndroidTest() override {}
+
+ void SetUp() override;
+
+ MOCK_METHOD1(OnChooseCredential, void(const autofill::PasswordForm*));
+
+ protected:
+ AccountChooserDialogAndroid* CreateDialogOneAccount();
+ AccountChooserDialogAndroid* CreateDialogManyAccounts();
+
+ AccountChooserDialogAndroid* CreateDialog(
+ ScopedVector<autofill::PasswordForm> credentials);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AccountChooserDialogAndroidTest);
+};
+
+void AccountChooserDialogAndroidTest::SetUp() {
+ ChromeRenderViewHostTestHarness::SetUp();
+ ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient(
+ web_contents(), nullptr);
+}
+
+AccountChooserDialogAndroid* AccountChooserDialogAndroidTest::CreateDialog(
+ ScopedVector<autofill::PasswordForm> credentials) {
+ ScopedVector<autofill::PasswordForm> deprecated_federated;
+ return new AccountChooserDialogAndroid(
+ web_contents(), std::move(credentials), std::move(deprecated_federated),
+ GURL("https://example.com"),
+ base::Bind(&AccountChooserDialogAndroidTest::OnChooseCredential,
+ base::Unretained(this)));
+}
+
+AccountChooserDialogAndroid*
+AccountChooserDialogAndroidTest::CreateDialogOneAccount() {
+ ScopedVector<autofill::PasswordForm> credentials;
+ credentials.push_back(CreatePasswordFormFromDataForTesting(kFormData));
+ return CreateDialog(std::move(credentials));
+}
+
+AccountChooserDialogAndroid*
+AccountChooserDialogAndroidTest::CreateDialogManyAccounts() {
+ ScopedVector<autofill::PasswordForm> credentials;
+ credentials.push_back(CreatePasswordFormFromDataForTesting(kFormData));
+ credentials.push_back(CreatePasswordFormFromDataForTesting(kFormData));
+ return CreateDialog(std::move(credentials));
+}
+
+TEST_F(AccountChooserDialogAndroidTest,
+ CheckHistogramsReportingOnceAccountViaOnAccountClick) {
+ base::HistogramTester histogram_tester;
+ AccountChooserDialogAndroid* dialog = CreateDialogOneAccount();
+ dialog->OnCredentialClicked(
+ base::android::AttachCurrentThread(), nullptr /* obj */,
+ 0 /* credential_item */,
+ static_cast<int>(
+ password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD),
+ false /* signin_button_clicked */);
+ dialog->Destroy(base::android::AttachCurrentThread(), nullptr);
+
+ histogram_tester.ExpectUniqueSample(
+ "PasswordManager.AccountChooserDialog",
+ password_manager::metrics_util::ACCOUNT_CHOOSER_CREDENTIAL_CHOSEN, 1);
+ histogram_tester.ExpectUniqueSample(
+ "PasswordManager.AccountChooserDialogOneAccount",
+ password_manager::metrics_util::ACCOUNT_CHOOSER_CREDENTIAL_CHOSEN, 1);
+ histogram_tester.ExpectTotalCount(
+ "PasswordManager.AccountChooserDialogMultipleAccounts", 0);
+}
+
+TEST_F(AccountChooserDialogAndroidTest,
+ CheckHistogramsReportingOneAccountChoosenViaSigninButton) {
+ base::HistogramTester histogram_tester;
+ AccountChooserDialogAndroid* dialog = CreateDialogOneAccount();
+ dialog->OnCredentialClicked(
+ base::android::AttachCurrentThread(), nullptr /* obj */,
+ 0 /* credential_item */,
+ static_cast<int>(
+ password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD),
+ true /* signin_button_clicked */);
+ dialog->Destroy(base::android::AttachCurrentThread(), nullptr);
+ histogram_tester.ExpectUniqueSample(
+ "PasswordManager.AccountChooserDialog",
+ password_manager::metrics_util::ACCOUNT_CHOOSER_SIGN_IN, 1);
+ histogram_tester.ExpectUniqueSample(
+ "PasswordManager.AccountChooserDialogOneAccount",
+ password_manager::metrics_util::ACCOUNT_CHOOSER_SIGN_IN, 1);
+ histogram_tester.ExpectTotalCount(
+ "PasswordManager.AccountChooserDialogMultipleAccounts", 0);
+}
+
+TEST_F(AccountChooserDialogAndroidTest, CheckHistogramsReportingManyAccounts) {
+ base::HistogramTester histogram_tester;
+ AccountChooserDialogAndroid* dialog = CreateDialogManyAccounts();
+ dialog->OnCredentialClicked(
+ base::android::AttachCurrentThread(), nullptr /* obj */,
+ 0 /* credential_item */,
+ static_cast<int>(
+ password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD),
+ false /* signin_button_clicked */);
+ dialog->Destroy(base::android::AttachCurrentThread(), nullptr);
+
+ histogram_tester.ExpectUniqueSample(
+ "PasswordManager.AccountChooserDialog",
+ password_manager::metrics_util::ACCOUNT_CHOOSER_CREDENTIAL_CHOSEN, 1);
+ histogram_tester.ExpectUniqueSample(
+ "PasswordManager.AccountChooserDialogMultipleAccounts",
+ password_manager::metrics_util::ACCOUNT_CHOOSER_CREDENTIAL_CHOSEN, 1);
+ histogram_tester.ExpectTotalCount(
+ "PasswordManager.AccountChooserDialogOneAccount", 0);
+}
« no previous file with comments | « chrome/browser/password_manager/account_chooser_dialog_android.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698