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

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 and add command setScriptTimeout 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 }
27
28 executeAsyncScript('arguments[0]();', [], 0);
29 }
30
31 function testExecuteAsyncScript() {
32 resetAsyncScriptInfo();
33
34 var injectedArgs = null;
35 function captureArguments(args) {
36 injectedArgs = args;
37 }
38 // Pass function captureArguments as the first argument. It is used to capture
39 // the injected arguments to the following script.
40 var script =
41 'var args = arguments; args[0](args); args[args.length - 1](args[1]);';
42 var script_args = [captureArguments, 1];
43 executeAsyncScript(script, script_args, 1000);
44
45 assertEquals(3, injectedArgs.length);
46 assertEquals(captureArguments, injectedArgs[0]);
47 assertEquals(1, injectedArgs[1]);
48 var info = getAsyncScriptInfo();
49 assert(info.finished);
50 assertEquals(1, info.result);
51 assertEquals(1, info.id);
52 }
53
54 function testFirstScriptFinishAfterSecondScriptExecute() {
55 resetAsyncScriptInfo();
56
57 executeAsyncScript(
58 'var f = arguments[0]; setTimeout(function(){ f(1); }, 100000);', [], 10);
59 var info = getAsyncScriptInfo();
60 assert(!info.finished);
61 assert(!info.hasOwnProperty('result'));
62 assertEquals(1, info.id);
63
64 executeAsyncScript('var fn = arguments[0]; fn(2);', [], 10);
65 assert(info.finished);
66 assertEquals(2, info.result);
67 assertEquals(2, info.id);
68 }
69
70 </script>
71 <body>
72 </body>
73 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698