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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE HTML>
2 <html>
3 <script src='test.js'></script>
4 <script src='execute_async_script.js'></script>
5 <script>
6
7 function resetAsyncScriptInfo() {
8 var info = getAsyncScriptInfo();
9 info['id'] = 0;
10 info['finished'] = false;
11 delete info['result'];
12 }
13
14 function testZeroScriptTimeout() {
15 resetAsyncScriptInfo();
16
17 try {
18 executeAsyncScript(
19 'var f = arguments[0]; setTimeout(function(){ f(0); }, 1000);', [], 0);
20 assert(false);
21 } catch (error) {
22 assertEquals(28, error.code);
23 var info = getAsyncScriptInfo();
24 assert(!info['finished']);
25 assert(!info.hasOwnProperty('result'));
26 assertEquals(2, info['id']);
27 }
28
29 executeAsyncScript('arguments[0]();', [], 0);
30 }
31
32 function testExecuteAsyncScript() {
33 resetAsyncScriptInfo();
34
35 var injectedArgs = null;
36 function captureArguments(args) {
37 injectedArgs = args;
38 }
39 // Pass function captureArguments as the first argument. It is used to capture
40 // the injected arguments to the following script.
41 var script =
42 'var args = arguments; args[0](args); args[args.length - 1](args[1]);';
43 var script_args = [captureArguments, 1];
44 executeAsyncScript(script, script_args, 1000);
45
46 assertEquals(3, injectedArgs.length);
47 assertEquals(captureArguments, injectedArgs[0]);
48 assertEquals(1, injectedArgs[1]);
49 var info = getAsyncScriptInfo();
50 assert(info['finished']);
51 assertEquals(1, info['result']);
52 assertEquals(1, info['id']);
53 }
54
55 function testFirstScriptFinishAfterSecondScriptExecute() {
56 resetAsyncScriptInfo();
57
58 executeAsyncScript(
59 'var f = arguments[0]; setTimeout(function(){ f(1); }, 100000);', [], 10);
60 var info = getAsyncScriptInfo();
61 assert(!info['finished']);
62 assert(!info.hasOwnProperty('result'));
63 assertEquals(1, info['id']);
64
65 executeAsyncScript('var fn = arguments[0]; fn(2);', [], 10);
66 assert(info['finished']);
67 assertEquals(2, info['result']);
68 assertEquals(2, info['id']);
69 }
70
71 </script>
72 <body>
73 </body>
74 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698