summaryrefslogtreecommitdiffstats
path: root/ppapi/tests/test_case.html
diff options
context:
space:
mode:
authordmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-08 23:30:11 +0000
committerdmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-08 23:30:11 +0000
commit7f801d827de060e0bb88e266e6aa889ba3e14289 (patch)
treece099bd5fe4f4453264737e75aac0e47507bef1a /ppapi/tests/test_case.html
parentc3cda1877dbcd1b56410bd4f1c2c862bbfc40b9d (diff)
downloadchromium_src-7f801d827de060e0bb88e266e6aa889ba3e14289.zip
chromium_src-7f801d827de060e0bb88e266e6aa889ba3e14289.tar.gz
chromium_src-7f801d827de060e0bb88e266e6aa889ba3e14289.tar.bz2
Reland http://codereview.chromium.org/7312008/
The only difference is I clear modifiers in Scrollbar test, and leave it enabled. Unrevert ppapi_tests change: 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. BUG=82606 TEST=these tests. Review URL: http://codereview.chromium.org/7237056 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91912 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests/test_case.html')
-rw-r--r--ppapi/tests/test_case.html66
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>