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

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

Issue 2317163003: [Merge M54] Only report PasswordState in Sync for UMA+non-custom passphrase users. (Closed)
Patch Set: Created 4 years, 3 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/chrome_password_manager_client.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/password_manager/chrome_password_manager_client_unittest.cc
diff --git a/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc b/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc
index b086529e529ac5328138c55ca097d30b8a695b62..1fbac0d5c700833b7a14863b0ce9206e58626f18 100644
--- a/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc
+++ b/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc
@@ -14,6 +14,7 @@
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
+#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/profile_sync_test_util.h"
#include "chrome/common/channel_info.h"
@@ -33,6 +34,7 @@
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/testing_pref_service.h"
+#include "components/sessions/content/content_record_password_state.h"
#include "components/syncable_prefs/testing_pref_service_syncable.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/browser_context.h"
@@ -43,6 +45,8 @@
using content::BrowserContext;
using content::WebContents;
+using sessions::GetPasswordStateFromNavigation;
+using sessions::SerializedNavigationEntry;
using testing::Return;
using testing::_;
@@ -86,8 +90,10 @@ class DummyLogReceiver : public password_manager::LogReceiver {
class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness {
public:
- ChromePasswordManagerClientTest() : field_trial_list_(nullptr) {}
+ ChromePasswordManagerClientTest()
+ : field_trial_list_(nullptr), metrics_enabled_(false) {}
void SetUp() override;
+ void TearDown() override;
syncable_prefs::TestingPrefServiceSyncable* prefs() {
return profile()->GetTestingPrefService();
@@ -99,6 +105,29 @@ class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness {
kPasswordManagerSettingsBehaviourChangeFieldTrialName, name));
}
+ // Caller does not own the returned pointer.
+ ProfileSyncServiceMock* SetupBasicMockSync() {
+ ProfileSyncServiceMock* mock_sync_service =
+ static_cast<ProfileSyncServiceMock*>(
+ ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile(), BuildMockProfileSyncService));
+
+ EXPECT_CALL(*mock_sync_service, IsFirstSetupComplete())
+ .WillRepeatedly(Return(true));
+ EXPECT_CALL(*mock_sync_service, IsSyncActive())
+ .WillRepeatedly(Return(true));
+ return mock_sync_service;
+ }
+
+ // Make a navigation entry that will accept an annotation.
+ void SetupNavigationForAnnotation() {
+ ProfileSyncServiceMock* mock_sync_service = SetupBasicMockSync();
+ EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase())
+ .WillRepeatedly(Return(false));
+ metrics_enabled_ = true;
+ NavigateAndCommit(GURL("about:blank"));
+ }
+
protected:
ChromePasswordManagerClient* GetClient();
@@ -109,6 +138,7 @@ class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness {
TestingPrefServiceSimple prefs_;
base::FieldTrialList field_trial_list_;
+ bool metrics_enabled_;
};
void ChromePasswordManagerClientTest::SetUp() {
@@ -117,6 +147,15 @@ void ChromePasswordManagerClientTest::SetUp() {
password_manager::prefs::kPasswordManagerSavingEnabled, true);
ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient(
web_contents(), nullptr);
+
+ // Connect our bool for testing.
+ ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(
+ &metrics_enabled_);
+}
+
+void ChromePasswordManagerClientTest::TearDown() {
+ ChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(nullptr);
+ ChromeRenderViewHostTestHarness::TearDown();
}
ChromePasswordManagerClient* ChromePasswordManagerClientTest::GetClient() {
@@ -179,23 +218,17 @@ TEST_F(ChromePasswordManagerClientTest,
}
TEST_F(ChromePasswordManagerClientTest, GetPasswordSyncState) {
- ChromePasswordManagerClient* client = GetClient();
-
- ProfileSyncServiceMock* mock_sync_service =
- static_cast<ProfileSyncServiceMock*>(
- ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
- profile(), BuildMockProfileSyncService));
+ ProfileSyncServiceMock* mock_sync_service = SetupBasicMockSync();
syncer::ModelTypeSet active_types;
active_types.Put(syncer::PASSWORDS);
- EXPECT_CALL(*mock_sync_service, IsFirstSetupComplete())
- .WillRepeatedly(Return(true));
- EXPECT_CALL(*mock_sync_service, IsSyncActive()).WillRepeatedly(Return(true));
EXPECT_CALL(*mock_sync_service, GetActiveDataTypes())
.WillRepeatedly(Return(active_types));
EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase())
.WillRepeatedly(Return(false));
+ ChromePasswordManagerClient* client = GetClient();
+
// Passwords are syncing and custom passphrase isn't used.
EXPECT_EQ(password_manager::SYNCING_NORMAL_ENCRYPTION,
client->GetPasswordSyncState());
@@ -352,3 +385,108 @@ TEST_F(ChromePasswordManagerClientTest, WebUINoLogging) {
log_router->UnregisterReceiver(&log_receiver);
}
+
+// Metrics enabled, syncing with non-custom passphrase: Do not annotate.
+TEST_F(ChromePasswordManagerClientTest,
+ AnnotateNavigationEntryWithMetricsNoCustom) {
+ ProfileSyncServiceMock* mock_sync_service = SetupBasicMockSync();
+ EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase())
+ .WillRepeatedly(Return(false));
+ metrics_enabled_ = true;
+
+ NavigateAndCommit(GURL("about:blank"));
+ GetClient()->AnnotateNavigationEntry(true);
+
+ EXPECT_EQ(
+ SerializedNavigationEntry::HAS_PASSWORD_FIELD,
+ GetPasswordStateFromNavigation(*controller().GetLastCommittedEntry()));
+}
+
+// Metrics disabled, syncing with non-custom passphrase: Do not annotate.
+TEST_F(ChromePasswordManagerClientTest,
+ AnnotateNavigationEntryNoMetricsNoCustom) {
+ ProfileSyncServiceMock* mock_sync_service = SetupBasicMockSync();
+ EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase())
+ .WillRepeatedly(Return(false));
+ metrics_enabled_ = false;
+
+ NavigateAndCommit(GURL("about:blank"));
+ GetClient()->AnnotateNavigationEntry(true);
+
+ EXPECT_EQ(
+ SerializedNavigationEntry::PASSWORD_STATE_UNKNOWN,
+ GetPasswordStateFromNavigation(*controller().GetLastCommittedEntry()));
+}
+
+// Metrics enabled, syncing with custom passphrase: Do not annotate.
+TEST_F(ChromePasswordManagerClientTest,
+ AnnotateNavigationEntryWithMetricsWithCustom) {
+ ProfileSyncServiceMock* mock_sync_service = SetupBasicMockSync();
+ EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase())
+ .WillRepeatedly(Return(true));
+ metrics_enabled_ = true;
+
+ NavigateAndCommit(GURL("about:blank"));
+ GetClient()->AnnotateNavigationEntry(true);
+
+ EXPECT_EQ(
+ SerializedNavigationEntry::PASSWORD_STATE_UNKNOWN,
+ GetPasswordStateFromNavigation(*controller().GetLastCommittedEntry()));
+}
+
+// Metrics disabled, syncing with custom passphrase: Do not annotate.
+TEST_F(ChromePasswordManagerClientTest,
+ AnnotateNavigationEntryNoMetricsWithCustom) {
+ ProfileSyncServiceMock* mock_sync_service = SetupBasicMockSync();
+ EXPECT_CALL(*mock_sync_service, IsUsingSecondaryPassphrase())
+ .WillRepeatedly(Return(true));
+ metrics_enabled_ = false;
+
+ NavigateAndCommit(GURL("about:blank"));
+ GetClient()->AnnotateNavigationEntry(true);
+
+ EXPECT_EQ(
+ SerializedNavigationEntry::PASSWORD_STATE_UNKNOWN,
+ GetPasswordStateFromNavigation(*controller().GetLastCommittedEntry()));
+}
+
+// State transition: Unannotated
+TEST_F(ChromePasswordManagerClientTest, AnnotateNavigationEntryUnannotated) {
+ SetupNavigationForAnnotation();
+
+ EXPECT_EQ(
+ SerializedNavigationEntry::PASSWORD_STATE_UNKNOWN,
+ GetPasswordStateFromNavigation(*controller().GetLastCommittedEntry()));
+}
+
+// State transition: unknown->false
+TEST_F(ChromePasswordManagerClientTest, AnnotateNavigationEntryToFalse) {
+ SetupNavigationForAnnotation();
+
+ GetClient()->AnnotateNavigationEntry(false);
+ EXPECT_EQ(
+ SerializedNavigationEntry::NO_PASSWORD_FIELD,
+ GetPasswordStateFromNavigation(*controller().GetLastCommittedEntry()));
+}
+
+// State transition: false->true
+TEST_F(ChromePasswordManagerClientTest, AnnotateNavigationEntryToTrue) {
+ SetupNavigationForAnnotation();
+
+ GetClient()->AnnotateNavigationEntry(false);
+ GetClient()->AnnotateNavigationEntry(true);
+ EXPECT_EQ(
+ SerializedNavigationEntry::HAS_PASSWORD_FIELD,
+ GetPasswordStateFromNavigation(*controller().GetLastCommittedEntry()));
+}
+
+// State transition: true->false (retains true)
+TEST_F(ChromePasswordManagerClientTest, AnnotateNavigationEntryTrueToFalse) {
+ SetupNavigationForAnnotation();
+
+ GetClient()->AnnotateNavigationEntry(true);
+ GetClient()->AnnotateNavigationEntry(false);
+ EXPECT_EQ(
+ SerializedNavigationEntry::HAS_PASSWORD_FIELD,
+ GetPasswordStateFromNavigation(*controller().GetLastCommittedEntry()));
+}
« no previous file with comments | « chrome/browser/password_manager/chrome_password_manager_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698