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

Side by Side Diff: components/autofill/content/browser/autofill_driver_impl_unittest.cc

Issue 133893004: Allow deleting autofill password suggestions on Shift+Delete (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleaning the code Created 6 years, 9 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
12 #include "components/autofill/content/browser/autofill_driver_impl.h" 12 #include "components/autofill/content/browser/autofill_driver_impl.h"
13 #include "components/autofill/core/browser/autofill_external_delegate.h" 13 #include "components/autofill/core/browser/autofill_external_delegate.h"
14 #include "components/autofill/core/browser/autofill_manager.h" 14 #include "components/autofill/core/browser/autofill_manager.h"
15 #include "components/autofill/core/browser/autofill_test_utils.h" 15 #include "components/autofill/core/browser/autofill_test_utils.h"
16 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" 16 #include "components/autofill/core/browser/test_autofill_manager_delegate.h"
17 #include "components/autofill/core/common/autofill_messages.h" 17 #include "components/autofill/core/common/autofill_messages.h"
18 #include "components/autofill/core/common/autofill_switches.h" 18 #include "components/autofill/core/common/autofill_switches.h"
19 #include "components/autofill/core/common/form_data_predictions.h" 19 #include "components/autofill/core/common/form_data_predictions.h"
20 #include "components/autofill/core/common/password_form.h"
20 #include "content/public/browser/browser_context.h" 21 #include "content/public/browser/browser_context.h"
21 #include "content/public/browser/navigation_details.h" 22 #include "content/public/browser/navigation_details.h"
22 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
23 #include "content/public/common/frame_navigate_params.h" 24 #include "content/public/common/frame_navigate_params.h"
24 #include "content/public/test/mock_render_process_host.h" 25 #include "content/public/test/mock_render_process_host.h"
25 #include "ipc/ipc_test_sink.h" 26 #include "ipc/ipc_test_sink.h"
26 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 29
29 namespace autofill { 30 namespace autofill {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 return false; 119 return false;
119 Tuple1<std::vector<FormDataPredictions> > autofill_param; 120 Tuple1<std::vector<FormDataPredictions> > autofill_param;
120 AutofillMsg_FieldTypePredictionsAvailable::Read(message, &autofill_param); 121 AutofillMsg_FieldTypePredictionsAvailable::Read(message, &autofill_param);
121 if (predictions) 122 if (predictions)
122 *predictions = autofill_param.a; 123 *predictions = autofill_param.a;
123 124
124 process()->sink().ClearMessages(); 125 process()->sink().ClearMessages();
125 return true; 126 return true;
126 } 127 }
127 128
129 // Searches for an |AutofillMsg_RemovePasswordSuggestion| message in the queue
130 // of sent IPC messages. If none is present, returns false. Otherwise,
131 // extracts the first |AutofillMsg_RemovePasswordSuggestion| message, fills
132 // the output parameters with the values of the message's parameter, and
133 // clears the queue of sent messages.
134 bool GetRemovePasswordSuggestionMessage(PasswordForm* results) {
135 const uint32 kMsgID = AutofillMsg_RemovePasswordSuggestion::ID;
136 const IPC::Message* message =
137 process()->sink().GetFirstMessageMatching(kMsgID);
138 if (!message)
139 return false;
140 Tuple1<PasswordForm> password_form;
141 AutofillMsg_RemovePasswordSuggestion::Read(message, &password_form);
142 if (results)
143 *results = password_form.a;
144 process()->sink().ClearMessages();
145 return true;
146 }
147
128 // Searches for a message matching |messageID| in the queue of sent IPC 148 // Searches for a message matching |messageID| in the queue of sent IPC
129 // messages. If none is present, returns false. Otherwise, extracts the first 149 // messages. If none is present, returns false. Otherwise, extracts the first
130 // matching message, fills the output parameter with the string16 from the 150 // matching message, fills the output parameter with the string16 from the
131 // message's parameter, and clears the queue of sent messages. 151 // message's parameter, and clears the queue of sent messages.
132 bool GetString16FromMessageWithID(uint32 messageID, base::string16* value) { 152 bool GetString16FromMessageWithID(uint32 messageID, base::string16* value) {
133 const IPC::Message* message = 153 const IPC::Message* message =
134 process()->sink().GetFirstMessageMatching(messageID); 154 process()->sink().GetFirstMessageMatching(messageID);
135 if (!message) 155 if (!message)
136 return false; 156 return false;
137 Tuple1<base::string16> autofill_param; 157 Tuple1<base::string16> autofill_param;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 driver_->SendFormDataToRenderer(input_page_id, input_form_data); 226 driver_->SendFormDataToRenderer(input_page_id, input_form_data);
207 227
208 int output_page_id = 0; 228 int output_page_id = 0;
209 FormData output_form_data; 229 FormData output_form_data;
210 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&output_page_id, 230 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&output_page_id,
211 &output_form_data)); 231 &output_form_data));
212 EXPECT_EQ(input_page_id, output_page_id); 232 EXPECT_EQ(input_page_id, output_page_id);
213 EXPECT_EQ(input_form_data, output_form_data); 233 EXPECT_EQ(input_form_data, output_form_data);
214 } 234 }
215 235
236 TEST_F(AutofillDriverImplTest, RemovePasswordSuggestionSentToRenderer) {
237 PasswordForm input_password_form;
238 input_password_form.username_value = base::ASCIIToUTF16("username");
239 input_password_form.password_value = base::ASCIIToUTF16("password");
240
241 driver_->RemovePasswordAutofillSuggestion(input_password_form);
242
243 PasswordForm output_password_form;
244 EXPECT_TRUE(GetRemovePasswordSuggestionMessage(&output_password_form));
245
246 EXPECT_EQ(input_password_form, output_password_form);
247 }
248
216 TEST_F(AutofillDriverImplTest, TypePredictionsNotSentToRendererWhenDisabled) { 249 TEST_F(AutofillDriverImplTest, TypePredictionsNotSentToRendererWhenDisabled) {
217 FormData form; 250 FormData form;
218 test::CreateTestAddressFormData(&form); 251 test::CreateTestAddressFormData(&form);
219 FormStructure form_structure(form); 252 FormStructure form_structure(form);
220 std::vector<FormStructure*> forms(1, &form_structure); 253 std::vector<FormStructure*> forms(1, &form_structure);
221 driver_->SendAutofillTypePredictionsToRenderer(forms); 254 driver_->SendAutofillTypePredictionsToRenderer(forms);
222 EXPECT_FALSE(GetFieldTypePredictionsAvailable(NULL)); 255 EXPECT_FALSE(GetFieldTypePredictionsAvailable(NULL));
223 } 256 }
224 257
225 TEST_F(AutofillDriverImplTest, TypePredictionsSentToRendererWhenEnabled) { 258 TEST_F(AutofillDriverImplTest, TypePredictionsSentToRendererWhenEnabled) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 TEST_F(AutofillDriverImplTest, SetNodeText) { 317 TEST_F(AutofillDriverImplTest, SetNodeText) {
285 base::string16 input_value(ASCIIToUTF16("barqux")); 318 base::string16 input_value(ASCIIToUTF16("barqux"));
286 base::string16 output_value; 319 base::string16 output_value;
287 driver_->RendererShouldSetNodeText(input_value); 320 driver_->RendererShouldSetNodeText(input_value);
288 EXPECT_TRUE(GetString16FromMessageWithID(AutofillMsg_SetNodeText::ID, 321 EXPECT_TRUE(GetString16FromMessageWithID(AutofillMsg_SetNodeText::ID,
289 &output_value)); 322 &output_value));
290 EXPECT_EQ(input_value, output_value); 323 EXPECT_EQ(input_value, output_value);
291 } 324 }
292 325
293 } // namespace autofill 326 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698