| 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/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/api/infobars/infobar_service.h" | 11 #include "chrome/browser/api/infobars/infobar_service.h" |
| 12 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 12 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
| 13 #include "chrome/browser/autofill/autofill_common_test.h" | 13 #include "chrome/browser/autofill/autofill_common_test.h" |
| 14 #include "chrome/browser/autofill/autofill_manager.h" | 14 #include "chrome/browser/autofill/autofill_manager.h" |
| 15 #include "chrome/browser/autofill/autofill_manager_delegate.h" |
| 15 #include "chrome/browser/autofill/autofill_metrics.h" | 16 #include "chrome/browser/autofill/autofill_metrics.h" |
| 16 #include "chrome/browser/autofill/personal_data_manager.h" | 17 #include "chrome/browser/autofill/personal_data_manager.h" |
| 17 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 18 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 18 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | 19 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 20 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" | 21 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" |
| 21 #include "chrome/browser/webdata/web_data_service.h" | 22 #include "chrome/browser/webdata/web_data_service.h" |
| 22 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| 23 #include "content/public/test/test_browser_thread.h" | 24 #include "content/public/test/test_browser_thread.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 server_experiment_id_ = server_experiment_id; | 167 server_experiment_id_ = server_experiment_id; |
| 167 } | 168 } |
| 168 | 169 |
| 169 private: | 170 private: |
| 170 std::string server_experiment_id_; | 171 std::string server_experiment_id_; |
| 171 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); | 172 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); |
| 172 }; | 173 }; |
| 173 | 174 |
| 174 class TestAutofillManager : public AutofillManager { | 175 class TestAutofillManager : public AutofillManager { |
| 175 public: | 176 public: |
| 176 TestAutofillManager(TabContents* tab_contents, | 177 TestAutofillManager(autofill::AutofillManagerDelegate* manager_delegate, |
| 178 TabContents* tab_contents, |
| 177 TestPersonalDataManager* personal_manager) | 179 TestPersonalDataManager* personal_manager) |
| 178 : AutofillManager(&autofill_delegate_, tab_contents, personal_manager), | 180 : AutofillManager(manager_delegate, tab_contents, personal_manager), |
| 179 autofill_delegate_(tab_contents), | |
| 180 autofill_enabled_(true), | 181 autofill_enabled_(true), |
| 181 did_finish_async_form_submit_(false), | 182 did_finish_async_form_submit_(false), |
| 182 message_loop_is_running_(false) { | 183 message_loop_is_running_(false) { |
| 183 set_metric_logger(new MockAutofillMetrics); | 184 set_metric_logger(new MockAutofillMetrics); |
| 184 } | 185 } |
| 185 | 186 |
| 186 virtual bool IsAutofillEnabled() const { return autofill_enabled_; } | 187 virtual bool IsAutofillEnabled() const { return autofill_enabled_; } |
| 187 | 188 |
| 188 void set_autofill_enabled(bool autofill_enabled) { | 189 void set_autofill_enabled(bool autofill_enabled) { |
| 189 autofill_enabled_ = autofill_enabled; | 190 autofill_enabled_ = autofill_enabled; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 AutofillManager::UploadFormDataAsyncCallback(submitted_form, | 241 AutofillManager::UploadFormDataAsyncCallback(submitted_form, |
| 241 load_time, | 242 load_time, |
| 242 interaction_time, | 243 interaction_time, |
| 243 submission_time); | 244 submission_time); |
| 244 } | 245 } |
| 245 | 246 |
| 246 private: | 247 private: |
| 247 // AutofillManager is ref counted. | 248 // AutofillManager is ref counted. |
| 248 virtual ~TestAutofillManager() {} | 249 virtual ~TestAutofillManager() {} |
| 249 | 250 |
| 250 TabAutofillManagerDelegate autofill_delegate_; | |
| 251 | |
| 252 bool autofill_enabled_; | 251 bool autofill_enabled_; |
| 253 bool did_finish_async_form_submit_; | 252 bool did_finish_async_form_submit_; |
| 254 bool message_loop_is_running_; | 253 bool message_loop_is_running_; |
| 255 | 254 |
| 256 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 255 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
| 257 }; | 256 }; |
| 258 | 257 |
| 259 } // namespace | 258 } // namespace |
| 260 | 259 |
| 261 class AutofillMetricsTest : public TabContentsTestHarness { | 260 class AutofillMetricsTest : public TabContentsTestHarness { |
| 262 public: | 261 public: |
| 263 AutofillMetricsTest(); | 262 AutofillMetricsTest(); |
| 264 virtual ~AutofillMetricsTest(); | 263 virtual ~AutofillMetricsTest(); |
| 265 | 264 |
| 266 virtual void SetUp() OVERRIDE; | 265 virtual void SetUp() OVERRIDE; |
| 267 virtual void TearDown() OVERRIDE; | 266 virtual void TearDown() OVERRIDE; |
| 268 | 267 |
| 269 protected: | 268 protected: |
| 270 AutofillCCInfoBarDelegate* CreateDelegate(MockAutofillMetrics* metric_logger, | 269 AutofillCCInfoBarDelegate* CreateDelegate(MockAutofillMetrics* metric_logger, |
| 271 CreditCard** created_card); | 270 CreditCard** created_card); |
| 272 | 271 |
| 273 content::TestBrowserThread ui_thread_; | 272 content::TestBrowserThread ui_thread_; |
| 274 content::TestBrowserThread file_thread_; | 273 content::TestBrowserThread file_thread_; |
| 275 | 274 |
| 276 scoped_refptr<TestAutofillManager> autofill_manager_; | 275 scoped_refptr<TestAutofillManager> autofill_manager_; |
| 276 scoped_ptr<TabAutofillManagerDelegate> manager_delegate_; |
| 277 TestPersonalDataManager personal_data_; | 277 TestPersonalDataManager personal_data_; |
| 278 | 278 |
| 279 private: | 279 private: |
| 280 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); | 280 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); |
| 281 }; | 281 }; |
| 282 | 282 |
| 283 AutofillMetricsTest::AutofillMetricsTest() | 283 AutofillMetricsTest::AutofillMetricsTest() |
| 284 : TabContentsTestHarness(), | 284 : TabContentsTestHarness(), |
| 285 ui_thread_(BrowserThread::UI, &message_loop_), | 285 ui_thread_(BrowserThread::UI, &message_loop_), |
| 286 file_thread_(BrowserThread::FILE) { | 286 file_thread_(BrowserThread::FILE) { |
| 287 } | 287 } |
| 288 | 288 |
| 289 AutofillMetricsTest::~AutofillMetricsTest() { | 289 AutofillMetricsTest::~AutofillMetricsTest() { |
| 290 // Order of destruction is important as AutofillManager relies on | 290 // Order of destruction is important as AutofillManager relies on |
| 291 // PersonalDataManager to be around when it gets destroyed. | 291 // PersonalDataManager to be around when it gets destroyed. |
| 292 autofill_manager_ = NULL; | 292 autofill_manager_ = NULL; |
| 293 } | 293 } |
| 294 | 294 |
| 295 void AutofillMetricsTest::SetUp() { | 295 void AutofillMetricsTest::SetUp() { |
| 296 Profile* profile = new TestingProfile(); | 296 Profile* profile = new TestingProfile(); |
| 297 browser_context_.reset(profile); | 297 browser_context_.reset(profile); |
| 298 PersonalDataManagerFactory::GetInstance()->SetTestingFactory( | 298 PersonalDataManagerFactory::GetInstance()->SetTestingFactory( |
| 299 profile, NULL); | 299 profile, NULL); |
| 300 | 300 |
| 301 TabContentsTestHarness::SetUp(); | 301 TabContentsTestHarness::SetUp(); |
| 302 autofill_manager_ = new TestAutofillManager(tab_contents(), | 302 manager_delegate_.reset(new TabAutofillManagerDelegate(tab_contents())); |
| 303 autofill_manager_ = new TestAutofillManager(manager_delegate_.get(), |
| 304 tab_contents(), |
| 303 &personal_data_); | 305 &personal_data_); |
| 304 | 306 |
| 305 file_thread_.Start(); | 307 file_thread_.Start(); |
| 306 } | 308 } |
| 307 | 309 |
| 308 void AutofillMetricsTest::TearDown() { | 310 void AutofillMetricsTest::TearDown() { |
| 309 file_thread_.Stop(); | 311 file_thread_.Stop(); |
| 310 TabContentsTestHarness::TearDown(); | 312 TabContentsTestHarness::TearDown(); |
| 311 } | 313 } |
| 312 | 314 |
| (...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 1468 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |
| 1467 TimeTicks::FromInternalValue(3)); | 1469 TimeTicks::FromInternalValue(3)); |
| 1468 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); | 1470 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); |
| 1469 autofill_manager_->Reset(); | 1471 autofill_manager_->Reset(); |
| 1470 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); | 1472 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); |
| 1471 } | 1473 } |
| 1472 | 1474 |
| 1473 // Restore the global Gmock verbosity level to its default value. | 1475 // Restore the global Gmock verbosity level to its default value. |
| 1474 ::testing::FLAGS_gmock_verbose = "warning"; | 1476 ::testing::FLAGS_gmock_verbose = "warning"; |
| 1475 } | 1477 } |
| OLD | NEW |