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 58eb799de88c6c76083d94ab7f2dddc7e852c301..d7b06f4b72fad09e893dc2df1cb59544c488ac24 100644 |
--- a/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc |
+++ b/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc |
@@ -20,8 +20,6 @@ |
#include "components/password_manager/content/browser/password_manager_internals_service_factory.h" |
#include "components/password_manager/content/common/credential_manager_messages.h" |
#include "components/password_manager/core/browser/credentials_filter.h" |
-#include "components/password_manager/core/browser/log_receiver.h" |
-#include "components/password_manager/core/browser/password_manager_internals_service.h" |
#include "components/password_manager/core/common/credential_manager_types.h" |
#include "components/password_manager/core/common/password_manager_pref_names.h" |
#include "components/password_manager/core/common/password_manager_switches.h" |
@@ -47,13 +45,6 @@ const char kPasswordManagerSettingsBehaviourChangeEnabledGroupName[] = |
const char kPasswordManagerSettingsBehaviourChangeDisabledGroupName[] = |
"PasswordManagerSettingsBehaviourChange.NotActive"; |
-const char kTestText[] = "abcd1234"; |
- |
-class MockLogReceiver : public password_manager::LogReceiver { |
- public: |
- MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); |
-}; |
- |
// TODO(vabr): Get rid of the mocked client in the client's own test, see |
// http://crbug.com/474577. |
class MockChromePasswordManagerClient : public ChromePasswordManagerClient { |
@@ -75,8 +66,7 @@ class MockChromePasswordManagerClient : public ChromePasswordManagerClient { |
class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness { |
public: |
- ChromePasswordManagerClientTest() |
- : service_(nullptr), field_trial_list_(nullptr) {} |
+ ChromePasswordManagerClientTest() : field_trial_list_(nullptr) {} |
void SetUp() override; |
syncable_prefs::TestingPrefServiceSyncable* prefs() { |
@@ -97,9 +87,6 @@ class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness { |
// returns false. |
bool WasLoggingActivationMessageSent(bool* activation_flag); |
- password_manager::PasswordManagerInternalsService* service_; |
- |
- testing::StrictMock<MockLogReceiver> receiver_; |
TestingPrefServiceSimple prefs_; |
base::FieldTrialList field_trial_list_; |
}; |
@@ -110,9 +97,6 @@ void ChromePasswordManagerClientTest::SetUp() { |
password_manager::prefs::kPasswordManagerSavingEnabled, true); |
ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( |
web_contents(), nullptr); |
- service_ = password_manager::PasswordManagerInternalsServiceFactory:: |
- GetForBrowserContext(profile()); |
- ASSERT_TRUE(service_); |
} |
ChromePasswordManagerClient* ChromePasswordManagerClientTest::GetClient() { |
@@ -133,86 +117,21 @@ bool ChromePasswordManagerClientTest::WasLoggingActivationMessageSent( |
return true; |
} |
-TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressNoReceiver) { |
- ChromePasswordManagerClient* client = GetClient(); |
- |
- EXPECT_CALL(receiver_, LogSavePasswordProgress(kTestText)).Times(0); |
- // Before attaching the receiver, no text should be passed. |
- client->LogSavePasswordProgress(kTestText); |
- EXPECT_FALSE(client->IsLoggingActive()); |
-} |
- |
-TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressAttachReceiver) { |
- ChromePasswordManagerClient* client = GetClient(); |
- EXPECT_FALSE(client->IsLoggingActive()); |
- |
- // After attaching the logger, text should be passed. |
- service_->RegisterReceiver(&receiver_); |
- EXPECT_TRUE(client->IsLoggingActive()); |
- EXPECT_CALL(receiver_, LogSavePasswordProgress(kTestText)).Times(1); |
- client->LogSavePasswordProgress(kTestText); |
- service_->UnregisterReceiver(&receiver_); |
- EXPECT_FALSE(client->IsLoggingActive()); |
-} |
- |
-TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressDetachReceiver) { |
- ChromePasswordManagerClient* client = GetClient(); |
- |
- service_->RegisterReceiver(&receiver_); |
- EXPECT_TRUE(client->IsLoggingActive()); |
- service_->UnregisterReceiver(&receiver_); |
- EXPECT_FALSE(client->IsLoggingActive()); |
- |
- // After detaching the logger, no text should be passed. |
- EXPECT_CALL(receiver_, LogSavePasswordProgress(kTestText)).Times(0); |
- client->LogSavePasswordProgress(kTestText); |
-} |
- |
TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressNotifyRenderer) { |
ChromePasswordManagerClient* client = GetClient(); |
bool logging_active = false; |
+ // Ensure the existence of a driver, which will send the IPCs we listen for |
+ // below. |
+ NavigateAndCommit(GURL("about:blank")); |
// Initially, the logging should be off, so no IPC messages. |
EXPECT_FALSE(WasLoggingActivationMessageSent(&logging_active)); |
- service_->RegisterReceiver(&receiver_); |
- EXPECT_TRUE(client->IsLoggingActive()); |
- EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_active)); |
- EXPECT_TRUE(logging_active); |
- |
- service_->UnregisterReceiver(&receiver_); |
- EXPECT_FALSE(client->IsLoggingActive()); |
- EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_active)); |
- EXPECT_FALSE(logging_active); |
-} |
- |
-TEST_F(ChromePasswordManagerClientTest, AnswerToPingsAboutLoggingState_Active) { |
- service_->RegisterReceiver(&receiver_); |
- |
- process()->sink().ClearMessages(); |
- |
- // Ping the client for logging activity update. |
- AutofillHostMsg_PasswordAutofillAgentConstructed msg(0); |
- static_cast<content::WebContentsObserver*>(GetClient())->OnMessageReceived( |
- msg, web_contents()->GetMainFrame()); |
- |
- bool logging_active = false; |
+ client->NotifyDriversAboutLoggingAvailability(true); |
EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_active)); |
EXPECT_TRUE(logging_active); |
- service_->UnregisterReceiver(&receiver_); |
-} |
- |
-TEST_F(ChromePasswordManagerClientTest, |
- AnswerToPingsAboutLoggingState_Inactive) { |
- process()->sink().ClearMessages(); |
- |
- // Ping the client for logging activity update. |
- AutofillHostMsg_PasswordAutofillAgentConstructed msg(0); |
- static_cast<content::WebContentsObserver*>(GetClient())->OnMessageReceived( |
- msg, web_contents()->GetMainFrame()); |
- |
- bool logging_active = true; |
+ client->NotifyDriversAboutLoggingAvailability(false); |
EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_active)); |
EXPECT_FALSE(logging_active); |
} |
@@ -232,18 +151,6 @@ TEST_F(ChromePasswordManagerClientTest, |
EXPECT_FALSE(GetClient()->IsAutomaticPasswordSavingEnabled()); |
} |
-TEST_F(ChromePasswordManagerClientTest, LogToAReceiver) { |
- ChromePasswordManagerClient* client = GetClient(); |
- service_->RegisterReceiver(&receiver_); |
- EXPECT_TRUE(client->IsLoggingActive()); |
- |
- EXPECT_CALL(receiver_, LogSavePasswordProgress(kTestText)).Times(1); |
- client->LogSavePasswordProgress(kTestText); |
- |
- service_->UnregisterReceiver(&receiver_); |
- EXPECT_FALSE(client->IsLoggingActive()); |
-} |
- |
TEST_F(ChromePasswordManagerClientTest, GetPasswordSyncState) { |
ChromePasswordManagerClient* client = GetClient(); |
@@ -404,3 +311,13 @@ TEST_F(ChromePasswordManagerClientTest, GetLastCommittedEntryURL) { |
NavigateAndCommit(kUrl); |
EXPECT_EQ(kUrl, GetClient()->GetLastCommittedEntryURL()); |
} |
+ |
+TEST_F(ChromePasswordManagerClientTest, GetLogRouter) { |
+ EXPECT_TRUE(GetClient()->GetLogRouter()); |
+} |
+ |
+TEST_F(ChromePasswordManagerClientTest, GetLogRouter_WebUI) { |
+ // No router for WebUI. |
+ NavigateAndCommit(GURL("about:password-manager-internals")); |
+ EXPECT_FALSE(GetClient()->GetLogRouter()); |
+} |