summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/test/automation/tab_proxy.cc47
-rw-r--r--chrome/test/automation/tab_proxy.h8
2 files changed, 21 insertions, 34 deletions
diff --git a/chrome/test/automation/tab_proxy.cc b/chrome/test/automation/tab_proxy.cc
index 6f360ad..d45fe9a 100644
--- a/chrome/test/automation/tab_proxy.cc
+++ b/chrome/test/automation/tab_proxy.cc
@@ -261,14 +261,13 @@ bool TabProxy::GetProcessID(int* process_id) const {
bool TabProxy::ExecuteAndExtractString(const std::wstring& frame_xpath,
const std::wstring& jscript,
std::wstring* string_value) {
- Value* root = NULL;
- bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root);
- if (!succeeded)
+ scoped_ptr<Value> root(ExecuteAndExtractValue(frame_xpath, jscript));
+ if (root == NULL)
return false;
DCHECK(root->IsType(Value::TYPE_LIST));
Value* value = NULL;
- succeeded = static_cast<ListValue*>(root)->Get(0, &value);
+ bool succeeded = static_cast<ListValue*>(root.get())->Get(0, &value);
if (succeeded) {
string16 read_value;
succeeded = value->GetAsString(&read_value);
@@ -277,80 +276,66 @@ bool TabProxy::ExecuteAndExtractString(const std::wstring& frame_xpath,
*string_value = UTF16ToWideHack(read_value);
}
}
-
- delete root;
return succeeded;
}
bool TabProxy::ExecuteAndExtractBool(const std::wstring& frame_xpath,
const std::wstring& jscript,
bool* bool_value) {
- Value* root = NULL;
- bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root);
- if (!succeeded)
+ scoped_ptr<Value> root(ExecuteAndExtractValue(frame_xpath, jscript));
+ if (root == NULL)
return false;
bool read_value = false;
DCHECK(root->IsType(Value::TYPE_LIST));
Value* value = NULL;
- succeeded = static_cast<ListValue*>(root)->Get(0, &value);
+ bool succeeded = static_cast<ListValue*>(root.get())->Get(0, &value);
if (succeeded) {
succeeded = value->GetAsBoolean(&read_value);
if (succeeded) {
*bool_value = read_value;
}
}
-
- delete value;
return succeeded;
}
bool TabProxy::ExecuteAndExtractInt(const std::wstring& frame_xpath,
const std::wstring& jscript,
int* int_value) {
- Value* root = NULL;
- bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root);
- if (!succeeded)
+ scoped_ptr<Value> root(ExecuteAndExtractValue(frame_xpath, jscript));
+ if (root == NULL)
return false;
int read_value = 0;
DCHECK(root->IsType(Value::TYPE_LIST));
Value* value = NULL;
- succeeded = static_cast<ListValue*>(root)->Get(0, &value);
+ bool succeeded = static_cast<ListValue*>(root.get())->Get(0, &value);
if (succeeded) {
succeeded = value->GetAsInteger(&read_value);
if (succeeded) {
*int_value = read_value;
}
}
-
- delete value;
return succeeded;
}
-bool TabProxy::ExecuteAndExtractValue(const std::wstring& frame_xpath,
- const std::wstring& jscript,
- Value** value) {
+Value* TabProxy::ExecuteAndExtractValue(const std::wstring& frame_xpath,
+ const std::wstring& jscript) {
if (!is_valid())
- return false;
-
- if (!value) {
- NOTREACHED();
- return false;
- }
+ return NULL;
std::string json;
if (!sender_->Send(new AutomationMsg_DomOperation(handle_, frame_xpath,
- jscript, &json)))
- return false;
+ jscript, &json))) {
+ return NULL;
+ }
// Wrap |json| in an array before deserializing because valid JSON has an
// array or an object as the root.
json.insert(0, "[");
json.append("]");
JSONStringValueSerializer deserializer(json);
- *value = deserializer.Deserialize(NULL, NULL);
- return *value != NULL;
+ return deserializer.Deserialize(NULL, NULL);
}
DOMElementProxyRef TabProxy::GetDOMDocument() {
diff --git a/chrome/test/automation/tab_proxy.h b/chrome/test/automation/tab_proxy.h
index 05f0469..26d3ea3 100644
--- a/chrome/test/automation/tab_proxy.h
+++ b/chrome/test/automation/tab_proxy.h
@@ -88,9 +88,6 @@ class TabProxy : public AutomationResourceProxy,
bool ExecuteAndExtractInt(const std::wstring& frame_xpath,
const std::wstring& jscript,
int* value) WARN_UNUSED_RESULT;
- bool ExecuteAndExtractValue(const std::wstring& frame_xpath,
- const std::wstring& jscript,
- base::Value** value) WARN_UNUSED_RESULT;
// Returns a DOMElementProxyRef to the tab's current DOM document.
// This proxy is invalidated when the document changes.
@@ -404,6 +401,11 @@ class TabProxy : public AutomationResourceProxy,
// purposes.
void LastObjectRemoved();
+ // Caller takes ownership over returned value. Returns NULL on failure.
+ base::Value* ExecuteAndExtractValue(
+ const std::wstring& frame_xpath,
+ const std::wstring& jscript) WARN_UNUSED_RESULT;
+
private:
base::Lock list_lock_; // Protects the observers_list_.
ObserverList<TabProxyDelegate> observers_list_;