Index: components/password_manager/content/browser/content_password_manager_driver_unittest.cc |
diff --git a/components/password_manager/content/browser/content_password_manager_driver_unittest.cc b/components/password_manager/content/browser/content_password_manager_driver_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7154fa8a211617fbc4a9cad64212001bdf934517 |
--- /dev/null |
+++ b/components/password_manager/content/browser/content_password_manager_driver_unittest.cc |
@@ -0,0 +1,78 @@ |
+// Copyright 2015 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 "components/password_manager/content/browser/content_password_manager_driver.h" |
+ |
+#include "components/autofill/content/common/autofill_messages.h" |
+#include "components/autofill/core/browser/test_autofill_client.h" |
+#include "components/password_manager/core/browser/stub_password_manager_client.h" |
+#include "content/public/test/mock_render_process_host.h" |
+#include "content/public/test/test_renderer_host.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace password_manager { |
+ |
+class ContentPasswordManagerDriverTest |
+ : public content::RenderViewHostTestHarness, |
+ public testing::WithParamInterface<bool> { |
+ public: |
+ bool WasLoggingActivationMessageSent(bool* activation_flag) { |
+ const uint32 kMsgID = AutofillMsg_SetLoggingState::ID; |
+ const IPC::Message* message = |
+ process()->sink().GetFirstMessageMatching(kMsgID); |
+ if (!message) |
+ return false; |
+ base::Tuple<bool> param; |
+ AutofillMsg_SetLoggingState::Read(message, ¶m); |
+ *activation_flag = base::get<0>(param); |
+ process()->sink().ClearMessages(); |
+ return true; |
+ } |
+ |
+ protected: |
+ StubPasswordManagerClient password_manager_client_; |
+ autofill::TestAutofillClient autofill_client_; |
+}; |
+ |
+TEST_P(ContentPasswordManagerDriverTest, |
+ AnswerToNotificationsAboutLoggingState) { |
+ const bool should_allow_logging = GetParam(); |
+ scoped_ptr<ContentPasswordManagerDriver> driver( |
+ new ContentPasswordManagerDriver(main_rfh(), &password_manager_client_, |
+ &autofill_client_)); |
+ process()->sink().ClearMessages(); |
+ |
+ driver->NotifyAboutLoggingAvailability(should_allow_logging); |
+ if (should_allow_logging) { |
+ bool logging_activated = false; |
+ EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_activated)); |
+ EXPECT_TRUE(logging_activated); |
+ } else { |
+ EXPECT_FALSE(WasLoggingActivationMessageSent(nullptr)); |
+ } |
+} |
+ |
+TEST_P(ContentPasswordManagerDriverTest, AnswerToIPCPingsAboutLoggingState) { |
+ const bool should_allow_logging = GetParam(); |
+ scoped_ptr<ContentPasswordManagerDriver> driver( |
+ new ContentPasswordManagerDriver(main_rfh(), &password_manager_client_, |
+ &autofill_client_)); |
+ |
+ driver->NotifyAboutLoggingAvailability(should_allow_logging); |
+ process()->sink().ClearMessages(); |
+ |
+ // Ping the driver for logging activity update. |
+ AutofillHostMsg_PasswordAutofillAgentConstructed msg(0); |
+ driver->HandleMessage(msg); |
+ |
+ bool logging_activated = false; |
+ EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_activated)); |
+ EXPECT_EQ(logging_activated, logging_activated); |
vasilii
2015/11/12 16:27:34
That's a very reliable check :-)
vabr (Chromium)
2015/11/12 21:55:43
:D
Good catch!
Fixed.
|
+} |
+ |
+INSTANTIATE_TEST_CASE_P(, |
+ ContentPasswordManagerDriverTest, |
+ testing::Values(true, false)); |
+ |
+} // namespace password_manager |