Chromium Code Reviews| Index: ppapi/tests/test_case.html |
| diff --git a/ppapi/tests/test_case.html b/ppapi/tests/test_case.html |
| index 89bf1b691b8d78286c1a2482b5c916a430704296..1d395fe4bf4bf1031711d9009bb9fc6638c35e87 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); |
|
cstefansen
2011/07/07 18:03:09
Consider using split() - it would simplify this co
dmichael (off chromium)
2011/07/07 21:17:59
I wanted to do that, but it doesn't quite have the
|
| + 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> |