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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc
index 7a33c36099272768565acb38ed73d5ed97cdbb5c..64055beb03adea144a1bb57460a3191f1a059150 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc
@@ -8,13 +8,16 @@
#include "base/message_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time.h"
+#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
#include "chrome/browser/ui/autofill/autofill_dialog_view.h"
#include "chrome/browser/ui/autofill/data_model_wrapper.h"
+#include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
#include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
#include "components/autofill/browser/autofill_common_test.h"
#include "components/autofill/browser/autofill_metrics.h"
#include "components/autofill/browser/test_personal_data_manager.h"
@@ -23,8 +26,13 @@
#include "components/autofill/core/common/autofill_switches.h"
#include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/form_field_data.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_delegate.h"
+#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/public/web/WebInputEvent.h"
namespace autofill {
@@ -201,10 +209,57 @@ class AutofillDialogControllerTest : public InProcessBrowserTest {
message_loop_runner_->Run();
}
+ AutofillDialogControllerImpl* SetupHtmlAndInvoke(
Ilya Sherman 2013/06/19 23:56:14 nit: "Setup" -> "SetUp"
Dan Beam 2013/06/20 00:26:57 Done.
+ const std::string& form_inner_html) {
Ilya Sherman 2013/06/19 23:56:14 nit: Docs.
+ ui_test_utils::NavigateToURL(
+ browser(), GURL(std::string("data:text/html,") +
+ "<!doctype html>"
+ "<html>"
+ "<body>"
+ "<form>" + form_inner_html + "</form>"
+ "<script>"
+ "function send(msg) {"
+ "domAutomationController.setAutomationId(0);"
+ "domAutomationController.send(msg);"
+ "}"
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
+ "document.forms[0].onautocompleteerror = function(e) {"
+ "send('error: ' + e.reason);"
+ "};"
+ "document.forms[0].onautocomplete = function() {"
+ "send('success');"
+ "};"
+ "window.onclick = function() {"
+ "document.forms[0].requestAutocomplete();"
+ "send('clicked');"
+ "};"
+ "</script>"
+ "</body>"
+ "</html>"));
+
+ dom_message_queue_.reset(new content::DOMMessageQueue);
+ content::WebContents* contents = GetActiveWebContents();
+ content::WaitForLoadStop(contents);
+
+ // Triggers the onclick handler which invokes requestAutocomplete().
+ content::SimulateMouseClick(contents, 0, WebKit::WebMouseEvent::ButtonLeft);
+ ExpectDomMessage("clicked");
+
+ return TabAutofillManagerDelegate::FromWebContents(contents)->
+ dialog_controller();
+ }
+
+ 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.
+ std::string message;
+ ASSERT_TRUE(dom_message_queue_->WaitForMessage(&message));
+ dom_message_queue_->ClearQueue();
+ 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.
+ }
+
private:
MockAutofillMetrics metric_logger_;
TestAutofillDialogController* controller_; // Weak reference.
scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
+ scoped_ptr<content::DOMMessageQueue> dom_message_queue_;
DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest);
};
@@ -568,6 +623,60 @@ IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, LongNotifications) {
EXPECT_EQ(no_notification_size.width(),
controller()->view()->GetTestableView()->GetSize().width());
}
+
+IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, AutocompleteEvent) {
+ AutofillDialogControllerImpl* controller =
+ SetupHtmlAndInvoke("<input autocomplete='cc-name'>");
+
+ PersonalDataManager* manager =
+ PersonalDataManagerFactory::GetForProfile(controller->profile());
+ ASSERT_TRUE(manager);
+
+ manager->AddProfile(test::GetVerifiedProfile());
+ manager->AddCreditCard(test::GetVerifiedCreditCard());
+
+ // Personal data manager needs to write to the WebDB to update its observers.
+ // Wait until that's done.
+ 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.
+
+ controller->view()->GetTestableView()->SetCvc(ASCIIToUTF16("123"));
+ controller->view()->GetTestableView()->SubmitForTesting();
+ ExpectDomMessage("success");
+}
+
+IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest,
+ AutocompleteErrorEventReasonInvalid) {
+ AutofillDialogControllerImpl* controller =
+ SetupHtmlAndInvoke("<input autocomplete='cc-name' pattern='.*zebra.*'>");
+
+ PersonalDataManager* manager =
+ PersonalDataManagerFactory::GetForProfile(controller->profile());
+ ASSERT_TRUE(manager);
+
+ manager->AddProfile(test::GetVerifiedProfile());
+
+ const CreditCard& credit_card = test::GetVerifiedCreditCard();
+ ASSERT_TRUE(
+ credit_card.GetRawInfo(CREDIT_CARD_NAME).find(ASCIIToUTF16("zebra")) ==
+ base::string16::npos);
+
+ manager->AddCreditCard(credit_card);
+
+ // Personal data manager needs to write to the WebDB to update its observers.
+ // Wait until that's done.
+ content::RunAllPendingInMessageLoop(content::BrowserThread::DB);
+
+ controller->view()->GetTestableView()->SetCvc(ASCIIToUTF16("123"));
+ controller->view()->GetTestableView()->SubmitForTesting();
+ ExpectDomMessage("error: invalid");
+}
+
+IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest,
+ AutocompleteErrorEventReasonCancel) {
+ SetupHtmlAndInvoke("<input autocomplete='cc-name'>")->view()->
+ GetTestableView()->CancelForTesting();
+ ExpectDomMessage("error: cancel");
+}
#endif // defined(TOOLKIT_VIEWS)
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698