| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 } | 259 } |
| 260 | 260 |
| 261 bool TabProxy::ExecuteAndExtractString(const std::wstring& frame_xpath, | 261 bool TabProxy::ExecuteAndExtractString(const std::wstring& frame_xpath, |
| 262 const std::wstring& jscript, | 262 const std::wstring& jscript, |
| 263 std::wstring* string_value) { | 263 std::wstring* string_value) { |
| 264 Value* root = NULL; | 264 Value* root = NULL; |
| 265 bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root); | 265 bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root); |
| 266 if (!succeeded) | 266 if (!succeeded) |
| 267 return false; | 267 return false; |
| 268 | 268 |
| 269 DCHECK(root->AsList()); | 269 DCHECK(root->IsType(Value::TYPE_LIST)); |
| 270 Value* value = NULL; | 270 Value* value = NULL; |
| 271 succeeded = root->AsList()->Get(0, &value); | 271 succeeded = static_cast<ListValue*>(root)->Get(0, &value); |
| 272 if (succeeded) { | 272 if (succeeded) { |
| 273 string16 read_value; | 273 string16 read_value; |
| 274 succeeded = value->GetAsString(&read_value); | 274 succeeded = value->GetAsString(&read_value); |
| 275 if (succeeded) { | 275 if (succeeded) { |
| 276 // TODO(viettrungluu): remove conversion. (But should |jscript| be UTF-8?) | 276 // TODO(viettrungluu): remove conversion. (But should |jscript| be UTF-8?) |
| 277 *string_value = UTF16ToWideHack(read_value); | 277 *string_value = UTF16ToWideHack(read_value); |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 | 280 |
| 281 delete root; | 281 delete root; |
| 282 return succeeded; | 282 return succeeded; |
| 283 } | 283 } |
| 284 | 284 |
| 285 bool TabProxy::ExecuteAndExtractBool(const std::wstring& frame_xpath, | 285 bool TabProxy::ExecuteAndExtractBool(const std::wstring& frame_xpath, |
| 286 const std::wstring& jscript, | 286 const std::wstring& jscript, |
| 287 bool* bool_value) { | 287 bool* bool_value) { |
| 288 Value* root = NULL; | 288 Value* root = NULL; |
| 289 bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root); | 289 bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root); |
| 290 if (!succeeded) | 290 if (!succeeded) |
| 291 return false; | 291 return false; |
| 292 | 292 |
| 293 bool read_value = false; | 293 bool read_value = false; |
| 294 DCHECK(root->AsList()); | 294 DCHECK(root->IsType(Value::TYPE_LIST)); |
| 295 Value* value = NULL; | 295 Value* value = NULL; |
| 296 succeeded = root->AsList()->Get(0, &value); | 296 succeeded = static_cast<ListValue*>(root)->Get(0, &value); |
| 297 if (succeeded) { | 297 if (succeeded) { |
| 298 succeeded = value->GetAsBoolean(&read_value); | 298 succeeded = value->GetAsBoolean(&read_value); |
| 299 if (succeeded) { | 299 if (succeeded) { |
| 300 *bool_value = read_value; | 300 *bool_value = read_value; |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 | 303 |
| 304 delete value; | 304 delete value; |
| 305 return succeeded; | 305 return succeeded; |
| 306 } | 306 } |
| 307 | 307 |
| 308 bool TabProxy::ExecuteAndExtractInt(const std::wstring& frame_xpath, | 308 bool TabProxy::ExecuteAndExtractInt(const std::wstring& frame_xpath, |
| 309 const std::wstring& jscript, | 309 const std::wstring& jscript, |
| 310 int* int_value) { | 310 int* int_value) { |
| 311 Value* root = NULL; | 311 Value* root = NULL; |
| 312 bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root); | 312 bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root); |
| 313 if (!succeeded) | 313 if (!succeeded) |
| 314 return false; | 314 return false; |
| 315 | 315 |
| 316 int read_value = 0; | 316 int read_value = 0; |
| 317 DCHECK(root->AsList()); | 317 DCHECK(root->IsType(Value::TYPE_LIST)); |
| 318 Value* value = NULL; | 318 Value* value = NULL; |
| 319 succeeded = root->AsList()->Get(0, &value); | 319 succeeded = static_cast<ListValue*>(root)->Get(0, &value); |
| 320 if (succeeded) { | 320 if (succeeded) { |
| 321 succeeded = value->GetAsInteger(&read_value); | 321 succeeded = value->GetAsInteger(&read_value); |
| 322 if (succeeded) { | 322 if (succeeded) { |
| 323 *int_value = read_value; | 323 *int_value = read_value; |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 | 326 |
| 327 delete value; | 327 delete value; |
| 328 return succeeded; | 328 return succeeded; |
| 329 } | 329 } |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 json)); | 850 json)); |
| 851 } | 851 } |
| 852 | 852 |
| 853 void TabProxy::FirstObjectAdded() { | 853 void TabProxy::FirstObjectAdded() { |
| 854 AddRef(); | 854 AddRef(); |
| 855 } | 855 } |
| 856 | 856 |
| 857 void TabProxy::LastObjectRemoved() { | 857 void TabProxy::LastObjectRemoved() { |
| 858 Release(); | 858 Release(); |
| 859 } | 859 } |
| OLD | NEW |