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 comments. 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_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..12262ed9e47fa398ca5d02c91ffa085898b4e1ef
--- /dev/null
+++ b/chrome/test/chromedriver/js/execute_async_script_test.html
@@ -0,0 +1,74 @@
+<!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 testZeroScriptTimeout() {
+ resetAsyncScriptInfo();
+
+ try {
+ executeAsyncScript(
+ 'var f = arguments[0]; setTimeout(function(){ f(0); }, 1000);', [], 0);
+ assert(false);
+ } catch (error) {
+ assertEquals(28, error.code);
+ var info = getAsyncScriptInfo();
+ assert(!info['finished']);
+ assert(!info.hasOwnProperty('result'));
+ assertEquals(2, info['id']);
+ }
+
+ executeAsyncScript('arguments[0]();', [], 0);
+}
+
+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, 1000);
+
+ 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);', [], 10);
+ var info = getAsyncScriptInfo();
+ assert(!info['finished']);
+ assert(!info.hasOwnProperty('result'));
+ assertEquals(1, info['id']);
+
+ executeAsyncScript('var fn = arguments[0]; fn(2);', [], 10);
+ assert(info['finished']);
+ assertEquals(2, info['result']);
+ assertEquals(2, info['id']);
+}
+
+</script>
+<body>
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698