Add an extension override bubble and warning box for proxy extensions. (2nd attempt...
[chromium-blink-merge.git] / ppapi / tests / test_case.html
blob987c10284c86306f14481cbd8a89c261aef0d213
1 <html><head>
2 <meta http-equiv="Pragma" content="no-cache" />
3 <meta http-equiv="Expires" content="-1" />
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;
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) {
15 var plugin = document.getElementById("plugin");
16 if (plugin.parentNode.removePlugin) {
17 plugin.parentNode.removeChild(plugin);
18 plugin = undefined;
20 if (CheckPostConditions())
21 sendAutomationMessage(result);
23 if (window == top)
24 return;
26 // Otherwise, we are in a subframe, so we can use this opportunity to resize
27 // ourselves.
28 AdjustHeight(window);
31 function AppendFrame(testcase, i) {
32 var p = document.createElement("P");
33 p.setAttribute("class", "frame-container");
35 var title = document.createElement("H2");
36 title.appendChild(document.createTextNode(testcase));
37 p.appendChild(title);
39 var frame = document.createElement("IFRAME");
40 var mode = ExtractSearchParameter("mode");
41 var websocket_host = ExtractSearchParameter("websocket_host");
42 var websocket_port = ExtractSearchParameter("websocket_port");
43 var ssl_server_port = ExtractSearchParameter("ssl_server_port");
44 var src = "?testcase=" + testcase;
45 if (mode == "nacl")
46 src += "&mode=nacl";
47 if (websocket_host != "")
48 src += "&websocket_host=" + websocket_host;
49 if (websocket_port != "")
50 src += "&websocket_port=" + websocket_port;
51 if (ssl_server_port != "")
52 src += "&ssl_server_port=" + ssl_server_port;
53 frame.setAttribute("src", src);
55 frame.setAttribute("onload", "LoadNext(" + (i + 1) + ")");
56 p.appendChild(frame);
58 document.body.appendChild(p);
61 function LoadNext(i) {
62 var links = document.links;
63 if (links.length > i)
64 AppendFrame(links[i].firstChild.nodeValue, i);
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]);
73 // Add new frames for each test, but do so one frame at a time.
74 LoadNext(0);
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;
86 return "";
89 // Parses the message, looking for strings of the form:
90 // TESTING_MESSAGE:<message_type>:<message_contents>
92 // If the message_data is not a string or does not match the above format, then
93 // undefined is returned.
95 // Otherwise, returns an array containing 2 items. The 0th element is the
96 // message_type, one of:
97 // - AddPostCondition
98 // - ClearConsole
99 // - DidExecuteTests
100 // - EvalScript
101 // - LogHTML
102 // - RemovePluginWhenFinished
103 // - ReportProgress
104 // The second item is the verbatim message_contents.
105 function ParseTestingMessage(message_data) {
106 if (typeof(message_data) != "string")
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];
121 function ClearConsole() {
122 window.document.getElementById("console").innerHTML = "";
125 function LogHTML(html) {
126 window.document.getElementById("console").innerHTML += html;
129 function RemovePluginWhenFinished() {
130 window.document.getElementById("container").removePlugin = true;
133 function sendAutomationMessage(msg) {
134 if (window.domAutomationController) {
135 window.domAutomationController.setAutomationId(0);
136 window.domAutomationController.send(msg);
140 function LogTestTime(test_time) {
141 console.log(test_time);
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);
150 sendAutomationMessage(msg);
153 function EvalScript(script) {
154 try {
155 eval(script);
156 } catch(ex) {
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);
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;
171 InternalError(error_string);
173 // Iterate through the post conditions defined in |conditions| and check that
174 // they all pass.
175 function CheckPostConditions() {
176 var success = true;
177 for (var i = 0; i < conditions.length; ++i) {
178 var script = conditions[i];
179 try {
180 if (!eval(script)) {
181 ConditionFailed("\"" + script + "\"");
182 success = false;
184 } catch (ex) {
185 ConditionFailed("\"" + script + "\"" + " failed with exception: " +
186 "\"" + ex.toString() + "\"");
187 success = false;
190 return success;
193 function IsTestingMessage(message_data) {
194 return (ParseTestingMessage(message_data) != undefined);
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];
202 if (type === "AddPostCondition")
203 AddPostCondition(contents);
204 else if (type === "ClearConsole")
205 ClearConsole();
206 else if (type === "DidExecuteTests")
207 DidExecuteTests(contents);
208 else if (type === "EvalScript")
209 EvalScript(contents);
210 else if (type === "LogHTML")
211 LogHTML(contents);
212 else if (type === "RemovePluginWhenFinished")
213 RemovePluginWhenFinished();
214 else if (type === "ReportProgress")
215 sendAutomationMessage(contents);
216 else if (type === "LogTestTime")
217 LogTestTime(contents);
221 function sendProgress() {
222 // We send "..." to signal that we're still working. See
223 // ppapi/tests/testing_instance.h for how this works.
224 sendAutomationMessage("...");
227 onload = function() {
228 var testcase = ExtractSearchParameter("testcase");
229 var mode = ExtractSearchParameter("mode");
230 document.title = 'Test ' + testcase;
231 var obj;
232 if (mode == "nacl_newlib") {
233 obj = document.createElement("EMBED");
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");
240 obj.setAttribute("type", "application/x-nacl");
241 obj.setAttribute("mode", mode);
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);
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);
252 } else {
253 var mimeType = "application/x-ppapi-tests";
254 if (mimeType in navigator.mimeTypes) {
255 obj = document.createElement("EMBED");
256 obj.setAttribute("src", "http://a.b.c/test");
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>';
264 if (obj) {
265 obj.setAttribute("width", 80);
266 obj.setAttribute("height", 80);
267 obj.setAttribute("style",
268 "background-color:#AAAAAA;border:1px solid black;");
269 obj.setAttribute("id", "plugin");
270 obj.setAttribute("testcase", testcase);
271 obj.setAttribute("protocol", window.location.protocol);
272 var websocket_host = ExtractSearchParameter("websocket_host");
273 if (websocket_host != "")
274 obj.setAttribute("websocket_host", websocket_host);
275 var websocket_port = ExtractSearchParameter("websocket_port");
276 if (websocket_port != "")
277 obj.setAttribute("websocket_port", websocket_port);
278 var ssl_server_port = ExtractSearchParameter("ssl_server_port");
279 if (ssl_server_port != "")
280 obj.setAttribute("ssl_server_port", ssl_server_port);
282 var container = document.getElementById("container");
283 container.addEventListener("message", handleTestingMessage, true);
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);
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);
301 // Register a bad dispatchEvent to make sure it isn't used. See 'EVIL' note
302 // below.
303 var original = obj.dispatchEvent;
304 obj.dispatchEvent = function() {
305 InternalError("Bad dispatchEvent called!");
307 container.appendChild(obj);
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,
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).
318 document.createEvent = function() {
319 InternalError("Bad document.createEvent called!");
321 function MessageEvent() {
322 InternalError("Bad MessageEvent constructor called!");
324 MessageEvent.prototype.initMessageEvent = function() {
325 InternalError("Bad MessageEvent.initMessageEvent called!");
328 </script>
329 </head><body>
330 <div>
331 <div id="container"></div>
332 <div id="console"><span class="load_msg">loading...</span></div>
333 </div>
334 </body></html>