X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fchrome%2Fbrowser%2Fpassword_manager%2Fchrome_password_manager_client_unittest.cc;h=304975dcc946f166af83ffa38a6ccedaecb699be;hb=004985e17e624662a4c85c76a7654039dc83f028;hp=6a75ab7421eb17f813b4bab9a27f21395fb3e861;hpb=2f108dbacb161091e42a3479f4e171339b7e7623;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc b/src/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc index 6a75ab7..304975d 100644 --- a/src/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc +++ b/src/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc @@ -2,12 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/command_line.h" + #include "chrome/browser/password_manager/chrome_password_manager_client.h" +#include "chrome/common/chrome_version_info.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 "components/password_manager/core/common/password_manager_switches.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" @@ -16,7 +22,10 @@ using content::WebContents; namespace { -class MockPasswordManagerLogger : public PasswordManagerLogger { +const char kTestText[] = "abcd1234"; + +class MockPasswordManagerLogger + : public password_manager::PasswordManagerLogger { public: MockPasswordManagerLogger() {} @@ -31,31 +40,96 @@ class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness { protected: ChromePasswordManagerClient* GetClient(); + + // 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 logger_; }; void ChromePasswordManagerClientTest::SetUp() { ChromeRenderViewHostTestHarness::SetUp(); - ChromePasswordManagerClient::CreateForWebContents(web_contents()); + ChromePasswordManagerClient::CreateForWebContentsWithAutofillManagerDelegate( + web_contents(), NULL); } ChromePasswordManagerClient* ChromePasswordManagerClientTest::GetClient() { return ChromePasswordManagerClient::FromWebContents(web_contents()); } -TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgress) { +bool ChromePasswordManagerClientTest::WasLoggingActivationMessageSent( + bool* activation_flag) { + const uint32 kMsgID = AutofillMsg_ChangeLoggingState::ID; + const IPC::Message* message = + process()->sink().GetFirstMessageMatching(kMsgID); + if (!message) + return false; + Tuple1 param; + AutofillMsg_ChangeLoggingState::Read(message, ¶m); + *activation_flag = param.a; + process()->sink().ClearMessages(); + return true; +} + +TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressNoLogger) { ChromePasswordManagerClient* client = GetClient(); - testing::StrictMock logger; - const std::string text("abcd1234"); + EXPECT_CALL(logger_, LogSavePasswordProgress(kTestText)).Times(0); // Before attaching the logger, no text should be passed. - client->LogSavePasswordProgress(text); + client->LogSavePasswordProgress(kTestText); + EXPECT_FALSE(client->IsLoggingActive()); +} + +TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressAttachLogger) { + ChromePasswordManagerClient* client = GetClient(); // After attaching the logger, text should be passed. - client->SetLogger(&logger); - EXPECT_CALL(logger, LogSavePasswordProgress(text)).Times(1); - client->LogSavePasswordProgress(text); + client->SetLogger(&logger_); + EXPECT_CALL(logger_, LogSavePasswordProgress(kTestText)).Times(1); + client->LogSavePasswordProgress(kTestText); + EXPECT_TRUE(client->IsLoggingActive()); +} + +TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressDetachLogger) { + ChromePasswordManagerClient* client = GetClient(); - // After detaching the logger, no text should be passed again. + client->SetLogger(&logger_); + // After detaching the logger, no text should be passed. client->SetLogger(NULL); - client->LogSavePasswordProgress(text); + 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); +} + +TEST_F(ChromePasswordManagerClientTest, + IsAutomaticPasswordSavingEnabledDefaultBehaviourTest) { + EXPECT_FALSE(GetClient()->IsAutomaticPasswordSavingEnabled()); +} + +TEST_F(ChromePasswordManagerClientTest, + IsAutomaticPasswordSavingEnabledWhenFlagIsSetTest) { + CommandLine::ForCurrentProcess()->AppendSwitch( + password_manager::switches::kEnableAutomaticPasswordSaving); + if (chrome::VersionInfo::GetChannel() == chrome::VersionInfo::CHANNEL_UNKNOWN) + EXPECT_TRUE(GetClient()->IsAutomaticPasswordSavingEnabled()); + else + EXPECT_FALSE(GetClient()->IsAutomaticPasswordSavingEnabled()); }