Commit dc869572 authored by isherman@chromium.org's avatar isherman@chromium.org

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
parent a703506e
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <vector> #include <vector>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h" #include "base/memory/scoped_vector.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
...@@ -41,6 +42,7 @@ ...@@ -41,6 +42,7 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/mock_render_process_host.h" #include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_utils.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "ipc/ipc_test_sink.h" #include "ipc/ipc_test_sink.h"
...@@ -484,10 +486,7 @@ class TestAutofillManager : public AutofillManager { ...@@ -484,10 +486,7 @@ class TestAutofillManager : public AutofillManager {
TestPersonalDataManager* personal_data) TestPersonalDataManager* personal_data)
: AutofillManager(web_contents, delegate, personal_data), : AutofillManager(web_contents, delegate, personal_data),
personal_data_(personal_data), personal_data_(personal_data),
autofill_enabled_(true), autofill_enabled_(true) {}
did_finish_async_form_submit_(false),
message_loop_is_running_(false) {
}
virtual ~TestAutofillManager() {} virtual ~TestAutofillManager() {}
virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; }
...@@ -520,12 +519,7 @@ class TestAutofillManager : public AutofillManager { ...@@ -520,12 +519,7 @@ class TestAutofillManager : public AutofillManager {
const base::TimeTicks& load_time, const base::TimeTicks& load_time,
const base::TimeTicks& interaction_time, const base::TimeTicks& interaction_time,
const base::TimeTicks& submission_time) OVERRIDE { const base::TimeTicks& submission_time) OVERRIDE {
if (message_loop_is_running_) { message_loop_runner_->Quit();
MessageLoop::current()->Quit();
message_loop_is_running_ = false;
} else {
did_finish_async_form_submit_ = true;
}
// If we have expected field types set, make sure they match. // If we have expected field types set, make sure they match.
if (!expected_submitted_field_types_.empty()) { if (!expected_submitted_field_types_.empty()) {
...@@ -555,16 +549,15 @@ class TestAutofillManager : public AutofillManager { ...@@ -555,16 +549,15 @@ class TestAutofillManager : public AutofillManager {
submission_time); 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. // Wait for the asynchronous OnFormSubmitted() call to complete.
void WaitForAsyncFormSubmit() { void WaitForAsyncFormSubmit() {
if (!did_finish_async_form_submit_) { message_loop_runner_->Run();
// 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;
}
} }
virtual void UploadFormData(const FormStructure& submitted_form) OVERRIDE { virtual void UploadFormData(const FormStructure& submitted_form) OVERRIDE {
...@@ -633,8 +626,7 @@ class TestAutofillManager : public AutofillManager { ...@@ -633,8 +626,7 @@ class TestAutofillManager : public AutofillManager {
std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> > std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> >
request_autocomplete_results_; request_autocomplete_results_;
bool did_finish_async_form_submit_; scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
bool message_loop_is_running_;
std::string autocheckout_url_prefix_; std::string autocheckout_url_prefix_;
std::string submitted_form_signature_; std::string submitted_form_signature_;
...@@ -731,6 +723,7 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness { ...@@ -731,6 +723,7 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness {
} }
void FormSubmitted(const FormData& form) { void FormSubmitted(const FormData& form) {
autofill_manager_->ResetMessageLoopRunner();
if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now()))
autofill_manager_->WaitForAsyncFormSubmit(); autofill_manager_->WaitForAsyncFormSubmit();
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <vector> #include <vector>
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/string16.h" #include "base/string16.h"
#include "base/time.h" #include "base/time.h"
...@@ -23,6 +24,7 @@ ...@@ -23,6 +24,7 @@
#include "components/autofill/common/form_field_data.h" #include "components/autofill/common/form_field_data.h"
#include "components/webdata/common/web_data_results.h" #include "components/webdata/common/web_data_results.h"
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_utils.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -187,9 +189,7 @@ class TestAutofillManager : public AutofillManager { ...@@ -187,9 +189,7 @@ class TestAutofillManager : public AutofillManager {
AutofillManagerDelegate* manager_delegate, AutofillManagerDelegate* manager_delegate,
TestPersonalDataManager* personal_manager) TestPersonalDataManager* personal_manager)
: AutofillManager(web_contents, manager_delegate, personal_manager), : AutofillManager(web_contents, manager_delegate, personal_manager),
autofill_enabled_(true), autofill_enabled_(true) {
did_finish_async_form_submit_(false),
message_loop_is_running_(false) {
set_metric_logger(new testing::NiceMock<MockAutofillMetrics>); set_metric_logger(new testing::NiceMock<MockAutofillMetrics>);
} }
virtual ~TestAutofillManager() {} virtual ~TestAutofillManager() {}
...@@ -226,18 +226,12 @@ class TestAutofillManager : public AutofillManager { ...@@ -226,18 +226,12 @@ class TestAutofillManager : public AutofillManager {
} }
void FormSubmitted(const FormData& form, const TimeTicks& timestamp) { void FormSubmitted(const FormData& form, const TimeTicks& timestamp) {
message_loop_runner_ = new content::MessageLoopRunner();
if (!OnFormSubmitted(form, timestamp)) if (!OnFormSubmitted(form, timestamp))
return; return;
// Wait for the asynchronous FormSubmitted() call to complete. // Wait for the asynchronous FormSubmitted() call to complete.
if (!did_finish_async_form_submit_) { message_loop_runner_->Run();
// 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;
}
} }
virtual void UploadFormDataAsyncCallback( virtual void UploadFormDataAsyncCallback(
...@@ -245,12 +239,7 @@ class TestAutofillManager : public AutofillManager { ...@@ -245,12 +239,7 @@ class TestAutofillManager : public AutofillManager {
const base::TimeTicks& load_time, const base::TimeTicks& load_time,
const base::TimeTicks& interaction_time, const base::TimeTicks& interaction_time,
const base::TimeTicks& submission_time) OVERRIDE { const base::TimeTicks& submission_time) OVERRIDE {
if (message_loop_is_running_) { message_loop_runner_->Quit();
MessageLoop::current()->Quit();
message_loop_is_running_ = false;
} else {
did_finish_async_form_submit_ = true;
}
AutofillManager::UploadFormDataAsyncCallback(submitted_form, AutofillManager::UploadFormDataAsyncCallback(submitted_form,
load_time, load_time,
...@@ -260,8 +249,7 @@ class TestAutofillManager : public AutofillManager { ...@@ -260,8 +249,7 @@ class TestAutofillManager : public AutofillManager {
private: private:
bool autofill_enabled_; bool autofill_enabled_;
bool did_finish_async_form_submit_; scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
bool message_loop_is_running_;
DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment