| 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 client_->set_first_run_seen(true); | 442 client_->set_first_run_seen(true); |
| 396 form_.skip_zero_click = true; | 443 form_.skip_zero_click = true; |
| 397 store_->AddLogin(form_); | 444 store_->AddLogin(form_); |
| 398 RunAllPendingTasks(); | 445 RunAllPendingTasks(); |
| 399 | 446 |
| 400 // Calling 'OnStore' with a credential that matches |form_| should update | 447 // Calling 'Store' with a credential that matches |form_| should update |
| 401 // the credential without prompting the user. | 448 // the credential without prompting the user. |
| 402 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); | 449 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_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 toggled the skip_zero_click flag off. | 457 // Verify that the update toggled the skip_zero_click flag off. |
| 411 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 458 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 412 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 459 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 413 } | 460 } |
| 414 | 461 |
| 415 TEST_F(CredentialManagerDispatcherTest, | 462 TEST_F(CredentialManagerImplTest, |
| 416 CredentialManagerFederatedStoreOverwriteZeroClick) { | 463 CredentialManagerFederatedStoreOverwriteZeroClick) { |
| 417 // Set the global zero click flag on, and populate the PasswordStore with a | 464 // Set the global zero click flag on, and populate the PasswordStore with a |
| 418 // form that's set to skip zero click. | 465 // form that's set to skip zero click. |
| 419 client_->set_zero_click_enabled(true); | 466 client_->set_zero_click_enabled(true); |
| 420 client_->set_first_run_seen(true); | 467 client_->set_first_run_seen(true); |
| 421 form_.federation_origin = url::Origin(GURL("https://example.com/")); | 468 form_.federation_origin = url::Origin(GURL("https://example.com/")); |
| 422 form_.skip_zero_click = true; | 469 form_.skip_zero_click = true; |
| 423 form_.signon_realm = "federation://example.com/example.com"; | 470 form_.signon_realm = "federation://example.com/example.com"; |
| 424 store_->AddLogin(form_); | 471 store_->AddLogin(form_); |
| 425 RunAllPendingTasks(); | 472 RunAllPendingTasks(); |
| 426 | 473 |
| 427 // Calling 'OnStore' with a credential that matches |form_| should update | 474 // Calling 'Store' with a credential that matches |form_| should update |
| 428 // the credential without prompting the user. | 475 // the credential without prompting the user. |
| 429 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); | 476 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); |
| 430 dispatcher()->OnStore(kRequestId, info); | 477 bool called = false; |
| 431 process()->sink().ClearMessages(); | 478 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 432 | 479 |
| 433 // Allow the PasswordFormManager to talk to the password store, determine | 480 // Allow the PasswordFormManager to talk to the password store, determine |
| 434 // the form is a match for an existing form, and update the PasswordStore. | 481 // the form is a match for an existing form, and update the PasswordStore. |
| 435 RunAllPendingTasks(); | 482 RunAllPendingTasks(); |
| 436 | 483 |
| 437 // Verify that the update toggled the skip_zero_click flag off. | 484 // Verify that the update toggled the skip_zero_click flag off. |
| 438 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 485 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 439 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 486 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 440 } | 487 } |
| 441 | 488 |
| 442 TEST_F(CredentialManagerDispatcherTest, | 489 TEST_F(CredentialManagerImplTest, CredentialManagerGetOverwriteZeroClick) { |
| 443 CredentialManagerGetOverwriteZeroClick) { | |
| 444 // Set the global zero click flag on, and populate the PasswordStore with a | 490 // Set the global zero click flag on, and populate the PasswordStore with a |
| 445 // form that's set to skip zero click and has a primary key that won't match | 491 // form that's set to skip zero click and has a primary key that won't match |
| 446 // credentials initially created via `store()`. | 492 // credentials initially created via `store()`. |
| 447 client_->set_zero_click_enabled(true); | 493 client_->set_zero_click_enabled(true); |
| 448 form_.skip_zero_click = true; | 494 form_.skip_zero_click = true; |
| 449 form_.username_element = base::ASCIIToUTF16("username-element"); | 495 form_.username_element = base::ASCIIToUTF16("username-element"); |
| 450 form_.password_element = base::ASCIIToUTF16("password-element"); | 496 form_.password_element = base::ASCIIToUTF16("password-element"); |
| 451 form_.signon_realm = "this is a realm"; | 497 form_.signon_realm = "this is a realm"; |
| 452 form_.origin = GURL("https://example.com/old_form.html"); | 498 form_.origin = GURL("https://example.com/old_form.html"); |
| 453 store_->AddLogin(form_); | 499 store_->AddLogin(form_); |
| 454 RunAllPendingTasks(); | 500 RunAllPendingTasks(); |
| 455 | 501 |
| 456 std::vector<GURL> federations; | 502 std::vector<GURL> federations; |
| 457 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 503 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 458 .Times(testing::Exactly(1)); | 504 .Times(testing::Exactly(1)); |
| 459 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 505 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 460 | 506 |
| 461 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); | 507 bool called = false; |
| 508 mojom::CredentialManagerError error; |
| 509 mojom::CredentialInfoPtr credential; |
| 510 CallGet(false, true, federations, |
| 511 base::Bind(&GetCredentialCallback, &called, &error, &credential)); |
| 462 | 512 |
| 463 RunAllPendingTasks(); | 513 RunAllPendingTasks(); |
| 464 | 514 |
| 465 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | 515 EXPECT_TRUE(called); |
| 466 const IPC::Message* message = | 516 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error); |
| 467 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 468 EXPECT_TRUE(message); | |
| 469 | 517 |
| 470 // Verify that the update toggled the skip_zero_click flag. | 518 // Verify that the update toggled the skip_zero_click flag. |
| 471 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 519 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 472 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 520 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 473 } | 521 } |
| 474 | 522 |
| 475 TEST_F(CredentialManagerDispatcherTest, | 523 TEST_F(CredentialManagerImplTest, |
| 476 CredentialManagerSignInWithSavingDisabledForCurrentPage) { | 524 CredentialManagerSignInWithSavingDisabledForCurrentPage) { |
| 477 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); | 525 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 478 EXPECT_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) | 526 EXPECT_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) |
| 479 .WillRepeatedly(testing::Return(false)); | 527 .WillRepeatedly(testing::Return(false)); |
| 480 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | 528 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
| 481 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) | 529 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) |
| 482 .Times(testing::Exactly(0)); | 530 .Times(testing::Exactly(0)); |
| 483 | 531 |
| 484 dispatcher()->OnStore(kRequestId, info); | 532 bool called = false; |
| 485 | 533 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 486 const uint32_t kMsgID = CredentialManagerMsg_AcknowledgeStore::ID; | |
| 487 const IPC::Message* message = | |
| 488 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 489 EXPECT_TRUE(message); | |
| 490 process()->sink().ClearMessages(); | |
| 491 | 534 |
| 492 RunAllPendingTasks(); | 535 RunAllPendingTasks(); |
| 493 | 536 |
| 537 EXPECT_TRUE(called); |
| 494 EXPECT_FALSE(client_->pending_manager()); | 538 EXPECT_FALSE(client_->pending_manager()); |
| 495 } | 539 } |
| 496 | 540 |
| 497 TEST_F(CredentialManagerDispatcherTest, | 541 TEST_F(CredentialManagerImplTest, CredentialManagerOnRequireUserMediation) { |
| 498 CredentialManagerOnRequireUserMediation) { | |
| 499 store_->AddLogin(form_); | 542 store_->AddLogin(form_); |
| 500 store_->AddLogin(cross_origin_form_); | 543 store_->AddLogin(cross_origin_form_); |
| 501 RunAllPendingTasks(); | 544 RunAllPendingTasks(); |
| 502 | 545 |
| 503 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 546 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 504 EXPECT_EQ(2U, passwords.size()); | 547 EXPECT_EQ(2U, passwords.size()); |
| 505 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); | 548 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); |
| 506 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); | 549 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); |
| 507 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 550 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 508 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); | 551 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); |
| 509 | 552 |
| 510 dispatcher()->OnRequireUserMediation(kRequestId); | 553 bool called = false; |
| 554 CallRequireUserMediation(base::Bind(&RespondCallback, &called)); |
| 555 |
| 511 RunAllPendingTasks(); | 556 RunAllPendingTasks(); |
| 512 | 557 |
| 513 const uint32_t kMsgID = | 558 EXPECT_TRUE(called); |
| 514 CredentialManagerMsg_AcknowledgeRequireUserMediation::ID; | |
| 515 const IPC::Message* message = | |
| 516 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 517 EXPECT_TRUE(message); | |
| 518 process()->sink().ClearMessages(); | |
| 519 | 559 |
| 520 passwords = store_->stored_passwords(); | 560 passwords = store_->stored_passwords(); |
| 521 EXPECT_EQ(2U, passwords.size()); | 561 EXPECT_EQ(2U, passwords.size()); |
| 522 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); | 562 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); |
| 523 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); | 563 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); |
| 524 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); | 564 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); |
| 525 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); | 565 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); |
| 526 } | 566 } |
| 527 | 567 |
| 528 TEST_F(CredentialManagerDispatcherTest, | 568 TEST_F(CredentialManagerImplTest, |
| 529 CredentialManagerOnRequireUserMediationIncognito) { | 569 CredentialManagerOnRequireUserMediationIncognito) { |
| 530 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); | 570 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); |
| 531 store_->AddLogin(form_); | 571 store_->AddLogin(form_); |
| 532 RunAllPendingTasks(); | 572 RunAllPendingTasks(); |
| 533 | 573 |
| 534 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 574 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 535 ASSERT_EQ(1U, passwords.size()); | 575 ASSERT_EQ(1U, passwords.size()); |
| 536 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); | 576 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); |
| 537 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 577 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 538 | 578 |
| 539 dispatcher()->OnRequireUserMediation(kRequestId); | 579 bool called = false; |
| 580 CallRequireUserMediation(base::Bind(&RespondCallback, &called)); |
| 540 RunAllPendingTasks(); | 581 RunAllPendingTasks(); |
| 541 | 582 |
| 542 const uint32_t kMsgID = | 583 EXPECT_TRUE(called); |
| 543 CredentialManagerMsg_AcknowledgeRequireUserMediation::ID; | |
| 544 const IPC::Message* message = | |
| 545 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 546 EXPECT_TRUE(message); | |
| 547 process()->sink().ClearMessages(); | |
| 548 | 584 |
| 549 passwords = store_->stored_passwords(); | 585 passwords = store_->stored_passwords(); |
| 550 ASSERT_EQ(1U, passwords.size()); | 586 ASSERT_EQ(1U, passwords.size()); |
| 551 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); | 587 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); |
| 552 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 588 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 553 } | 589 } |
| 554 | 590 |
| 555 TEST_F(CredentialManagerDispatcherTest, | 591 TEST_F(CredentialManagerImplTest, |
| 556 CredentialManagerOnRequireUserMediationWithAffiliation) { | 592 CredentialManagerOnRequireUserMediationWithAffiliation) { |
| 557 store_->AddLogin(form_); | 593 store_->AddLogin(form_); |
| 558 store_->AddLogin(cross_origin_form_); | 594 store_->AddLogin(cross_origin_form_); |
| 559 store_->AddLogin(affiliated_form1_); | 595 store_->AddLogin(affiliated_form1_); |
| 560 store_->AddLogin(affiliated_form2_); | 596 store_->AddLogin(affiliated_form2_); |
| 561 | 597 |
| 562 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 598 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 563 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 599 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 564 | 600 |
| 565 std::vector<GURL> federations; | 601 std::vector<GURL> federations; |
| 566 std::vector<std::string> affiliated_realms; | 602 std::vector<std::string> affiliated_realms; |
| 567 affiliated_realms.push_back(kTestAndroidRealm1); | 603 affiliated_realms.push_back(kTestAndroidRealm1); |
| 568 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 604 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 569 ->ExpectCallToGetAffiliatedAndroidRealms( | 605 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 570 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 606 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 571 RunAllPendingTasks(); | 607 RunAllPendingTasks(); |
| 572 | 608 |
| 573 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 609 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 574 EXPECT_EQ(4U, passwords.size()); | 610 EXPECT_EQ(4U, passwords.size()); |
| 575 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 611 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 576 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); | 612 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); |
| 577 EXPECT_FALSE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click); | 613 EXPECT_FALSE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click); |
| 578 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click); | 614 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click); |
| 579 | 615 |
| 580 dispatcher()->OnRequireUserMediation(kRequestId); | 616 bool called = false; |
| 617 CallRequireUserMediation(base::Bind(&RespondCallback, &called)); |
| 581 RunAllPendingTasks(); | 618 RunAllPendingTasks(); |
| 582 process()->sink().ClearMessages(); | |
| 583 | 619 |
| 584 passwords = store_->stored_passwords(); | 620 passwords = store_->stored_passwords(); |
| 585 EXPECT_EQ(4U, passwords.size()); | 621 EXPECT_EQ(4U, passwords.size()); |
| 586 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); | 622 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); |
| 587 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); | 623 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); |
| 588 EXPECT_TRUE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click); | 624 EXPECT_TRUE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click); |
| 589 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click); | 625 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click); |
| 590 } | 626 } |
| 591 | 627 |
| 592 TEST_F(CredentialManagerDispatcherTest, | 628 TEST_F(CredentialManagerImplTest, |
| 593 CredentialManagerOnRequestCredentialWithEmptyPasswordStore) { | 629 CredentialManagerOnRequestCredentialWithEmptyPasswordStore) { |
| 594 std::vector<GURL> federations; | 630 std::vector<GURL> federations; |
| 595 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | 631 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
| 596 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) | 632 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) |
| 597 .Times(testing::Exactly(0)); | 633 .Times(testing::Exactly(0)); |
| 598 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 634 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 599 .Times(testing::Exactly(0)); | 635 .Times(testing::Exactly(0)); |
| 600 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 636 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 601 | 637 |
| 602 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); | 638 ExpectCredentialType(false, true, federations, mojom::CredentialType::EMPTY); |
| 603 | |
| 604 RunAllPendingTasks(); | |
| 605 | |
| 606 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | |
| 607 const IPC::Message* message = | |
| 608 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 609 EXPECT_TRUE(message); | |
| 610 CredentialManagerMsg_SendCredential::Param param; | |
| 611 CredentialManagerMsg_SendCredential::Read(message, ¶m); | |
| 612 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, std::get<1>(param).type); | |
| 613 process()->sink().ClearMessages(); | |
| 614 } | 639 } |
| 615 | 640 |
| 616 TEST_F(CredentialManagerDispatcherTest, | 641 TEST_F(CredentialManagerImplTest, |
| 617 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) { | 642 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) { |
| 618 store_->AddLogin(cross_origin_form_); | 643 store_->AddLogin(cross_origin_form_); |
| 619 | 644 |
| 620 std::vector<GURL> federations; | 645 std::vector<GURL> federations; |
| 621 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | 646 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
| 622 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) | 647 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) |
| 623 .Times(testing::Exactly(0)); | 648 .Times(testing::Exactly(0)); |
| 624 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 649 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 625 .Times(testing::Exactly(0)); | 650 .Times(testing::Exactly(0)); |
| 626 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 651 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 627 | 652 |
| 628 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); | 653 ExpectCredentialType(false, true, federations, mojom::CredentialType::EMPTY); |
| 629 | |
| 630 RunAllPendingTasks(); | |
| 631 | |
| 632 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | |
| 633 const IPC::Message* message = | |
| 634 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 635 EXPECT_TRUE(message); | |
| 636 CredentialManagerMsg_SendCredential::Param param; | |
| 637 CredentialManagerMsg_SendCredential::Read(message, ¶m); | |
| 638 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, std::get<1>(param).type); | |
| 639 process()->sink().ClearMessages(); | |
| 640 } | 654 } |
| 641 | 655 |
| 642 TEST_F(CredentialManagerDispatcherTest, | 656 TEST_F(CredentialManagerImplTest, |
| 643 CredentialManagerOnRequestCredentialWithFullPasswordStore) { | 657 CredentialManagerOnRequestCredentialWithFullPasswordStore) { |
| 644 client_->set_zero_click_enabled(false); | 658 client_->set_zero_click_enabled(false); |
| 645 store_->AddLogin(form_); | 659 store_->AddLogin(form_); |
| 646 | 660 |
| 647 std::vector<GURL> federations; | 661 std::vector<GURL> federations; |
| 648 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 662 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 649 .Times(testing::Exactly(1)); | 663 .Times(testing::Exactly(1)); |
| 650 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 664 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 651 | 665 |
| 652 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); | 666 bool called = false; |
| 667 mojom::CredentialManagerError error; |
| 668 mojom::CredentialInfoPtr credential; |
| 669 CallGet(false, true, federations, |
| 670 base::Bind(&GetCredentialCallback, &called, &error, &credential)); |
| 653 | 671 |
| 654 RunAllPendingTasks(); | 672 RunAllPendingTasks(); |
| 655 | 673 |
| 656 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | 674 EXPECT_TRUE(called); |
| 657 const IPC::Message* message = | 675 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error); |
| 658 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 659 EXPECT_TRUE(message); | |
| 660 } | 676 } |
| 661 | 677 |
| 662 TEST_F( | 678 TEST_F( |
| 663 CredentialManagerDispatcherTest, | 679 CredentialManagerImplTest, |
| 664 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) { | 680 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) { |
| 665 std::vector<GURL> federations; | 681 std::vector<GURL> federations; |
| 666 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 682 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 667 .Times(testing::Exactly(0)); | 683 .Times(testing::Exactly(0)); |
| 668 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 684 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 669 | 685 |
| 670 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 686 bool called = false; |
| 687 mojom::CredentialManagerError error; |
| 688 mojom::CredentialInfoPtr credential; |
| 689 CallGet(true, true, federations, |
| 690 base::Bind(&GetCredentialCallback, &called, &error, &credential)); |
| 671 | 691 |
| 672 RunAllPendingTasks(); | 692 RunAllPendingTasks(); |
| 673 | 693 |
| 674 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | 694 EXPECT_TRUE(called); |
| 675 const IPC::Message* message = | 695 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error); |
| 676 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 677 EXPECT_TRUE(message); | |
| 678 CredentialManagerMsg_SendCredential::Param send_param; | |
| 679 CredentialManagerMsg_SendCredential::Read(message, &send_param); | |
| 680 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, | |
| 681 std::get<1>(send_param).type); | |
| 682 } | 696 } |
| 683 | 697 |
| 684 TEST_F(CredentialManagerDispatcherTest, | 698 TEST_F(CredentialManagerImplTest, |
| 685 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) { | 699 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) { |
| 686 store_->AddLogin(form_); | 700 store_->AddLogin(form_); |
| 687 client_->set_first_run_seen(true); | 701 client_->set_first_run_seen(true); |
| 688 | 702 |
| 689 std::vector<GURL> federations; | 703 std::vector<GURL> federations; |
| 690 | 704 |
| 691 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); | 705 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); |
| 692 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 693 | 706 |
| 694 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); | 707 ExpectZeroClickSignInSuccess(true, true, federations, |
| 708 mojom::CredentialType::PASSWORD); |
| 695 } | 709 } |
| 696 | 710 |
| 697 TEST_F(CredentialManagerDispatcherTest, | 711 TEST_F(CredentialManagerImplTest, |
| 698 CredentialManagerOnRequestCredentialWithoutPasswords) { | 712 CredentialManagerOnRequestCredentialWithoutPasswords) { |
| 699 store_->AddLogin(form_); | 713 store_->AddLogin(form_); |
| 700 client_->set_first_run_seen(true); | 714 client_->set_first_run_seen(true); |
| 701 | 715 |
| 702 std::vector<GURL> federations; | 716 std::vector<GURL> federations; |
| 703 | 717 |
| 704 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); | 718 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); |
| 705 dispatcher()->OnRequestCredential(kRequestId, true, false, federations); | |
| 706 | 719 |
| 707 ExpectZeroClickSignInFailure(); | 720 ExpectZeroClickSignInFailure(true, false, federations); |
| 708 } | 721 } |
| 709 | 722 |
| 710 TEST_F(CredentialManagerDispatcherTest, | 723 TEST_F(CredentialManagerImplTest, |
| 711 CredentialManagerOnRequestCredentialFederatedMatch) { | 724 CredentialManagerOnRequestCredentialFederatedMatch) { |
| 712 form_.federation_origin = url::Origin(GURL("https://example.com/")); | 725 form_.federation_origin = url::Origin(GURL("https://example.com/")); |
| 713 store_->AddLogin(form_); | 726 store_->AddLogin(form_); |
| 714 client_->set_first_run_seen(true); | 727 client_->set_first_run_seen(true); |
| 715 | 728 |
| 716 std::vector<GURL> federations; | 729 std::vector<GURL> federations; |
| 717 federations.push_back(GURL("https://example.com/")); | 730 federations.push_back(GURL("https://example.com/")); |
| 718 | 731 |
| 719 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); | 732 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); |
| 720 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 721 | 733 |
| 722 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_FEDERATED); | 734 ExpectZeroClickSignInSuccess(true, true, federations, |
| 735 mojom::CredentialType::FEDERATED); |
| 723 } | 736 } |
| 724 | 737 |
| 725 TEST_F(CredentialManagerDispatcherTest, | 738 TEST_F(CredentialManagerImplTest, |
| 726 CredentialManagerOnRequestCredentialFederatedNoMatch) { | 739 CredentialManagerOnRequestCredentialFederatedNoMatch) { |
| 727 form_.federation_origin = url::Origin(GURL("https://example.com/")); | 740 form_.federation_origin = url::Origin(GURL("https://example.com/")); |
| 728 store_->AddLogin(form_); | 741 store_->AddLogin(form_); |
| 729 client_->set_first_run_seen(true); | 742 client_->set_first_run_seen(true); |
| 730 | 743 |
| 731 std::vector<GURL> federations; | 744 std::vector<GURL> federations; |
| 732 federations.push_back(GURL("https://not-example.com/")); | 745 federations.push_back(GURL("https://not-example.com/")); |
| 733 | 746 |
| 734 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); | 747 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); |
| 735 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 736 | 748 |
| 737 ExpectZeroClickSignInFailure(); | 749 ExpectZeroClickSignInFailure(true, true, federations); |
| 738 } | 750 } |
| 739 | 751 |
| 740 TEST_F(CredentialManagerDispatcherTest, | 752 TEST_F(CredentialManagerImplTest, |
| 741 CredentialManagerOnRequestCredentialAffiliatedPasswordMatch) { | 753 CredentialManagerOnRequestCredentialAffiliatedPasswordMatch) { |
| 742 store_->AddLogin(affiliated_form1_); | 754 store_->AddLogin(affiliated_form1_); |
| 743 client_->set_first_run_seen(true); | 755 client_->set_first_run_seen(true); |
| 744 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 756 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 745 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 757 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 746 | 758 |
| 747 std::vector<GURL> federations; | 759 std::vector<GURL> federations; |
| 748 std::vector<std::string> affiliated_realms; | 760 std::vector<std::string> affiliated_realms; |
| 749 affiliated_realms.push_back(kTestAndroidRealm1); | 761 affiliated_realms.push_back(kTestAndroidRealm1); |
| 750 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 762 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 751 ->ExpectCallToGetAffiliatedAndroidRealms( | 763 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 752 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 764 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 753 | 765 |
| 754 // We pass in 'true' for the 'include_passwords' argument to ensure that | 766 // We pass in 'true' for the 'include_passwords' argument to ensure that |
| 755 // password-type credentials are included as potential matches. | 767 // password-type credentials are included as potential matches. |
| 756 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 768 ExpectZeroClickSignInSuccess(true, true, federations, |
| 757 | 769 mojom::CredentialType::PASSWORD); |
| 758 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); | |
| 759 } | 770 } |
| 760 | 771 |
| 761 TEST_F(CredentialManagerDispatcherTest, | 772 TEST_F(CredentialManagerImplTest, |
| 762 CredentialManagerOnRequestCredentialAffiliatedPasswordNoMatch) { | 773 CredentialManagerOnRequestCredentialAffiliatedPasswordNoMatch) { |
| 763 store_->AddLogin(affiliated_form1_); | 774 store_->AddLogin(affiliated_form1_); |
| 764 client_->set_first_run_seen(true); | 775 client_->set_first_run_seen(true); |
| 765 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 776 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 766 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 777 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 767 | 778 |
| 768 std::vector<GURL> federations; | 779 std::vector<GURL> federations; |
| 769 std::vector<std::string> affiliated_realms; | 780 std::vector<std::string> affiliated_realms; |
| 770 affiliated_realms.push_back(kTestAndroidRealm1); | 781 affiliated_realms.push_back(kTestAndroidRealm1); |
| 771 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 782 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 772 ->ExpectCallToGetAffiliatedAndroidRealms( | 783 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 773 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 784 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 774 | 785 |
| 775 // We pass in 'false' for the 'include_passwords' argument to ensure that | 786 // We pass in 'false' for the 'include_passwords' argument to ensure that |
| 776 // password-type credentials are excluded as potential matches. | 787 // password-type credentials are excluded as potential matches. |
| 777 dispatcher()->OnRequestCredential(kRequestId, true, false, federations); | 788 ExpectZeroClickSignInFailure(true, false, federations); |
| 778 | |
| 779 ExpectZeroClickSignInFailure(); | |
| 780 } | 789 } |
| 781 | 790 |
| 782 TEST_F(CredentialManagerDispatcherTest, | 791 TEST_F(CredentialManagerImplTest, |
| 783 CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) { | 792 CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) { |
| 784 affiliated_form1_.federation_origin = | 793 affiliated_form1_.federation_origin = |
| 785 url::Origin(GURL("https://example.com/")); | 794 url::Origin(GURL("https://example.com/")); |
| 786 store_->AddLogin(affiliated_form1_); | 795 store_->AddLogin(affiliated_form1_); |
| 787 client_->set_first_run_seen(true); | 796 client_->set_first_run_seen(true); |
| 788 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 797 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 789 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 798 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 790 | 799 |
| 791 std::vector<GURL> federations; | 800 std::vector<GURL> federations; |
| 792 federations.push_back(GURL("https://example.com/")); | 801 federations.push_back(GURL("https://example.com/")); |
| 793 | 802 |
| 794 std::vector<std::string> affiliated_realms; | 803 std::vector<std::string> affiliated_realms; |
| 795 affiliated_realms.push_back(kTestAndroidRealm1); | 804 affiliated_realms.push_back(kTestAndroidRealm1); |
| 796 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 805 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 797 ->ExpectCallToGetAffiliatedAndroidRealms( | 806 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 798 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 807 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 799 | 808 |
| 800 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 809 ExpectZeroClickSignInSuccess(true, true, federations, |
| 801 | 810 mojom::CredentialType::FEDERATED); |
| 802 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_FEDERATED); | |
| 803 } | 811 } |
| 804 | 812 |
| 805 TEST_F(CredentialManagerDispatcherTest, | 813 TEST_F(CredentialManagerImplTest, |
| 806 CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) { | 814 CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) { |
| 807 affiliated_form1_.federation_origin = | 815 affiliated_form1_.federation_origin = |
| 808 url::Origin(GURL("https://example.com/")); | 816 url::Origin(GURL("https://example.com/")); |
| 809 store_->AddLogin(affiliated_form1_); | 817 store_->AddLogin(affiliated_form1_); |
| 810 client_->set_first_run_seen(true); | 818 client_->set_first_run_seen(true); |
| 811 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 819 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 812 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 820 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 813 | 821 |
| 814 std::vector<GURL> federations; | 822 std::vector<GURL> federations; |
| 815 federations.push_back(GURL("https://not-example.com/")); | 823 federations.push_back(GURL("https://not-example.com/")); |
| 816 | 824 |
| 817 std::vector<std::string> affiliated_realms; | 825 std::vector<std::string> affiliated_realms; |
| 818 affiliated_realms.push_back(kTestAndroidRealm1); | 826 affiliated_realms.push_back(kTestAndroidRealm1); |
| 819 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 827 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 820 ->ExpectCallToGetAffiliatedAndroidRealms( | 828 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 821 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 829 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 822 | 830 |
| 823 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 831 ExpectZeroClickSignInFailure(true, true, federations); |
| 824 | |
| 825 ExpectZeroClickSignInFailure(); | |
| 826 } | 832 } |
| 827 | 833 |
| 828 TEST_F(CredentialManagerDispatcherTest, RequestCredentialWithoutFirstRun) { | 834 TEST_F(CredentialManagerImplTest, RequestCredentialWithoutFirstRun) { |
| 829 client_->set_first_run_seen(false); | 835 client_->set_first_run_seen(false); |
| 830 | 836 |
| 831 store_->AddLogin(form_); | 837 store_->AddLogin(form_); |
| 832 | 838 |
| 833 std::vector<GURL> federations; | 839 std::vector<GURL> federations; |
| 834 EXPECT_CALL(*client_, | 840 EXPECT_CALL(*client_, |
| 835 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_))) | 841 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_))) |
| 836 .Times(1); | 842 .Times(1); |
| 837 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 838 | 843 |
| 839 ExpectZeroClickSignInFailure(); | 844 ExpectZeroClickSignInFailure(true, true, federations); |
| 840 } | 845 } |
| 841 | 846 |
| 842 TEST_F(CredentialManagerDispatcherTest, RequestCredentialWithFirstRunAndSkip) { | 847 TEST_F(CredentialManagerImplTest, RequestCredentialWithFirstRunAndSkip) { |
| 843 client_->set_first_run_seen(true); | 848 client_->set_first_run_seen(true); |
| 844 | 849 |
| 845 form_.skip_zero_click = true; | 850 form_.skip_zero_click = true; |
| 846 store_->AddLogin(form_); | 851 store_->AddLogin(form_); |
| 847 | 852 |
| 848 std::vector<GURL> federations; | 853 std::vector<GURL> federations; |
| 849 EXPECT_CALL(*client_, | 854 EXPECT_CALL(*client_, |
| 850 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_))) | 855 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_))) |
| 851 .Times(1); | 856 .Times(1); |
| 852 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 853 | 857 |
| 854 ExpectZeroClickSignInFailure(); | 858 ExpectZeroClickSignInFailure(true, true, federations); |
| 855 } | 859 } |
| 856 | 860 |
| 857 TEST_F(CredentialManagerDispatcherTest, RequestCredentialWithTLSErrors) { | 861 TEST_F(CredentialManagerImplTest, RequestCredentialWithTLSErrors) { |
| 858 // If we encounter TLS errors, we won't return credentials. | 862 // If we encounter TLS errors, we won't return credentials. |
| 859 EXPECT_CALL(*client_, DidLastPageLoadEncounterSSLErrors()) | 863 EXPECT_CALL(*client_, DidLastPageLoadEncounterSSLErrors()) |
| 860 .WillRepeatedly(testing::Return(true)); | 864 .WillRepeatedly(testing::Return(true)); |
| 861 | 865 |
| 862 store_->AddLogin(form_); | 866 store_->AddLogin(form_); |
| 863 | 867 |
| 864 std::vector<GURL> federations; | 868 std::vector<GURL> federations; |
| 865 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 866 | 869 |
| 867 ExpectZeroClickSignInFailure(); | 870 ExpectZeroClickSignInFailure(true, true, federations); |
| 868 } | 871 } |
| 869 | 872 |
| 870 TEST_F(CredentialManagerDispatcherTest, | 873 TEST_F(CredentialManagerImplTest, |
| 871 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { | 874 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { |
| 872 store_->AddLogin(form_); | 875 store_->AddLogin(form_); |
| 873 store_->AddLogin(origin_path_form_); | 876 store_->AddLogin(origin_path_form_); |
| 874 | 877 |
| 875 std::vector<GURL> federations; | 878 std::vector<GURL> federations; |
| 876 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 879 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 877 .Times(testing::Exactly(0)); | 880 .Times(testing::Exactly(0)); |
| 878 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 881 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 879 | 882 |
| 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. | 883 // With two items in the password store, we shouldn't get credentials back. |
| 892 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, | 884 ExpectCredentialType(true, true, federations, mojom::CredentialType::EMPTY); |
| 893 std::get<1>(send_param).type); | |
| 894 } | 885 } |
| 895 | 886 |
| 896 TEST_F(CredentialManagerDispatcherTest, | 887 TEST_F(CredentialManagerImplTest, |
| 897 OnRequestCredentialWithZeroClickOnlyAndSkipZeroClickPasswordStore) { | 888 OnRequestCredentialWithZeroClickOnlyAndSkipZeroClickPasswordStore) { |
| 898 form_.skip_zero_click = true; | 889 form_.skip_zero_click = true; |
| 899 store_->AddLogin(form_); | 890 store_->AddLogin(form_); |
| 900 store_->AddLogin(origin_path_form_); | 891 store_->AddLogin(origin_path_form_); |
| 901 | 892 |
| 902 std::vector<GURL> federations; | 893 std::vector<GURL> federations; |
| 903 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 894 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 904 .Times(testing::Exactly(0)); | 895 .Times(testing::Exactly(0)); |
| 905 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 896 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 906 | 897 |
| 907 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 908 | |
| 909 RunAllPendingTasks(); | |
| 910 | |
| 911 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | |
| 912 const IPC::Message* message = | |
| 913 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 914 EXPECT_TRUE(message); | |
| 915 CredentialManagerMsg_SendCredential::Param send_param; | |
| 916 CredentialManagerMsg_SendCredential::Read(message, &send_param); | |
| 917 | |
| 918 // With two items in the password store, we shouldn't get credentials back, | 898 // With two items in the password store, we shouldn't get credentials back, |
| 919 // even though only one item has |skip_zero_click| set |false|. | 899 // even though only one item has |skip_zero_click| set |false|. |
| 920 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, | 900 ExpectCredentialType(true, true, federations, mojom::CredentialType::EMPTY); |
| 921 std::get<1>(send_param).type); | |
| 922 } | 901 } |
| 923 | 902 |
| 924 TEST_F(CredentialManagerDispatcherTest, | 903 TEST_F(CredentialManagerImplTest, |
| 925 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) { | 904 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) { |
| 926 store_->AddLogin(cross_origin_form_); | 905 store_->AddLogin(cross_origin_form_); |
| 927 | 906 |
| 928 form_.skip_zero_click = true; | 907 form_.skip_zero_click = true; |
| 929 store_->AddLogin(form_); | 908 store_->AddLogin(form_); |
| 930 | 909 |
| 931 std::vector<GURL> federations; | 910 std::vector<GURL> federations; |
| 932 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 911 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 933 .Times(testing::Exactly(0)); | 912 .Times(testing::Exactly(0)); |
| 934 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 913 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 935 | 914 |
| 936 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | |
| 937 | |
| 938 RunAllPendingTasks(); | |
| 939 | |
| 940 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | |
| 941 const IPC::Message* message = | |
| 942 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 943 EXPECT_TRUE(message); | |
| 944 CredentialManagerMsg_SendCredential::Param send_param; | |
| 945 CredentialManagerMsg_SendCredential::Read(message, &send_param); | |
| 946 | |
| 947 // We only have cross-origin zero-click credentials; they should not be | 915 // We only have cross-origin zero-click credentials; they should not be |
| 948 // returned. | 916 // returned. |
| 949 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, | 917 ExpectCredentialType(true, true, federations, mojom::CredentialType::EMPTY); |
| 950 std::get<1>(send_param).type); | |
| 951 } | 918 } |
| 952 | 919 |
| 953 TEST_F(CredentialManagerDispatcherTest, | 920 TEST_F(CredentialManagerImplTest, |
| 954 CredentialManagerOnRequestCredentialWhileRequestPending) { | 921 CredentialManagerOnRequestCredentialWhileRequestPending) { |
| 955 client_->set_zero_click_enabled(false); | 922 client_->set_zero_click_enabled(false); |
| 956 store_->AddLogin(form_); | 923 store_->AddLogin(form_); |
| 957 | 924 |
| 958 std::vector<GURL> federations; | 925 std::vector<GURL> federations; |
| 959 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 926 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 960 .Times(testing::Exactly(0)); | 927 .Times(testing::Exactly(0)); |
| 961 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 928 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 962 | 929 |
| 963 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); | 930 // 1st request. |
| 964 dispatcher()->OnRequestCredential(kRequestId + 1, false, true, federations); | 931 bool called_1 = false; |
| 932 mojom::CredentialManagerError error_1; |
| 933 mojom::CredentialInfoPtr credential_1; |
| 934 CallGet( |
| 935 false, true, federations, |
| 936 base::Bind(&GetCredentialCallback, &called_1, &error_1, &credential_1)); |
| 937 // 2nd request. |
| 938 bool called_2 = false; |
| 939 mojom::CredentialManagerError error_2; |
| 940 mojom::CredentialInfoPtr credential_2; |
| 941 CallGet( |
| 942 false, true, federations, |
| 943 base::Bind(&GetCredentialCallback, &called_2, &error_2, &credential_2)); |
| 965 | 944 |
| 966 // Check that the second request triggered a rejection. | |
| 967 uint32_t kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; | |
| 968 const IPC::Message* message = | |
| 969 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 970 EXPECT_TRUE(message); | |
| 971 | |
| 972 CredentialManagerMsg_RejectCredentialRequest::Param reject_param; | |
| 973 CredentialManagerMsg_RejectCredentialRequest::Read(message, &reject_param); | |
| 974 EXPECT_EQ(blink::WebCredentialManagerPendingRequestError, | |
| 975 std::get<1>(reject_param)); | |
| 976 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 945 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 977 .Times(testing::Exactly(1)); | 946 .Times(testing::Exactly(1)); |
| 978 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 947 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 979 | 948 |
| 980 process()->sink().ClearMessages(); | |
| 981 | |
| 982 // Execute the PasswordStore asynchronousness. | 949 // Execute the PasswordStore asynchronousness. |
| 983 RunAllPendingTasks(); | 950 RunAllPendingTasks(); |
| 984 | 951 |
| 952 // Check that the second request triggered a rejection. |
| 953 EXPECT_TRUE(called_2); |
| 954 EXPECT_EQ(mojom::CredentialManagerError::PENDINGREQUEST, error_2); |
| 955 EXPECT_TRUE(credential_2.is_null()); |
| 956 |
| 985 // Check that the first request resolves. | 957 // Check that the first request resolves. |
| 986 kMsgID = CredentialManagerMsg_SendCredential::ID; | 958 EXPECT_TRUE(called_1); |
| 987 message = process()->sink().GetFirstMessageMatching(kMsgID); | 959 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error_1); |
| 988 EXPECT_TRUE(message); | 960 EXPECT_NE(mojom::CredentialType::EMPTY, credential_1->type); |
| 989 CredentialManagerMsg_SendCredential::Param send_param; | |
| 990 CredentialManagerMsg_SendCredential::Read(message, &send_param); | |
| 991 EXPECT_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, | |
| 992 std::get<1>(send_param).type); | |
| 993 process()->sink().ClearMessages(); | |
| 994 } | 961 } |
| 995 | 962 |
| 996 TEST_F(CredentialManagerDispatcherTest, ResetSkipZeroClickAfterPrompt) { | 963 TEST_F(CredentialManagerImplTest, ResetSkipZeroClickAfterPrompt) { |
| 997 // Turn on the global zero-click flag, and add two credentials in separate | 964 // Turn on the global zero-click flag, and add two credentials in separate |
| 998 // origins, both set to skip zero-click. | 965 // origins, both set to skip zero-click. |
| 999 client_->set_zero_click_enabled(true); | 966 client_->set_zero_click_enabled(true); |
| 1000 form_.skip_zero_click = true; | 967 form_.skip_zero_click = true; |
| 1001 store_->AddLogin(form_); | 968 store_->AddLogin(form_); |
| 1002 cross_origin_form_.skip_zero_click = true; | 969 cross_origin_form_.skip_zero_click = true; |
| 1003 store_->AddLogin(cross_origin_form_); | 970 store_->AddLogin(cross_origin_form_); |
| 1004 | 971 |
| 1005 // Execute the PasswordStore asynchronousness to ensure everything is | 972 // Execute the PasswordStore asynchronousness to ensure everything is |
| 1006 // written before proceeding. | 973 // written before proceeding. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1019 std::vector<GURL> federations; | 986 std::vector<GURL> federations; |
| 1020 // Check that the form in the database has been updated. `OnRequestCredential` | 987 // Check that the form in the database has been updated. `OnRequestCredential` |
| 1021 // generates a call to prompt the user to choose a credential. | 988 // generates a call to prompt the user to choose a credential. |
| 1022 // MockPasswordManagerClient mocks a user choice, and when users choose a | 989 // MockPasswordManagerClient mocks a user choice, and when users choose a |
| 1023 // credential (and have the global zero-click flag enabled), we make sure that | 990 // credential (and have the global zero-click flag enabled), we make sure that |
| 1024 // they'll be logged in again next time. | 991 // they'll be logged in again next time. |
| 1025 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 992 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 1026 .Times(testing::Exactly(1)); | 993 .Times(testing::Exactly(1)); |
| 1027 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 994 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 1028 | 995 |
| 1029 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); | 996 bool called = false; |
| 997 mojom::CredentialManagerError error; |
| 998 mojom::CredentialInfoPtr credential; |
| 999 CallGet(false, true, federations, |
| 1000 base::Bind(&GetCredentialCallback, &called, &error, &credential)); |
| 1001 |
| 1030 RunAllPendingTasks(); | 1002 RunAllPendingTasks(); |
| 1031 | 1003 |
| 1032 passwords = store_->stored_passwords(); | 1004 passwords = store_->stored_passwords(); |
| 1033 EXPECT_EQ(2U, passwords.size()); | 1005 EXPECT_EQ(2U, passwords.size()); |
| 1034 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); | 1006 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); |
| 1035 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); | 1007 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); |
| 1036 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 1008 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 1037 EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); | 1009 EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); |
| 1038 } | 1010 } |
| 1039 | 1011 |
| 1040 TEST_F(CredentialManagerDispatcherTest, | 1012 TEST_F(CredentialManagerImplTest, NoResetSkipZeroClickAfterPromptInIncognito) { |
| 1041 NoResetSkipZeroClickAfterPromptInIncognito) { | |
| 1042 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); | 1013 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); |
| 1043 // Turn on the global zero-click flag which should be overriden by Incognito. | 1014 // Turn on the global zero-click flag which should be overriden by Incognito. |
| 1044 client_->set_zero_click_enabled(true); | 1015 client_->set_zero_click_enabled(true); |
| 1045 form_.skip_zero_click = true; | 1016 form_.skip_zero_click = true; |
| 1046 store_->AddLogin(form_); | 1017 store_->AddLogin(form_); |
| 1047 RunAllPendingTasks(); | 1018 RunAllPendingTasks(); |
| 1048 | 1019 |
| 1049 // Sanity check. | 1020 // Sanity check. |
| 1050 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 1021 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 1051 ASSERT_EQ(1U, passwords.size()); | 1022 ASSERT_EQ(1U, passwords.size()); |
| 1052 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); | 1023 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); |
| 1053 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); | 1024 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); |
| 1054 | 1025 |
| 1055 // Trigger a request which should return the credential found in |form_|, and | 1026 // Trigger a request which should return the credential found in |form_|, and |
| 1056 // wait for it to process. | 1027 // wait for it to process. |
| 1057 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 1028 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 1058 .Times(testing::Exactly(1)); | 1029 .Times(testing::Exactly(1)); |
| 1059 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 1030 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 1060 | 1031 |
| 1061 dispatcher()->OnRequestCredential(kRequestId, false, true, | 1032 bool called = false; |
| 1062 std::vector<GURL>()); | 1033 mojom::CredentialManagerError error; |
| 1034 mojom::CredentialInfoPtr credential; |
| 1035 CallGet(false, true, std::vector<GURL>(), |
| 1036 base::Bind(&GetCredentialCallback, &called, &error, &credential)); |
| 1037 |
| 1063 RunAllPendingTasks(); | 1038 RunAllPendingTasks(); |
| 1064 | 1039 |
| 1065 // The form shouldn't become a zero-click one. | 1040 // The form shouldn't become a zero-click one. |
| 1066 passwords = store_->stored_passwords(); | 1041 passwords = store_->stored_passwords(); |
| 1067 ASSERT_EQ(1U, passwords.size()); | 1042 ASSERT_EQ(1U, passwords.size()); |
| 1068 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); | 1043 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); |
| 1069 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); | 1044 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); |
| 1070 } | 1045 } |
| 1071 | 1046 |
| 1072 TEST_F(CredentialManagerDispatcherTest, IncognitoZeroClickRequestCredential) { | 1047 TEST_F(CredentialManagerImplTest, IncognitoZeroClickRequestCredential) { |
| 1073 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); | 1048 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); |
| 1074 store_->AddLogin(form_); | 1049 store_->AddLogin(form_); |
| 1075 | 1050 |
| 1076 std::vector<GURL> federations; | 1051 std::vector<GURL> federations; |
| 1077 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 1052 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 1078 .Times(testing::Exactly(0)); | 1053 .Times(testing::Exactly(0)); |
| 1079 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 1054 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 1080 | 1055 |
| 1081 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1056 ExpectCredentialType(true, true, federations, mojom::CredentialType::EMPTY); |
| 1082 | |
| 1083 RunAllPendingTasks(); | |
| 1084 | |
| 1085 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | |
| 1086 const IPC::Message* message = | |
| 1087 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 1088 ASSERT_TRUE(message); | |
| 1089 CredentialManagerMsg_SendCredential::Param param; | |
| 1090 CredentialManagerMsg_SendCredential::Read(message, ¶m); | |
| 1091 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, std::get<1>(param).type); | |
| 1092 } | 1057 } |
| 1093 | 1058 |
| 1094 TEST_F(CredentialManagerDispatcherTest, | 1059 TEST_F(CredentialManagerImplTest, ZeroClickWithAffiliatedFormInPasswordStore) { |
| 1095 ZeroClickWithAffiliatedFormInPasswordStore) { | |
| 1096 // Insert the affiliated form into the store, and mock out the association | 1060 // Insert the affiliated form into the store, and mock out the association |
| 1097 // with the current origin. As it's the only form matching the origin, it | 1061 // with the current origin. As it's the only form matching the origin, it |
| 1098 // ought to be returned automagically. | 1062 // ought to be returned automagically. |
| 1099 store_->AddLogin(affiliated_form1_); | 1063 store_->AddLogin(affiliated_form1_); |
| 1100 | 1064 |
| 1101 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 1065 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 1102 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 1066 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 1103 | 1067 |
| 1104 std::vector<GURL> federations; | 1068 std::vector<GURL> federations; |
| 1105 std::vector<std::string> affiliated_realms; | 1069 std::vector<std::string> affiliated_realms; |
| 1106 affiliated_realms.push_back(kTestAndroidRealm1); | 1070 affiliated_realms.push_back(kTestAndroidRealm1); |
| 1107 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 1071 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 1108 ->ExpectCallToGetAffiliatedAndroidRealms( | 1072 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 1109 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 1073 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 1110 | 1074 |
| 1111 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1075 ExpectZeroClickSignInSuccess(true, true, federations, |
| 1112 | 1076 mojom::CredentialType::PASSWORD); |
| 1113 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); | |
| 1114 } | 1077 } |
| 1115 | 1078 |
| 1116 TEST_F(CredentialManagerDispatcherTest, | 1079 TEST_F(CredentialManagerImplTest, |
| 1117 ZeroClickWithTwoAffiliatedFormsInPasswordStore) { | 1080 ZeroClickWithTwoAffiliatedFormsInPasswordStore) { |
| 1118 // Insert two affiliated forms into the store, and mock out the association | 1081 // Insert two affiliated forms into the store, and mock out the association |
| 1119 // with the current origin. Multiple forms === no zero-click sign in. | 1082 // with the current origin. Multiple forms === no zero-click sign in. |
| 1120 store_->AddLogin(affiliated_form1_); | 1083 store_->AddLogin(affiliated_form1_); |
| 1121 store_->AddLogin(affiliated_form2_); | 1084 store_->AddLogin(affiliated_form2_); |
| 1122 | 1085 |
| 1123 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 1086 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 1124 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 1087 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 1125 | 1088 |
| 1126 std::vector<GURL> federations; | 1089 std::vector<GURL> federations; |
| 1127 std::vector<std::string> affiliated_realms; | 1090 std::vector<std::string> affiliated_realms; |
| 1128 affiliated_realms.push_back(kTestAndroidRealm1); | 1091 affiliated_realms.push_back(kTestAndroidRealm1); |
| 1129 affiliated_realms.push_back(kTestAndroidRealm2); | 1092 affiliated_realms.push_back(kTestAndroidRealm2); |
| 1130 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 1093 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 1131 ->ExpectCallToGetAffiliatedAndroidRealms( | 1094 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 1132 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 1095 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 1133 | 1096 |
| 1134 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1097 ExpectZeroClickSignInFailure(true, true, federations); |
| 1135 | |
| 1136 ExpectZeroClickSignInFailure(); | |
| 1137 } | 1098 } |
| 1138 | 1099 |
| 1139 TEST_F(CredentialManagerDispatcherTest, | 1100 TEST_F(CredentialManagerImplTest, |
| 1140 ZeroClickWithUnaffiliatedFormsInPasswordStore) { | 1101 ZeroClickWithUnaffiliatedFormsInPasswordStore) { |
| 1141 // Insert the affiliated form into the store, but don't mock out the | 1102 // Insert the affiliated form into the store, but don't mock out the |
| 1142 // association with the current origin. No association === no zero-click sign | 1103 // association with the current origin. No association === no zero-click sign |
| 1143 // in. | 1104 // in. |
| 1144 store_->AddLogin(affiliated_form1_); | 1105 store_->AddLogin(affiliated_form1_); |
| 1145 | 1106 |
| 1146 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 1107 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 1147 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 1108 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 1148 | 1109 |
| 1149 std::vector<GURL> federations; | 1110 std::vector<GURL> federations; |
| 1150 std::vector<std::string> affiliated_realms; | 1111 std::vector<std::string> affiliated_realms; |
| 1151 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 1112 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 1152 ->ExpectCallToGetAffiliatedAndroidRealms( | 1113 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 1153 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 1114 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 1154 | 1115 |
| 1155 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1116 ExpectZeroClickSignInFailure(true, true, federations); |
| 1156 | |
| 1157 ExpectZeroClickSignInFailure(); | |
| 1158 } | 1117 } |
| 1159 | 1118 |
| 1160 TEST_F(CredentialManagerDispatcherTest, | 1119 TEST_F(CredentialManagerImplTest, |
| 1161 ZeroClickWithFormAndUnaffiliatedFormsInPasswordStore) { | 1120 ZeroClickWithFormAndUnaffiliatedFormsInPasswordStore) { |
| 1162 // Insert the affiliated form into the store, along with a real form for the | 1121 // Insert the affiliated form into the store, along with a real form for the |
| 1163 // origin, and don't mock out the association with the current origin. No | 1122 // origin, and don't mock out the association with the current origin. No |
| 1164 // association + existing form === zero-click sign in. | 1123 // association + existing form === zero-click sign in. |
| 1165 store_->AddLogin(form_); | 1124 store_->AddLogin(form_); |
| 1166 store_->AddLogin(affiliated_form1_); | 1125 store_->AddLogin(affiliated_form1_); |
| 1167 | 1126 |
| 1168 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); | 1127 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 1169 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 1128 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 1170 | 1129 |
| 1171 std::vector<GURL> federations; | 1130 std::vector<GURL> federations; |
| 1172 std::vector<std::string> affiliated_realms; | 1131 std::vector<std::string> affiliated_realms; |
| 1173 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 1132 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 1174 ->ExpectCallToGetAffiliatedAndroidRealms( | 1133 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 1175 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 1134 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 1176 | 1135 |
| 1177 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1136 ExpectZeroClickSignInSuccess(true, true, federations, |
| 1178 | 1137 mojom::CredentialType::PASSWORD); |
| 1179 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); | |
| 1180 } | 1138 } |
| 1181 | 1139 |
| 1182 TEST_F(CredentialManagerDispatcherTest, GetSynthesizedFormForOrigin) { | 1140 TEST_F(CredentialManagerImplTest, GetSynthesizedFormForOrigin) { |
| 1183 autofill::PasswordForm synthesized = | 1141 autofill::PasswordForm synthesized = |
| 1184 dispatcher_->GetSynthesizedFormForOrigin(); | 1142 cm_service_impl_->GetSynthesizedFormForOrigin(); |
| 1185 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); | 1143 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); |
| 1186 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); | 1144 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); |
| 1187 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); | 1145 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); |
| 1188 EXPECT_TRUE(synthesized.ssl_valid); | 1146 EXPECT_TRUE(synthesized.ssl_valid); |
| 1189 } | 1147 } |
| 1190 | 1148 |
| 1191 } // namespace password_manager | 1149 } // namespace password_manager |
| OLD | NEW |