Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Unified Diff: ppapi/tests/test_case.html

Issue 7312008: Porting ppapi_tests framework to postMessage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable Scrollbar test on Mac for now, merge Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/tests/test_case.cc ('k') | ppapi/tests/test_post_message.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+ 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>
« no previous file with comments | « ppapi/tests/test_case.cc ('k') | ppapi/tests/test_post_message.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698