| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <tuple> | 7 #include <tuple> |
| 8 | 8 |
| 9 #include "components/password_manager/content/common/credential_manager_messages
.h" | 9 #include "components/password_manager/content/common/credential_manager_messages
.h" |
| 10 #include "components/password_manager/content/renderer/credential_manager_client
.h" | 10 #include "components/password_manager/content/renderer/credential_manager_client
.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 sink().ClearMessages(); | 84 sink().ClearMessages(); |
| 85 return request_id != -1; | 85 return request_id != -1; |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool callback_errored() const { return callback_errored_; } | 88 bool callback_errored() const { return callback_errored_; } |
| 89 void set_callback_errored(bool state) { callback_errored_ = state; } | 89 void set_callback_errored(bool state) { callback_errored_ = state; } |
| 90 bool callback_succeeded() const { return callback_succeeded_; } | 90 bool callback_succeeded() const { return callback_succeeded_; } |
| 91 void set_callback_succeeded(bool state) { callback_succeeded_ = state; } | 91 void set_callback_succeeded(bool state) { callback_succeeded_ = state; } |
| 92 | 92 |
| 93 protected: | 93 protected: |
| 94 scoped_ptr<CredentialManagerClient> client_; | 94 std::unique_ptr<CredentialManagerClient> client_; |
| 95 | 95 |
| 96 // True if a message's callback's 'onSuccess'/'onError' methods were called, | 96 // True if a message's callback's 'onSuccess'/'onError' methods were called, |
| 97 // false otherwise. We put these on the test object rather than on the | 97 // false otherwise. We put these on the test object rather than on the |
| 98 // Test*Callbacks objects because ownership of those objects passes into the | 98 // Test*Callbacks objects because ownership of those objects passes into the |
| 99 // client, which destroys the callbacks after calling them to resolve the | 99 // client, which destroys the callbacks after calling them to resolve the |
| 100 // pending Blink-side Promise. | 100 // pending Blink-side Promise. |
| 101 bool callback_errored_; | 101 bool callback_errored_; |
| 102 bool callback_succeeded_; | 102 bool callback_succeeded_; |
| 103 | 103 |
| 104 scoped_ptr<blink::WebPasswordCredential> credential_; | 104 std::unique_ptr<blink::WebPasswordCredential> credential_; |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 class TestNotificationCallbacks | 107 class TestNotificationCallbacks |
| 108 : public blink::WebCredentialManagerClient::NotificationCallbacks { | 108 : public blink::WebCredentialManagerClient::NotificationCallbacks { |
| 109 public: | 109 public: |
| 110 explicit TestNotificationCallbacks(CredentialManagerClientTest* test) | 110 explicit TestNotificationCallbacks(CredentialManagerClientTest* test) |
| 111 : test_(test) {} | 111 : test_(test) {} |
| 112 | 112 |
| 113 ~TestNotificationCallbacks() override {} | 113 ~TestNotificationCallbacks() override {} |
| 114 | 114 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 142 CredentialManagerClientTest* test_; | 142 CredentialManagerClientTest* test_; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 } // namespace | 145 } // namespace |
| 146 | 146 |
| 147 TEST_F(CredentialManagerClientTest, SendStore) { | 147 TEST_F(CredentialManagerClientTest, SendStore) { |
| 148 int request_id; | 148 int request_id; |
| 149 EXPECT_FALSE( | 149 EXPECT_FALSE( |
| 150 ExtractRequestId(CredentialManagerHostMsg_Store::ID, request_id)); | 150 ExtractRequestId(CredentialManagerHostMsg_Store::ID, request_id)); |
| 151 | 151 |
| 152 scoped_ptr<TestNotificationCallbacks> callbacks( | 152 std::unique_ptr<TestNotificationCallbacks> callbacks( |
| 153 new TestNotificationCallbacks(this)); | 153 new TestNotificationCallbacks(this)); |
| 154 client_->dispatchStore(*credential(), callbacks.release()); | 154 client_->dispatchStore(*credential(), callbacks.release()); |
| 155 | 155 |
| 156 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_Store::ID, request_id)); | 156 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_Store::ID, request_id)); |
| 157 | 157 |
| 158 client_->OnAcknowledgeStore(request_id); | 158 client_->OnAcknowledgeStore(request_id); |
| 159 EXPECT_TRUE(callback_succeeded()); | 159 EXPECT_TRUE(callback_succeeded()); |
| 160 EXPECT_FALSE(callback_errored()); | 160 EXPECT_FALSE(callback_errored()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 TEST_F(CredentialManagerClientTest, SendRequestUserMediation) { | 163 TEST_F(CredentialManagerClientTest, SendRequestUserMediation) { |
| 164 int request_id; | 164 int request_id; |
| 165 EXPECT_FALSE(ExtractRequestId( | 165 EXPECT_FALSE(ExtractRequestId( |
| 166 CredentialManagerHostMsg_RequireUserMediation::ID, request_id)); | 166 CredentialManagerHostMsg_RequireUserMediation::ID, request_id)); |
| 167 | 167 |
| 168 scoped_ptr<TestNotificationCallbacks> callbacks( | 168 std::unique_ptr<TestNotificationCallbacks> callbacks( |
| 169 new TestNotificationCallbacks(this)); | 169 new TestNotificationCallbacks(this)); |
| 170 client_->dispatchRequireUserMediation(callbacks.release()); | 170 client_->dispatchRequireUserMediation(callbacks.release()); |
| 171 | 171 |
| 172 EXPECT_TRUE(ExtractRequestId( | 172 EXPECT_TRUE(ExtractRequestId( |
| 173 CredentialManagerHostMsg_RequireUserMediation::ID, request_id)); | 173 CredentialManagerHostMsg_RequireUserMediation::ID, request_id)); |
| 174 | 174 |
| 175 client_->OnAcknowledgeRequireUserMediation(request_id); | 175 client_->OnAcknowledgeRequireUserMediation(request_id); |
| 176 EXPECT_TRUE(callback_succeeded()); | 176 EXPECT_TRUE(callback_succeeded()); |
| 177 EXPECT_FALSE(callback_errored()); | 177 EXPECT_FALSE(callback_errored()); |
| 178 } | 178 } |
| 179 | 179 |
| 180 TEST_F(CredentialManagerClientTest, SendRequestCredential) { | 180 TEST_F(CredentialManagerClientTest, SendRequestCredential) { |
| 181 int request_id; | 181 int request_id; |
| 182 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, | 182 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, |
| 183 request_id)); | 183 request_id)); |
| 184 | 184 |
| 185 scoped_ptr<TestRequestCallbacks> callbacks(new TestRequestCallbacks(this)); | 185 std::unique_ptr<TestRequestCallbacks> callbacks( |
| 186 new TestRequestCallbacks(this)); |
| 186 std::vector<GURL> federations; | 187 std::vector<GURL> federations; |
| 187 client_->dispatchGet(false, true, federations, callbacks.release()); | 188 client_->dispatchGet(false, true, federations, callbacks.release()); |
| 188 | 189 |
| 189 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, | 190 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, |
| 190 request_id)); | 191 request_id)); |
| 191 | 192 |
| 192 CredentialInfo info; | 193 CredentialInfo info; |
| 193 info.type = CredentialType::CREDENTIAL_TYPE_PASSWORD; | 194 info.type = CredentialType::CREDENTIAL_TYPE_PASSWORD; |
| 194 client_->OnSendCredential(request_id, info); | 195 client_->OnSendCredential(request_id, info); |
| 195 EXPECT_TRUE(callback_succeeded()); | 196 EXPECT_TRUE(callback_succeeded()); |
| 196 EXPECT_FALSE(callback_errored()); | 197 EXPECT_FALSE(callback_errored()); |
| 197 } | 198 } |
| 198 | 199 |
| 199 TEST_F(CredentialManagerClientTest, SendRequestCredentialEmpty) { | 200 TEST_F(CredentialManagerClientTest, SendRequestCredentialEmpty) { |
| 200 int request_id; | 201 int request_id; |
| 201 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, | 202 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, |
| 202 request_id)); | 203 request_id)); |
| 203 | 204 |
| 204 scoped_ptr<TestRequestCallbacks> callbacks(new TestRequestCallbacks(this)); | 205 std::unique_ptr<TestRequestCallbacks> callbacks( |
| 206 new TestRequestCallbacks(this)); |
| 205 std::vector<GURL> federations; | 207 std::vector<GURL> federations; |
| 206 client_->dispatchGet(false, true, federations, callbacks.release()); | 208 client_->dispatchGet(false, true, federations, callbacks.release()); |
| 207 | 209 |
| 208 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, | 210 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, |
| 209 request_id)); | 211 request_id)); |
| 210 | 212 |
| 211 CredentialInfo info; // Send an empty credential in response. | 213 CredentialInfo info; // Send an empty credential in response. |
| 212 client_->OnSendCredential(request_id, info); | 214 client_->OnSendCredential(request_id, info); |
| 213 EXPECT_TRUE(callback_succeeded()); | 215 EXPECT_TRUE(callback_succeeded()); |
| 214 EXPECT_FALSE(callback_errored()); | 216 EXPECT_FALSE(callback_errored()); |
| 215 } | 217 } |
| 216 | 218 |
| 217 } // namespace password_manager | 219 } // namespace password_manager |
| OLD | NEW |