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 /chrome/browser/automation | |
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
Diffstat (limited to 'chrome/browser/automation')
4 files changed, 73 insertions, 0 deletions
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); |