| 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 "components/password_manager/content/browser/content_credential_manager
_dispatcher.h" | 5 #include "components/password_manager/content/browser/content_credential_manager
_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/run_loop.h" |
| 8 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/password_manager/content/common/credential_manager_messages
.h" | 11 #include "components/password_manager/content/common/credential_manager_messages
.h" |
| 11 #include "components/password_manager/content/common/credential_manager_types.h" | 12 #include "components/password_manager/content/common/credential_manager_types.h" |
| 13 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
| 14 #include "components/password_manager/core/browser/test_password_store.h" |
| 12 #include "content/public/test/mock_render_process_host.h" | 15 #include "content/public/test/mock_render_process_host.h" |
| 13 #include "content/public/test/test_renderer_host.h" | 16 #include "content/public/test/test_renderer_host.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 19 |
| 17 using content::BrowserContext; | 20 using content::BrowserContext; |
| 18 using content::WebContents; | 21 using content::WebContents; |
| 19 | 22 |
| 20 namespace { | 23 namespace { |
| 21 | 24 |
| 22 // Chosen by fair dice roll. Guaranteed to be random. | 25 // Chosen by fair dice roll. Guaranteed to be random. |
| 23 const int kRequestId = 4; | 26 const int kRequestId = 4; |
| 24 | 27 |
| 28 class TestPasswordManagerClient |
| 29 : public password_manager::StubPasswordManagerClient { |
| 30 public: |
| 31 TestPasswordManagerClient(password_manager::PasswordStore* store) |
| 32 : store_(store) {} |
| 33 virtual ~TestPasswordManagerClient() {} |
| 34 |
| 35 virtual password_manager::PasswordStore* GetPasswordStore() OVERRIDE { |
| 36 return store_; |
| 37 } |
| 38 |
| 39 private: |
| 40 password_manager::PasswordStore* store_; |
| 41 }; |
| 42 |
| 43 void RunAllPendingTasks() { |
| 44 base::RunLoop run_loop; |
| 45 base::MessageLoop::current()->PostTask( |
| 46 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 47 run_loop.Run(); |
| 48 } |
| 49 |
| 25 } // namespace | 50 } // namespace |
| 26 | 51 |
| 27 namespace password_manager { | 52 namespace password_manager { |
| 28 | 53 |
| 29 class ContentCredentialManagerDispatcherTest | 54 class ContentCredentialManagerDispatcherTest |
| 30 : public content::RenderViewHostTestHarness { | 55 : public content::RenderViewHostTestHarness { |
| 31 public: | 56 public: |
| 32 ContentCredentialManagerDispatcherTest() {} | 57 ContentCredentialManagerDispatcherTest() {} |
| 33 | 58 |
| 34 virtual void SetUp() OVERRIDE { | 59 virtual void SetUp() OVERRIDE { |
| 35 content::RenderViewHostTestHarness::SetUp(); | 60 content::RenderViewHostTestHarness::SetUp(); |
| 61 store_ = new TestPasswordStore; |
| 62 client_.reset(new TestPasswordManagerClient(store_.get())); |
| 36 dispatcher_.reset( | 63 dispatcher_.reset( |
| 37 new ContentCredentialManagerDispatcher(web_contents(), nullptr)); | 64 new ContentCredentialManagerDispatcher(web_contents(), client_.get())); |
| 65 } |
| 66 |
| 67 virtual void TearDown() OVERRIDE { |
| 68 store_->Shutdown(); |
| 69 content::RenderViewHostTestHarness::TearDown(); |
| 38 } | 70 } |
| 39 | 71 |
| 40 ContentCredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } | 72 ContentCredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } |
| 41 | 73 |
| 42 private: | 74 private: |
| 75 scoped_refptr<TestPasswordStore> store_; |
| 43 scoped_ptr<ContentCredentialManagerDispatcher> dispatcher_; | 76 scoped_ptr<ContentCredentialManagerDispatcher> dispatcher_; |
| 77 scoped_ptr<TestPasswordManagerClient> client_; |
| 44 }; | 78 }; |
| 45 | 79 |
| 46 TEST_F(ContentCredentialManagerDispatcherTest, | 80 TEST_F(ContentCredentialManagerDispatcherTest, |
| 47 CredentialManagerOnNotifyFailedSignIn) { | 81 CredentialManagerOnNotifyFailedSignIn) { |
| 48 CredentialInfo info(base::ASCIIToUTF16("id"), | 82 CredentialInfo info(base::ASCIIToUTF16("id"), |
| 49 base::ASCIIToUTF16("name"), | 83 base::ASCIIToUTF16("name"), |
| 50 GURL("https://example.com/image.png")); | 84 GURL("https://example.com/image.png")); |
| 51 dispatcher()->OnNotifyFailedSignIn(kRequestId, info); | 85 dispatcher()->OnNotifyFailedSignIn(kRequestId, info); |
| 52 | 86 |
| 53 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; | 87 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 80 process()->sink().GetFirstMessageMatching(kMsgID); | 114 process()->sink().GetFirstMessageMatching(kMsgID); |
| 81 EXPECT_TRUE(message); | 115 EXPECT_TRUE(message); |
| 82 process()->sink().ClearMessages(); | 116 process()->sink().ClearMessages(); |
| 83 } | 117 } |
| 84 | 118 |
| 85 TEST_F(ContentCredentialManagerDispatcherTest, | 119 TEST_F(ContentCredentialManagerDispatcherTest, |
| 86 CredentialManagerOnRequestCredential) { | 120 CredentialManagerOnRequestCredential) { |
| 87 std::vector<GURL> federations; | 121 std::vector<GURL> federations; |
| 88 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 122 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 89 | 123 |
| 124 RunAllPendingTasks(); |
| 125 |
| 90 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 126 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 91 const IPC::Message* message = | 127 const IPC::Message* message = |
| 92 process()->sink().GetFirstMessageMatching(kMsgID); | 128 process()->sink().GetFirstMessageMatching(kMsgID); |
| 93 EXPECT_TRUE(message); | 129 EXPECT_TRUE(message); |
| 94 process()->sink().ClearMessages(); | 130 process()->sink().ClearMessages(); |
| 95 } | 131 } |
| 96 | 132 |
| 97 } // namespace password_manager | 133 } // namespace password_manager |
| OLD | NEW |