blob: c963b13093ae4947638ebcb932180f9b55608113 [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]e7425db2013-07-17 20:15:2116 if (plugin.removePlugin) {
17 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() {
130 window.document.getElementById("plugin").removePlugin = true;
131}
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]52d6a082012-12-06 22:47:42140// If something goes really wrong, the test running inside the plugin may not
141// terminate. For example, if the plugin does not load, the test will never
142// send "PASS" to the browser. In this case we should explicitly use the
143// automation controller to terminate the test.
144function InternalError(msg) {
145 LogHTML("<p>" + msg);
[email protected]79efedbd2013-01-11 21:53:20146 sendAutomationMessage(msg);
[email protected]52d6a082012-12-06 22:47:42147}
148
[email protected]08610102011-12-17 14:24:30149function EvalScript(script) {
150 try {
151 eval(script);
152 } catch(ex) {
153 }
154}
155
[email protected]13e343c2012-03-16 22:34:22156var conditions = [];
157// Add a "PostCondition". These are bits of script that are run after the plugin
158// is destroyed. If they evaluate to false or throw an exception, it's
159// considered a failure.
160function AddPostCondition(script) {
161 conditions.push(script);
162}
163// Update the HTML to show the failure and update cookies so that ui_tests
164// doesn't count this as a pass.
165function ConditionFailed(error) {
166 error_string = "Post condition check failed: " + error;
[email protected]e7425db2013-07-17 20:15:21167 InternalError(error_string);
[email protected]13e343c2012-03-16 22:34:22168}
169// Iterate through the post conditions defined in |conditions| and check that
170// they all pass.
171function CheckPostConditions() {
[email protected]e7425db2013-07-17 20:15:21172 var success = true;
[email protected]13e343c2012-03-16 22:34:22173 for (var i = 0; i < conditions.length; ++i) {
174 var script = conditions[i];
175 try {
176 if (!eval(script)) {
177 ConditionFailed("\"" + script + "\"");
[email protected]e7425db2013-07-17 20:15:21178 success = false;
[email protected]13e343c2012-03-16 22:34:22179 }
180 } catch (ex) {
181 ConditionFailed("\"" + script + "\"" + " failed with exception: " +
182 "\"" + ex.toString() + "\"");
[email protected]e7425db2013-07-17 20:15:21183 success = false;
[email protected]13e343c2012-03-16 22:34:22184 }
185 }
[email protected]e7425db2013-07-17 20:15:21186 return success;
[email protected]13e343c2012-03-16 22:34:22187}
188
[email protected]7f801d82011-07-08 23:30:11189function IsTestingMessage(message_data) {
190 return (ParseTestingMessage(message_data) != undefined);
191}
192
193function handleTestingMessage(message_event) {
194 var type_contents_tuple = ParseTestingMessage(message_event.data);
195 if (type_contents_tuple) {
196 var type = type_contents_tuple[0];
197 var contents = type_contents_tuple[1];
[email protected]e7425db2013-07-17 20:15:21198 if (type === "AddPostCondition")
199 AddPostCondition(contents);
200 else if (type === "ClearConsole")
[email protected]7f801d82011-07-08 23:30:11201 ClearConsole();
202 else if (type === "DidExecuteTests")
[email protected]e7425db2013-07-17 20:15:21203 DidExecuteTests(contents);
[email protected]08610102011-12-17 14:24:30204 else if (type === "EvalScript")
205 EvalScript(contents);
[email protected]e7425db2013-07-17 20:15:21206 else if (type === "LogHTML")
207 LogHTML(contents);
208 else if (type === "RemovePluginWhenFinished")
209 RemovePluginWhenFinished();
210 else if (type === "ReportProgress")
211 sendAutomationMessage(contents);
[email protected]7f801d82011-07-08 23:30:11212 }
213}
214
[email protected]00d8e0d2013-01-11 15:52:36215function sendProgress() {
[email protected]00d8e0d2013-01-11 15:52:36216 // We send "..." to signal that we're still working. See
217 // ppapi/tests/testing_instance.h for how this works.
218 sendAutomationMessage("...");
219}
220
[email protected]52d2c8e02010-11-16 20:59:23221onload = function() {
222 var testcase = ExtractSearchParameter("testcase");
223 var mode = ExtractSearchParameter("mode");
224 document.title = 'Test ' + testcase;
225 var obj;
[email protected]4223f8d2012-06-07 01:10:06226 if (mode == "nacl_newlib") {
[email protected]88bfb432011-05-23 22:43:59227 obj = document.createElement("EMBED");
[email protected]4223f8d2012-06-07 01:10:06228 obj.setAttribute("src", "ppapi_nacl_tests_newlib.nmf");
229 obj.setAttribute("type", "application/x-nacl");
230 obj.setAttribute("mode", mode);
231 } else if (mode == "nacl_glibc") {
232 obj = document.createElement("EMBED");
233 obj.setAttribute("src", "ppapi_nacl_tests_glibc.nmf");
[email protected]849b0712011-04-28 19:15:08234 obj.setAttribute("type", "application/x-nacl");
[email protected]52d2c8e02010-11-16 20:59:23235 obj.setAttribute("mode", mode);
[email protected]1e40ba002013-03-07 22:07:33236 } else if (mode == "nacl_pnacl") {
237 obj = document.createElement("EMBED");
238 obj.setAttribute("src", "ppapi_nacl_tests_pnacl.nmf");
239 obj.setAttribute("type", "application/x-nacl");
240 obj.setAttribute("mode", mode);
[email protected]52d2c8e02010-11-16 20:59:23241 } else {
242 var mimeType = "application/x-ppapi-tests";
243 if (mimeType in navigator.mimeTypes) {
[email protected]ebc5c8be2011-05-20 22:52:59244 obj = document.createElement("EMBED");
[email protected]88bfb432011-05-23 22:43:59245 obj.setAttribute("src", "http://a.b.c/test");
[email protected]52d2c8e02010-11-16 20:59:23246 obj.setAttribute("type", mimeType);
247 } else {
248 document.getElementById("console").innerHTML =
249 '<span class="fail">FAIL</span>: ' +
250 '<span class="err_msg">Test plug-in is not registered.</span>';
251 }
252 }
253 if (obj) {
[email protected]09c37ba2012-01-05 18:00:33254 obj.setAttribute("width", 80);
255 obj.setAttribute("height", 80);
256 obj.setAttribute("style",
257 "background-color:#AAAAAA;border:1px solid black;");
[email protected]1758e882010-11-01 16:16:50258 obj.setAttribute("id", "plugin");
[email protected]1758e882010-11-01 16:16:50259 obj.setAttribute("testcase", testcase);
[email protected]7f801d82011-07-08 23:30:11260 obj.setAttribute("protocol", window.location.protocol);
[email protected]21de9cb22013-02-14 13:07:34261 var websocket_host = ExtractSearchParameter("websocket_host");
262 if (websocket_host != "")
263 obj.setAttribute("websocket_host", websocket_host);
[email protected]bedf8742012-03-16 16:44:11264 var websocket_port = ExtractSearchParameter("websocket_port");
265 if (websocket_port != "")
266 obj.setAttribute("websocket_port", websocket_port);
[email protected]6c113402012-03-23 01:31:51267 var ssl_server_port = ExtractSearchParameter("ssl_server_port");
268 if (ssl_server_port != "")
269 obj.setAttribute("ssl_server_port", ssl_server_port);
270
[email protected]7f801d82011-07-08 23:30:11271 var container = document.getElementById("container");
[email protected]7f801d82011-07-08 23:30:11272 container.addEventListener("message", handleTestingMessage, true);
[email protected]00d8e0d2013-01-11 15:52:36273
[email protected]52d6a082012-12-06 22:47:42274 // "error" and "crash" events will only fire for NaCl, but adding these
275 // listeners doesn't hurt in the non-NaCl cases.
276 obj.addEventListener("error", function() {
277 InternalError("Plugin did not load. '" + obj.lastError + "'");
278 }, true);
279 obj.addEventListener("crash", function() {
280 InternalError("Plugin crashed. '" + obj.lastError + "'");
281 }, true);
[email protected]00d8e0d2013-01-11 15:52:36282
283 // NaCl sends progress events while loading. When we get one, notify the
284 // domAutomationController so that it knows we're still working.
285 obj.addEventListener("loadstart", sendProgress, true);
286 obj.addEventListener("progress", sendProgress, true);
287 obj.addEventListener("load", sendProgress, true);
288 obj.addEventListener("loadend", sendProgress, true);
289
[email protected]c4cc74c2011-11-17 17:06:34290 // Register a bad dispatchEvent to make sure it isn't used. See 'EVIL' note
291 // below.
[email protected]52d6a082012-12-06 22:47:42292 var original = obj.dispatchEvent;
[email protected]c4cc74c2011-11-17 17:06:34293 obj.dispatchEvent = function() {
[email protected]72876e12013-01-11 20:58:03294 // TODO(dmichael): NaCl triggers this; take out the special case for NaCl
295 // when crbug.com/109775 is fixed.
296 if (mode.indexOf("nacl") !== 0)
297 InternalError("Bad dispatchEvent called!");
298
[email protected]00d8e0d2013-01-11 15:52:36299 // Pass it on anyways, we need the event to detect load progress and
300 // errors.
301 return original.apply(obj, arguments);
[email protected]c4cc74c2011-11-17 17:06:34302 }
[email protected]2deab8c2011-11-15 23:30:04303 container.appendChild(obj);
[email protected]1758e882010-11-01 16:16:50304 }
305}
[email protected]c4cc74c2011-11-17 17:06:34306
307// EVIL Note:
308// This part of the script does some nefarious things to make sure that it
309// doesn't affect the behavior of PostMessage (on which all the tests rely). In
310// particular, we replace document.createEvent, MessageEvent.initMessageEvent,
311// and the MessageEvent constructor. Previous versions of the PostMessage
312// implementation made use of these and would fail (http://crbug.com/82604).
[email protected]72876e12013-01-11 20:58:03313// The NaCl plugin uses dispatchEvent for progress events, hence we are careful
314// to make that still pass for NaCl (see above, and see crbug.com/109775).
[email protected]c4cc74c2011-11-17 17:06:34315document.createEvent = function() {
[email protected]72876e12013-01-11 20:58:03316 InternalError("Bad document.createEvent called!");
[email protected]c4cc74c2011-11-17 17:06:34317}
318function MessageEvent() {
[email protected]72876e12013-01-11 20:58:03319 InternalError("Bad MessageEvent constructor called!");
[email protected]c4cc74c2011-11-17 17:06:34320}
321MessageEvent.prototype.initMessageEvent = function() {
[email protected]72876e12013-01-11 20:58:03322 InternalError("Bad MessageEvent.initMessageEvent called!");
[email protected]c4cc74c2011-11-17 17:06:34323}
324
[email protected]1758e882010-11-01 16:16:50325</script>
326</head><body>
327<div>
328 <div id="container"></div>
[email protected]8f080382012-12-05 16:13:06329 <div id="console"><span class="load_msg">loading...</span></div>
[email protected]1758e882010-11-01 16:16:50330</div>
331</body></html>