Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/ref_counted.h" | |
| 6 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 7 #include "base/time.h" | 8 #include "base/time.h" |
| 8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
| 10 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 11 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
| 11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "components/autofill/browser/autofill_metrics.h" | 15 #include "components/autofill/browser/autofill_metrics.h" |
| 15 #include "components/autofill/common/form_data.h" | 16 #include "components/autofill/common/form_data.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 AutofillMetrics::AutocheckoutCompletionStatus autocheckout_status_; | 68 AutofillMetrics::AutocheckoutCompletionStatus autocheckout_status_; |
| 68 | 69 |
| 69 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics); | 70 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics); |
| 70 }; | 71 }; |
| 71 | 72 |
| 72 class TestAutofillDialogController : public AutofillDialogControllerImpl { | 73 class TestAutofillDialogController : public AutofillDialogControllerImpl { |
| 73 public: | 74 public: |
| 74 TestAutofillDialogController(content::WebContents* contents, | 75 TestAutofillDialogController(content::WebContents* contents, |
| 75 const FormData& form_data, | 76 const FormData& form_data, |
| 76 const AutofillMetrics& metric_logger, | 77 const AutofillMetrics& metric_logger, |
| 78 scoped_refptr<content::MessageLoopRunner> runner, | |
| 77 const DialogType dialog_type) | 79 const DialogType dialog_type) |
| 78 : AutofillDialogControllerImpl(contents, | 80 : AutofillDialogControllerImpl(contents, |
| 79 form_data, | 81 form_data, |
| 80 GURL(), | 82 GURL(), |
| 81 dialog_type, | 83 dialog_type, |
| 82 base::Bind(&MockCallback)), | 84 base::Bind(&MockCallback)), |
| 83 metric_logger_(metric_logger) { | 85 metric_logger_(metric_logger), |
| 86 message_loop_runner_(runner) { | |
| 84 DisableWallet(); | 87 DisableWallet(); |
| 85 } | 88 } |
| 86 | 89 |
| 87 virtual ~TestAutofillDialogController() {} | 90 virtual ~TestAutofillDialogController() {} |
| 88 | 91 |
| 89 virtual void ViewClosed() OVERRIDE { | 92 virtual void ViewClosed() OVERRIDE { |
| 93 message_loop_runner_->Quit(); | |
| 90 AutofillDialogControllerImpl::ViewClosed(); | 94 AutofillDialogControllerImpl::ViewClosed(); |
| 91 MessageLoop::current()->Quit(); | |
| 92 } | 95 } |
| 93 | 96 |
| 94 virtual bool InputIsValid(AutofillFieldType type, | 97 virtual bool InputIsValid(AutofillFieldType type, |
| 95 const string16& value) OVERRIDE { | 98 const string16& value) OVERRIDE { |
| 96 return true; | 99 return true; |
| 97 } | 100 } |
| 98 | 101 |
| 99 virtual std::vector<AutofillFieldType> InputsAreValid( | 102 virtual std::vector<AutofillFieldType> InputsAreValid( |
| 100 const DetailOutputMap& inputs, ValidationType validation_type) OVERRIDE { | 103 const DetailOutputMap& inputs, ValidationType validation_type) OVERRIDE { |
| 101 return std::vector<AutofillFieldType>(); | 104 return std::vector<AutofillFieldType>(); |
| 102 } | 105 } |
| 103 | 106 |
| 104 // Increase visibility for testing. | 107 // Increase visibility for testing. |
| 105 AutofillDialogView* view() { return AutofillDialogControllerImpl::view(); } | 108 AutofillDialogView* view() { return AutofillDialogControllerImpl::view(); } |
| 106 | 109 |
| 107 private: | 110 private: |
| 108 // To specify our own metric logger. | 111 // To specify our own metric logger. |
| 109 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { | 112 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { |
| 110 return metric_logger_; | 113 return metric_logger_; |
| 111 } | 114 } |
| 112 | 115 |
| 113 const AutofillMetrics& metric_logger_; | 116 const AutofillMetrics& metric_logger_; |
| 117 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
| 114 | 118 |
| 115 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); | 119 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); |
| 116 }; | 120 }; |
| 117 | 121 |
| 118 } // namespace | 122 } // namespace |
| 119 | 123 |
| 120 class AutofillDialogControllerTest : public InProcessBrowserTest { | 124 class AutofillDialogControllerTest : public InProcessBrowserTest { |
| 121 public: | 125 public: |
| 122 AutofillDialogControllerTest() {} | 126 AutofillDialogControllerTest() {} |
| 123 virtual ~AutofillDialogControllerTest() {} | 127 virtual ~AutofillDialogControllerTest() {} |
| 124 | 128 |
| 125 content::WebContents* GetActiveWebContents() { | 129 content::WebContents* GetActiveWebContents() { |
| 126 return browser()->tab_strip_model()->GetActiveWebContents(); | 130 return browser()->tab_strip_model()->GetActiveWebContents(); |
| 127 } | 131 } |
| 128 | 132 |
| 133 TestAutofillDialogController* CreateController( | |
| 134 const FormData& form, | |
| 135 const AutofillMetrics& metric_logger, | |
| 136 const DialogType dialog_type) { | |
| 137 message_loop_runner_ = new content::MessageLoopRunner; | |
| 138 return new TestAutofillDialogController( | |
| 139 GetActiveWebContents(), form, metric_logger, message_loop_runner_, | |
| 140 dialog_type); | |
| 141 } | |
| 142 | |
| 143 void RunMessageLoop() { | |
| 144 message_loop_runner_->Run(); | |
| 145 } | |
|
Ilya Sherman
2013/04/20 01:19:07
nit: Please leave a blank line after this one.
groby-ooo-7-16
2013/04/20 02:28:37
Done.
| |
| 129 private: | 146 private: |
| 147 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
| 130 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); | 148 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerTest); |
| 131 }; | 149 }; |
| 132 | 150 |
| 133 // TODO(isherman): Enable this test on other platforms once the UI is | 151 // TODO(isherman): Enable this test on other platforms once the UI is |
| 134 // implemented on those platforms. | 152 // implemented on those platforms. |
| 135 #if defined(TOOLKIT_VIEWS) | 153 #if defined(TOOLKIT_VIEWS) |
| 136 #define MAYBE_RequestAutocompleteUiDurationMetrics \ | 154 #define MAYBE_RequestAutocompleteUiDurationMetrics \ |
| 137 RequestAutocompleteUiDurationMetrics | 155 RequestAutocompleteUiDurationMetrics |
| 138 #else | 156 #else |
| 139 #define MAYBE_RequestAutocompleteUiDurationMetrics \ | 157 #define MAYBE_RequestAutocompleteUiDurationMetrics \ |
| 140 DISABLED_RequestAutocompleteUiDurationMetrics | 158 DISABLED_RequestAutocompleteUiDurationMetrics |
| 141 #endif // defined(TOOLKIT_VIEWS) | 159 #endif // defined(TOOLKIT_VIEWS) |
| 142 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, | 160 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, |
| 143 MAYBE_RequestAutocompleteUiDurationMetrics) { | 161 MAYBE_RequestAutocompleteUiDurationMetrics) { |
| 144 FormData form; | 162 FormData form; |
| 145 form.name = ASCIIToUTF16("TestForm"); | 163 form.name = ASCIIToUTF16("TestForm"); |
| 146 form.method = ASCIIToUTF16("POST"); | 164 form.method = ASCIIToUTF16("POST"); |
| 147 form.origin = GURL("http://example.com/form.html"); | 165 form.origin = GURL("http://example.com/form.html"); |
| 148 form.action = GURL("http://example.com/submit.html"); | 166 form.action = GURL("http://example.com/submit.html"); |
| 149 form.user_submitted = true; | 167 form.user_submitted = true; |
| 150 | 168 |
| 151 FormFieldData field; | 169 FormFieldData field; |
| 152 field.autocomplete_attribute = "email"; | 170 field.autocomplete_attribute = "email"; |
| 153 form.fields.push_back(field); | 171 form.fields.push_back(field); |
| 154 | 172 |
| 155 // Submit the form data. | 173 // Submit the form data. |
| 156 { | 174 { |
| 157 MockAutofillMetrics metric_logger; | 175 MockAutofillMetrics metric_logger; |
| 158 TestAutofillDialogController* dialog_controller = | 176 TestAutofillDialogController* dialog_controller = CreateController( |
| 159 new TestAutofillDialogController( | 177 form, metric_logger, DIALOG_TYPE_REQUEST_AUTOCOMPLETE); |
| 160 GetActiveWebContents(), form, metric_logger, | |
| 161 DIALOG_TYPE_REQUEST_AUTOCOMPLETE); | |
| 162 dialog_controller->Show(); | 178 dialog_controller->Show(); |
| 163 dialog_controller->view()->SubmitForTesting(); | 179 dialog_controller->view()->SubmitForTesting(); |
| 164 | 180 |
| 165 content::RunMessageLoop(); | 181 RunMessageLoop(); |
| 166 | 182 |
| 167 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, | 183 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, |
| 168 metric_logger.dialog_dismissal_action()); | 184 metric_logger.dialog_dismissal_action()); |
| 169 EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger.dialog_type()); | 185 EXPECT_EQ(DIALOG_TYPE_REQUEST_AUTOCOMPLETE, metric_logger.dialog_type()); |
| 170 } | 186 } |
| 171 | 187 |
| 172 // Cancel out of the dialog. | 188 // Cancel out of the dialog. |
| 173 { | 189 { |
| 174 MockAutofillMetrics metric_logger; | 190 MockAutofillMetrics metric_logger; |
| 175 TestAutofillDialogController* dialog_controller = | 191 TestAutofillDialogController* dialog_controller = CreateController( |
| 176 new TestAutofillDialogController( | 192 form, metric_logger, DIALOG_TYPE_AUTOCHECKOUT); |
| 177 GetActiveWebContents(), form, metric_logger, | |
| 178 DIALOG_TYPE_AUTOCHECKOUT); | |
| 179 dialog_controller->Show(); | 193 dialog_controller->Show(); |
| 180 dialog_controller->view()->CancelForTesting(); | 194 dialog_controller->view()->CancelForTesting(); |
| 181 | 195 |
| 182 content::RunMessageLoop(); | 196 RunMessageLoop(); |
| 183 | 197 |
| 184 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, | 198 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, |
| 185 metric_logger.dialog_dismissal_action()); | 199 metric_logger.dialog_dismissal_action()); |
| 186 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type()); | 200 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type()); |
| 187 } | 201 } |
| 188 | 202 |
| 189 // Take some other action that dismisses the dialog. | 203 // Take some other action that dismisses the dialog. |
| 190 { | 204 { |
| 191 MockAutofillMetrics metric_logger; | 205 MockAutofillMetrics metric_logger; |
| 192 TestAutofillDialogController* dialog_controller = | 206 TestAutofillDialogController* dialog_controller = CreateController( |
| 193 new TestAutofillDialogController( | 207 form, metric_logger, DIALOG_TYPE_AUTOCHECKOUT); |
| 194 GetActiveWebContents(), form, metric_logger, | |
| 195 DIALOG_TYPE_AUTOCHECKOUT); | |
| 196 dialog_controller->Show(); | 208 dialog_controller->Show(); |
| 197 dialog_controller->Hide(); | 209 dialog_controller->Hide(); |
| 198 | 210 |
| 199 content::RunMessageLoop(); | 211 RunMessageLoop(); |
| 200 | 212 |
| 201 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, | 213 EXPECT_EQ(AutofillMetrics::DIALOG_CANCELED, |
| 202 metric_logger.dialog_dismissal_action()); | 214 metric_logger.dialog_dismissal_action()); |
| 203 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type()); | 215 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type()); |
| 204 } | 216 } |
| 205 | 217 |
| 206 // Test Autocheckout success metrics. | 218 // Test Autocheckout success metrics. |
| 207 { | 219 { |
| 208 MockAutofillMetrics metric_logger; | 220 MockAutofillMetrics metric_logger; |
| 209 TestAutofillDialogController* dialog_controller = | 221 TestAutofillDialogController* dialog_controller = CreateController( |
| 210 new TestAutofillDialogController( | 222 form, metric_logger, DIALOG_TYPE_AUTOCHECKOUT); |
| 211 GetActiveWebContents(), form, metric_logger, | |
| 212 DIALOG_TYPE_AUTOCHECKOUT); | |
| 213 dialog_controller->Show(); | 223 dialog_controller->Show(); |
| 214 dialog_controller->view()->SubmitForTesting(); | 224 dialog_controller->view()->SubmitForTesting(); |
| 215 | 225 |
| 216 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, | 226 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, |
| 217 metric_logger.dialog_dismissal_action()); | 227 metric_logger.dialog_dismissal_action()); |
| 218 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type()); | 228 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type()); |
| 219 | 229 |
| 220 dialog_controller->Hide(); | 230 dialog_controller->Hide(); |
| 221 | 231 |
| 222 content::RunMessageLoop(); | 232 RunMessageLoop(); |
| 223 | 233 |
| 224 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_SUCCEEDED, | 234 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_SUCCEEDED, |
| 225 metric_logger.autocheckout_status()); | 235 metric_logger.autocheckout_status()); |
| 226 } | 236 } |
| 227 | 237 |
| 228 // Test Autocheckout failure metric. | 238 // Test Autocheckout failure metric. |
| 229 { | 239 { |
| 230 MockAutofillMetrics metric_logger; | 240 MockAutofillMetrics metric_logger; |
| 231 TestAutofillDialogController* dialog_controller = | 241 TestAutofillDialogController* dialog_controller = CreateController( |
| 232 new TestAutofillDialogController( | 242 form, metric_logger, DIALOG_TYPE_AUTOCHECKOUT); |
| 233 GetActiveWebContents(), form, metric_logger, | |
| 234 DIALOG_TYPE_AUTOCHECKOUT); | |
| 235 dialog_controller->Show(); | 243 dialog_controller->Show(); |
| 236 dialog_controller->view()->SubmitForTesting(); | 244 dialog_controller->view()->SubmitForTesting(); |
| 237 | 245 |
| 238 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, | 246 EXPECT_EQ(AutofillMetrics::DIALOG_ACCEPTED, |
| 239 metric_logger.dialog_dismissal_action()); | 247 metric_logger.dialog_dismissal_action()); |
| 240 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type()); | 248 EXPECT_EQ(DIALOG_TYPE_AUTOCHECKOUT, metric_logger.dialog_type()); |
| 241 | 249 |
| 242 dialog_controller->OnAutocheckoutError(); | 250 dialog_controller->OnAutocheckoutError(); |
| 243 dialog_controller->view()->CancelForTesting(); | 251 dialog_controller->view()->CancelForTesting(); |
| 244 | 252 |
| 245 content::RunMessageLoop(); | 253 RunMessageLoop(); |
| 246 | 254 |
| 247 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_FAILED, | 255 EXPECT_EQ(AutofillMetrics::AUTOCHECKOUT_FAILED, |
| 248 metric_logger.autocheckout_status()); | 256 metric_logger.autocheckout_status()); |
| 249 } | 257 } |
| 250 } | 258 } |
| 251 | 259 |
| 252 } // namespace autofill | 260 } // namespace autofill |
| OLD | NEW |