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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc

Issue 17391012: Implement 'invalid' AutocompleteErrorEvent#reason (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/autofill/autofill_dialog_controller_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/content/browser/wallet/wallet_test_util.h" 21 #include "components/autofill/content/browser/wallet/wallet_test_util.h"
19 #include "components/autofill/core/browser/autofill_common_test.h" 22 #include "components/autofill/core/browser/autofill_common_test.h"
20 #include "components/autofill/core/browser/autofill_metrics.h" 23 #include "components/autofill/core/browser/autofill_metrics.h"
21 #include "components/autofill/core/browser/test_personal_data_manager.h" 24 #include "components/autofill/core/browser/test_personal_data_manager.h"
22 #include "components/autofill/core/browser/validation.h" 25 #include "components/autofill/core/browser/validation.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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 return browser()->tab_strip_model()->GetActiveWebContents(); 214 return browser()->tab_strip_model()->GetActiveWebContents();
207 } 215 }
208 216
209 const MockAutofillMetrics& metric_logger() { return metric_logger_; } 217 const MockAutofillMetrics& metric_logger() { return metric_logger_; }
210 TestAutofillDialogController* controller() { return controller_; } 218 TestAutofillDialogController* controller() { return controller_; }
211 219
212 void RunMessageLoop() { 220 void RunMessageLoop() {
213 message_loop_runner_->Run(); 221 message_loop_runner_->Run();
214 } 222 }
215 223
224 // Loads an HTML page in |GetActiveWebContents()| with markup as follows:
225 // <form>|form_inner_html|</form>. After loading, emulates a click event on
226 // the page as requestAutocomplete() must be in response to a user gesture.
227 // Returns the |AutofillDialogControllerImpl| created by this invocation.
228 AutofillDialogControllerImpl* SetUpHtmlAndInvoke(
229 const std::string& form_inner_html) {
230 content::WebContents* contents = GetActiveWebContents();
231 TabAutofillManagerDelegate* delegate =
232 TabAutofillManagerDelegate::FromWebContents(contents);
233 DCHECK(!delegate->GetDialogControllerForTesting());
234
235 ui_test_utils::NavigateToURL(
236 browser(), GURL(std::string("data:text/html,") +
237 "<!doctype html>"
238 "<html>"
239 "<body>"
240 "<form>" + form_inner_html + "</form>"
241 "<script>"
242 "function send(msg) {"
243 "domAutomationController.setAutomationId(0);"
244 "domAutomationController.send(msg);"
245 "}"
246 "document.forms[0].onautocompleteerror = function(e) {"
247 "send('error: ' + e.reason);"
248 "};"
249 "document.forms[0].onautocomplete = function() {"
250 "send('success');"
251 "};"
252 "window.onclick = function() {"
253 "document.forms[0].requestAutocomplete();"
254 "send('clicked');"
255 "};"
256 "</script>"
257 "</body>"
258 "</html>"));
259 content::WaitForLoadStop(contents);
260
261 dom_message_queue_.reset(new content::DOMMessageQueue);
262
263 // Triggers the onclick handler which invokes requestAutocomplete().
264 content::SimulateMouseClick(contents, 0, WebKit::WebMouseEvent::ButtonLeft);
265 ExpectDomMessage("clicked");
266
267 AutofillDialogControllerImpl* controller =
268 delegate->GetDialogControllerForTesting();
269 DCHECK(controller);
270 return controller;
271 }
272
273 // Wait for a message from the DOM automation controller (from JS in the
274 // page). Requires |SetUpHtmlAndInvoke()| be called first.
275 void ExpectDomMessage(const std::string& expected) {
276 std::string message;
277 ASSERT_TRUE(dom_message_queue_->WaitForMessage(&message));
278 dom_message_queue_->ClearQueue();
279 EXPECT_EQ("\"" + expected + "\"", message);
280 }
281
282 void AddCreditcardToProfile(Profile* profile, const CreditCard& card) {
283 PersonalDataManagerFactory::GetForProfile(profile)->AddCreditCard(card);
284 WaitForWebDB();
285 }
286
287 void AddAutofillProfileToProfile(Profile* profile,
288 const AutofillProfile& autofill_profile) {
289 PersonalDataManagerFactory::GetForProfile(profile)->AddProfile(
290 autofill_profile);
291 WaitForWebDB();
292 }
293
294 void WaitForWebDB() {
295 content::RunAllPendingInMessageLoop(content::BrowserThread::DB);
296 }
297
216 private: 298 private:
217 MockAutofillMetrics metric_logger_; 299 MockAutofillMetrics metric_logger_;
218 TestAutofillDialogController* controller_; // Weak reference. 300 TestAutofillDialogController* controller_; // Weak reference.
219 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 301 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
302 scoped_ptr<content::DOMMessageQueue> dom_message_queue_;
220 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); 303 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest);
221 }; 304 };
222 305
223 // TODO(isherman): Enable these tests on other platforms once the UI is 306 // TODO(isherman): Enable these tests on other platforms once the UI is
224 // implemented on those platforms. 307 // implemented on those platforms.
225 #if defined(TOOLKIT_VIEWS) 308 #if defined(TOOLKIT_VIEWS)
226 // Submit the form data. 309 // Submit the form data.
227 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Submit) { 310 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Submit) {
228 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); 311 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE);
229 controller()->view()->GetTestableView()->SubmitForTesting(); 312 controller()->GetTestableView()->SubmitForTesting();
230 313
231 RunMessageLoop(); 314 RunMessageLoop();
232 315
233 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, 316 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED,
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 // Cancel out of the dialog. 321 // Cancel out of the dialog.
239 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Cancel) { 322 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Cancel) {
240 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); 323 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE);
241 controller()->view()->GetTestableView()->CancelForTesting(); 324 controller()->GetTestableView()->CancelForTesting();
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 // Take some other action that dismisses the dialog. 333 // Take some other action that dismisses the dialog.
251 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Hide) { 334 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Hide) {
252 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); 335 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE);
253 controller()->Hide(); 336 controller()->Hide();
254 337
255 RunMessageLoop(); 338 RunMessageLoop();
256 339
257 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, 340 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED,
258 metric_logger().dialog_dismissal_action()); 341 metric_logger().dialog_dismissal_action());
259 EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger().dialog_type()); 342 EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger().dialog_type());
260 } 343 }
261 344
262 // Test Autocheckout success metrics. 345 // Test Autocheckout success metrics.
263 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutSuccess) { 346 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutSuccess) {
264 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); 347 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT);
265 controller()->view()->GetTestableView()->SubmitForTesting(); 348 controller()->GetTestableView()->SubmitForTesting();
266 349
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 controller()->OnAutocheckoutSuccess(); 354 controller()->OnAutocheckoutSuccess();
272 controller()->view()->GetTestableView()->CancelForTesting(); 355 controller()->GetTestableView()->CancelForTesting();
273 RunMessageLoop(); 356 RunMessageLoop();
274 357
275 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_SUCCEEDED, 358 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_SUCCEEDED,
276 metric_logger().autocheckout_status()); 359 metric_logger().autocheckout_status());
277 360
278 // Ensure closing the dialog doesn't fire any new metrics. 361 // Ensure closing the dialog doesn't fire any new metrics.
279 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, 362 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED,
280 metric_logger().dialog_dismissal_action()); 363 metric_logger().dialog_dismissal_action());
281 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); 364 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type());
282 } 365 }
283 366
284 // Test Autocheckout failure metric. 367 // Test Autocheckout failure metric.
285 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutError) { 368 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutError) {
286 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); 369 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT);
287 controller()->view()->GetTestableView()->SubmitForTesting(); 370 controller()->GetTestableView()->SubmitForTesting();
288 371
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 controller()->OnAutocheckoutError(); 376 controller()->OnAutocheckoutError();
294 controller()->view()->GetTestableView()->CancelForTesting(); 377 controller()->GetTestableView()->CancelForTesting();
295 RunMessageLoop(); 378 RunMessageLoop();
296 379
297 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_FAILED, 380 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_FAILED,
298 metric_logger().autocheckout_status()); 381 metric_logger().autocheckout_status());
299 382
300 // Ensure closing the dialog doesn't fire any new metrics. 383 // Ensure closing the dialog doesn't fire any new metrics.
301 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, 384 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED,
302 metric_logger().dialog_dismissal_action()); 385 metric_logger().dialog_dismissal_action());
303 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); 386 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type());
304 } 387 }
305 388
306 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutCancelled) { 389 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocheckoutCancelled) {
307 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); 390 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT);
308 controller()->view()->GetTestableView()->SubmitForTesting(); 391 controller()->GetTestableView()->SubmitForTesting();
309 392
310 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, 393 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED,
311 metric_logger().dialog_dismissal_action()); 394 metric_logger().dialog_dismissal_action());
312 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); 395 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type());
313 396
314 controller()->view()->GetTestableView()->CancelForTesting(); 397 controller()->GetTestableView()->CancelForTesting();
315 RunMessageLoop(); 398 RunMessageLoop();
316 399
317 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_CANCELLED, 400 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_CANCELLED,
318 metric_logger().autocheckout_status()); 401 metric_logger().autocheckout_status());
319 402
320 // Ensure closing the dialog doesn't fire any new metrics. 403 // Ensure closing the dialog doesn't fire any new metrics.
321 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, 404 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED,
322 metric_logger().dialog_dismissal_action()); 405 metric_logger().dialog_dismissal_action());
323 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type()); 406 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger().dialog_type());
324 } 407 }
325 408
326 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) { 409 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillInputFromAutofill) {
327 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); 410 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE);
328 controller()->DisableWallet(wallet::WalletClient::UNKNOWN_ERROR); 411 controller()->DisableWallet(wallet::WalletClient::UNKNOWN_ERROR);
329 412
330 AutofillProfile full_profile(test::GetFullProfile()); 413 AutofillProfile full_profile(test::GetFullProfile());
331 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 414 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
332 415
333 const DetailInputs& inputs = 416 const DetailInputs& inputs =
334 controller()->RequestedFieldsForSection(SECTION_SHIPPING); 417 controller()->RequestedFieldsForSection(SECTION_SHIPPING);
335 const DetailInput& triggering_input = inputs[0]; 418 const DetailInput& triggering_input = inputs[0];
336 string16 value = full_profile.GetRawInfo(triggering_input.type); 419 string16 value = full_profile.GetRawInfo(triggering_input.type);
337 TestableAutofillDialogView* view = controller()->view()->GetTestableView(); 420 TestableAutofillDialogView* view = controller()->GetTestableView();
338 view->SetTextContentsOfInput(triggering_input, 421 view->SetTextContentsOfInput(triggering_input,
339 value.substr(0, value.size() / 2)); 422 value.substr(0, value.size() / 2));
340 view->ActivateInput(triggering_input); 423 view->ActivateInput(triggering_input);
341 424
342 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); 425 ASSERT_EQ(&triggering_input, controller()->input_showing_popup());
343 controller()->DidAcceptSuggestion(string16(), 0); 426 controller()->DidAcceptSuggestion(string16(), 0);
344 427
345 // All inputs should be filled. 428 // All inputs should be filled.
346 AutofillProfileWrapper wrapper(&full_profile, 0); 429 AutofillProfileWrapper wrapper(&full_profile, 0);
347 for (size_t i = 0; i < inputs.size(); ++i) { 430 for (size_t i = 0; i < inputs.size(); ++i) {
(...skipping 26 matching lines...) Expand all
374 } 457 }
375 458
376 // Test that the Autocheckout progress bar is showing after submitting the 459 // Test that the Autocheckout progress bar is showing after submitting the
377 // dialog for controller with type DIALOG_TYPE_AUTOCHECKOUT. 460 // dialog for controller with type DIALOG_TYPE_AUTOCHECKOUT.
378 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, 461 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest,
379 AutocheckoutShowsProgressBar) { 462 AutocheckoutShowsProgressBar) {
380 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT); 463 InitializeControllerOfType(DIALOG_TYPE_AUTOCHECKOUT);
381 EXPECT_TRUE(controller()->ShouldShowDetailArea()); 464 EXPECT_TRUE(controller()->ShouldShowDetailArea());
382 EXPECT_FALSE(controller()->ShouldShowProgressBar()); 465 EXPECT_FALSE(controller()->ShouldShowProgressBar());
383 466
384 controller()->view()->GetTestableView()->SubmitForTesting(); 467 controller()->GetTestableView()->SubmitForTesting();
385 EXPECT_FALSE(controller()->ShouldShowDetailArea()); 468 EXPECT_FALSE(controller()->ShouldShowDetailArea());
386 EXPECT_TRUE(controller()->ShouldShowProgressBar()); 469 EXPECT_TRUE(controller()->ShouldShowProgressBar());
387 } 470 }
388 471
389 // Test that the Autocheckout progress bar is not showing after submitting the 472 // Test that the Autocheckout progress bar is not showing after submitting the
390 // dialog for controller with type DIALOG_TYPE_REQUEST_AUTOCOMPLETE. 473 // dialog for controller with type DIALOG_TYPE_REQUEST_AUTOCOMPLETE.
391 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, 474 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest,
392 RequestAutocompleteDoesntShowProgressBar) { 475 RequestAutocompleteDoesntShowProgressBar) {
393 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); 476 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE);
394 EXPECT_TRUE(controller()->ShouldShowDetailArea()); 477 EXPECT_TRUE(controller()->ShouldShowDetailArea());
395 EXPECT_FALSE(controller()->ShouldShowProgressBar()); 478 EXPECT_FALSE(controller()->ShouldShowProgressBar());
396 479
397 controller()->view()->GetTestableView()->SubmitForTesting(); 480 controller()->GetTestableView()->SubmitForTesting();
398 EXPECT_TRUE(controller()->ShouldShowDetailArea()); 481 EXPECT_TRUE(controller()->ShouldShowDetailArea());
399 EXPECT_FALSE(controller()->ShouldShowProgressBar()); 482 EXPECT_FALSE(controller()->ShouldShowProgressBar());
400 } 483 }
401 484
402 // Tests that changing the value of a CC expiration date combobox works as 485 // Tests that changing the value of a CC expiration date combobox works as
403 // expected when Autofill is used to fill text inputs. 486 // expected when Autofill is used to fill text inputs.
404 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillComboboxFromAutofill) { 487 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, FillComboboxFromAutofill) {
405 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); 488 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE);
406 controller()->DisableWallet(wallet::WalletClient::UNKNOWN_ERROR); 489 controller()->DisableWallet(wallet::WalletClient::UNKNOWN_ERROR);
407 490
408 CreditCard card1; 491 CreditCard card1;
409 test::SetCreditCardInfo(&card1, "JJ Smith", "4111111111111111", "12", "2018"); 492 test::SetCreditCardInfo(&card1, "JJ Smith", "4111111111111111", "12", "2018");
410 controller()->GetTestingManager()->AddTestingCreditCard(&card1); 493 controller()->GetTestingManager()->AddTestingCreditCard(&card1);
411 CreditCard card2; 494 CreditCard card2;
412 test::SetCreditCardInfo(&card2, "B Bird", "3111111111111111", "11", "2017"); 495 test::SetCreditCardInfo(&card2, "B Bird", "3111111111111111", "11", "2017");
413 controller()->GetTestingManager()->AddTestingCreditCard(&card2); 496 controller()->GetTestingManager()->AddTestingCreditCard(&card2);
414 AutofillProfile full_profile(test::GetFullProfile()); 497 AutofillProfile full_profile(test::GetFullProfile());
415 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 498 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
416 499
417 const DetailInputs& inputs = 500 const DetailInputs& inputs =
418 controller()->RequestedFieldsForSection(SECTION_CC); 501 controller()->RequestedFieldsForSection(SECTION_CC);
419 const DetailInput& triggering_input = inputs[0]; 502 const DetailInput& triggering_input = inputs[0];
420 string16 value = card1.GetRawInfo(triggering_input.type); 503 string16 value = card1.GetRawInfo(triggering_input.type);
421 TestableAutofillDialogView* view = controller()->view()->GetTestableView(); 504 TestableAutofillDialogView* view = controller()->GetTestableView();
422 view->SetTextContentsOfInput(triggering_input, 505 view->SetTextContentsOfInput(triggering_input,
423 value.substr(0, value.size() / 2)); 506 value.substr(0, value.size() / 2));
424 view->ActivateInput(triggering_input); 507 view->ActivateInput(triggering_input);
425 508
426 ASSERT_EQ(&triggering_input, controller()->input_showing_popup()); 509 ASSERT_EQ(&triggering_input, controller()->input_showing_popup());
427 controller()->DidAcceptSuggestion(string16(), 0); 510 controller()->DidAcceptSuggestion(string16(), 0);
428 511
429 // All inputs should be filled. 512 // All inputs should be filled.
430 AutofillCreditCardWrapper wrapper1(&card1); 513 AutofillCreditCardWrapper wrapper1(&card1);
431 for (size_t i = 0; i < inputs.size(); ++i) { 514 for (size_t i = 0; i < inputs.size(); ++i) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 model->ActivatedAt(1); 637 model->ActivatedAt(1);
555 ASSERT_TRUE(model->IsItemCheckedAt(1)); 638 ASSERT_TRUE(model->IsItemCheckedAt(1));
556 EXPECT_TRUE(controller()->IsEditingExistingData(SECTION_CC)); 639 EXPECT_TRUE(controller()->IsEditingExistingData(SECTION_CC));
557 } 640 }
558 641
559 // Notifications with long message text should not make the dialog bigger. 642 // Notifications with long message text should not make the dialog bigger.
560 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, LongNotifications) { 643 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, LongNotifications) {
561 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); 644 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE);
562 645
563 const gfx::Size no_notification_size = 646 const gfx::Size no_notification_size =
564 controller()->view()->GetTestableView()->GetSize(); 647 controller()->GetTestableView()->GetSize();
565 ASSERT_GT(no_notification_size.width(), 0); 648 ASSERT_GT(no_notification_size.width(), 0);
566 649
567 std::vector<DialogNotification> notifications; 650 std::vector<DialogNotification> notifications;
568 notifications.push_back( 651 notifications.push_back(
569 DialogNotification(DialogNotification::DEVELOPER_WARNING, ASCIIToUTF16( 652 DialogNotification(DialogNotification::DEVELOPER_WARNING, ASCIIToUTF16(
570 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do " 653 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
571 "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim " 654 "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim "
572 "ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut " 655 "ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut "
573 "aliquip ex ea commodo consequat. Duis aute irure dolor in " 656 "aliquip ex ea commodo consequat. Duis aute irure dolor in "
574 "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla " 657 "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "
575 "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in " 658 "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in "
576 "culpa qui officia deserunt mollit anim id est laborum."))); 659 "culpa qui officia deserunt mollit anim id est laborum.")));
577 controller()->set_notifications(notifications); 660 controller()->set_notifications(notifications);
578 controller()->view()->UpdateNotificationArea(); 661 controller()->view()->UpdateNotificationArea();
579 662
580 EXPECT_EQ(no_notification_size.width(), 663 EXPECT_EQ(no_notification_size.width(),
581 controller()->view()->GetTestableView()->GetSize().width()); 664 controller()->GetTestableView()->GetSize().width());
665 }
666
667 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocompleteEvent) {
668 AutofillDialogControllerImpl* controller =
669 SetUpHtmlAndInvoke("<input autocomplete='cc-name'>");
670
671 AddCreditcardToProfile(controller->profile(), test::GetVerifiedCreditCard());
672 AddAutofillProfileToProfile(controller->profile(),
673 test::GetVerifiedProfile());
674
675 TestableAutofillDialogView* view = controller->GetTestableView();
676 view->SetTextContentsOfSuggestionInput(SECTION_CC, ASCIIToUTF16("123"));
677 view->SubmitForTesting();
678 ExpectDomMessage("success");
679 }
680
681 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest,
682 AutocompleteErrorEventReasonInvalid) {
683 AutofillDialogControllerImpl* controller =
684 SetUpHtmlAndInvoke("<input autocomplete='cc-name' pattern='.*zebra.*'>");
685
686 const CreditCard& credit_card = test::GetVerifiedCreditCard();
687 ASSERT_TRUE(
688 credit_card.GetRawInfo(CREDIT_CARD_NAME).find(ASCIIToUTF16("zebra")) ==
689 base::string16::npos);
690 AddCreditcardToProfile(controller->profile(), credit_card);
691 AddAutofillProfileToProfile(controller->profile(),
692 test::GetVerifiedProfile());
693
694 TestableAutofillDialogView* view = controller->GetTestableView();
695 view->SetTextContentsOfSuggestionInput(SECTION_CC, ASCIIToUTF16("123"));
696 view->SubmitForTesting();
697 ExpectDomMessage("error: invalid");
698 }
699
700 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest,
701 AutocompleteErrorEventReasonCancel) {
702 SetUpHtmlAndInvoke("<input autocomplete='cc-name'>")->GetTestableView()->
703 CancelForTesting();
704 ExpectDomMessage("error: cancel");
582 } 705 }
583 706
584 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, NoCvcSegfault) { 707 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, NoCvcSegfault) {
585 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); 708 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE);
586 controller()->DisableWallet(wallet::WalletClient::UNKNOWN_ERROR); 709 controller()->DisableWallet(wallet::WalletClient::UNKNOWN_ERROR);
587 controller()->set_use_validation(true); 710 controller()->set_use_validation(true);
588 711
589 CreditCard credit_card(test::GetVerifiedCreditCard()); 712 CreditCard credit_card(test::GetVerifiedCreditCard());
590 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); 713 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
591 EXPECT_FALSE(controller()->IsEditingExistingData(SECTION_CC)); 714 EXPECT_FALSE(controller()->IsEditingExistingData(SECTION_CC));
592 715
593 ASSERT_NO_FATAL_FAILURE( 716 ASSERT_NO_FATAL_FAILURE(
594 controller()->view()->GetTestableView()->SubmitForTesting()); 717 controller()->GetTestableView()->SubmitForTesting());
595 } 718 }
596 #endif // defined(TOOLKIT_VIEWS) 719 #endif // defined(TOOLKIT_VIEWS)
597 720
598 } // namespace autofill 721 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/autofill/autofill_dialog_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698