| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 | 6 |
| 7 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 7 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 8 | 8 |
| 9 #include "chrome/common/chrome_version_info.h" | 9 #include "chrome/common/chrome_version_info.h" |
| 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness { | 37 class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness { |
| 38 public: | 38 public: |
| 39 ChromePasswordManagerClientTest(); | 39 ChromePasswordManagerClientTest(); |
| 40 | 40 |
| 41 virtual void SetUp() OVERRIDE; | 41 virtual void SetUp() OVERRIDE; |
| 42 | 42 |
| 43 protected: | 43 protected: |
| 44 ChromePasswordManagerClient* GetClient(); | 44 ChromePasswordManagerClient* GetClient(); |
| 45 | 45 |
| 46 // If the test IPC sink contains an AutofillMsg_ChangeLoggingState message, | 46 // If the test IPC sink contains an AutofillMsg_SetLoggingState message, then |
| 47 // then copies its argument into |activation_flag| and returns true. Otherwise | 47 // copies its argument into |activation_flag| and returns true. Otherwise |
| 48 // returns false. | 48 // returns false. |
| 49 bool WasLoggingActivationMessageSent(bool* activation_flag); | 49 bool WasLoggingActivationMessageSent(bool* activation_flag); |
| 50 | 50 |
| 51 password_manager::PasswordManagerInternalsService* service_; | 51 password_manager::PasswordManagerInternalsService* service_; |
| 52 | 52 |
| 53 testing::StrictMock<MockLogReceiver> receiver_; | 53 testing::StrictMock<MockLogReceiver> receiver_; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 ChromePasswordManagerClientTest::ChromePasswordManagerClientTest() | 56 ChromePasswordManagerClientTest::ChromePasswordManagerClientTest() |
| 57 : service_(NULL) { | 57 : service_(NULL) { |
| 58 } | 58 } |
| 59 | 59 |
| 60 void ChromePasswordManagerClientTest::SetUp() { | 60 void ChromePasswordManagerClientTest::SetUp() { |
| 61 ChromeRenderViewHostTestHarness::SetUp(); | 61 ChromeRenderViewHostTestHarness::SetUp(); |
| 62 ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( | 62 ChromePasswordManagerClient::CreateForWebContentsWithAutofillClient( |
| 63 web_contents(), NULL); | 63 web_contents(), NULL); |
| 64 service_ = password_manager::PasswordManagerInternalsServiceFactory:: | 64 service_ = password_manager::PasswordManagerInternalsServiceFactory:: |
| 65 GetForBrowserContext(profile()); | 65 GetForBrowserContext(profile()); |
| 66 ASSERT_TRUE(service_); | 66 ASSERT_TRUE(service_); |
| 67 } | 67 } |
| 68 | 68 |
| 69 ChromePasswordManagerClient* ChromePasswordManagerClientTest::GetClient() { | 69 ChromePasswordManagerClient* ChromePasswordManagerClientTest::GetClient() { |
| 70 return ChromePasswordManagerClient::FromWebContents(web_contents()); | 70 return ChromePasswordManagerClient::FromWebContents(web_contents()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 bool ChromePasswordManagerClientTest::WasLoggingActivationMessageSent( | 73 bool ChromePasswordManagerClientTest::WasLoggingActivationMessageSent( |
| 74 bool* activation_flag) { | 74 bool* activation_flag) { |
| 75 const uint32 kMsgID = AutofillMsg_ChangeLoggingState::ID; | 75 const uint32 kMsgID = AutofillMsg_SetLoggingState::ID; |
| 76 const IPC::Message* message = | 76 const IPC::Message* message = |
| 77 process()->sink().GetFirstMessageMatching(kMsgID); | 77 process()->sink().GetFirstMessageMatching(kMsgID); |
| 78 if (!message) | 78 if (!message) |
| 79 return false; | 79 return false; |
| 80 Tuple1<bool> param; | 80 Tuple1<bool> param; |
| 81 AutofillMsg_ChangeLoggingState::Read(message, ¶m); | 81 AutofillMsg_SetLoggingState::Read(message, ¶m); |
| 82 *activation_flag = param.a; | 82 *activation_flag = param.a; |
| 83 process()->sink().ClearMessages(); | 83 process()->sink().ClearMessages(); |
| 84 return true; | 84 return true; |
| 85 } | 85 } |
| 86 | 86 |
| 87 TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressNoReceiver) { | 87 TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressNoReceiver) { |
| 88 ChromePasswordManagerClient* client = GetClient(); | 88 ChromePasswordManagerClient* client = GetClient(); |
| 89 | 89 |
| 90 EXPECT_CALL(receiver_, LogSavePasswordProgress(kTestText)).Times(0); | 90 EXPECT_CALL(receiver_, LogSavePasswordProgress(kTestText)).Times(0); |
| 91 // Before attaching the receiver, no text should be passed. | 91 // Before attaching the receiver, no text should be passed. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 EXPECT_TRUE(client->IsLoggingActive()); | 130 EXPECT_TRUE(client->IsLoggingActive()); |
| 131 EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_active)); | 131 EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_active)); |
| 132 EXPECT_TRUE(logging_active); | 132 EXPECT_TRUE(logging_active); |
| 133 | 133 |
| 134 service_->UnregisterReceiver(&receiver_); | 134 service_->UnregisterReceiver(&receiver_); |
| 135 EXPECT_FALSE(client->IsLoggingActive()); | 135 EXPECT_FALSE(client->IsLoggingActive()); |
| 136 EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_active)); | 136 EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_active)); |
| 137 EXPECT_FALSE(logging_active); | 137 EXPECT_FALSE(logging_active); |
| 138 } | 138 } |
| 139 | 139 |
| 140 TEST_F(ChromePasswordManagerClientTest, AnswerToPingsAboutLoggingState_Active) { |
| 141 service_->RegisterReceiver(&receiver_); |
| 142 |
| 143 process()->sink().ClearMessages(); |
| 144 |
| 145 // Ping the client for logging activity update. |
| 146 AutofillHostMsg_PasswordAutofillAgentConstructed msg(0); |
| 147 static_cast<IPC::Listener*>(GetClient())->OnMessageReceived(msg); |
| 148 |
| 149 bool logging_active = false; |
| 150 EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_active)); |
| 151 EXPECT_TRUE(logging_active); |
| 152 |
| 153 service_->UnregisterReceiver(&receiver_); |
| 154 } |
| 155 |
| 156 TEST_F(ChromePasswordManagerClientTest, |
| 157 AnswerToPingsAboutLoggingState_Inactive) { |
| 158 process()->sink().ClearMessages(); |
| 159 |
| 160 // Ping the client for logging activity update. |
| 161 AutofillHostMsg_PasswordAutofillAgentConstructed msg(0); |
| 162 static_cast<IPC::Listener*>(GetClient())->OnMessageReceived(msg); |
| 163 |
| 164 bool logging_active = true; |
| 165 EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_active)); |
| 166 EXPECT_FALSE(logging_active); |
| 167 } |
| 168 |
| 140 TEST_F(ChromePasswordManagerClientTest, | 169 TEST_F(ChromePasswordManagerClientTest, |
| 141 IsAutomaticPasswordSavingEnabledDefaultBehaviourTest) { | 170 IsAutomaticPasswordSavingEnabledDefaultBehaviourTest) { |
| 142 EXPECT_FALSE(GetClient()->IsAutomaticPasswordSavingEnabled()); | 171 EXPECT_FALSE(GetClient()->IsAutomaticPasswordSavingEnabled()); |
| 143 } | 172 } |
| 144 | 173 |
| 145 TEST_F(ChromePasswordManagerClientTest, | 174 TEST_F(ChromePasswordManagerClientTest, |
| 146 IsAutomaticPasswordSavingEnabledWhenFlagIsSetTest) { | 175 IsAutomaticPasswordSavingEnabledWhenFlagIsSetTest) { |
| 147 CommandLine::ForCurrentProcess()->AppendSwitch( | 176 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 148 password_manager::switches::kEnableAutomaticPasswordSaving); | 177 password_manager::switches::kEnableAutomaticPasswordSaving); |
| 149 if (chrome::VersionInfo::GetChannel() == chrome::VersionInfo::CHANNEL_UNKNOWN) | 178 if (chrome::VersionInfo::GetChannel() == chrome::VersionInfo::CHANNEL_UNKNOWN) |
| 150 EXPECT_TRUE(GetClient()->IsAutomaticPasswordSavingEnabled()); | 179 EXPECT_TRUE(GetClient()->IsAutomaticPasswordSavingEnabled()); |
| 151 else | 180 else |
| 152 EXPECT_FALSE(GetClient()->IsAutomaticPasswordSavingEnabled()); | 181 EXPECT_FALSE(GetClient()->IsAutomaticPasswordSavingEnabled()); |
| 153 } | 182 } |
| 154 | 183 |
| 155 TEST_F(ChromePasswordManagerClientTest, LogToAReceiver) { | 184 TEST_F(ChromePasswordManagerClientTest, LogToAReceiver) { |
| 156 ChromePasswordManagerClient* client = GetClient(); | 185 ChromePasswordManagerClient* client = GetClient(); |
| 157 service_->RegisterReceiver(&receiver_); | 186 service_->RegisterReceiver(&receiver_); |
| 158 EXPECT_TRUE(client->IsLoggingActive()); | 187 EXPECT_TRUE(client->IsLoggingActive()); |
| 159 | 188 |
| 160 EXPECT_CALL(receiver_, LogSavePasswordProgress(kTestText)).Times(1); | 189 EXPECT_CALL(receiver_, LogSavePasswordProgress(kTestText)).Times(1); |
| 161 client->LogSavePasswordProgress(kTestText); | 190 client->LogSavePasswordProgress(kTestText); |
| 162 | 191 |
| 163 service_->UnregisterReceiver(&receiver_); | 192 service_->UnregisterReceiver(&receiver_); |
| 164 EXPECT_FALSE(client->IsLoggingActive()); | 193 EXPECT_FALSE(client->IsLoggingActive()); |
| 165 } | 194 } |
| OLD | NEW |