| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/automation/window_proxy.h" | 5 #include "chrome/test/automation/window_proxy.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "chrome/common/automation_constants.h" | 11 #include "chrome/common/automation_constants.h" |
| 12 #include "chrome/common/automation_messages.h" | 12 #include "chrome/common/automation_messages.h" |
| 13 #include "chrome/test/automation/automation_proxy.h" | 13 #include "chrome/test/automation/automation_proxy.h" |
| 14 #include "chrome/test/automation/browser_proxy.h" | 14 #include "chrome/test/automation/browser_proxy.h" |
| 15 #include "chrome/test/automation/tab_proxy.h" | 15 #include "chrome/test/automation/tab_proxy.h" |
| 16 #include "gfx/rect.h" | 16 #include "gfx/rect.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 | 18 |
| 19 bool WindowProxy::SimulateOSClick(const gfx::Point& click, int flags) { | 19 bool WindowProxy::SimulateOSClick(const gfx::Point& click, int flags) { |
| 20 if (!is_valid()) return false; | 20 if (!is_valid()) return false; |
| 21 | 21 |
| 22 return sender_->Send( | 22 return sender_->Send(new AutomationMsg_WindowClick(handle_, click, flags)); |
| 23 new AutomationMsg_WindowClick(0, handle_, click, flags)); | |
| 24 } | 23 } |
| 25 | 24 |
| 26 bool WindowProxy::SimulateOSMouseMove(const gfx::Point& location) { | 25 bool WindowProxy::SimulateOSMouseMove(const gfx::Point& location) { |
| 27 if (!is_valid()) return false; | 26 if (!is_valid()) return false; |
| 28 | 27 |
| 29 return sender_->Send( | 28 return sender_->Send( |
| 30 new AutomationMsg_WindowMouseMove(0, handle_, location)); | 29 new AutomationMsg_WindowMouseMove(handle_, location)); |
| 31 } | 30 } |
| 32 | 31 |
| 33 bool WindowProxy::GetWindowTitle(string16* text) { | 32 bool WindowProxy::GetWindowTitle(string16* text) { |
| 34 if (!is_valid()) return false; | 33 if (!is_valid()) return false; |
| 35 | 34 |
| 36 if (!text) { | 35 if (!text) { |
| 37 NOTREACHED(); | 36 NOTREACHED(); |
| 38 return false; | 37 return false; |
| 39 } | 38 } |
| 40 | 39 |
| 41 return sender_->Send(new AutomationMsg_WindowTitle(0, handle_, text)); | 40 return sender_->Send(new AutomationMsg_WindowTitle(handle_, text)); |
| 42 } | 41 } |
| 43 | 42 |
| 44 bool WindowProxy::SimulateOSKeyPress(app::KeyboardCode key, int flags) { | 43 bool WindowProxy::SimulateOSKeyPress(app::KeyboardCode key, int flags) { |
| 45 if (!is_valid()) return false; | 44 if (!is_valid()) return false; |
| 46 | 45 |
| 47 return sender_->Send( | 46 return sender_->Send( |
| 48 new AutomationMsg_WindowKeyPress(0, handle_, key, flags)); | 47 new AutomationMsg_WindowKeyPress(handle_, key, flags)); |
| 49 } | 48 } |
| 50 | 49 |
| 51 bool WindowProxy::SetVisible(bool visible) { | 50 bool WindowProxy::SetVisible(bool visible) { |
| 52 if (!is_valid()) return false; | 51 if (!is_valid()) return false; |
| 53 | 52 |
| 54 bool result = false; | 53 bool result = false; |
| 55 | 54 |
| 56 sender_->Send(new AutomationMsg_SetWindowVisible(0, handle_, visible, | 55 sender_->Send(new AutomationMsg_SetWindowVisible(handle_, visible, &result)); |
| 57 &result)); | |
| 58 return result; | 56 return result; |
| 59 } | 57 } |
| 60 | 58 |
| 61 bool WindowProxy::IsActive(bool* active) { | 59 bool WindowProxy::IsActive(bool* active) { |
| 62 if (!is_valid()) return false; | 60 if (!is_valid()) return false; |
| 63 | 61 |
| 64 bool result = false; | 62 bool result = false; |
| 65 | 63 |
| 66 sender_->Send(new AutomationMsg_IsWindowActive(0, handle_, &result, active)); | 64 sender_->Send(new AutomationMsg_IsWindowActive(handle_, &result, active)); |
| 67 return result; | 65 return result; |
| 68 } | 66 } |
| 69 | 67 |
| 70 bool WindowProxy::Activate() { | 68 bool WindowProxy::Activate() { |
| 71 if (!is_valid()) return false; | 69 if (!is_valid()) return false; |
| 72 | 70 |
| 73 return sender_->Send(new AutomationMsg_ActivateWindow(0, handle_)); | 71 return sender_->Send(new AutomationMsg_ActivateWindow(handle_)); |
| 74 } | 72 } |
| 75 | 73 |
| 76 bool WindowProxy::GetViewBounds(int view_id, gfx::Rect* bounds, | 74 bool WindowProxy::GetViewBounds(int view_id, gfx::Rect* bounds, |
| 77 bool screen_coordinates) { | 75 bool screen_coordinates) { |
| 78 if (!is_valid()) | 76 if (!is_valid()) |
| 79 return false; | 77 return false; |
| 80 | 78 |
| 81 if (!bounds) { | 79 if (!bounds) { |
| 82 NOTREACHED(); | 80 NOTREACHED(); |
| 83 return false; | 81 return false; |
| 84 } | 82 } |
| 85 | 83 |
| 86 bool result = false; | 84 bool result = false; |
| 87 | 85 |
| 88 if (!sender_->Send(new AutomationMsg_WindowViewBounds( | 86 if (!sender_->Send(new AutomationMsg_WindowViewBounds( |
| 89 0, handle_, view_id, screen_coordinates, &result, bounds))) { | 87 handle_, view_id, screen_coordinates, &result, bounds))) { |
| 90 return false; | 88 return false; |
| 91 } | 89 } |
| 92 | 90 |
| 93 return result; | 91 return result; |
| 94 } | 92 } |
| 95 | 93 |
| 96 bool WindowProxy::GetBounds(gfx::Rect* bounds) { | 94 bool WindowProxy::GetBounds(gfx::Rect* bounds) { |
| 97 if (!is_valid()) | 95 if (!is_valid()) |
| 98 return false; | 96 return false; |
| 99 bool result = false; | 97 bool result = false; |
| 100 sender_->Send(new AutomationMsg_GetWindowBounds(0, handle_, bounds, | 98 sender_->Send(new AutomationMsg_GetWindowBounds(handle_, bounds, &result)); |
| 101 &result)); | |
| 102 return result; | 99 return result; |
| 103 } | 100 } |
| 104 | 101 |
| 105 bool WindowProxy::SetBounds(const gfx::Rect& bounds) { | 102 bool WindowProxy::SetBounds(const gfx::Rect& bounds) { |
| 106 if (!is_valid()) | 103 if (!is_valid()) |
| 107 return false; | 104 return false; |
| 108 bool result = false; | 105 bool result = false; |
| 109 sender_->Send(new AutomationMsg_SetWindowBounds(0, handle_, bounds, | 106 sender_->Send(new AutomationMsg_SetWindowBounds(handle_, bounds, &result)); |
| 110 &result)); | |
| 111 return result; | 107 return result; |
| 112 } | 108 } |
| 113 | 109 |
| 114 bool WindowProxy::GetFocusedViewID(int* view_id) { | 110 bool WindowProxy::GetFocusedViewID(int* view_id) { |
| 115 if (!is_valid()) return false; | 111 if (!is_valid()) return false; |
| 116 | 112 |
| 117 if (!view_id) { | 113 if (!view_id) { |
| 118 NOTREACHED(); | 114 NOTREACHED(); |
| 119 return false; | 115 return false; |
| 120 } | 116 } |
| 121 | 117 |
| 122 return sender_->Send(new AutomationMsg_GetFocusedViewID(0, handle_, | 118 return sender_->Send(new AutomationMsg_GetFocusedViewID(handle_, view_id)); |
| 123 view_id)); | |
| 124 } | 119 } |
| 125 | 120 |
| 126 bool WindowProxy::WaitForFocusedViewIDToChange( | 121 bool WindowProxy::WaitForFocusedViewIDToChange( |
| 127 int old_view_id, int* new_view_id) { | 122 int old_view_id, int* new_view_id) { |
| 128 bool result = false; | 123 bool result = false; |
| 129 if (!sender_->Send(new AutomationMsg_WaitForFocusedViewIDToChange | 124 if (!sender_->Send(new AutomationMsg_WaitForFocusedViewIDToChange( |
| 130 (0, handle_, old_view_id, &result, new_view_id))) | 125 handle_, old_view_id, &result, new_view_id))) |
| 131 return false; | 126 return false; |
| 132 return result; | 127 return result; |
| 133 } | 128 } |
| 134 | 129 |
| 135 scoped_refptr<BrowserProxy> WindowProxy::GetBrowser() { | 130 scoped_refptr<BrowserProxy> WindowProxy::GetBrowser() { |
| 136 return GetBrowserWithTimeout(base::kNoTimeout, NULL); | 131 return GetBrowserWithTimeout(base::kNoTimeout, NULL); |
| 137 } | 132 } |
| 138 | 133 |
| 139 scoped_refptr<BrowserProxy> WindowProxy::GetBrowserWithTimeout( | 134 scoped_refptr<BrowserProxy> WindowProxy::GetBrowserWithTimeout( |
| 140 uint32 timeout_ms, bool* is_timeout) { | 135 uint32 timeout_ms, bool* is_timeout) { |
| 141 if (!is_valid()) | 136 if (!is_valid()) |
| 142 return NULL; | 137 return NULL; |
| 143 | 138 |
| 144 bool handle_ok = false; | 139 bool handle_ok = false; |
| 145 int browser_handle = 0; | 140 int browser_handle = 0; |
| 146 | 141 |
| 147 sender_->Send(new AutomationMsg_BrowserForWindow(0, handle_, &handle_ok, | 142 sender_->Send(new AutomationMsg_BrowserForWindow(handle_, &handle_ok, |
| 148 &browser_handle)); | 143 &browser_handle)); |
| 149 if (!handle_ok) | 144 if (!handle_ok) |
| 150 return NULL; | 145 return NULL; |
| 151 | 146 |
| 152 BrowserProxy* browser = | 147 BrowserProxy* browser = |
| 153 static_cast<BrowserProxy*>(tracker_->GetResource(browser_handle)); | 148 static_cast<BrowserProxy*>(tracker_->GetResource(browser_handle)); |
| 154 if (!browser) { | 149 if (!browser) { |
| 155 browser = new BrowserProxy(sender_, tracker_, browser_handle); | 150 browser = new BrowserProxy(sender_, tracker_, browser_handle); |
| 156 browser->AddRef(); | 151 browser->AddRef(); |
| 157 } | 152 } |
| 158 | 153 |
| 159 // Since there is no scoped_refptr::attach. | 154 // Since there is no scoped_refptr::attach. |
| 160 scoped_refptr<BrowserProxy> result; | 155 scoped_refptr<BrowserProxy> result; |
| 161 result.swap(&browser); | 156 result.swap(&browser); |
| 162 return result; | 157 return result; |
| 163 } | 158 } |
| 164 | 159 |
| 165 bool WindowProxy::IsMaximized(bool* maximized) { | 160 bool WindowProxy::IsMaximized(bool* maximized) { |
| 166 if (!is_valid()) | 161 if (!is_valid()) |
| 167 return false; | 162 return false; |
| 168 | 163 |
| 169 bool result = false; | 164 bool result = false; |
| 170 | 165 |
| 171 sender_->Send(new AutomationMsg_IsWindowMaximized(0, handle_, maximized, | 166 sender_->Send(new AutomationMsg_IsWindowMaximized(handle_, maximized, |
| 172 &result)); | 167 &result)); |
| 173 return result; | 168 return result; |
| 174 } | 169 } |
| OLD | NEW |