Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1363b6b13d78986c68148173e96118d237668af0 |
| --- /dev/null |
| +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc |
| @@ -0,0 +1,164 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/bind.h" |
| +#include "base/message_loop.h" |
| +#include "base/time.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "chrome/browser/autofill/autofill_metrics.h" |
| +#include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
| +#include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/common/form_data.h" |
| +#include "chrome/common/form_field_data.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "content/public/test/test_utils.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace autofill { |
| + |
| +namespace { |
| + |
| +void MockCallback(const FormStructure*) {} |
| + |
| +class MockAutofillMetrics : public AutofillMetrics { |
| + public: |
| + MockAutofillMetrics() |
| + : requester_(static_cast<DialogRequester>(-1)), |
| + metric_(static_cast<AutofillMetrics::DialogDismissalAction>(-1)) {} |
| + virtual ~MockAutofillMetrics() {} |
| + |
| + // AutofillMetrics: |
| + virtual void LogRequestAutocompleteUiDuration( |
| + const base::TimeDelta& duration, |
| + DialogRequester requester, |
| + DialogDismissalAction dismissal_action) const OVERRIDE { |
| + // Ignore constness for testing. |
| + MockAutofillMetrics* mutable_this = const_cast<MockAutofillMetrics*>(this); |
| + mutable_this->requester_ = requester; |
| + mutable_this->metric_ = dismissal_action; |
| + } |
| + |
| + DialogRequester requester() const { return requester_; } |
| + AutofillMetrics::DialogDismissalAction metric() const { return metric_; } |
| + |
| + private: |
| + DialogRequester requester_; |
| + AutofillMetrics::DialogDismissalAction metric_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics); |
| +}; |
| + |
| +class TestAutofillDialogController : public AutofillDialogControllerImpl { |
| + public: |
| + TestAutofillDialogController(content::WebContents* contents, |
| + const FormData& form_data, |
| + const AutofillMetrics& metric_logger, |
| + const DialogRequester requester) |
| + : AutofillDialogControllerImpl(contents, |
| + form_data, |
| + GURL(), |
| + content::SSLStatus(), |
| + metric_logger, |
| + requester, |
| + base::Bind(&MockCallback)) { |
| + } |
| + |
| + virtual ~TestAutofillDialogController() {} |
| + |
| + virtual void ViewClosed(DialogAction action) OVERRIDE { |
| + AutofillDialogControllerImpl::ViewClosed(action); |
| + MessageLoop::current()->Quit(); |
| + } |
| + |
| + // Increase visibility for testing. |
| + AutofillDialogView* view() { return AutofillDialogControllerImpl::view(); } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); |
| +}; |
| + |
| +} // namespace |
| + |
| +class AutofillDialogControllerTest : public InProcessBrowserTest { |
| + public: |
| + AutofillDialogControllerTest() {} |
| + virtual ~AutofillDialogControllerTest() {} |
| + |
| + content::WebContents* GetActiveWebContents() { |
| + return browser()->tab_strip_model()->GetActiveWebContents(); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); |
| +}; |
| + |
| +// TODO(isherman): Enable this test on other platforms once the UI is |
| +// implemented on those platforms. |
| +#if defined(TOOLKIT_VIEWS) |
|
Evan Stade
2013/02/05 20:06:41
do you have to ifdef out the whole test instead of
Ilya Sherman
2013/02/06 00:02:25
Done.
|
| +IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, |
| + RequestAutocompleteUiDurationMetrics) { |
| + FormData form; |
| + form.name = ASCIIToUTF16("TestForm"); |
| + form.method = ASCIIToUTF16("POST"); |
| + form.origin = GURL("http://example.com/form.html"); |
| + form.action = GURL("http://example.com/submit.html"); |
| + form.user_submitted = true; |
| + |
| + FormFieldData field; |
| + field.autocomplete_attribute = "email"; |
| + form.fields.push_back(field); |
| + |
| + // Submit the form data. |
| + { |
| + MockAutofillMetrics metric_logger; |
| + TestAutofillDialogController* dialog_controller = |
| + new TestAutofillDialogController( |
| + GetActiveWebContents(), form, metric_logger, |
| + DIALOG_REQUESTER_REQUEST_AUTOCOMPLETE); |
| + dialog_controller->Show(); |
| + dialog_controller->view()->SubmitForTesting(); |
| + |
| + content::RunMessageLoop(); |
| + |
| + EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, metric_logger.metric()); |
| + EXPECT_EQ(DIALOG_REQUESTER_REQUEST_AUTOCOMPLETE, metric_logger.requester()); |
| + } |
| + |
| + // Cancel out of the dialog. |
| + { |
| + MockAutofillMetrics metric_logger; |
| + TestAutofillDialogController* dialog_controller = |
| + new TestAutofillDialogController( |
| + GetActiveWebContents(), form, metric_logger, |
| + DIALOG_REQUESTER_AUTOCHECKOUT); |
| + dialog_controller->Show(); |
| + dialog_controller->view()->CancelForTesting(); |
| + |
| + content::RunMessageLoop(); |
| + |
| + EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, metric_logger.metric()); |
| + EXPECT_EQ(DIALOG_REQUESTER_AUTOCHECKOUT, metric_logger.requester()); |
| + } |
| + |
| + // Take some other action that dismisses the dialog. |
| + { |
| + MockAutofillMetrics metric_logger; |
| + TestAutofillDialogController* dialog_controller = |
| + new TestAutofillDialogController( |
| + GetActiveWebContents(), form, metric_logger, |
| + DIALOG_REQUESTER_AUTOCHECKOUT); |
| + dialog_controller->Show(); |
| + dialog_controller->Hide(); |
| + |
| + content::RunMessageLoop(); |
| + |
| + EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, metric_logger.metric()); |
| + EXPECT_EQ(DIALOG_REQUESTER_AUTOCHECKOUT, metric_logger.requester()); |
| + } |
| +} |
| +#endif // defined(TOOLKIT_VIEWS) |
| + |
| +} // namespace autofill |