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

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc

Issue 12091086: [Autofill] Add UMA timing metrics for requestAutocomplete dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase harder Created 7 years, 10 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
new file mode 100644
index 0000000000000000000000000000000000000000..fae5371997c525d31495921df811931aafe5020e
--- /dev/null
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_browsertest.cc
@@ -0,0 +1,174 @@
+// 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()
+ : dialog_type_(static_cast<DialogType>(-1)),
+ metric_(static_cast<AutofillMetrics::DialogDismissalAction>(-1)) {}
+ virtual ~MockAutofillMetrics() {}
+
+ // AutofillMetrics:
+ virtual void LogRequestAutocompleteUiDuration(
+ const base::TimeDelta& duration,
+ DialogType dialog_type,
+ DialogDismissalAction dismissal_action) const OVERRIDE {
+ // Ignore constness for testing.
+ MockAutofillMetrics* mutable_this = const_cast<MockAutofillMetrics*>(this);
+ mutable_this->dialog_type_ = dialog_type;
+ mutable_this->metric_ = dismissal_action;
+ }
+
+ DialogType dialog_type() const { return dialog_type_; }
+ AutofillMetrics::DialogDismissalAction metric() const { return metric_; }
+
+ private:
+ DialogType dialog_type_;
+ 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 DialogType dialog_type)
+ : AutofillDialogControllerImpl(contents,
+ form_data,
+ GURL(),
+ content::SSLStatus(),
+ metric_logger,
+ dialog_type,
+ base::Bind(&MockCallback)) {
+ }
+
+ virtual ~TestAutofillDialogController() {}
+
+ virtual void ViewClosed(DialogAction action) OVERRIDE {
+ AutofillDialogControllerImpl::ViewClosed(action);
+ MessageLoop::current()->Quit();
+ }
+
+ virtual bool InputIsValid(AutofillFieldType type,
+ const string16& value) OVERRIDE {
+ return true;
+ }
+
+ // 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)
+#define MAYBE_RequestAutocompleteUiDurationMetrics \
+ RequestAutocompleteUiDurationMetrics
+#else
+#define MAYBE_RequestAutocompleteUiDurationMetrics \
+ DISABLED_RequestAutocompleteUiDurationMetrics
+#endif // defined(TOOLKIT_VIEWS)
+IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest,
+ MAYBE_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_TYPE_REQUEST_AUTOCOMPLETE);
+ dialog_controller->Show();
+ dialog_controller->view()->SubmitForTesting();
+
+ content::RunMessageLoop();
+
+ EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, metric_logger.metric());
+ EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger.dialog_type());
+ }
+
+ // Cancel out of the dialog.
+ {
+ MockAutofillMetrics metric_logger;
+ TestAutofillDialogController* dialog_controller =
+ new TestAutofillDialogController(
+ GetActiveWebContents(), form, metric_logger,
+ DIALOG_TYPE_AUTOCHECKOUT);
+ dialog_controller->Show();
+ dialog_controller->view()->CancelForTesting();
+
+ content::RunMessageLoop();
+
+ EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, metric_logger.metric());
+ EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type());
+ }
+
+ // Take some other action that dismisses the dialog.
+ {
+ MockAutofillMetrics metric_logger;
+ TestAutofillDialogController* dialog_controller =
+ new TestAutofillDialogController(
+ GetActiveWebContents(), form, metric_logger,
+ DIALOG_TYPE_AUTOCHECKOUT);
+ dialog_controller->Show();
+ dialog_controller->Hide();
+
+ content::RunMessageLoop();
+
+ EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, metric_logger.metric());
+ EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type());
+ }
+}
+
+} // namespace autofill
« no previous file with comments | « chrome/browser/autofill/autofill_metrics_unittest.cc ('k') | chrome/browser/ui/autofill/autofill_dialog_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698