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

Side by Side 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: Fix the test. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "base/message_loop.h"
7 #include "base/time.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/autofill/autofill_metrics.h"
10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
11 #include "chrome/browser/ui/autofill/autofill_dialog_view.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/common/form_data.h"
15 #include "chrome/common/form_field_data.h"
16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "content/public/test/test_utils.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace autofill {
21
22 namespace {
23
24 void MockCallback(const FormStructure*) {}
25
26 class MockAutofillMetrics : public AutofillMetrics {
27 public:
28 MockAutofillMetrics()
29 : requester_(static_cast<DialogRequester>(-1)),
30 metric_(static_cast<AutofillMetrics::DialogDismissalAction>(-1)) {}
31 virtual ~MockAutofillMetrics() {}
32
33 // AutofillMetrics:
34 virtual void LogRequestAutocompleteUiDuration(
35 const base::TimeDelta& duration,
36 DialogRequester requester,
37 DialogDismissalAction dismissal_action) const OVERRIDE {
38 // Ignore constness for testing.
39 MockAutofillMetrics* mutable_this = const_cast<MockAutofillMetrics*>(this);
40 mutable_this->requester_ = requester;
41 mutable_this->metric_ = dismissal_action;
42 }
43
44 DialogRequester requester() const { return requester_; }
45 AutofillMetrics::DialogDismissalAction metric() const { return metric_; }
46
47 private:
48 DialogRequester requester_;
49 AutofillMetrics::DialogDismissalAction metric_;
50
51 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics);
52 };
53
54 class TestAutofillDialogController : public AutofillDialogControllerImpl {
55 public:
56 TestAutofillDialogController(content::WebContents* contents,
57 const FormData& form_data,
58 const AutofillMetrics& metric_logger,
59 const DialogRequester requester)
60 : AutofillDialogControllerImpl(contents,
61 form_data,
62 GURL(),
63 content::SSLStatus(),
64 metric_logger,
65 requester,
66 base::Bind(&MockCallback)) {
67 }
68
69 virtual ~TestAutofillDialogController() {}
70
71 virtual void ViewClosed(DialogAction action) OVERRIDE {
72 AutofillDialogControllerImpl::ViewClosed(action);
73 MessageLoop::current()->Quit();
74 }
75
76 // Increase visibility for testing.
77 AutofillDialogView* view() { return AutofillDialogControllerImpl::view(); }
78
79 private:
80 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController);
81 };
82
83 } // namespace
84
85 class AutofillDialogControllerTest : public InProcessBrowserTest {
86 public:
87 AutofillDialogControllerTest() {}
88 virtual ~AutofillDialogControllerTest() {}
89
90 content::WebContents* GetActiveWebContents() {
91 return browser()->tab_strip_model()->GetActiveWebContents();
92 }
93
94 private:
95 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest);
96 };
97
98 // TODO(isherman): Enable this test on other platforms once the UI is
99 // implemented on those platforms.
100 #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.
101 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest,
102 RequestAutocompleteUiDurationMetrics) {
103 FormData form;
104 form.name = ASCIIToUTF16("TestForm");
105 form.method = ASCIIToUTF16("POST");
106 form.origin = GURL("http://example.com/form.html");
107 form.action = GURL("http://example.com/submit.html");
108 form.user_submitted = true;
109
110 FormFieldData field;
111 field.autocomplete_attribute = "email";
112 form.fields.push_back(field);
113
114 // Submit the form data.
115 {
116 MockAutofillMetrics metric_logger;
117 TestAutofillDialogController* dialog_controller =
118 new TestAutofillDialogController(
119 GetActiveWebContents(), form, metric_logger,
120 DIALOG_REQUESTER_REQUEST_AUTOCOMPLETE);
121 dialog_controller->Show();
122 dialog_controller->view()->SubmitForTesting();
123
124 content::RunMessageLoop();
125
126 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, metric_logger.metric());
127 EXPECT_EQ(DIALOG_REQUESTER_REQUEST_AUTOCOMPLETE, metric_logger.requester());
128 }
129
130 // Cancel out of the dialog.
131 {
132 MockAutofillMetrics metric_logger;
133 TestAutofillDialogController* dialog_controller =
134 new TestAutofillDialogController(
135 GetActiveWebContents(), form, metric_logger,
136 DIALOG_REQUESTER_AUTOCHECKOUT);
137 dialog_controller->Show();
138 dialog_controller->view()->CancelForTesting();
139
140 content::RunMessageLoop();
141
142 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, metric_logger.metric());
143 EXPECT_EQ(DIALOG_REQUESTER_AUTOCHECKOUT, metric_logger.requester());
144 }
145
146 // Take some other action that dismisses the dialog.
147 {
148 MockAutofillMetrics metric_logger;
149 TestAutofillDialogController* dialog_controller =
150 new TestAutofillDialogController(
151 GetActiveWebContents(), form, metric_logger,
152 DIALOG_REQUESTER_AUTOCHECKOUT);
153 dialog_controller->Show();
154 dialog_controller->Hide();
155
156 content::RunMessageLoop();
157
158 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, metric_logger.metric());
159 EXPECT_EQ(DIALOG_REQUESTER_AUTOCHECKOUT, metric_logger.requester());
160 }
161 }
162 #endif // defined(TOOLKIT_VIEWS)
163
164 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698