OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
11 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 12 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
12 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 13 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
13 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | 14 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
| 15 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" |
14 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h" | 16 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h" |
15 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
| 20 #include "chrome/test/base/ui_test_utils.h" |
18 #include "components/autofill/browser/autofill_common_test.h" | 21 #include "components/autofill/browser/autofill_common_test.h" |
19 #include "components/autofill/browser/autofill_metrics.h" | 22 #include "components/autofill/browser/autofill_metrics.h" |
20 #include "components/autofill/browser/test_personal_data_manager.h" | 23 #include "components/autofill/browser/test_personal_data_manager.h" |
21 #include "components/autofill/browser/validation.h" | 24 #include "components/autofill/browser/validation.h" |
22 #include "components/autofill/content/browser/wallet/wallet_test_util.h" | 25 #include "components/autofill/content/browser/wallet/wallet_test_util.h" |
23 #include "components/autofill/core/common/autofill_switches.h" | 26 #include "components/autofill/core/common/autofill_switches.h" |
24 #include "components/autofill/core/common/form_data.h" | 27 #include "components/autofill/core/common/form_data.h" |
25 #include "components/autofill/core/common/form_field_data.h" | 28 #include "components/autofill/core/common/form_field_data.h" |
| 29 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/browser/web_contents_delegate.h" |
| 32 #include "content/public/test/browser_test_utils.h" |
26 #include "content/public/test/test_utils.h" | 33 #include "content/public/test/test_utils.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "third_party/WebKit/public/web/WebInputEvent.h" |
28 | 36 |
29 namespace autofill { | 37 namespace autofill { |
30 | 38 |
31 namespace { | 39 namespace { |
32 | 40 |
33 void MockCallback(const FormStructure*, const std::string&) {} | 41 void MockCallback(const FormStructure*, const std::string&) {} |
34 | 42 |
35 class MockAutofillMetrics : public AutofillMetrics { | 43 class MockAutofillMetrics : public AutofillMetrics { |
36 public: | 44 public: |
37 MockAutofillMetrics() | 45 MockAutofillMetrics() |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 return browser()->tab_strip_model()->GetActiveWebContents(); | 202 return browser()->tab_strip_model()->GetActiveWebContents(); |
195 } | 203 } |
196 | 204 |
197 const MockAutofillMetrics& metric_logger() { return metric_logger_; } | 205 const MockAutofillMetrics& metric_logger() { return metric_logger_; } |
198 TestAutofillDialogController* controller() { return controller_; } | 206 TestAutofillDialogController* controller() { return controller_; } |
199 | 207 |
200 void RunMessageLoop() { | 208 void RunMessageLoop() { |
201 message_loop_runner_->Run(); | 209 message_loop_runner_->Run(); |
202 } | 210 } |
203 | 211 |
| 212 // Loads an HTML page in |GetActiveWebContents()| with markup as follows: |
| 213 // <form>|form_inner_html|</form>. After loading, emulates a click event on |
| 214 // the page as requestAutocomplete() must be in response to a user gesture. |
| 215 // Returns the |AutofillDialogControllerImpl| created by this invocation. |
| 216 AutofillDialogControllerImpl* SetUpHtmlAndInvoke( |
| 217 const std::string& form_inner_html) { |
| 218 content::WebContents* contents = GetActiveWebContents(); |
| 219 TabAutofillManagerDelegate* delegate = |
| 220 TabAutofillManagerDelegate::FromWebContents(contents); |
| 221 DCHECK(!delegate->GetDialogControllerForTesting()); |
| 222 |
| 223 ui_test_utils::NavigateToURL( |
| 224 browser(), GURL(std::string("data:text/html,") + |
| 225 "<!doctype html>" |
| 226 "<html>" |
| 227 "<body>" |
| 228 "<form>" + form_inner_html + "</form>" |
| 229 "<script>" |
| 230 "function send(msg) {" |
| 231 "domAutomationController.setAutomationId(0);" |
| 232 "domAutomationController.send(msg);" |
| 233 "}" |
| 234 "document.forms[0].onautocompleteerror = function(e) {" |
| 235 "send('error: ' + e.reason);" |
| 236 "};" |
| 237 "document.forms[0].onautocomplete = function() {" |
| 238 "send('success');" |
| 239 "};" |
| 240 "window.onclick = function() {" |
| 241 "document.forms[0].requestAutocomplete();" |
| 242 "send('clicked');" |
| 243 "};" |
| 244 "</script>" |
| 245 "</body>" |
| 246 "</html>")); |
| 247 content::WaitForLoadStop(contents); |
| 248 |
| 249 dom_message_queue_.reset(new content::DOMMessageQueue); |
| 250 |
| 251 // Triggers the onclick handler which invokes requestAutocomplete(). |
| 252 content::SimulateMouseClick(contents, 0, WebKit::WebMouseEvent::ButtonLeft); |
| 253 ExpectDomMessage("clicked"); |
| 254 |
| 255 AutofillDialogControllerImpl* controller = |
| 256 delegate->GetDialogControllerForTesting(); |
| 257 DCHECK(controller); |
| 258 return controller; |
| 259 } |
| 260 |
| 261 // Wait for a message from the DOM automation controller (from JS in the |
| 262 // page). Requires |SetUpHtmlAndInvoke()| be called first. |
| 263 void ExpectDomMessage(const std::string& expected) { |
| 264 std::string message; |
| 265 ASSERT_TRUE(dom_message_queue_->WaitForMessage(&message)); |
| 266 dom_message_queue_->ClearQueue(); |
| 267 EXPECT_EQ("\"" + expected + "\"", message); |
| 268 } |
| 269 |
| 270 void AddCreditcardToProfile(Profile* profile, const CreditCard& card) { |
| 271 PersonalDataManagerFactory::GetForProfile(profile)->AddCreditCard(card); |
| 272 WaitForWebDB(); |
| 273 } |
| 274 |
| 275 void AddAutofillProfileToProfile(Profile* profile, |
| 276 const AutofillProfile& autofill_profile) { |
| 277 PersonalDataManagerFactory::GetForProfile(profile)->AddProfile( |
| 278 autofill_profile); |
| 279 WaitForWebDB(); |
| 280 } |
| 281 |
| 282 void WaitForWebDB() { |
| 283 content::RunAllPendingInMessageLoop(content::BrowserThread::DB); |
| 284 } |
| 285 |
204 private: | 286 private: |
205 MockAutofillMetrics metric_logger_; | 287 MockAutofillMetrics metric_logger_; |
206 TestAutofillDialogController* controller_; // Weak reference. | 288 TestAutofillDialogController* controller_; // Weak reference. |
207 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 289 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 290 scoped_ptr<content::DOMMessageQueue> dom_message_queue_; |
208 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); | 291 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); |
209 }; | 292 }; |
210 | 293 |
211 // TODO(isherman): Enable these tests on other platforms once the UI is | 294 // TODO(isherman): Enable these tests on other platforms once the UI is |
212 // implemented on those platforms. | 295 // implemented on those platforms. |
213 #if defined(TOOLKIT_VIEWS) | 296 #if defined(TOOLKIT_VIEWS) |
214 // Submit the form data. | 297 // Submit the form data. |
215 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Submit) { | 298 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Submit) { |
216 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); | 299 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); |
217 controller()->view()->GetTestableView()->SubmitForTesting(); | 300 controller()->GetTestableView()->SubmitForTesting(); |
218 | 301 |
219 RunMessageLoop(); | 302 RunMessageLoop(); |
220 | 303 |
221 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, | 304 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, |
222 metric_logger().dialog_dismissal_action()); | 305 metric_logger().dialog_dismissal_action()); |
223 EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger().dialog_type()); | 306 EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger().dialog_type()); |
224 } | 307 } |
225 | 308 |
226 // Cancel out of the dialog. | 309 // Cancel out of the dialog. |
227 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Cancel) { | 310 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Cancel) { |
228 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); | 311 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); |
229 controller()->view()->GetTestableView()->CancelForTesting(); | 312 controller()->GetTestableView()->CancelForTesting(); |
230 | 313 |
231 RunMessageLoop(); | 314 RunMessageLoop(); |
232 | 315 |
233 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, | 316 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, |
234 metric_logger().dialog_dismissal_action()); | 317 metric_logger().dialog_dismissal_action()); |
235 EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger().dialog_type()); | 318 EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger().dialog_type()); |
236 } | 319 } |
237 | 320 |
238 // Take some other action that dismisses the dialog. | 321 // Take some other action that dismisses the dialog. |
239 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Hide) { | 322 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Hide) { |
240 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); | 323 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); |
241 controller()->Hide(); | 324 controller()->Hide(); |
242 | 325 |
243 RunMessageLoop(); | 326 RunMessageLoop(); |
244 | 327 |
245 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, | 328 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, |
246 metric_logger().dialog_dismissal_action()); | 329 metric_logger().dialog_dismissal_action()); |
247 EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger().dialog_type()); | 330 EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger().dialog_type()); |
248 } | 331 } |
249 | 332 |
250 // Test Autocheckout success metrics. | 333 // Test Autocheckout success metrics. |
251 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutSuccess) { | 334 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutSuccess) { |
252 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); | 335 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); |
253 controller()->view()->GetTestableView()->SubmitForTesting(); | 336 controller()->GetTestableView()->SubmitForTesting(); |
254 | 337 |
255 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, | 338 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, |
256 metric_logger().dialog_dismissal_action()); | 339 metric_logger().dialog_dismissal_action()); |
257 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); | 340 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); |
258 | 341 |
259 controller()->OnAutocheckoutSuccess(); | 342 controller()->OnAutocheckoutSuccess(); |
260 controller()->view()->GetTestableView()->CancelForTesting(); | 343 controller()->GetTestableView()->CancelForTesting(); |
261 RunMessageLoop(); | 344 RunMessageLoop(); |
262 | 345 |
263 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_SUCCEEDED, | 346 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_SUCCEEDED, |
264 metric_logger().autocheckout_status()); | 347 metric_logger().autocheckout_status()); |
265 | 348 |
266 // Ensure closing the dialog doesn't fire any new metrics. | 349 // Ensure closing the dialog doesn't fire any new metrics. |
267 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, | 350 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, |
268 metric_logger().dialog_dismissal_action()); | 351 metric_logger().dialog_dismissal_action()); |
269 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); | 352 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); |
270 } | 353 } |
271 | 354 |
272 // Test Autocheckout failure metric. | 355 // Test Autocheckout failure metric. |
273 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutError) { | 356 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutError) { |
274 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); | 357 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); |
275 controller()->view()->GetTestableView()->SubmitForTesting(); | 358 controller()->GetTestableView()->SubmitForTesting(); |
276 | 359 |
277 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, | 360 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, |
278 metric_logger().dialog_dismissal_action()); | 361 metric_logger().dialog_dismissal_action()); |
279 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); | 362 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); |
280 | 363 |
281 controller()->OnAutocheckoutError(); | 364 controller()->OnAutocheckoutError(); |
282 controller()->view()->GetTestableView()->CancelForTesting(); | 365 controller()->GetTestableView()->CancelForTesting(); |
283 RunMessageLoop(); | 366 RunMessageLoop(); |
284 | 367 |
285 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_FAILED, | 368 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_FAILED, |
286 metric_logger().autocheckout_status()); | 369 metric_logger().autocheckout_status()); |
287 | 370 |
288 // Ensure closing the dialog doesn't fire any new metrics. | 371 // Ensure closing the dialog doesn't fire any new metrics. |
289 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, | 372 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, |
290 metric_logger().dialog_dismissal_action()); | 373 metric_logger().dialog_dismissal_action()); |
291 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); | 374 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); |
292 } | 375 } |
293 | 376 |
294 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutCancelled) { | 377 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutCancelled) { |
295 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); | 378 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); |
296 controller()->view()->GetTestableView()->SubmitForTesting(); | 379 controller()->GetTestableView()->SubmitForTesting(); |
297 | 380 |
298 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, | 381 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, |
299 metric_logger().dialog_dismissal_action()); | 382 metric_logger().dialog_dismissal_action()); |
300 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); | 383 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); |
301 | 384 |
302 controller()->view()->GetTestableView()->CancelForTesting(); | 385 controller()->GetTestableView()->CancelForTesting(); |
303 RunMessageLoop(); | 386 RunMessageLoop(); |
304 | 387 |
305 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_CANCELLED, | 388 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_CANCELLED, |
306 metric_logger().autocheckout_status()); | 389 metric_logger().autocheckout_status()); |
307 | 390 |
308 // Ensure closing the dialog doesn't fire any new metrics. | 391 // Ensure closing the dialog doesn't fire any new metrics. |
309 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, | 392 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, |
310 metric_logger().dialog_dismissal_action()); | 393 metric_logger().dialog_dismissal_action()); |
311 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); | 394 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); |
312 } | 395 } |
313 | 396 |
314 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) { | 397 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) { |
315 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); | 398 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); |
316 controller()->DisableWallet(wallet::WalletClient::UNKNOWN_ERROR); | 399 controller()->DisableWallet(wallet::WalletClient::UNKNOWN_ERROR); |
317 | 400 |
318 AutofillProfile full_profile(test::GetFullProfile()); | 401 AutofillProfile full_profile(test::GetFullProfile()); |
319 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 402 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
320 | 403 |
321 const DetailInputs& inputs = | 404 const DetailInputs& inputs = |
322 controller()->RequestedFieldsForSection(SECTION_SHIPPING); | 405 controller()->RequestedFieldsForSection(SECTION_SHIPPING); |
323 const DetailInput& triggering_input = inputs[0]; | 406 const DetailInput& triggering_input = inputs[0]; |
324 string16 value = full_profile.GetRawInfo(triggering_input.type); | 407 string16 value = full_profile.GetRawInfo(triggering_input.type); |
325 TestableAutofillDialogView* view = controller()->view()->GetTestableView(); | 408 TestableAutofillDialogView* view = controller()->GetTestableView(); |
326 view->SetTextContentsOfInput(triggering_input, | 409 view->SetTextContentsOfInput(triggering_input, |
327 value.substr(0, value.size() / 2)); | 410 value.substr(0, value.size() / 2)); |
328 view->ActivateInput(triggering_input); | 411 view->ActivateInput(triggering_input); |
329 | 412 |
330 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); | 413 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); |
331 controller()->DidAcceptSuggestion(string16(), 0); | 414 controller()->DidAcceptSuggestion(string16(), 0); |
332 | 415 |
333 // All inputs should be filled. | 416 // All inputs should be filled. |
334 AutofillProfileWrapper wrapper(&full_profile, 0); | 417 AutofillProfileWrapper wrapper(&full_profile, 0); |
335 for (size_t i = 0; i < inputs.size(); ++i) { | 418 for (size_t i = 0; i < inputs.size(); ++i) { |
(...skipping 26 matching lines...) Expand all Loading... |
362 } | 445 } |
363 | 446 |
364 // Test that the Autocheckout progress bar is showing after submitting the | 447 // Test that the Autocheckout progress bar is showing after submitting the |
365 // dialog for controller with type DIALOG_TYPE_AUTOCHECKOUT. | 448 // dialog for controller with type DIALOG_TYPE_AUTOCHECKOUT. |
366 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, | 449 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, |
367 AutocheckoutShowsProgressBar) { | 450 AutocheckoutShowsProgressBar) { |
368 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); | 451 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); |
369 EXPECT_TRUE(controller()->ShouldShowDetailArea()); | 452 EXPECT_TRUE(controller()->ShouldShowDetailArea()); |
370 EXPECT_FALSE(controller()->ShouldShowProgressBar()); | 453 EXPECT_FALSE(controller()->ShouldShowProgressBar()); |
371 | 454 |
372 controller()->view()->GetTestableView()->SubmitForTesting(); | 455 controller()->GetTestableView()->SubmitForTesting(); |
373 EXPECT_FALSE(controller()->ShouldShowDetailArea()); | 456 EXPECT_FALSE(controller()->ShouldShowDetailArea()); |
374 EXPECT_TRUE(controller()->ShouldShowProgressBar()); | 457 EXPECT_TRUE(controller()->ShouldShowProgressBar()); |
375 } | 458 } |
376 | 459 |
377 // Test that the Autocheckout progress bar is not showing after submitting the | 460 // Test that the Autocheckout progress bar is not showing after submitting the |
378 // dialog for controller with type DIALOG_TYPE_REQUEST_AUTOCOMPLETE. | 461 // dialog for controller with type DIALOG_TYPE_REQUEST_AUTOCOMPLETE. |
379 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, | 462 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, |
380 RequestAutocompleteDoesntShowProgressBar) { | 463 RequestAutocompleteDoesntShowProgressBar) { |
381 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); | 464 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); |
382 EXPECT_TRUE(controller()->ShouldShowDetailArea()); | 465 EXPECT_TRUE(controller()->ShouldShowDetailArea()); |
383 EXPECT_FALSE(controller()->ShouldShowProgressBar()); | 466 EXPECT_FALSE(controller()->ShouldShowProgressBar()); |
384 | 467 |
385 controller()->view()->GetTestableView()->SubmitForTesting(); | 468 controller()->GetTestableView()->SubmitForTesting(); |
386 EXPECT_TRUE(controller()->ShouldShowDetailArea()); | 469 EXPECT_TRUE(controller()->ShouldShowDetailArea()); |
387 EXPECT_FALSE(controller()->ShouldShowProgressBar()); | 470 EXPECT_FALSE(controller()->ShouldShowProgressBar()); |
388 } | 471 } |
389 | 472 |
390 // Tests that changing the value of a CC expiration date combobox works as | 473 // Tests that changing the value of a CC expiration date combobox works as |
391 // expected when Autofill is used to fill text inputs. | 474 // expected when Autofill is used to fill text inputs. |
392 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillComboboxFromAutofill) { | 475 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillComboboxFromAutofill) { |
393 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); | 476 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); |
394 controller()->DisableWallet(wallet::WalletClient::UNKNOWN_ERROR); | 477 controller()->DisableWallet(wallet::WalletClient::UNKNOWN_ERROR); |
395 | 478 |
396 CreditCard card1; | 479 CreditCard card1; |
397 test::SetCreditCardInfo(&card1, "JJ Smith", "4111111111111111", "12", "2018"); | 480 test::SetCreditCardInfo(&card1, "JJ Smith", "4111111111111111", "12", "2018"); |
398 controller()->GetTestingManager()->AddTestingCreditCard(&card1); | 481 controller()->GetTestingManager()->AddTestingCreditCard(&card1); |
399 CreditCard card2; | 482 CreditCard card2; |
400 test::SetCreditCardInfo(&card2, "B Bird", "3111111111111111", "11", "2017"); | 483 test::SetCreditCardInfo(&card2, "B Bird", "3111111111111111", "11", "2017"); |
401 controller()->GetTestingManager()->AddTestingCreditCard(&card2); | 484 controller()->GetTestingManager()->AddTestingCreditCard(&card2); |
402 AutofillProfile full_profile(test::GetFullProfile()); | 485 AutofillProfile full_profile(test::GetFullProfile()); |
403 controller()->GetTestingManager()->AddTestingProfile(&full_profile); | 486 controller()->GetTestingManager()->AddTestingProfile(&full_profile); |
404 | 487 |
405 const DetailInputs& inputs = | 488 const DetailInputs& inputs = |
406 controller()->RequestedFieldsForSection(SECTION_CC); | 489 controller()->RequestedFieldsForSection(SECTION_CC); |
407 const DetailInput& triggering_input = inputs[0]; | 490 const DetailInput& triggering_input = inputs[0]; |
408 string16 value = card1.GetRawInfo(triggering_input.type); | 491 string16 value = card1.GetRawInfo(triggering_input.type); |
409 TestableAutofillDialogView* view = controller()->view()->GetTestableView(); | 492 TestableAutofillDialogView* view = controller()->GetTestableView(); |
410 view->SetTextContentsOfInput(triggering_input, | 493 view->SetTextContentsOfInput(triggering_input, |
411 value.substr(0, value.size() / 2)); | 494 value.substr(0, value.size() / 2)); |
412 view->ActivateInput(triggering_input); | 495 view->ActivateInput(triggering_input); |
413 | 496 |
414 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); | 497 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); |
415 controller()->DidAcceptSuggestion(string16(), 0); | 498 controller()->DidAcceptSuggestion(string16(), 0); |
416 | 499 |
417 // All inputs should be filled. | 500 // All inputs should be filled. |
418 AutofillCreditCardWrapper wrapper1(&card1); | 501 AutofillCreditCardWrapper wrapper1(&card1); |
419 for (size_t i = 0; i < inputs.size(); ++i) { | 502 for (size_t i = 0; i < inputs.size(); ++i) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 model->ActivatedAt(1); | 625 model->ActivatedAt(1); |
543 ASSERT_TRUE(model->IsItemCheckedAt(1)); | 626 ASSERT_TRUE(model->IsItemCheckedAt(1)); |
544 EXPECT_TRUE(controller()->IsEditingExistingData(SECTION_CC)); | 627 EXPECT_TRUE(controller()->IsEditingExistingData(SECTION_CC)); |
545 } | 628 } |
546 | 629 |
547 // Notifications with long message text should not make the dialog bigger. | 630 // Notifications with long message text should not make the dialog bigger. |
548 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, LongNotifications) { | 631 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, LongNotifications) { |
549 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); | 632 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); |
550 | 633 |
551 const gfx::Size no_notification_size = | 634 const gfx::Size no_notification_size = |
552 controller()->view()->GetTestableView()->GetSize(); | 635 controller()->GetTestableView()->GetSize(); |
553 ASSERT_GT(no_notification_size.width(), 0); | 636 ASSERT_GT(no_notification_size.width(), 0); |
554 | 637 |
555 std::vector<DialogNotification> notifications; | 638 std::vector<DialogNotification> notifications; |
556 notifications.push_back( | 639 notifications.push_back( |
557 DialogNotification(DialogNotification::DEVELOPER_WARNING, ASCIIToUTF16( | 640 DialogNotification(DialogNotification::DEVELOPER_WARNING, ASCIIToUTF16( |
558 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do " | 641 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do " |
559 "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim " | 642 "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim " |
560 "ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut " | 643 "ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut " |
561 "aliquip ex ea commodo consequat. Duis aute irure dolor in " | 644 "aliquip ex ea commodo consequat. Duis aute irure dolor in " |
562 "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla " | 645 "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla " |
563 "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in " | 646 "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in " |
564 "culpa qui officia deserunt mollit anim id est laborum."))); | 647 "culpa qui officia deserunt mollit anim id est laborum."))); |
565 controller()->set_notifications(notifications); | 648 controller()->set_notifications(notifications); |
566 controller()->view()->UpdateNotificationArea(); | 649 controller()->view()->UpdateNotificationArea(); |
567 | 650 |
568 EXPECT_EQ(no_notification_size.width(), | 651 EXPECT_EQ(no_notification_size.width(), |
569 controller()->view()->GetTestableView()->GetSize().width()); | 652 controller()->GetTestableView()->GetSize().width()); |
| 653 } |
| 654 |
| 655 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocompleteEvent) { |
| 656 AutofillDialogControllerImpl* controller = |
| 657 SetUpHtmlAndInvoke("<input autocomplete='cc-name'>"); |
| 658 |
| 659 AddCreditcardToProfile(controller->profile(), test::GetVerifiedCreditCard()); |
| 660 AddAutofillProfileToProfile(controller->profile(), |
| 661 test::GetVerifiedProfile()); |
| 662 |
| 663 TestableAutofillDialogView* view = controller->GetTestableView(); |
| 664 view->SetTextContentsOfSuggestionInput(SECTION_CC, ASCIIToUTF16("123")); |
| 665 view->SubmitForTesting(); |
| 666 ExpectDomMessage("success"); |
| 667 } |
| 668 |
| 669 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, |
| 670 AutocompleteErrorEventReasonInvalid) { |
| 671 AutofillDialogControllerImpl* controller = |
| 672 SetUpHtmlAndInvoke("<input autocomplete='cc-name' pattern='.*zebra.*'>"); |
| 673 |
| 674 const CreditCard& credit_card = test::GetVerifiedCreditCard(); |
| 675 ASSERT_TRUE( |
| 676 credit_card.GetRawInfo(CREDIT_CARD_NAME).find(ASCIIToUTF16("zebra")) == |
| 677 base::string16::npos); |
| 678 AddCreditcardToProfile(controller->profile(), credit_card); |
| 679 AddAutofillProfileToProfile(controller->profile(), |
| 680 test::GetVerifiedProfile()); |
| 681 |
| 682 TestableAutofillDialogView* view = controller->GetTestableView(); |
| 683 view->SetTextContentsOfSuggestionInput(SECTION_CC, ASCIIToUTF16("123")); |
| 684 view->SubmitForTesting(); |
| 685 ExpectDomMessage("error: invalid"); |
| 686 } |
| 687 |
| 688 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, |
| 689 AutocompleteErrorEventReasonCancel) { |
| 690 SetUpHtmlAndInvoke("<input autocomplete='cc-name'>")->GetTestableView()-> |
| 691 CancelForTesting(); |
| 692 ExpectDomMessage("error: cancel"); |
570 } | 693 } |
571 #endif // defined(TOOLKIT_VIEWS) | 694 #endif // defined(TOOLKIT_VIEWS) |
572 | 695 |
573 } // namespace autofill | 696 } // namespace autofill |
OLD | NEW |