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

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/basictypes.h"
5 #include "base/bind.h" 6 #include "base/bind.h"
6 #include "base/command_line.h" 7 #include "base/command_line.h"
7 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
8 #include "base/message_loop.h" 9 #include "base/message_loop.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/synchronization/waitable_event.h"
10 #include "base/time.h" 12 #include "base/time.h"
13 #include "chrome/browser/autofill/personal_data_manager_factory.h"
11 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" 14 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
12 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" 15 #include "chrome/browser/ui/autofill/autofill_dialog_view.h"
13 #include "chrome/browser/ui/autofill/data_model_wrapper.h" 16 #include "chrome/browser/ui/autofill/data_model_wrapper.h"
17 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
14 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h" 18 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h"
15 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 #include "chrome/browser/ui/view_ids.h"
17 #include "chrome/test/base/in_process_browser_test.h" 22 #include "chrome/test/base/in_process_browser_test.h"
23 #include "chrome/test/base/ui_test_utils.h"
18 #include "components/autofill/browser/autofill_common_test.h" 24 #include "components/autofill/browser/autofill_common_test.h"
19 #include "components/autofill/browser/autofill_metrics.h" 25 #include "components/autofill/browser/autofill_metrics.h"
20 #include "components/autofill/browser/test_personal_data_manager.h" 26 #include "components/autofill/browser/test_personal_data_manager.h"
21 #include "components/autofill/browser/validation.h" 27 #include "components/autofill/browser/validation.h"
22 #include "components/autofill/content/browser/wallet/wallet_test_util.h" 28 #include "components/autofill/content/browser/wallet/wallet_test_util.h"
23 #include "components/autofill/core/common/autofill_switches.h" 29 #include "components/autofill/core/common/autofill_switches.h"
24 #include "components/autofill/core/common/form_data.h" 30 #include "components/autofill/core/common/form_data.h"
25 #include "components/autofill/core/common/form_field_data.h" 31 #include "components/autofill/core/common/form_field_data.h"
32 #include "content/public/browser/browser_thread.h"
33 #include "content/public/browser/web_contents.h"
34 #include "content/public/browser/web_contents_delegate.h"
35 #include "content/public/test/browser_test_utils.h"
26 #include "content/public/test/test_utils.h" 36 #include "content/public/test/test_utils.h"
27 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
38 #include "third_party/WebKit/public/web/WebInputEvent.h"
28 39
29 namespace autofill { 40 namespace autofill {
30 41
31 namespace { 42 namespace {
32 43
33 void MockCallback(const FormStructure*, const std::string&) {} 44 void MockCallback(const FormStructure*, const std::string&) {}
34 45
35 class MockAutofillMetrics : public AutofillMetrics { 46 class MockAutofillMetrics : public AutofillMetrics {
36 public: 47 public:
37 MockAutofillMetrics() 48 MockAutofillMetrics()
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 return browser()->tab_strip_model()->GetActiveWebContents(); 205 return browser()->tab_strip_model()->GetActiveWebContents();
195 } 206 }
196 207
197 const MockAutofillMetrics& metric_logger() { return metric_logger_; } 208 const MockAutofillMetrics& metric_logger() { return metric_logger_; }
198 TestAutofillDialogController* controller() { return controller_; } 209 TestAutofillDialogController* controller() { return controller_; }
199 210
200 void RunMessageLoop() { 211 void RunMessageLoop() {
201 message_loop_runner_->Run(); 212 message_loop_runner_->Run();
202 } 213 }
203 214
215 void LoadHtmlInWebContents(const std::string& html) {
216 GURL url(std::string("data:text/html,") + html);
217 ui_test_utils::NavigateToURL(browser(), url);
218 content::WaitForLoadStop(GetActiveWebContents());
219 }
220
221 void ExpectThatLastErrorReasonIs(content::WebContents* contents,
222 const std::string& reason) {
223 std::string message;
224 ASSERT_TRUE(ExecuteScriptInFrameAndExtractString(
225 contents,
226 std::string(),
227 "domAutomationController.send(lastReason);",
228 &message));
229 EXPECT_EQ(reason, message);
230 }
231
204 private: 232 private:
205 MockAutofillMetrics metric_logger_; 233 MockAutofillMetrics metric_logger_;
206 TestAutofillDialogController* controller_; // Weak reference. 234 TestAutofillDialogController* controller_; // Weak reference.
207 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 235 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
208 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); 236 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest);
209 }; 237 };
210 238
211 // TODO(isherman): Enable these tests on other platforms once the UI is 239 // TODO(isherman): Enable these tests on other platforms once the UI is
212 // implemented on those platforms. 240 // implemented on those platforms.
213 #if defined(TOOLKIT_VIEWS) 241 #if defined(TOOLKIT_VIEWS)
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 "aliquip ex ea commodo consequat. Duis aute irure dolor in " 589 "aliquip ex ea commodo consequat. Duis aute irure dolor in "
562 "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla " 590 "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "
563 "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in " 591 "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in "
564 "culpa qui officia deserunt mollit anim id est laborum."))); 592 "culpa qui officia deserunt mollit anim id est laborum.")));
565 controller()->set_notifications(notifications); 593 controller()->set_notifications(notifications);
566 controller()->view()->UpdateNotificationArea(); 594 controller()->view()->UpdateNotificationArea();
567 595
568 EXPECT_EQ(no_notification_size.width(), 596 EXPECT_EQ(no_notification_size.width(),
569 controller()->view()->GetTestableView()->GetSize().width()); 597 controller()->view()->GetTestableView()->GetSize().width());
570 } 598 }
599
600 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, ErrorReasonInvalid) {
601 LoadHtmlInWebContents(
602 "<!doctype html>"
603 "<html>"
604 " <body>"
605 " <form>"
606 " <input pattern='.*zebra.*' autocomplete='cc-name'>"
607 " </form>"
608 " <script>"
609 " domAutomationController.setAutomationId(0);"
610 " var lastReason = '';"
611 " document.forms[0].onautocompleterror = function(e) {"
612 " lastReason = e.reason;"
613 " domAutomationController.send('REASON');"
614 " };"
615 " document.forms[0].onautocomplete = function() {"
616 " domAutomationController.send('FAILURE');"
617 " };"
618 " window.onclick = function() {"
619 " document.forms[0].requestAutocomplete();"
620 " domAutomationController.send('CLICKED');"
621 " };"
622 " </script>"
623 " </body>"
624 "</html>");
625
626 std::string message;
627 content::DOMMessageQueue dom_message_queue;
628
629 // Triggers the onclick handler which invokes requestAutocomplete().
630 content::WebContents* contents = GetActiveWebContents();
631 content::SimulateMouseClick(contents, 0, WebKit::WebMouseEvent::ButtonLeft);
632
633 ASSERT_TRUE(dom_message_queue.WaitForMessage(&message));
634 ASSERT_EQ("\"CLICKED\"", message);
635
636 TabAutofillManagerDelegate* delegate =
637 TabAutofillManagerDelegate::FromWebContents(contents);
638 ASSERT_TRUE(delegate);
639
640 AutofillDialogControllerImpl* controller = delegate->dialog_controller();
641 ASSERT_TRUE(controller);
642
643 PersonalDataManager* manager =
644 PersonalDataManagerFactory::GetForProfile(controller->profile());
645 ASSERT_TRUE(manager);
646
647 manager->AddProfile(test::GetVerifiedProfile());
648
649 const CreditCard& credit_card = test::GetVerifiedCreditCard();
650 ASSERT_TRUE(
651 credit_card.GetRawInfo(CREDIT_CARD_NAME).find(ASCIIToUTF16("zebra")) ==
652 base::string16::npos);
653
654 manager->AddCreditCard(credit_card);
655
656 // Personal data manager needs to write to the WebDB to update its observers.
657 // Wait until that's done.
658 content::RunAllPendingInMessageLoop(content::BrowserThread::DB);
659
660 controller->view()->GetTestableView()->SetCvc(ASCIIToUTF16("123"));
661
662 dom_message_queue.ClearQueue();
663 controller->view()->GetTestableView()->SubmitForTesting();
664
665 // TODO(dbeam): do some magic here to make `onautocompleteerror` fire.
Dan Beam 2013/06/19 08:38:53 estade@/isherman@: if you know what this magic is,
666
667 ASSERT_TRUE(dom_message_queue.WaitForMessage(&message));
668 ASSERT_EQ("\"REASON\"", message);
669
670 ExpectThatLastErrorReasonIs(contents, "invalid");
671 }
571 #endif // defined(TOOLKIT_VIEWS) 672 #endif // defined(TOOLKIT_VIEWS)
572 673
573 } // namespace autofill 674 } // 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