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

Side by Side Diff: components/password_manager/core/browser/password_autofill_manager_unittest.cc

Issue 492043003: Fill on account select in the password manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Unit tests Created 6 years 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 | Annotate | Revision Log
« no previous file with comments | « components/password_manager/core/browser/password_autofill_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/core/browser/password_autofill_manager.h" 5 #include "components/password_manager/core/browser/password_autofill_manager.h"
6 6
7 #include "base/command_line.h"
7 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/popup_item_ids.h" 11 #include "components/autofill/core/browser/popup_item_ids.h"
11 #include "components/autofill/core/browser/test_autofill_client.h" 12 #include "components/autofill/core/browser/test_autofill_client.h"
12 #include "components/autofill/core/browser/test_autofill_driver.h" 13 #include "components/autofill/core/browser/test_autofill_driver.h"
14 #include "components/autofill/core/common/autofill_switches.h"
13 #include "components/autofill/core/common/form_field_data.h" 15 #include "components/autofill/core/common/form_field_data.h"
14 #include "components/autofill/core/common/password_form_fill_data.h" 16 #include "components/autofill/core/common/password_form_fill_data.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"
19 #include "components/strings/grit/components_strings.h"
17 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/gfx/geometry/rect_f.h" 23 #include "ui/gfx/geometry/rect_f.h"
20 24
21 // The name of the username/password element in the form. 25 // The name of the username/password element in the form.
22 const char kUsernameName[] = "username"; 26 const char kUsernameName[] = "username";
23 const char kInvalidUsername[] = "no-username"; 27 const char kInvalidUsername[] = "no-username";
24 const char kPasswordName[] = "password"; 28 const char kPasswordName[] = "password";
25 29
26 const char kAliceUsername[] = "alice"; 30 const char kAliceUsername[] = "alice";
27 const char kAlicePassword[] = "password"; 31 const char kAlicePassword[] = "password";
28 32
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 ShowAutofillPopup( 260 ShowAutofillPopup(
257 element_bounds, _, 261 element_bounds, _,
258 testing::UnorderedElementsAre( 262 testing::UnorderedElementsAre(
259 test_username_, additional_username, other_username), 263 test_username_, additional_username, other_username),
260 _, _, _, _)); 264 _, _, _, _));
261 password_autofill_manager_->OnShowPasswordSuggestions( 265 password_autofill_manager_->OnShowPasswordSuggestions(
262 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("xyz"), true, 266 dummy_key, base::i18n::RIGHT_TO_LEFT, base::ASCIIToUTF16("xyz"), true,
263 element_bounds); 267 element_bounds);
264 } 268 }
265 269
270 TEST_F(PasswordAutofillManagerTest, FillOnAccountSelectOnly) {
271 CommandLine::ForCurrentProcess()->AppendSwitch(
272 autofill::switches::kEnableFillOnAccountSelect);
273
274 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient);
275 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient);
276 InitializePasswordAutofillManager(client.get(), autofill_client.get());
277
278 gfx::RectF element_bounds;
279 autofill::PasswordFormFillData data;
280 data.username_field.value = test_username_;
281 data.password_field.value = test_password_;
282 data.preferred_realm = "http://foo.com/";
283
284 autofill::PasswordAndRealm additional;
285 additional.realm = "https://foobarrealm.org";
286 base::string16 additional_username(base::ASCIIToUTF16("John Foo"));
287 data.additional_logins[additional_username] = additional;
288
289 autofill::UsernamesCollectionKey usernames_key;
290 usernames_key.realm = "http://yetanother.net";
291 std::vector<base::string16> other_names;
292 base::string16 other_username(base::ASCIIToUTF16("John Different"));
293 other_names.push_back(other_username);
294 data.other_possible_usernames[usernames_key] = other_names;
295
296 int dummy_key = 0;
297 password_autofill_manager_->OnAddPasswordFormMapping(dummy_key, data);
298
299 // Simulate displaying suggestions matching a username and specifying that the
300 // field is a password field.
301 base::string16 title = l10n_util::GetStringUTF16(
302 IDS_AUTOFILL_PASSWORD_FIELD_SUGGESTIONS_TITLE);
303 EXPECT_CALL(*autofill_client,
304 ShowAutofillPopup(
305 element_bounds, _,
306 testing::UnorderedElementsAre(title, test_username_),
307 _, _, _, _));
308 password_autofill_manager_->OnShowPasswordSuggestions(
309 dummy_key, base::i18n::RIGHT_TO_LEFT, test_username_,
310 autofill::ShowPasswordSuggestionsOptions::IS_PASSWORD_FIELD,
311 element_bounds);
312 }
313
266 } // namespace password_manager 314 } // namespace password_manager
OLDNEW
« no previous file with comments | « components/password_manager/core/browser/password_autofill_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698