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 "chrome/browser/password_manager/chrome_password_manager_client.h" | 5 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/common/chrome_version_info.h" | 10 #include "chrome/common/chrome_version_info.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "content/public/test/mock_render_process_host.h" | 22 #include "content/public/test/mock_render_process_host.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 | 25 |
26 using content::BrowserContext; | 26 using content::BrowserContext; |
27 using content::WebContents; | 27 using content::WebContents; |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 const char kTestText[] = "abcd1234"; | 31 const char kTestText[] = "abcd1234"; |
32 const int kRequestId = 4; | |
33 | 32 |
34 class MockLogReceiver : public password_manager::LogReceiver { | 33 class MockLogReceiver : public password_manager::LogReceiver { |
35 public: | 34 public: |
36 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); | 35 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); |
37 }; | 36 }; |
38 | 37 |
39 class TestChromePasswordManagerClient : public ChromePasswordManagerClient { | 38 class TestChromePasswordManagerClient : public ChromePasswordManagerClient { |
40 public: | 39 public: |
41 explicit TestChromePasswordManagerClient(content::WebContents* web_contents) | 40 explicit TestChromePasswordManagerClient(content::WebContents* web_contents) |
42 : ChromePasswordManagerClient(web_contents, NULL), | 41 : ChromePasswordManagerClient(web_contents, NULL), |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 GURL("https://accounts.google.com/ServiceLogin?continue=" | 323 GURL("https://accounts.google.com/ServiceLogin?continue=" |
325 "https://mail.google.com&rart=234")); | 324 "https://mail.google.com&rart=234")); |
326 EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage()); | 325 EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage()); |
327 | 326 |
328 // Reauth pages are only on accounts.google.com | 327 // Reauth pages are only on accounts.google.com |
329 NavigateAndCommit( | 328 NavigateAndCommit( |
330 GURL("https://other.site.com/ServiceLogin?continue=" | 329 GURL("https://other.site.com/ServiceLogin?continue=" |
331 "https://passwords.google.com&rart=234")); | 330 "https://passwords.google.com&rart=234")); |
332 EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage()); | 331 EXPECT_TRUE(client->IsPasswordManagerEnabledForCurrentPage()); |
333 } | 332 } |
334 | |
335 TEST_F(ChromePasswordManagerClientTest, CredentialManagerOnNotifyFailedSignIn) { | |
336 scoped_ptr<TestChromePasswordManagerClient> client( | |
337 new TestChromePasswordManagerClient(web_contents())); | |
338 | |
339 password_manager::CredentialInfo info(base::ASCIIToUTF16("id"), | |
340 base::ASCIIToUTF16("name"), | |
341 GURL("https://example.com/image.png")); | |
342 client->OnNotifyFailedSignIn(kRequestId, info); | |
343 | |
344 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; | |
345 const IPC::Message* message = | |
346 process()->sink().GetFirstMessageMatching(kMsgID); | |
347 EXPECT_TRUE(message); | |
348 process()->sink().ClearMessages(); | |
349 } | |
350 | |
351 TEST_F(ChromePasswordManagerClientTest, CredentialManagerOnNotifySignedIn) { | |
352 scoped_ptr<TestChromePasswordManagerClient> client( | |
353 new TestChromePasswordManagerClient(web_contents())); | |
354 | |
355 password_manager::CredentialInfo info(base::ASCIIToUTF16("id"), | |
356 base::ASCIIToUTF16("name"), | |
357 GURL("https://example.com/image.png")); | |
358 client->OnNotifySignedIn(kRequestId, info); | |
359 | |
360 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID; | |
361 const IPC::Message* message = | |
362 process()->sink().GetFirstMessageMatching(kMsgID); | |
363 EXPECT_TRUE(message); | |
364 process()->sink().ClearMessages(); | |
365 } | |
366 | |
367 TEST_F(ChromePasswordManagerClientTest, CredentialManagerOnNotifySignedOut) { | |
368 scoped_ptr<TestChromePasswordManagerClient> client( | |
369 new TestChromePasswordManagerClient(web_contents())); | |
370 | |
371 client->OnNotifySignedOut(kRequestId); | |
372 | |
373 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedOut::ID; | |
374 const IPC::Message* message = | |
375 process()->sink().GetFirstMessageMatching(kMsgID); | |
376 EXPECT_TRUE(message); | |
377 process()->sink().ClearMessages(); | |
378 } | |
379 | |
380 TEST_F(ChromePasswordManagerClientTest, CredentialManagerOnRequestCredential) { | |
381 scoped_ptr<TestChromePasswordManagerClient> client( | |
382 new TestChromePasswordManagerClient(web_contents())); | |
383 | |
384 std::vector<GURL> federations; | |
385 client->OnRequestCredential(kRequestId, false, federations); | |
386 | |
387 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | |
388 const IPC::Message* message = | |
389 process()->sink().GetFirstMessageMatching(kMsgID); | |
390 EXPECT_TRUE(message); | |
391 process()->sink().ClearMessages(); | |
392 } | |
OLD | NEW |