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

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

Issue 223133003: Allow deleting autofill password suggestions on Shift+Delete (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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 <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 "components/autofill/content/browser/content_autofill_driver.h" 11 #include "components/autofill/content/browser/content_autofill_driver.h"
12 #include "components/autofill/content/common/autofill_messages.h" 12 #include "components/autofill/content/common/autofill_messages.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_switches.h" 17 #include "components/autofill/core/common/autofill_switches.h"
18 #include "components/autofill/core/common/form_data_predictions.h" 18 #include "components/autofill/core/common/form_data_predictions.h"
19 #include "components/autofill/core/common/password_form.h"
19 #include "content/public/browser/browser_context.h" 20 #include "content/public/browser/browser_context.h"
20 #include "content/public/browser/navigation_details.h" 21 #include "content/public/browser/navigation_details.h"
21 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
22 #include "content/public/common/frame_navigate_params.h" 23 #include "content/public/common/frame_navigate_params.h"
23 #include "content/public/test/mock_render_process_host.h" 24 #include "content/public/test/mock_render_process_host.h"
24 #include "content/public/test/test_renderer_host.h" 25 #include "content/public/test/test_renderer_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
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 if (!AutofillMsg_FieldTypePredictionsAvailable::Read(message, 140 if (!AutofillMsg_FieldTypePredictionsAvailable::Read(message,
140 &autofill_param)) 141 &autofill_param))
141 return false; 142 return false;
142 if (predictions) 143 if (predictions)
143 *predictions = autofill_param.a; 144 *predictions = autofill_param.a;
144 145
145 process()->sink().ClearMessages(); 146 process()->sink().ClearMessages();
146 return true; 147 return true;
147 } 148 }
148 149
150 // Searches for an |AutofillMsg_RemovePasswordSuggestion| message in the queue
151 // of sent IPC messages. If none is present, returns false. Otherwise,
152 // extracts the first |AutofillMsg_RemovePasswordSuggestion| message, fills
153 // the output parameters with the values of the message's parameter, and
154 // clears the queue of sent messages.
155 bool GetRemovePasswordSuggestionMessage(
156 base::string16* username_to_remove) {
157 const uint32 kMsgID = AutofillMsg_RemovePasswordSuggestion::ID;
158 const IPC::Message* message =
159 process()->sink().GetFirstMessageMatching(kMsgID);
160 if (!message)
161 return false;
162 Tuple1<base::string16> autofill_param;
163 if (!AutofillMsg_RemovePasswordSuggestion::Read(message, &autofill_param))
164 return false;
165 if (username_to_remove)
166 *username_to_remove = autofill_param.a;
167 process()->sink().ClearMessages();
168 return true;
169 }
170
149 // Searches for a message matching |messageID| in the queue of sent IPC 171 // Searches for a message matching |messageID| in the queue of sent IPC
150 // messages. If none is present, returns false. Otherwise, extracts the first 172 // messages. If none is present, returns false. Otherwise, extracts the first
151 // matching message, fills the output parameter with the string16 from the 173 // matching message, fills the output parameter with the string16 from the
152 // message's parameter, and clears the queue of sent messages. 174 // message's parameter, and clears the queue of sent messages.
153 bool GetString16FromMessageWithID(uint32 messageID, base::string16* value) { 175 bool GetString16FromMessageWithID(uint32 messageID, base::string16* value) {
154 const IPC::Message* message = 176 const IPC::Message* message =
155 process()->sink().GetFirstMessageMatching(messageID); 177 process()->sink().GetFirstMessageMatching(messageID);
156 if (!message) 178 if (!message)
157 return false; 179 return false;
158 Tuple1<base::string16> autofill_param; 180 Tuple1<base::string16> autofill_param;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 258
237 int output_page_id = 0; 259 int output_page_id = 0;
238 FormData output_form_data; 260 FormData output_form_data;
239 EXPECT_FALSE( 261 EXPECT_FALSE(
240 GetAutofillPreviewFormMessage(&output_page_id, &output_form_data)); 262 GetAutofillPreviewFormMessage(&output_page_id, &output_form_data));
241 EXPECT_TRUE(GetAutofillFillFormMessage(&output_page_id, &output_form_data)); 263 EXPECT_TRUE(GetAutofillFillFormMessage(&output_page_id, &output_form_data));
242 EXPECT_EQ(input_page_id, output_page_id); 264 EXPECT_EQ(input_page_id, output_page_id);
243 EXPECT_EQ(input_form_data, output_form_data); 265 EXPECT_EQ(input_form_data, output_form_data);
244 } 266 }
245 267
268 TEST_F(ContentAutofillDriverTest, RemovePasswordSuggestionSentToRenderer) {
269 base::string16 input_username(base::ASCIIToUTF16("username"));
270
271 driver_->RemovePasswordAutofillSuggestion(input_username);
272
273 base::string16 output_username;
274 EXPECT_TRUE(GetRemovePasswordSuggestionMessage(&output_username));
275
276 EXPECT_EQ(input_username, output_username);
277 }
278
246 TEST_F(ContentAutofillDriverTest, FormDataSentToRenderer_PreviewForm) { 279 TEST_F(ContentAutofillDriverTest, FormDataSentToRenderer_PreviewForm) {
247 int input_page_id = 42; 280 int input_page_id = 42;
248 FormData input_form_data; 281 FormData input_form_data;
249 test::CreateTestAddressFormData(&input_form_data); 282 test::CreateTestAddressFormData(&input_form_data);
250 driver_->SendFormDataToRenderer( 283 driver_->SendFormDataToRenderer(
251 input_page_id, AutofillDriver::FORM_DATA_ACTION_PREVIEW, input_form_data); 284 input_page_id, AutofillDriver::FORM_DATA_ACTION_PREVIEW, input_form_data);
252 285
253 int output_page_id = 0; 286 int output_page_id = 0;
254 FormData output_form_data; 287 FormData output_form_data;
255 EXPECT_FALSE(GetAutofillFillFormMessage(&output_page_id, &output_form_data)); 288 EXPECT_FALSE(GetAutofillFillFormMessage(&output_page_id, &output_form_data));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 base::string16 input_value(base::ASCIIToUTF16("barqux")); 361 base::string16 input_value(base::ASCIIToUTF16("barqux"));
329 base::string16 output_value; 362 base::string16 output_value;
330 driver_->RendererShouldPreviewFieldWithValue(input_value); 363 driver_->RendererShouldPreviewFieldWithValue(input_value);
331 EXPECT_TRUE(GetString16FromMessageWithID( 364 EXPECT_TRUE(GetString16FromMessageWithID(
332 AutofillMsg_PreviewFieldWithValue::ID, 365 AutofillMsg_PreviewFieldWithValue::ID,
333 &output_value)); 366 &output_value));
334 EXPECT_EQ(input_value, output_value); 367 EXPECT_EQ(input_value, output_value);
335 } 368 }
336 369
337 } // namespace autofill 370 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698