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 2008 Google Inc. All rights reserved. --> | |
5 <head> | |
6 <title>SRPC Open URL as NaCl Descriptor Test</title> | |
7 <META HTTP-EQUIV="Pragma" CONTENT="no-cache" /> | |
8 <META HTTP-EQUIV="Expires" CONTENT="-1" /> | |
9 <style type="text/css"> | |
10 pre.notrun { background-color: skyblue } | |
11 pre.pass { background-color: lime } | |
12 pre.fail { background-color: red } | |
13 td.notrun { background-color: skyblue } | |
14 td.pass { background-color: lime } | |
15 td.fail { background-color: red } | |
16 </style> | |
17 <script type="application/x-javascript"> | |
18 //<![CDATA[ | |
19 var server = 0; | |
20 var logElement = 0; | |
21 var testTimeoutHandler = 0; | |
22 var testPassed = false; | |
23 var testErrorMsg = ''; | |
24 | |
25 // testState normally assumes these state values in this order: | |
26 // 'initializing'=>'loading valid file'=>'loading invalid file'=>'complete' | |
27 var testState = ''; | |
28 | |
29 // Puts text from 'str' into the logElement on the page. | |
30 function generalLog(str) { | |
31 logElement.textContent += str + '\n'; | |
32 } | |
33 | |
34 // Clears the test watchdog timer. | |
35 function clearTestTimeoutHandler() { | |
36 if (0 != testTimeoutHandler) { | |
37 clearTimeout(testTimeoutHandler); | |
38 testTimeoutHandler = 0; | |
39 } | |
40 } | |
41 | |
42 // Sets all test status information and cleans up after testing. | |
43 // 'msg' is the error message or '' for success. | |
44 function allTestsComplete(msg) { | |
45 clearTestTimeoutHandler(); | |
46 testState = 'complete'; | |
47 testErrorMsg = msg; | |
48 if (testPassed) { | |
49 logElement.className = 'pass'; | |
50 } else { | |
51 logElement.className = 'fail'; | |
52 } | |
53 } | |
54 | |
55 // Test Stage 6: Verifies that a cross-domain file cannot be loaded. | |
56 function invalidFileLoadCallback() { | |
57 this.onload = function(nacl_desc) { | |
58 // Should not have been able to load a cross-domain file. | |
59 generalLog('ERROR: invalidFileLoadCallback onload invoked.'); | |
60 generalLog('Loading from a nonexistent URL should have been an error.'); | |
61 allTestsComplete('Load of nonexistent URL succeeded (incorrectly).'); | |
62 } | |
63 this.onfail = function(object) { | |
64 // Correctly invoked the onfail handler for attempting to read a | |
65 // cross-domain file. Everything is working as expected. | |
66 generalLog('invalidFileLoadCallback onfail correctly invoked: ' + | |
67 object); | |
68 testPassed = true; | |
69 allTestsComplete(''); | |
70 } | |
71 } | |
72 | |
73 // Test Stage 5: Starts a load of an invalid URL (which should not work). | |
74 function startInvalidFileLoad() { | |
75 testState = 'loading cross-origin file'; | |
76 var url = 'url_as_nacl_desc_nonexistent_url.html'; | |
77 generalLog('Loading URL ' + url); | |
78 generalLog('Expecting to see url get failure.'); | |
79 server.__urlAsNaClDesc(url, new invalidFileLoadCallback()); | |
80 } | |
81 | |
82 // Test Stage 4: Verifies that a cross-domain file cannot be loaded. | |
83 function crossOriginFileLoadCallback() { | |
84 this.onload = function(nacl_desc) { | |
85 // Should not have been able to load a cross-domain file. | |
86 generalLog('ERROR: crossOriginFileLoadCallback onload invoked.'); | |
87 generalLog('Loading from the wrong domain should have been an error.'); | |
88 allTestsComplete('Load of cross-origin file succeeded (incorrectly).'); | |
89 } | |
90 this.onfail = function(object) { | |
91 // Correctly invoked the onfail handler for attempting to read a | |
92 // cross-domain file. Everything is working as expected. | |
93 generalLog('crossOriginFileLoadCallback onfail correctly invoked: ' + | |
94 object); | |
95 // TODO(sehr): selenium always returns a table of contents when | |
96 // an invalid url is specified. Enable this next line and remove the | |
97 // setting of testPassed and call to allTestsComplete when that is fixed. | |
98 // startInvalidFileLoad(); | |
99 testPassed = true; | |
100 allTestsComplete(''); | |
101 } | |
102 } | |
103 | |
104 // Test Stage 3: Starts a load of a cross-domain file (which should not work). | |
105 function startCrossOriginFileLoad() { | |
106 testState = 'loading cross-origin file'; | |
107 var url = 'http://www.google.com/robots.txt'; | |
108 generalLog('Loading URL ' + url); | |
109 generalLog('Expecting to see same origin violation.'); | |
110 server.__urlAsNaClDesc(url, new crossOriginFileLoadCallback()); | |
111 } | |
112 | |
113 // Test Stage 2: Verifies that an existing file can be loaded. | |
114 function validFileLoadCallback() { | |
115 this.onload = function(nacl_desc) { | |
116 // Get the data that was loaded from the file. | |
117 generalLog('validFileLoadCallback onload correctly invoked.'); | |
118 var msg = server.cat(nacl_desc, 4096); | |
119 generalLog('cat returned, converting to string.'); | |
120 var str = ''; | |
121 var len = msg.length; | |
122 var byte; | |
123 for (var i = 0; i < len && (byte = msg[i]) != 0; i++) { | |
124 str += String.fromCharCode(byte); | |
125 } | |
126 generalLog(str); | |
127 | |
128 // Note that the Selenium framework returns a list of all files that | |
129 // *could* be opened if the requested file could not be opened. | |
130 // Check for getting the real data from the test file, not just the | |
131 // list of all existing files. | |
132 var expected_text = 'TEST PASSED'; | |
133 if (str.indexOf(expected_text) >= 0) { | |
134 // Start a load from the wrong domain. | |
135 startCrossOriginFileLoad(); | |
136 } else { | |
137 generalLog('ERROR: validFileLoadCallback did not find expected text: ' + | |
138 expected_text); | |
139 allTestsComplete('File load test did not find text: ' + expected_text); | |
140 } | |
141 } | |
142 this.onfail = function(object) { | |
143 generalLog('ERROR: validFileLoadCallback onfail invoked: ' + object); | |
144 allTestsComplete('File load test failed: ' + object); | |
145 } | |
146 } | |
147 | |
148 // Test Stage 1: Starts a load of a valid file. | |
149 function startValidFileLoad() { | |
150 testState = 'loading valid file'; | |
151 var url = 'srpc_url_as_nacl_desc_success.html'; | |
152 generalLog('Loading URL ' + url); | |
153 server.__urlAsNaClDesc(url, new validFileLoadCallback()); | |
154 } | |
155 | |
156 // Test watchdog timer. Makes sure the test does not run too long if | |
157 // something hangs. | |
158 function handleTestTimeout() { | |
159 generalLog('The test did not finish in the allotted time.'); | |
160 allTestsComplete('Test timed out, testState=' + testState); | |
161 } | |
162 //]]> | |
163 </script> | |
164 </head> | |
165 <body onload="nacllib.waitForModulesAndRunTests();" | |
166 onunload="nacllib.cleanUp();" > | |
167 | |
168 <h1>SRPC Open URL as NaCl Descriptor Test</h1> | |
169 | |
170 <h2> Output logs</h2> | |
171 <table border=5 cellpadding=5% summary="Test status table"> | |
172 <tr> | |
173 <td><b>General test output</b></td> | |
174 </tr> | |
175 <tr> | |
176 <td valign=top><pre id="GeneralOutput"></pre></td> | |
177 </tr> | |
178 </table> | |
179 | |
180 <table summary="The color codes used for identifying test outcomes"> | |
181 <tr> <td align="center"> <em> Legend </em> </td> </tr> | |
182 <tr> <td align="center" class="notrun"> Test not run </td> </tr> | |
183 <tr> <td align="center" class="pass"> Test passed </td> </tr> | |
184 <tr> <td align="center" class="fail"> Test failed </td> </tr> | |
185 </table> | |
186 | |
187 <p> | |
188 <b> | |
189 NOTE: Some versions of some WebKit-based browsers do not correctly report | |
190 JavaScript exceptions raised by NPAPI plugins. This can cause some of | |
191 the above tests to spuriously report failure. | |
192 </b> | |
193 </p> | |
194 | |
195 <div id="status">NO-STATUS</div> | |
196 | |
197 <embed type="application/x-ppapi-nacl-srpc" id="nacl_server" | |
198 name="nacl_module" width="0" height="0" src="cat.nexe" /> | |
199 | |
200 <script type="text/javascript" src="nacl_js_lib.js"></script> | |
201 <script type="text/javascript"> | |
202 //<![CDATA[ | |
203 var nacllib = new NaclLib('nacl_module', 'status', 500); | |
204 | |
205 // Returns true ("wait") to the NaclLib test driver until all of the | |
206 // tests are complete. I.e., either all of the file load callbacks have | |
207 // completed successfully or an error has occurred. | |
208 nacllib.wait = function() { | |
209 if ('' == testState) { | |
210 // The module has successfully loaded and this code is being | |
211 // called for the first time. Get set up and start testing. | |
212 testState = 'initializing'; | |
213 | |
214 server = document.getElementById('nacl_server'); | |
215 logElement = document.getElementById('GeneralOutput'); | |
216 generalLog('Module loaded.'); | |
217 | |
218 testTimeoutHandler = setTimeout('handleTestTimeout()', 10000); | |
219 startValidFileLoad(); | |
220 return true; | |
221 } else if ('complete' != testState) { | |
222 // Continue to return true until all testing is complete. This tells | |
223 // the test driver to wait before calling the test() method. | |
224 return true; | |
225 } else { | |
226 // Testing is complete. Allow the test driver to call test(). | |
227 return false; | |
228 } | |
229 } | |
230 | |
231 // Returns the test status to the NaclLib test driver. This is called | |
232 // by the NaclLib test driver after the wait() method has returned false. | |
233 // I.e., this is called only after all tests are complete. | |
234 nacllib.test = function() { | |
235 // The actual testing is all finished by the time this method is | |
236 // called, so just return the test results. | |
237 if ('' == testState) { | |
238 return 'The module did not load.'; | |
239 } else if (!testPassed && '' != testErrorMsg) { | |
240 return testErrorMsg; | |
241 } else if (!testPassed) { | |
242 return 'Generic test failure.'; | |
243 } else { | |
244 return ''; | |
245 } | |
246 } | |
247 //]]> | |
248 </script> | |
249 </body> | |
250 </html> | |
OLD | NEW |