| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" |
| 7 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/string16.h" | 9 #include "base/string16.h" |
| 9 #include "base/time.h" | 10 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 12 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
| 12 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 13 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 13 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | 14 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" |
| 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 15 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 16 #include "components/autofill/browser/autocheckout_page_meta_data.h" | 17 #include "components/autofill/browser/autocheckout_page_meta_data.h" |
| 17 #include "components/autofill/browser/autofill_common_test.h" | 18 #include "components/autofill/browser/autofill_common_test.h" |
| 18 #include "components/autofill/browser/autofill_manager.h" | 19 #include "components/autofill/browser/autofill_manager.h" |
| 19 #include "components/autofill/browser/autofill_manager_delegate.h" | 20 #include "components/autofill/browser/autofill_manager_delegate.h" |
| 20 #include "components/autofill/browser/autofill_metrics.h" | 21 #include "components/autofill/browser/autofill_metrics.h" |
| 21 #include "components/autofill/browser/personal_data_manager.h" | 22 #include "components/autofill/browser/personal_data_manager.h" |
| 22 #include "components/autofill/common/form_data.h" | 23 #include "components/autofill/common/form_data.h" |
| 23 #include "components/autofill/common/form_field_data.h" | 24 #include "components/autofill/common/form_field_data.h" |
| 24 #include "components/webdata/common/web_data_results.h" | 25 #include "components/webdata/common/web_data_results.h" |
| 25 #include "content/public/test/test_browser_thread.h" | 26 #include "content/public/test/test_browser_thread.h" |
| 27 #include "content/public/test/test_utils.h" |
| 26 #include "googleurl/src/gurl.h" | 28 #include "googleurl/src/gurl.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "ui/gfx/rect.h" | 31 #include "ui/gfx/rect.h" |
| 30 | 32 |
| 31 using content::BrowserThread; | 33 using content::BrowserThread; |
| 32 using ::testing::_; | 34 using ::testing::_; |
| 33 using ::testing::AnyNumber; | 35 using ::testing::AnyNumber; |
| 34 using ::testing::Mock; | 36 using ::testing::Mock; |
| 35 using base::TimeTicks; | 37 using base::TimeTicks; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 std::string server_experiment_id_; | 182 std::string server_experiment_id_; |
| 181 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); | 183 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); |
| 182 }; | 184 }; |
| 183 | 185 |
| 184 class TestAutofillManager : public AutofillManager { | 186 class TestAutofillManager : public AutofillManager { |
| 185 public: | 187 public: |
| 186 TestAutofillManager(content::WebContents* web_contents, | 188 TestAutofillManager(content::WebContents* web_contents, |
| 187 AutofillManagerDelegate* manager_delegate, | 189 AutofillManagerDelegate* manager_delegate, |
| 188 TestPersonalDataManager* personal_manager) | 190 TestPersonalDataManager* personal_manager) |
| 189 : AutofillManager(web_contents, manager_delegate, personal_manager), | 191 : AutofillManager(web_contents, manager_delegate, personal_manager), |
| 190 autofill_enabled_(true), | 192 autofill_enabled_(true) { |
| 191 did_finish_async_form_submit_(false), | |
| 192 message_loop_is_running_(false) { | |
| 193 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>); | 193 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>); |
| 194 } | 194 } |
| 195 virtual ~TestAutofillManager() {} | 195 virtual ~TestAutofillManager() {} |
| 196 | 196 |
| 197 virtual std::string GetAutocheckoutURLPrefix() const OVERRIDE { | 197 virtual std::string GetAutocheckoutURLPrefix() const OVERRIDE { |
| 198 return std::string(); | 198 return std::string(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } | 201 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } |
| 202 | 202 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 219 } | 219 } |
| 220 | 220 |
| 221 // |form_structure| will be owned by |form_structures()|. | 221 // |form_structure| will be owned by |form_structures()|. |
| 222 TestFormStructure* form_structure = new TestFormStructure(empty_form); | 222 TestFormStructure* form_structure = new TestFormStructure(empty_form); |
| 223 form_structure->SetFieldTypes(heuristic_types, server_types); | 223 form_structure->SetFieldTypes(heuristic_types, server_types); |
| 224 form_structure->set_server_experiment_id(experiment_id); | 224 form_structure->set_server_experiment_id(experiment_id); |
| 225 form_structures()->push_back(form_structure); | 225 form_structures()->push_back(form_structure); |
| 226 } | 226 } |
| 227 | 227 |
| 228 void FormSubmitted(const FormData& form, const TimeTicks& timestamp) { | 228 void FormSubmitted(const FormData& form, const TimeTicks& timestamp) { |
| 229 message_loop_runner_ = new content::MessageLoopRunner(); |
| 229 if (!OnFormSubmitted(form, timestamp)) | 230 if (!OnFormSubmitted(form, timestamp)) |
| 230 return; | 231 return; |
| 231 | 232 |
| 232 // Wait for the asynchronous FormSubmitted() call to complete. | 233 // Wait for the asynchronous FormSubmitted() call to complete. |
| 233 if (!did_finish_async_form_submit_) { | 234 message_loop_runner_->Run(); |
| 234 // TODO(isherman): It seems silly to need this variable. Is there some | |
| 235 // way I can just query the message loop's state? | |
| 236 message_loop_is_running_ = true; | |
| 237 MessageLoop::current()->Run(); | |
| 238 } else { | |
| 239 did_finish_async_form_submit_ = false; | |
| 240 } | |
| 241 } | 235 } |
| 242 | 236 |
| 243 virtual void UploadFormDataAsyncCallback( | 237 virtual void UploadFormDataAsyncCallback( |
| 244 const FormStructure* submitted_form, | 238 const FormStructure* submitted_form, |
| 245 const base::TimeTicks& load_time, | 239 const base::TimeTicks& load_time, |
| 246 const base::TimeTicks& interaction_time, | 240 const base::TimeTicks& interaction_time, |
| 247 const base::TimeTicks& submission_time) OVERRIDE { | 241 const base::TimeTicks& submission_time) OVERRIDE { |
| 248 if (message_loop_is_running_) { | 242 message_loop_runner_->Quit(); |
| 249 MessageLoop::current()->Quit(); | |
| 250 message_loop_is_running_ = false; | |
| 251 } else { | |
| 252 did_finish_async_form_submit_ = true; | |
| 253 } | |
| 254 | 243 |
| 255 AutofillManager::UploadFormDataAsyncCallback(submitted_form, | 244 AutofillManager::UploadFormDataAsyncCallback(submitted_form, |
| 256 load_time, | 245 load_time, |
| 257 interaction_time, | 246 interaction_time, |
| 258 submission_time); | 247 submission_time); |
| 259 } | 248 } |
| 260 | 249 |
| 261 private: | 250 private: |
| 262 bool autofill_enabled_; | 251 bool autofill_enabled_; |
| 263 bool did_finish_async_form_submit_; | 252 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 264 bool message_loop_is_running_; | |
| 265 | 253 |
| 266 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 254 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
| 267 }; | 255 }; |
| 268 | 256 |
| 269 } // namespace | 257 } // namespace |
| 270 | 258 |
| 271 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { | 259 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { |
| 272 public: | 260 public: |
| 273 AutofillMetricsTest(); | 261 AutofillMetricsTest(); |
| 274 virtual ~AutofillMetricsTest(); | 262 virtual ~AutofillMetricsTest(); |
| (...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1563 TimeTicks::FromInternalValue(5)); | 1551 TimeTicks::FromInternalValue(5)); |
| 1564 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 1552 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |
| 1565 TimeTicks::FromInternalValue(3)); | 1553 TimeTicks::FromInternalValue(3)); |
| 1566 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); | 1554 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); |
| 1567 autofill_manager_->Reset(); | 1555 autofill_manager_->Reset(); |
| 1568 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); | 1556 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); |
| 1569 } | 1557 } |
| 1570 } | 1558 } |
| 1571 | 1559 |
| 1572 } // namespace autofill | 1560 } // namespace autofill |
| OLD | NEW |