Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: components/password_manager/content/browser/credential_manager_dispatcher_unittest.cc

Issue 1031153002: [Credential Management] Smart lock save Credentials bubble should not always pop up. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_dispatc her.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/prefs/pref_registry_simple.h" 9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/testing_pref_service.h" 10 #include "base/prefs/testing_pref_service.h"
(...skipping 19 matching lines...) Expand all
30 using testing::_; 30 using testing::_;
31 31
32 namespace { 32 namespace {
33 33
34 // Chosen by fair dice roll. Guaranteed to be random. 34 // Chosen by fair dice roll. Guaranteed to be random.
35 const int kRequestId = 4; 35 const int kRequestId = 4;
36 36
37 class MockPasswordManagerClient 37 class MockPasswordManagerClient
38 : public password_manager::StubPasswordManagerClient { 38 : public password_manager::StubPasswordManagerClient {
39 public: 39 public:
40 MOCK_CONST_METHOD0(IsSavingEnabledForCurrentPage, bool());
40 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); 41 MOCK_CONST_METHOD0(IsOffTheRecord, bool());
41 MOCK_METHOD1(NotifyUserAutoSigninPtr, 42 MOCK_METHOD1(NotifyUserAutoSigninPtr,
42 bool(const std::vector<autofill::PasswordForm*>& local_forms)); 43 bool(const std::vector<autofill::PasswordForm*>& local_forms));
43 MOCK_METHOD2(PromptUserToSavePasswordPtr, 44 MOCK_METHOD2(PromptUserToSavePasswordPtr,
44 void(password_manager::PasswordFormManager*, 45 void(password_manager::PasswordFormManager*,
45 password_manager::CredentialSourceType type)); 46 password_manager::CredentialSourceType type));
46 MOCK_METHOD4(PromptUserToChooseCredentialsPtr, 47 MOCK_METHOD4(PromptUserToChooseCredentialsPtr,
47 bool(const std::vector<autofill::PasswordForm*>& local_forms, 48 bool(const std::vector<autofill::PasswordForm*>& local_forms,
48 const std::vector<autofill::PasswordForm*>& federated_forms, 49 const std::vector<autofill::PasswordForm*>& federated_forms,
49 const GURL& origin, 50 const GURL& origin,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 : public content::RenderViewHostTestHarness { 155 : public content::RenderViewHostTestHarness {
155 public: 156 public:
156 CredentialManagerDispatcherTest() {} 157 CredentialManagerDispatcherTest() {}
157 158
158 void SetUp() override { 159 void SetUp() override {
159 content::RenderViewHostTestHarness::SetUp(); 160 content::RenderViewHostTestHarness::SetUp();
160 store_ = new TestPasswordStore; 161 store_ = new TestPasswordStore;
161 client_.reset(new MockPasswordManagerClient(store_.get())); 162 client_.reset(new MockPasswordManagerClient(store_.get()));
162 dispatcher_.reset(new TestCredentialManagerDispatcher( 163 dispatcher_.reset(new TestCredentialManagerDispatcher(
163 web_contents(), client_.get(), &stub_driver_)); 164 web_contents(), client_.get(), &stub_driver_));
165 ON_CALL(*client_, IsSavingEnabledForCurrentPage())
166 .WillByDefault(testing::Return(true));
164 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false)); 167 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false));
165 168
166 NavigateAndCommit(GURL("https://example.com/test.html")); 169 NavigateAndCommit(GURL("https://example.com/test.html"));
167 170
168 form_.username_value = base::ASCIIToUTF16("Username"); 171 form_.username_value = base::ASCIIToUTF16("Username");
169 form_.display_name = base::ASCIIToUTF16("Display Name"); 172 form_.display_name = base::ASCIIToUTF16("Display Name");
170 form_.password_value = base::ASCIIToUTF16("Password"); 173 form_.password_value = base::ASCIIToUTF16("Password");
171 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); 174 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin();
172 form_.signon_realm = form_.origin.spec(); 175 form_.signon_realm = form_.origin.spec();
173 form_.scheme = autofill::PasswordForm::SCHEME_HTML; 176 form_.scheme = autofill::PasswordForm::SCHEME_HTML;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 autofill::PasswordForm new_form = 251 autofill::PasswordForm new_form =
249 client_->pending_manager()->pending_credentials(); 252 client_->pending_manager()->pending_credentials();
250 EXPECT_EQ(form_.username_value, new_form.username_value); 253 EXPECT_EQ(form_.username_value, new_form.username_value);
251 EXPECT_EQ(form_.display_name, new_form.display_name); 254 EXPECT_EQ(form_.display_name, new_form.display_name);
252 EXPECT_EQ(form_.password_value, new_form.password_value); 255 EXPECT_EQ(form_.password_value, new_form.password_value);
253 EXPECT_EQ(form_.origin, new_form.origin); 256 EXPECT_EQ(form_.origin, new_form.origin);
254 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); 257 EXPECT_EQ(form_.signon_realm, new_form.signon_realm);
255 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); 258 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme);
256 } 259 }
257 260
258 TEST_F(CredentialManagerDispatcherTest, CredentialManagerIncognitoSignedIn) { 261 TEST_F(CredentialManagerDispatcherTest,
262 CredentialManagerSignInWithSavingDisabledForCurrentPage) {
259 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_LOCAL); 263 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_LOCAL);
260 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); 264 EXPECT_CALL(*client_, IsSavingEnabledForCurrentPage())
265 .WillRepeatedly(testing::Return(false));
261 EXPECT_CALL( 266 EXPECT_CALL(
262 *client_, 267 *client_,
263 PromptUserToSavePasswordPtr( 268 PromptUserToSavePasswordPtr(
264 _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)) 269 _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API))
265 .Times(testing::Exactly(0)); 270 .Times(testing::Exactly(0));
266 271
267 dispatcher()->OnNotifySignedIn(kRequestId, info); 272 dispatcher()->OnNotifySignedIn(kRequestId, info);
268 273
269 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID; 274 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID;
270 const IPC::Message* message = 275 const IPC::Message* message =
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; 612 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
608 const IPC::Message* message = 613 const IPC::Message* message =
609 process()->sink().GetFirstMessageMatching(kMsgID); 614 process()->sink().GetFirstMessageMatching(kMsgID);
610 ASSERT_TRUE(message); 615 ASSERT_TRUE(message);
611 CredentialManagerMsg_SendCredential::Param param; 616 CredentialManagerMsg_SendCredential::Param param;
612 CredentialManagerMsg_SendCredential::Read(message, &param); 617 CredentialManagerMsg_SendCredential::Read(message, &param);
613 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); 618 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type);
614 } 619 }
615 620
616 } // namespace password_manager 621 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698