OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/tab_proxy.h" | 5 #include "chrome/test/automation/tab_proxy.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/common/automation_messages.h" | 13 #include "chrome/common/automation_messages.h" |
14 #include "chrome/common/json_value_serializer.h" | 14 #include "chrome/common/json_value_serializer.h" |
15 #include "chrome/test/automation/automation_proxy.h" | 15 #include "chrome/test/automation/automation_proxy.h" |
16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
17 | 17 |
18 TabProxy::TabProxy(AutomationMessageSender* sender, | 18 TabProxy::TabProxy(AutomationMessageSender* sender, |
19 AutomationHandleTracker* tracker, | 19 AutomationHandleTracker* tracker, |
20 int handle) | 20 int handle) |
21 : AutomationResourceProxy(tracker, sender, handle) { | 21 : AutomationResourceProxy(tracker, sender, handle) { |
22 } | 22 } |
23 | 23 |
24 | 24 |
25 bool TabProxy::GetTabTitle(std::wstring* title) const { | 25 bool TabProxy::GetTabTitle(string16* title) const { |
26 if (!is_valid()) | 26 if (!is_valid()) |
27 return false; | 27 return false; |
28 | 28 |
29 if (!title) { | 29 if (!title) { |
30 NOTREACHED(); | 30 NOTREACHED(); |
31 return false; | 31 return false; |
32 } | 32 } |
33 | 33 |
34 int tab_title_size_response = 0; | 34 int tab_title_size_response = 0; |
35 | 35 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 AutomationMsg_NavigationResponseValues navigate_response = | 92 AutomationMsg_NavigationResponseValues navigate_response = |
93 AUTOMATION_MSG_NAVIGATION_ERROR; | 93 AUTOMATION_MSG_NAVIGATION_ERROR; |
94 | 94 |
95 sender_->Send(new AutomationMsg_NavigateToURLBlockUntilNavigationsComplete( | 95 sender_->Send(new AutomationMsg_NavigateToURLBlockUntilNavigationsComplete( |
96 handle_, url, number_of_navigations, &navigate_response)); | 96 handle_, url, number_of_navigations, &navigate_response)); |
97 | 97 |
98 return navigate_response; | 98 return navigate_response; |
99 } | 99 } |
100 | 100 |
101 bool TabProxy::SetAuth(const std::wstring& username, | 101 bool TabProxy::SetAuth(const string16& username, |
102 const std::wstring& password) { | 102 const string16& password) { |
103 if (!is_valid()) | 103 if (!is_valid()) |
104 return false; | 104 return false; |
105 | 105 |
106 AutomationMsg_NavigationResponseValues navigate_response = | 106 AutomationMsg_NavigationResponseValues navigate_response = |
107 AUTOMATION_MSG_NAVIGATION_ERROR; | 107 AUTOMATION_MSG_NAVIGATION_ERROR; |
108 sender_->Send(new AutomationMsg_SetAuth(handle_, username, password, | 108 sender_->Send(new AutomationMsg_SetAuth(handle_, username, password, |
109 &navigate_response)); | 109 &navigate_response)); |
110 return navigate_response == AUTOMATION_MSG_NAVIGATION_SUCCESS; | 110 return navigate_response == AUTOMATION_MSG_NAVIGATION_SUCCESS; |
111 } | 111 } |
112 | 112 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 return false; | 226 return false; |
227 | 227 |
228 if (!process_id) { | 228 if (!process_id) { |
229 NOTREACHED(); | 229 NOTREACHED(); |
230 return false; | 230 return false; |
231 } | 231 } |
232 | 232 |
233 return sender_->Send(new AutomationMsg_TabProcessID(handle_, process_id)); | 233 return sender_->Send(new AutomationMsg_TabProcessID(handle_, process_id)); |
234 } | 234 } |
235 | 235 |
236 bool TabProxy::ExecuteAndExtractString(const std::wstring& frame_xpath, | 236 bool TabProxy::ExecuteAndExtractString(const string16& frame_xpath, |
237 const std::wstring& jscript, | 237 const string16& jscript, |
238 std::wstring* string_value) { | 238 string16* string_value) { |
239 Value* root = NULL; | 239 Value* root = NULL; |
240 bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root); | 240 bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root); |
241 if (!succeeded) | 241 if (!succeeded) |
242 return false; | 242 return false; |
243 | 243 |
244 DCHECK(root->IsType(Value::TYPE_LIST)); | 244 DCHECK(root->IsType(Value::TYPE_LIST)); |
245 Value* value = NULL; | 245 Value* value = NULL; |
246 succeeded = static_cast<ListValue*>(root)->Get(0, &value); | 246 succeeded = static_cast<ListValue*>(root)->Get(0, &value); |
247 if (succeeded) { | 247 if (succeeded) { |
248 string16 read_value; | 248 string16 read_value; |
249 succeeded = value->GetAsString(&read_value); | 249 succeeded = value->GetAsString(&read_value); |
250 if (succeeded) { | 250 if (succeeded) |
251 // TODO(viettrungluu): remove conversion. (But should |jscript| be UTF-8?) | 251 *string_value = read_value; |
252 *string_value = UTF16ToWideHack(read_value); | |
253 } | |
254 } | 252 } |
255 | 253 |
256 delete root; | 254 delete root; |
257 return succeeded; | 255 return succeeded; |
258 } | 256 } |
259 | 257 |
260 bool TabProxy::ExecuteAndExtractBool(const std::wstring& frame_xpath, | 258 bool TabProxy::ExecuteAndExtractBool(const string16& frame_xpath, |
261 const std::wstring& jscript, | 259 const string16& jscript, |
262 bool* bool_value) { | 260 bool* bool_value) { |
263 Value* root = NULL; | 261 Value* root = NULL; |
264 bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root); | 262 bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root); |
265 if (!succeeded) | 263 if (!succeeded) |
266 return false; | 264 return false; |
267 | 265 |
268 bool read_value = false; | 266 bool read_value = false; |
269 DCHECK(root->IsType(Value::TYPE_LIST)); | 267 DCHECK(root->IsType(Value::TYPE_LIST)); |
270 Value* value = NULL; | 268 Value* value = NULL; |
271 succeeded = static_cast<ListValue*>(root)->Get(0, &value); | 269 succeeded = static_cast<ListValue*>(root)->Get(0, &value); |
272 if (succeeded) { | 270 if (succeeded) { |
273 succeeded = value->GetAsBoolean(&read_value); | 271 succeeded = value->GetAsBoolean(&read_value); |
274 if (succeeded) { | 272 if (succeeded) { |
275 *bool_value = read_value; | 273 *bool_value = read_value; |
276 } | 274 } |
277 } | 275 } |
278 | 276 |
279 delete value; | 277 delete value; |
280 return succeeded; | 278 return succeeded; |
281 } | 279 } |
282 | 280 |
283 bool TabProxy::ExecuteAndExtractInt(const std::wstring& frame_xpath, | 281 bool TabProxy::ExecuteAndExtractInt(const string16& frame_xpath, |
284 const std::wstring& jscript, | 282 const string16& jscript, |
285 int* int_value) { | 283 int* int_value) { |
286 Value* root = NULL; | 284 Value* root = NULL; |
287 bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root); | 285 bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root); |
288 if (!succeeded) | 286 if (!succeeded) |
289 return false; | 287 return false; |
290 | 288 |
291 int read_value = 0; | 289 int read_value = 0; |
292 DCHECK(root->IsType(Value::TYPE_LIST)); | 290 DCHECK(root->IsType(Value::TYPE_LIST)); |
293 Value* value = NULL; | 291 Value* value = NULL; |
294 succeeded = static_cast<ListValue*>(root)->Get(0, &value); | 292 succeeded = static_cast<ListValue*>(root)->Get(0, &value); |
295 if (succeeded) { | 293 if (succeeded) { |
296 succeeded = value->GetAsInteger(&read_value); | 294 succeeded = value->GetAsInteger(&read_value); |
297 if (succeeded) { | 295 if (succeeded) { |
298 *int_value = read_value; | 296 *int_value = read_value; |
299 } | 297 } |
300 } | 298 } |
301 | 299 |
302 delete value; | 300 delete value; |
303 return succeeded; | 301 return succeeded; |
304 } | 302 } |
305 | 303 |
306 bool TabProxy::ExecuteAndExtractValue(const std::wstring& frame_xpath, | 304 bool TabProxy::ExecuteAndExtractValue(const string16& frame_xpath, |
307 const std::wstring& jscript, | 305 const string16& jscript, |
308 Value** value) { | 306 Value** value) { |
309 if (!is_valid()) | 307 if (!is_valid()) |
310 return false; | 308 return false; |
311 | 309 |
312 if (!value) { | 310 if (!value) { |
313 NOTREACHED(); | 311 NOTREACHED(); |
314 return false; | 312 return false; |
315 } | 313 } |
316 | 314 |
317 std::string json; | 315 std::string json; |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 TabProxy::~TabProxy() {} | 815 TabProxy::~TabProxy() {} |
818 | 816 |
819 bool TabProxy::ExecuteJavaScriptAndGetJSON(const std::string& script, | 817 bool TabProxy::ExecuteJavaScriptAndGetJSON(const std::string& script, |
820 std::string* json) { | 818 std::string* json) { |
821 if (!is_valid()) | 819 if (!is_valid()) |
822 return false; | 820 return false; |
823 if (!json) { | 821 if (!json) { |
824 NOTREACHED(); | 822 NOTREACHED(); |
825 return false; | 823 return false; |
826 } | 824 } |
827 return sender_->Send(new AutomationMsg_DomOperation(handle_, L"", | 825 return sender_->Send(new AutomationMsg_DomOperation(handle_, string16(), |
828 UTF8ToWide(script), | 826 UTF8ToUTF16(script), |
829 json)); | 827 json)); |
830 } | 828 } |
831 | 829 |
832 void TabProxy::FirstObjectAdded() { | 830 void TabProxy::FirstObjectAdded() { |
833 AddRef(); | 831 AddRef(); |
834 } | 832 } |
835 | 833 |
836 void TabProxy::LastObjectRemoved() { | 834 void TabProxy::LastObjectRemoved() { |
837 Release(); | 835 Release(); |
838 } | 836 } |
OLD | NEW |