blob: 987c10284c86306f14481cbd8a89c261aef0d213 [file] [log] [blame]
[email protected]1758e882010-11-01 16:16:501<html><head>
[email protected]849b0712011-04-28 19:15:082<meta http-equiv="Pragma" content="no-cache" />
3<meta http-equiv="Expires" content="-1" />
[email protected]1758e882010-11-01 16:16:504<link rel="stylesheet" href="test_page.css">
5<script>
6function 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]e7425db2013-07-17 20:15:2112// 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.
14function DidExecuteTests(result) {
[email protected]13e343c2012-03-16 22:34:2215 var plugin = document.getElementById("plugin");
[email protected]9e998c0f2013-11-02 13:27:5216 if (plugin.parentNode.removePlugin) {
[email protected]e7425db2013-07-17 20:15:2117 plugin.parentNode.removeChild(plugin);
18 plugin = undefined;
19 }
20 if (CheckPostConditions())
21 sendAutomationMessage(result);
[email protected]13e343c2012-03-16 22:34:2222
[email protected]1758e882010-11-01 16:16:5023 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
31function 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]849b0712011-04-28 19:15:0840 var mode = ExtractSearchParameter("mode");
[email protected]21de9cb22013-02-14 13:07:3441 var websocket_host = ExtractSearchParameter("websocket_host");
[email protected]bedf8742012-03-16 16:44:1142 var websocket_port = ExtractSearchParameter("websocket_port");
[email protected]6c113402012-03-23 01:31:5143 var ssl_server_port = ExtractSearchParameter("ssl_server_port");
[email protected]bedf8742012-03-16 16:44:1144 var src = "?testcase=" + testcase;
[email protected]849b0712011-04-28 19:15:0845 if (mode == "nacl")
[email protected]bedf8742012-03-16 16:44:1146 src += "&mode=nacl";
[email protected]21de9cb22013-02-14 13:07:3447 if (websocket_host != "")
48 src += "&websocket_host=" + websocket_host;
[email protected]bedf8742012-03-16 16:44:1149 if (websocket_port != "")
50 src += "&websocket_port=" + websocket_port;
[email protected]6c113402012-03-23 01:31:5151 if (ssl_server_port != "")
52 src += "&ssl_server_port=" + ssl_server_port;
[email protected]bedf8742012-03-16 16:44:1153 frame.setAttribute("src", src);
54
[email protected]1758e882010-11-01 16:16:5055 frame.setAttribute("onload", "LoadNext(" + (i + 1) + ")");
56 p.appendChild(frame);
57
58 document.body.appendChild(p);
59}
60
61function LoadNext(i) {
62 var links = document.links;
63 if (links.length > i)
64 AppendFrame(links[i].firstChild.nodeValue, i);
65}
66
67function 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]52d2c8e02010-11-16 20:59:2377function 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]1758e882010-11-01 16:16:5088
[email protected]7f801d82011-07-08 23:30:1189// 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]13e343c2012-03-16 22:34:2297// - AddPostCondition
[email protected]e7425db2013-07-17 20:15:2198// - ClearConsole
99// - DidExecuteTests
100// - EvalScript
101// - LogHTML
102// - RemovePluginWhenFinished
103// - ReportProgress
[email protected]7f801d82011-07-08 23:30:11104// The second item is the verbatim message_contents.
105function ParseTestingMessage(message_data) {
[email protected]13e343c2012-03-16 22:34:22106 if (typeof(message_data) != "string")
[email protected]7f801d82011-07-08 23:30:11107 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
121function ClearConsole() {
122 window.document.getElementById("console").innerHTML = "";
123}
124
125function LogHTML(html) {
126 window.document.getElementById("console").innerHTML += html;
127}
128
[email protected]e7425db2013-07-17 20:15:21129function RemovePluginWhenFinished() {
[email protected]9e998c0f2013-11-02 13:27:52130 window.document.getElementById("container").removePlugin = true;
[email protected]e7425db2013-07-17 20:15:21131}
132
[email protected]00d8e0d2013-01-11 15:52:36133function sendAutomationMessage(msg) {
134 if (window.domAutomationController) {
135 window.domAutomationController.setAutomationId(0);
136 window.domAutomationController.send(msg);
137 }
138}
139
[email protected]a33a08982013-10-31 17:23:29140function LogTestTime(test_time) {
141 console.log(test_time);
142}
143
[email protected]52d6a082012-12-06 22:47:42144// 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.
148function InternalError(msg) {
149 LogHTML("<p>" + msg);
[email protected]79efedbd2013-01-11 21:53:20150 sendAutomationMessage(msg);
[email protected]52d6a082012-12-06 22:47:42151}
152
[email protected]08610102011-12-17 14:24:30153function EvalScript(script) {
154 try {
155 eval(script);
156 } catch(ex) {
157 }
158}
159
[email protected]13e343c2012-03-16 22:34:22160var 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.
164function 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.
169function ConditionFailed(error) {
170 error_string = "Post condition check failed: " + error;
[email protected]e7425db2013-07-17 20:15:21171 InternalError(error_string);
[email protected]13e343c2012-03-16 22:34:22172}
173// Iterate through the post conditions defined in |conditions| and check that
174// they all pass.
175function CheckPostConditions() {
[email protected]e7425db2013-07-17 20:15:21176 var success = true;
[email protected]13e343c2012-03-16 22:34:22177 for (var i = 0; i < conditions.length; ++i) {
178 var script = conditions[i];
179 try {
180 if (!eval(script)) {
181 ConditionFailed("\"" + script + "\"");
[email protected]e7425db2013-07-17 20:15:21182 success = false;
[email protected]13e343c2012-03-16 22:34:22183 }
184 } catch (ex) {
185 ConditionFailed("\"" + script + "\"" + " failed with exception: " +
186 "\"" + ex.toString() + "\"");
[email protected]e7425db2013-07-17 20:15:21187 success = false;
[email protected]13e343c2012-03-16 22:34:22188 }
189 }
[email protected]e7425db2013-07-17 20:15:21190 return success;
[email protected]13e343c2012-03-16 22:34:22191}
192
[email protected]7f801d82011-07-08 23:30:11193function IsTestingMessage(message_data) {
194 return (ParseTestingMessage(message_data) != undefined);
195}
196
197function 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]e7425db2013-07-17 20:15:21202 if (type === "AddPostCondition")
203 AddPostCondition(contents);
204 else if (type === "ClearConsole")
[email protected]7f801d82011-07-08 23:30:11205 ClearConsole();
206 else if (type === "DidExecuteTests")
[email protected]e7425db2013-07-17 20:15:21207 DidExecuteTests(contents);
[email protected]08610102011-12-17 14:24:30208 else if (type === "EvalScript")
209 EvalScript(contents);
[email protected]e7425db2013-07-17 20:15:21210 else if (type === "LogHTML")
211 LogHTML(contents);
212 else if (type === "RemovePluginWhenFinished")
213 RemovePluginWhenFinished();
214 else if (type === "ReportProgress")
215 sendAutomationMessage(contents);
[email protected]a33a08982013-10-31 17:23:29216 else if (type === "LogTestTime")
217 LogTestTime(contents);
[email protected]7f801d82011-07-08 23:30:11218 }
219}
220
[email protected]00d8e0d2013-01-11 15:52:36221function sendProgress() {
[email protected]00d8e0d2013-01-11 15:52:36222 // 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]52d2c8e02010-11-16 20:59:23227onload = function() {
228 var testcase = ExtractSearchParameter("testcase");
229 var mode = ExtractSearchParameter("mode");
230 document.title = 'Test ' + testcase;
231 var obj;
[email protected]4223f8d2012-06-07 01:10:06232 if (mode == "nacl_newlib") {
[email protected]88bfb432011-05-23 22:43:59233 obj = document.createElement("EMBED");
[email protected]4223f8d2012-06-07 01:10:06234 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]849b0712011-04-28 19:15:08240 obj.setAttribute("type", "application/x-nacl");
[email protected]52d2c8e02010-11-16 20:59:23241 obj.setAttribute("mode", mode);
[email protected]1e40ba002013-03-07 22:07:33242 } 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]2c8a5092014-04-03 12:01:49247 } 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]52d2c8e02010-11-16 20:59:23252 } else {
253 var mimeType = "application/x-ppapi-tests";
254 if (mimeType in navigator.mimeTypes) {
[email protected]ebc5c8be2011-05-20 22:52:59255 obj = document.createElement("EMBED");
[email protected]88bfb432011-05-23 22:43:59256 obj.setAttribute("src", "http://a.b.c/test");
[email protected]52d2c8e02010-11-16 20:59:23257 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]09c37ba2012-01-05 18:00:33265 obj.setAttribute("width", 80);
266 obj.setAttribute("height", 80);
267 obj.setAttribute("style",
268 "background-color:#AAAAAA;border:1px solid black;");
[email protected]1758e882010-11-01 16:16:50269 obj.setAttribute("id", "plugin");
[email protected]1758e882010-11-01 16:16:50270 obj.setAttribute("testcase", testcase);
[email protected]7f801d82011-07-08 23:30:11271 obj.setAttribute("protocol", window.location.protocol);
[email protected]21de9cb22013-02-14 13:07:34272 var websocket_host = ExtractSearchParameter("websocket_host");
273 if (websocket_host != "")
274 obj.setAttribute("websocket_host", websocket_host);
[email protected]bedf8742012-03-16 16:44:11275 var websocket_port = ExtractSearchParameter("websocket_port");
276 if (websocket_port != "")
277 obj.setAttribute("websocket_port", websocket_port);
[email protected]6c113402012-03-23 01:31:51278 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]7f801d82011-07-08 23:30:11282 var container = document.getElementById("container");
[email protected]7f801d82011-07-08 23:30:11283 container.addEventListener("message", handleTestingMessage, true);
[email protected]00d8e0d2013-01-11 15:52:36284
[email protected]52d6a082012-12-06 22:47:42285 // "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]00d8e0d2013-01-11 15:52:36293
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]c4cc74c2011-11-17 17:06:34301 // Register a bad dispatchEvent to make sure it isn't used. See 'EVIL' note
302 // below.
[email protected]52d6a082012-12-06 22:47:42303 var original = obj.dispatchEvent;
[email protected]c4cc74c2011-11-17 17:06:34304 obj.dispatchEvent = function() {
[email protected]67239b12013-11-09 01:37:29305 InternalError("Bad dispatchEvent called!");
[email protected]c4cc74c2011-11-17 17:06:34306 }
[email protected]2deab8c2011-11-15 23:30:04307 container.appendChild(obj);
[email protected]1758e882010-11-01 16:16:50308 }
309}
[email protected]c4cc74c2011-11-17 17:06:34310
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]67239b12013-11-09 01:37:29315// 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]c4cc74c2011-11-17 17:06:34318document.createEvent = function() {
[email protected]72876e12013-01-11 20:58:03319 InternalError("Bad document.createEvent called!");
[email protected]c4cc74c2011-11-17 17:06:34320}
321function MessageEvent() {
[email protected]72876e12013-01-11 20:58:03322 InternalError("Bad MessageEvent constructor called!");
[email protected]c4cc74c2011-11-17 17:06:34323}
324MessageEvent.prototype.initMessageEvent = function() {
[email protected]72876e12013-01-11 20:58:03325 InternalError("Bad MessageEvent.initMessageEvent called!");
[email protected]c4cc74c2011-11-17 17:06:34326}
327
[email protected]1758e882010-11-01 16:16:50328</script>
329</head><body>
330<div>
331 <div id="container"></div>
[email protected]8f080382012-12-05 16:13:06332 <div id="console"><span class="load_msg">loading...</span></div>
[email protected]1758e882010-11-01 16:16:50333</div>
334</body></html>