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

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

Issue 879913004: Credential Management: Support zeroclick credential in 'request()'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rework 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
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/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 18 matching lines...) Expand all
29 // Chosen by fair dice roll. Guaranteed to be random. 29 // Chosen by fair dice roll. Guaranteed to be random.
30 const int kRequestId = 4; 30 const int kRequestId = 4;
31 31
32 class TestPasswordManagerClient 32 class TestPasswordManagerClient
33 : public password_manager::StubPasswordManagerClient { 33 : public password_manager::StubPasswordManagerClient {
34 public: 34 public:
35 TestPasswordManagerClient(password_manager::PasswordStore* store) 35 TestPasswordManagerClient(password_manager::PasswordStore* store)
36 : did_prompt_user_to_save_(false), 36 : did_prompt_user_to_save_(false),
37 did_prompt_user_to_choose_(false), 37 did_prompt_user_to_choose_(false),
38 is_off_the_record_(false), 38 is_off_the_record_(false),
39 is_zero_click_disabled_(false),
39 store_(store) {} 40 store_(store) {}
40 ~TestPasswordManagerClient() override {} 41 ~TestPasswordManagerClient() override {}
41 42
42 password_manager::PasswordStore* GetPasswordStore() override { 43 password_manager::PasswordStore* GetPasswordStore() override {
43 return store_; 44 return store_;
44 } 45 }
45 46
46 bool PromptUserToSavePassword( 47 bool PromptUserToSavePassword(
47 scoped_ptr<password_manager::PasswordFormManager> manager) override { 48 scoped_ptr<password_manager::PasswordFormManager> manager) override {
48 did_prompt_user_to_save_ = true; 49 did_prompt_user_to_save_ = true;
(...skipping 19 matching lines...) Expand all
68 local_forms.empty() ? *federated_forms[0] : *local_entries[0], 69 local_forms.empty() ? *federated_forms[0] : *local_entries[0],
69 local_forms.empty() 70 local_forms.empty()
70 ? password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED 71 ? password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED
71 : password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); 72 : password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL);
72 base::MessageLoop::current()->PostTask(FROM_HERE, 73 base::MessageLoop::current()->PostTask(FROM_HERE,
73 base::Bind(callback, info)); 74 base::Bind(callback, info));
74 return true; 75 return true;
75 } 76 }
76 77
77 bool IsOffTheRecord() override { return is_off_the_record_; } 78 bool IsOffTheRecord() override { return is_off_the_record_; }
79 bool IsZeroClickDisabled() override { return is_zero_click_disabled_; }
78 80
79 bool did_prompt_user_to_save() const { return did_prompt_user_to_save_; } 81 bool did_prompt_user_to_save() const { return did_prompt_user_to_save_; }
80 bool did_prompt_user_to_choose() const { return did_prompt_user_to_choose_; } 82 bool did_prompt_user_to_choose() const { return did_prompt_user_to_choose_; }
81 83
82 password_manager::PasswordFormManager* pending_manager() const { 84 password_manager::PasswordFormManager* pending_manager() const {
83 return manager_.get(); 85 return manager_.get();
84 } 86 }
85 87
86 void set_off_the_record(bool off_the_record) { 88 void set_off_the_record(bool off_the_record) {
87 is_off_the_record_ = off_the_record; 89 is_off_the_record_ = off_the_record;
88 } 90 }
89 91
92 void set_zero_click_disabled(bool zero_click_disabled) {
93 is_zero_click_disabled_ = zero_click_disabled;
94 }
95
90 private: 96 private:
91 bool did_prompt_user_to_save_; 97 bool did_prompt_user_to_save_;
92 bool did_prompt_user_to_choose_; 98 bool did_prompt_user_to_choose_;
93 bool is_off_the_record_; 99 bool is_off_the_record_;
100 bool is_zero_click_disabled_;
94 password_manager::PasswordStore* store_; 101 password_manager::PasswordStore* store_;
95 scoped_ptr<password_manager::PasswordFormManager> manager_; 102 scoped_ptr<password_manager::PasswordFormManager> manager_;
96 }; 103 };
97 104
98 class TestCredentialManagerDispatcher 105 class TestCredentialManagerDispatcher
99 : public password_manager::CredentialManagerDispatcher { 106 : public password_manager::CredentialManagerDispatcher {
100 public: 107 public:
101 TestCredentialManagerDispatcher( 108 TestCredentialManagerDispatcher(
102 content::WebContents* web_contents, 109 content::WebContents* web_contents,
103 password_manager::PasswordManagerClient* client, 110 password_manager::PasswordManagerClient* client,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 EXPECT_TRUE(message); 288 EXPECT_TRUE(message);
282 CredentialManagerMsg_SendCredential::Param param; 289 CredentialManagerMsg_SendCredential::Param param;
283 CredentialManagerMsg_SendCredential::Read(message, &param); 290 CredentialManagerMsg_SendCredential::Read(message, &param);
284 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); 291 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type);
285 process()->sink().ClearMessages(); 292 process()->sink().ClearMessages();
286 EXPECT_FALSE(client_->did_prompt_user_to_choose()); 293 EXPECT_FALSE(client_->did_prompt_user_to_choose());
287 } 294 }
288 295
289 TEST_F(CredentialManagerDispatcherTest, 296 TEST_F(CredentialManagerDispatcherTest,
290 CredentialManagerOnRequestCredentialWithFullPasswordStore) { 297 CredentialManagerOnRequestCredentialWithFullPasswordStore) {
298 client_->set_zero_click_disabled(true);
Mike West 2015/01/28 14:42:14 Since we don't check the 'is_zero_click' attribute
291 store_->AddLogin(form_); 299 store_->AddLogin(form_);
292 300
293 std::vector<GURL> federations; 301 std::vector<GURL> federations;
294 dispatcher()->OnRequestCredential(kRequestId, false, federations); 302 dispatcher()->OnRequestCredential(kRequestId, false, federations);
295 303
296 RunAllPendingTasks(); 304 RunAllPendingTasks();
297 305
298 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; 306 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
299 const IPC::Message* message = 307 const IPC::Message* message =
300 process()->sink().GetFirstMessageMatching(kMsgID); 308 process()->sink().GetFirstMessageMatching(kMsgID);
301 EXPECT_TRUE(message); 309 EXPECT_TRUE(message);
302 EXPECT_TRUE(client_->did_prompt_user_to_choose()); 310 EXPECT_TRUE(client_->did_prompt_user_to_choose());
303 } 311 }
304 312
313 TEST_F(
314 CredentialManagerDispatcherTest,
315 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) {
316 std::vector<GURL> federations;
317 dispatcher()->OnRequestCredential(kRequestId, true, federations);
318
319 RunAllPendingTasks();
320
321 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
322 const IPC::Message* message =
323 process()->sink().GetFirstMessageMatching(kMsgID);
324 EXPECT_TRUE(message);
325 EXPECT_FALSE(client_->did_prompt_user_to_choose());
326 CredentialManagerMsg_SendCredential::Param send_param;
327 CredentialManagerMsg_SendCredential::Read(message, &send_param);
328 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type);
329 }
330
331 TEST_F(CredentialManagerDispatcherTest,
332 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) {
333 store_->AddLogin(form_);
334
335 std::vector<GURL> federations;
336 dispatcher()->OnRequestCredential(kRequestId, true, federations);
337
338 RunAllPendingTasks();
339
340 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
341 const IPC::Message* message =
342 process()->sink().GetFirstMessageMatching(kMsgID);
343 EXPECT_TRUE(message);
344 EXPECT_FALSE(client_->did_prompt_user_to_choose());
345 CredentialManagerMsg_SendCredential::Param send_param;
346 CredentialManagerMsg_SendCredential::Read(message, &send_param);
347 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL, get<1>(send_param).type);
348 }
349
350 TEST_F(CredentialManagerDispatcherTest,
351 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) {
352 store_->AddLogin(form_);
353 store_->AddLogin(form_);
354
355 std::vector<GURL> federations;
356 dispatcher()->OnRequestCredential(kRequestId, true, federations);
357
358 RunAllPendingTasks();
359
360 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
361 const IPC::Message* message =
362 process()->sink().GetFirstMessageMatching(kMsgID);
363 EXPECT_TRUE(message);
364 EXPECT_FALSE(client_->did_prompt_user_to_choose());
365 CredentialManagerMsg_SendCredential::Param send_param;
366 CredentialManagerMsg_SendCredential::Read(message, &send_param);
367
368 // With two items in the password store, we shouldn't get credentials back.
369 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type);
370 }
371
305 TEST_F(CredentialManagerDispatcherTest, 372 TEST_F(CredentialManagerDispatcherTest,
306 CredentialManagerOnRequestCredentialWhileRequestPending) { 373 CredentialManagerOnRequestCredentialWhileRequestPending) {
374 client_->set_zero_click_disabled(true);
Mike West 2015/01/28 14:42:14 Ditto.
307 store_->AddLogin(form_); 375 store_->AddLogin(form_);
308 376
309 std::vector<GURL> federations; 377 std::vector<GURL> federations;
310 dispatcher()->OnRequestCredential(kRequestId, false, federations); 378 dispatcher()->OnRequestCredential(kRequestId, false, federations);
311 dispatcher()->OnRequestCredential(kRequestId, false, federations); 379 dispatcher()->OnRequestCredential(kRequestId, false, federations);
312 380
313 // Check that the second request triggered a rejection. 381 // Check that the second request triggered a rejection.
314 uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; 382 uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID;
315 const IPC::Message* message = 383 const IPC::Message* message =
316 process()->sink().GetFirstMessageMatching(kMsgID); 384 process()->sink().GetFirstMessageMatching(kMsgID);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 const IPC::Message* message = 418 const IPC::Message* message =
351 process()->sink().GetFirstMessageMatching(kMsgID); 419 process()->sink().GetFirstMessageMatching(kMsgID);
352 ASSERT_TRUE(message); 420 ASSERT_TRUE(message);
353 CredentialManagerMsg_SendCredential::Param param; 421 CredentialManagerMsg_SendCredential::Param param;
354 CredentialManagerMsg_SendCredential::Read(message, &param); 422 CredentialManagerMsg_SendCredential::Read(message, &param);
355 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); 423 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type);
356 EXPECT_FALSE(client_->did_prompt_user_to_choose()); 424 EXPECT_FALSE(client_->did_prompt_user_to_choose());
357 } 425 }
358 426
359 } // namespace password_manager 427 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698