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" | |
6 | |
7 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 5 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
8 | 6 |
| 7 #include "base/command_line.h" |
| 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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 GURL("https://accounts.google.com/ServiceLogin?continue=" | 318 GURL("https://accounts.google.com/ServiceLogin?continue=" |
315 "https://mail.google.com&rart=234")); | 319 "https://mail.google.com&rart=234")); |
316 EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage()); | 320 EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage()); |
317 | 321 |
318 // Reauth pages are only on accounts.google.com | 322 // Reauth pages are only on accounts.google.com |
319 NavigateAndCommit( | 323 NavigateAndCommit( |
320 GURL("https://other.site.com/ServiceLogin?continue=" | 324 GURL("https://other.site.com/ServiceLogin?continue=" |
321 "https://passwords.google.com&rart=234")); | 325 "https://passwords.google.com&rart=234")); |
322 EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage()); | 326 EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage()); |
323 } | 327 } |
| 328 |
| 329 TEST_F(ChromePasswordManagerClientTest, CredentialManagerOnNotifyFailedSignIn) { |
| 330 scoped_ptr<TestChromePasswordManagerClient> client( |
| 331 new TestChromePasswordManagerClient(web_contents())); |
| 332 |
| 333 password_manager::CredentialInfo info(base::ASCIIToUTF16("id"), |
| 334 base::ASCIIToUTF16("name"), |
| 335 GURL("https://example.com/image.png")); |
| 336 client->OnNotifyFailedSignIn(kRequestId, info); |
| 337 |
| 338 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; |
| 339 const IPC::Message* message = |
| 340 process()->sink().GetFirstMessageMatching(kMsgID); |
| 341 EXPECT_TRUE(message); |
| 342 process()->sink().ClearMessages(); |
| 343 } |
| 344 |
| 345 TEST_F(ChromePasswordManagerClientTest, CredentialManagerOnNotifySignedIn) { |
| 346 scoped_ptr<TestChromePasswordManagerClient> client( |
| 347 new TestChromePasswordManagerClient(web_contents())); |
| 348 |
| 349 password_manager::CredentialInfo info(base::ASCIIToUTF16("id"), |
| 350 base::ASCIIToUTF16("name"), |
| 351 GURL("https://example.com/image.png")); |
| 352 client->OnNotifySignedIn(kRequestId, info); |
| 353 |
| 354 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID; |
| 355 const IPC::Message* message = |
| 356 process()->sink().GetFirstMessageMatching(kMsgID); |
| 357 EXPECT_TRUE(message); |
| 358 process()->sink().ClearMessages(); |
| 359 } |
| 360 |
| 361 TEST_F(ChromePasswordManagerClientTest, CredentialManagerOnNotifySignedOut) { |
| 362 scoped_ptr<TestChromePasswordManagerClient> client( |
| 363 new TestChromePasswordManagerClient(web_contents())); |
| 364 |
| 365 client->OnNotifySignedOut(kRequestId); |
| 366 |
| 367 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedOut::ID; |
| 368 const IPC::Message* message = |
| 369 process()->sink().GetFirstMessageMatching(kMsgID); |
| 370 EXPECT_TRUE(message); |
| 371 process()->sink().ClearMessages(); |
| 372 } |
| 373 |
| 374 TEST_F(ChromePasswordManagerClientTest, CredentialManagerOnRequestCredential) { |
| 375 scoped_ptr<TestChromePasswordManagerClient> client( |
| 376 new TestChromePasswordManagerClient(web_contents())); |
| 377 |
| 378 std::vector<GURL> federations; |
| 379 client->OnRequestCredential(kRequestId, false, federations); |
| 380 |
| 381 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 382 const IPC::Message* message = |
| 383 process()->sink().GetFirstMessageMatching(kMsgID); |
| 384 EXPECT_TRUE(message); |
| 385 process()->sink().ClearMessages(); |
| 386 } |
OLD | NEW |