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

Unified Diff: chrome/test/chromedriver/js/execute_async_script_test.html

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
« no previous file with comments | « chrome/test/chromedriver/js/execute_async_script.js ('k') | chrome/test/chromedriver/run_py_tests.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/chromedriver/js/execute_async_script_test.html
diff --git a/chrome/test/chromedriver/js/execute_async_script_test.html b/chrome/test/chromedriver/js/execute_async_script_test.html
new file mode 100644
index 0000000000000000000000000000000000000000..b17808cdd8300b6f2b471fc5f616649825225dcd
--- /dev/null
+++ b/chrome/test/chromedriver/js/execute_async_script_test.html
@@ -0,0 +1,67 @@
+<!DOCTYPE HTML>
+<html>
+<script src='test.js'></script>
+<script src='execute_async_script.js'></script>
+<script>
+
+function resetAsyncScriptInfo() {
+ var info = getAsyncScriptInfo();
+ info.id = 0;
+ info.finished = false;
+ delete info.result;
+}
+
+function testJavascriptError() {
+ resetAsyncScriptInfo();
+
+ try {
+ executeAsyncScript('f(123);', []);
+ assert(false);
+ } catch (error) {
+ assertEquals(17, error.code);
+ }
+}
+
+function testExecuteAsyncScript() {
+ resetAsyncScriptInfo();
+
+ var injectedArgs = null;
+ function captureArguments(args) {
+ injectedArgs = args;
+ }
+ // Pass function captureArguments as the first argument. It is used to capture
+ // the injected arguments to the following script.
+ var script =
+ 'var args = arguments; args[0](args); args[args.length - 1](args[1]);';
+ var script_args = [captureArguments, 1];
+ executeAsyncScript(script, script_args);
+
+ assertEquals(3, injectedArgs.length);
+ assertEquals(captureArguments, injectedArgs[0]);
+ assertEquals(1, injectedArgs[1]);
+ var info = getAsyncScriptInfo();
+ assert(info.finished);
+ assertEquals(1, info.result);
+ assertEquals(1, info.id);
+}
+
+function testFirstScriptFinishAfterSecondScriptExecute() {
+ resetAsyncScriptInfo();
+
+ executeAsyncScript(
+ 'var f = arguments[0]; setTimeout(function(){ f(1); }, 100000);', []);
+ var info = getAsyncScriptInfo();
+ assert(!info.finished);
+ assert(!info.hasOwnProperty('result'));
+ assertEquals(1, info.id);
+
+ executeAsyncScript('var fn = arguments[0]; fn(2);', []);
+ assert(info.finished);
+ assertEquals(2, info.result);
+ assertEquals(2, info.id);
+}
+
+</script>
+<body>
+</body>
+</html>
« no previous file with comments | « chrome/test/chromedriver/js/execute_async_script.js ('k') | chrome/test/chromedriver/run_py_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698