| 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/credential_manager_dispatc
her.h" | 5 #include "components/password_manager/content/browser/credential_manager_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <tuple> | 10 #include <tuple> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
| 21 #include "components/password_manager/content/common/credential_manager_messages
.h" | 21 #include "components/password_manager/content/public/cpp/type_converters.h" |
| 22 #include "components/password_manager/core/browser/credential_manager_password_f
orm_manager.h" | 22 #include "components/password_manager/core/browser/credential_manager_password_f
orm_manager.h" |
| 23 #include "components/password_manager/core/browser/mock_affiliated_match_helper.
h" | 23 #include "components/password_manager/core/browser/mock_affiliated_match_helper.
h" |
| 24 #include "components/password_manager/core/browser/password_manager.h" | 24 #include "components/password_manager/core/browser/password_manager.h" |
| 25 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | 25 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
| 26 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" | 26 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" |
| 27 #include "components/password_manager/core/browser/test_password_store.h" | 27 #include "components/password_manager/core/browser/test_password_store.h" |
| 28 #include "components/password_manager/core/common/credential_manager_types.h" | 28 #include "components/password_manager/core/common/credential_manager_types.h" |
| 29 #include "components/password_manager/core/common/password_manager_pref_names.h" | 29 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 30 #include "components/prefs/pref_registry_simple.h" | 30 #include "components/prefs/pref_registry_simple.h" |
| 31 #include "components/prefs/testing_pref_service.h" | 31 #include "components/prefs/testing_pref_service.h" |
| 32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 33 #include "content/public/test/mock_render_process_host.h" | 33 #include "content/public/test/mock_render_process_host.h" |
| 34 #include "content/public/test/test_renderer_host.h" | 34 #include "content/public/test/test_renderer_host.h" |
| 35 #include "mojo/common/url_type_converters.h" |
| 35 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 37 | 38 |
| 38 using content::BrowserContext; | 39 using content::BrowserContext; |
| 39 using content::WebContents; | 40 using content::WebContents; |
| 40 | 41 |
| 41 using testing::_; | 42 using testing::_; |
| 42 | 43 |
| 43 namespace password_manager { | 44 namespace password_manager { |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| 46 | 47 |
| 47 // Chosen by fair dice roll. Guaranteed to be random. | |
| 48 const int kRequestId = 4; | |
| 49 | |
| 50 const char kTestWebOrigin[] = "https://example.com/"; | 48 const char kTestWebOrigin[] = "https://example.com/"; |
| 51 const char kTestAndroidRealm1[] = "android://hash@com.example.one.android/"; | 49 const char kTestAndroidRealm1[] = "android://hash@com.example.one.android/"; |
| 52 const char kTestAndroidRealm2[] = "android://hash@com.example.two.android/"; | 50 const char kTestAndroidRealm2[] = "android://hash@com.example.two.android/"; |
| 53 | 51 |
| 54 class MockPasswordManagerClient : public StubPasswordManagerClient { | 52 class MockPasswordManagerClient : public StubPasswordManagerClient { |
| 55 public: | 53 public: |
| 56 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool()); | 54 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool()); |
| 57 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); | 55 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); |
| 58 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); | 56 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); |
| 59 MOCK_METHOD1(NotifyUserAutoSigninPtr, | 57 MOCK_METHOD1(NotifyUserAutoSigninPtr, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 126 } |
| 129 | 127 |
| 130 private: | 128 private: |
| 131 TestingPrefServiceSimple prefs_; | 129 TestingPrefServiceSimple prefs_; |
| 132 PasswordStore* store_; | 130 PasswordStore* store_; |
| 133 std::unique_ptr<PasswordFormManager> manager_; | 131 std::unique_ptr<PasswordFormManager> manager_; |
| 134 | 132 |
| 135 DISALLOW_COPY_AND_ASSIGN(MockPasswordManagerClient); | 133 DISALLOW_COPY_AND_ASSIGN(MockPasswordManagerClient); |
| 136 }; | 134 }; |
| 137 | 135 |
| 138 class TestCredentialManagerDispatcher : public CredentialManagerDispatcher { | 136 class TestCredentialManagerImpl : public CredentialManagerImpl { |
| 139 public: | 137 public: |
| 140 TestCredentialManagerDispatcher(content::WebContents* web_contents, | 138 TestCredentialManagerImpl(content::WebContents* web_contents, |
| 141 PasswordManagerClient* client, | 139 PasswordManagerClient* client, |
| 142 PasswordManagerDriver* driver); | 140 PasswordManagerDriver* driver); |
| 143 | 141 |
| 144 private: | 142 private: |
| 145 base::WeakPtr<PasswordManagerDriver> GetDriver() override; | 143 base::WeakPtr<PasswordManagerDriver> GetDriver() override; |
| 146 | 144 |
| 147 base::WeakPtr<PasswordManagerDriver> driver_; | 145 base::WeakPtr<PasswordManagerDriver> driver_; |
| 148 }; | 146 }; |
| 149 | 147 |
| 150 TestCredentialManagerDispatcher::TestCredentialManagerDispatcher( | 148 TestCredentialManagerImpl::TestCredentialManagerImpl( |
| 151 content::WebContents* web_contents, | 149 content::WebContents* web_contents, |
| 152 PasswordManagerClient* client, | 150 PasswordManagerClient* client, |
| 153 PasswordManagerDriver* driver) | 151 PasswordManagerDriver* driver) |
| 154 : CredentialManagerDispatcher(web_contents, client), | 152 : CredentialManagerImpl(web_contents, client), |
| 155 driver_(driver->AsWeakPtr()) {} | 153 driver_(driver->AsWeakPtr()) {} |
| 156 | 154 |
| 157 base::WeakPtr<PasswordManagerDriver> | 155 base::WeakPtr<PasswordManagerDriver> TestCredentialManagerImpl::GetDriver() { |
| 158 TestCredentialManagerDispatcher::GetDriver() { | |
| 159 return driver_; | 156 return driver_; |
| 160 } | 157 } |
| 161 | 158 |
| 162 void RunAllPendingTasks() { | 159 void RunAllPendingTasks() { |
| 163 base::RunLoop run_loop; | 160 base::RunLoop run_loop; |
| 164 base::MessageLoop::current()->PostTask( | 161 base::MessageLoop::current()->PostTask( |
| 165 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 162 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 166 run_loop.Run(); | 163 run_loop.Run(); |
| 167 } | 164 } |
| 168 | 165 |
| 169 class SlightlyLessStubbyPasswordManagerDriver | 166 class SlightlyLessStubbyPasswordManagerDriver |
| 170 : public StubPasswordManagerDriver { | 167 : public StubPasswordManagerDriver { |
| 171 public: | 168 public: |
| 172 explicit SlightlyLessStubbyPasswordManagerDriver( | 169 explicit SlightlyLessStubbyPasswordManagerDriver( |
| 173 PasswordManagerClient* client) | 170 PasswordManagerClient* client) |
| 174 : password_manager_(client) {} | 171 : password_manager_(client) {} |
| 175 | 172 |
| 176 PasswordManager* GetPasswordManager() override { return &password_manager_; } | 173 PasswordManager* GetPasswordManager() override { return &password_manager_; } |
| 177 | 174 |
| 178 private: | 175 private: |
| 179 PasswordManager password_manager_; | 176 PasswordManager password_manager_; |
| 180 }; | 177 }; |
| 181 | 178 |
| 179 // Callbacks from CredentialManagerImpl methods |
| 180 void RespondCallback(bool* called) { |
| 181 *called = true; |
| 182 } |
| 183 |
| 184 void GetCredentialCallback(bool* called, |
| 185 mojom::CredentialManagerError* out_error, |
| 186 mojom::CredentialInfoPtr* out_info, |
| 187 mojom::CredentialManagerError error, |
| 188 mojom::CredentialInfoPtr info) { |
| 189 *called = true; |
| 190 *out_error = error; |
| 191 *out_info = std::move(info); |
| 192 } |
| 193 |
| 182 } // namespace | 194 } // namespace |
| 183 | 195 |
| 184 class CredentialManagerDispatcherTest | 196 class CredentialManagerImplTest : public content::RenderViewHostTestHarness { |
| 185 : public content::RenderViewHostTestHarness { | |
| 186 public: | 197 public: |
| 187 CredentialManagerDispatcherTest() {} | 198 CredentialManagerImplTest() {} |
| 188 | 199 |
| 189 void SetUp() override { | 200 void SetUp() override { |
| 190 content::RenderViewHostTestHarness::SetUp(); | 201 content::RenderViewHostTestHarness::SetUp(); |
| 191 store_ = new TestPasswordStore; | 202 store_ = new TestPasswordStore; |
| 192 client_.reset( | 203 client_.reset( |
| 193 new testing::NiceMock<MockPasswordManagerClient>(store_.get())); | 204 new testing::NiceMock<MockPasswordManagerClient>(store_.get())); |
| 194 stub_driver_.reset( | 205 stub_driver_.reset( |
| 195 new SlightlyLessStubbyPasswordManagerDriver(client_.get())); | 206 new SlightlyLessStubbyPasswordManagerDriver(client_.get())); |
| 196 dispatcher_.reset(new TestCredentialManagerDispatcher( | 207 cm_service_impl_.reset(new TestCredentialManagerImpl( |
| 197 web_contents(), client_.get(), stub_driver_.get())); | 208 web_contents(), client_.get(), stub_driver_.get())); |
| 198 ON_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) | 209 ON_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) |
| 199 .WillByDefault(testing::Return(true)); | 210 .WillByDefault(testing::Return(true)); |
| 200 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false)); | 211 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false)); |
| 201 ON_CALL(*client_, DidLastPageLoadEncounterSSLErrors()) | 212 ON_CALL(*client_, DidLastPageLoadEncounterSSLErrors()) |
| 202 .WillByDefault(testing::Return(false)); | 213 .WillByDefault(testing::Return(false)); |
| 203 | 214 |
| 204 NavigateAndCommit(GURL("https://example.com/test.html")); | 215 NavigateAndCommit(GURL("https://example.com/test.html")); |
| 205 | 216 |
| 206 form_.username_value = base::ASCIIToUTF16("Username"); | 217 form_.username_value = base::ASCIIToUTF16("Username"); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 cross_origin_form_.origin = GURL("https://example.net/"); | 255 cross_origin_form_.origin = GURL("https://example.net/"); |
| 245 cross_origin_form_.signon_realm = cross_origin_form_.origin.spec(); | 256 cross_origin_form_.signon_realm = cross_origin_form_.origin.spec(); |
| 246 cross_origin_form_.scheme = autofill::PasswordForm::SCHEME_HTML; | 257 cross_origin_form_.scheme = autofill::PasswordForm::SCHEME_HTML; |
| 247 cross_origin_form_.skip_zero_click = false; | 258 cross_origin_form_.skip_zero_click = false; |
| 248 | 259 |
| 249 store_->Clear(); | 260 store_->Clear(); |
| 250 EXPECT_TRUE(store_->IsEmpty()); | 261 EXPECT_TRUE(store_->IsEmpty()); |
| 251 } | 262 } |
| 252 | 263 |
| 253 void TearDown() override { | 264 void TearDown() override { |
| 265 cm_service_impl_.reset(); |
| 266 |
| 254 store_->ShutdownOnUIThread(); | 267 store_->ShutdownOnUIThread(); |
| 255 content::RenderViewHostTestHarness::TearDown(); | 268 content::RenderViewHostTestHarness::TearDown(); |
| 256 } | 269 } |
| 257 | 270 |
| 258 void ExpectZeroClickSignInFailure() { | 271 void ExpectZeroClickSignInFailure(bool zero_click_only, |
| 272 bool include_passwords, |
| 273 const std::vector<GURL>& federations) { |
| 274 bool called = false; |
| 275 mojom::CredentialManagerError error; |
| 276 mojom::CredentialInfoPtr credential; |
| 277 CallGet(zero_click_only, include_passwords, federations, |
| 278 base::Bind(&GetCredentialCallback, &called, &error, &credential)); |
| 259 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 279 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 260 .Times(testing::Exactly(0)); | 280 .Times(testing::Exactly(0)); |
| 261 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)) | 281 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)) |
| 262 .Times(testing::Exactly(0)); | 282 .Times(testing::Exactly(0)); |
| 263 | 283 |
| 264 RunAllPendingTasks(); | 284 RunAllPendingTasks(); |
| 265 | 285 |
| 266 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | 286 EXPECT_TRUE(called); |
| 267 const IPC::Message* message = | 287 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error); |
| 268 process()->sink().GetFirstMessageMatching(kMsgID); | 288 EXPECT_EQ(mojom::CredentialType::EMPTY, credential->type); |
| 269 ASSERT_TRUE(message); | |
| 270 CredentialManagerMsg_SendCredential::Param send_param; | |
| 271 CredentialManagerMsg_SendCredential::Read(message, &send_param); | |
| 272 | |
| 273 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, | |
| 274 std::get<1>(send_param).type); | |
| 275 } | 289 } |
| 276 | 290 |
| 277 void ExpectZeroClickSignInSuccess(CredentialType type) { | 291 void ExpectZeroClickSignInSuccess(bool zero_click_only, |
| 292 bool include_passwords, |
| 293 const std::vector<GURL>& federations, |
| 294 mojom::CredentialType type) { |
| 295 bool called = false; |
| 296 mojom::CredentialManagerError error; |
| 297 mojom::CredentialInfoPtr credential; |
| 298 CallGet(zero_click_only, include_passwords, federations, |
| 299 base::Bind(&GetCredentialCallback, &called, &error, &credential)); |
| 278 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 300 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 279 .Times(testing::Exactly(0)); | 301 .Times(testing::Exactly(0)); |
| 280 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)) | 302 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)) |
| 281 .Times(testing::Exactly(1)); | 303 .Times(testing::Exactly(1)); |
| 282 | 304 |
| 283 RunAllPendingTasks(); | 305 RunAllPendingTasks(); |
| 284 | 306 |
| 285 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | 307 EXPECT_TRUE(called); |
| 286 const IPC::Message* message = | 308 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error); |
| 287 process()->sink().GetFirstMessageMatching(kMsgID); | 309 EXPECT_EQ(type, credential->type); |
| 288 ASSERT_TRUE(message); | |
| 289 CredentialManagerMsg_SendCredential::Param send_param; | |
| 290 CredentialManagerMsg_SendCredential::Read(message, &send_param); | |
| 291 | |
| 292 EXPECT_EQ(type, std::get<1>(send_param).type); | |
| 293 } | 310 } |
| 294 | 311 |
| 295 CredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } | 312 void ExpectCredentialType(bool zero_click_only, |
| 313 bool include_passwords, |
| 314 const std::vector<GURL>& federations, |
| 315 mojom::CredentialType type) { |
| 316 bool called = false; |
| 317 mojom::CredentialManagerError error; |
| 318 mojom::CredentialInfoPtr credential; |
| 319 CallGet(zero_click_only, include_passwords, federations, |
| 320 base::Bind(&GetCredentialCallback, &called, &error, &credential)); |
| 321 |
| 322 RunAllPendingTasks(); |
| 323 |
| 324 EXPECT_TRUE(called); |
| 325 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error); |
| 326 EXPECT_EQ(type, credential->type); |
| 327 } |
| 328 |
| 329 CredentialManagerImpl* cm_service_impl() { return cm_service_impl_.get(); } |
| 330 |
| 331 // Helpers for testing CredentialManagerImpl methods. |
| 332 void CallStore(const CredentialInfo& info, |
| 333 const CredentialManagerImpl::StoreCallback& callback) { |
| 334 mojom::CredentialInfoPtr credential = mojom::CredentialInfo::From(info); |
| 335 cm_service_impl_->Store(std::move(credential), callback); |
| 336 } |
| 337 |
| 338 void CallRequireUserMediation( |
| 339 const CredentialManagerImpl::RequireUserMediationCallback& callback) { |
| 340 cm_service_impl_->RequireUserMediation(callback); |
| 341 } |
| 342 |
| 343 void CallGet(bool zero_click_only, |
| 344 bool include_passwords, |
| 345 const std::vector<GURL>& federations, |
| 346 const CredentialManagerImpl::GetCallback& callback) { |
| 347 cm_service_impl_->Get(zero_click_only, include_passwords, |
| 348 mojo::Array<mojo::String>::From(federations), |
| 349 callback); |
| 350 } |
| 296 | 351 |
| 297 protected: | 352 protected: |
| 298 autofill::PasswordForm form_; | 353 autofill::PasswordForm form_; |
| 299 autofill::PasswordForm affiliated_form1_; | 354 autofill::PasswordForm affiliated_form1_; |
| 300 autofill::PasswordForm affiliated_form2_; | 355 autofill::PasswordForm affiliated_form2_; |
| 301 autofill::PasswordForm origin_path_form_; | 356 autofill::PasswordForm origin_path_form_; |
| 302 autofill::PasswordForm cross_origin_form_; | 357 autofill::PasswordForm cross_origin_form_; |
| 303 scoped_refptr<TestPasswordStore> store_; | 358 scoped_refptr<TestPasswordStore> store_; |
| 304 std::unique_ptr<testing::NiceMock<MockPasswordManagerClient>> client_; | 359 std::unique_ptr<testing::NiceMock<MockPasswordManagerClient>> client_; |
| 305 std::unique_ptr<SlightlyLessStubbyPasswordManagerDriver> stub_driver_; | 360 std::unique_ptr<SlightlyLessStubbyPasswordManagerDriver> stub_driver_; |
| 306 std::unique_ptr<CredentialManagerDispatcher> dispatcher_; | 361 std::unique_ptr<CredentialManagerImpl> cm_service_impl_; |
| 307 }; | 362 }; |
| 308 | 363 |
| 309 TEST_F(CredentialManagerDispatcherTest, IsZeroClickAllowed) { | 364 TEST_F(CredentialManagerImplTest, IsZeroClickAllowed) { |
| 310 // IsZeroClickAllowed is uneffected by the first-run status. | 365 // IsZeroClickAllowed is uneffected by the first-run status. |
| 311 client_->set_zero_click_enabled(true); | 366 client_->set_zero_click_enabled(true); |
| 312 client_->set_first_run_seen(true); | 367 client_->set_first_run_seen(true); |
| 313 EXPECT_TRUE(dispatcher()->IsZeroClickAllowed()); | 368 EXPECT_TRUE(cm_service_impl()->IsZeroClickAllowed()); |
| 314 | 369 |
| 315 client_->set_zero_click_enabled(true); | 370 client_->set_zero_click_enabled(true); |
| 316 client_->set_first_run_seen(false); | 371 client_->set_first_run_seen(false); |
| 317 EXPECT_TRUE(dispatcher()->IsZeroClickAllowed()); | 372 EXPECT_TRUE(cm_service_impl()->IsZeroClickAllowed()); |
| 318 | 373 |
| 319 client_->set_zero_click_enabled(false); | 374 client_->set_zero_click_enabled(false); |
| 320 client_->set_first_run_seen(true); | 375 client_->set_first_run_seen(true); |
| 321 EXPECT_FALSE(dispatcher()->IsZeroClickAllowed()); | 376 EXPECT_FALSE(cm_service_impl()->IsZeroClickAllowed()); |
| 322 | 377 |
| 323 client_->set_zero_click_enabled(false); | 378 client_->set_zero_click_enabled(false); |
| 324 client_->set_first_run_seen(false); | 379 client_->set_first_run_seen(false); |
| 325 EXPECT_FALSE(dispatcher()->IsZeroClickAllowed()); | 380 EXPECT_FALSE(cm_service_impl()->IsZeroClickAllowed()); |
| 326 } | 381 } |
| 327 | 382 |
| 328 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnStore) { | 383 TEST_F(CredentialManagerImplTest, CredentialManagerOnStore) { |
| 329 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); | 384 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 330 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | 385 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
| 331 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) | 386 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) |
| 332 .Times(testing::Exactly(1)); | 387 .Times(testing::Exactly(1)); |
| 333 | 388 |
| 334 dispatcher()->OnStore(kRequestId, info); | 389 bool called = false; |
| 335 | 390 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 336 const uint32_t kMsgID = CredentialManagerMsg_AcknowledgeStore::ID; | |
| 337 const IPC::Message* message = | |
| 338 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 339 EXPECT_TRUE(message); | |
| 340 process()->sink().ClearMessages(); | |
| 341 | 391 |
| 342 // Allow the PasswordFormManager to talk to the password store, determine | 392 // Allow the PasswordFormManager to talk to the password store, determine |
| 343 // that the form is new, and set it as pending. | 393 // that the form is new, and set it as pending. |
| 344 RunAllPendingTasks(); | 394 RunAllPendingTasks(); |
| 345 | 395 |
| 396 EXPECT_TRUE(called); |
| 346 EXPECT_TRUE(client_->pending_manager()->HasCompletedMatching()); | 397 EXPECT_TRUE(client_->pending_manager()->HasCompletedMatching()); |
| 347 | 398 |
| 348 autofill::PasswordForm new_form = | 399 autofill::PasswordForm new_form = |
| 349 client_->pending_manager()->pending_credentials(); | 400 client_->pending_manager()->pending_credentials(); |
| 350 EXPECT_EQ(form_.username_value, new_form.username_value); | 401 EXPECT_EQ(form_.username_value, new_form.username_value); |
| 351 EXPECT_EQ(form_.display_name, new_form.display_name); | 402 EXPECT_EQ(form_.display_name, new_form.display_name); |
| 352 EXPECT_EQ(form_.password_value, new_form.password_value); | 403 EXPECT_EQ(form_.password_value, new_form.password_value); |
| 353 EXPECT_EQ(form_.origin, new_form.origin); | 404 EXPECT_EQ(form_.origin, new_form.origin); |
| 354 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); | 405 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); |
| 355 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); | 406 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); |
| 356 } | 407 } |
| 357 | 408 |
| 358 TEST_F(CredentialManagerDispatcherTest, CredentialManagerStoreOverwrite) { | 409 TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwrite) { |
| 359 // Populate the PasswordStore with a form. | 410 // Populate the PasswordStore with a form. |
| 360 store_->AddLogin(form_); | 411 store_->AddLogin(form_); |
| 361 RunAllPendingTasks(); | 412 RunAllPendingTasks(); |
| 362 | 413 |
| 363 // Calling 'OnStore' with a credential that matches |form_| should update | 414 // Calling 'Store' with a credential that matches |form_| should update |
| 364 // the password without prompting the user. | 415 // the password without prompting the user. |
| 365 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); | 416 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 366 info.password = base::ASCIIToUTF16("Totally new password."); | 417 info.password = base::ASCIIToUTF16("Totally new password."); |
| 367 dispatcher()->OnStore(kRequestId, info); | 418 bool called = false; |
| 419 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 368 | 420 |
| 369 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | 421 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
| 370 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) | 422 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) |
| 371 .Times(testing::Exactly(0)); | 423 .Times(testing::Exactly(0)); |
| 372 | 424 |
| 373 const uint32_t kMsgID = CredentialManagerMsg_AcknowledgeStore::ID; | |
| 374 const IPC::Message* message = | |
| 375 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 376 EXPECT_TRUE(message); | |
| 377 process()->sink().ClearMessages(); | |
| 378 | |
| 379 // Allow the PasswordFormManager to talk to the password store, determine | 425 // Allow the PasswordFormManager to talk to the password store, determine |
| 380 // the form is a match for an existing form, and update the PasswordStore. | 426 // the form is a match for an existing form, and update the PasswordStore. |
| 381 RunAllPendingTasks(); | 427 RunAllPendingTasks(); |
| 382 | 428 |
| 429 EXPECT_TRUE(called); |
| 430 |
| 383 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 431 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 384 EXPECT_EQ(1U, passwords.size()); | 432 EXPECT_EQ(1U, passwords.size()); |
| 385 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); | 433 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); |
| 386 EXPECT_EQ(base::ASCIIToUTF16("Totally new password."), | 434 EXPECT_EQ(base::ASCIIToUTF16("Totally new password."), |
| 387 passwords[form_.signon_realm][0].password_value); | 435 passwords[form_.signon_realm][0].password_value); |
| 388 } | 436 } |
| 389 | 437 |
| 390 TEST_F(CredentialManagerDispatcherTest, | 438 TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwriteZeroClick) { |
| 391 CredentialManagerStoreOverwriteZeroClick) { | |
| 392 // Set the global zero click flag on, and populate the PasswordStore with a | 439 // Set the global zero click flag on, and populate the PasswordStore with a |
| 393 // form that's set to skip zero click. | 440 // form that's set to skip zero click. |
| 394 client_->set_zero_click_enabled(true); | 441 client_->set_zero_click_enabled(true); |
| 395 form_.skip_zero_click = true; | 442 form_.skip_zero_click = true; |
| 396 store_->AddLogin(form_); | 443 store_->AddLogin(form_); |
| 397 RunAllPendingTasks(); | 444 RunAllPendingTasks(); |
| 398 | 445 |
| 399 // Calling 'OnStore' with a credential that matches |form_| should update | 446 // Calling 'Store' with a credential that matches |form_| should update |
| 400 // the password without prompting the user. | 447 // the password without prompting the user. |
| 401 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); | 448 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 402 info.password = base::ASCIIToUTF16("Totally new password."); | 449 info.password = base::ASCIIToUTF16("Totally new password."); |
| 403 dispatcher()->OnStore(kRequestId, info); | 450 bool called = false; |
| 404 process()->sink().ClearMessages(); | 451 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 405 | 452 |
| 406 // Allow the PasswordFormManager to talk to the password store, determine | 453 // Allow the PasswordFormManager to talk to the password store, determine |
| 407 // the form is a match for an existing form, and update the PasswordStore. | 454 // the form is a match for an existing form, and update the PasswordStore. |
| 408 RunAllPendingTasks(); | 455 RunAllPendingTasks(); |
| 409 | 456 |
| 410 // Verify that the update didn't toggle the skip_zero_click flag off. | 457 // Verify that the update didn't toggle the skip_zero_click flag off. |
| 411 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 458 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 412 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); | 459 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); |
| 413 } | 460 } |
| 414 | 461 |
| 415 TEST_F(CredentialManagerDispatcherTest, | 462 TEST_F(CredentialManagerImplTest, CredentialManagerGetOverwriteZeroClick) { |
| 416 CredentialManagerGetOverwriteZeroClick) { | |
| 417 // Set the global zero click flag on, and populate the PasswordStore with a | 463 // Set the global zero click flag on, and populate the PasswordStore with a |
| 418 // form that's set to skip zero click and has a primary key that won't match | 464 // form that's set to skip zero click and has a primary key that won't match |
| 419 // credentials initially created via `store()`. | 465 // credentials initially created via `store()`. |
| 420 client_->set_zero_click_enabled(true); | 466 client_->set_zero_click_enabled(true); |
| 421 form_.skip_zero_click = true; | 467 form_.skip_zero_click = true; |
| 422 form_.username_element = base::ASCIIToUTF16("username-element"); | 468 form_.username_element = base::ASCIIToUTF16("username-element"); |
| 423 form_.password_element = base::ASCIIToUTF16("password-element"); | 469 form_.password_element = base::ASCIIToUTF16("password-element"); |
| 424 form_.signon_realm = "this is a realm"; | 470 form_.signon_realm = "this is a realm"; |
| 425 form_.origin = GURL("https://example.com/old_form.html"); | 471 form_.origin = GURL("https://example.com/old_form.html"); |
| 426 store_->AddLogin(form_); | 472 store_->AddLogin(form_); |
| 427 RunAllPendingTasks(); | 473 RunAllPendingTasks(); |
| 428 | 474 |
| 429 std::vector<GURL> federations; | 475 std::vector<GURL> federations; |
| 430 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 476 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 431 .Times(testing::Exactly(1)); | 477 .Times(testing::Exactly(1)); |
| 432 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 478 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 433 | 479 |
| 434 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); | 480 bool called = false; |
| 481 mojom::CredentialManagerError error; |
| 482 mojom::CredentialInfoPtr credential; |
| 483 CallGet(false, true, federations, |
| 484 base::Bind(&GetCredentialCallback, &called, &error, &credential)); |
| 435 | 485 |
| 436 RunAllPendingTasks(); | 486 RunAllPendingTasks(); |
| 437 | 487 |
| 438 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | 488 EXPECT_TRUE(called); |
| 439 const IPC::Message* message = | 489 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error); |
| 440 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 441 EXPECT_TRUE(message); | |
| 442 | 490 |
| 443 // Verify that the update toggled the skip_zero_click flag. | 491 // Verify that the update toggled the skip_zero_click flag. |
| 444 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 492 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 445 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 493 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 446 } | 494 } |
| 447 | 495 |
| 448 TEST_F(CredentialManagerDispatcherTest, | 496 TEST_F(CredentialManagerImplTest, |
| 449 CredentialManagerSignInWithSavingDisabledForCurrentPage) { | 497 CredentialManagerSignInWithSavingDisabledForCurrentPage) { |
| 450 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); | 498 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 451 EXPECT_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) | 499 EXPECT_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) |
| 452 .WillRepeatedly(testing::Return(false)); | 500 .WillRepeatedly(testing::Return(false)); |
| 453 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | 501 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
| 454 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) | 502 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) |
| 455 .Times(testing::Exactly(0)); | 503 .Times(testing::Exactly(0)); |
| 456 | 504 |
| 457 dispatcher()->OnStore(kRequestId, info); | 505 bool called = false; |
| 458 | 506 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 459 const uint32_t kMsgID = CredentialManagerMsg_AcknowledgeStore::ID; | |
| 460 const IPC::Message* message = | |
| 461 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 462 EXPECT_TRUE(message); | |
| 463 process()->sink().ClearMessages(); | |
| 464 | 507 |
| 465 RunAllPendingTasks(); | 508 RunAllPendingTasks(); |
| 466 | 509 |
| 510 EXPECT_TRUE(called); |
| 467 EXPECT_FALSE(client_->pending_manager()); | 511 EXPECT_FALSE(client_->pending_manager()); |
| 468 } | 512 } |
| 469 | 513 |
| 470 TEST_F(CredentialManagerDispatcherTest, | 514 TEST_F(CredentialManagerImplTest, CredentialManagerOnRequireUserMediation) { |
| 471 CredentialManagerOnRequireUserMediation) { | |
| 472 store_->AddLogin(form_); | 515 store_->AddLogin(form_); |
| 473 store_->AddLogin(cross_origin_form_); | 516 store_->AddLogin(cross_origin_form_); |
| 474 RunAllPendingTasks(); | 517 RunAllPendingTasks(); |
| 475 | 518 |
| 476 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 519 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 477 EXPECT_EQ(2U, passwords.size()); | 520 EXPECT_EQ(2U, passwords.size()); |
| 478 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); | 521 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); |
| 479 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); | 522 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); |
| 480 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 523 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 481 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); | 524 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); |
| 482 | 525 |
| 483 dispatcher()->OnRequireUserMediation(kRequestId); | 526 bool called = false; |
| 527 CallRequireUserMediation(base::Bind(&RespondCallback, &called)); |
| 528 |
| 484 RunAllPendingTasks(); | 529 RunAllPendingTasks(); |
| 485 | 530 |
| 486 const uint32_t kMsgID = | 531 EXPECT_TRUE(called); |
| 487 CredentialManagerMsg_AcknowledgeRequireUserMediation::ID; | |
| 488 const IPC::Message* message = | |
| 489 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 490 EXPECT_TRUE(message); | |
| 491 process()->sink().ClearMessages(); | |
| 492 | 532 |
| 493 passwords = store_->stored_passwords(); | 533 passwords = store_->stored_passwords(); |
| 494 EXPECT_EQ(2U, passwords.size()); | 534 EXPECT_EQ(2U, passwords.size()); |
| 495 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); | 535 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); |
| 496 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); | 536 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); |
| 497 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); | 537 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); |
| 498 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); | 538 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); |
| 499 } | 539 } |
| 500 | 540 |
| 501 TEST_F(CredentialManagerDispatcherTest, | 541 TEST_F(CredentialManagerImplTest, |
| 502 CredentialManagerOnRequireUserMediationIncognito) { | 542 CredentialManagerOnRequireUserMediationIncognito) { |
| 503 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); | 543 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); |
| 504 store_->AddLogin(form_); | 544 store_->AddLogin(form_); |
| 505 RunAllPendingTasks(); | 545 RunAllPendingTasks(); |
| 506 | 546 |
| 507 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 547 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 508 ASSERT_EQ(1U, passwords.size()); | 548 ASSERT_EQ(1U, passwords.size()); |
| 509 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); | 549 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); |
| 510 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 550 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 511 | 551 |
| 512 dispatcher()->OnRequireUserMediation(kRequestId); | 552 bool called = false; |
| 553 CallRequireUserMediation(base::Bind(&RespondCallback, &called)); |
| 513 RunAllPendingTasks(); | 554 RunAllPendingTasks(); |
| 514 | 555 |
| 515 const uint32_t kMsgID = | 556 EXPECT_TRUE(called); |
| 516 CredentialManagerMsg_AcknowledgeRequireUserMediation::ID; | |
| 517 const IPC::Message* message = | |
| 518 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 519 EXPECT_TRUE(message); | |
| 520 process()->sink().ClearMessages(); | |
| 521 | 557 |
| 522 passwords = store_->stored_passwords(); | 558 passwords = store_->stored_passwords(); |
| 523 ASSERT_EQ(1U, passwords.size()); | 559 ASSERT_EQ(1U, passwords.size()); |
| 524 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); | 560 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); |
| 525 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 561 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 526 } | 562 } |
| 527 | 563 |
| 528 TEST_F(CredentialManagerDispatcherTest, | 564 TEST_F(CredentialManagerImplTest, |
| 529 CredentialManagerOnRequireUserMediationWithAffiliation) { | 565 CredentialManagerOnRequireUserMediationWithAffiliation) { |
| 530 store_->AddLogin(form_); | 566 store_->AddLogin(form_); |
| 531 store_->AddLogin(cross_origin_form_); | 567 store_->AddLogin(cross_origin_form_); |
| 532 store_->AddLogin(affiliated_form1_); | 568 store_->AddLogin(affiliated_form1_); |
| 533 store_->AddLogin(affiliated_form2_); | 569 store_->AddLogin(affiliated_form2_); |
| 534 | 570 |
| 535 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 571 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 536 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 572 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 537 | 573 |
| 538 std::vector<GURL> federations; | 574 std::vector<GURL> federations; |
| 539 std::vector<std::string> affiliated_realms; | 575 std::vector<std::string> affiliated_realms; |
| 540 affiliated_realms.push_back(kTestAndroidRealm1); | 576 affiliated_realms.push_back(kTestAndroidRealm1); |
| 541 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 577 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 542 ->ExpectCallToGetAffiliatedAndroidRealms( | 578 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 543 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 579 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 544 RunAllPendingTasks(); | 580 RunAllPendingTasks(); |
| 545 | 581 |
| 546 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 582 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 547 EXPECT_EQ(4U, passwords.size()); | 583 EXPECT_EQ(4U, passwords.size()); |
| 548 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 584 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 549 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); | 585 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); |
| 550 EXPECT_FALSE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click); | 586 EXPECT_FALSE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click); |
| 551 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click); | 587 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click); |
| 552 | 588 |
| 553 dispatcher()->OnRequireUserMediation(kRequestId); | 589 bool called = false; |
| 590 CallRequireUserMediation(base::Bind(&RespondCallback, &called)); |
| 554 RunAllPendingTasks(); | 591 RunAllPendingTasks(); |
| 555 process()->sink().ClearMessages(); | |
| 556 | 592 |
| 557 passwords = store_->stored_passwords(); | 593 passwords = store_->stored_passwords(); |
| 558 EXPECT_EQ(4U, passwords.size()); | 594 EXPECT_EQ(4U, passwords.size()); |
| 559 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); | 595 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); |
| 560 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); | 596 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); |
| 561 EXPECT_TRUE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click); | 597 EXPECT_TRUE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click); |
| 562 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click); | 598 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click); |
| 563 } | 599 } |
| 564 | 600 |
| 565 TEST_F(CredentialManagerDispatcherTest, | 601 TEST_F(CredentialManagerImplTest, |
| 566 CredentialManagerOnRequestCredentialWithEmptyPasswordStore) { | 602 CredentialManagerOnRequestCredentialWithEmptyPasswordStore) { |
| 567 std::vector<GURL> federations; | 603 std::vector<GURL> federations; |
| 568 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | 604 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
| 569 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) | 605 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) |
| 570 .Times(testing::Exactly(0)); | 606 .Times(testing::Exactly(0)); |
| 571 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 607 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 572 .Times(testing::Exactly(0)); | 608 .Times(testing::Exactly(0)); |
| 573 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 609 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 574 | 610 |
| 575 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); | 611 ExpectCredentialType(false, true, federations, mojom::CredentialType::EMPTY); |
| 576 | |
| 577 RunAllPendingTasks(); | |
| 578 | |
| 579 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | |
| 580 const IPC::Message* message = | |
| 581 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 582 EXPECT_TRUE(message); | |
| 583 CredentialManagerMsg_SendCredential::Param param; | |
| 584 CredentialManagerMsg_SendCredential::Read(message, ¶m); | |
| 585 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, std::get<1>(param).type); | |
| 586 process()->sink().ClearMessages(); | |
| 587 } | 612 } |
| 588 | 613 |
| 589 TEST_F(CredentialManagerDispatcherTest, | 614 TEST_F(CredentialManagerImplTest, |
| 590 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) { | 615 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) { |
| 591 store_->AddLogin(cross_origin_form_); | 616 store_->AddLogin(cross_origin_form_); |
| 592 | 617 |
| 593 std::vector<GURL> federations; | 618 std::vector<GURL> federations; |
| 594 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | 619 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
| 595 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) | 620 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) |
| 596 .Times(testing::Exactly(0)); | 621 .Times(testing::Exactly(0)); |
| 597 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 622 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 598 .Times(testing::Exactly(0)); | 623 .Times(testing::Exactly(0)); |
| 599 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 624 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 600 | 625 |
| 601 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); | 626 ExpectCredentialType(false, true, federations, mojom::CredentialType::EMPTY); |
| 602 | |
| 603 RunAllPendingTasks(); | |
| 604 | |
| 605 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | |
| 606 const IPC::Message* message = | |
| 607 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 608 EXPECT_TRUE(message); | |
| 609 CredentialManagerMsg_SendCredential::Param param; | |
| 610 CredentialManagerMsg_SendCredential::Read(message, ¶m); | |
| 611 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, std::get<1>(param).type); | |
| 612 process()->sink().ClearMessages(); | |
| 613 } | 627 } |
| 614 | 628 |
| 615 TEST_F(CredentialManagerDispatcherTest, | 629 TEST_F(CredentialManagerImplTest, |
| 616 CredentialManagerOnRequestCredentialWithFullPasswordStore) { | 630 CredentialManagerOnRequestCredentialWithFullPasswordStore) { |
| 617 client_->set_zero_click_enabled(false); | 631 client_->set_zero_click_enabled(false); |
| 618 store_->AddLogin(form_); | 632 store_->AddLogin(form_); |
| 619 | 633 |
| 620 std::vector<GURL> federations; | 634 std::vector<GURL> federations; |
| 621 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 635 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 622 .Times(testing::Exactly(1)); | 636 .Times(testing::Exactly(1)); |
| 623 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 637 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 624 | 638 |
| 625 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); | 639 bool called = false; |
| 640 mojom::CredentialManagerError error; |
| 641 mojom::CredentialInfoPtr credential; |
| 642 CallGet(false, true, federations, |
| 643 base::Bind(&GetCredentialCallback, &called, &error, &credential)); |
| 626 | 644 |
| 627 RunAllPendingTasks(); | 645 RunAllPendingTasks(); |
| 628 | 646 |
| 629 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | 647 EXPECT_TRUE(called); |
| 630 const IPC::Message* message = | 648 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error); |
| 631 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 632 EXPECT_TRUE(message); | |
| 633 } | 649 } |
| 634 | 650 |
| 635 TEST_F( | 651 TEST_F( |
| 636 CredentialManagerDispatcherTest, | 652 CredentialManagerImplTest, |
| 637 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) { | 653 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) { |
| 638 std::vector<GURL> federations; | 654 std::vector<GURL> federations; |
| 639 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 655 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 640 .Times(testing::Exactly(0)); | 656 .Times(testing::Exactly(0)); |
| 641 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 657 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 642 | 658 |
| 643 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 659 bool called = false; |
| 660 mojom::CredentialManagerError error; |
| 661 mojom::CredentialInfoPtr credential; |
| 662 CallGet(true, true, federations, |
| 663 base::Bind(&GetCredentialCallback, &called, &error, &credential)); |
| 644 | 664 |
| 645 RunAllPendingTasks(); | 665 RunAllPendingTasks(); |
| 646 | 666 |
| 647 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | 667 EXPECT_TRUE(called); |
| 648 const IPC::Message* message = | 668 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error); |
| 649 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 650 EXPECT_TRUE(message); | |
| 651 CredentialManagerMsg_SendCredential::Param send_param; | |
| 652 CredentialManagerMsg_SendCredential::Read(message, &send_param); | |
| 653 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, | |
| 654 std::get<1>(send_param).type); | |
| 655 } | 669 } |
| 656 | 670 |
| 657 TEST_F(CredentialManagerDispatcherTest, | 671 TEST_F(CredentialManagerImplTest, |
| 658 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) { | 672 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) { |
| 659 store_->AddLogin(form_); | 673 store_->AddLogin(form_); |
| 660 client_->set_first_run_seen(true); | 674 client_->set_first_run_seen(true); |
| 661 | 675 |
| 662 std::vector<GURL> federations; | 676 std::vector<GURL> federations; |
| 663 | 677 |
| 664 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); | 678 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); |
| 665 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 666 | 679 |
| 667 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); | 680 ExpectZeroClickSignInSuccess(true, true, federations, |
| 681 mojom::CredentialType::PASSWORD); |
| 668 } | 682 } |
| 669 | 683 |
| 670 TEST_F(CredentialManagerDispatcherTest, | 684 TEST_F(CredentialManagerImplTest, |
| 671 CredentialManagerOnRequestCredentialWithoutPasswords) { | 685 CredentialManagerOnRequestCredentialWithoutPasswords) { |
| 672 store_->AddLogin(form_); | 686 store_->AddLogin(form_); |
| 673 client_->set_first_run_seen(true); | 687 client_->set_first_run_seen(true); |
| 674 | 688 |
| 675 std::vector<GURL> federations; | 689 std::vector<GURL> federations; |
| 676 | 690 |
| 677 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); | 691 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); |
| 678 dispatcher()->OnRequestCredential(kRequestId, true, false, federations); | |
| 679 | 692 |
| 680 ExpectZeroClickSignInFailure(); | 693 ExpectZeroClickSignInFailure(true, false, federations); |
| 681 } | 694 } |
| 682 | 695 |
| 683 TEST_F(CredentialManagerDispatcherTest, | 696 TEST_F(CredentialManagerImplTest, |
| 684 CredentialManagerOnRequestCredentialFederatedMatch) { | 697 CredentialManagerOnRequestCredentialFederatedMatch) { |
| 685 form_.federation_origin = url::Origin(GURL("https://example.com/")); | 698 form_.federation_origin = url::Origin(GURL("https://example.com/")); |
| 686 store_->AddLogin(form_); | 699 store_->AddLogin(form_); |
| 687 client_->set_first_run_seen(true); | 700 client_->set_first_run_seen(true); |
| 688 | 701 |
| 689 std::vector<GURL> federations; | 702 std::vector<GURL> federations; |
| 690 federations.push_back(GURL("https://example.com/")); | 703 federations.push_back(GURL("https://example.com/")); |
| 691 | 704 |
| 692 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); | 705 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); |
| 693 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 694 | 706 |
| 695 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_FEDERATED); | 707 ExpectZeroClickSignInSuccess(true, true, federations, |
| 708 mojom::CredentialType::FEDERATED); |
| 696 } | 709 } |
| 697 | 710 |
| 698 TEST_F(CredentialManagerDispatcherTest, | 711 TEST_F(CredentialManagerImplTest, |
| 699 CredentialManagerOnRequestCredentialFederatedNoMatch) { | 712 CredentialManagerOnRequestCredentialFederatedNoMatch) { |
| 700 form_.federation_origin = url::Origin(GURL("https://example.com/")); | 713 form_.federation_origin = url::Origin(GURL("https://example.com/")); |
| 701 store_->AddLogin(form_); | 714 store_->AddLogin(form_); |
| 702 client_->set_first_run_seen(true); | 715 client_->set_first_run_seen(true); |
| 703 | 716 |
| 704 std::vector<GURL> federations; | 717 std::vector<GURL> federations; |
| 705 federations.push_back(GURL("https://not-example.com/")); | 718 federations.push_back(GURL("https://not-example.com/")); |
| 706 | 719 |
| 707 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); | 720 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); |
| 708 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 709 | 721 |
| 710 ExpectZeroClickSignInFailure(); | 722 ExpectZeroClickSignInFailure(true, true, federations); |
| 711 } | 723 } |
| 712 | 724 |
| 713 TEST_F(CredentialManagerDispatcherTest, | 725 TEST_F(CredentialManagerImplTest, |
| 714 CredentialManagerOnRequestCredentialAffiliatedPasswordMatch) { | 726 CredentialManagerOnRequestCredentialAffiliatedPasswordMatch) { |
| 715 store_->AddLogin(affiliated_form1_); | 727 store_->AddLogin(affiliated_form1_); |
| 716 client_->set_first_run_seen(true); | 728 client_->set_first_run_seen(true); |
| 717 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 729 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 718 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 730 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 719 | 731 |
| 720 std::vector<GURL> federations; | 732 std::vector<GURL> federations; |
| 721 std::vector<std::string> affiliated_realms; | 733 std::vector<std::string> affiliated_realms; |
| 722 affiliated_realms.push_back(kTestAndroidRealm1); | 734 affiliated_realms.push_back(kTestAndroidRealm1); |
| 723 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 735 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 724 ->ExpectCallToGetAffiliatedAndroidRealms( | 736 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 725 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 737 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 726 | 738 |
| 727 // We pass in 'true' for the 'include_passwords' argument to ensure that | 739 // We pass in 'true' for the 'include_passwords' argument to ensure that |
| 728 // password-type credentials are included as potential matches. | 740 // password-type credentials are included as potential matches. |
| 729 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 741 ExpectZeroClickSignInSuccess(true, true, federations, |
| 730 | 742 mojom::CredentialType::PASSWORD); |
| 731 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); | |
| 732 } | 743 } |
| 733 | 744 |
| 734 TEST_F(CredentialManagerDispatcherTest, | 745 TEST_F(CredentialManagerImplTest, |
| 735 CredentialManagerOnRequestCredentialAffiliatedPasswordNoMatch) { | 746 CredentialManagerOnRequestCredentialAffiliatedPasswordNoMatch) { |
| 736 store_->AddLogin(affiliated_form1_); | 747 store_->AddLogin(affiliated_form1_); |
| 737 client_->set_first_run_seen(true); | 748 client_->set_first_run_seen(true); |
| 738 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 749 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 739 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 750 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 740 | 751 |
| 741 std::vector<GURL> federations; | 752 std::vector<GURL> federations; |
| 742 std::vector<std::string> affiliated_realms; | 753 std::vector<std::string> affiliated_realms; |
| 743 affiliated_realms.push_back(kTestAndroidRealm1); | 754 affiliated_realms.push_back(kTestAndroidRealm1); |
| 744 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 755 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 745 ->ExpectCallToGetAffiliatedAndroidRealms( | 756 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 746 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 757 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 747 | 758 |
| 748 // We pass in 'false' for the 'include_passwords' argument to ensure that | 759 // We pass in 'false' for the 'include_passwords' argument to ensure that |
| 749 // password-type credentials are excluded as potential matches. | 760 // password-type credentials are excluded as potential matches. |
| 750 dispatcher()->OnRequestCredential(kRequestId, true, false, federations); | 761 ExpectZeroClickSignInFailure(true, false, federations); |
| 751 | |
| 752 ExpectZeroClickSignInFailure(); | |
| 753 } | 762 } |
| 754 | 763 |
| 755 TEST_F(CredentialManagerDispatcherTest, | 764 TEST_F(CredentialManagerImplTest, |
| 756 CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) { | 765 CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) { |
| 757 affiliated_form1_.federation_origin = | 766 affiliated_form1_.federation_origin = |
| 758 url::Origin(GURL("https://example.com/")); | 767 url::Origin(GURL("https://example.com/")); |
| 759 store_->AddLogin(affiliated_form1_); | 768 store_->AddLogin(affiliated_form1_); |
| 760 client_->set_first_run_seen(true); | 769 client_->set_first_run_seen(true); |
| 761 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 770 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 762 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 771 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 763 | 772 |
| 764 std::vector<GURL> federations; | 773 std::vector<GURL> federations; |
| 765 federations.push_back(GURL("https://example.com/")); | 774 federations.push_back(GURL("https://example.com/")); |
| 766 | 775 |
| 767 std::vector<std::string> affiliated_realms; | 776 std::vector<std::string> affiliated_realms; |
| 768 affiliated_realms.push_back(kTestAndroidRealm1); | 777 affiliated_realms.push_back(kTestAndroidRealm1); |
| 769 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 778 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 770 ->ExpectCallToGetAffiliatedAndroidRealms( | 779 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 771 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 780 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 772 | 781 |
| 773 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 782 ExpectZeroClickSignInSuccess(true, true, federations, |
| 774 | 783 mojom::CredentialType::FEDERATED); |
| 775 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_FEDERATED); | |
| 776 } | 784 } |
| 777 | 785 |
| 778 TEST_F(CredentialManagerDispatcherTest, | 786 TEST_F(CredentialManagerImplTest, |
| 779 CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) { | 787 CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) { |
| 780 affiliated_form1_.federation_origin = | 788 affiliated_form1_.federation_origin = |
| 781 url::Origin(GURL("https://example.com/")); | 789 url::Origin(GURL("https://example.com/")); |
| 782 store_->AddLogin(affiliated_form1_); | 790 store_->AddLogin(affiliated_form1_); |
| 783 client_->set_first_run_seen(true); | 791 client_->set_first_run_seen(true); |
| 784 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 792 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 785 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 793 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 786 | 794 |
| 787 std::vector<GURL> federations; | 795 std::vector<GURL> federations; |
| 788 federations.push_back(GURL("https://not-example.com/")); | 796 federations.push_back(GURL("https://not-example.com/")); |
| 789 | 797 |
| 790 std::vector<std::string> affiliated_realms; | 798 std::vector<std::string> affiliated_realms; |
| 791 affiliated_realms.push_back(kTestAndroidRealm1); | 799 affiliated_realms.push_back(kTestAndroidRealm1); |
| 792 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 800 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 793 ->ExpectCallToGetAffiliatedAndroidRealms( | 801 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 794 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 802 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 795 | 803 |
| 796 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 804 ExpectZeroClickSignInFailure(true, true, federations); |
| 797 | |
| 798 ExpectZeroClickSignInFailure(); | |
| 799 } | 805 } |
| 800 | 806 |
| 801 TEST_F(CredentialManagerDispatcherTest, RequestCredentialWithoutFirstRun) { | 807 TEST_F(CredentialManagerImplTest, RequestCredentialWithoutFirstRun) { |
| 802 client_->set_first_run_seen(false); | 808 client_->set_first_run_seen(false); |
| 803 | 809 |
| 804 store_->AddLogin(form_); | 810 store_->AddLogin(form_); |
| 805 | 811 |
| 806 std::vector<GURL> federations; | 812 std::vector<GURL> federations; |
| 807 EXPECT_CALL(*client_, | 813 EXPECT_CALL(*client_, |
| 808 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_))) | 814 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_))) |
| 809 .Times(1); | 815 .Times(1); |
| 810 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 811 | 816 |
| 812 ExpectZeroClickSignInFailure(); | 817 ExpectZeroClickSignInFailure(true, true, federations); |
| 813 } | 818 } |
| 814 | 819 |
| 815 TEST_F(CredentialManagerDispatcherTest, RequestCredentialWithFirstRunAndSkip) { | 820 TEST_F(CredentialManagerImplTest, RequestCredentialWithFirstRunAndSkip) { |
| 816 client_->set_first_run_seen(true); | 821 client_->set_first_run_seen(true); |
| 817 | 822 |
| 818 form_.skip_zero_click = true; | 823 form_.skip_zero_click = true; |
| 819 store_->AddLogin(form_); | 824 store_->AddLogin(form_); |
| 820 | 825 |
| 821 std::vector<GURL> federations; | 826 std::vector<GURL> federations; |
| 822 EXPECT_CALL(*client_, | 827 EXPECT_CALL(*client_, |
| 823 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_))) | 828 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_))) |
| 824 .Times(1); | 829 .Times(1); |
| 825 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 826 | 830 |
| 827 ExpectZeroClickSignInFailure(); | 831 ExpectZeroClickSignInFailure(true, true, federations); |
| 828 } | 832 } |
| 829 | 833 |
| 830 TEST_F(CredentialManagerDispatcherTest, RequestCredentialWithTLSErrors) { | 834 TEST_F(CredentialManagerImplTest, RequestCredentialWithTLSErrors) { |
| 831 // If we encounter TLS errors, we won't return credentials. | 835 // If we encounter TLS errors, we won't return credentials. |
| 832 EXPECT_CALL(*client_, DidLastPageLoadEncounterSSLErrors()) | 836 EXPECT_CALL(*client_, DidLastPageLoadEncounterSSLErrors()) |
| 833 .WillRepeatedly(testing::Return(true)); | 837 .WillRepeatedly(testing::Return(true)); |
| 834 | 838 |
| 835 store_->AddLogin(form_); | 839 store_->AddLogin(form_); |
| 836 | 840 |
| 837 std::vector<GURL> federations; | 841 std::vector<GURL> federations; |
| 838 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 839 | 842 |
| 840 ExpectZeroClickSignInFailure(); | 843 ExpectZeroClickSignInFailure(true, true, federations); |
| 841 } | 844 } |
| 842 | 845 |
| 843 TEST_F(CredentialManagerDispatcherTest, | 846 TEST_F(CredentialManagerImplTest, |
| 844 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { | 847 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { |
| 845 store_->AddLogin(form_); | 848 store_->AddLogin(form_); |
| 846 store_->AddLogin(origin_path_form_); | 849 store_->AddLogin(origin_path_form_); |
| 847 | 850 |
| 848 std::vector<GURL> federations; | 851 std::vector<GURL> federations; |
| 849 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 852 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 850 .Times(testing::Exactly(0)); | 853 .Times(testing::Exactly(0)); |
| 851 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 854 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 852 | 855 |
| 853 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 854 | |
| 855 RunAllPendingTasks(); | |
| 856 | |
| 857 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | |
| 858 const IPC::Message* message = | |
| 859 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 860 EXPECT_TRUE(message); | |
| 861 CredentialManagerMsg_SendCredential::Param send_param; | |
| 862 CredentialManagerMsg_SendCredential::Read(message, &send_param); | |
| 863 | |
| 864 // With two items in the password store, we shouldn't get credentials back. | 856 // With two items in the password store, we shouldn't get credentials back. |
| 865 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, | 857 ExpectCredentialType(true, true, federations, mojom::CredentialType::EMPTY); |
| 866 std::get<1>(send_param).type); | |
| 867 } | 858 } |
| 868 | 859 |
| 869 TEST_F(CredentialManagerDispatcherTest, | 860 TEST_F(CredentialManagerImplTest, |
| 870 OnRequestCredentialWithZeroClickOnlyAndSkipZeroClickPasswordStore) { | 861 OnRequestCredentialWithZeroClickOnlyAndSkipZeroClickPasswordStore) { |
| 871 form_.skip_zero_click = true; | 862 form_.skip_zero_click = true; |
| 872 store_->AddLogin(form_); | 863 store_->AddLogin(form_); |
| 873 store_->AddLogin(origin_path_form_); | 864 store_->AddLogin(origin_path_form_); |
| 874 | 865 |
| 875 std::vector<GURL> federations; | 866 std::vector<GURL> federations; |
| 876 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 867 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 877 .Times(testing::Exactly(0)); | 868 .Times(testing::Exactly(0)); |
| 878 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 869 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 879 | 870 |
| 880 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 881 | |
| 882 RunAllPendingTasks(); | |
| 883 | |
| 884 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | |
| 885 const IPC::Message* message = | |
| 886 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 887 EXPECT_TRUE(message); | |
| 888 CredentialManagerMsg_SendCredential::Param send_param; | |
| 889 CredentialManagerMsg_SendCredential::Read(message, &send_param); | |
| 890 | |
| 891 // With two items in the password store, we shouldn't get credentials back, | 871 // With two items in the password store, we shouldn't get credentials back, |
| 892 // even though only one item has |skip_zero_click| set |false|. | 872 // even though only one item has |skip_zero_click| set |false|. |
| 893 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, | 873 ExpectCredentialType(true, true, federations, mojom::CredentialType::EMPTY); |
| 894 std::get<1>(send_param).type); | |
| 895 } | 874 } |
| 896 | 875 |
| 897 TEST_F(CredentialManagerDispatcherTest, | 876 TEST_F(CredentialManagerImplTest, |
| 898 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) { | 877 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) { |
| 899 store_->AddLogin(cross_origin_form_); | 878 store_->AddLogin(cross_origin_form_); |
| 900 | 879 |
| 901 form_.skip_zero_click = true; | 880 form_.skip_zero_click = true; |
| 902 store_->AddLogin(form_); | 881 store_->AddLogin(form_); |
| 903 | 882 |
| 904 std::vector<GURL> federations; | 883 std::vector<GURL> federations; |
| 905 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 884 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 906 .Times(testing::Exactly(0)); | 885 .Times(testing::Exactly(0)); |
| 907 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 886 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 908 | 887 |
| 909 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 910 | |
| 911 RunAllPendingTasks(); | |
| 912 | |
| 913 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | |
| 914 const IPC::Message* message = | |
| 915 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 916 EXPECT_TRUE(message); | |
| 917 CredentialManagerMsg_SendCredential::Param send_param; | |
| 918 CredentialManagerMsg_SendCredential::Read(message, &send_param); | |
| 919 | |
| 920 // We only have cross-origin zero-click credentials; they should not be | 888 // We only have cross-origin zero-click credentials; they should not be |
| 921 // returned. | 889 // returned. |
| 922 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, | 890 ExpectCredentialType(true, true, federations, mojom::CredentialType::EMPTY); |
| 923 std::get<1>(send_param).type); | |
| 924 } | 891 } |
| 925 | 892 |
| 926 TEST_F(CredentialManagerDispatcherTest, | 893 TEST_F(CredentialManagerImplTest, |
| 927 CredentialManagerOnRequestCredentialWhileRequestPending) { | 894 CredentialManagerOnRequestCredentialWhileRequestPending) { |
| 928 client_->set_zero_click_enabled(false); | 895 client_->set_zero_click_enabled(false); |
| 929 store_->AddLogin(form_); | 896 store_->AddLogin(form_); |
| 930 | 897 |
| 931 std::vector<GURL> federations; | 898 std::vector<GURL> federations; |
| 932 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 899 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 933 .Times(testing::Exactly(0)); | 900 .Times(testing::Exactly(0)); |
| 934 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 901 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 935 | 902 |
| 936 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); | 903 // 1st request. |
| 937 dispatcher()->OnRequestCredential(kRequestId + 1, false, true, federations); | 904 bool called_1 = false; |
| 905 mojom::CredentialManagerError error_1; |
| 906 mojom::CredentialInfoPtr credential_1; |
| 907 CallGet( |
| 908 false, true, federations, |
| 909 base::Bind(&GetCredentialCallback, &called_1, &error_1, &credential_1)); |
| 910 // 2nd request. |
| 911 bool called_2 = false; |
| 912 mojom::CredentialManagerError error_2; |
| 913 mojom::CredentialInfoPtr credential_2; |
| 914 CallGet( |
| 915 false, true, federations, |
| 916 base::Bind(&GetCredentialCallback, &called_2, &error_2, &credential_2)); |
| 938 | 917 |
| 939 // Check that the second request triggered a rejection. | |
| 940 uint32_t kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; | |
| 941 const IPC::Message* message = | |
| 942 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 943 EXPECT_TRUE(message); | |
| 944 | |
| 945 CredentialManagerMsg_RejectCredentialRequest::Param reject_param; | |
| 946 CredentialManagerMsg_RejectCredentialRequest::Read(message, &reject_param); | |
| 947 EXPECT_EQ(blink::WebCredentialManagerPendingRequestError, | |
| 948 std::get<1>(reject_param)); | |
| 949 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 918 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 950 .Times(testing::Exactly(1)); | 919 .Times(testing::Exactly(1)); |
| 951 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 920 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 952 | 921 |
| 953 process()->sink().ClearMessages(); | |
| 954 | |
| 955 // Execute the PasswordStore asynchronousness. | 922 // Execute the PasswordStore asynchronousness. |
| 956 RunAllPendingTasks(); | 923 RunAllPendingTasks(); |
| 957 | 924 |
| 925 // Check that the second request triggered a rejection. |
| 926 EXPECT_TRUE(called_2); |
| 927 EXPECT_EQ(mojom::CredentialManagerError::PENDINGREQUEST, error_2); |
| 928 EXPECT_TRUE(credential_2.is_null()); |
| 929 |
| 958 // Check that the first request resolves. | 930 // Check that the first request resolves. |
| 959 kMsgID = CredentialManagerMsg_SendCredential::ID; | 931 EXPECT_TRUE(called_1); |
| 960 message = process()->sink().GetFirstMessageMatching(kMsgID); | 932 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error_1); |
| 961 EXPECT_TRUE(message); | 933 EXPECT_NE(mojom::CredentialType::EMPTY, credential_1->type); |
| 962 CredentialManagerMsg_SendCredential::Param send_param; | |
| 963 CredentialManagerMsg_SendCredential::Read(message, &send_param); | |
| 964 EXPECT_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, | |
| 965 std::get<1>(send_param).type); | |
| 966 process()->sink().ClearMessages(); | |
| 967 } | 934 } |
| 968 | 935 |
| 969 TEST_F(CredentialManagerDispatcherTest, ResetSkipZeroClickAfterPrompt) { | 936 TEST_F(CredentialManagerImplTest, ResetSkipZeroClickAfterPrompt) { |
| 970 // Turn on the global zero-click flag, and add two credentials in separate | 937 // Turn on the global zero-click flag, and add two credentials in separate |
| 971 // origins, both set to skip zero-click. | 938 // origins, both set to skip zero-click. |
| 972 client_->set_zero_click_enabled(true); | 939 client_->set_zero_click_enabled(true); |
| 973 form_.skip_zero_click = true; | 940 form_.skip_zero_click = true; |
| 974 store_->AddLogin(form_); | 941 store_->AddLogin(form_); |
| 975 cross_origin_form_.skip_zero_click = true; | 942 cross_origin_form_.skip_zero_click = true; |
| 976 store_->AddLogin(cross_origin_form_); | 943 store_->AddLogin(cross_origin_form_); |
| 977 | 944 |
| 978 // Execute the PasswordStore asynchronousness to ensure everything is | 945 // Execute the PasswordStore asynchronousness to ensure everything is |
| 979 // written before proceeding. | 946 // written before proceeding. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 992 std::vector<GURL> federations; | 959 std::vector<GURL> federations; |
| 993 // Check that the form in the database has been updated. `OnRequestCredential` | 960 // Check that the form in the database has been updated. `OnRequestCredential` |
| 994 // generates a call to prompt the user to choose a credential. | 961 // generates a call to prompt the user to choose a credential. |
| 995 // MockPasswordManagerClient mocks a user choice, and when users choose a | 962 // MockPasswordManagerClient mocks a user choice, and when users choose a |
| 996 // credential (and have the global zero-click flag enabled), we make sure that | 963 // credential (and have the global zero-click flag enabled), we make sure that |
| 997 // they'll be logged in again next time. | 964 // they'll be logged in again next time. |
| 998 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 965 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 999 .Times(testing::Exactly(1)); | 966 .Times(testing::Exactly(1)); |
| 1000 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 967 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 1001 | 968 |
| 1002 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); | 969 bool called = false; |
| 970 mojom::CredentialManagerError error; |
| 971 mojom::CredentialInfoPtr credential; |
| 972 CallGet(false, true, federations, |
| 973 base::Bind(&GetCredentialCallback, &called, &error, &credential)); |
| 974 |
| 1003 RunAllPendingTasks(); | 975 RunAllPendingTasks(); |
| 1004 | 976 |
| 1005 passwords = store_->stored_passwords(); | 977 passwords = store_->stored_passwords(); |
| 1006 EXPECT_EQ(2U, passwords.size()); | 978 EXPECT_EQ(2U, passwords.size()); |
| 1007 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); | 979 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); |
| 1008 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); | 980 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); |
| 1009 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 981 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 1010 EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); | 982 EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); |
| 1011 } | 983 } |
| 1012 | 984 |
| 1013 TEST_F(CredentialManagerDispatcherTest, | 985 TEST_F(CredentialManagerImplTest, NoResetSkipZeroClickAfterPromptInIncognito) { |
| 1014 NoResetSkipZeroClickAfterPromptInIncognito) { | |
| 1015 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); | 986 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); |
| 1016 // Turn on the global zero-click flag which should be overriden by Incognito. | 987 // Turn on the global zero-click flag which should be overriden by Incognito. |
| 1017 client_->set_zero_click_enabled(true); | 988 client_->set_zero_click_enabled(true); |
| 1018 form_.skip_zero_click = true; | 989 form_.skip_zero_click = true; |
| 1019 store_->AddLogin(form_); | 990 store_->AddLogin(form_); |
| 1020 RunAllPendingTasks(); | 991 RunAllPendingTasks(); |
| 1021 | 992 |
| 1022 // Sanity check. | 993 // Sanity check. |
| 1023 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 994 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 1024 ASSERT_EQ(1U, passwords.size()); | 995 ASSERT_EQ(1U, passwords.size()); |
| 1025 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); | 996 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); |
| 1026 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); | 997 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); |
| 1027 | 998 |
| 1028 // Trigger a request which should return the credential found in |form_|, and | 999 // Trigger a request which should return the credential found in |form_|, and |
| 1029 // wait for it to process. | 1000 // wait for it to process. |
| 1030 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 1001 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 1031 .Times(testing::Exactly(1)); | 1002 .Times(testing::Exactly(1)); |
| 1032 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 1003 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 1033 | 1004 |
| 1034 dispatcher()->OnRequestCredential(kRequestId, false, true, | 1005 bool called = false; |
| 1035 std::vector<GURL>()); | 1006 mojom::CredentialManagerError error; |
| 1007 mojom::CredentialInfoPtr credential; |
| 1008 CallGet(false, true, std::vector<GURL>(), |
| 1009 base::Bind(&GetCredentialCallback, &called, &error, &credential)); |
| 1010 |
| 1036 RunAllPendingTasks(); | 1011 RunAllPendingTasks(); |
| 1037 | 1012 |
| 1038 // The form shouldn't become a zero-click one. | 1013 // The form shouldn't become a zero-click one. |
| 1039 passwords = store_->stored_passwords(); | 1014 passwords = store_->stored_passwords(); |
| 1040 ASSERT_EQ(1U, passwords.size()); | 1015 ASSERT_EQ(1U, passwords.size()); |
| 1041 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); | 1016 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); |
| 1042 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); | 1017 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); |
| 1043 } | 1018 } |
| 1044 | 1019 |
| 1045 TEST_F(CredentialManagerDispatcherTest, IncognitoZeroClickRequestCredential) { | 1020 TEST_F(CredentialManagerImplTest, IncognitoZeroClickRequestCredential) { |
| 1046 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); | 1021 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); |
| 1047 store_->AddLogin(form_); | 1022 store_->AddLogin(form_); |
| 1048 | 1023 |
| 1049 std::vector<GURL> federations; | 1024 std::vector<GURL> federations; |
| 1050 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 1025 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 1051 .Times(testing::Exactly(0)); | 1026 .Times(testing::Exactly(0)); |
| 1052 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 1027 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 1053 | 1028 |
| 1054 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1029 ExpectCredentialType(true, true, federations, mojom::CredentialType::EMPTY); |
| 1055 | |
| 1056 RunAllPendingTasks(); | |
| 1057 | |
| 1058 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | |
| 1059 const IPC::Message* message = | |
| 1060 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 1061 ASSERT_TRUE(message); | |
| 1062 CredentialManagerMsg_SendCredential::Param param; | |
| 1063 CredentialManagerMsg_SendCredential::Read(message, ¶m); | |
| 1064 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, std::get<1>(param).type); | |
| 1065 } | 1030 } |
| 1066 | 1031 |
| 1067 TEST_F(CredentialManagerDispatcherTest, | 1032 TEST_F(CredentialManagerImplTest, ZeroClickWithAffiliatedFormInPasswordStore) { |
| 1068 ZeroClickWithAffiliatedFormInPasswordStore) { | |
| 1069 // Insert the affiliated form into the store, and mock out the association | 1033 // Insert the affiliated form into the store, and mock out the association |
| 1070 // with the current origin. As it's the only form matching the origin, it | 1034 // with the current origin. As it's the only form matching the origin, it |
| 1071 // ought to be returned automagically. | 1035 // ought to be returned automagically. |
| 1072 store_->AddLogin(affiliated_form1_); | 1036 store_->AddLogin(affiliated_form1_); |
| 1073 | 1037 |
| 1074 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 1038 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 1075 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 1039 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 1076 | 1040 |
| 1077 std::vector<GURL> federations; | 1041 std::vector<GURL> federations; |
| 1078 std::vector<std::string> affiliated_realms; | 1042 std::vector<std::string> affiliated_realms; |
| 1079 affiliated_realms.push_back(kTestAndroidRealm1); | 1043 affiliated_realms.push_back(kTestAndroidRealm1); |
| 1080 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 1044 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 1081 ->ExpectCallToGetAffiliatedAndroidRealms( | 1045 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 1082 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 1046 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 1083 | 1047 |
| 1084 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1048 ExpectZeroClickSignInSuccess(true, true, federations, |
| 1085 | 1049 mojom::CredentialType::PASSWORD); |
| 1086 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); | |
| 1087 } | 1050 } |
| 1088 | 1051 |
| 1089 TEST_F(CredentialManagerDispatcherTest, | 1052 TEST_F(CredentialManagerImplTest, |
| 1090 ZeroClickWithTwoAffiliatedFormsInPasswordStore) { | 1053 ZeroClickWithTwoAffiliatedFormsInPasswordStore) { |
| 1091 // Insert two affiliated forms into the store, and mock out the association | 1054 // Insert two affiliated forms into the store, and mock out the association |
| 1092 // with the current origin. Multiple forms === no zero-click sign in. | 1055 // with the current origin. Multiple forms === no zero-click sign in. |
| 1093 store_->AddLogin(affiliated_form1_); | 1056 store_->AddLogin(affiliated_form1_); |
| 1094 store_->AddLogin(affiliated_form2_); | 1057 store_->AddLogin(affiliated_form2_); |
| 1095 | 1058 |
| 1096 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 1059 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 1097 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 1060 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 1098 | 1061 |
| 1099 std::vector<GURL> federations; | 1062 std::vector<GURL> federations; |
| 1100 std::vector<std::string> affiliated_realms; | 1063 std::vector<std::string> affiliated_realms; |
| 1101 affiliated_realms.push_back(kTestAndroidRealm1); | 1064 affiliated_realms.push_back(kTestAndroidRealm1); |
| 1102 affiliated_realms.push_back(kTestAndroidRealm2); | 1065 affiliated_realms.push_back(kTestAndroidRealm2); |
| 1103 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 1066 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 1104 ->ExpectCallToGetAffiliatedAndroidRealms( | 1067 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 1105 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 1068 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 1106 | 1069 |
| 1107 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1070 ExpectZeroClickSignInFailure(true, true, federations); |
| 1108 | |
| 1109 ExpectZeroClickSignInFailure(); | |
| 1110 } | 1071 } |
| 1111 | 1072 |
| 1112 TEST_F(CredentialManagerDispatcherTest, | 1073 TEST_F(CredentialManagerImplTest, |
| 1113 ZeroClickWithUnaffiliatedFormsInPasswordStore) { | 1074 ZeroClickWithUnaffiliatedFormsInPasswordStore) { |
| 1114 // Insert the affiliated form into the store, but don't mock out the | 1075 // Insert the affiliated form into the store, but don't mock out the |
| 1115 // association with the current origin. No association === no zero-click sign | 1076 // association with the current origin. No association === no zero-click sign |
| 1116 // in. | 1077 // in. |
| 1117 store_->AddLogin(affiliated_form1_); | 1078 store_->AddLogin(affiliated_form1_); |
| 1118 | 1079 |
| 1119 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 1080 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 1120 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 1081 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 1121 | 1082 |
| 1122 std::vector<GURL> federations; | 1083 std::vector<GURL> federations; |
| 1123 std::vector<std::string> affiliated_realms; | 1084 std::vector<std::string> affiliated_realms; |
| 1124 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 1085 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 1125 ->ExpectCallToGetAffiliatedAndroidRealms( | 1086 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 1126 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 1087 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 1127 | 1088 |
| 1128 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1089 ExpectZeroClickSignInFailure(true, true, federations); |
| 1129 | |
| 1130 ExpectZeroClickSignInFailure(); | |
| 1131 } | 1090 } |
| 1132 | 1091 |
| 1133 TEST_F(CredentialManagerDispatcherTest, | 1092 TEST_F(CredentialManagerImplTest, |
| 1134 ZeroClickWithFormAndUnaffiliatedFormsInPasswordStore) { | 1093 ZeroClickWithFormAndUnaffiliatedFormsInPasswordStore) { |
| 1135 // Insert the affiliated form into the store, along with a real form for the | 1094 // Insert the affiliated form into the store, along with a real form for the |
| 1136 // origin, and don't mock out the association with the current origin. No | 1095 // origin, and don't mock out the association with the current origin. No |
| 1137 // association + existing form === zero-click sign in. | 1096 // association + existing form === zero-click sign in. |
| 1138 store_->AddLogin(form_); | 1097 store_->AddLogin(form_); |
| 1139 store_->AddLogin(affiliated_form1_); | 1098 store_->AddLogin(affiliated_form1_); |
| 1140 | 1099 |
| 1141 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 1100 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 1142 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 1101 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 1143 | 1102 |
| 1144 std::vector<GURL> federations; | 1103 std::vector<GURL> federations; |
| 1145 std::vector<std::string> affiliated_realms; | 1104 std::vector<std::string> affiliated_realms; |
| 1146 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 1105 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 1147 ->ExpectCallToGetAffiliatedAndroidRealms( | 1106 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 1148 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 1107 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 1149 | 1108 |
| 1150 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1109 ExpectZeroClickSignInSuccess(true, true, federations, |
| 1151 | 1110 mojom::CredentialType::PASSWORD); |
| 1152 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); | |
| 1153 } | 1111 } |
| 1154 | 1112 |
| 1155 TEST_F(CredentialManagerDispatcherTest, GetSynthesizedFormForOrigin) { | 1113 TEST_F(CredentialManagerImplTest, GetSynthesizedFormForOrigin) { |
| 1156 autofill::PasswordForm synthesized = | 1114 autofill::PasswordForm synthesized = |
| 1157 dispatcher_->GetSynthesizedFormForOrigin(); | 1115 cm_service_impl_->GetSynthesizedFormForOrigin(); |
| 1158 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); | 1116 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); |
| 1159 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); | 1117 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); |
| 1160 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); | 1118 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); |
| 1161 EXPECT_TRUE(synthesized.ssl_valid); | 1119 EXPECT_TRUE(synthesized.ssl_valid); |
| 1162 } | 1120 } |
| 1163 | 1121 |
| 1164 } // namespace password_manager | 1122 } // namespace password_manager |
| OLD | NEW |