blob: 9f897d0ac03310547ec661b115394d8febfae242 [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
12function DidExecuteTests() {
[email protected]13e343c2012-03-16 22:34:2213 var plugin = document.getElementById("plugin");
14 plugin.parentNode.removeChild(plugin);
15 plugin = undefined;
16 CheckPostConditions();
17
[email protected]1758e882010-11-01 16:16:5018 if (window == top)
19 return;
20
21 // Otherwise, we are in a subframe, so we can use this opportunity to resize
22 // ourselves.
23 AdjustHeight(window);
24}
25
26function AppendFrame(testcase, i) {
27 var p = document.createElement("P");
28 p.setAttribute("class", "frame-container");
29
30 var title = document.createElement("H2");
31 title.appendChild(document.createTextNode(testcase));
32 p.appendChild(title);
33
34 var frame = document.createElement("IFRAME");
[email protected]849b0712011-04-28 19:15:0835 var mode = ExtractSearchParameter("mode");
[email protected]21de9cb22013-02-14 13:07:3436 var websocket_host = ExtractSearchParameter("websocket_host");
[email protected]bedf8742012-03-16 16:44:1137 var websocket_port = ExtractSearchParameter("websocket_port");
[email protected]6c113402012-03-23 01:31:5138 var ssl_server_port = ExtractSearchParameter("ssl_server_port");
[email protected]bedf8742012-03-16 16:44:1139 var src = "?testcase=" + testcase;
[email protected]849b0712011-04-28 19:15:0840 if (mode == "nacl")
[email protected]bedf8742012-03-16 16:44:1141 src += "&mode=nacl";
[email protected]21de9cb22013-02-14 13:07:3442 if (websocket_host != "")
43 src += "&websocket_host=" + websocket_host;
[email protected]bedf8742012-03-16 16:44:1144 if (websocket_port != "")
45 src += "&websocket_port=" + websocket_port;
[email protected]6c113402012-03-23 01:31:5146 if (ssl_server_port != "")
47 src += "&ssl_server_port=" + ssl_server_port;
[email protected]bedf8742012-03-16 16:44:1148 frame.setAttribute("src", src);
49
[email protected]1758e882010-11-01 16:16:5050 frame.setAttribute("onload", "LoadNext(" + (i + 1) + ")");
51 p.appendChild(frame);
52
53 document.body.appendChild(p);
54}
55
56function LoadNext(i) {
57 var links = document.links;
58 if (links.length > i)
59 AppendFrame(links[i].firstChild.nodeValue, i);
60}
61
62function RunAll() {
63 // Remove any existing frames.
64 var existing = document.getElementsByClassName("frame-container");
65 while (existing.length)
66 existing[0].parentNode.removeChild(existing[0]);
67
68 // Add new frames for each test, but do so one frame at a time.
69 LoadNext(0);
70}
71
[email protected]52d2c8e02010-11-16 20:59:2372function ExtractSearchParameter(name) {
73 var nameIndex = location.search.indexOf(name + "=");
74 if (nameIndex != -1) {
75 var value = location.search.substring(nameIndex + name.length + 1);
76 var endIndex = value.indexOf("&");
77 if (endIndex != -1)
78 value = value.substring(0, endIndex);
79 return value;
80 }
81 return "";
82}
[email protected]1758e882010-11-01 16:16:5083
[email protected]7f801d82011-07-08 23:30:1184// Parses the message, looking for strings of the form:
85// TESTING_MESSAGE:<message_type>:<message_contents>
86//
87// If the message_data is not a string or does not match the above format, then
88// undefined is returned.
89//
90// Otherwise, returns an array containing 2 items. The 0th element is the
91// message_type, one of:
92// - ClearContents
93// - DidExecuteTests
94// - LogHTML
95// - SetCookie
[email protected]08610102011-12-17 14:24:3096// - EvalScript
[email protected]13e343c2012-03-16 22:34:2297// - AddPostCondition
[email protected]7f801d82011-07-08 23:30:1198// The second item is the verbatim message_contents.
99function ParseTestingMessage(message_data) {
[email protected]13e343c2012-03-16 22:34:22100 if (typeof(message_data) != "string")
[email protected]7f801d82011-07-08 23:30:11101 return undefined;
102 var testing_message_prefix = "TESTING_MESSAGE";
103 var delim_str = ":";
104 var delim1 = message_data.indexOf(delim_str);
105 if (message_data.substring(0, delim1) !== testing_message_prefix)
106 return undefined;
107 var delim2 = message_data.indexOf(delim_str, delim1 + 1);
108 if (delim2 == -1)
109 delim2 = message_data.length;
110 var message_type = message_data.substring(delim1 + 1, delim2);
111 var message_contents = message_data.substring(delim2 + 1);
112 return [message_type, message_contents];
113}
114
115function ClearConsole() {
116 window.document.getElementById("console").innerHTML = "";
117}
118
119function LogHTML(html) {
120 window.document.getElementById("console").innerHTML += html;
121}
122
[email protected]00d8e0d2013-01-11 15:52:36123function sendAutomationMessage(msg) {
124 if (window.domAutomationController) {
125 window.domAutomationController.setAutomationId(0);
126 window.domAutomationController.send(msg);
127 }
128}
129
[email protected]52d6a082012-12-06 22:47:42130// If something goes really wrong, the test running inside the plugin may not
131// terminate. For example, if the plugin does not load, the test will never
132// send "PASS" to the browser. In this case we should explicitly use the
133// automation controller to terminate the test.
134function InternalError(msg) {
135 LogHTML("<p>" + msg);
[email protected]79efedbd2013-01-11 21:53:20136 sendAutomationMessage(msg);
[email protected]52d6a082012-12-06 22:47:42137}
138
[email protected]7f801d82011-07-08 23:30:11139function SetCookie(key_value_string) {
140 window.document.cookie = key_value_string + "; path=/";
141}
142
[email protected]08610102011-12-17 14:24:30143function EvalScript(script) {
144 try {
145 eval(script);
146 } catch(ex) {
147 }
148}
149
[email protected]13e343c2012-03-16 22:34:22150var conditions = [];
151// Add a "PostCondition". These are bits of script that are run after the plugin
152// is destroyed. If they evaluate to false or throw an exception, it's
153// considered a failure.
154function AddPostCondition(script) {
155 conditions.push(script);
156}
157// Update the HTML to show the failure and update cookies so that ui_tests
158// doesn't count this as a pass.
159function ConditionFailed(error) {
160 error_string = "Post condition check failed: " + error;
161 var i = 0;
162 // If the plugin thinks the test passed but a post-condition failed, we want
163 // to clear the PASS cookie so that ui_tests doesn't count it is a passed
164 // test.
165 if (window.document.cookie.indexOf("PASS") != -1) {
166 while (window.document.cookie.indexOf("PPAPI_PROGRESS_" + i) != -1) {
167 window.document.cookie = "PPAPI_PROGRESS_" + i + "=; max-age=0";
168 ++i;
169 }
170 window.document.cookie = "PPAPI_PROGRESS_0=" + error_string
171 }
172 LogHTML("<p>" + error_string);
173}
174// Iterate through the post conditions defined in |conditions| and check that
175// they all pass.
176function CheckPostConditions() {
177 for (var i = 0; i < conditions.length; ++i) {
178 var script = conditions[i];
179 try {
180 if (!eval(script)) {
181 ConditionFailed("\"" + script + "\"");
182 }
183 } catch (ex) {
184 ConditionFailed("\"" + script + "\"" + " failed with exception: " +
185 "\"" + ex.toString() + "\"");
186 }
187 }
188}
189
[email protected]7f801d82011-07-08 23:30:11190function IsTestingMessage(message_data) {
191 return (ParseTestingMessage(message_data) != undefined);
192}
193
194function handleTestingMessage(message_event) {
195 var type_contents_tuple = ParseTestingMessage(message_event.data);
196 if (type_contents_tuple) {
197 var type = type_contents_tuple[0];
198 var contents = type_contents_tuple[1];
199 if (type === "ClearConsole")
200 ClearConsole();
201 else if (type === "DidExecuteTests")
202 DidExecuteTests();
203 else if (type === "LogHTML")
204 LogHTML(contents);
205 else if (type === "SetCookie")
206 SetCookie(contents);
[email protected]08610102011-12-17 14:24:30207 else if (type === "EvalScript")
208 EvalScript(contents);
[email protected]13e343c2012-03-16 22:34:22209 else if (type == "AddPostCondition")
210 AddPostCondition(contents);
[email protected]7f801d82011-07-08 23:30:11211 }
212}
213
[email protected]00d8e0d2013-01-11 15:52:36214function sendProgress() {
[email protected]00d8e0d2013-01-11 15:52:36215 // We send "..." to signal that we're still working. See
216 // ppapi/tests/testing_instance.h for how this works.
217 sendAutomationMessage("...");
218}
219
[email protected]52d2c8e02010-11-16 20:59:23220onload = function() {
221 var testcase = ExtractSearchParameter("testcase");
222 var mode = ExtractSearchParameter("mode");
223 document.title = 'Test ' + testcase;
224 var obj;
[email protected]4223f8d2012-06-07 01:10:06225 if (mode == "nacl_newlib") {
[email protected]88bfb432011-05-23 22:43:59226 obj = document.createElement("EMBED");
[email protected]4223f8d2012-06-07 01:10:06227 obj.setAttribute("src", "ppapi_nacl_tests_newlib.nmf");
228 obj.setAttribute("type", "application/x-nacl");
229 obj.setAttribute("mode", mode);
230 } else if (mode == "nacl_glibc") {
231 obj = document.createElement("EMBED");
232 obj.setAttribute("src", "ppapi_nacl_tests_glibc.nmf");
[email protected]849b0712011-04-28 19:15:08233 obj.setAttribute("type", "application/x-nacl");
[email protected]52d2c8e02010-11-16 20:59:23234 obj.setAttribute("mode", mode);
235 } else {
236 var mimeType = "application/x-ppapi-tests";
237 if (mimeType in navigator.mimeTypes) {
[email protected]ebc5c8be2011-05-20 22:52:59238 obj = document.createElement("EMBED");
[email protected]88bfb432011-05-23 22:43:59239 obj.setAttribute("src", "http://a.b.c/test");
[email protected]52d2c8e02010-11-16 20:59:23240 obj.setAttribute("type", mimeType);
241 } else {
242 document.getElementById("console").innerHTML =
243 '<span class="fail">FAIL</span>: ' +
244 '<span class="err_msg">Test plug-in is not registered.</span>';
245 }
246 }
247 if (obj) {
[email protected]09c37ba2012-01-05 18:00:33248 obj.setAttribute("width", 80);
249 obj.setAttribute("height", 80);
250 obj.setAttribute("style",
251 "background-color:#AAAAAA;border:1px solid black;");
[email protected]1758e882010-11-01 16:16:50252 obj.setAttribute("id", "plugin");
[email protected]1758e882010-11-01 16:16:50253 obj.setAttribute("testcase", testcase);
[email protected]7f801d82011-07-08 23:30:11254 obj.setAttribute("protocol", window.location.protocol);
[email protected]21de9cb22013-02-14 13:07:34255 var websocket_host = ExtractSearchParameter("websocket_host");
256 if (websocket_host != "")
257 obj.setAttribute("websocket_host", websocket_host);
[email protected]bedf8742012-03-16 16:44:11258 var websocket_port = ExtractSearchParameter("websocket_port");
259 if (websocket_port != "")
260 obj.setAttribute("websocket_port", websocket_port);
[email protected]6c113402012-03-23 01:31:51261 var ssl_server_port = ExtractSearchParameter("ssl_server_port");
262 if (ssl_server_port != "")
263 obj.setAttribute("ssl_server_port", ssl_server_port);
264
[email protected]7f801d82011-07-08 23:30:11265 var container = document.getElementById("container");
[email protected]7f801d82011-07-08 23:30:11266 container.addEventListener("message", handleTestingMessage, true);
[email protected]00d8e0d2013-01-11 15:52:36267
[email protected]52d6a082012-12-06 22:47:42268 // "error" and "crash" events will only fire for NaCl, but adding these
269 // listeners doesn't hurt in the non-NaCl cases.
270 obj.addEventListener("error", function() {
271 InternalError("Plugin did not load. '" + obj.lastError + "'");
272 }, true);
273 obj.addEventListener("crash", function() {
274 InternalError("Plugin crashed. '" + obj.lastError + "'");
275 }, true);
[email protected]00d8e0d2013-01-11 15:52:36276
277 // NaCl sends progress events while loading. When we get one, notify the
278 // domAutomationController so that it knows we're still working.
279 obj.addEventListener("loadstart", sendProgress, true);
280 obj.addEventListener("progress", sendProgress, true);
281 obj.addEventListener("load", sendProgress, true);
282 obj.addEventListener("loadend", sendProgress, true);
283
[email protected]c4cc74c2011-11-17 17:06:34284 // Register a bad dispatchEvent to make sure it isn't used. See 'EVIL' note
285 // below.
[email protected]52d6a082012-12-06 22:47:42286 var original = obj.dispatchEvent;
[email protected]c4cc74c2011-11-17 17:06:34287 obj.dispatchEvent = function() {
[email protected]72876e12013-01-11 20:58:03288 // TODO(dmichael): NaCl triggers this; take out the special case for NaCl
289 // when crbug.com/109775 is fixed.
290 if (mode.indexOf("nacl") !== 0)
291 InternalError("Bad dispatchEvent called!");
292
[email protected]00d8e0d2013-01-11 15:52:36293 // Pass it on anyways, we need the event to detect load progress and
294 // errors.
295 return original.apply(obj, arguments);
[email protected]c4cc74c2011-11-17 17:06:34296 }
[email protected]2deab8c2011-11-15 23:30:04297 container.appendChild(obj);
[email protected]1758e882010-11-01 16:16:50298 }
299}
[email protected]c4cc74c2011-11-17 17:06:34300
301// EVIL Note:
302// This part of the script does some nefarious things to make sure that it
303// doesn't affect the behavior of PostMessage (on which all the tests rely). In
304// particular, we replace document.createEvent, MessageEvent.initMessageEvent,
305// and the MessageEvent constructor. Previous versions of the PostMessage
306// implementation made use of these and would fail (http://crbug.com/82604).
[email protected]72876e12013-01-11 20:58:03307// The NaCl plugin uses dispatchEvent for progress events, hence we are careful
308// to make that still pass for NaCl (see above, and see crbug.com/109775).
[email protected]c4cc74c2011-11-17 17:06:34309document.createEvent = function() {
[email protected]72876e12013-01-11 20:58:03310 InternalError("Bad document.createEvent called!");
[email protected]c4cc74c2011-11-17 17:06:34311}
312function MessageEvent() {
[email protected]72876e12013-01-11 20:58:03313 InternalError("Bad MessageEvent constructor called!");
[email protected]c4cc74c2011-11-17 17:06:34314}
315MessageEvent.prototype.initMessageEvent = function() {
[email protected]72876e12013-01-11 20:58:03316 InternalError("Bad MessageEvent.initMessageEvent called!");
[email protected]c4cc74c2011-11-17 17:06:34317}
318
[email protected]1758e882010-11-01 16:16:50319</script>
320</head><body>
321<div>
322 <div id="container"></div>
[email protected]8f080382012-12-05 16:13:06323 <div id="console"><span class="load_msg">loading...</span></div>
[email protected]1758e882010-11-01 16:16:50324</div>
325</body></html>