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

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

Issue 231283003: Password manager: introduce logging for the internals page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed Created 6 years, 8 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: 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 7c41f7e3f56395b9eb903add4eaf392bf7ed25e0..8507676d998825074c4da1b99c06004bdd4b755a 100644
--- a/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc
+++ b/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc
@@ -5,9 +5,11 @@
#include "chrome/browser/password_manager/chrome_password_manager_client.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
+#include "components/autofill/content/common/autofill_messages.h"
#include "components/password_manager/core/browser/password_manager_logger.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/test/mock_render_process_host.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -35,7 +37,12 @@ class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness {
protected:
ChromePasswordManagerClient* GetClient();
- testing::StrictMock<MockPasswordManagerLogger> logger;
+ // If the test IPC sink contains an AutofillMsg_ChangeLoggingState message,
+ // then copies its argument into |activation_flag| and returns true. Otherwise
+ // returns false.
+ bool WasLoggingActivationMessageSent(bool* activation_flag);
+
+ testing::StrictMock<MockPasswordManagerLogger> logger_;
};
void ChromePasswordManagerClientTest::SetUp() {
@@ -47,10 +54,24 @@ ChromePasswordManagerClient* ChromePasswordManagerClientTest::GetClient() {
return ChromePasswordManagerClient::FromWebContents(web_contents());
}
+bool ChromePasswordManagerClientTest::WasLoggingActivationMessageSent(
+ bool* activation_flag) {
+ const uint32 kMsgID = AutofillMsg_ChangeLoggingState::ID;
Ilya Sherman 2014/04/23 20:21:44 nit: De-indent this line and all of the other line
vabr (Chromium) 2014/04/24 10:59:27 Done.
+ const IPC::Message* message =
+ process()->sink().GetFirstMessageMatching(kMsgID);
+ if (!message)
+ return false;
+ Tuple1<bool> param;
+ AutofillMsg_ChangeLoggingState::Read(message, &param);
+ *activation_flag = param.a;
+ process()->sink().ClearMessages();
+ return true;
+}
+
TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressNoLogger) {
ChromePasswordManagerClient* client = GetClient();
- EXPECT_CALL(logger, LogSavePasswordProgress(kTestText)).Times(0);
+ EXPECT_CALL(logger_, LogSavePasswordProgress(kTestText)).Times(0);
// Before attaching the logger, no text should be passed.
client->LogSavePasswordProgress(kTestText);
EXPECT_FALSE(client->IsLoggingActive());
@@ -60,8 +81,8 @@ TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressAttachLogger) {
ChromePasswordManagerClient* client = GetClient();
// After attaching the logger, text should be passed.
- client->SetLogger(&logger);
- EXPECT_CALL(logger, LogSavePasswordProgress(kTestText)).Times(1);
+ client->SetLogger(&logger_);
+ EXPECT_CALL(logger_, LogSavePasswordProgress(kTestText)).Times(1);
client->LogSavePasswordProgress(kTestText);
EXPECT_TRUE(client->IsLoggingActive());
}
@@ -69,10 +90,26 @@ TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressAttachLogger) {
TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressDetachLogger) {
ChromePasswordManagerClient* client = GetClient();
- client->SetLogger(&logger);
+ client->SetLogger(&logger_);
// After detaching the logger, no text should be passed.
client->SetLogger(NULL);
- EXPECT_CALL(logger, LogSavePasswordProgress(kTestText)).Times(0);
+ EXPECT_CALL(logger_, LogSavePasswordProgress(kTestText)).Times(0);
client->LogSavePasswordProgress(kTestText);
EXPECT_FALSE(client->IsLoggingActive());
}
+
+TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressNotifyRenderer) {
+ ChromePasswordManagerClient* client = GetClient();
+ bool logging_active = false;
+
+ // Initially, the logging should be off, so no IPC messages.
+ EXPECT_FALSE(WasLoggingActivationMessageSent(&logging_active));
+
+ client->SetLogger(&logger_);
+ EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_active));
+ EXPECT_TRUE(logging_active);
+
+ client->SetLogger(NULL);
+ EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_active));
+ EXPECT_FALSE(logging_active);
+}

Powered by Google App Engine
This is Rietveld 408576698