From 368ca47678e6c2208bd1849e5c8ad6f954ff0989 Mon Sep 17 00:00:00 2001 From: "dmichael@chromium.org" Date: Fri, 8 Jul 2011 16:23:36 +0000 Subject: Porting ppapi_tests framework to postMessage. Some tests still rely on scripting, so we changed to using InstancePrivate (since scripting will disappear from Instance soon). Also use conditional compilation so that if compiled as untrusted with NaCl, the tests use Instance instead of InstancePrivate. This means that tests which rely on scripting aren't runnable in NaCl. I also added a gyp option: pepper_scripting. The default is that scripting is on in this CL, but it will make it easy to turn it off in local builds. Soon we'll switch the default to no scripting, and soon after we can remove the option entirely. BUG=82606 TEST=these tests Review URL: http://codereview.chromium.org/7312008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91859 0039d316-1c4b-4281-b951-d872f2087c98 --- ppapi/tests/test_case.html | 66 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'ppapi/tests/test_case.html') diff --git a/ppapi/tests/test_case.html b/ppapi/tests/test_case.html index 89bf1b6..1d395fe 100644 --- a/ppapi/tests/test_case.html +++ b/ppapi/tests/test_case.html @@ -66,6 +66,67 @@ function ExtractSearchParameter(name) { return ""; } +// Parses the message, looking for strings of the form: +// TESTING_MESSAGE:: +// +// If the message_data is not a string or does not match the above format, then +// undefined is returned. +// +// Otherwise, returns an array containing 2 items. The 0th element is the +// message_type, one of: +// - ClearContents +// - DidExecuteTests +// - LogHTML +// - SetCookie +// The second item is the verbatim message_contents. +function ParseTestingMessage(message_data) { + if (typeof(message_data)!='string') + return undefined; + var testing_message_prefix = "TESTING_MESSAGE"; + var delim_str = ":"; + var delim1 = message_data.indexOf(delim_str); + if (message_data.substring(0, delim1) !== testing_message_prefix) + return undefined; + var delim2 = message_data.indexOf(delim_str, delim1 + 1); + if (delim2 == -1) + delim2 = message_data.length; + var message_type = message_data.substring(delim1 + 1, delim2); + var message_contents = message_data.substring(delim2 + 1); + return [message_type, message_contents]; +} + +function ClearConsole() { + window.document.getElementById("console").innerHTML = ""; +} + +function LogHTML(html) { + window.document.getElementById("console").innerHTML += html; +} + +function SetCookie(key_value_string) { + window.document.cookie = key_value_string + "; path=/"; +} + +function IsTestingMessage(message_data) { + return (ParseTestingMessage(message_data) != undefined); +} + +function handleTestingMessage(message_event) { + var type_contents_tuple = ParseTestingMessage(message_event.data); + if (type_contents_tuple) { + var type = type_contents_tuple[0]; + var contents = type_contents_tuple[1]; + if (type === "ClearConsole") + ClearConsole(); + else if (type === "DidExecuteTests") + DidExecuteTests(); + else if (type === "LogHTML") + LogHTML(contents); + else if (type === "SetCookie") + SetCookie(contents); + } +} + onload = function() { var testcase = ExtractSearchParameter("testcase"); var mode = ExtractSearchParameter("mode"); @@ -91,7 +152,10 @@ onload = function() { if (obj) { obj.setAttribute("id", "plugin"); obj.setAttribute("testcase", testcase); - document.getElementById("container").appendChild(obj); + obj.setAttribute("protocol", window.location.protocol); + var container = document.getElementById("container"); + container.appendChild(obj); + container.addEventListener("message", handleTestingMessage, true); } } -- cgit v1.1