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

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: ToT 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/content/common/autofill_messages.h" 13 #include "components/autofill/content/common/autofill_messages.h"
14 #include "components/autofill/core/browser/autofill_external_delegate.h" 14 #include "components/autofill/core/browser/autofill_external_delegate.h"
15 #include "components/autofill/core/browser/autofill_manager.h" 15 #include "components/autofill/core/browser/autofill_manager.h"
16 #include "components/autofill/core/browser/autofill_test_utils.h" 16 #include "components/autofill/core/browser/autofill_test_utils.h"
17 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" 17 #include "components/autofill/core/browser/test_autofill_manager_delegate.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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 if (!AutofillMsg_FieldTypePredictionsAvailable::Read(message, 142 if (!AutofillMsg_FieldTypePredictionsAvailable::Read(message,
142 &autofill_param)) 143 &autofill_param))
143 return false; 144 return false;
144 if (predictions) 145 if (predictions)
145 *predictions = autofill_param.a; 146 *predictions = autofill_param.a;
146 147
147 process()->sink().ClearMessages(); 148 process()->sink().ClearMessages();
148 return true; 149 return true;
149 } 150 }
150 151
152 // Searches for an |AutofillMsg_RemovePasswordSuggestion| message in the queue
153 // of sent IPC messages. If none is present, returns false. Otherwise,
154 // extracts the first |AutofillMsg_RemovePasswordSuggestion| message, fills
155 // the output parameters with the values of the message's parameter, and
156 // clears the queue of sent messages.
157 bool GetRemovePasswordSuggestionMessage(PasswordForm* results) {
158 const uint32 kMsgID = AutofillMsg_RemovePasswordSuggestion::ID;
159 const IPC::Message* message =
160 process()->sink().GetFirstMessageMatching(kMsgID);
161 if (!message)
162 return false;
163 Tuple1<PasswordForm> password_form;
164 AutofillMsg_RemovePasswordSuggestion::Read(message, &password_form);
165 if (results)
166 *results = password_form.a;
167 process()->sink().ClearMessages();
168 return true;
169 }
170
151 // 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
152 // messages. If none is present, returns false. Otherwise, extracts the first 172 // messages. If none is present, returns false. Otherwise, extracts the first
153 // matching message, fills the output parameter with the string16 from the 173 // matching message, fills the output parameter with the string16 from the
154 // message's parameter, and clears the queue of sent messages. 174 // message's parameter, and clears the queue of sent messages.
155 bool GetString16FromMessageWithID(uint32 messageID, base::string16* value) { 175 bool GetString16FromMessageWithID(uint32 messageID, base::string16* value) {
156 const IPC::Message* message = 176 const IPC::Message* message =
157 process()->sink().GetFirstMessageMatching(messageID); 177 process()->sink().GetFirstMessageMatching(messageID);
158 if (!message) 178 if (!message)
159 return false; 179 return false;
160 Tuple1<base::string16> autofill_param; 180 Tuple1<base::string16> autofill_param;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 int output_page_id = 0; 275 int output_page_id = 0;
256 FormData output_form_data; 276 FormData output_form_data;
257 EXPECT_FALSE(GetAutofillFillFormMessage(&output_page_id, 277 EXPECT_FALSE(GetAutofillFillFormMessage(&output_page_id,
258 &output_form_data)); 278 &output_form_data));
259 EXPECT_TRUE(GetAutofillPreviewFormMessage(&output_page_id, 279 EXPECT_TRUE(GetAutofillPreviewFormMessage(&output_page_id,
260 &output_form_data)); 280 &output_form_data));
261 EXPECT_EQ(input_page_id, output_page_id); 281 EXPECT_EQ(input_page_id, output_page_id);
262 EXPECT_EQ(input_form_data, output_form_data); 282 EXPECT_EQ(input_form_data, output_form_data);
263 } 283 }
264 284
285 TEST_F(AutofillDriverImplTest, RemovePasswordSuggestionSentToRenderer) {
286 PasswordForm input_password_form;
287 input_password_form.username_value = base::ASCIIToUTF16("username");
288 input_password_form.password_value = base::ASCIIToUTF16("password");
289
290 driver_->RemovePasswordAutofillSuggestion(input_password_form);
291
292 PasswordForm output_password_form;
293 EXPECT_TRUE(GetRemovePasswordSuggestionMessage(&output_password_form));
294
295 EXPECT_EQ(input_password_form, output_password_form);
296 }
297
265 TEST_F(AutofillDriverImplTest, TypePredictionsNotSentToRendererWhenDisabled) { 298 TEST_F(AutofillDriverImplTest, TypePredictionsNotSentToRendererWhenDisabled) {
266 FormData form; 299 FormData form;
267 test::CreateTestAddressFormData(&form); 300 test::CreateTestAddressFormData(&form);
268 FormStructure form_structure(form); 301 FormStructure form_structure(form);
269 std::vector<FormStructure*> forms(1, &form_structure); 302 std::vector<FormStructure*> forms(1, &form_structure);
270 driver_->SendAutofillTypePredictionsToRenderer(forms); 303 driver_->SendAutofillTypePredictionsToRenderer(forms);
271 EXPECT_FALSE(GetFieldTypePredictionsAvailable(NULL)); 304 EXPECT_FALSE(GetFieldTypePredictionsAvailable(NULL));
272 } 305 }
273 306
274 TEST_F(AutofillDriverImplTest, TypePredictionsSentToRendererWhenEnabled) { 307 TEST_F(AutofillDriverImplTest, TypePredictionsSentToRendererWhenEnabled) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 TEST_F(AutofillDriverImplTest, SetNodeText) { 354 TEST_F(AutofillDriverImplTest, SetNodeText) {
322 base::string16 input_value(base::ASCIIToUTF16("barqux")); 355 base::string16 input_value(base::ASCIIToUTF16("barqux"));
323 base::string16 output_value; 356 base::string16 output_value;
324 driver_->RendererShouldSetNodeText(input_value); 357 driver_->RendererShouldSetNodeText(input_value);
325 EXPECT_TRUE(GetString16FromMessageWithID(AutofillMsg_SetNodeText::ID, 358 EXPECT_TRUE(GetString16FromMessageWithID(AutofillMsg_SetNodeText::ID,
326 &output_value)); 359 &output_value));
327 EXPECT_EQ(input_value, output_value); 360 EXPECT_EQ(input_value, output_value);
328 } 361 }
329 362
330 } // namespace autofill 363 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698