OLD | NEW |
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 Loading... |
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_RemoveSavedPassword| message in the queue |
| 151 // of sent IPC messages. If none is present, returns false. Otherwise, |
| 152 // extracts the first |AutofillMsg_RemoveSavedPassword| message and returns |
| 153 // true. |
| 154 bool GetRemoveSavedPasswordMessage() { |
| 155 const uint32 kMsgID = AutofillMsg_RemoveSavedPassword::ID; |
| 156 const IPC::Message* message = |
| 157 process()->sink().GetFirstMessageMatching(kMsgID); |
| 158 if (!message) |
| 159 return false; |
| 160 process()->sink().ClearMessages(); |
| 161 return true; |
| 162 } |
| 163 |
149 // Searches for a message matching |messageID| in the queue of sent IPC | 164 // Searches for a message matching |messageID| in the queue of sent IPC |
150 // messages. If none is present, returns false. Otherwise, extracts the first | 165 // messages. If none is present, returns false. Otherwise, extracts the first |
151 // matching message, fills the output parameter with the string16 from the | 166 // matching message, fills the output parameter with the string16 from the |
152 // message's parameter, and clears the queue of sent messages. | 167 // message's parameter, and clears the queue of sent messages. |
153 bool GetString16FromMessageWithID(uint32 messageID, base::string16* value) { | 168 bool GetString16FromMessageWithID(uint32 messageID, base::string16* value) { |
154 const IPC::Message* message = | 169 const IPC::Message* message = |
155 process()->sink().GetFirstMessageMatching(messageID); | 170 process()->sink().GetFirstMessageMatching(messageID); |
156 if (!message) | 171 if (!message) |
157 return false; | 172 return false; |
158 Tuple1<base::string16> autofill_param; | 173 Tuple1<base::string16> autofill_param; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 251 |
237 int output_page_id = 0; | 252 int output_page_id = 0; |
238 FormData output_form_data; | 253 FormData output_form_data; |
239 EXPECT_FALSE( | 254 EXPECT_FALSE( |
240 GetAutofillPreviewFormMessage(&output_page_id, &output_form_data)); | 255 GetAutofillPreviewFormMessage(&output_page_id, &output_form_data)); |
241 EXPECT_TRUE(GetAutofillFillFormMessage(&output_page_id, &output_form_data)); | 256 EXPECT_TRUE(GetAutofillFillFormMessage(&output_page_id, &output_form_data)); |
242 EXPECT_EQ(input_page_id, output_page_id); | 257 EXPECT_EQ(input_page_id, output_page_id); |
243 EXPECT_EQ(input_form_data, output_form_data); | 258 EXPECT_EQ(input_form_data, output_form_data); |
244 } | 259 } |
245 | 260 |
| 261 TEST_F(ContentAutofillDriverTest, RemoveSavedPasswordSentToRenderer) { |
| 262 base::string16 input_username(base::ASCIIToUTF16("username")); |
| 263 driver_->RemovePasswordAutofillSuggestion(input_username); |
| 264 EXPECT_EQ(driver_->mock_autofill_manager()->username_to_remove(), |
| 265 input_username); |
| 266 EXPECT_TRUE(GetRemoveSavedPasswordMessage()); |
| 267 } |
| 268 |
246 TEST_F(ContentAutofillDriverTest, FormDataSentToRenderer_PreviewForm) { | 269 TEST_F(ContentAutofillDriverTest, FormDataSentToRenderer_PreviewForm) { |
247 int input_page_id = 42; | 270 int input_page_id = 42; |
248 FormData input_form_data; | 271 FormData input_form_data; |
249 test::CreateTestAddressFormData(&input_form_data); | 272 test::CreateTestAddressFormData(&input_form_data); |
250 driver_->SendFormDataToRenderer( | 273 driver_->SendFormDataToRenderer( |
251 input_page_id, AutofillDriver::FORM_DATA_ACTION_PREVIEW, input_form_data); | 274 input_page_id, AutofillDriver::FORM_DATA_ACTION_PREVIEW, input_form_data); |
252 | 275 |
253 int output_page_id = 0; | 276 int output_page_id = 0; |
254 FormData output_form_data; | 277 FormData output_form_data; |
255 EXPECT_FALSE(GetAutofillFillFormMessage(&output_page_id, &output_form_data)); | 278 EXPECT_FALSE(GetAutofillFillFormMessage(&output_page_id, &output_form_data)); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 base::string16 input_value(base::ASCIIToUTF16("barqux")); | 351 base::string16 input_value(base::ASCIIToUTF16("barqux")); |
329 base::string16 output_value; | 352 base::string16 output_value; |
330 driver_->RendererShouldPreviewFieldWithValue(input_value); | 353 driver_->RendererShouldPreviewFieldWithValue(input_value); |
331 EXPECT_TRUE(GetString16FromMessageWithID( | 354 EXPECT_TRUE(GetString16FromMessageWithID( |
332 AutofillMsg_PreviewFieldWithValue::ID, | 355 AutofillMsg_PreviewFieldWithValue::ID, |
333 &output_value)); | 356 &output_value)); |
334 EXPECT_EQ(input_value, output_value); | 357 EXPECT_EQ(input_value, output_value); |
335 } | 358 } |
336 | 359 |
337 } // namespace autofill | 360 } // namespace autofill |
OLD | NEW |