diff options
author | jknotten@chromium.org <jknotten@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-24 08:57:13 +0000 |
---|---|---|
committer | jknotten@chromium.org <jknotten@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-24 08:57:13 +0000 |
commit | f51411b225a29bfb3d97fc011fc181c2f2ddf021 (patch) | |
tree | e273d72719a3879e5b0daac5281ef4bb1035d66d | |
parent | 34c2eee08d599451fb1d63af28944e9d355f1c92 (diff) | |
download | chromium_src-f51411b225a29bfb3d97fc011fc181c2f2ddf021.zip chromium_src-f51411b225a29bfb3d97fc011fc181c2f2ddf021.tar.gz chromium_src-f51411b225a29bfb3d97fc011fc181c2f2ddf021.tar.bz2 |
Improve flaky ui_test AutomationProxyVisibleTest.AutocompleteMatchesTest
The omnibox requires that it is focused before text input to it will
kick off the autocompletion providers. We add code
(edit->WaitForFocus()) to the test to wait for the focus to be obtained
before setting the omnibox’s text input and proceeding with the rest of
the test.
BUG=19876
TEST=Existing
Review URL: http://codereview.chromium.org/3348021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60443 0039d316-1c4b-4281-b951-d872f2087c98
10 files changed, 107 insertions, 23 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc index 3201f2a..49b687b 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.cc +++ b/chrome/browser/autocomplete/autocomplete_edit.cc @@ -448,6 +448,10 @@ const AutocompleteResult& AutocompleteEditModel::result() const { void AutocompleteEditModel::OnSetFocus(bool control_down) { has_focus_ = true; control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; + NotificationService::current()->Notify( + NotificationType::AUTOCOMPLETE_EDIT_FOCUSED, + Source<AutocompleteEditModel>(this), + NotificationService::NoDetails()); } void AutocompleteEditModel::OnKillFocus() { diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index f927c50..6628cf1 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -1309,3 +1309,24 @@ void SavePackageNotificationObserver::Observe( } } +AutocompleteEditFocusedObserver::AutocompleteEditFocusedObserver( + AutomationProvider* automation, + AutocompleteEditModel* autocomplete_edit, + IPC::Message* reply_message) + : automation_(automation), + reply_message_(reply_message), + autocomplete_edit_model_(autocomplete_edit) { + Source<AutocompleteEditModel> source(autocomplete_edit); + registrar_.Add(this, NotificationType::AUTOCOMPLETE_EDIT_FOCUSED, source); +} + +void AutocompleteEditFocusedObserver::Observe( + NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK(type == NotificationType::AUTOCOMPLETE_EDIT_FOCUSED); + AutomationMsg_WaitForAutocompleteEditFocus::WriteReplyParams( + reply_message_, true); + automation_->Send(reply_message_); + delete this; +} diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h index 949a594..e03f8a3 100644 --- a/chrome/browser/automation/automation_provider_observers.h +++ b/chrome/browser/automation/automation_provider_observers.h @@ -26,6 +26,7 @@ #include "chrome/common/notification_type.h" #include "chrome/test/automation/automation_messages.h" +class AutocompleteEditModel; class AutomationProvider; class Browser; class Extension; @@ -862,4 +863,25 @@ class SavePackageNotificationObserver : public NotificationObserver { DISALLOW_COPY_AND_ASSIGN(SavePackageNotificationObserver); }; +// Allows automation provider to wait until the autocomplete edit +// has received focus +class AutocompleteEditFocusedObserver : public NotificationObserver { + public: + AutocompleteEditFocusedObserver(AutomationProvider* automation, + AutocompleteEditModel* autocomplete_edit, + IPC::Message* reply_message); + + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + private: + NotificationRegistrar registrar_; + AutomationProvider* automation_; + IPC::Message* reply_message_; + AutocompleteEditModel* autocomplete_edit_model_; + + DISALLOW_COPY_AND_ASSIGN(AutocompleteEditFocusedObserver); +}; + #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_ diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index cecdeb7..07865e6 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -306,6 +306,8 @@ void TestingAutomationProvider::OnMessageReceived( AutocompleteEditIsQueryInProgress) IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetMatches, AutocompleteEditGetMatches) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForAutocompleteEditFocus, + WaitForAutocompleteEditFocus) IPC_MESSAGE_HANDLER(AutomationMsg_ApplyAccelerator, ApplyAccelerator) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation, ExecuteJavascript) @@ -1111,6 +1113,30 @@ void TestingAutomationProvider::AutocompleteEditGetMatches( } } +// Waits for the autocomplete edit to receive focus +void TestingAutomationProvider::WaitForAutocompleteEditFocus( + int autocomplete_edit_handle, + IPC::Message* reply_message) { + if (!autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { + AutomationMsg_WaitForAutocompleteEditFocus::WriteReplyParams( + reply_message_, false); + Send(reply_message); + return; + } + + AutocompleteEditModel* model = autocomplete_edit_tracker_-> + GetResource(autocomplete_edit_handle)-> model(); + if (model->has_focus()) { + AutomationMsg_WaitForAutocompleteEditFocus::WriteReplyParams( + reply_message, true); + Send(reply_message); + return; + } + + // The observer deletes itself when the notification arrives. + new AutocompleteEditFocusedObserver(this, model, reply_message); +} + void TestingAutomationProvider::GetAutocompleteEditForBrowser( int browser_handle, bool* success, diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h index 8099884..07418a6 100644 --- a/chrome/browser/automation/testing_automation_provider.h +++ b/chrome/browser/automation/testing_automation_provider.h @@ -141,6 +141,10 @@ class TestingAutomationProvider : public AutomationProvider, bool* success, std::vector<AutocompleteMatchData>* matches); + // Waits for the autocomplete edit to receive focus + void WaitForAutocompleteEditFocus(int autocomplete_edit_handle, + IPC::Message* reply_message); + // Deprecated. void ApplyAccelerator(int handle, int id); diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h index 167ca6c..c90d54a 100644 --- a/chrome/common/notification_type.h +++ b/chrome/common/notification_type.h @@ -724,6 +724,9 @@ class NotificationType { // Sent by the autocomplete edit when it is destroyed. AUTOCOMPLETE_EDIT_DESTROYED, + // Sent by the autocomplete edit when it is focused. + AUTOCOMPLETE_EDIT_FOCUSED, + // Sent when the main Google URL has been updated. Some services cache // this value and need to update themselves when it changes. See // google_util::GetGoogleURLAndUpdateIfNecessary(). diff --git a/chrome/test/automation/autocomplete_edit_proxy.cc b/chrome/test/automation/autocomplete_edit_proxy.cc index 59c64ba..5bfd13c 100644 --- a/chrome/test/automation/autocomplete_edit_proxy.cc +++ b/chrome/test/automation/autocomplete_edit_proxy.cc @@ -20,23 +20,27 @@ bool AutocompleteEditProxy::GetText(std::wstring* text) const { NOTREACHED(); return false; } - bool result = false; - - sender_->Send(new AutomationMsg_AutocompleteEditGetText(0, handle_, &result, - text)); - + sender_->Send(new AutomationMsg_AutocompleteEditGetText( + 0, handle_, &result, text)); return result; } -bool AutocompleteEditProxy::SetText(const std::wstring& text) { +bool AutocompleteEditProxy::WaitForFocus() const { if (!is_valid()) return false; + bool edit_exists = false; + sender_->Send(new AutomationMsg_WaitForAutocompleteEditFocus( + 0, handle_, &edit_exists)); + return edit_exists; +} +bool AutocompleteEditProxy::SetText(const std::wstring& text) { + if (!is_valid()) + return false; bool result = false; - - sender_->Send(new AutomationMsg_AutocompleteEditSetText(0, handle_, text, - &result)); + sender_->Send(new AutomationMsg_AutocompleteEditSetText( + 0, handle_, text, &result)); return result; } @@ -47,18 +51,15 @@ bool AutocompleteEditProxy::IsQueryInProgress(bool* query_in_progress) const { NOTREACHED(); return false; } - bool edit_exists = false; - - sender_->Send( - new AutomationMsg_AutocompleteEditIsQueryInProgress( - 0, handle_, &edit_exists, query_in_progress)); - + sender_->Send(new AutomationMsg_AutocompleteEditIsQueryInProgress( + 0, handle_, &edit_exists, query_in_progress)); return edit_exists; } - bool AutocompleteEditProxy::WaitForQuery(int wait_timeout_ms) const { + // TODO(jknotten): use a delayed message / observer instead. + // See, for example, AutocompleteEditProxy::WaitForFocus. const TimeTicks start = TimeTicks::Now(); const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout_ms); bool query_in_progress; @@ -78,11 +79,8 @@ bool AutocompleteEditProxy::GetAutocompleteMatches(Matches* matches) const { NOTREACHED(); return false; } - bool edit_exists = false; - sender_->Send(new AutomationMsg_AutocompleteEditGetMatches( 0, handle_, &edit_exists, matches)); - return edit_exists; } diff --git a/chrome/test/automation/autocomplete_edit_proxy.h b/chrome/test/automation/autocomplete_edit_proxy.h index 04f63d9..cfcf291 100644 --- a/chrome/test/automation/autocomplete_edit_proxy.h +++ b/chrome/test/automation/autocomplete_edit_proxy.h @@ -142,6 +142,9 @@ class AutocompleteEditProxy : public AutomationResourceProxy { // Gets a list of autocomplete matches that have been gathered so far. bool GetAutocompleteMatches(Matches* matches) const; + // Waits for the autocomplete edit to receive focus. + bool WaitForFocus() const; + // Waits for all queries to autocomplete providers to complete. // |wait_timeout_ms| gives the number of milliseconds to wait for the query // to finish. Returns false if IPC call failed or if the function times out. diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h index 2664ee6..537067f 100644 --- a/chrome/test/automation/automation_messages_internal.h +++ b/chrome/test/automation/automation_messages_internal.h @@ -1436,4 +1436,9 @@ IPC_BEGIN_MESSAGES(Automation) int /* target count */, bool /* success */) + // Waits for the autocomplete edit to receive focus. + IPC_SYNC_MESSAGE_ROUTED1_1(AutomationMsg_WaitForAutocompleteEditFocus, + int /* autocomplete edit handle */, + bool /* success */) + IPC_END_MESSAGES(Automation) diff --git a/chrome/test/automation/automation_proxy_uitest.cc b/chrome/test/automation/automation_proxy_uitest.cc index 614f37b..8c19ac7 100644 --- a/chrome/test/automation/automation_proxy_uitest.cc +++ b/chrome/test/automation/automation_proxy_uitest.cc @@ -1353,9 +1353,6 @@ TEST_F(AutomationProxyTest, AutocompleteParallelProxy) { #if defined(OS_MACOSX) // TODO(port): Implement AutocompleteEditProxy on Mac. #define AutocompleteMatchesTest DISABLED_AutocompleteMatchesTest -#else -// So flaky, http://crbug.com/19876. -#define AutocompleteMatchesTest FLAKY_AutocompleteMatchesTest #endif TEST_F(AutomationProxyVisibleTest, AutocompleteMatchesTest) { scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); @@ -1363,8 +1360,9 @@ TEST_F(AutomationProxyVisibleTest, AutocompleteMatchesTest) { scoped_refptr<AutocompleteEditProxy> edit( browser->GetAutocompleteEdit()); ASSERT_TRUE(edit.get()); - EXPECT_TRUE(browser->ApplyAccelerator(IDC_FOCUS_LOCATION)); EXPECT_TRUE(edit->is_valid()); + EXPECT_TRUE(browser->ApplyAccelerator(IDC_FOCUS_LOCATION)); + ASSERT_TRUE(edit->WaitForFocus()); EXPECT_TRUE(edit->SetText(L"Roflcopter")); EXPECT_TRUE(edit->WaitForQuery(action_max_timeout_ms())); bool query_in_progress; |