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/run_loop.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "components/password_manager/content/common/credential_manager_messages
.h" | 11 #include "components/password_manager/content/common/credential_manager_messages
.h" |
12 #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" | 13 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
14 #include "components/password_manager/core/browser/test_password_store.h" | 14 #include "components/password_manager/core/browser/test_password_store.h" |
| 15 #include "content/public/browser/web_contents.h" |
15 #include "content/public/test/mock_render_process_host.h" | 16 #include "content/public/test/mock_render_process_host.h" |
16 #include "content/public/test/test_renderer_host.h" | 17 #include "content/public/test/test_renderer_host.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 using content::BrowserContext; | 21 using content::BrowserContext; |
21 using content::WebContents; | 22 using content::WebContents; |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
(...skipping 30 matching lines...) Expand all Loading... |
55 : public content::RenderViewHostTestHarness { | 56 : public content::RenderViewHostTestHarness { |
56 public: | 57 public: |
57 ContentCredentialManagerDispatcherTest() {} | 58 ContentCredentialManagerDispatcherTest() {} |
58 | 59 |
59 virtual void SetUp() override { | 60 virtual void SetUp() override { |
60 content::RenderViewHostTestHarness::SetUp(); | 61 content::RenderViewHostTestHarness::SetUp(); |
61 store_ = new TestPasswordStore; | 62 store_ = new TestPasswordStore; |
62 client_.reset(new TestPasswordManagerClient(store_.get())); | 63 client_.reset(new TestPasswordManagerClient(store_.get())); |
63 dispatcher_.reset( | 64 dispatcher_.reset( |
64 new ContentCredentialManagerDispatcher(web_contents(), client_.get())); | 65 new ContentCredentialManagerDispatcher(web_contents(), client_.get())); |
| 66 |
| 67 NavigateAndCommit(GURL("https://example.com/test.html")); |
| 68 |
| 69 form_.username_value = base::ASCIIToUTF16("Username"); |
| 70 form_.display_name = base::ASCIIToUTF16("Display Name"); |
| 71 form_.password_value = base::ASCIIToUTF16("Password"); |
| 72 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); |
| 73 form_.signon_realm = form_.origin.spec(); |
| 74 form_.scheme = autofill::PasswordForm::SCHEME_HTML; |
65 } | 75 } |
66 | 76 |
67 virtual void TearDown() OVERRIDE { | 77 virtual void TearDown() OVERRIDE { |
68 store_->Shutdown(); | 78 store_->Shutdown(); |
69 content::RenderViewHostTestHarness::TearDown(); | 79 content::RenderViewHostTestHarness::TearDown(); |
70 } | 80 } |
71 | 81 |
72 ContentCredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } | 82 ContentCredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } |
73 | 83 |
74 private: | 84 protected: |
| 85 autofill::PasswordForm form_; |
75 scoped_refptr<TestPasswordStore> store_; | 86 scoped_refptr<TestPasswordStore> store_; |
76 scoped_ptr<ContentCredentialManagerDispatcher> dispatcher_; | 87 scoped_ptr<ContentCredentialManagerDispatcher> dispatcher_; |
77 scoped_ptr<TestPasswordManagerClient> client_; | 88 scoped_ptr<TestPasswordManagerClient> client_; |
78 }; | 89 }; |
79 | 90 |
80 TEST_F(ContentCredentialManagerDispatcherTest, | 91 TEST_F(ContentCredentialManagerDispatcherTest, |
81 CredentialManagerOnNotifyFailedSignIn) { | 92 CredentialManagerOnNotifyFailedSignIn) { |
82 CredentialInfo info(base::ASCIIToUTF16("id"), | 93 CredentialInfo info(base::ASCIIToUTF16("id"), |
83 base::ASCIIToUTF16("name"), | 94 base::ASCIIToUTF16("name"), |
84 GURL("https://example.com/image.png")); | 95 GURL("https://example.com/image.png")); |
(...skipping 25 matching lines...) Expand all Loading... |
110 dispatcher()->OnNotifySignedOut(kRequestId); | 121 dispatcher()->OnNotifySignedOut(kRequestId); |
111 | 122 |
112 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedOut::ID; | 123 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedOut::ID; |
113 const IPC::Message* message = | 124 const IPC::Message* message = |
114 process()->sink().GetFirstMessageMatching(kMsgID); | 125 process()->sink().GetFirstMessageMatching(kMsgID); |
115 EXPECT_TRUE(message); | 126 EXPECT_TRUE(message); |
116 process()->sink().ClearMessages(); | 127 process()->sink().ClearMessages(); |
117 } | 128 } |
118 | 129 |
119 TEST_F(ContentCredentialManagerDispatcherTest, | 130 TEST_F(ContentCredentialManagerDispatcherTest, |
120 CredentialManagerOnRequestCredential) { | 131 CredentialManagerOnRequestCredentialWithEmptyPasswordStore) { |
121 std::vector<GURL> federations; | 132 std::vector<GURL> federations; |
122 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 133 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
123 | 134 |
| 135 RunAllPendingTasks(); |
| 136 |
| 137 const uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; |
| 138 const IPC::Message* message = |
| 139 process()->sink().GetFirstMessageMatching(kMsgID); |
| 140 EXPECT_TRUE(message); |
| 141 process()->sink().ClearMessages(); |
| 142 } |
| 143 |
| 144 TEST_F(ContentCredentialManagerDispatcherTest, |
| 145 CredentialManagerOnRequestCredentialWithFullPasswordStore) { |
| 146 store_->AddLogin(form_); |
| 147 |
| 148 std::vector<GURL> federations; |
| 149 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 150 |
124 RunAllPendingTasks(); | 151 RunAllPendingTasks(); |
125 | 152 |
126 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 153 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
127 const IPC::Message* message = | 154 const IPC::Message* message = |
128 process()->sink().GetFirstMessageMatching(kMsgID); | 155 process()->sink().GetFirstMessageMatching(kMsgID); |
129 EXPECT_TRUE(message); | 156 EXPECT_TRUE(message); |
130 process()->sink().ClearMessages(); | 157 process()->sink().ClearMessages(); |
131 } | 158 } |
132 | 159 |
133 TEST_F(ContentCredentialManagerDispatcherTest, | 160 TEST_F(ContentCredentialManagerDispatcherTest, |
134 CredentialManagerOnRequestCredentialWhileRequestPending) { | 161 CredentialManagerOnRequestCredentialWhileRequestPending) { |
| 162 store_->AddLogin(form_); |
| 163 |
135 std::vector<GURL> federations; | 164 std::vector<GURL> federations; |
136 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 165 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
137 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 166 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
138 | 167 |
139 // Check that the second request triggered a rejection. | 168 // Check that the second request triggered a rejection. |
140 uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; | 169 uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; |
141 const IPC::Message* message = | 170 const IPC::Message* message = |
142 process()->sink().GetFirstMessageMatching(kMsgID); | 171 process()->sink().GetFirstMessageMatching(kMsgID); |
143 EXPECT_TRUE(message); | 172 EXPECT_TRUE(message); |
144 process()->sink().ClearMessages(); | 173 process()->sink().ClearMessages(); |
145 | 174 |
146 // Execute the PasswordStore asynchronousness. | 175 // Execute the PasswordStore asynchronousness. |
147 RunAllPendingTasks(); | 176 RunAllPendingTasks(); |
148 | 177 |
149 // Check that the first request resolves. | 178 // Check that the first request resolves. |
150 kMsgID = CredentialManagerMsg_SendCredential::ID; | 179 kMsgID = CredentialManagerMsg_SendCredential::ID; |
151 message = process()->sink().GetFirstMessageMatching(kMsgID); | 180 message = process()->sink().GetFirstMessageMatching(kMsgID); |
152 EXPECT_TRUE(message); | 181 EXPECT_TRUE(message); |
153 process()->sink().ClearMessages(); | 182 process()->sink().ClearMessages(); |
154 } | 183 } |
155 | 184 |
156 } // namespace password_manager | 185 } // namespace password_manager |
OLD | NEW |