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

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

Issue 890943002: Add a global setting for "Auto sign-in". (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | components/password_manager/content/browser/credential_manager_dispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
10 #include "base/prefs/testing_pref_service.h"
9 #include "base/run_loop.h" 11 #include "base/run_loop.h"
10 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
11 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
12 #include "components/password_manager/content/browser/credential_manager_passwor d_form_manager.h" 14 #include "components/password_manager/content/browser/credential_manager_passwor d_form_manager.h"
13 #include "components/password_manager/content/common/credential_manager_messages .h" 15 #include "components/password_manager/content/common/credential_manager_messages .h"
14 #include "components/password_manager/content/common/credential_manager_types.h" 16 #include "components/password_manager/content/common/credential_manager_types.h"
15 #include "components/password_manager/core/browser/stub_password_manager_client. h" 17 #include "components/password_manager/core/browser/stub_password_manager_client. h"
16 #include "components/password_manager/core/browser/stub_password_manager_driver. h" 18 #include "components/password_manager/core/browser/stub_password_manager_driver. h"
17 #include "components/password_manager/core/browser/test_password_store.h" 19 #include "components/password_manager/core/browser/test_password_store.h"
20 #include "components/password_manager/core/common/password_manager_pref_names.h"
18 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
19 #include "content/public/test/mock_render_process_host.h" 22 #include "content/public/test/mock_render_process_host.h"
20 #include "content/public/test/test_renderer_host.h" 23 #include "content/public/test/test_renderer_host.h"
21 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
23 26
24 using content::BrowserContext; 27 using content::BrowserContext;
25 using content::WebContents; 28 using content::WebContents;
26 29
27 namespace { 30 namespace {
28 31
29 // Chosen by fair dice roll. Guaranteed to be random. 32 // Chosen by fair dice roll. Guaranteed to be random.
30 const int kRequestId = 4; 33 const int kRequestId = 4;
31 34
32 class TestPasswordManagerClient 35 class TestPasswordManagerClient
33 : public password_manager::StubPasswordManagerClient { 36 : public password_manager::StubPasswordManagerClient {
34 public: 37 public:
35 TestPasswordManagerClient(password_manager::PasswordStore* store) 38 TestPasswordManagerClient(password_manager::PasswordStore* store)
36 : did_prompt_user_to_save_(false), 39 : did_prompt_user_to_save_(false),
37 did_prompt_user_to_choose_(false), 40 did_prompt_user_to_choose_(false),
38 is_off_the_record_(false), 41 is_off_the_record_(false),
39 is_zero_click_enabled_(true), 42 store_(store) {
40 store_(store) {} 43 prefs_.registry()->RegisterBooleanPref(
44 password_manager::prefs::kPasswordManagerAutoSignin, true);
45 }
41 ~TestPasswordManagerClient() override {} 46 ~TestPasswordManagerClient() override {}
42 47
43 password_manager::PasswordStore* GetPasswordStore() override { 48 password_manager::PasswordStore* GetPasswordStore() override {
44 return store_; 49 return store_;
45 } 50 }
46 51
52 PrefService* GetPrefs() override { return &prefs_; }
53
47 bool PromptUserToSavePassword( 54 bool PromptUserToSavePassword(
48 scoped_ptr<password_manager::PasswordFormManager> manager) override { 55 scoped_ptr<password_manager::PasswordFormManager> manager) override {
49 did_prompt_user_to_save_ = true; 56 did_prompt_user_to_save_ = true;
50 manager_.reset(manager.release()); 57 manager_.reset(manager.release());
51 return true; 58 return true;
52 } 59 }
53 60
54 bool PromptUserToChooseCredentials( 61 bool PromptUserToChooseCredentials(
55 const std::vector<autofill::PasswordForm*>& local_forms, 62 const std::vector<autofill::PasswordForm*>& local_forms,
56 const std::vector<autofill::PasswordForm*>& federated_forms, 63 const std::vector<autofill::PasswordForm*>& federated_forms,
(...skipping 12 matching lines...) Expand all
69 local_forms.empty() ? *federated_forms[0] : *local_entries[0], 76 local_forms.empty() ? *federated_forms[0] : *local_entries[0],
70 local_forms.empty() 77 local_forms.empty()
71 ? password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED 78 ? password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED
72 : password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); 79 : password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL);
73 base::MessageLoop::current()->PostTask(FROM_HERE, 80 base::MessageLoop::current()->PostTask(FROM_HERE,
74 base::Bind(callback, info)); 81 base::Bind(callback, info));
75 return true; 82 return true;
76 } 83 }
77 84
78 bool IsOffTheRecord() override { return is_off_the_record_; } 85 bool IsOffTheRecord() override { return is_off_the_record_; }
79 bool IsZeroClickEnabled() override { return is_zero_click_enabled_; }
80 86
81 bool did_prompt_user_to_save() const { return did_prompt_user_to_save_; } 87 bool did_prompt_user_to_save() const { return did_prompt_user_to_save_; }
82 bool did_prompt_user_to_choose() const { return did_prompt_user_to_choose_; } 88 bool did_prompt_user_to_choose() const { return did_prompt_user_to_choose_; }
83 89
84 password_manager::PasswordFormManager* pending_manager() const { 90 password_manager::PasswordFormManager* pending_manager() const {
85 return manager_.get(); 91 return manager_.get();
86 } 92 }
87 93
88 void set_off_the_record(bool off_the_record) { 94 void set_off_the_record(bool off_the_record) {
89 is_off_the_record_ = off_the_record; 95 is_off_the_record_ = off_the_record;
90 } 96 }
91 97
92 void set_zero_click_enabled(bool zero_click_enabled) { 98 void set_zero_click_enabled(bool zero_click_enabled) {
93 is_zero_click_enabled_ = zero_click_enabled; 99 prefs_.SetBoolean(password_manager::prefs::kPasswordManagerAutoSignin,
100 zero_click_enabled);
94 } 101 }
95 102
96 private: 103 private:
104 TestingPrefServiceSimple prefs_;
97 bool did_prompt_user_to_save_; 105 bool did_prompt_user_to_save_;
98 bool did_prompt_user_to_choose_; 106 bool did_prompt_user_to_choose_;
99 bool is_off_the_record_; 107 bool is_off_the_record_;
100 bool is_zero_click_enabled_;
101 password_manager::PasswordStore* store_; 108 password_manager::PasswordStore* store_;
102 scoped_ptr<password_manager::PasswordFormManager> manager_; 109 scoped_ptr<password_manager::PasswordFormManager> manager_;
103 }; 110 };
104 111
105 class TestCredentialManagerDispatcher 112 class TestCredentialManagerDispatcher
106 : public password_manager::CredentialManagerDispatcher { 113 : public password_manager::CredentialManagerDispatcher {
107 public: 114 public:
108 TestCredentialManagerDispatcher( 115 TestCredentialManagerDispatcher(
109 content::WebContents* web_contents, 116 content::WebContents* web_contents,
110 password_manager::PasswordManagerClient* client, 117 password_manager::PasswordManagerClient* client,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 content::RenderViewHostTestHarness::TearDown(); 191 content::RenderViewHostTestHarness::TearDown();
185 } 192 }
186 193
187 CredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } 194 CredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); }
188 195
189 protected: 196 protected:
190 autofill::PasswordForm form_; 197 autofill::PasswordForm form_;
191 autofill::PasswordForm form2_; 198 autofill::PasswordForm form2_;
192 autofill::PasswordForm cross_origin_form_; 199 autofill::PasswordForm cross_origin_form_;
193 scoped_refptr<TestPasswordStore> store_; 200 scoped_refptr<TestPasswordStore> store_;
194 scoped_ptr<CredentialManagerDispatcher> dispatcher_;
195 scoped_ptr<TestPasswordManagerClient> client_; 201 scoped_ptr<TestPasswordManagerClient> client_;
196 StubPasswordManagerDriver stub_driver_; 202 StubPasswordManagerDriver stub_driver_;
203 scoped_ptr<CredentialManagerDispatcher> dispatcher_;
197 }; 204 };
198 205
199 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifyFailedSignIn) { 206 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifyFailedSignIn) {
200 CredentialInfo info; 207 CredentialInfo info;
201 info.type = CredentialType::CREDENTIAL_TYPE_LOCAL; 208 info.type = CredentialType::CREDENTIAL_TYPE_LOCAL;
202 dispatcher()->OnNotifyFailedSignIn(kRequestId, info); 209 dispatcher()->OnNotifyFailedSignIn(kRequestId, info);
203 210
204 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; 211 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID;
205 const IPC::Message* message = 212 const IPC::Message* message =
206 process()->sink().GetFirstMessageMatching(kMsgID); 213 process()->sink().GetFirstMessageMatching(kMsgID);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 const IPC::Message* message = 433 const IPC::Message* message =
427 process()->sink().GetFirstMessageMatching(kMsgID); 434 process()->sink().GetFirstMessageMatching(kMsgID);
428 ASSERT_TRUE(message); 435 ASSERT_TRUE(message);
429 CredentialManagerMsg_SendCredential::Param param; 436 CredentialManagerMsg_SendCredential::Param param;
430 CredentialManagerMsg_SendCredential::Read(message, &param); 437 CredentialManagerMsg_SendCredential::Read(message, &param);
431 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); 438 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type);
432 EXPECT_FALSE(client_->did_prompt_user_to_choose()); 439 EXPECT_FALSE(client_->did_prompt_user_to_choose());
433 } 440 }
434 441
435 } // namespace password_manager 442 } // namespace password_manager
OLDNEW
« no previous file with comments | « no previous file | components/password_manager/content/browser/credential_manager_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698