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