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

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
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/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
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 AutofillDialogControllerImpl* SetupHtmlAndInvoke(
Ilya Sherman 2013/06/19 23:56:14 nit: "Setup" -> "SetUp"
Dan Beam 2013/06/20 00:26:57 Done.
213 const std::string& form_inner_html) {
Ilya Sherman 2013/06/19 23:56:14 nit: Docs.
214 ui_test_utils::NavigateToURL(
215 browser(), GURL(std::string("data:text/html,") +
216 "<!doctype html>"
217 "<html>"
218 "<body>"
219 "<form>" + form_inner_html + "</form>"
220 "<script>"
221 "function send(msg) {"
222 "domAutomationController.setAutomationId(0);"
223 "domAutomationController.send(msg);"
224 "}"
Ilya Sherman 2013/06/19 23:56:14 nit: Does this not require a semicolon?
Dan Beam 2013/06/20 00:26:57 no, function declarations (function name() {}) do
225 "document.forms[0].onautocompleteerror = function(e) {"
226 "send('error: ' + e.reason);"
227 "};"
228 "document.forms[0].onautocomplete = function() {"
229 "send('success');"
230 "};"
231 "window.onclick = function() {"
232 "document.forms[0].requestAutocomplete();"
233 "send('clicked');"
234 "};"
235 "</script>"
236 "</body>"
237 "</html>"));
238
239 dom_message_queue_.reset(new content::DOMMessageQueue);
240 content::WebContents* contents = GetActiveWebContents();
241 content::WaitForLoadStop(contents);
242
243 // Triggers the onclick handler which invokes requestAutocomplete().
244 content::SimulateMouseClick(contents, 0, WebKit::WebMouseEvent::ButtonLeft);
245 ExpectDomMessage("clicked");
246
247 return TabAutofillManagerDelegate::FromWebContents(contents)->
248 dialog_controller();
249 }
250
251 void ExpectDomMessage(const std::string& expected) {
Ilya Sherman 2013/06/19 23:56:14 nit: Worth adding a SCOPED_TRACE(expected)?
Ilya Sherman 2013/06/19 23:56:14 nit: Docs.
Dan Beam 2013/06/20 00:26:57 Done.
Dan Beam 2013/06/20 00:27:19 what does this do?
Ilya Sherman 2013/06/20 01:11:27 Nevermind, it's not helpful for this test.
252 std::string message;
253 ASSERT_TRUE(dom_message_queue_->WaitForMessage(&message));
254 dom_message_queue_->ClearQueue();
255 EXPECT_EQ(std::string("\"").append(expected).append("\""), message);
Ilya Sherman 2013/06/19 23:56:14 nit: Why not just "\"" + expected + "\""?
Dan Beam 2013/06/20 00:26:57 Done.
256 }
257
204 private: 258 private:
205 MockAutofillMetrics metric_logger_; 259 MockAutofillMetrics metric_logger_;
206 TestAutofillDialogController* controller_; // Weak reference. 260 TestAutofillDialogController* controller_; // Weak reference.
207 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 261 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
262 scoped_ptr<content::DOMMessageQueue> dom_message_queue_;
208 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); 263 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest);
209 }; 264 };
210 265
211 // TODO(isherman): Enable these tests on other platforms once the UI is 266 // TODO(isherman): Enable these tests on other platforms once the UI is
212 // implemented on those platforms. 267 // implemented on those platforms.
213 #if defined(TOOLKIT_VIEWS) 268 #if defined(TOOLKIT_VIEWS)
214 // Submit the form data. 269 // Submit the form data.
215 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Submit) { 270 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, Submit) {
216 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE); 271 InitializeControllerOfType(DIALOG_TYPE_REQUEST_AUTOCOMPLETE);
217 controller()->view()->GetTestableView()->SubmitForTesting(); 272 controller()->view()->GetTestableView()->SubmitForTesting();
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 "aliquip ex ea commodo consequat. Duis aute irure dolor in " 616 "aliquip ex ea commodo consequat. Duis aute irure dolor in "
562 "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla " 617 "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "
563 "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in " 618 "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in "
564 "culpa qui officia deserunt mollit anim id est laborum."))); 619 "culpa qui officia deserunt mollit anim id est laborum.")));
565 controller()->set_notifications(notifications); 620 controller()->set_notifications(notifications);
566 controller()->view()->UpdateNotificationArea(); 621 controller()->view()->UpdateNotificationArea();
567 622
568 EXPECT_EQ(no_notification_size.width(), 623 EXPECT_EQ(no_notification_size.width(),
569 controller()->view()->GetTestableView()->GetSize().width()); 624 controller()->view()->GetTestableView()->GetSize().width());
570 } 625 }
626
627 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocompleteEvent) {
628 AutofillDialogControllerImpl* controller =
629 SetupHtmlAndInvoke("<input autocomplete='cc-name'>");
630
631 PersonalDataManager* manager =
632 PersonalDataManagerFactory::GetForProfile(controller->profile());
633 ASSERT_TRUE(manager);
634
635 manager->AddProfile(test::GetVerifiedProfile());
636 manager->AddCreditCard(test::GetVerifiedCreditCard());
637
638 // Personal data manager needs to write to the WebDB to update its observers.
639 // Wait until that's done.
640 content::RunAllPendingInMessageLoop(content::BrowserThread::DB);
Ilya Sherman 2013/06/19 23:56:14 nit: Would be nice to decompose lines 631-640 into
Dan Beam 2013/06/20 00:26:57 Done.
641
642 controller->view()->GetTestableView()->SetCvc(ASCIIToUTF16("123"));
643 controller->view()->GetTestableView()->SubmitForTesting();
644 ExpectDomMessage("success");
645 }
646
647 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest,
648 AutocompleteErrorEventReasonInvalid) {
649 AutofillDialogControllerImpl* controller =
650 SetupHtmlAndInvoke("<input autocomplete='cc-name' pattern='.*zebra.*'>");
651
652 PersonalDataManager* manager =
653 PersonalDataManagerFactory::GetForProfile(controller->profile());
654 ASSERT_TRUE(manager);
655
656 manager->AddProfile(test::GetVerifiedProfile());
657
658 const CreditCard& credit_card = test::GetVerifiedCreditCard();
659 ASSERT_TRUE(
660 credit_card.GetRawInfo(CREDIT_CARD_NAME).find(ASCIIToUTF16("zebra")) ==
661 base::string16::npos);
662
663 manager->AddCreditCard(credit_card);
664
665 // Personal data manager needs to write to the WebDB to update its observers.
666 // Wait until that's done.
667 content::RunAllPendingInMessageLoop(content::BrowserThread::DB);
668
669 controller->view()->GetTestableView()->SetCvc(ASCIIToUTF16("123"));
670 controller->view()->GetTestableView()->SubmitForTesting();
671 ExpectDomMessage("error: invalid");
672 }
673
674 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest,
675 AutocompleteErrorEventReasonCancel) {
676 SetupHtmlAndInvoke("<input autocomplete='cc-name'>")->view()->
677 GetTestableView()->CancelForTesting();
678 ExpectDomMessage("error: cancel");
679 }
571 #endif // defined(TOOLKIT_VIEWS) 680 #endif // defined(TOOLKIT_VIEWS)
572 681
573 } // namespace autofill 682 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698