| 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 if (0 == failing_count) { | |
| 126 // Set the magic Selenium variable to signal success. | |
| 127 document.cookie = 'status=OK'; | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 var EnqueueAndRunTests = function() { | |
| 132 // Setup -- abort entire test if this fails. | |
| 133 try { | |
| 134 // If these fail at the beginning, all the tests will abort. | |
| 135 // Otherwise more specific tests are done on them. | |
| 136 default_addr = server.__defaultSocketAddress(); | |
| 137 } catch (string) { | |
| 138 window.alert('Socket address test setup failed.'); | |
| 139 return; | |
| 140 } | |
| 141 // Enqueue the tests. | |
| 142 DefaultSocketAddress(); | |
| 143 Connect(); | |
| 144 // Run them all. | |
| 145 RunAllTests(); | |
| 146 } | |
| 147 //]]> | |
| 148 </script> | |
| 149 </head> | |
| 150 <body onload="nacllib.waitForModulesAndRunTests();" | |
| 151 onunload="nacllib.cleanUp();" > | |
| 152 <h1> SRPC Socket Address API Test </h1> | |
| 153 <table cellspacing=5 cellpadding=5 border=5 summary="Test status table"> | |
| 154 <tr> | |
| 155 <td> | |
| 156 </td> | |
| 157 <td> | |
| 158 <b> __defaultSocketAddress tests </b> | |
| 159 </td> | |
| 160 <td> | |
| 161 <b> connect tests </b> | |
| 162 </td> | |
| 163 </tr> | |
| 164 <tr> | |
| 165 <td> | |
| 166 <b> Argument count tests </b> | |
| 167 </td> | |
| 168 <td> | |
| 169 <table summary="Default argument count test"> | |
| 170 <tr> | |
| 171 <td id="default_too_many" class="notrun"> | |
| 172 argc: too many | |
| 173 </td> | |
| 174 </tr> | |
| 175 </table> | |
| 176 </td> | |
| 177 <td> | |
| 178 <table summary="Connect argument count test"> | |
| 179 <tr> | |
| 180 <td id="connect_too_many" class="notrun"> | |
| 181 argc: too many | |
| 182 </td> | |
| 183 </tr> | |
| 184 </table> | |
| 185 </td> | |
| 186 </tr> | |
| 187 | |
| 188 <tr> | |
| 189 <td> | |
| 190 <b> Expected behavior </b> | |
| 191 </td> | |
| 192 <td valign=top> | |
| 193 <table summary="Default behavior tests"> | |
| 194 <tr> | |
| 195 <td id="default_conforming" class="notrun"> | |
| 196 conforming invocation | |
| 197 </td> | |
| 198 </tr> | |
| 199 </table> | |
| 200 </td> | |
| 201 <td valign=top> | |
| 202 <table summary="Connection behavior tests"> | |
| 203 <tr> | |
| 204 <td id="connect_default" class="notrun"> | |
| 205 to default | |
| 206 </td> | |
| 207 </tr> | |
| 208 <tr> | |
| 209 <td id="connect_nacl" class="notrun"> | |
| 210 to address returned from NaCl | |
| 211 </td> | |
| 212 </tr> | |
| 213 </table> | |
| 214 </td> | |
| 215 </tr> | |
| 216 </table> | |
| 217 | |
| 218 <table summary="The color codes used for identifying test outcomes"> | |
| 219 <tr> <td align="center"> <em> Legend </em> </td> </tr> | |
| 220 <tr> <td align="center" class="notrun"> Test not run </td> </tr> | |
| 221 <tr> <td align="center" class="pass"> Test passed </td> </tr> | |
| 222 <tr> <td align="center" class="fail"> Test failed </td> </tr> | |
| 223 </table> | |
| 224 <p> | |
| 225 <b> | |
| 226 NOTE: Some versions of some WebKit-based browsers do not correctly report | |
| 227 JavaScript exceptions raised by NPAPI plugins. This can cause some of | |
| 228 the above tests to spuriously report failure. | |
| 229 </b> | |
| 230 </p> | |
| 231 | |
| 232 <div id=status>NO-STATUS</div> | |
| 233 | |
| 234 <embed type="application/x-nacl" id="nacl_server" name="nacl_module" | |
| 235 width="0" height="0" src="srpc_nrd_server.nexe" /> | |
| 236 | |
| 237 <script type="text/javascript" src="nacl_js_lib.js"></script> | |
| 238 <script type="text/javascript"> | |
| 239 //<![CDATA[ | |
| 240 var nacllib = new NaclLib("nacl_module", "status", 500); | |
| 241 | |
| 242 nacllib.test = function() { | |
| 243 server = document.getElementById("nacl_server"); | |
| 244 EnqueueAndRunTests(); | |
| 245 if (0 == testQueue.length) { | |
| 246 return "No tests run."; | |
| 247 } else if (0 != failing_count) { | |
| 248 return "Tests failed."; | |
| 249 } else { | |
| 250 return ""; | |
| 251 } | |
| 252 } | |
| 253 //]]> | |
| 254 </script> | |
| 255 </body> | |
| 256 </html> | |
| OLD | NEW |