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