Chromium Code Reviews| Index: chrome/test/chromedriver/window_commands.cc |
| diff --git a/chrome/test/chromedriver/window_commands.cc b/chrome/test/chromedriver/window_commands.cc |
| index f7a9f3f7a913b7ba25362512ab35ddc69caac71f..eb3c2e3238a5623daaf52fef9045e9638262b237 100644 |
| --- a/chrome/test/chromedriver/window_commands.cc |
| +++ b/chrome/test/chromedriver/window_commands.cc |
| @@ -9,10 +9,13 @@ |
| #include "base/callback.h" |
| #include "base/string_number_conversions.h" |
| #include "base/stringprintf.h" |
| +#include "base/threading/platform_thread.h" |
| +#include "base/time.h" |
| #include "base/values.h" |
| #include "chrome/test/chromedriver/basic_types.h" |
| #include "chrome/test/chromedriver/chrome.h" |
| #include "chrome/test/chromedriver/element_util.h" |
| +#include "chrome/test/chromedriver/js.h" |
| #include "chrome/test/chromedriver/session.h" |
| #include "chrome/test/chromedriver/status.h" |
| #include "chrome/test/chromedriver/ui_events.h" |
| @@ -102,6 +105,69 @@ Status ExecuteExecuteScript( |
| session->frame, "function(){" + script + "}", *args, value); |
| } |
| +Status ExecuteExecuteAsyncScript( |
| + Session* session, |
| + WebView* web_view, |
| + const base::DictionaryValue& params, |
| + scoped_ptr<base::Value>* value) { |
| + std::string script; |
| + if (!params.GetString("script", &script)) |
| + return Status(kUnknownError, "'script' must be a string"); |
| + const base::ListValue* script_args; |
| + if (!params.GetList("args", &script_args)) |
| + return Status(kUnknownError, "'args' must be a list"); |
| + |
| + base::ListValue args; |
| + args.AppendString(script); |
| + args.Append(script_args->DeepCopy()); |
| + scoped_ptr<base::Value> tmp; |
| + Status status = web_view->CallFunction( |
| + session->frame, kExecuteAsyncScriptScript, args, &tmp); |
| + if (status.IsError()) |
| + return status; |
| + |
| + base::Time start_time = base::Time::Now(); |
| + base::ListValue args_tmp; |
| + while (true) { |
| + scoped_ptr<base::Value> result; |
| + status = web_view->CallFunction( |
| + session->frame, |
| + "function() {" |
| + " return {" |
| + " 'finished': document['chromedriverAsyncScriptFinsished']," |
| + " 'result': document['chromedriverAsyncScriptResult']" |
| + " };" |
| + "}", |
| + args_tmp, |
| + &result); |
| + if (status.IsError()) { |
| + if (status.code() == kNoSuchFrame) |
| + return Status(kJavaScriptError, "page or frame unload", status); |
|
kkania
2013/03/08 17:25:12
this should be unknown error, JavaScriptError is o
chrisgao (Use stgao instead)
2013/03/08 21:06:24
In the protocol(https://code.google.com/p/selenium
|
| + return status; |
| + } |
| + const base::DictionaryValue* dict; |
| + if (!result->GetAsDictionary(&dict)) |
| + return Status(kUnknownError, "failed to tell if script has finished"); |
| + bool finished = false; |
| + if (!dict->GetBoolean("finished", &finished)) |
| + return Status(kUnknownError, "flag 'finished' is not returned"); |
| + if (finished) { |
| + const base::Value* script_result; |
| + if (!dict->Get("result", &script_result)) |
|
kkania
2013/03/08 17:25:12
i think this will fail if the user calls the callb
chrisgao (Use stgao instead)
2013/03/08 21:06:24
In this case, the result is set as undefined in th
|
| + return Status(kUnknownError, "failed to get result of script"); |
| + value->reset(script_result->DeepCopy()); |
| + return Status(kOk); |
| + } |
| + |
| + if ((base::Time::Now() - start_time).InMilliseconds() >= |
| + session->script_timeout) |
| + break; |
| + |
| + base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(50)); |
| + } |
| + return Status(kTimeout); |
| +} |
| + |
| Status ExecuteSwitchToFrame( |
| Session* session, |
| WebView* web_view, |