summaryrefslogtreecommitdiffstats
path: root/src/civetweb/test/ajax/test.html
blob: 40fa07997724045ca736206d31ada0429c774ec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <title>Test</title>
    <script type='text/javascript' language="javascript" src='jquery.js'></script>
    <script type='text/javascript' language="javascript">
    <!--

    function mbox() {
      alert('Javascript OK');
    }


    var totalCount = 10;
    var pendingCount = 0;
    var errorCount = 0;
    var pushCount = 0;
    var allErrorCount = 0;
    var autoTest = false;
    var testType = "cgi";

    function NextTestType() {
      if (testType == "cgi") testType = "lp";
      else if (testType == "lp") testType = "lua";
      else testType = "cgi";
    }

    function runTest(method, isAsync) {

      ++pushCount;
      document.getElementById('start').innerHTML = 'Test: ' + pushCount;
      document.getElementById('resTotal').innerHTML = 'running';

      for (var i = 1; i <= totalCount; ++i) {
        document.getElementById('res'+i).innerHTML = "ready";
      }

      errorCount = 0;
      pendingCount = totalCount;

      for (var i = 1; i <= totalCount; ++i) {

        fetch(i,  method, isAsync);
      }
    }
    
    function runAutoTest() {
      if (autoTest) {
        runTest("POST", true)
        setTimeout("runAutoTest()", 250)
      }
    }


    function fetch(id, method, isAsync) {

      document.getElementById('res'+id).innerHTML = "pending";

      $.ajax({
        async: isAsync,
        url: 'echo.' + testType + '?id=' + id,
        type: method,
        timeout: 2000,
        data: { 'id' : id ,
                'longText1' : "adfsdfasdklkjlgasfdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
                'longText2' : "bsdfsdfasdklkjlgasdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
                'longText3' : "sdfsadagsdklkjlgasdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
                'longText4' : "q34sdfas3fhbkjlgasdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
                'longText5' : "askj2kjcvxychklgasdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
                'longText6' : "asdfjklhlkjhv8öajsdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
                'async' : isAsync
              },
        dataType: 'json',
        succes: function(data) {
        },
        error: function() {
          ++errorCount;
        },
        complete: function(jqXHR, textStatus) {

          --pendingCount;

          document.getElementById('res'+id).innerHTML = textStatus;
          console.log('id: ' + id + ' (' + pendingCount + '/' + totalCount + '), status: ' + textStatus);

          if (pendingCount == 0) {
            document.getElementById('resTotal').innerHTML = 'done';
            console.log('complete, error count: ' + errorCount);
            allErrorCount = allErrorCount + errorCount;
            document.getElementById('resSAll').innerHTML = 'total errors: ' + allErrorCount + "/" + (pushCount*totalCount);
          }
        }
      });

    }


    //-->
    </script>

  </head>
  <body>
    <p>
      <div id="start">Test not started.</div>
    </p>
    <p>
      <table>
        <tr>
          <td>
            <input id="testButton1" type="button" onclick="javascript:runTest('GET', false)" value="sync GET"></input>
          </td>
          <td>
            <input id="testButton2" type="button" onclick="javascript:runTest('POST', false)" value="sync POST"></input>
          </td>
        </tr>
        <tr>
          <td>
            <input id="testButton3" type="button" onclick="javascript:runTest('GET', true)" value="async GET"></input>
          </td>
          <td>
            <input id="testButton4" type="button" onclick="javascript:runTest('POST', true)" value="async POST"></input>
          </td>
        </tr>
        <tr>
          <td>
            <input id="testButton5" type="button" onclick="autoTest=!autoTest; javascript:runAutoTest()" value="automatic test"></input>
          </td>        
          <td>
            <input id="testButton6" type="button" onclick="NextTestType(); this.value=testType" value='cgi'></input>
          </td>        
        </tr>
        
        <tr>
          <td>
            <input id="testButtonReset" type="button" onclick="autoTest=false; javascript:location.reload(true)" value="reset"></input>
          </td>
          <td>
            <input id="testButtonBack" type="button" onclick="history.back()" value="back"></input>
          </td>
        </tr>
        <tr>
          <td>
            <input id="testButtonBox" type="button" onclick="javascript:mbox()" value="MsgBox"></input>            
          </td>
          <td>
          </td>
        </tr>
      </table>
    </p>
    <p>
      <table border="1">
        <tr><th>Test</th><th>Result</th></tr>
        <tr><td>1</td><td><div id="res1">not started</div></td></tr>
        <tr><td>2</td><td><div id="res2">not started</div></td></tr>
        <tr><td>3</td><td><div id="res3">not started</div></td></tr>
        <tr><td>4</td><td><div id="res4">not started</div></td></tr>
        <tr><td>5</td><td><div id="res5">not started</div></td></tr>
        <tr><td>6</td><td><div id="res6">not started</div></td></tr>
        <tr><td>7</td><td><div id="res7">not started</div></td></tr>
        <tr><td>8</td><td><div id="res8">not started</div></td></tr>
        <tr><td>9</td><td><div id="res9">not started</div></td></tr>
        <tr><td>10</td><td><div id="res10">not started</div></td></tr>
      </table>
      <div id="resTotal">Push [Test] to start.</div>
      <div id="resSAll"></div>
    </p>
  </body>
</html>