diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-04 08:58:19 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-04 08:58:19 +0000 |
commit | 7d5c3acd124fae8816416374f629752138ec08e1 (patch) | |
tree | e7c0eb48729c056ed4bbafbd3816fafd269a8f15 /chrome/test/automation | |
parent | 13a9e86809ec0b88304afe5d2126d24b6750a327 (diff) | |
download | chromium_src-7d5c3acd124fae8816416374f629752138ec08e1.zip chromium_src-7d5c3acd124fae8816416374f629752138ec08e1.tar.gz chromium_src-7d5c3acd124fae8816416374f629752138ec08e1.tar.bz2 |
Revert my change to get the tree green. Not sure why the tests became flaky. I'll try to check them in again but in smaller chunks tomorrow.
TBR=mpcomplete
Review URL: http://codereview.chromium.org/21039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9132 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/automation')
-rw-r--r-- | chrome/test/automation/autocomplete_edit_proxy.h | 7 | ||||
-rw-r--r-- | chrome/test/automation/automation_messages.h | 23 | ||||
-rw-r--r-- | chrome/test/automation/automation_messages_internal.h | 8 | ||||
-rw-r--r-- | chrome/test/automation/automation_proxy.cc | 3 | ||||
-rw-r--r-- | chrome/test/automation/tab_proxy.cc | 730 |
5 files changed, 521 insertions, 250 deletions
diff --git a/chrome/test/automation/autocomplete_edit_proxy.h b/chrome/test/automation/autocomplete_edit_proxy.h index bd7c87a..85172d3 100644 --- a/chrome/test/automation/autocomplete_edit_proxy.h +++ b/chrome/test/automation/autocomplete_edit_proxy.h @@ -49,10 +49,12 @@ struct AutocompleteMatchData { }; typedef std::vector<AutocompleteMatchData> Matches; +namespace IPC { + template <> struct ParamTraits<AutocompleteMatchData> { typedef AutocompleteMatchData param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { m->WriteString(p.provider_name); m->WriteInt(p.relevance); m->WriteBool(p.deletable); @@ -66,7 +68,7 @@ struct ParamTraits<AutocompleteMatchData> { m->WriteBool(p.starred); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + static bool Read(const Message* m, void** iter, param_type* r) { std::string destination_url; if (!m->ReadString(iter, &r->provider_name) || !m->ReadInt(iter, &r->relevance) || @@ -110,6 +112,7 @@ struct ParamTraits<AutocompleteMatchData> { l->append(L"]"); } }; +} // namespace IPC class AutocompleteEditProxy : public AutomationResourceProxy { public: diff --git a/chrome/test/automation/automation_messages.h b/chrome/test/automation/automation_messages.h index d4e916c..e1fdf80 100644 --- a/chrome/test/automation/automation_messages.h +++ b/chrome/test/automation/automation_messages.h @@ -8,6 +8,7 @@ #include <string> #include "base/basictypes.h" +#include "chrome/common/ipc_message.h" #include "chrome/common/ipc_message_utils.h" enum AutomationMsg_NavigationResponseValues { @@ -16,9 +17,25 @@ enum AutomationMsg_NavigationResponseValues { AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, }; -#define MESSAGES_INTERNAL_FILE \ - "chrome/test/automation/automation_messages_internal.h" -#include "chrome/common/ipc_message_macros.h" +// Two-pass include of render_messages_internal. Preprocessor magic allows +// us to use 1 header to define the enums and classes for our render messages. +#define IPC_MESSAGE_MACROS_ENUMS +#include "chrome/test/automation/automation_messages_internal.h" + +#ifdef IPC_MESSAGE_MACROS_LOG_ENABLED +# undef IPC_MESSAGE_MACROS_LOG +# define IPC_MESSAGE_MACROS_CLASSES +#include "chrome/test/automation/automation_messages_internal.h" + +# undef IPC_MESSAGE_MACROS_CLASSES +# define IPC_MESSAGE_MACROS_LOG +#include "chrome/test/automation/automation_messages_internal.h" +#else +// No debug strings requested, just define the classes +# define IPC_MESSAGE_MACROS_CLASSES +#include "chrome/test/automation/automation_messages_internal.h" +#endif + #endif // CHROME_TEST_AUTOMATION_AUTOMATION_MESSAGES_H__ diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h index 05290d0d..a22818c 100644 --- a/chrome/test/automation/automation_messages_internal.h +++ b/chrome/test/automation/automation_messages_internal.h @@ -31,7 +31,9 @@ // since the PageCyclerReferenceTest depends on the correctness of the // message IDs across the builds. -IPC_BEGIN_MESSAGES(Automation) +// By using a start value of 0 for automation messages, we keep backward +// compatability with old builds. +IPC_BEGIN_MESSAGES(Automation, 0) // This message is fired when the AutomationProvider is up and running // in the app (the app is not fully up at this point). @@ -204,9 +206,7 @@ IPC_BEGIN_MESSAGES(Automation) IPC_MESSAGE_ROUTED2(AutomationMsg_RedirectsFromRequest, int, // tab handle GURL) // source URL - IPC_MESSAGE_ROUTED2(AutomationMsg_RedirectsFromResponse, - bool /* succeeded */, - std::vector<GURL> /* redirects */) + IPC_MESSAGE_EMPTY(AutomationMsg_RedirectsFromResponse) // This message asks the AutomationProvider whether a tab is waiting for // login info. diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc index d0a5d69..f8d4b93 100644 --- a/chrome/test/automation/automation_proxy.cc +++ b/chrome/test/automation/automation_proxy.cc @@ -8,6 +8,7 @@ #include "base/logging.h" #include "base/ref_counted.h" +#include "chrome/common/ipc_message_macros.h" #include "chrome/test/automation/automation_constants.h" #include "chrome/test/automation/automation_messages.h" #include "chrome/test/automation/browser_proxy.h" @@ -553,7 +554,7 @@ TabProxy* AutomationProxy::CreateExternalTab(HWND parent, void* iter = NULL; int handle = 0; TabProxy* tab_proxy = NULL; - if (ReadParam(response, &iter, external_tab_container) && + if (IPC::ReadParam(response, &iter, external_tab_container) && IsWindow(*external_tab_container)) { if (response->ReadInt(&iter, &handle) && (handle >= 0)) { diff --git a/chrome/test/automation/tab_proxy.cc b/chrome/test/automation/tab_proxy.cc index 2d689ac..5673e69 100644 --- a/chrome/test/automation/tab_proxy.cc +++ b/chrome/test/automation/tab_proxy.cc @@ -24,15 +24,23 @@ bool TabProxy::GetTabTitle(std::wstring* title) const { } IPC::Message* response = NULL; - int tab_title_size_response; - bool succeeded = sender_->SendAndWaitForResponse( - new AutomationMsg_TabTitleRequest(0, handle_), &response, - AutomationMsg_TabTitleResponse::ID) && - AutomationMsg_TabTitleResponse::Read(response, &tab_title_size_response, title) && - tab_title_size_response >= 0; - scoped_ptr<IPC::Message> auto_deleter(response); + new AutomationMsg_TabTitleRequest(0, handle_), &response, + AutomationMsg_TabTitleResponse::ID); + + if (!succeeded) + return false; + void* iter = NULL; + int tab_title_size_response = -1; + if (response->ReadInt(&iter, &tab_title_size_response) && + (tab_title_size_response >= 0)) { + response->ReadWString(&iter, title); + } else { + succeeded = false; + } + + delete response; return succeeded; } @@ -47,18 +55,24 @@ bool TabProxy::IsShelfVisible(bool* is_visible) { IPC::Message* response = NULL; bool succeeded = sender_->SendAndWaitForResponse( - new AutomationMsg_ShelfVisibilityRequest(0, handle_), - &response, AutomationMsg_ShelfVisibilityResponse::ID) && - AutomationMsg_ShelfVisibilityResponse::Read(response, is_visible); - scoped_ptr<IPC::Message> auto_deleter(response); - return succeeded; + new AutomationMsg_ShelfVisibilityRequest(0, handle_), + &response, + AutomationMsg_ShelfVisibilityResponse::ID); + if (!succeeded) + return false; + + void* iter = NULL; + response->ReadBool(&iter, is_visible); + delete response; + return true; } bool TabProxy::OpenFindInPage() { if (!is_valid()) return false; - return sender_->Send(new AutomationMsg_OpenFindInPageRequest(0, handle_)); + return sender_->Send( + new AutomationMsg_OpenFindInPageRequest(0, handle_)); // This message expects no response. } @@ -74,10 +88,15 @@ bool TabProxy::IsFindWindowFullyVisible(bool* is_visible) { IPC::Message* response = NULL; bool succeeded = sender_->SendAndWaitForResponse( new AutomationMsg_FindWindowVisibilityRequest(0, handle_), - &response, AutomationMsg_FindWindowVisibilityResponse::ID) && - AutomationMsg_FindWindowVisibilityResponse::Read(response, is_visible); - scoped_ptr<IPC::Message> auto_deleter(response); - return succeeded; + &response, + AutomationMsg_FindWindowVisibilityResponse::ID); + if (!succeeded) + return false; + + void* iter = NULL; + response->ReadBool(&iter, is_visible); + delete response; + return true; } bool TabProxy::GetFindWindowLocation(int* x, int* y) { @@ -87,17 +106,23 @@ bool TabProxy::GetFindWindowLocation(int* x, int* y) { IPC::Message* response = NULL; bool succeeded = sender_->SendAndWaitForResponse( new AutomationMsg_FindWindowLocationRequest(0, handle_), - &response, AutomationMsg_FindWindowLocationResponse::ID) && - AutomationMsg_FindWindowLocationResponse::Read(response, x, y); - scoped_ptr<IPC::Message> auto_deleter(response); - return succeeded; + &response, + AutomationMsg_FindWindowLocationResponse::ID); + if (!succeeded) + return false; + + void* iter = NULL; + response->ReadInt(&iter, x); + response->ReadInt(&iter, y); + delete response; + return true; } int TabProxy::FindInPage(const std::wstring& search_string, FindInPageDirection forward, FindInPageCase match_case, bool find_next, - int* ordinal) { + int* active_ordinal) { if (!is_valid()) return -1; @@ -109,15 +134,22 @@ int TabProxy::FindInPage(const std::wstring& search_string, request.forward = forward == TRUE; IPC::Message* response = NULL; - int matches; bool succeeded = sender_->SendAndWaitForResponse( new AutomationMsg_FindRequest(0, handle_, request), - &response, AutomationMsg_FindInPageResponse2::ID) && - AutomationMsg_FindInPageResponse2::Read(response, ordinal, &matches); - scoped_ptr<IPC::Message> auto_deleter(response); + &response, + AutomationMsg_FindInPageResponse2::ID); if (!succeeded) return -1; - return matches; + + void* iter = NULL; + int ordinal; + int matches_found; + response->ReadInt(&iter, &ordinal); + response->ReadInt(&iter, &matches_found); + if (active_ordinal) + *active_ordinal = ordinal; + delete response; + return matches_found; } int TabProxy::NavigateToURL(const GURL& url) { @@ -131,13 +163,18 @@ int TabProxy::NavigateToURLWithTimeout(const GURL& url, return AUTOMATION_MSG_NAVIGATION_ERROR; IPC::Message* response = NULL; + bool succeeded = sender_->SendAndWaitForResponseWithTimeout( + new AutomationMsg_NavigateToURLRequest(0, handle_, url), &response, + AutomationMsg_NavigateToURLResponse::ID, timeout_ms, is_timeout); + + if (!succeeded) + return AUTOMATION_MSG_NAVIGATION_ERROR; + + void* iter = NULL; int navigate_response = AUTOMATION_MSG_NAVIGATION_ERROR; - if (sender_->SendAndWaitForResponseWithTimeout( - new AutomationMsg_NavigateToURLRequest(0, handle_, url), &response, - AutomationMsg_NavigateToURLResponse::ID, timeout_ms, is_timeout)) { - AutomationMsg_NavigateToURLResponse::Read(response, &navigate_response); - } - scoped_ptr<IPC::Message> auto_deleter(response); + response->ReadInt(&iter, &navigate_response); + + delete response; return navigate_response; } @@ -147,15 +184,19 @@ int TabProxy::NavigateInExternalTab(const GURL& url) { IPC::Message* response = NULL; bool is_timeout = false; - int rv = AUTOMATION_MSG_NAVIGATION_ERROR; - if (sender_->SendAndWaitForResponseWithTimeout( - new AutomationMsg_NavigateInExternalTabRequest(0, handle_, url), - &response, AutomationMsg_NavigateInExternalTabResponse::ID, INFINITE, - &is_timeout)) { - AutomationMsg_NavigateInExternalTabResponse::Read(response, &rv); - } - scoped_ptr<IPC::Message> auto_deleter(response); - return rv; + bool succeeded = sender_->SendAndWaitForResponseWithTimeout( + new AutomationMsg_NavigateInExternalTabRequest(0, handle_, url), &response, + AutomationMsg_NavigateInExternalTabResponse::ID, INFINITE, &is_timeout); + + if (!succeeded) + return AUTOMATION_MSG_NAVIGATION_ERROR; + + void* iter = NULL; + int navigate_response = AUTOMATION_MSG_NAVIGATION_ERROR; + response->ReadInt(&iter, &navigate_response); + + delete response; + return navigate_response; } bool TabProxy::SetAuth(const std::wstring& username, @@ -164,13 +205,19 @@ bool TabProxy::SetAuth(const std::wstring& username, return false; IPC::Message* response = NULL; - int navigate_response = -1; bool succeeded = sender_->SendAndWaitForResponse( - new AutomationMsg_SetAuthRequest(0, handle_, username, password), - &response, AutomationMsg_SetAuthResponse::ID) && - AutomationMsg_SetAuthResponse::Read(response, &navigate_response) && - navigate_response >= 0; - scoped_ptr<IPC::Message> auto_deleter(response); + new AutomationMsg_SetAuthRequest(0, handle_, username, password), &response, + AutomationMsg_SetAuthResponse::ID); + + if (!succeeded) + return false; + + void* iter = NULL; + int navigate_response = -1; + succeeded = (response->ReadInt(&iter, &navigate_response) && + navigate_response >= 0); + + delete response; return succeeded; } @@ -179,13 +226,19 @@ bool TabProxy::CancelAuth() { return false; IPC::Message* response = NULL; - int navigate_response = -1; bool succeeded = sender_->SendAndWaitForResponse( - new AutomationMsg_CancelAuthRequest(0, handle_), &response, - AutomationMsg_CancelAuthResponse::ID) && - AutomationMsg_CancelAuthResponse::Read(response, &navigate_response) && - navigate_response >= 0; - scoped_ptr<IPC::Message> auto_deleter(response); + new AutomationMsg_CancelAuthRequest(0, handle_), &response, + AutomationMsg_CancelAuthResponse::ID); + + if (!succeeded) + return false; + + void* iter = NULL; + int navigate_response = -1; + succeeded = (response->ReadInt(&iter, &navigate_response) && + navigate_response >= 0); + + delete response; return succeeded; } @@ -194,12 +247,18 @@ bool TabProxy::NeedsAuth() const { return false; IPC::Message* response = NULL; - bool needs_auth = false; bool succeeded = sender_->SendAndWaitForResponse( - new AutomationMsg_NeedsAuthRequest(0, handle_), &response, - AutomationMsg_NeedsAuthResponse::ID) && - AutomationMsg_NeedsAuthResponse::Read(response, &needs_auth); - scoped_ptr<IPC::Message> auto_deleter(response); + new AutomationMsg_NeedsAuthRequest(0, handle_), &response, + AutomationMsg_NeedsAuthResponse::ID); + + if (!succeeded) + return false; + + void* iter = NULL; + bool needs_auth = false; + response->ReadBool(&iter, &needs_auth); + + delete response; return needs_auth; } @@ -208,13 +267,18 @@ int TabProxy::GoBack() { return AUTOMATION_MSG_NAVIGATION_ERROR; IPC::Message* response = NULL; + bool succeeded = sender_->SendAndWaitForResponse( + new AutomationMsg_GoBackRequest(0, handle_), &response, + AutomationMsg_GoBackResponse::ID); + + if (!succeeded) + return AUTOMATION_MSG_NAVIGATION_ERROR; + + void* iter = NULL; int navigate_response = AUTOMATION_MSG_NAVIGATION_ERROR; - if (sender_->SendAndWaitForResponse( - new AutomationMsg_GoBackRequest(0, handle_), &response, - AutomationMsg_GoBackResponse::ID)) { - AutomationMsg_GoBackResponse::Read(response, &navigate_response); - } - scoped_ptr<IPC::Message> auto_deleter(response); + response->ReadInt(&iter, &navigate_response); + + delete response; return navigate_response; } @@ -223,13 +287,18 @@ int TabProxy::GoForward() { return AUTOMATION_MSG_NAVIGATION_ERROR; IPC::Message* response = NULL; + bool succeeded = sender_->SendAndWaitForResponse( + new AutomationMsg_GoForwardRequest(0, handle_), &response, + AutomationMsg_GoForwardResponse::ID); + + if (!succeeded) + return AUTOMATION_MSG_NAVIGATION_ERROR; + + void* iter = NULL; int navigate_response = AUTOMATION_MSG_NAVIGATION_ERROR; - if (sender_->SendAndWaitForResponse( - new AutomationMsg_GoForwardRequest(0, handle_), &response, - AutomationMsg_GoForwardResponse::ID)) { - AutomationMsg_GoForwardResponse::Read(response, &navigate_response); - } - scoped_ptr<IPC::Message> auto_deleter(response); + response->ReadInt(&iter, &navigate_response); + + delete response; return navigate_response; } @@ -238,30 +307,48 @@ int TabProxy::Reload() { return AUTOMATION_MSG_NAVIGATION_ERROR; IPC::Message* response = NULL; + bool succeeded = sender_->SendAndWaitForResponse( + new AutomationMsg_ReloadRequest(0, handle_), &response, + AutomationMsg_ReloadResponse::ID); + + if (!succeeded) + return AUTOMATION_MSG_NAVIGATION_ERROR; + + void* iter = NULL; int navigate_response = AUTOMATION_MSG_NAVIGATION_ERROR; - if (sender_->SendAndWaitForResponse( - new AutomationMsg_ReloadRequest(0, handle_), &response, - AutomationMsg_ReloadResponse::ID)) { - AutomationMsg_ReloadResponse::Read(response, &navigate_response); - } - scoped_ptr<IPC::Message> auto_deleter(response); + response->ReadInt(&iter, &navigate_response); + + delete response; return navigate_response; } bool TabProxy::GetRedirectsFrom(const GURL& source_url, std::vector<GURL>* redirects) { + std::vector<GURL> output; + IPC::Message* response = NULL; bool succeeded = sender_->SendAndWaitForResponse( new AutomationMsg_RedirectsFromRequest(0, handle_, source_url), &response, AutomationMsg_RedirectsFromResponse::ID); + if (!succeeded) + return false; scoped_ptr<IPC::Message> auto_deleter(response); - if (succeeded) { - succeeded = AutomationMsg_RedirectsFromResponse::Read( - response, &succeeded, redirects) && - succeeded; - } - return succeeded; + void* iter = NULL; + int num_redirects; + if (!response->ReadInt(&iter, &num_redirects)) + return false; + if (num_redirects < 0) + return false; // Negative redirect counts indicate failure. + + for (int i = 0; i < num_redirects; i++) { + GURL cur; + if (!IPC::ParamTraits<GURL>::Read(response, &iter, &cur)) + return false; + output.push_back(cur); + } + redirects->swap(output); + return true; } bool TabProxy::GetCurrentURL(GURL* url) const { @@ -274,12 +361,23 @@ bool TabProxy::GetCurrentURL(GURL* url) const { } IPC::Message* response = NULL; - bool succeeded; - succeeded = sender_->SendAndWaitForResponse( - new AutomationMsg_TabURLRequest(0, handle_), &response, - AutomationMsg_TabURLResponse::ID) && - AutomationMsg_TabURLResponse::Read(response, &succeeded, url); - scoped_ptr<IPC::Message> auto_deleter(response); + bool succeeded = sender_->SendAndWaitForResponse( + new AutomationMsg_TabURLRequest(0, handle_), &response, + AutomationMsg_TabURLResponse::ID); + + if (!succeeded) + return false; + + void* iter = NULL; + bool tab_url_success = false; + if (response->ReadBool(&iter, &tab_url_success) && tab_url_success) { + if (!IPC::ParamTraits<GURL>::Read(response, &iter, url)) + succeeded = false; + } else { + succeeded = false; + } + + delete response; return succeeded; } @@ -288,14 +386,21 @@ bool TabProxy::NavigateToURLAsync(const GURL& url) { return false; IPC::Message* response = NULL; - bool status = false; - if (sender_->SendAndWaitForResponse( - new AutomationMsg_NavigationAsyncRequest(0, handle_, url), &response, - AutomationMsg_NavigationAsyncResponse::ID)) { - AutomationMsg_NavigationAsyncResponse::Read(response, &status); + bool succeeded = sender_->SendAndWaitForResponse( + new AutomationMsg_NavigationAsyncRequest(0, handle_, url), &response, + AutomationMsg_NavigationAsyncResponse::ID); + + if (!succeeded) + return false; + + bool status; + if (AutomationMsg_NavigationAsyncResponse::Read(response, &status) && + status) { + succeeded = true; } - scoped_ptr<IPC::Message> auto_deleter(response); - return status; + + delete response; + return succeeded; } bool TabProxy::GetHWND(HWND* hwnd) const { @@ -306,13 +411,20 @@ bool TabProxy::GetHWND(HWND* hwnd) const { return false; } IPC::Message* response = NULL; - bool succeeded = false; - if (sender_->SendAndWaitForResponse( - new AutomationMsg_TabHWNDRequest(0, handle_), &response, - AutomationMsg_TabHWNDResponse::ID)) { - succeeded = AutomationMsg_TabHWNDResponse::Read(response, hwnd); + bool succeeded = sender_->SendAndWaitForResponse( + new AutomationMsg_TabHWNDRequest(0, handle_), &response, + AutomationMsg_TabHWNDResponse::ID); + if (!succeeded) + return false; + void* iter = NULL; + HWND tab_hwnd = NULL; + if (AutomationMsg_TabHWNDResponse::Read(response, &tab_hwnd) && tab_hwnd) { + *hwnd = tab_hwnd; + } else { + succeeded = false; } - scoped_ptr<IPC::Message> auto_deleter(response); + + delete response; return succeeded; } @@ -326,13 +438,22 @@ bool TabProxy::GetProcessID(int* process_id) const { } IPC::Message* response = NULL; - bool succeeded = false; - if (sender_->SendAndWaitForResponse( - new AutomationMsg_TabProcessIDRequest(0, handle_), &response, - AutomationMsg_TabProcessIDResponse::ID)) { - succeeded = AutomationMsg_TabProcessIDResponse::Read(response, process_id); + bool succeeded = sender_->SendAndWaitForResponse( + new AutomationMsg_TabProcessIDRequest(0, handle_), &response, + AutomationMsg_TabProcessIDResponse::ID); + + if (!succeeded) + return false; + + void* iter = NULL; + int pid; + if (AutomationMsg_TabProcessIDResponse::Read(response, &pid) && (pid >= 0)) { + *process_id = pid; + } else { + succeeded = false; } - scoped_ptr<IPC::Message> auto_deleter(response); + + delete response; return succeeded; } @@ -420,12 +541,14 @@ bool TabProxy::ExecuteAndExtractValue(const std::wstring& frame_xpath, bool succeeded = sender_->SendAndWaitForResponse( new AutomationMsg_DomOperationRequest(0, handle_, frame_xpath, jscript), &response, AutomationMsg_DomOperationResponse::ID); + + void* iter = NULL; std::string json; - if (succeeded) - succeeded = AutomationMsg_DomOperationResponse::Read(response, &json); - scoped_ptr<IPC::Message> auto_deleter(response); - if (!succeeded) + succeeded = response->ReadString(&iter, &json); + if (!succeeded) { + delete response; return false; + } // Wrap |json| in an array before deserializing because valid JSON has an // array or an object as the root. json.insert(0, "["); @@ -433,6 +556,8 @@ bool TabProxy::ExecuteAndExtractValue(const std::wstring& frame_xpath, JSONStringValueSerializer deserializer(json); *value = deserializer.Deserialize(NULL); + + delete response; return *value != NULL; } @@ -447,10 +572,19 @@ bool TabProxy::GetConstrainedWindowCount(int* count) const { IPC::Message* response = NULL; bool succeeded = sender_->SendAndWaitForResponse( - new AutomationMsg_ConstrainedWindowCountRequest(0, handle_), - &response, AutomationMsg_ConstrainedWindowCountResponse::ID) && - AutomationMsg_ConstrainedWindowCountResponse::Read(response, count); - scoped_ptr<IPC::Message> auto_deleter(response); + new AutomationMsg_ConstrainedWindowCountRequest(0, handle_), + &response, AutomationMsg_ConstrainedWindowCountResponse::ID); + + void* iter = NULL; + int count_response = -1; + if (response->ReadInt(&iter, &count_response) && + (count_response >= 0)) { + *count = count_response; + } else { + succeeded = false; + } + + delete response; return succeeded; } @@ -460,14 +594,18 @@ ConstrainedWindowProxy* TabProxy::GetConstrainedWindow( return NULL; IPC::Message* response = NULL; + bool succeeded = sender_->SendAndWaitForResponse( + new AutomationMsg_ConstrainedWindowRequest(0, handle_, window_index), + &response, AutomationMsg_ConstrainedWindowResponse::ID); + if (!succeeded) + return NULL; + + void* iter = NULL; int handle; - if (sender_->SendAndWaitForResponse( - new AutomationMsg_ConstrainedWindowRequest(0, handle_, window_index), - &response, AutomationMsg_ConstrainedWindowResponse::ID)) { - scoped_ptr<IPC::Message> response_deleter(response); - if (AutomationMsg_ConstrainedWindowResponse::Read(response, &handle)) - return new ConstrainedWindowProxy(sender_, tracker_, handle); - } + + scoped_ptr<IPC::Message> response_deleter(response); // Ensure deleted. + if (response->ReadInt(&iter, &handle) && (handle != 0)) + return new ConstrainedWindowProxy(sender_, tracker_, handle); return NULL; } @@ -489,13 +627,25 @@ bool TabProxy::GetCookies(const GURL& url, std::string* cookies) { return false; IPC::Message* response = NULL; - int size; bool succeeded = sender_->SendAndWaitForResponse( new AutomationMsg_GetCookiesRequest(0, url, handle_), &response, - AutomationMsg_GetCookiesResponse::ID) && - AutomationMsg_GetCookiesResponse::Read(response, &size, cookies) && - size >= 0; - scoped_ptr<IPC::Message> response_deleter(response); + AutomationMsg_GetCookiesResponse::ID); + + if (succeeded) { + void* iter = NULL; + int size; + std::string local_value; + + if (response->ReadInt(&iter, &size) && size >=0) { + if (!response->ReadString(&iter, cookies)) { + succeeded = false; + } + } else { + succeeded = false; + } + } + + delete response; return succeeded; } @@ -520,13 +670,20 @@ bool TabProxy::GetCookieByName(const GURL& url, bool TabProxy::SetCookie(const GURL& url, const std::string& value) { IPC::Message* response = NULL; - int response_value; bool succeeded = sender_->SendAndWaitForResponse( - new AutomationMsg_SetCookieRequest(0, url, value, handle_), &response, - AutomationMsg_SetCookieResponse::ID) && - AutomationMsg_SetCookieResponse::Read(response, &response_value) && - response_value >= 0; - scoped_ptr<IPC::Message> response_deleter(response); + new AutomationMsg_SetCookieRequest(0, url, value, handle_), &response, + AutomationMsg_SetCookieResponse::ID); + if (!succeeded) + return false; + + void* iter = NULL; + int response_value; + + if (!response->ReadInt(&iter, &response_value) || response_value < 0) { + succeeded = false; + } + + delete response; return succeeded; } @@ -535,28 +692,35 @@ int TabProxy::InspectElement(int x, int y) { return -1; IPC::Message* response = NULL; - int ret = -1; - if (sender_->SendAndWaitForResponse( + bool succeeded = sender_->SendAndWaitForResponse( new AutomationMsg_InspectElementRequest(0, handle_, x, y), - &response, AutomationMsg_InspectElementResponse::ID)) { - AutomationMsg_InspectElementResponse::Read(response, &ret); - } - scoped_ptr<IPC::Message> response_deleter(response); + &response, AutomationMsg_InspectElementResponse::ID); + if (!succeeded) + return -1; + + int ret; + AutomationMsg_InspectElementResponse::Read(response, &ret); return ret; } -bool TabProxy::GetDownloadDirectory(std::wstring* directory) { - DCHECK(directory); +bool TabProxy::GetDownloadDirectory(std::wstring* download_directory) { + DCHECK(download_directory); if (!is_valid()) return false; IPC::Message* response = NULL; - bool succeeded = sender_->SendAndWaitForResponse( - new AutomationMsg_DownloadDirectoryRequest(0, handle_), &response, - AutomationMsg_DownloadDirectoryResponse::ID) && - AutomationMsg_DownloadDirectoryResponse::Read(response, directory); - scoped_ptr<IPC::Message> response_deleter(response); - return succeeded; + bool succeeded = + sender_->SendAndWaitForResponse( + new AutomationMsg_DownloadDirectoryRequest(0, handle_), + &response, + AutomationMsg_DownloadDirectoryResponse::ID); + if (!succeeded) + return false; + + void* iter = NULL; + response->ReadWString(&iter, download_directory); + delete response; + return true; } bool TabProxy::ShowInterstitialPage(const std::string& html_text, @@ -568,12 +732,18 @@ bool TabProxy::ShowInterstitialPage(const std::string& html_text, IPC::Message* response = NULL; bool succeeded = sender_->SendAndWaitForResponseWithTimeout( new AutomationMsg_ShowInterstitialPageRequest(0, handle_, html_text), - &response, AutomationMsg_ShowInterstitialPageResponse::ID, timeout_ms, - &is_timeout) && - AutomationMsg_ShowInterstitialPageResponse::Read(response, &succeeded) && - succeeded; - scoped_ptr<IPC::Message> response_deleter(response); - return succeeded; + &response, + AutomationMsg_ShowInterstitialPageResponse::ID, timeout_ms, &is_timeout); + + if (!succeeded || !is_timeout) + return false; + + void* iter = NULL; + bool result = true; + response->ReadBool(&iter, &result); + + delete response; + return result; } bool TabProxy::HideInterstitialPage() { @@ -581,14 +751,21 @@ bool TabProxy::HideInterstitialPage() { return false; IPC::Message* response = NULL; - bool result; - bool succeeded = sender_->SendAndWaitForResponse( - new AutomationMsg_HideInterstitialPageRequest(0, handle_), - &response, AutomationMsg_HideInterstitialPageResponse::ID) && - AutomationMsg_HideInterstitialPageResponse::Read(response, &result) && - result; - scoped_ptr<IPC::Message> response_deleter(response); - return succeeded; + bool succeeded = + sender_->SendAndWaitForResponse( + new AutomationMsg_HideInterstitialPageRequest(0, handle_), + &response, + AutomationMsg_HideInterstitialPageResponse::ID); + + if (!succeeded) + return false; + + void* iter = NULL; + bool result = true; + response->ReadBool(&iter, &result); + + delete response; + return result; } bool TabProxy::Close() { @@ -600,13 +777,21 @@ bool TabProxy::Close(bool wait_until_closed) { return false; IPC::Message* response = NULL; - bool succeeded = sender_->SendAndWaitForResponse( - new AutomationMsg_CloseTabRequest(0, handle_, wait_until_closed), - &response, AutomationMsg_CloseTabResponse::ID) && - AutomationMsg_CloseTabResponse::Read(response, &succeeded) && - succeeded; - scoped_ptr<IPC::Message> response_deleter(response); - return succeeded; + bool succeeded = + sender_->SendAndWaitForResponse( + new AutomationMsg_CloseTabRequest(0, handle_, wait_until_closed), + &response, + AutomationMsg_CloseTabResponse::ID); + + if (!succeeded) + return false; + + void* iter = NULL; + bool result = true; + response->ReadBool(&iter, &result); + + delete response; + return result; } bool TabProxy::SetAccelerators(HACCEL accel_table, @@ -617,14 +802,20 @@ bool TabProxy::SetAccelerators(HACCEL accel_table, IPC::Message* response = NULL; bool is_timeout = false; bool succeeded = sender_->SendAndWaitForResponseWithTimeout( - new AutomationMsg_SetAcceleratorsForTab( - 0, handle_, accel_table, accel_table_entry_count), - &response, AutomationMsg_SetAcceleratorsForTabResponse::ID, INFINITE, - &is_timeout) && - AutomationMsg_SetAcceleratorsForTabResponse::Read(response, &succeeded) && - succeeded; - scoped_ptr<IPC::Message> response_deleter(response); - return succeeded; + new AutomationMsg_SetAcceleratorsForTab(0, handle_, accel_table, + accel_table_entry_count), + &response, + AutomationMsg_SetAcceleratorsForTabResponse::ID, INFINITE, &is_timeout); + + if (!succeeded) + return AUTOMATION_MSG_NAVIGATION_ERROR; + + void* iter = NULL; + bool set_accel_response = false; + response->ReadBool(&iter, &set_accel_response); + + delete response; + return set_accel_response; } bool TabProxy::ProcessUnhandledAccelerator(const MSG& msg) { @@ -640,11 +831,9 @@ bool TabProxy::WaitForTabToBeRestored(uint32 timeout_ms) { return false; IPC::Message* response = NULL; bool is_timeout; - bool succeeded = sender_->SendAndWaitForResponseWithTimeout( + return sender_->SendAndWaitForResponseWithTimeout( new AutomationMsg_WaitForTabToBeRestored(0, handle_), &response, AutomationMsg_TabFinishedRestoring::ID, timeout_ms, &is_timeout); - scoped_ptr<IPC::Message> response_deleter(response); - return succeeded; } bool TabProxy::GetSecurityState(SecurityStyle* security_style, @@ -657,18 +846,27 @@ bool TabProxy::GetSecurityState(SecurityStyle* security_style, IPC::Message* response = NULL; bool is_timeout = false; - int value; - bool succeeded; - succeeded = sender_->SendAndWaitForResponseWithTimeout( + bool succeeded = sender_->SendAndWaitForResponseWithTimeout( new AutomationMsg_GetSecurityState(0, handle_), &response, - AutomationMsg_GetSecurityStateResponse::ID, INFINITE, &is_timeout) && - AutomationMsg_GetSecurityStateResponse::Read( - response, &succeeded, &value, ssl_cert_status, mixed_content_state); - if (succeeded) - *security_style = static_cast<SecurityStyle>(value); + AutomationMsg_GetSecurityStateResponse::ID, INFINITE, &is_timeout); scoped_ptr<IPC::Message> auto_deleter(response); - return succeeded; + + if (!succeeded) + return false; + + void* iter = NULL; + int value; + + response->ReadBool(&iter, &succeeded); + if (!succeeded) + return false; + response->ReadInt(&iter, &value); + *security_style = static_cast<SecurityStyle>(value); + response->ReadInt(&iter, ssl_cert_status); + response->ReadInt(&iter, mixed_content_state); + + return true; } bool TabProxy::GetPageType(NavigationEntry::PageType* page_type) { @@ -679,17 +877,23 @@ bool TabProxy::GetPageType(NavigationEntry::PageType* page_type) { IPC::Message* response = NULL; bool is_timeout = false; - int value; - bool succeeded; - succeeded = sender_->SendAndWaitForResponseWithTimeout( + bool succeeded = sender_->SendAndWaitForResponseWithTimeout( new AutomationMsg_GetPageType(0, handle_), &response, - AutomationMsg_GetPageTypeResponse::ID, INFINITE, &is_timeout) && - AutomationMsg_GetPageTypeResponse::Read(response, &succeeded, &value); + AutomationMsg_GetPageTypeResponse::ID, INFINITE, &is_timeout); scoped_ptr<IPC::Message> auto_deleter(response); - if (succeeded) - *page_type = static_cast<NavigationEntry::PageType>(value); - return succeeded; + + if (!succeeded) + return false; + + void* iter = NULL; + int value; + response->ReadBool(&iter, &succeeded); + if (!succeeded) + return false; + response->ReadInt(&iter, &value); + *page_type = static_cast<NavigationEntry::PageType>(value); + return true; } bool TabProxy::TakeActionOnSSLBlockingPage(bool proceed) { @@ -697,15 +901,21 @@ bool TabProxy::TakeActionOnSSLBlockingPage(bool proceed) { return false; IPC::Message* response = NULL; - bool timeout = false; - bool success = sender_->SendAndWaitForResponseWithTimeout( + bool is_timeout = false; + bool succeeded = sender_->SendAndWaitForResponseWithTimeout( new AutomationMsg_ActionOnSSLBlockingPage(0, handle_, proceed), &response, - AutomationMsg_ActionOnSSLBlockingPageResponse::ID, INFINITE, &timeout) && - AutomationMsg_ActionOnSSLBlockingPageResponse::Read(response, &success) && - success; + AutomationMsg_ActionOnSSLBlockingPageResponse::ID, INFINITE, &is_timeout); scoped_ptr<IPC::Message> auto_deleter(response); - return success; + + if (!succeeded) + return false; + + void* iter = NULL; + bool status = false; + response->ReadBool(&iter, &status); + + return status; } bool TabProxy::PrintNow() { @@ -714,12 +924,15 @@ bool TabProxy::PrintNow() { IPC::Message* response = NULL; bool succeeded = sender_->SendAndWaitForResponse( - new AutomationMsg_PrintNowRequest(0, handle_), &response, - AutomationMsg_PrintNowResponse::ID) && - AutomationMsg_PrintNowResponse::Read(response, &succeeded) && - succeeded; + new AutomationMsg_PrintNowRequest(0, handle_), &response, + AutomationMsg_PrintNowResponse::ID); scoped_ptr<IPC::Message> auto_deleter(response); - return succeeded; + if (!succeeded) + return false; + + void* iter = NULL; + succeeded = false; + return response->ReadBool(&iter, &succeeded) && succeeded; } bool TabProxy::SavePage(const std::wstring& file_name, @@ -730,12 +943,18 @@ bool TabProxy::SavePage(const std::wstring& file_name, IPC::Message* response = NULL; bool succeeded = sender_->SendAndWaitForResponse( - new AutomationMsg_SavePageRequest( - 0, handle_, file_name, dir_path, static_cast<int>(type)), - &response, AutomationMsg_SavePageResponse::ID) && - AutomationMsg_SavePageResponse::Read(response, &succeeded) && - succeeded; - scoped_ptr<IPC::Message> auto_deleter(response); + new AutomationMsg_SavePageRequest(0, handle_, file_name, + dir_path, static_cast<int>(type)), + &response, + AutomationMsg_SavePageResponse::ID); + + if (!succeeded) + return false; + + void* iter = NULL; + response->ReadBool(&iter, &succeeded); + delete response; + return succeeded; } @@ -759,11 +978,15 @@ bool TabProxy::GetSSLInfoBarCount(int* count) { IPC::Message* response = NULL; bool success = sender_->SendAndWaitForResponse( new AutomationMsg_GetSSLInfoBarCountRequest(0, handle_), - &response, AutomationMsg_GetSSLInfoBarCountResponse::ID) && - AutomationMsg_GetSSLInfoBarCountResponse::Read(response, count) && - count >= 0; + &response, + AutomationMsg_GetSSLInfoBarCountResponse::ID); scoped_ptr<IPC::Message> auto_deleter(response); - return success; + if (!success) + return false; + + void* iter = NULL; + response->ReadInt(&iter, count); + return true; } bool TabProxy::ClickSSLInfoBarLink(int info_bar_index, @@ -773,26 +996,36 @@ bool TabProxy::ClickSSLInfoBarLink(int info_bar_index, IPC::Message* response = NULL; bool success = sender_->SendAndWaitForResponse( - new AutomationMsg_ClickSSLInfoBarLinkRequest( - 0, handle_, info_bar_index, wait_for_navigation), - &response, AutomationMsg_ClickSSLInfoBarLinkResponse::ID) && - AutomationMsg_ClickSSLInfoBarLinkResponse::Read(response, &success) && - success; + new AutomationMsg_ClickSSLInfoBarLinkRequest(0, handle_, + info_bar_index, + wait_for_navigation), + &response, + AutomationMsg_ClickSSLInfoBarLinkResponse::ID); scoped_ptr<IPC::Message> auto_deleter(response); + if (!success) + return false; + + void* iter = NULL; + response->ReadBool(&iter, &success); return success; } -bool TabProxy::GetLastNavigationTime(int64* nav_time) { +bool TabProxy::GetLastNavigationTime(int64* last_navigation_time) { if (!is_valid()) return false; IPC::Message* response = NULL; bool success = sender_->SendAndWaitForResponse( new AutomationMsg_GetLastNavigationTimeRequest(0, handle_), - &response, AutomationMsg_GetLastNavigationTimeResponse::ID) && - AutomationMsg_GetLastNavigationTimeResponse::Read(response, nav_time); + &response, + AutomationMsg_GetLastNavigationTimeResponse::ID); scoped_ptr<IPC::Message> auto_deleter(response); - return success; + if (!success) + return false; + + void* iter = NULL; + response->ReadInt64(&iter, last_navigation_time); + return true; } bool TabProxy::WaitForNavigation(int64 last_navigation_time) { @@ -801,12 +1034,17 @@ bool TabProxy::WaitForNavigation(int64 last_navigation_time) { IPC::Message* response = NULL; bool success = sender_->SendAndWaitForResponse( - new AutomationMsg_WaitForNavigationRequest( - 0, handle_, last_navigation_time), - &response, AutomationMsg_WaitForNavigationResponse::ID) && - AutomationMsg_WaitForNavigationResponse::Read(response, &success) && - success; + new AutomationMsg_WaitForNavigationRequest(0, + handle_, + last_navigation_time), + &response, + AutomationMsg_WaitForNavigationResponse::ID); scoped_ptr<IPC::Message> auto_deleter(response); + if (!success) + return false; + + void* iter = NULL; + response->ReadBool(&iter, &success); return success; } @@ -817,9 +1055,15 @@ bool TabProxy::GetPageCurrentEncoding(std::wstring* encoding) { IPC::Message* response; bool succeeded = sender_->SendAndWaitForResponse( new AutomationMsg_GetPageCurrentEncodingRequest(0, handle_), - &response, AutomationMsg_GetPageCurrentEncodingResponse::ID) && - AutomationMsg_GetPageCurrentEncodingResponse::Read(response, encoding); - scoped_ptr<IPC::Message> response_deleter(response); + &response, + AutomationMsg_GetPageCurrentEncodingResponse::ID); + + scoped_ptr<IPC::Message> response_deleter(response); // Delete on return. + if (!succeeded) + return false; + + void* iter = NULL; + succeeded = response->ReadWString(&iter, encoding); return succeeded; } @@ -830,9 +1074,15 @@ bool TabProxy::OverrideEncoding(const std::wstring& encoding) { IPC::Message* response; bool succeeded = sender_->SendAndWaitForResponse( new AutomationMsg_OverrideEncodingRequest(0, handle_, encoding), - &response, AutomationMsg_OverrideEncodingResponse::ID) && - AutomationMsg_OverrideEncodingResponse::Read(response, &succeeded) && - succeeded; - scoped_ptr<IPC::Message> response_deleter(response); - return succeeded; + &response, + AutomationMsg_OverrideEncodingResponse::ID); + + scoped_ptr<IPC::Message> response_deleter(response); // Delete on return. + if (!succeeded) + return false; + + void* iter = NULL; + bool successed_set_value = false; + succeeded = response->ReadBool(&iter, &successed_set_value); + return succeeded && successed_set_value; } |