| Index: chrome/test/chromedriver/window_commands.cc
|
| diff --git a/chrome/test/chromedriver/window_commands.cc b/chrome/test/chromedriver/window_commands.cc
|
| index 54dca1e590cc7a28603a83d5911204e9ef1ce1eb..89fb139f19b9bc229d4d6f469081c8636e43374d 100644
|
| --- a/chrome/test/chromedriver/window_commands.cc
|
| +++ b/chrome/test/chromedriver/window_commands.cc
|
| @@ -17,6 +17,7 @@
|
| #include "chrome/test/chromedriver/session.h"
|
| #include "chrome/test/chromedriver/status.h"
|
| #include "chrome/test/chromedriver/ui_events.h"
|
| +#include "chrome/test/chromedriver/util.h"
|
| #include "chrome/test/chromedriver/web_view.h"
|
|
|
| namespace {
|
| @@ -138,19 +139,22 @@ Status ExecuteWindowCommand(
|
| if (status.IsError())
|
| return status;
|
|
|
| - Status nav_status = web_view->WaitForPendingNavigations(session->frame);
|
| + Status nav_status =
|
| + web_view->WaitForPendingNavigations(session->GetCurrentFrameId());
|
| if (nav_status.IsError())
|
| return nav_status;
|
| status = command.Run(session, web_view, params, value);
|
| // Switch to main frame and retry command if subframe no longer exists.
|
| if (status.code() == kNoSuchFrame) {
|
| - session->frame = "";
|
| - nav_status = web_view->WaitForPendingNavigations(session->frame);
|
| + session->SwitchToTopFrame();
|
| + nav_status =
|
| + web_view->WaitForPendingNavigations(session->GetCurrentFrameId());
|
| if (nav_status.IsError())
|
| return nav_status;
|
| status = command.Run(session, web_view, params, value);
|
| }
|
| - nav_status = web_view->WaitForPendingNavigations(session->frame);
|
| + nav_status =
|
| + web_view->WaitForPendingNavigations(session->GetCurrentFrameId());
|
| if (status.IsOk() && nav_status.IsError() &&
|
| nav_status.code() != kDisconnected)
|
| return nav_status;
|
| @@ -181,7 +185,7 @@ Status ExecuteExecuteScript(
|
| return Status(kUnknownError, "'args' must be a list");
|
|
|
| return web_view->CallFunction(
|
| - session->frame, "function(){" + script + "}", *args, value);
|
| + session->GetCurrentFrameId(), "function(){" + script + "}", *args, value);
|
| }
|
|
|
| Status ExecuteSwitchToFrame(
|
| @@ -194,7 +198,7 @@ Status ExecuteSwitchToFrame(
|
| return Status(kUnknownError, "missing 'id'");
|
|
|
| if (id->IsType(base::Value::TYPE_NULL)) {
|
| - session->frame = "";
|
| + session->SwitchToTopFrame();
|
| return Status(kOk);
|
| }
|
|
|
| @@ -225,10 +229,33 @@ Status ExecuteSwitchToFrame(
|
| }
|
| std::string frame;
|
| Status status = web_view->GetFrameByFunction(
|
| - session->frame, script, args, &frame);
|
| + session->GetCurrentFrameId(), script, args, &frame);
|
| if (status.IsError())
|
| return status;
|
| - session->frame = frame;
|
| +
|
| + scoped_ptr<base::Value> result;
|
| + status = web_view->CallFunction(
|
| + session->GetCurrentFrameId(), script, args, &result);
|
| + if (status.IsError())
|
| + return status;
|
| + const base::DictionaryValue* element;
|
| + if (!result->GetAsDictionary(&element))
|
| + return Status(kUnknownError, "fail to locate the sub frame element");
|
| +
|
| + std::string chrome_driver_id = GenerateId();
|
| + const char* kSetFrameIdentifier =
|
| + "function(frame, id) {"
|
| + " frame.setAttribute('cd_frame_id_', id);"
|
| + "}";
|
| + base::ListValue new_args;
|
| + new_args.Append(element->DeepCopy());
|
| + new_args.AppendString(chrome_driver_id);
|
| + result.reset(NULL);
|
| + status = web_view->CallFunction(
|
| + session->GetCurrentFrameId(), kSetFrameIdentifier, new_args, &result);
|
| + if (status.IsError())
|
| + return status;
|
| + session->SwitchToSubFrame(frame, chrome_driver_id);
|
| return Status(kOk);
|
| }
|
|
|
| @@ -245,7 +272,8 @@ Status ExecuteGetTitle(
|
| " return document.URL;"
|
| "}";
|
| base::ListValue args;
|
| - return web_view->CallFunction(session->frame, kGetTitleScript, args, value);
|
| + return web_view->CallFunction(
|
| + session->GetCurrentFrameId(), kGetTitleScript, args, value);
|
| }
|
|
|
| Status ExecuteGetPageSource(
|
| @@ -258,7 +286,8 @@ Status ExecuteGetPageSource(
|
| " return new XMLSerializer().serializeToString(document);"
|
| "}";
|
| base::ListValue args;
|
| - return web_view->CallFunction(session->frame, kGetPageSource, args, value);
|
| + return web_view->CallFunction(
|
| + session->GetCurrentFrameId(), kGetPageSource, args, value);
|
| }
|
|
|
| Status ExecuteFindElement(
|
| @@ -286,7 +315,7 @@ Status ExecuteGetCurrentUrl(
|
| const base::DictionaryValue& params,
|
| scoped_ptr<base::Value>* value) {
|
| std::string url;
|
| - Status status = GetUrl(web_view, session->frame, &url);
|
| + Status status = GetUrl(web_view, session->GetCurrentFrameId(), &url);
|
| if (status.IsError())
|
| return status;
|
| value->reset(new base::StringValue(url));
|
| @@ -342,13 +371,13 @@ Status ExecuteMouseMoveTo(
|
| }
|
|
|
| if (has_offset) {
|
| - location.offset(x_offset, y_offset);
|
| + location.Offset(x_offset, y_offset);
|
| } else {
|
| WebSize size;
|
| Status status = GetElementSize(session, web_view, element_id, &size);
|
| if (status.IsError())
|
| return status;
|
| - location.offset(size.width / 2, size.height / 2);
|
| + location.Offset(size.width / 2, size.height / 2);
|
| }
|
|
|
| std::list<MouseEvent> events;
|
| @@ -438,7 +467,7 @@ Status ExecuteGetActiveElement(
|
| scoped_ptr<base::Value>* value) {
|
| base::ListValue args;
|
| return web_view->CallFunction(
|
| - session->frame,
|
| + session->GetCurrentFrameId(),
|
| "function() { return document.activeElement || document.body }",
|
| args,
|
| value);
|
| @@ -450,7 +479,7 @@ Status ExecuteGetAppCacheStatus(
|
| const base::DictionaryValue& params,
|
| scoped_ptr<base::Value>* value) {
|
| return web_view->EvaluateScript(
|
| - session->frame,
|
| + session->GetCurrentFrameId(),
|
| "applicationCache.status",
|
| value);
|
| }
|
| @@ -461,7 +490,7 @@ Status ExecuteIsBrowserOnline(
|
| const base::DictionaryValue& params,
|
| scoped_ptr<base::Value>* value) {
|
| return web_view->EvaluateScript(
|
| - session->frame,
|
| + session->GetCurrentFrameId(),
|
| "navigator.onLine",
|
| value);
|
| }
|
| @@ -478,7 +507,7 @@ Status ExecuteGetStorageItem(
|
| base::ListValue args;
|
| args.Append(new base::StringValue(key));
|
| return web_view->CallFunction(
|
| - session->frame,
|
| + session->GetCurrentFrameId(),
|
| base::StringPrintf("function(key) { return %s[key]; }", storage),
|
| args,
|
| value);
|
| @@ -497,7 +526,7 @@ Status ExecuteGetStorageKeys(
|
| "}"
|
| "keys";
|
| return web_view->EvaluateScript(
|
| - session->frame,
|
| + session->GetCurrentFrameId(),
|
| base::StringPrintf(script, storage),
|
| value);
|
| }
|
| @@ -518,7 +547,7 @@ Status ExecuteSetStorageItem(
|
| args.Append(new base::StringValue(key));
|
| args.Append(new base::StringValue(storage_value));
|
| return web_view->CallFunction(
|
| - session->frame,
|
| + session->GetCurrentFrameId(),
|
| base::StringPrintf("function(key, value) { %s[key] = value; }", storage),
|
| args,
|
| value);
|
| @@ -536,7 +565,7 @@ Status ExecuteRemoveStorageItem(
|
| base::ListValue args;
|
| args.Append(new base::StringValue(key));
|
| return web_view->CallFunction(
|
| - session->frame,
|
| + session->GetCurrentFrameId(),
|
| base::StringPrintf("function(key) { %s.removeItem(key) }", storage),
|
| args,
|
| value);
|
| @@ -549,7 +578,7 @@ Status ExecuteClearStorage(
|
| const base::DictionaryValue& params,
|
| scoped_ptr<base::Value>* value) {
|
| return web_view->EvaluateScript(
|
| - session->frame,
|
| + session->GetCurrentFrameId(),
|
| base::StringPrintf("%s.clear()", storage),
|
| value);
|
| }
|
| @@ -561,7 +590,7 @@ Status ExecuteGetStorageSize(
|
| const base::DictionaryValue& params,
|
| scoped_ptr<base::Value>* value) {
|
| return web_view->EvaluateScript(
|
| - session->frame,
|
| + session->GetCurrentFrameId(),
|
| base::StringPrintf("%s.length", storage),
|
| value);
|
| }
|
| @@ -609,7 +638,7 @@ Status ExecuteAddCookie(
|
| args.Append(cookie->DeepCopy());
|
| scoped_ptr<base::Value> result;
|
| return web_view->CallFunction(
|
| - session->frame, kAddCookieScript, args, &result);
|
| + session->GetCurrentFrameId(), kAddCookieScript, args, &result);
|
| }
|
|
|
| Status ExecuteDeleteCookie(
|
| @@ -623,7 +652,7 @@ Status ExecuteDeleteCookie(
|
| base::DictionaryValue params_url;
|
| scoped_ptr<base::Value> value_url;
|
| std::string url;
|
| - Status status = GetUrl(web_view, session->frame, &url);
|
| + Status status = GetUrl(web_view, session->GetCurrentFrameId(), &url);
|
| if (status.IsError())
|
| return status;
|
| return web_view->DeleteCookie(name, url);
|
| @@ -643,7 +672,7 @@ Status ExecuteDeleteAllCookies(
|
| base::DictionaryValue params_url;
|
| scoped_ptr<base::Value> value_url;
|
| std::string url;
|
| - status = GetUrl(web_view, session->frame, &url);
|
| + status = GetUrl(web_view, session->GetCurrentFrameId(), &url);
|
| if (status.IsError())
|
| return status;
|
| for (std::list<Cookie>::const_iterator it = cookies.begin();
|
|
|