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..00058fab3f9978529eb8e87f6dcfa897e5b95f01 100644 |
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc |
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc |
@@ -2,19 +2,25 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "base/basictypes.h" |
#include "base/bind.h" |
#include "base/command_line.h" |
#include "base/memory/ref_counted.h" |
#include "base/message_loop.h" |
#include "base/strings/utf_string_conversions.h" |
+#include "base/synchronization/waitable_event.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/browser/ui/view_ids.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 +29,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,6 +212,23 @@ class AutofillDialogControllerTest : public InProcessBrowserTest { |
message_loop_runner_->Run(); |
} |
+ void LoadHtmlInWebContents(const std::string& html) { |
+ GURL url(std::string("data:text/html,") + html); |
+ ui_test_utils::NavigateToURL(browser(), url); |
+ content::WaitForLoadStop(GetActiveWebContents()); |
+ } |
+ |
+ void ExpectThatLastErrorReasonIs(content::WebContents* contents, |
+ const std::string& reason) { |
+ std::string message; |
+ ASSERT_TRUE(ExecuteScriptInFrameAndExtractString( |
+ contents, |
+ std::string(), |
+ "domAutomationController.send(lastReason);", |
+ &message)); |
+ EXPECT_EQ(reason, message); |
+ } |
+ |
private: |
MockAutofillMetrics metric_logger_; |
TestAutofillDialogController* controller_; // Weak reference. |
@@ -568,6 +596,79 @@ IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, LongNotifications) { |
EXPECT_EQ(no_notification_size.width(), |
controller()->view()->GetTestableView()->GetSize().width()); |
} |
+ |
+IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, ErrorReasonInvalid) { |
+ LoadHtmlInWebContents( |
+ "<!doctype html>" |
+ "<html>" |
+ " <body>" |
+ " <form>" |
+ " <input pattern='.*zebra.*' autocomplete='cc-name'>" |
+ " </form>" |
+ " <script>" |
+ " domAutomationController.setAutomationId(0);" |
+ " var lastReason = '';" |
+ " document.forms[0].onautocompleterror = function(e) {" |
+ " lastReason = e.reason;" |
+ " domAutomationController.send('REASON');" |
+ " };" |
+ " document.forms[0].onautocomplete = function() {" |
+ " domAutomationController.send('FAILURE');" |
+ " };" |
+ " window.onclick = function() {" |
+ " document.forms[0].requestAutocomplete();" |
+ " domAutomationController.send('CLICKED');" |
+ " };" |
+ " </script>" |
+ " </body>" |
+ "</html>"); |
+ |
+ std::string message; |
+ content::DOMMessageQueue dom_message_queue; |
+ |
+ // Triggers the onclick handler which invokes requestAutocomplete(). |
+ content::WebContents* contents = GetActiveWebContents(); |
+ content::SimulateMouseClick(contents, 0, WebKit::WebMouseEvent::ButtonLeft); |
+ |
+ ASSERT_TRUE(dom_message_queue.WaitForMessage(&message)); |
+ ASSERT_EQ("\"CLICKED\"", message); |
+ |
+ TabAutofillManagerDelegate* delegate = |
+ TabAutofillManagerDelegate::FromWebContents(contents); |
+ ASSERT_TRUE(delegate); |
+ |
+ AutofillDialogControllerImpl* controller = delegate->dialog_controller(); |
+ ASSERT_TRUE(controller); |
+ |
+ 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")); |
+ |
+ dom_message_queue.ClearQueue(); |
+ controller->view()->GetTestableView()->SubmitForTesting(); |
+ |
+ // 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,
|
+ |
+ ASSERT_TRUE(dom_message_queue.WaitForMessage(&message)); |
+ ASSERT_EQ("\"REASON\"", message); |
+ |
+ ExpectThatLastErrorReasonIs(contents, "invalid"); |
+} |
#endif // defined(TOOLKIT_VIEWS) |
} // namespace autofill |