[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 1 | <html><head> |
[email protected] | 849b071 | 2011-04-28 19:15:08 | [diff] [blame] | 2 | <meta http-equiv="Pragma" content="no-cache" /> |
| 3 | <meta http-equiv="Expires" content="-1" /> |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 4 | <link rel="stylesheet" href="test_page.css"> |
| 5 | <script> |
| 6 | function AdjustHeight(frameWin) { |
| 7 | var div = frameWin.document.getElementsByTagName("div")[0]; |
| 8 | var height = frameWin.getComputedStyle(div).height; |
| 9 | frameWin.frameElement.style.height = height; |
| 10 | } |
| 11 | |
[email protected] | e7425db | 2013-07-17 20:15:21 | [diff] [blame] | 12 | // Called when the tests are completed. |result| should be "PASS" if the test(s) |
| 13 | // passed, or information about the failure if the test(s) did not pass. |
| 14 | function DidExecuteTests(result) { |
[email protected] | 13e343c | 2012-03-16 22:34:22 | [diff] [blame] | 15 | var plugin = document.getElementById("plugin"); |
[email protected] | 9e998c0f | 2013-11-02 13:27:52 | [diff] [blame] | 16 | if (plugin.parentNode.removePlugin) { |
[email protected] | e7425db | 2013-07-17 20:15:21 | [diff] [blame] | 17 | plugin.parentNode.removeChild(plugin); |
| 18 | plugin = undefined; |
| 19 | } |
| 20 | if (CheckPostConditions()) |
| 21 | sendAutomationMessage(result); |
[email protected] | 13e343c | 2012-03-16 22:34:22 | [diff] [blame] | 22 | |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 23 | if (window == top) |
| 24 | return; |
| 25 | |
| 26 | // Otherwise, we are in a subframe, so we can use this opportunity to resize |
| 27 | // ourselves. |
| 28 | AdjustHeight(window); |
| 29 | } |
| 30 | |
| 31 | function AppendFrame(testcase, i) { |
| 32 | var p = document.createElement("P"); |
| 33 | p.setAttribute("class", "frame-container"); |
| 34 | |
| 35 | var title = document.createElement("H2"); |
| 36 | title.appendChild(document.createTextNode(testcase)); |
| 37 | p.appendChild(title); |
| 38 | |
| 39 | var frame = document.createElement("IFRAME"); |
[email protected] | 849b071 | 2011-04-28 19:15:08 | [diff] [blame] | 40 | var mode = ExtractSearchParameter("mode"); |
[email protected] | 21de9cb2 | 2013-02-14 13:07:34 | [diff] [blame] | 41 | var websocket_host = ExtractSearchParameter("websocket_host"); |
[email protected] | bedf874 | 2012-03-16 16:44:11 | [diff] [blame] | 42 | var websocket_port = ExtractSearchParameter("websocket_port"); |
[email protected] | 6c11340 | 2012-03-23 01:31:51 | [diff] [blame] | 43 | var ssl_server_port = ExtractSearchParameter("ssl_server_port"); |
[email protected] | bedf874 | 2012-03-16 16:44:11 | [diff] [blame] | 44 | var src = "?testcase=" + testcase; |
[email protected] | 849b071 | 2011-04-28 19:15:08 | [diff] [blame] | 45 | if (mode == "nacl") |
[email protected] | bedf874 | 2012-03-16 16:44:11 | [diff] [blame] | 46 | src += "&mode=nacl"; |
[email protected] | 21de9cb2 | 2013-02-14 13:07:34 | [diff] [blame] | 47 | if (websocket_host != "") |
| 48 | src += "&websocket_host=" + websocket_host; |
[email protected] | bedf874 | 2012-03-16 16:44:11 | [diff] [blame] | 49 | if (websocket_port != "") |
| 50 | src += "&websocket_port=" + websocket_port; |
[email protected] | 6c11340 | 2012-03-23 01:31:51 | [diff] [blame] | 51 | if (ssl_server_port != "") |
| 52 | src += "&ssl_server_port=" + ssl_server_port; |
[email protected] | bedf874 | 2012-03-16 16:44:11 | [diff] [blame] | 53 | frame.setAttribute("src", src); |
| 54 | |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 55 | frame.setAttribute("onload", "LoadNext(" + (i + 1) + ")"); |
| 56 | p.appendChild(frame); |
| 57 | |
| 58 | document.body.appendChild(p); |
| 59 | } |
| 60 | |
| 61 | function LoadNext(i) { |
| 62 | var links = document.links; |
| 63 | if (links.length > i) |
| 64 | AppendFrame(links[i].firstChild.nodeValue, i); |
| 65 | } |
| 66 | |
| 67 | function RunAll() { |
| 68 | // Remove any existing frames. |
| 69 | var existing = document.getElementsByClassName("frame-container"); |
| 70 | while (existing.length) |
| 71 | existing[0].parentNode.removeChild(existing[0]); |
| 72 | |
| 73 | // Add new frames for each test, but do so one frame at a time. |
| 74 | LoadNext(0); |
| 75 | } |
| 76 | |
[email protected] | 52d2c8e0 | 2010-11-16 20:59:23 | [diff] [blame] | 77 | function ExtractSearchParameter(name) { |
| 78 | var nameIndex = location.search.indexOf(name + "="); |
| 79 | if (nameIndex != -1) { |
| 80 | var value = location.search.substring(nameIndex + name.length + 1); |
| 81 | var endIndex = value.indexOf("&"); |
| 82 | if (endIndex != -1) |
| 83 | value = value.substring(0, endIndex); |
| 84 | return value; |
| 85 | } |
| 86 | return ""; |
| 87 | } |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 88 | |
[email protected] | 7f801d8 | 2011-07-08 23:30:11 | [diff] [blame] | 89 | // Parses the message, looking for strings of the form: |
| 90 | // TESTING_MESSAGE:<message_type>:<message_contents> |
| 91 | // |
| 92 | // If the message_data is not a string or does not match the above format, then |
| 93 | // undefined is returned. |
| 94 | // |
| 95 | // Otherwise, returns an array containing 2 items. The 0th element is the |
| 96 | // message_type, one of: |
[email protected] | 13e343c | 2012-03-16 22:34:22 | [diff] [blame] | 97 | // - AddPostCondition |
[email protected] | e7425db | 2013-07-17 20:15:21 | [diff] [blame] | 98 | // - ClearConsole |
| 99 | // - DidExecuteTests |
| 100 | // - EvalScript |
| 101 | // - LogHTML |
| 102 | // - RemovePluginWhenFinished |
| 103 | // - ReportProgress |
[email protected] | 7f801d8 | 2011-07-08 23:30:11 | [diff] [blame] | 104 | // The second item is the verbatim message_contents. |
| 105 | function ParseTestingMessage(message_data) { |
[email protected] | 13e343c | 2012-03-16 22:34:22 | [diff] [blame] | 106 | if (typeof(message_data) != "string") |
[email protected] | 7f801d8 | 2011-07-08 23:30:11 | [diff] [blame] | 107 | return undefined; |
| 108 | var testing_message_prefix = "TESTING_MESSAGE"; |
| 109 | var delim_str = ":"; |
| 110 | var delim1 = message_data.indexOf(delim_str); |
| 111 | if (message_data.substring(0, delim1) !== testing_message_prefix) |
| 112 | return undefined; |
| 113 | var delim2 = message_data.indexOf(delim_str, delim1 + 1); |
| 114 | if (delim2 == -1) |
| 115 | delim2 = message_data.length; |
| 116 | var message_type = message_data.substring(delim1 + 1, delim2); |
| 117 | var message_contents = message_data.substring(delim2 + 1); |
| 118 | return [message_type, message_contents]; |
| 119 | } |
| 120 | |
| 121 | function ClearConsole() { |
| 122 | window.document.getElementById("console").innerHTML = ""; |
| 123 | } |
| 124 | |
| 125 | function LogHTML(html) { |
| 126 | window.document.getElementById("console").innerHTML += html; |
| 127 | } |
| 128 | |
[email protected] | e7425db | 2013-07-17 20:15:21 | [diff] [blame] | 129 | function RemovePluginWhenFinished() { |
[email protected] | 9e998c0f | 2013-11-02 13:27:52 | [diff] [blame] | 130 | window.document.getElementById("container").removePlugin = true; |
[email protected] | e7425db | 2013-07-17 20:15:21 | [diff] [blame] | 131 | } |
| 132 | |
[email protected] | 00d8e0d | 2013-01-11 15:52:36 | [diff] [blame] | 133 | function sendAutomationMessage(msg) { |
| 134 | if (window.domAutomationController) { |
| 135 | window.domAutomationController.setAutomationId(0); |
| 136 | window.domAutomationController.send(msg); |
| 137 | } |
| 138 | } |
| 139 | |
[email protected] | a33a0898 | 2013-10-31 17:23:29 | [diff] [blame] | 140 | function LogTestTime(test_time) { |
| 141 | console.log(test_time); |
| 142 | } |
| 143 | |
[email protected] | 52d6a08 | 2012-12-06 22:47:42 | [diff] [blame] | 144 | // If something goes really wrong, the test running inside the plugin may not |
| 145 | // terminate. For example, if the plugin does not load, the test will never |
| 146 | // send "PASS" to the browser. In this case we should explicitly use the |
| 147 | // automation controller to terminate the test. |
| 148 | function InternalError(msg) { |
| 149 | LogHTML("<p>" + msg); |
[email protected] | 79efedbd | 2013-01-11 21:53:20 | [diff] [blame] | 150 | sendAutomationMessage(msg); |
[email protected] | 52d6a08 | 2012-12-06 22:47:42 | [diff] [blame] | 151 | } |
| 152 | |
[email protected] | 0861010 | 2011-12-17 14:24:30 | [diff] [blame] | 153 | function EvalScript(script) { |
| 154 | try { |
| 155 | eval(script); |
| 156 | } catch(ex) { |
| 157 | } |
| 158 | } |
| 159 | |
[email protected] | 13e343c | 2012-03-16 22:34:22 | [diff] [blame] | 160 | var conditions = []; |
| 161 | // Add a "PostCondition". These are bits of script that are run after the plugin |
| 162 | // is destroyed. If they evaluate to false or throw an exception, it's |
| 163 | // considered a failure. |
| 164 | function AddPostCondition(script) { |
| 165 | conditions.push(script); |
| 166 | } |
| 167 | // Update the HTML to show the failure and update cookies so that ui_tests |
| 168 | // doesn't count this as a pass. |
| 169 | function ConditionFailed(error) { |
| 170 | error_string = "Post condition check failed: " + error; |
[email protected] | e7425db | 2013-07-17 20:15:21 | [diff] [blame] | 171 | InternalError(error_string); |
[email protected] | 13e343c | 2012-03-16 22:34:22 | [diff] [blame] | 172 | } |
| 173 | // Iterate through the post conditions defined in |conditions| and check that |
| 174 | // they all pass. |
| 175 | function CheckPostConditions() { |
[email protected] | e7425db | 2013-07-17 20:15:21 | [diff] [blame] | 176 | var success = true; |
[email protected] | 13e343c | 2012-03-16 22:34:22 | [diff] [blame] | 177 | for (var i = 0; i < conditions.length; ++i) { |
| 178 | var script = conditions[i]; |
| 179 | try { |
| 180 | if (!eval(script)) { |
| 181 | ConditionFailed("\"" + script + "\""); |
[email protected] | e7425db | 2013-07-17 20:15:21 | [diff] [blame] | 182 | success = false; |
[email protected] | 13e343c | 2012-03-16 22:34:22 | [diff] [blame] | 183 | } |
| 184 | } catch (ex) { |
| 185 | ConditionFailed("\"" + script + "\"" + " failed with exception: " + |
| 186 | "\"" + ex.toString() + "\""); |
[email protected] | e7425db | 2013-07-17 20:15:21 | [diff] [blame] | 187 | success = false; |
[email protected] | 13e343c | 2012-03-16 22:34:22 | [diff] [blame] | 188 | } |
| 189 | } |
[email protected] | e7425db | 2013-07-17 20:15:21 | [diff] [blame] | 190 | return success; |
[email protected] | 13e343c | 2012-03-16 22:34:22 | [diff] [blame] | 191 | } |
| 192 | |
[email protected] | 7f801d8 | 2011-07-08 23:30:11 | [diff] [blame] | 193 | function IsTestingMessage(message_data) { |
| 194 | return (ParseTestingMessage(message_data) != undefined); |
| 195 | } |
| 196 | |
| 197 | function handleTestingMessage(message_event) { |
| 198 | var type_contents_tuple = ParseTestingMessage(message_event.data); |
| 199 | if (type_contents_tuple) { |
| 200 | var type = type_contents_tuple[0]; |
| 201 | var contents = type_contents_tuple[1]; |
[email protected] | e7425db | 2013-07-17 20:15:21 | [diff] [blame] | 202 | if (type === "AddPostCondition") |
| 203 | AddPostCondition(contents); |
| 204 | else if (type === "ClearConsole") |
[email protected] | 7f801d8 | 2011-07-08 23:30:11 | [diff] [blame] | 205 | ClearConsole(); |
| 206 | else if (type === "DidExecuteTests") |
[email protected] | e7425db | 2013-07-17 20:15:21 | [diff] [blame] | 207 | DidExecuteTests(contents); |
[email protected] | 0861010 | 2011-12-17 14:24:30 | [diff] [blame] | 208 | else if (type === "EvalScript") |
| 209 | EvalScript(contents); |
[email protected] | e7425db | 2013-07-17 20:15:21 | [diff] [blame] | 210 | else if (type === "LogHTML") |
| 211 | LogHTML(contents); |
| 212 | else if (type === "RemovePluginWhenFinished") |
| 213 | RemovePluginWhenFinished(); |
| 214 | else if (type === "ReportProgress") |
| 215 | sendAutomationMessage(contents); |
[email protected] | a33a0898 | 2013-10-31 17:23:29 | [diff] [blame] | 216 | else if (type === "LogTestTime") |
| 217 | LogTestTime(contents); |
[email protected] | 7f801d8 | 2011-07-08 23:30:11 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
[email protected] | 00d8e0d | 2013-01-11 15:52:36 | [diff] [blame] | 221 | function sendProgress() { |
[email protected] | 00d8e0d | 2013-01-11 15:52:36 | [diff] [blame] | 222 | // We send "..." to signal that we're still working. See |
| 223 | // ppapi/tests/testing_instance.h for how this works. |
| 224 | sendAutomationMessage("..."); |
| 225 | } |
| 226 | |
[email protected] | 52d2c8e0 | 2010-11-16 20:59:23 | [diff] [blame] | 227 | onload = function() { |
| 228 | var testcase = ExtractSearchParameter("testcase"); |
| 229 | var mode = ExtractSearchParameter("mode"); |
| 230 | document.title = 'Test ' + testcase; |
| 231 | var obj; |
[email protected] | 4223f8d | 2012-06-07 01:10:06 | [diff] [blame] | 232 | if (mode == "nacl_newlib") { |
[email protected] | 88bfb43 | 2011-05-23 22:43:59 | [diff] [blame] | 233 | obj = document.createElement("EMBED"); |
[email protected] | 4223f8d | 2012-06-07 01:10:06 | [diff] [blame] | 234 | obj.setAttribute("src", "ppapi_nacl_tests_newlib.nmf"); |
| 235 | obj.setAttribute("type", "application/x-nacl"); |
| 236 | obj.setAttribute("mode", mode); |
| 237 | } else if (mode == "nacl_glibc") { |
| 238 | obj = document.createElement("EMBED"); |
| 239 | obj.setAttribute("src", "ppapi_nacl_tests_glibc.nmf"); |
[email protected] | 849b071 | 2011-04-28 19:15:08 | [diff] [blame] | 240 | obj.setAttribute("type", "application/x-nacl"); |
[email protected] | 52d2c8e0 | 2010-11-16 20:59:23 | [diff] [blame] | 241 | obj.setAttribute("mode", mode); |
[email protected] | 1e40ba00 | 2013-03-07 22:07:33 | [diff] [blame] | 242 | } else if (mode == "nacl_pnacl") { |
| 243 | obj = document.createElement("EMBED"); |
| 244 | obj.setAttribute("src", "ppapi_nacl_tests_pnacl.nmf"); |
| 245 | obj.setAttribute("type", "application/x-nacl"); |
| 246 | obj.setAttribute("mode", mode); |
[email protected] | 2c8a509 | 2014-04-03 12:01:49 | [diff] [blame^] | 247 | } else if (mode == "nacl_pnacl_nonsfi") { |
| 248 | obj = document.createElement("EMBED"); |
| 249 | obj.setAttribute("src", "ppapi_nacl_tests_pnacl_nonsfi.nmf"); |
| 250 | obj.setAttribute("type", "application/x-nacl"); |
| 251 | obj.setAttribute("mode", mode); |
[email protected] | 52d2c8e0 | 2010-11-16 20:59:23 | [diff] [blame] | 252 | } else { |
| 253 | var mimeType = "application/x-ppapi-tests"; |
| 254 | if (mimeType in navigator.mimeTypes) { |
[email protected] | ebc5c8be | 2011-05-20 22:52:59 | [diff] [blame] | 255 | obj = document.createElement("EMBED"); |
[email protected] | 88bfb43 | 2011-05-23 22:43:59 | [diff] [blame] | 256 | obj.setAttribute("src", "http://a.b.c/test"); |
[email protected] | 52d2c8e0 | 2010-11-16 20:59:23 | [diff] [blame] | 257 | obj.setAttribute("type", mimeType); |
| 258 | } else { |
| 259 | document.getElementById("console").innerHTML = |
| 260 | '<span class="fail">FAIL</span>: ' + |
| 261 | '<span class="err_msg">Test plug-in is not registered.</span>'; |
| 262 | } |
| 263 | } |
| 264 | if (obj) { |
[email protected] | 09c37ba | 2012-01-05 18:00:33 | [diff] [blame] | 265 | obj.setAttribute("width", 80); |
| 266 | obj.setAttribute("height", 80); |
| 267 | obj.setAttribute("style", |
| 268 | "background-color:#AAAAAA;border:1px solid black;"); |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 269 | obj.setAttribute("id", "plugin"); |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 270 | obj.setAttribute("testcase", testcase); |
[email protected] | 7f801d8 | 2011-07-08 23:30:11 | [diff] [blame] | 271 | obj.setAttribute("protocol", window.location.protocol); |
[email protected] | 21de9cb2 | 2013-02-14 13:07:34 | [diff] [blame] | 272 | var websocket_host = ExtractSearchParameter("websocket_host"); |
| 273 | if (websocket_host != "") |
| 274 | obj.setAttribute("websocket_host", websocket_host); |
[email protected] | bedf874 | 2012-03-16 16:44:11 | [diff] [blame] | 275 | var websocket_port = ExtractSearchParameter("websocket_port"); |
| 276 | if (websocket_port != "") |
| 277 | obj.setAttribute("websocket_port", websocket_port); |
[email protected] | 6c11340 | 2012-03-23 01:31:51 | [diff] [blame] | 278 | var ssl_server_port = ExtractSearchParameter("ssl_server_port"); |
| 279 | if (ssl_server_port != "") |
| 280 | obj.setAttribute("ssl_server_port", ssl_server_port); |
| 281 | |
[email protected] | 7f801d8 | 2011-07-08 23:30:11 | [diff] [blame] | 282 | var container = document.getElementById("container"); |
[email protected] | 7f801d8 | 2011-07-08 23:30:11 | [diff] [blame] | 283 | container.addEventListener("message", handleTestingMessage, true); |
[email protected] | 00d8e0d | 2013-01-11 15:52:36 | [diff] [blame] | 284 | |
[email protected] | 52d6a08 | 2012-12-06 22:47:42 | [diff] [blame] | 285 | // "error" and "crash" events will only fire for NaCl, but adding these |
| 286 | // listeners doesn't hurt in the non-NaCl cases. |
| 287 | obj.addEventListener("error", function() { |
| 288 | InternalError("Plugin did not load. '" + obj.lastError + "'"); |
| 289 | }, true); |
| 290 | obj.addEventListener("crash", function() { |
| 291 | InternalError("Plugin crashed. '" + obj.lastError + "'"); |
| 292 | }, true); |
[email protected] | 00d8e0d | 2013-01-11 15:52:36 | [diff] [blame] | 293 | |
| 294 | // NaCl sends progress events while loading. When we get one, notify the |
| 295 | // domAutomationController so that it knows we're still working. |
| 296 | obj.addEventListener("loadstart", sendProgress, true); |
| 297 | obj.addEventListener("progress", sendProgress, true); |
| 298 | obj.addEventListener("load", sendProgress, true); |
| 299 | obj.addEventListener("loadend", sendProgress, true); |
| 300 | |
[email protected] | c4cc74c | 2011-11-17 17:06:34 | [diff] [blame] | 301 | // Register a bad dispatchEvent to make sure it isn't used. See 'EVIL' note |
| 302 | // below. |
[email protected] | 52d6a08 | 2012-12-06 22:47:42 | [diff] [blame] | 303 | var original = obj.dispatchEvent; |
[email protected] | c4cc74c | 2011-11-17 17:06:34 | [diff] [blame] | 304 | obj.dispatchEvent = function() { |
[email protected] | 67239b1 | 2013-11-09 01:37:29 | [diff] [blame] | 305 | InternalError("Bad dispatchEvent called!"); |
[email protected] | c4cc74c | 2011-11-17 17:06:34 | [diff] [blame] | 306 | } |
[email protected] | 2deab8c | 2011-11-15 23:30:04 | [diff] [blame] | 307 | container.appendChild(obj); |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 308 | } |
| 309 | } |
[email protected] | c4cc74c | 2011-11-17 17:06:34 | [diff] [blame] | 310 | |
| 311 | // EVIL Note: |
| 312 | // This part of the script does some nefarious things to make sure that it |
| 313 | // doesn't affect the behavior of PostMessage (on which all the tests rely). In |
| 314 | // particular, we replace document.createEvent, MessageEvent.initMessageEvent, |
[email protected] | 67239b1 | 2013-11-09 01:37:29 | [diff] [blame] | 315 | // and the MessageEvent constructor. Previously, the NaCl integration |
| 316 | // implementation made use of these and would fail (http://crbug.com/82604 |
| 317 | // and http://crbug.com/109775). |
[email protected] | c4cc74c | 2011-11-17 17:06:34 | [diff] [blame] | 318 | document.createEvent = function() { |
[email protected] | 72876e1 | 2013-01-11 20:58:03 | [diff] [blame] | 319 | InternalError("Bad document.createEvent called!"); |
[email protected] | c4cc74c | 2011-11-17 17:06:34 | [diff] [blame] | 320 | } |
| 321 | function MessageEvent() { |
[email protected] | 72876e1 | 2013-01-11 20:58:03 | [diff] [blame] | 322 | InternalError("Bad MessageEvent constructor called!"); |
[email protected] | c4cc74c | 2011-11-17 17:06:34 | [diff] [blame] | 323 | } |
| 324 | MessageEvent.prototype.initMessageEvent = function() { |
[email protected] | 72876e1 | 2013-01-11 20:58:03 | [diff] [blame] | 325 | InternalError("Bad MessageEvent.initMessageEvent called!"); |
[email protected] | c4cc74c | 2011-11-17 17:06:34 | [diff] [blame] | 326 | } |
| 327 | |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 328 | </script> |
| 329 | </head><body> |
| 330 | <div> |
| 331 | <div id="container"></div> |
[email protected] | 8f08038 | 2012-12-05 16:13:06 | [diff] [blame] | 332 | <div id="console"><span class="load_msg">loading...</span></div> |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 333 | </div> |
| 334 | </body></html> |