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 "components/autofill/content/browser/content_autofill_driver.h" | 5 #include "components/autofill/content/browser/content_autofill_driver.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 #include <tuple> | 11 #include <tuple> |
12 #include <utility> | 12 #include <utility> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/run_loop.h" | |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "components/autofill/content/common/autofill_messages.h" | |
18 #include "components/autofill/core/browser/autofill_external_delegate.h" | 18 #include "components/autofill/core/browser/autofill_external_delegate.h" |
19 #include "components/autofill/core/browser/autofill_manager.h" | 19 #include "components/autofill/core/browser/autofill_manager.h" |
20 #include "components/autofill/core/browser/autofill_test_utils.h" | 20 #include "components/autofill/core/browser/autofill_test_utils.h" |
21 #include "components/autofill/core/browser/test_autofill_client.h" | 21 #include "components/autofill/core/browser/test_autofill_client.h" |
22 #include "components/autofill/core/common/autofill_switches.h" | 22 #include "components/autofill/core/common/autofill_switches.h" |
23 #include "components/autofill/core/common/form_data_predictions.h" | 23 #include "components/autofill/core/common/form_data_predictions.h" |
24 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
25 #include "content/public/browser/navigation_details.h" | 25 #include "content/public/browser/navigation_details.h" |
26 #include "content/public/browser/storage_partition.h" | 26 #include "content/public/browser/storage_partition.h" |
27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
28 #include "content/public/common/frame_navigate_params.h" | 28 #include "content/public/common/frame_navigate_params.h" |
29 #include "content/public/test/mock_render_process_host.h" | 29 #include "content/public/test/mock_render_process_host.h" |
30 #include "content/public/test/test_renderer_host.h" | 30 #include "content/public/test/test_renderer_host.h" |
31 #include "ipc/ipc_test_sink.h" | 31 #include "mojo/common/common_type_converters.h" |
32 #include "mojo/public/cpp/bindings/binding_set.h" | |
33 #include "services/shell/public/cpp/interface_provider.h" | |
32 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
34 | 36 |
35 namespace autofill { | 37 namespace autofill { |
36 | 38 |
37 namespace { | 39 namespace { |
38 | 40 |
39 const char kAppLocale[] = "en-US"; | 41 const char kAppLocale[] = "en-US"; |
40 const AutofillManager::AutofillDownloadManagerState kDownloadState = | 42 const AutofillManager::AutofillDownloadManagerState kDownloadState = |
41 AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER; | 43 AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER; |
42 | 44 |
45 class FakeAutofillAgent : public mojom::AutofillAgent { | |
46 public: | |
47 FakeAutofillAgent() | |
48 : fillform_id_(-1), | |
49 previewform_id_(-1), | |
50 called_clearform_(false), | |
51 called_clearpreviewedform_(false) {} | |
52 | |
53 ~FakeAutofillAgent() override {} | |
54 | |
55 void BindRequest(mojo::ScopedMessagePipeHandle handle) { | |
56 bindings_.AddBinding( | |
57 this, mojo::MakeRequest<mojom::AutofillAgent>(std::move(handle))); | |
58 } | |
59 | |
60 void SetQuitLoopClosure(base::Closure closure) { quit_closure_ = closure; } | |
61 | |
62 // Returns the id and formdata received via | |
63 // mojo interface method mojom::AutofillAgent::FillForm(). | |
64 bool GetAutofillFillFormMessage(int* page_id, FormData* results) { | |
65 if (fillform_id_ == -1) | |
66 return false; | |
67 if (!fillform_form_) | |
68 return false; | |
69 | |
70 if (page_id) | |
71 *page_id = fillform_id_; | |
72 if (results) | |
73 *results = *fillform_form_; | |
74 return true; | |
75 } | |
76 | |
77 // Returns the id and formdata received via | |
78 // mojo interface method mojom::AutofillAgent::PreviewForm(). | |
79 bool GetAutofillPreviewFormMessage(int* page_id, FormData* results) { | |
80 if (previewform_id_ == -1) | |
81 return false; | |
82 if (!previewform_form_) | |
83 return false; | |
84 | |
85 if (page_id) | |
86 *page_id = previewform_id_; | |
87 if (results) | |
88 *results = *previewform_form_; | |
89 return true; | |
90 } | |
91 | |
92 // Returns data received via mojo interface method | |
93 // mojom::AutofillAent::FieldTypePredictionsAvailable(). | |
94 bool GetFieldTypePredictionsAvailable( | |
95 std::vector<FormDataPredictions>* predictions) { | |
96 if (!predictions_) | |
97 return false; | |
98 if (predictions) | |
99 *predictions = *predictions_; | |
100 return true; | |
101 } | |
102 | |
103 // Returns whether mojo interface method mojom::AutofillAgent::ClearForm() got | |
104 // called. | |
105 bool GetCalledClearForm() { return called_clearform_; } | |
106 | |
107 // Returns whether mojo interface method | |
108 // mojom::AutofillAgent::ClearPreviewedForm() got called. | |
109 bool GetCalledClearPreviewedForm() { return called_clearpreviewedform_; } | |
110 | |
111 // Returns data received via mojo interface method | |
112 // mojom::AutofillAent::FillFieldWithValue(). | |
113 bool GetString16FillFieldWithValue(base::string16* value) { | |
114 if (!value_fillfield_) | |
115 return false; | |
116 if (value) | |
117 *value = *value_fillfield_; | |
118 return true; | |
119 } | |
120 | |
121 // Returns data received via mojo interface method | |
122 // mojom::AutofillAent::PreviewFieldWithValue(). | |
123 bool GetString16PreviewFieldWithValue(base::string16* value) { | |
124 if (!value_previewfield_) | |
125 return false; | |
126 if (value) | |
127 *value = *value_previewfield_; | |
128 return true; | |
129 } | |
130 | |
131 // Returns data received via mojo interface method | |
132 // mojom::AutofillAent::AcceptDataListSuggestion(). | |
133 bool GetString16AcceptDataListSuggestion(base::string16* value) { | |
134 if (!value_acceptdata_) | |
135 return false; | |
136 if (value) | |
137 *value = *value_acceptdata_; | |
138 return true; | |
139 } | |
140 | |
141 private: | |
142 void CallDone() { | |
143 if (!quit_closure_.is_null()) { | |
144 quit_closure_.Run(); | |
145 quit_closure_.Reset(); | |
146 } | |
147 } | |
148 | |
149 // mojom::AutofillAgent methods: | |
150 void FirstUserGestureObservedInTab() override {} | |
151 | |
152 void FillForm(int32_t id, const FormData& form) override { | |
153 fillform_id_ = id; | |
154 fillform_form_.reset(new FormData(form)); | |
155 CallDone(); | |
156 } | |
157 | |
158 void PreviewForm(int32_t id, const FormData& form) override { | |
159 previewform_id_ = id; | |
160 previewform_form_.reset(new FormData(form)); | |
161 CallDone(); | |
162 } | |
163 | |
164 void FieldTypePredictionsAvailable( | |
165 mojo::Array<FormDataPredictions> forms) override { | |
166 predictions_.reset( | |
167 new std::vector<FormDataPredictions>(forms.PassStorage())); | |
168 CallDone(); | |
169 } | |
170 | |
171 void ClearForm() override { | |
172 called_clearform_ = true; | |
173 CallDone(); | |
174 } | |
175 | |
176 void ClearPreviewedForm() override { | |
177 called_clearpreviewedform_ = true; | |
178 CallDone(); | |
179 } | |
180 | |
181 void FillFieldWithValue(const mojo::String& value) override { | |
182 value_fillfield_.reset(new base::string16(value.To<base::string16>())); | |
183 CallDone(); | |
184 } | |
185 | |
186 void PreviewFieldWithValue(const mojo::String& value) override { | |
187 value_previewfield_.reset(new base::string16(value.To<base::string16>())); | |
188 CallDone(); | |
189 } | |
190 | |
191 void AcceptDataListSuggestion(const mojo::String& value) override { | |
192 value_acceptdata_.reset(new base::string16(value.To<base::string16>())); | |
193 CallDone(); | |
194 } | |
195 | |
196 void FillPasswordSuggestion(const mojo::String& username, | |
197 const mojo::String& password) override {} | |
198 | |
199 void PreviewPasswordSuggestion(const mojo::String& username, | |
200 const mojo::String& password) override {} | |
201 | |
202 void ShowInitialPasswordAccountSuggestions( | |
203 int32_t key, | |
204 const PasswordFormFillData& form_data) override {} | |
205 | |
206 mojo::BindingSet<mojom::AutofillAgent> bindings_; | |
207 | |
208 base::Closure quit_closure_; | |
209 | |
210 // Records data received from FillForm() call. | |
211 int32_t fillform_id_; | |
212 std::unique_ptr<FormData> fillform_form_; | |
213 // Records data received from PreviewForm() call. | |
214 int32_t previewform_id_; | |
215 std::unique_ptr<FormData> previewform_form_; | |
216 // Records data received from FieldTypePredictionsAvailable() call. | |
217 std::unique_ptr<std::vector<FormDataPredictions>> predictions_; | |
218 // Records whether ClearForm() got called. | |
219 bool called_clearform_; | |
220 // Records whether ClearPreviewedForm() got called. | |
221 bool called_clearpreviewedform_; | |
222 // Records string received from FillFieldWithValue() call. | |
223 std::unique_ptr<base::string16> value_fillfield_; | |
224 // Records string received from PreviewFieldWithValue() call. | |
225 std::unique_ptr<base::string16> value_previewfield_; | |
226 // Records string received from AcceptDataListSuggestion() call. | |
227 std::unique_ptr<base::string16> value_acceptdata_; | |
228 }; | |
229 | |
43 } // namespace | 230 } // namespace |
44 | 231 |
45 class MockAutofillManager : public AutofillManager { | 232 class MockAutofillManager : public AutofillManager { |
46 public: | 233 public: |
47 MockAutofillManager(AutofillDriver* driver, AutofillClient* client) | 234 MockAutofillManager(AutofillDriver* driver, AutofillClient* client) |
48 : AutofillManager(driver, client, kAppLocale, kDownloadState) {} | 235 : AutofillManager(driver, client, kAppLocale, kDownloadState) {} |
49 virtual ~MockAutofillManager() {} | 236 virtual ~MockAutofillManager() {} |
50 | 237 |
51 MOCK_METHOD0(Reset, void()); | 238 MOCK_METHOD0(Reset, void()); |
52 }; | 239 }; |
(...skipping 17 matching lines...) Expand all Loading... | |
70 }; | 257 }; |
71 | 258 |
72 class ContentAutofillDriverTest : public content::RenderViewHostTestHarness { | 259 class ContentAutofillDriverTest : public content::RenderViewHostTestHarness { |
73 public: | 260 public: |
74 void SetUp() override { | 261 void SetUp() override { |
75 content::RenderViewHostTestHarness::SetUp(); | 262 content::RenderViewHostTestHarness::SetUp(); |
76 | 263 |
77 test_autofill_client_.reset(new TestAutofillClient()); | 264 test_autofill_client_.reset(new TestAutofillClient()); |
78 driver_.reset(new TestContentAutofillDriver(web_contents()->GetMainFrame(), | 265 driver_.reset(new TestContentAutofillDriver(web_contents()->GetMainFrame(), |
79 test_autofill_client_.get())); | 266 test_autofill_client_.get())); |
267 | |
268 shell::InterfaceProvider* remote_interfaces = | |
269 web_contents()->GetMainFrame()->GetRemoteInterfaces(); | |
270 shell::InterfaceProvider::TestApi test_api(remote_interfaces); | |
271 test_api.SetBinderForName(mojom::AutofillAgent::Name_, | |
272 base::Bind(&FakeAutofillAgent::BindRequest, | |
273 base::Unretained(&fake_agent_))); | |
80 } | 274 } |
81 | 275 |
82 void TearDown() override { | 276 void TearDown() override { |
83 // Reset the driver now to cause all pref observers to be removed and avoid | 277 // Reset the driver now to cause all pref observers to be removed and avoid |
84 // crashes that otherwise occur in the destructor. | 278 // crashes that otherwise occur in the destructor. |
85 driver_.reset(); | 279 driver_.reset(); |
86 content::RenderViewHostTestHarness::TearDown(); | 280 content::RenderViewHostTestHarness::TearDown(); |
87 } | 281 } |
88 | 282 |
89 protected: | 283 protected: |
90 // Searches for an |AutofillMsg_FillForm| message in the queue of sent IPC | |
91 // messages. If none is present, returns false. Otherwise, extracts the first | |
92 // |AutofillMsg_FillForm| message, fills the output parameters with the values | |
93 // of the message's parameters, and clears the queue of sent messages. | |
94 bool GetAutofillFillFormMessage(int* page_id, FormData* results) { | |
95 const uint32_t kMsgID = AutofillMsg_FillForm::ID; | |
96 const IPC::Message* message = | |
97 process()->sink().GetFirstMessageMatching(kMsgID); | |
98 if (!message) | |
99 return false; | |
100 std::tuple<int, FormData> autofill_param; | |
101 if (!AutofillMsg_FillForm::Read(message, &autofill_param)) | |
102 return false; | |
103 if (page_id) | |
104 *page_id = std::get<0>(autofill_param); | |
105 if (results) | |
106 *results = std::get<1>(autofill_param); | |
107 process()->sink().ClearMessages(); | |
108 return true; | |
109 } | |
110 | |
111 // Searches for an |AutofillMsg_PreviewForm| message in the queue of sent IPC | |
112 // messages. If none is present, returns false. Otherwise, extracts the first | |
113 // |AutofillMsg_PreviewForm| message, fills the output parameters with the | |
114 // values of the message's parameters, and clears the queue of sent messages. | |
115 bool GetAutofillPreviewFormMessage(int* page_id, FormData* results) { | |
116 const uint32_t kMsgID = AutofillMsg_PreviewForm::ID; | |
117 const IPC::Message* message = | |
118 process()->sink().GetFirstMessageMatching(kMsgID); | |
119 if (!message) | |
120 return false; | |
121 std::tuple<int, FormData> autofill_param; | |
122 if (!AutofillMsg_PreviewForm::Read(message, &autofill_param)) | |
123 return false; | |
124 if (page_id) | |
125 *page_id = std::get<0>(autofill_param); | |
126 if (results) | |
127 *results = std::get<1>(autofill_param); | |
128 process()->sink().ClearMessages(); | |
129 return true; | |
130 } | |
131 | |
132 // Searches for an |AutofillMsg_FieldTypePredictionsAvailable| message in the | |
133 // queue of sent IPC messages. If none is present, returns false. Otherwise, | |
134 // extracts the first |AutofillMsg_FieldTypePredictionsAvailable| message, | |
135 // fills the output parameter with the values of the message's parameter, and | |
136 // clears the queue of sent messages. | |
137 bool GetFieldTypePredictionsAvailable( | |
138 std::vector<FormDataPredictions>* predictions) { | |
139 const uint32_t kMsgID = AutofillMsg_FieldTypePredictionsAvailable::ID; | |
140 const IPC::Message* message = | |
141 process()->sink().GetFirstMessageMatching(kMsgID); | |
142 if (!message) | |
143 return false; | |
144 std::tuple<std::vector<FormDataPredictions> > autofill_param; | |
145 if (!AutofillMsg_FieldTypePredictionsAvailable::Read(message, | |
146 &autofill_param)) | |
147 return false; | |
148 if (predictions) | |
149 *predictions = std::get<0>(autofill_param); | |
150 | |
151 process()->sink().ClearMessages(); | |
152 return true; | |
153 } | |
154 | |
155 // Searches for a message matching |messageID| in the queue of sent IPC | |
156 // messages. If none is present, returns false. Otherwise, extracts the first | |
157 // matching message, fills the output parameter with the string16 from the | |
158 // message's parameter, and clears the queue of sent messages. | |
159 bool GetString16FromMessageWithID(uint32_t messageID, base::string16* value) { | |
160 const IPC::Message* message = | |
161 process()->sink().GetFirstMessageMatching(messageID); | |
162 if (!message) | |
163 return false; | |
164 std::tuple<base::string16> autofill_param; | |
165 switch (messageID) { | |
166 case AutofillMsg_FillFieldWithValue::ID: | |
167 if (!AutofillMsg_FillFieldWithValue::Read(message, &autofill_param)) | |
168 return false; | |
169 break; | |
170 case AutofillMsg_PreviewFieldWithValue::ID: | |
171 if (!AutofillMsg_PreviewFieldWithValue::Read(message, &autofill_param)) | |
172 return false; | |
173 break; | |
174 case AutofillMsg_AcceptDataListSuggestion::ID: | |
175 if (!AutofillMsg_AcceptDataListSuggestion::Read(message, | |
176 &autofill_param)) | |
177 return false; | |
178 break; | |
179 default: | |
180 NOTREACHED(); | |
181 } | |
182 if (value) | |
183 *value = std::get<0>(autofill_param); | |
184 process()->sink().ClearMessages(); | |
185 return true; | |
186 } | |
187 | |
188 // Searches for a message matching |messageID| in the queue of sent IPC | |
189 // messages. If none is present, returns false. Otherwise, clears the queue | |
190 // of sent messages and returns true. | |
191 bool HasMessageMatchingID(uint32_t messageID) { | |
192 const IPC::Message* message = | |
193 process()->sink().GetFirstMessageMatching(messageID); | |
194 if (!message) | |
195 return false; | |
196 process()->sink().ClearMessages(); | |
197 return true; | |
198 } | |
199 | |
200 std::unique_ptr<TestAutofillClient> test_autofill_client_; | 284 std::unique_ptr<TestAutofillClient> test_autofill_client_; |
201 std::unique_ptr<TestContentAutofillDriver> driver_; | 285 std::unique_ptr<TestContentAutofillDriver> driver_; |
286 | |
287 FakeAutofillAgent fake_agent_; | |
202 }; | 288 }; |
203 | 289 |
204 TEST_F(ContentAutofillDriverTest, GetURLRequestContext) { | 290 TEST_F(ContentAutofillDriverTest, GetURLRequestContext) { |
205 net::URLRequestContextGetter* request_context = | 291 net::URLRequestContextGetter* request_context = |
206 driver_->GetURLRequestContext(); | 292 driver_->GetURLRequestContext(); |
207 net::URLRequestContextGetter* expected_request_context = | 293 net::URLRequestContextGetter* expected_request_context = |
208 content::BrowserContext::GetDefaultStoragePartition( | 294 content::BrowserContext::GetDefaultStoragePartition( |
209 web_contents()->GetBrowserContext())->GetURLRequestContext(); | 295 web_contents()->GetBrowserContext())->GetURLRequestContext(); |
210 EXPECT_EQ(request_context, expected_request_context); | 296 EXPECT_EQ(request_context, expected_request_context); |
211 } | 297 } |
(...skipping 14 matching lines...) Expand all Loading... | |
226 details.is_main_frame = false; | 312 details.is_main_frame = false; |
227 ASSERT_TRUE(!details.is_navigation_to_different_page()); | 313 ASSERT_TRUE(!details.is_navigation_to_different_page()); |
228 content::FrameNavigateParams params = content::FrameNavigateParams(); | 314 content::FrameNavigateParams params = content::FrameNavigateParams(); |
229 driver_->DidNavigateFrame(details, params); | 315 driver_->DidNavigateFrame(details, params); |
230 } | 316 } |
231 | 317 |
232 TEST_F(ContentAutofillDriverTest, FormDataSentToRenderer_FillForm) { | 318 TEST_F(ContentAutofillDriverTest, FormDataSentToRenderer_FillForm) { |
233 int input_page_id = 42; | 319 int input_page_id = 42; |
234 FormData input_form_data; | 320 FormData input_form_data; |
235 test::CreateTestAddressFormData(&input_form_data); | 321 test::CreateTestAddressFormData(&input_form_data); |
322 base::RunLoop run_loop; | |
323 fake_agent_.SetQuitLoopClosure(run_loop.QuitClosure()); | |
236 driver_->SendFormDataToRenderer( | 324 driver_->SendFormDataToRenderer( |
237 input_page_id, AutofillDriver::FORM_DATA_ACTION_FILL, input_form_data); | 325 input_page_id, AutofillDriver::FORM_DATA_ACTION_FILL, input_form_data); |
238 | 326 |
327 run_loop.RunUntilIdle(); | |
yzshen1
2016/06/29 22:25:44
Shouldn't we use run_loop.Run() here (and below)?
leonhsl(Using Gerrit)
2016/06/29 23:28:34
Inside driver->SendFormDataToRenderer() and some o
yzshen1
2016/06/30 16:58:17
Hmm.. This is a good question. We don't have a way
Ken Rockot(use gerrit already)
2016/06/30 17:03:23
I agree that RunUntilIdle() is generally bad, but
| |
328 | |
239 int output_page_id = 0; | 329 int output_page_id = 0; |
240 FormData output_form_data; | 330 FormData output_form_data; |
241 EXPECT_FALSE( | 331 EXPECT_FALSE(fake_agent_.GetAutofillPreviewFormMessage(&output_page_id, |
242 GetAutofillPreviewFormMessage(&output_page_id, &output_form_data)); | 332 &output_form_data)); |
243 EXPECT_TRUE(GetAutofillFillFormMessage(&output_page_id, &output_form_data)); | 333 EXPECT_TRUE(fake_agent_.GetAutofillFillFormMessage(&output_page_id, |
334 &output_form_data)); | |
244 EXPECT_EQ(input_page_id, output_page_id); | 335 EXPECT_EQ(input_page_id, output_page_id); |
245 EXPECT_TRUE(input_form_data.SameFormAs(output_form_data)); | 336 EXPECT_TRUE(input_form_data.SameFormAs(output_form_data)); |
246 } | 337 } |
247 | 338 |
248 TEST_F(ContentAutofillDriverTest, FormDataSentToRenderer_PreviewForm) { | 339 TEST_F(ContentAutofillDriverTest, FormDataSentToRenderer_PreviewForm) { |
249 int input_page_id = 42; | 340 int input_page_id = 42; |
250 FormData input_form_data; | 341 FormData input_form_data; |
251 test::CreateTestAddressFormData(&input_form_data); | 342 test::CreateTestAddressFormData(&input_form_data); |
343 base::RunLoop run_loop; | |
344 fake_agent_.SetQuitLoopClosure(run_loop.QuitClosure()); | |
252 driver_->SendFormDataToRenderer( | 345 driver_->SendFormDataToRenderer( |
253 input_page_id, AutofillDriver::FORM_DATA_ACTION_PREVIEW, input_form_data); | 346 input_page_id, AutofillDriver::FORM_DATA_ACTION_PREVIEW, input_form_data); |
254 | 347 |
348 run_loop.RunUntilIdle(); | |
349 | |
255 int output_page_id = 0; | 350 int output_page_id = 0; |
256 FormData output_form_data; | 351 FormData output_form_data; |
257 EXPECT_FALSE(GetAutofillFillFormMessage(&output_page_id, &output_form_data)); | 352 EXPECT_FALSE(fake_agent_.GetAutofillFillFormMessage(&output_page_id, |
258 EXPECT_TRUE( | 353 &output_form_data)); |
259 GetAutofillPreviewFormMessage(&output_page_id, &output_form_data)); | 354 EXPECT_TRUE(fake_agent_.GetAutofillPreviewFormMessage(&output_page_id, |
355 &output_form_data)); | |
260 EXPECT_EQ(input_page_id, output_page_id); | 356 EXPECT_EQ(input_page_id, output_page_id); |
261 EXPECT_TRUE(input_form_data.SameFormAs(output_form_data)); | 357 EXPECT_TRUE(input_form_data.SameFormAs(output_form_data)); |
262 } | 358 } |
263 | 359 |
264 TEST_F(ContentAutofillDriverTest, | 360 TEST_F(ContentAutofillDriverTest, |
265 TypePredictionsNotSentToRendererWhenDisabled) { | 361 TypePredictionsNotSentToRendererWhenDisabled) { |
266 FormData form; | 362 FormData form; |
267 test::CreateTestAddressFormData(&form); | 363 test::CreateTestAddressFormData(&form); |
268 FormStructure form_structure(form); | 364 FormStructure form_structure(form); |
269 std::vector<FormStructure*> forms(1, &form_structure); | 365 std::vector<FormStructure*> forms(1, &form_structure); |
366 | |
367 base::RunLoop run_loop; | |
368 fake_agent_.SetQuitLoopClosure(run_loop.QuitClosure()); | |
270 driver_->SendAutofillTypePredictionsToRenderer(forms); | 369 driver_->SendAutofillTypePredictionsToRenderer(forms); |
271 EXPECT_FALSE(GetFieldTypePredictionsAvailable(NULL)); | 370 run_loop.RunUntilIdle(); |
371 | |
372 EXPECT_FALSE(fake_agent_.GetFieldTypePredictionsAvailable(NULL)); | |
272 } | 373 } |
273 | 374 |
274 TEST_F(ContentAutofillDriverTest, TypePredictionsSentToRendererWhenEnabled) { | 375 TEST_F(ContentAutofillDriverTest, TypePredictionsSentToRendererWhenEnabled) { |
275 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 376 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
276 switches::kShowAutofillTypePredictions); | 377 switches::kShowAutofillTypePredictions); |
277 | 378 |
278 FormData form; | 379 FormData form; |
279 test::CreateTestAddressFormData(&form); | 380 test::CreateTestAddressFormData(&form); |
280 FormStructure form_structure(form); | 381 FormStructure form_structure(form); |
281 std::vector<FormStructure*> forms(1, &form_structure); | 382 std::vector<FormStructure*> forms(1, &form_structure); |
282 std::vector<FormDataPredictions> expected_type_predictions = | 383 std::vector<FormDataPredictions> expected_type_predictions = |
283 FormStructure::GetFieldTypePredictions(forms); | 384 FormStructure::GetFieldTypePredictions(forms); |
385 | |
386 base::RunLoop run_loop; | |
387 fake_agent_.SetQuitLoopClosure(run_loop.QuitClosure()); | |
284 driver_->SendAutofillTypePredictionsToRenderer(forms); | 388 driver_->SendAutofillTypePredictionsToRenderer(forms); |
389 run_loop.RunUntilIdle(); | |
285 | 390 |
286 std::vector<FormDataPredictions> output_type_predictions; | 391 std::vector<FormDataPredictions> output_type_predictions; |
287 EXPECT_TRUE(GetFieldTypePredictionsAvailable(&output_type_predictions)); | 392 EXPECT_TRUE( |
393 fake_agent_.GetFieldTypePredictionsAvailable(&output_type_predictions)); | |
288 EXPECT_EQ(expected_type_predictions, output_type_predictions); | 394 EXPECT_EQ(expected_type_predictions, output_type_predictions); |
289 } | 395 } |
290 | 396 |
291 TEST_F(ContentAutofillDriverTest, AcceptDataListSuggestion) { | 397 TEST_F(ContentAutofillDriverTest, AcceptDataListSuggestion) { |
292 base::string16 input_value(base::ASCIIToUTF16("barfoo")); | 398 base::string16 input_value(base::ASCIIToUTF16("barfoo")); |
293 base::string16 output_value; | 399 base::string16 output_value; |
400 | |
401 base::RunLoop run_loop; | |
402 fake_agent_.SetQuitLoopClosure(run_loop.QuitClosure()); | |
294 driver_->RendererShouldAcceptDataListSuggestion(input_value); | 403 driver_->RendererShouldAcceptDataListSuggestion(input_value); |
295 EXPECT_TRUE(GetString16FromMessageWithID( | 404 run_loop.RunUntilIdle(); |
296 AutofillMsg_AcceptDataListSuggestion::ID, &output_value)); | 405 |
406 EXPECT_TRUE(fake_agent_.GetString16AcceptDataListSuggestion(&output_value)); | |
297 EXPECT_EQ(input_value, output_value); | 407 EXPECT_EQ(input_value, output_value); |
298 } | 408 } |
299 | 409 |
300 TEST_F(ContentAutofillDriverTest, ClearFilledFormSentToRenderer) { | 410 TEST_F(ContentAutofillDriverTest, ClearFilledFormSentToRenderer) { |
411 base::RunLoop run_loop; | |
412 fake_agent_.SetQuitLoopClosure(run_loop.QuitClosure()); | |
301 driver_->RendererShouldClearFilledForm(); | 413 driver_->RendererShouldClearFilledForm(); |
302 EXPECT_TRUE(HasMessageMatchingID(AutofillMsg_ClearForm::ID)); | 414 run_loop.RunUntilIdle(); |
415 | |
416 EXPECT_TRUE(fake_agent_.GetCalledClearForm()); | |
303 } | 417 } |
304 | 418 |
305 TEST_F(ContentAutofillDriverTest, ClearPreviewedFormSentToRenderer) { | 419 TEST_F(ContentAutofillDriverTest, ClearPreviewedFormSentToRenderer) { |
420 base::RunLoop run_loop; | |
421 fake_agent_.SetQuitLoopClosure(run_loop.QuitClosure()); | |
306 driver_->RendererShouldClearPreviewedForm(); | 422 driver_->RendererShouldClearPreviewedForm(); |
307 EXPECT_TRUE(HasMessageMatchingID(AutofillMsg_ClearPreviewedForm::ID)); | 423 run_loop.RunUntilIdle(); |
424 | |
425 EXPECT_TRUE(fake_agent_.GetCalledClearPreviewedForm()); | |
308 } | 426 } |
309 | 427 |
310 TEST_F(ContentAutofillDriverTest, FillFieldWithValue) { | 428 TEST_F(ContentAutofillDriverTest, FillFieldWithValue) { |
311 base::string16 input_value(base::ASCIIToUTF16("barqux")); | 429 base::string16 input_value(base::ASCIIToUTF16("barqux")); |
312 base::string16 output_value; | 430 base::string16 output_value; |
313 | 431 |
432 base::RunLoop run_loop; | |
433 fake_agent_.SetQuitLoopClosure(run_loop.QuitClosure()); | |
314 driver_->RendererShouldFillFieldWithValue(input_value); | 434 driver_->RendererShouldFillFieldWithValue(input_value); |
315 EXPECT_TRUE(GetString16FromMessageWithID(AutofillMsg_FillFieldWithValue::ID, | 435 run_loop.RunUntilIdle(); |
316 &output_value)); | 436 |
437 EXPECT_TRUE(fake_agent_.GetString16FillFieldWithValue(&output_value)); | |
317 EXPECT_EQ(input_value, output_value); | 438 EXPECT_EQ(input_value, output_value); |
318 } | 439 } |
319 | 440 |
320 TEST_F(ContentAutofillDriverTest, PreviewFieldWithValue) { | 441 TEST_F(ContentAutofillDriverTest, PreviewFieldWithValue) { |
321 base::string16 input_value(base::ASCIIToUTF16("barqux")); | 442 base::string16 input_value(base::ASCIIToUTF16("barqux")); |
322 base::string16 output_value; | 443 base::string16 output_value; |
444 | |
445 base::RunLoop run_loop; | |
446 fake_agent_.SetQuitLoopClosure(run_loop.QuitClosure()); | |
323 driver_->RendererShouldPreviewFieldWithValue(input_value); | 447 driver_->RendererShouldPreviewFieldWithValue(input_value); |
324 EXPECT_TRUE(GetString16FromMessageWithID( | 448 run_loop.RunUntilIdle(); |
325 AutofillMsg_PreviewFieldWithValue::ID, | 449 |
326 &output_value)); | 450 EXPECT_TRUE(fake_agent_.GetString16PreviewFieldWithValue(&output_value)); |
327 EXPECT_EQ(input_value, output_value); | 451 EXPECT_EQ(input_value, output_value); |
328 } | 452 } |
329 | 453 |
330 } // namespace autofill | 454 } // namespace autofill |
OLD | NEW |