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

Unified Diff: components/password_manager/content/browser/credential_manager_dispatcher_unittest.cc

Issue 1031153002: [Credential Management] Smart lock save Credentials bubble should not always pop up. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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/content/browser/credential_manager_dispatcher_unittest.cc
diff --git a/components/password_manager/content/browser/credential_manager_dispatcher_unittest.cc b/components/password_manager/content/browser/credential_manager_dispatcher_unittest.cc
index ba253d96686bf25a1c9d57a5ce79a25538441734..2a77236637a29260cff169895624520c4435a218 100644
--- a/components/password_manager/content/browser/credential_manager_dispatcher_unittest.cc
+++ b/components/password_manager/content/browser/credential_manager_dispatcher_unittest.cc
@@ -37,7 +37,9 @@ const int kRequestId = 4;
class MockPasswordManagerClient
: public password_manager::StubPasswordManagerClient {
public:
+ MOCK_CONST_METHOD0(IsPasswordManagerEnabledForCurrentPage, bool());
MOCK_CONST_METHOD0(IsOffTheRecord, bool());
+ MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool());
MOCK_METHOD1(NotifyUserAutoSigninPtr,
bool(const std::vector<autofill::PasswordForm*>& local_forms));
MOCK_METHOD2(PromptUserToSavePasswordPtr,
@@ -54,6 +56,8 @@ class MockPasswordManagerClient
: store_(store) {
prefs_.registry()->RegisterBooleanPref(
password_manager::prefs::kPasswordManagerAutoSignin, true);
+ prefs_.registry()->RegisterBooleanPref(
+ password_manager::prefs::kPasswordManagerSavingEnabled, true);
}
~MockPasswordManagerClient() override {}
@@ -99,6 +103,11 @@ class MockPasswordManagerClient
return manager_.get();
}
+ void set_password_manager_saving_enabled(bool is_enabled) {
+ prefs_.SetBoolean(password_manager::prefs::kPasswordManagerSavingEnabled,
+ is_enabled);
+ }
+
void set_zero_click_enabled(bool zero_click_enabled) {
prefs_.SetBoolean(password_manager::prefs::kPasswordManagerAutoSignin,
zero_click_enabled);
@@ -162,6 +171,10 @@ class CredentialManagerDispatcherTest
dispatcher_.reset(new TestCredentialManagerDispatcher(
web_contents(), client_.get(), &stub_driver_));
ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false));
+ ON_CALL(*client_, DidLastPageLoadEncounterSSLErrors())
+ .WillByDefault(testing::Return(false));
+ ON_CALL(*client_, IsPasswordManagerEnabledForCurrentPage())
+ .WillByDefault(testing::Return(true));
NavigateAndCommit(GURL("https://example.com/test.html"));
@@ -277,6 +290,76 @@ TEST_F(CredentialManagerDispatcherTest, CredentialManagerIncognitoSignedIn) {
EXPECT_FALSE(client_->pending_manager());
}
+TEST_F(CredentialManagerDispatcherTest, CredentialManagerSignInWithSSLErrors) {
+ CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_LOCAL);
+ EXPECT_CALL(*client_, DidLastPageLoadEncounterSSLErrors())
+ .WillRepeatedly(testing::Return(true));
+ EXPECT_CALL(
+ *client_,
+ PromptUserToSavePasswordPtr(
+ _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API))
+ .Times(testing::Exactly(0));
+
+ dispatcher()->OnNotifySignedIn(kRequestId, info);
+
+ const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID;
+ const IPC::Message* message =
+ process()->sink().GetFirstMessageMatching(kMsgID);
+ EXPECT_TRUE(message);
+ process()->sink().ClearMessages();
+
+ RunAllPendingTasks();
+
+ EXPECT_FALSE(client_->pending_manager());
+}
+
+TEST_F(CredentialManagerDispatcherTest,
+ CredentialManagerSignInWithDisabledPasswordManager) {
+ CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_LOCAL);
+ client_->set_password_manager_saving_enabled(false);
+ EXPECT_CALL(
+ *client_,
+ PromptUserToSavePasswordPtr(
+ _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API))
+ .Times(testing::Exactly(0));
+
+ dispatcher()->OnNotifySignedIn(kRequestId, info);
+
+ const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID;
+ const IPC::Message* message =
+ process()->sink().GetFirstMessageMatching(kMsgID);
+ EXPECT_TRUE(message);
+ process()->sink().ClearMessages();
+
+ RunAllPendingTasks();
+
+ EXPECT_FALSE(client_->pending_manager());
+}
+
+TEST_F(CredentialManagerDispatcherTest,
+ CredentialManagerSignInWthPasswordManagerDisabledForCurrentPage) {
+ CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_LOCAL);
+ EXPECT_CALL(*client_, IsPasswordManagerEnabledForCurrentPage())
+ .WillRepeatedly(testing::Return(false));
+ EXPECT_CALL(
+ *client_,
+ PromptUserToSavePasswordPtr(
+ _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API))
+ .Times(testing::Exactly(0));
+
+ dispatcher()->OnNotifySignedIn(kRequestId, info);
+
+ const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID;
+ const IPC::Message* message =
+ process()->sink().GetFirstMessageMatching(kMsgID);
+ EXPECT_TRUE(message);
+ process()->sink().ClearMessages();
+
+ RunAllPendingTasks();
+
+ EXPECT_FALSE(client_->pending_manager());
+}
+
TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifySignedOut) {
store_->AddLogin(form_);
store_->AddLogin(cross_origin_form_);

Powered by Google App Engine
This is Rietveld 408576698