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

Side by Side Diff: chrome/browser/ui/passwords/manage_passwords_ui_controller_unittest.cc

Issue 1096983002: Update usages of std::map to use ScopedPtrMap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@passwordmanager-scopedmemory
Patch Set: Rebase. Created 5 years, 6 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 | « chrome/browser/ui/passwords/manage_passwords_test.cc ('k') | chromeos/dbus/gsm_sms_client.cc » ('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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/prefs/pref_service.h" 6 #include "base/prefs/pref_service.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "chrome/browser/ui/passwords/manage_passwords_bubble.h" 9 #include "chrome/browser/ui/passwords/manage_passwords_bubble.h"
10 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" 10 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->state()); 148 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->state());
149 EXPECT_FALSE(controller()->PasswordPendingUserDecision()); 149 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
150 EXPECT_EQ(GURL::EmptyGURL(), controller()->origin()); 150 EXPECT_EQ(GURL::EmptyGURL(), controller()->origin());
151 151
152 ManagePasswordsIconMock mock; 152 ManagePasswordsIconMock mock;
153 controller()->UpdateIconAndBubbleState(&mock); 153 controller()->UpdateIconAndBubbleState(&mock);
154 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, mock.state()); 154 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, mock.state());
155 } 155 }
156 156
157 TEST_F(ManagePasswordsUIControllerTest, PasswordAutofilled) { 157 TEST_F(ManagePasswordsUIControllerTest, PasswordAutofilled) {
158 base::string16 kTestUsername = test_local_form().username_value; 158 scoped_ptr<autofill::PasswordForm> test_form(
159 new autofill::PasswordForm(test_local_form()));
160 autofill::PasswordForm* test_form_ptr = test_form.get();
161 base::string16 kTestUsername = test_form->username_value;
159 autofill::PasswordFormMap map; 162 autofill::PasswordFormMap map;
160 map[kTestUsername] = &test_local_form(); 163 map.insert(kTestUsername, test_form.Pass());
161 controller()->OnPasswordAutofilled(map); 164 controller()->OnPasswordAutofilled(map);
162 165
163 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->state()); 166 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->state());
164 EXPECT_FALSE(controller()->PasswordPendingUserDecision()); 167 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
165 EXPECT_EQ(test_local_form().origin, controller()->origin()); 168 EXPECT_EQ(test_form_ptr->origin, controller()->origin());
166 ASSERT_EQ(1u, controller()->GetCurrentForms().size()); 169 ASSERT_EQ(1u, controller()->GetCurrentForms().size());
167 EXPECT_EQ(kTestUsername, controller()->GetCurrentForms()[0]->username_value); 170 EXPECT_EQ(kTestUsername, controller()->GetCurrentForms()[0]->username_value);
168 171
169 // Controller should store a separate copy of the form as it doesn't own it. 172 // Controller should store a separate copy of the form as it doesn't own it.
170 EXPECT_NE(&test_local_form(), controller()->GetCurrentForms()[0]); 173 EXPECT_NE(test_form_ptr, controller()->GetCurrentForms()[0]);
171 174
172 ManagePasswordsIconMock mock; 175 ManagePasswordsIconMock mock;
173 controller()->UpdateIconAndBubbleState(&mock); 176 controller()->UpdateIconAndBubbleState(&mock);
174 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state()); 177 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state());
175 } 178 }
176 179
177 TEST_F(ManagePasswordsUIControllerTest, PasswordSubmitted) { 180 TEST_F(ManagePasswordsUIControllerTest, PasswordSubmitted) {
178 scoped_ptr<password_manager::PasswordFormManager> test_form_manager( 181 scoped_ptr<password_manager::PasswordFormManager> test_form_manager(
179 CreateFormManager()); 182 CreateFormManager());
180 controller()->OnPasswordSubmitted(test_form_manager.Pass()); 183 controller()->OnPasswordSubmitted(test_form_manager.Pass());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // it's being masked by the stub implementation of 284 // it's being masked by the stub implementation of
282 // ManagePasswordsUIControllerMock::PendingCredentials. 285 // ManagePasswordsUIControllerMock::PendingCredentials.
283 EXPECT_EQ(GURL::EmptyGURL(), controller()->origin()); 286 EXPECT_EQ(GURL::EmptyGURL(), controller()->origin());
284 287
285 ManagePasswordsIconMock mock; 288 ManagePasswordsIconMock mock;
286 controller()->UpdateIconAndBubbleState(&mock); 289 controller()->UpdateIconAndBubbleState(&mock);
287 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, mock.state()); 290 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, mock.state());
288 } 291 }
289 292
290 TEST_F(ManagePasswordsUIControllerTest, BlacklistBlockedAutofill) { 293 TEST_F(ManagePasswordsUIControllerTest, BlacklistBlockedAutofill) {
291 test_local_form().blacklisted_by_user = true; 294 scoped_ptr<autofill::PasswordForm> test_form(
292 base::string16 kTestUsername = test_local_form().username_value; 295 new autofill::PasswordForm(test_local_form()));
296 autofill::PasswordForm* test_form_ptr = test_form.get();
297 test_form->blacklisted_by_user = true;
298 base::string16 kTestUsername = test_form->username_value;
293 autofill::PasswordFormMap map; 299 autofill::PasswordFormMap map;
294 map[kTestUsername] = &test_local_form(); 300 map.insert(kTestUsername, test_form.Pass());
295 controller()->OnBlacklistBlockedAutofill(map); 301 controller()->OnBlacklistBlockedAutofill(map);
296 302
297 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, controller()->state()); 303 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, controller()->state());
298 EXPECT_FALSE(controller()->PasswordPendingUserDecision()); 304 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
299 EXPECT_EQ(test_local_form().origin, controller()->origin()); 305 EXPECT_EQ(test_form_ptr->origin, controller()->origin());
300 ASSERT_EQ(1u, controller()->GetCurrentForms().size()); 306 ASSERT_EQ(1u, controller()->GetCurrentForms().size());
301 EXPECT_EQ(kTestUsername, controller()->GetCurrentForms()[0]->username_value); 307 EXPECT_EQ(kTestUsername, controller()->GetCurrentForms()[0]->username_value);
302 308
303 // Controller should store a separate copy of the form as it doesn't own it. 309 // Controller should store a separate copy of the form as it doesn't own it.
304 EXPECT_NE(&test_local_form(), controller()->GetCurrentForms()[0]); 310 EXPECT_NE(test_form_ptr, controller()->GetCurrentForms()[0]);
305 311
306 ManagePasswordsIconMock mock; 312 ManagePasswordsIconMock mock;
307 controller()->UpdateIconAndBubbleState(&mock); 313 controller()->UpdateIconAndBubbleState(&mock);
308 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, mock.state()); 314 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, mock.state());
309 } 315 }
310 316
311 TEST_F(ManagePasswordsUIControllerTest, ClickedUnblacklist) { 317 TEST_F(ManagePasswordsUIControllerTest, ClickedUnblacklist) {
312 base::string16 kTestUsername = base::ASCIIToUTF16("test_username"); 318 base::string16 kTestUsername = base::ASCIIToUTF16("test_username");
313 autofill::PasswordFormMap map; 319 autofill::PasswordFormMap map;
314 map[kTestUsername] = &test_local_form(); 320 scoped_ptr<autofill::PasswordForm> test_form(
315 test_local_form().blacklisted_by_user = true; 321 new autofill::PasswordForm(test_local_form()));
322 autofill::PasswordForm& test_form_ref = *test_form;
323 map.insert(kTestUsername, test_form.Pass());
324 test_form_ref.blacklisted_by_user = true;
316 controller()->OnBlacklistBlockedAutofill(map); 325 controller()->OnBlacklistBlockedAutofill(map);
317 controller()->UnblacklistSite(); 326 controller()->UnblacklistSite();
318 327
319 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->state()); 328 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->state());
320 EXPECT_FALSE(controller()->PasswordPendingUserDecision()); 329 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
321 EXPECT_EQ(test_local_form().origin, controller()->origin()); 330 EXPECT_EQ(test_local_form().origin, controller()->origin());
322 331
323 ManagePasswordsIconMock mock; 332 ManagePasswordsIconMock mock;
324 controller()->UpdateIconAndBubbleState(&mock); 333 controller()->UpdateIconAndBubbleState(&mock);
325 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state()); 334 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state());
326 } 335 }
327 336
328 TEST_F(ManagePasswordsUIControllerTest, UnblacklistedElsewhere) { 337 TEST_F(ManagePasswordsUIControllerTest, UnblacklistedElsewhere) {
329 test_local_form().blacklisted_by_user = true; 338 test_local_form().blacklisted_by_user = true;
330 base::string16 kTestUsername = base::ASCIIToUTF16("test_username"); 339 base::string16 kTestUsername = base::ASCIIToUTF16("test_username");
331 autofill::PasswordFormMap map; 340 autofill::PasswordFormMap map;
332 map[kTestUsername] = &test_local_form(); 341 map.insert(kTestUsername,
342 make_scoped_ptr(new autofill::PasswordForm(test_local_form())));
333 controller()->OnBlacklistBlockedAutofill(map); 343 controller()->OnBlacklistBlockedAutofill(map);
334 344
335 password_manager::PasswordStoreChange change( 345 password_manager::PasswordStoreChange change(
336 password_manager::PasswordStoreChange::REMOVE, test_local_form()); 346 password_manager::PasswordStoreChange::REMOVE, test_local_form());
337 password_manager::PasswordStoreChangeList list(1, change); 347 password_manager::PasswordStoreChangeList list(1, change);
338 controller()->OnLoginsChanged(list); 348 controller()->OnLoginsChanged(list);
339 349
340 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->state()); 350 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->state());
341 EXPECT_FALSE(controller()->PasswordPendingUserDecision()); 351 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
342 EXPECT_EQ(test_local_form().origin, controller()->origin()); 352 EXPECT_EQ(test_local_form().origin, controller()->origin());
343 353
344 ManagePasswordsIconMock mock; 354 ManagePasswordsIconMock mock;
345 controller()->UpdateIconAndBubbleState(&mock); 355 controller()->UpdateIconAndBubbleState(&mock);
346 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state()); 356 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state());
347 } 357 }
348 358
349 TEST_F(ManagePasswordsUIControllerTest, BlacklistedElsewhere) { 359 TEST_F(ManagePasswordsUIControllerTest, BlacklistedElsewhere) {
350 base::string16 kTestUsername = base::ASCIIToUTF16("test_username"); 360 base::string16 kTestUsername = base::ASCIIToUTF16("test_username");
351 autofill::PasswordFormMap map; 361 autofill::PasswordFormMap map;
352 map[kTestUsername] = &test_local_form(); 362 map.insert(kTestUsername,
363 make_scoped_ptr(new autofill::PasswordForm(test_local_form())));
353 controller()->OnPasswordAutofilled(map); 364 controller()->OnPasswordAutofilled(map);
354 365
355 test_local_form().blacklisted_by_user = true; 366 test_local_form().blacklisted_by_user = true;
356 password_manager::PasswordStoreChange change( 367 password_manager::PasswordStoreChange change(
357 password_manager::PasswordStoreChange::ADD, test_local_form()); 368 password_manager::PasswordStoreChange::ADD, test_local_form());
358 password_manager::PasswordStoreChangeList list(1, change); 369 password_manager::PasswordStoreChangeList list(1, change);
359 controller()->OnLoginsChanged(list); 370 controller()->OnLoginsChanged(list);
360 371
361 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, controller()->state()); 372 EXPECT_EQ(password_manager::ui::BLACKLIST_STATE, controller()->state());
362 EXPECT_FALSE(controller()->PasswordPendingUserDecision()); 373 EXPECT_FALSE(controller()->PasswordPendingUserDecision());
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 547
537 controller()->ManageAccounts(); 548 controller()->ManageAccounts();
538 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->state()); 549 EXPECT_EQ(password_manager::ui::MANAGE_STATE, controller()->state());
539 controller()->UpdateIconAndBubbleState(&mock); 550 controller()->UpdateIconAndBubbleState(&mock);
540 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state()); 551 EXPECT_EQ(password_manager::ui::MANAGE_STATE, mock.state());
541 } 552 }
542 553
543 TEST_F(ManagePasswordsUIControllerTest, InactiveOnPSLMatched) { 554 TEST_F(ManagePasswordsUIControllerTest, InactiveOnPSLMatched) {
544 base::string16 kTestUsername = base::ASCIIToUTF16("test_username"); 555 base::string16 kTestUsername = base::ASCIIToUTF16("test_username");
545 autofill::PasswordFormMap map; 556 autofill::PasswordFormMap map;
546 autofill::PasswordForm psl_matched_test_form = test_local_form(); 557 scoped_ptr<autofill::PasswordForm> psl_matched_test_form(
547 psl_matched_test_form.original_signon_realm = "http://pslmatched.example.com"; 558 new autofill::PasswordForm(test_local_form()));
548 map[kTestUsername] = &psl_matched_test_form; 559 psl_matched_test_form->original_signon_realm =
560 "http://pslmatched.example.com";
561 map.insert(kTestUsername, psl_matched_test_form.Pass());
549 controller()->OnPasswordAutofilled(map); 562 controller()->OnPasswordAutofilled(map);
550 563
551 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->state()); 564 EXPECT_EQ(password_manager::ui::INACTIVE_STATE, controller()->state());
552 } 565 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/passwords/manage_passwords_test.cc ('k') | chromeos/dbus/gsm_sms_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698