OLD | NEW |
| (Empty) |
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
3 <html> | |
4 <!-- Copyright 2009 Google Inc. All rights reserved. --> | |
5 <head> | |
6 <title> SRPC Socket Address API Test </title> | |
7 <META HTTP-EQUIV="Pragma" CONTENT="no-cache" /> | |
8 <META HTTP-EQUIV="Expires" CONTENT="-1" /> | |
9 <style type="text/css"> | |
10 td.notrun { background-color: skyblue } | |
11 td.pass { background-color: lime } | |
12 td.fail { background-color: red } | |
13 </style> | |
14 <script type="application/x-javascript"> | |
15 //<![CDATA[ | |
16 var SetTestResult = function(element_id, result) { | |
17 var element = document.getElementById(element_id); | |
18 element.className = result; | |
19 } | |
20 | |
21 // The NaCl module. Used to produce handles and for __shmFactory invocations. | |
22 var server; | |
23 // The default socket address for the plugin. | |
24 var default_addr; | |
25 // The count of failing tests. Set from the queue length, and decremented | |
26 // whenever a test passes. | |
27 var failing_count; | |
28 | |
29 // The queue of small tests. | |
30 var testQueue = [ ]; | |
31 var appendTest = function(test_descr) { | |
32 testQueue[testQueue.length] = test_descr; | |
33 } | |
34 | |
35 var expectPass = function(element, has_return, fp) { | |
36 appendTest(new Array('pass', element, has_return, fp)); | |
37 } | |
38 | |
39 var expectFail = function(element, fp) { | |
40 appendTest(new Array('fail', element, fp)); | |
41 } | |
42 | |
43 var DefaultSocketAddress = function() { | |
44 // Test the creation of socket address objects. | |
45 // Attempt to retrieve with the wrong number of parameters. | |
46 expectFail('default_too_many', | |
47 function() { | |
48 return server.__defaultSocketAddress('extra'); | |
49 }); | |
50 // Attempt to get the default socket address. | |
51 expectPass('default_conforming', | |
52 true, | |
53 function() { | |
54 return server.__defaultSocketAddress(); | |
55 }); | |
56 } | |
57 | |
58 var Connect = function() { | |
59 // Test connection to socket address objects. | |
60 // Attempt to create with the wrong number of parameters. | |
61 expectFail('connect_too_many', | |
62 function() { | |
63 return default_addr.connect('extra'); | |
64 }); | |
65 // Attempt to connect to the default socket address. | |
66 expectPass('connect_default', | |
67 true, | |
68 function() { | |
69 return default_addr.connect(); | |
70 }); | |
71 // Attempt to connect to a socket address returned from a NaCl module. | |
72 expectPass('connect_nacl', | |
73 true, | |
74 function() { | |
75 var sockaddr = server.start_server(); | |
76 return sockaddr.connect(); | |
77 }); | |
78 } | |
79 | |
80 // The test run functions. | |
81 var testExpectedPass = function(element, has_return, fp) { | |
82 var result = undefined; | |
83 try { | |
84 result = fp(); | |
85 if (has_return && (undefined == result)) { | |
86 SetTestResult(element, 'fail'); | |
87 } else { | |
88 SetTestResult(element, 'pass'); | |
89 --failing_count; | |
90 } | |
91 } catch (string) { | |
92 SetTestResult(element, 'fail'); | |
93 } | |
94 } | |
95 | |
96 var testExpectedFail = function(element, fp) { | |
97 var result = undefined; | |
98 try { | |
99 result = fp(); | |
100 SetTestResult(element, 'fail'); | |
101 } catch (string) { | |
102 if (undefined == result) { | |
103 SetTestResult(element, 'pass'); | |
104 --failing_count; | |
105 } else { | |
106 SetTestResult(element, 'fail'); | |
107 } | |
108 } | |
109 } | |
110 | |
111 var RunAllTests = function() { | |
112 var i; | |
113 var len = testQueue.length; | |
114 // All tests are considered failure until they have run successfully. | |
115 // This catches runs that end prematurely. | |
116 failing_count = len; | |
117 for (i = 0; i < len; ++i) { | |
118 var test_descr = testQueue[i]; | |
119 if ('pass' == test_descr[0]) { | |
120 testExpectedPass(test_descr[1], test_descr[2], test_descr[3]); | |
121 } else { | |
122 testExpectedFail(test_descr[1], test_descr[2]); | |
123 } | |
124 } | |
125 } | |
126 | |
127 var EnqueueAndRunTests = function() { | |
128 // Setup -- abort entire test if this fails. | |
129 try { | |
130 // If these fail at the beginning, all the tests will abort. | |
131 // Otherwise more specific tests are done on them. | |
132 default_addr = server.__defaultSocketAddress(); | |
133 } catch (string) { | |
134 window.alert('Socket address test setup failed.'); | |
135 return; | |
136 } | |
137 // Enqueue the tests. | |
138 DefaultSocketAddress(); | |
139 Connect(); | |
140 // Run them all. | |
141 RunAllTests(); | |
142 } | |
143 //]]> | |
144 </script> | |
145 </head> | |
146 <body onload="nacllib.waitForModulesAndRunTests();" | |
147 onunload="nacllib.cleanUp();" > | |
148 <h1> SRPC Socket Address API Test </h1> | |
149 <table cellspacing=5 cellpadding=5 border=5 summary="Test status table"> | |
150 <tr> | |
151 <td> | |
152 </td> | |
153 <td> | |
154 <b> __defaultSocketAddress tests </b> | |
155 </td> | |
156 <td> | |
157 <b> connect tests </b> | |
158 </td> | |
159 </tr> | |
160 <tr> | |
161 <td> | |
162 <b> Argument count tests </b> | |
163 </td> | |
164 <td> | |
165 <table summary="Default argument count test"> | |
166 <tr> | |
167 <td id="default_too_many" class="notrun"> | |
168 argc: too many | |
169 </td> | |
170 </tr> | |
171 </table> | |
172 </td> | |
173 <td> | |
174 <table summary="Connect argument count test"> | |
175 <tr> | |
176 <td id="connect_too_many" class="notrun"> | |
177 argc: too many | |
178 </td> | |
179 </tr> | |
180 </table> | |
181 </td> | |
182 </tr> | |
183 | |
184 <tr> | |
185 <td> | |
186 <b> Expected behavior </b> | |
187 </td> | |
188 <td valign=top> | |
189 <table summary="Default behavior tests"> | |
190 <tr> | |
191 <td id="default_conforming" class="notrun"> | |
192 conforming invocation | |
193 </td> | |
194 </tr> | |
195 </table> | |
196 </td> | |
197 <td valign=top> | |
198 <table summary="Connection behavior tests"> | |
199 <tr> | |
200 <td id="connect_default" class="notrun"> | |
201 to default | |
202 </td> | |
203 </tr> | |
204 <tr> | |
205 <td id="connect_nacl" class="notrun"> | |
206 to address returned from NaCl | |
207 </td> | |
208 </tr> | |
209 </table> | |
210 </td> | |
211 </tr> | |
212 </table> | |
213 | |
214 <table summary="The color codes used for identifying test outcomes"> | |
215 <tr> <td align="center"> <em> Legend </em> </td> </tr> | |
216 <tr> <td align="center" class="notrun"> Test not run </td> </tr> | |
217 <tr> <td align="center" class="pass"> Test passed </td> </tr> | |
218 <tr> <td align="center" class="fail"> Test failed </td> </tr> | |
219 </table> | |
220 <p> | |
221 <b> | |
222 NOTE: Some versions of some WebKit-based browsers do not correctly report | |
223 JavaScript exceptions raised by NPAPI plugins. This can cause some of | |
224 the above tests to spuriously report failure. | |
225 </b> | |
226 </p> | |
227 | |
228 <div id=status>NO-STATUS</div> | |
229 | |
230 <embed type="application/x-ppapi-nacl-srpc" id="nacl_server" | |
231 name="nacl_module" width="0" height="0" src="srpc_nrd_server.nexe" /> | |
232 | |
233 <script type="text/javascript" src="nacl_js_lib.js"></script> | |
234 <script type="text/javascript"> | |
235 //<![CDATA[ | |
236 var nacllib = new NaclLib("nacl_module", "status", 500); | |
237 | |
238 nacllib.test = function() { | |
239 server = document.getElementById("nacl_server"); | |
240 EnqueueAndRunTests(); | |
241 if (0 == testQueue.length) { | |
242 return "No tests run."; | |
243 } else if (0 != failing_count) { | |
244 return "Tests failed."; | |
245 } else { | |
246 return ""; | |
247 } | |
248 } | |
249 //]]> | |
250 </script> | |
251 </body> | |
252 </html> | |
OLD | NEW |