Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / test / chromedriver / js / execute_async_script_test.html
blobd1ebe262ab97ffe275d9604d5a9e0b514d1c5414
1 <!DOCTYPE HTML>
2 <html>
3 <script src='test.js'></script>
4 <script src='execute_async_script.js'></script>
5 <script>
7 function resetAsyncScriptInfo() {
8 delete document[ASYNC_INFO_KEY];
11 function testScriptThrows() {
12 resetAsyncScriptInfo();
13 var info = getAsyncScriptInfo();
15 executeAsyncScript('f(123);', [], true);
16 assertEquals(StatusCode.JAVASCRIPT_ERROR, info.result.status);
17 executeAsyncScript('f(123);', [], false);
18 assertEquals(StatusCode.UNKNOWN_ERROR, info.result.status);
21 function testUserScriptWithArgs() {
22 resetAsyncScriptInfo();
24 var injectedArgs = null;
25 function captureArguments(args) {
26 injectedArgs = args;
28 // Pass function captureArguments as the first argument. It is used to capture
29 // the injected arguments to the following script.
30 var script =
31 'var args = arguments; args[0](args); args[args.length - 1](args[1]);';
32 var script_args = [captureArguments, 1];
33 executeAsyncScript(script, script_args, true);
35 assertEquals(3, injectedArgs.length);
36 assertEquals(captureArguments, injectedArgs[0]);
37 assertEquals(1, injectedArgs[1]);
39 var info = getAsyncScriptInfo();
40 assertEquals(0, info.result.status);
41 assertEquals(1, info.result.value);
42 assertEquals(2, info.id);
45 function testNonUserScript() {
46 resetAsyncScriptInfo();
47 var info = getAsyncScriptInfo();
49 executeAsyncScript('arguments[1](arguments[0])', [33], false);
50 assertEquals(0, info.result.status);
51 assertEquals(33, info.result.value);
53 executeAsyncScript('arguments[2](new Error("ERR"))', [33], false);
54 assertEquals(StatusCode.UNKNOWN_ERROR, info.result.status);
55 assertEquals(0, info.result.value.indexOf('ERR'));
57 executeAsyncScript('var e = new Error("ERR"); e.code = 111; arguments[1](e)',
58 [], false);
59 assertEquals(111, info.result.status);
60 assertEquals(0, info.result.value.indexOf('ERR'));
63 function testNoResultBeforeTimeout() {
64 resetAsyncScriptInfo();
65 var info = getAsyncScriptInfo();
67 executeAsyncScript(
68 'var a = arguments; window.setTimeout(function() {a[0](33)}, 0);',
69 [], true, 0);
71 assert(!info.result);
74 function testZeroTimeout(runner) {
75 resetAsyncScriptInfo();
76 var info = getAsyncScriptInfo();
78 executeAsyncScript(
79 'var a = arguments; window.setTimeout(function() {a[0](33)}, 0);',
80 [], true, 0);
82 window.setTimeout(function() {
83 assertEquals(0, info.result.status);
84 assertEquals(33, info.result.value);
85 runner.continueTesting();
86 }, 0);
87 runner.waitForAsync();
90 function testUserScriptTimesOut(runner) {
91 resetAsyncScriptInfo();
92 var info = getAsyncScriptInfo();
94 executeAsyncScript('', [], true, 500);
96 window.setTimeout(function() {
97 assertEquals(StatusCode.SCRIPT_TIMEOUT, info.result.status);
98 assert(info.result.value.indexOf('0.5') != -1);
99 runner.continueTesting();
100 }, 500);
102 runner.waitForAsync();
105 function testNonUserScriptTimesOut(runner) {
106 resetAsyncScriptInfo();
107 var info = getAsyncScriptInfo();
109 executeAsyncScript('', [], false, 500);
111 window.setTimeout(function() {
112 assertEquals(StatusCode.UNKNOWN_ERROR, info.result.status);
113 assert(info.result.value.indexOf('0.5') != -1);
114 runner.continueTesting();
115 }, 500);
117 runner.waitForAsync();
120 function testFirstScriptFinishAfterSecondScriptExecute() {
121 resetAsyncScriptInfo();
123 executeAsyncScript(
124 'var f = arguments[0]; setTimeout(function(){ f(1); }, 100000);', []);
125 var info = getAsyncScriptInfo();
126 assert(!info.hasOwnProperty('result'));
127 assertEquals(1, info.id);
129 executeAsyncScript('var fn = arguments[0]; fn(2);', []);
130 assertEquals(0, info.result.status);
131 assertEquals(2, info.result.value);
132 assertEquals(3, info.id);
135 </script>
136 <body>
137 </body>
138 </html>