diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-17 00:09:23 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-17 00:09:23 +0000 |
commit | dc86957249846fe4420f335933a94b83fb8ee349 (patch) | |
tree | 402301ecc24ad6c29ee26644ced0da4fc360e887 /components | |
parent | a703506e2b37a4c4bd4fdc15024cca320504bb87 (diff) | |
download | chromium_src-dc86957249846fe4420f335933a94b83fb8ee349.zip chromium_src-dc86957249846fe4420f335933a94b83fb8ee349.tar.gz chromium_src-dc86957249846fe4420f335933a94b83fb8ee349.tar.bz2 |
Use content::MessageLoopRunner in a couple of Autofill tests.
BUG=none
Review URL: https://codereview.chromium.org/14096008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194493 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r-- | components/autofill/browser/autofill_manager_unittest.cc | 33 | ||||
-rw-r--r-- | components/autofill/browser/autofill_metrics_unittest.cc | 26 |
2 files changed, 20 insertions, 39 deletions
diff --git a/components/autofill/browser/autofill_manager_unittest.cc b/components/autofill/browser/autofill_manager_unittest.cc index 0daffb0..80b46b0 100644 --- a/components/autofill/browser/autofill_manager_unittest.cc +++ b/components/autofill/browser/autofill_manager_unittest.cc @@ -6,6 +6,7 @@ #include <vector> #include "base/command_line.h" +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" #include "base/prefs/pref_service.h" @@ -41,6 +42,7 @@ #include "content/public/browser/web_contents.h" #include "content/public/test/mock_render_process_host.h" #include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_utils.h" #include "googleurl/src/gurl.h" #include "grit/generated_resources.h" #include "ipc/ipc_test_sink.h" @@ -484,10 +486,7 @@ class TestAutofillManager : public AutofillManager { TestPersonalDataManager* personal_data) : AutofillManager(web_contents, delegate, personal_data), personal_data_(personal_data), - autofill_enabled_(true), - did_finish_async_form_submit_(false), - message_loop_is_running_(false) { - } + autofill_enabled_(true) {} virtual ~TestAutofillManager() {} virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } @@ -520,12 +519,7 @@ class TestAutofillManager : public AutofillManager { const base::TimeTicks& load_time, const base::TimeTicks& interaction_time, const base::TimeTicks& submission_time) OVERRIDE { - if (message_loop_is_running_) { - MessageLoop::current()->Quit(); - message_loop_is_running_ = false; - } else { - did_finish_async_form_submit_ = true; - } + message_loop_runner_->Quit(); // If we have expected field types set, make sure they match. if (!expected_submitted_field_types_.empty()) { @@ -555,16 +549,15 @@ class TestAutofillManager : public AutofillManager { submission_time); } + // Resets the MessageLoopRunner so that it can wait for an asynchronous form + // submission to complete. + void ResetMessageLoopRunner() { + message_loop_runner_ = new content::MessageLoopRunner(); + } + // Wait for the asynchronous OnFormSubmitted() call to complete. void WaitForAsyncFormSubmit() { - if (!did_finish_async_form_submit_) { - // TODO(isherman): It seems silly to need this variable. Is there some - // way I can just query the message loop's state? - message_loop_is_running_ = true; - MessageLoop::current()->Run(); - } else { - did_finish_async_form_submit_ = false; - } + message_loop_runner_->Run(); } virtual void UploadFormData(const FormStructure& submitted_form) OVERRIDE { @@ -633,8 +626,7 @@ class TestAutofillManager : public AutofillManager { std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> > request_autocomplete_results_; - bool did_finish_async_form_submit_; - bool message_loop_is_running_; + scoped_refptr<content::MessageLoopRunner> message_loop_runner_; std::string autocheckout_url_prefix_; std::string submitted_form_signature_; @@ -731,6 +723,7 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness { } void FormSubmitted(const FormData& form) { + autofill_manager_->ResetMessageLoopRunner(); if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) autofill_manager_->WaitForAsyncFormSubmit(); } diff --git a/components/autofill/browser/autofill_metrics_unittest.cc b/components/autofill/browser/autofill_metrics_unittest.cc index 5888b8c..b6df550 100644 --- a/components/autofill/browser/autofill_metrics_unittest.cc +++ b/components/autofill/browser/autofill_metrics_unittest.cc @@ -4,6 +4,7 @@ #include <vector> +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/string16.h" #include "base/time.h" @@ -23,6 +24,7 @@ #include "components/autofill/common/form_field_data.h" #include "components/webdata/common/web_data_results.h" #include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_utils.h" #include "googleurl/src/gurl.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -187,9 +189,7 @@ class TestAutofillManager : public AutofillManager { AutofillManagerDelegate* manager_delegate, TestPersonalDataManager* personal_manager) : AutofillManager(web_contents, manager_delegate, personal_manager), - autofill_enabled_(true), - did_finish_async_form_submit_(false), - message_loop_is_running_(false) { + autofill_enabled_(true) { set_metric_logger(new testing::NiceMock<MockAutofillMetrics>); } virtual ~TestAutofillManager() {} @@ -226,18 +226,12 @@ class TestAutofillManager : public AutofillManager { } void FormSubmitted(const FormData& form, const TimeTicks& timestamp) { + message_loop_runner_ = new content::MessageLoopRunner(); if (!OnFormSubmitted(form, timestamp)) return; // Wait for the asynchronous FormSubmitted() call to complete. - if (!did_finish_async_form_submit_) { - // TODO(isherman): It seems silly to need this variable. Is there some - // way I can just query the message loop's state? - message_loop_is_running_ = true; - MessageLoop::current()->Run(); - } else { - did_finish_async_form_submit_ = false; - } + message_loop_runner_->Run(); } virtual void UploadFormDataAsyncCallback( @@ -245,12 +239,7 @@ class TestAutofillManager : public AutofillManager { const base::TimeTicks& load_time, const base::TimeTicks& interaction_time, const base::TimeTicks& submission_time) OVERRIDE { - if (message_loop_is_running_) { - MessageLoop::current()->Quit(); - message_loop_is_running_ = false; - } else { - did_finish_async_form_submit_ = true; - } + message_loop_runner_->Quit(); AutofillManager::UploadFormDataAsyncCallback(submitted_form, load_time, @@ -260,8 +249,7 @@ class TestAutofillManager : public AutofillManager { private: bool autofill_enabled_; - bool did_finish_async_form_submit_; - bool message_loop_is_running_; + scoped_refptr<content::MessageLoopRunner> message_loop_runner_; DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); }; |