Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Unified Diff: chrome/test/chromedriver/js/execute_async_script.js

Issue 12675002: [chromedriver] Implement command: executeAsyncScript and setScriptTimeout (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address +5000 timeout problem. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/chromedriver/js/execute_async_script.js
diff --git a/chrome/test/chromedriver/js/execute_async_script.js b/chrome/test/chromedriver/js/execute_async_script.js
new file mode 100644
index 0000000000000000000000000000000000000000..2c3e4a1d788fd2d997de015b1a8e984c3f522202
--- /dev/null
+++ b/chrome/test/chromedriver/js/execute_async_script.js
@@ -0,0 +1,47 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+* Return the information of asynchronous script execution.
+*
+* @return {Object.<string, ?>} Information of asynchronous script execution.
+*/
+function getAsyncScriptInfo() {
+ var key = 'chromedriverAsyncScriptInfo';
+ if (!(key in document))
+ document[key] = {'id': 0, 'finished': false};
+ return document[key];
+}
+
+/**
+* Execute the given script and save its asynchronous result.
+*
+* If script1 finishes after script2 is executed, then script1's result will be
+* discarded while script2's will be saved.
+*
+* @param {!string} script The asynchronous script to be executed.
+* @param {Array.<*>} args Arguments to be passed to the script.
+*/
+function executeAsyncScript(script, args) {
+ var info = getAsyncScriptInfo();
+ info.id++;
+ info.finished = false;
+ delete info.result;
+ var id = info.id;
+
+ function callback(result) {
+ if (id == info.id) {
+ info.result = result;
+ info.finished = true;
+ }
+ }
+ args.push(callback);
+
+ try {
+ new Function(script).apply(null, args);
+ } catch (error) {
+ error.code = 17; // Error code for JavaScriptError.
+ throw error;
+ }
+}
« no previous file with comments | « chrome/test/chromedriver/command_executor_impl.cc ('k') | chrome/test/chromedriver/js/execute_async_script_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698