diff options
author | dmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-08 16:23:36 +0000 |
---|---|---|
committer | dmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-08 16:23:36 +0000 |
commit | 368ca47678e6c2208bd1849e5c8ad6f954ff0989 (patch) | |
tree | f308afb5e2e1f77906b8bd5b0479903ac9c7f42b /ppapi/tests/test_case.html | |
parent | 7b084b0f357f6a8a2cd4b58a56af234e7af063f5 (diff) | |
download | chromium_src-368ca47678e6c2208bd1849e5c8ad6f954ff0989.zip chromium_src-368ca47678e6c2208bd1849e5c8ad6f954ff0989.tar.gz chromium_src-368ca47678e6c2208bd1849e5c8ad6f954ff0989.tar.bz2 |
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
Diffstat (limited to 'ppapi/tests/test_case.html')
-rw-r--r-- | ppapi/tests/test_case.html | 66 |
1 files changed, 65 insertions, 1 deletions
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:<message_type>:<message_contents> +// +// 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); } } </script> |