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

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

Issue 1208133002: [Autofill/Autocomplete Feature] Substring matching instead of prefix matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added |match_start| usage. Created 5 years, 5 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 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/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/popup_item_ids.h" 10 #include "components/autofill/core/browser/popup_item_ids.h"
(...skipping 30 matching lines...) Expand all
41 } 41 }
42 42
43 namespace password_manager { 43 namespace password_manager {
44 44
45 namespace { 45 namespace {
46 46
47 class MockPasswordManagerDriver : public StubPasswordManagerDriver { 47 class MockPasswordManagerDriver : public StubPasswordManagerDriver {
48 public: 48 public:
49 MOCK_METHOD2(FillSuggestion, 49 MOCK_METHOD2(FillSuggestion,
50 void(const base::string16&, const base::string16&)); 50 void(const base::string16&, const base::string16&));
51 MOCK_METHOD2(PreviewSuggestion, 51 MOCK_METHOD3(PreviewSuggestion,
52 void(const base::string16&, const base::string16&)); 52 void(const base::string16&,
53 const base::string16&,
54 size_t match_start));
53 }; 55 };
54 56
55 class TestPasswordManagerClient : public StubPasswordManagerClient { 57 class TestPasswordManagerClient : public StubPasswordManagerClient {
56 public: 58 public:
57 MockPasswordManagerDriver* mock_driver() { return &driver_; } 59 MockPasswordManagerDriver* mock_driver() { return &driver_; }
58 60
59 private: 61 private:
60 MockPasswordManagerDriver driver_; 62 MockPasswordManagerDriver driver_;
61 }; 63 };
62 64
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 141
140 password_autofill_manager_->DidNavigateMainFrame(); 142 password_autofill_manager_->DidNavigateMainFrame();
141 EXPECT_FALSE(password_autofill_manager_->FillSuggestionForTest( 143 EXPECT_FALSE(password_autofill_manager_->FillSuggestionForTest(
142 fill_data_id(), test_username_)); 144 fill_data_id(), test_username_));
143 } 145 }
144 146
145 TEST_F(PasswordAutofillManagerTest, PreviewSuggestion) { 147 TEST_F(PasswordAutofillManagerTest, PreviewSuggestion) {
146 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); 148 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient);
147 InitializePasswordAutofillManager(client.get(), nullptr); 149 InitializePasswordAutofillManager(client.get(), nullptr);
148 150
151 size_t match_start = 0;
149 EXPECT_CALL(*client->mock_driver(), 152 EXPECT_CALL(*client->mock_driver(),
150 PreviewSuggestion(test_username_, test_password_)); 153 PreviewSuggestion(test_username_, test_password_, match_start));
151 EXPECT_TRUE(password_autofill_manager_->PreviewSuggestionForTest( 154 EXPECT_TRUE(password_autofill_manager_->PreviewSuggestionForTest(
152 fill_data_id(), test_username_)); 155 fill_data_id(), test_username_, match_start));
153 testing::Mock::VerifyAndClearExpectations(client->mock_driver()); 156 testing::Mock::VerifyAndClearExpectations(client->mock_driver());
154 157
155 EXPECT_CALL(*client->mock_driver(), PreviewSuggestion(_, _)).Times(0); 158 EXPECT_CALL(*client->mock_driver(), PreviewSuggestion(_, _, _)).Times(0);
156 EXPECT_FALSE(password_autofill_manager_->PreviewSuggestionForTest( 159 EXPECT_FALSE(password_autofill_manager_->PreviewSuggestionForTest(
157 fill_data_id(), base::ASCIIToUTF16(kInvalidUsername))); 160 fill_data_id(), base::ASCIIToUTF16(kInvalidUsername), match_start));
158 161
159 const int invalid_fill_data_id = fill_data_id() + 1; 162 const int invalid_fill_data_id = fill_data_id() + 1;
160 163
161 EXPECT_FALSE(password_autofill_manager_->PreviewSuggestionForTest( 164 EXPECT_FALSE(password_autofill_manager_->PreviewSuggestionForTest(
162 invalid_fill_data_id, test_username_)); 165 invalid_fill_data_id, test_username_, match_start));
163 166
164 password_autofill_manager_->DidNavigateMainFrame(); 167 password_autofill_manager_->DidNavigateMainFrame();
165 EXPECT_FALSE(password_autofill_manager_->PreviewSuggestionForTest( 168 EXPECT_FALSE(password_autofill_manager_->PreviewSuggestionForTest(
166 fill_data_id(), test_username_)); 169 fill_data_id(), test_username_, match_start));
167 } 170 }
168 171
169 // Test that the popup is marked as visible after recieving password 172 // Test that the popup is marked as visible after recieving password
170 // suggestions. 173 // suggestions.
171 TEST_F(PasswordAutofillManagerTest, ExternalDelegatePasswordSuggestions) { 174 TEST_F(PasswordAutofillManagerTest, ExternalDelegatePasswordSuggestions) {
172 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient); 175 scoped_ptr<TestPasswordManagerClient> client(new TestPasswordManagerClient);
173 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient); 176 scoped_ptr<MockAutofillClient> autofill_client(new MockAutofillClient);
174 InitializePasswordAutofillManager(client.get(), autofill_client.get()); 177 InitializePasswordAutofillManager(client.get(), autofill_client.get());
175 178
176 gfx::RectF element_bounds; 179 gfx::RectF element_bounds;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 SuggestionVectorValuesAre(testing::UnorderedElementsAre( 351 SuggestionVectorValuesAre(testing::UnorderedElementsAre(
349 title, 352 title,
350 test_username_)), 353 test_username_)),
351 _)); 354 _));
352 password_autofill_manager_->OnShowPasswordSuggestions( 355 password_autofill_manager_->OnShowPasswordSuggestions(
353 dummy_key, base::i18n::RIGHT_TO_LEFT, test_username_, 356 dummy_key, base::i18n::RIGHT_TO_LEFT, test_username_,
354 autofill::IS_PASSWORD_FIELD, element_bounds); 357 autofill::IS_PASSWORD_FIELD, element_bounds);
355 } 358 }
356 359
357 } // namespace password_manager 360 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698