Chromium Code Reviews| 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" |
|
vabr (Chromium)
2014/08/22 14:04:32
nit: Since you touch this anyway, please move the
| |
| 6 | |
| 7 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 6 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 8 | 7 |
| 8 #include "base/strings/string16.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "chrome/common/chrome_version_info.h" | 10 #include "chrome/common/chrome_version_info.h" |
| 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 12 #include "components/autofill/content/common/autofill_messages.h" | 13 #include "components/autofill/content/common/autofill_messages.h" |
| 13 #include "components/password_manager/content/browser/password_manager_internals _service_factory.h" | 14 #include "components/password_manager/content/browser/password_manager_internals _service_factory.h" |
| 15 #include "components/password_manager/content/common/credential_manager_messages .h" | |
| 16 #include "components/password_manager/content/common/credential_manager_types.h" | |
| 14 #include "components/password_manager/core/browser/log_receiver.h" | 17 #include "components/password_manager/core/browser/log_receiver.h" |
| 15 #include "components/password_manager/core/browser/password_manager_internals_se rvice.h" | 18 #include "components/password_manager/core/browser/password_manager_internals_se rvice.h" |
| 16 #include "components/password_manager/core/common/password_manager_switches.h" | 19 #include "components/password_manager/core/common/password_manager_switches.h" |
| 17 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
| 18 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/test/mock_render_process_host.h" | 22 #include "content/public/test/mock_render_process_host.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 25 |
| 23 using content::BrowserContext; | 26 using content::BrowserContext; |
| 24 using content::WebContents; | 27 using content::WebContents; |
| 25 | 28 |
| 26 namespace { | 29 namespace { |
| 27 | 30 |
| 28 const char kTestText[] = "abcd1234"; | 31 const char kTestText[] = "abcd1234"; |
| 32 const int kRequestId = 4; | |
| 29 | 33 |
| 30 class MockLogReceiver : public password_manager::LogReceiver { | 34 class MockLogReceiver : public password_manager::LogReceiver { |
| 31 public: | 35 public: |
| 32 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); | 36 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); |
| 33 }; | 37 }; |
| 34 | 38 |
| 35 class TestChromePasswordManagerClient : public ChromePasswordManagerClient { | 39 class TestChromePasswordManagerClient : public ChromePasswordManagerClient { |
| 36 public: | 40 public: |
| 37 explicit TestChromePasswordManagerClient(content::WebContents* web_contents) | 41 explicit TestChromePasswordManagerClient(content::WebContents* web_contents) |
| 38 : ChromePasswordManagerClient(web_contents, NULL), | 42 : ChromePasswordManagerClient(web_contents, NULL), |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 | 263 |
| 260 // Adding disallow switch should cause sync credential to be filtered. | 264 // Adding disallow switch should cause sync credential to be filtered. |
| 261 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 265 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 262 command_line->AppendSwitch( | 266 command_line->AppendSwitch( |
| 263 password_manager::switches::kDisallowAutofillSyncCredential); | 267 password_manager::switches::kDisallowAutofillSyncCredential); |
| 264 client.reset(new TestChromePasswordManagerClient(web_contents())); | 268 client.reset(new TestChromePasswordManagerClient(web_contents())); |
| 265 client->set_is_sync_account_credential(true); | 269 client->set_is_sync_account_credential(true); |
| 266 NavigateAndCommit(GURL("https://accounts.google.com/Login")); | 270 NavigateAndCommit(GURL("https://accounts.google.com/Login")); |
| 267 EXPECT_TRUE(client->ShouldFilterAutofillResult(form)); | 271 EXPECT_TRUE(client->ShouldFilterAutofillResult(form)); |
| 268 } | 272 } |
| 273 | |
| 274 TEST_F(ChromePasswordManagerClientTest, CredentialManagerOnNotifyFailedSignIn) { | |
| 275 scoped_ptr<TestChromePasswordManagerClient> client( | |
| 276 new TestChromePasswordManagerClient(web_contents())); | |
| 277 | |
| 278 password_manager::CredentialInfo info(base::ASCIIToUTF16("id"), | |
| 279 base::ASCIIToUTF16("name"), | |
| 280 GURL("https://example.com/image.png")); | |
| 281 client->OnNotifyFailedSignIn(kRequestId, info); | |
| 282 | |
| 283 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; | |
| 284 const IPC::Message* message = | |
| 285 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 286 EXPECT_TRUE(!!message); | |
|
vabr (Chromium)
2014/08/22 14:04:32
nit: I'm surprised you need to "!!" this -- pointe
| |
| 287 process()->sink().ClearMessages(); | |
| 288 } | |
| 289 | |
| 290 TEST_F(ChromePasswordManagerClientTest, CredentialManagerOnNotifySignedIn) { | |
| 291 scoped_ptr<TestChromePasswordManagerClient> client( | |
| 292 new TestChromePasswordManagerClient(web_contents())); | |
| 293 | |
| 294 password_manager::CredentialInfo info(base::ASCIIToUTF16("id"), | |
| 295 base::ASCIIToUTF16("name"), | |
| 296 GURL("https://example.com/image.png")); | |
| 297 client->OnNotifySignedIn(kRequestId, info); | |
| 298 | |
| 299 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID; | |
| 300 const IPC::Message* message = | |
| 301 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 302 EXPECT_TRUE(!!message); | |
| 303 process()->sink().ClearMessages(); | |
| 304 } | |
| 305 | |
| 306 TEST_F(ChromePasswordManagerClientTest, CredentialManagerOnNotifySignedOut) { | |
| 307 scoped_ptr<TestChromePasswordManagerClient> client( | |
| 308 new TestChromePasswordManagerClient(web_contents())); | |
| 309 | |
| 310 client->OnNotifySignedOut(kRequestId); | |
| 311 | |
| 312 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedOut::ID; | |
| 313 const IPC::Message* message = | |
| 314 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 315 EXPECT_TRUE(!!message); | |
| 316 process()->sink().ClearMessages(); | |
| 317 } | |
| 318 | |
| 319 TEST_F(ChromePasswordManagerClientTest, CredentialManagerOnRequestCredential) { | |
| 320 scoped_ptr<TestChromePasswordManagerClient> client( | |
| 321 new TestChromePasswordManagerClient(web_contents())); | |
| 322 | |
| 323 std::vector<GURL> federations; | |
| 324 client->OnRequestCredential(kRequestId, false, federations); | |
| 325 | |
| 326 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | |
| 327 const IPC::Message* message = | |
| 328 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 329 EXPECT_TRUE(!!message); | |
| 330 process()->sink().ClearMessages(); | |
| 331 } | |
| OLD | NEW |