blob: e93d748c69e0589290f67a3b0e7ebc66ad97bb5b [file] [log] [blame]
[email protected]1758e882010-11-01 16:16:501<html><head>
[email protected]849b0712011-04-28 19:15:082<meta http-equiv="Pragma" content="no-cache" />
3<meta http-equiv="Expires" content="-1" />
[email protected]1758e882010-11-01 16:16:504<link rel="stylesheet" href="test_page.css">
5<script>
6function AdjustHeight(frameWin) {
7 var div = frameWin.document.getElementsByTagName("div")[0];
8 var height = frameWin.getComputedStyle(div).height;
9 frameWin.frameElement.style.height = height;
10}
11
12function DidExecuteTests() {
13 if (window == top)
14 return;
15
16 // Otherwise, we are in a subframe, so we can use this opportunity to resize
17 // ourselves.
18 AdjustHeight(window);
19}
20
21function AppendFrame(testcase, i) {
22 var p = document.createElement("P");
23 p.setAttribute("class", "frame-container");
24
25 var title = document.createElement("H2");
26 title.appendChild(document.createTextNode(testcase));
27 p.appendChild(title);
28
29 var frame = document.createElement("IFRAME");
[email protected]849b0712011-04-28 19:15:0830 var mode = ExtractSearchParameter("mode");
31 if (mode == "nacl")
32 frame.setAttribute("src", "?testcase=" + testcase + "&mode=nacl");
33 else
34 frame.setAttribute("src", "?testcase=" + testcase);
[email protected]1758e882010-11-01 16:16:5035 frame.setAttribute("onload", "LoadNext(" + (i + 1) + ")");
36 p.appendChild(frame);
37
38 document.body.appendChild(p);
39}
40
41function LoadNext(i) {
42 var links = document.links;
43 if (links.length > i)
44 AppendFrame(links[i].firstChild.nodeValue, i);
45}
46
47function RunAll() {
48 // Remove any existing frames.
49 var existing = document.getElementsByClassName("frame-container");
50 while (existing.length)
51 existing[0].parentNode.removeChild(existing[0]);
52
53 // Add new frames for each test, but do so one frame at a time.
54 LoadNext(0);
55}
56
[email protected]52d2c8e02010-11-16 20:59:2357function ExtractSearchParameter(name) {
58 var nameIndex = location.search.indexOf(name + "=");
59 if (nameIndex != -1) {
60 var value = location.search.substring(nameIndex + name.length + 1);
61 var endIndex = value.indexOf("&");
62 if (endIndex != -1)
63 value = value.substring(0, endIndex);
64 return value;
65 }
66 return "";
67}
[email protected]1758e882010-11-01 16:16:5068
[email protected]7f801d82011-07-08 23:30:1169// Parses the message, looking for strings of the form:
70// TESTING_MESSAGE:<message_type>:<message_contents>
71//
72// If the message_data is not a string or does not match the above format, then
73// undefined is returned.
74//
75// Otherwise, returns an array containing 2 items. The 0th element is the
76// message_type, one of:
77// - ClearContents
78// - DidExecuteTests
79// - LogHTML
80// - SetCookie
81// The second item is the verbatim message_contents.
82function ParseTestingMessage(message_data) {
83 if (typeof(message_data)!='string')
84 return undefined;
85 var testing_message_prefix = "TESTING_MESSAGE";
86 var delim_str = ":";
87 var delim1 = message_data.indexOf(delim_str);
88 if (message_data.substring(0, delim1) !== testing_message_prefix)
89 return undefined;
90 var delim2 = message_data.indexOf(delim_str, delim1 + 1);
91 if (delim2 == -1)
92 delim2 = message_data.length;
93 var message_type = message_data.substring(delim1 + 1, delim2);
94 var message_contents = message_data.substring(delim2 + 1);
95 return [message_type, message_contents];
96}
97
98function ClearConsole() {
99 window.document.getElementById("console").innerHTML = "";
100}
101
102function LogHTML(html) {
103 window.document.getElementById("console").innerHTML += html;
104}
105
106function SetCookie(key_value_string) {
107 window.document.cookie = key_value_string + "; path=/";
108}
109
110function IsTestingMessage(message_data) {
111 return (ParseTestingMessage(message_data) != undefined);
112}
113
114function handleTestingMessage(message_event) {
115 var type_contents_tuple = ParseTestingMessage(message_event.data);
116 if (type_contents_tuple) {
117 var type = type_contents_tuple[0];
118 var contents = type_contents_tuple[1];
119 if (type === "ClearConsole")
120 ClearConsole();
121 else if (type === "DidExecuteTests")
122 DidExecuteTests();
123 else if (type === "LogHTML")
124 LogHTML(contents);
125 else if (type === "SetCookie")
126 SetCookie(contents);
127 }
128}
129
[email protected]52d2c8e02010-11-16 20:59:23130onload = function() {
131 var testcase = ExtractSearchParameter("testcase");
132 var mode = ExtractSearchParameter("mode");
133 document.title = 'Test ' + testcase;
134 var obj;
135 if (mode == "nacl") {
[email protected]88bfb432011-05-23 22:43:59136 obj = document.createElement("EMBED");
137 obj.setAttribute("src", "test_case.nmf");
[email protected]849b0712011-04-28 19:15:08138 obj.setAttribute("type", "application/x-nacl");
[email protected]52d2c8e02010-11-16 20:59:23139 obj.setAttribute("mode", mode);
140 } else {
141 var mimeType = "application/x-ppapi-tests";
142 if (mimeType in navigator.mimeTypes) {
[email protected]ebc5c8be2011-05-20 22:52:59143 obj = document.createElement("EMBED");
[email protected]88bfb432011-05-23 22:43:59144 obj.setAttribute("src", "http://a.b.c/test");
[email protected]52d2c8e02010-11-16 20:59:23145 obj.setAttribute("type", mimeType);
[email protected]06e0a342011-09-27 04:24:30146 obj.setAttribute("width", 80);
147 obj.setAttribute("height", 80);
148 obj.setAttribute("style",
149 "background-color:#AAAAAA;border:1px solid black;");
[email protected]52d2c8e02010-11-16 20:59:23150 } else {
151 document.getElementById("console").innerHTML =
152 '<span class="fail">FAIL</span>: ' +
153 '<span class="err_msg">Test plug-in is not registered.</span>';
154 }
155 }
156 if (obj) {
[email protected]1758e882010-11-01 16:16:50157 obj.setAttribute("id", "plugin");
[email protected]1758e882010-11-01 16:16:50158 obj.setAttribute("testcase", testcase);
[email protected]7f801d82011-07-08 23:30:11159 obj.setAttribute("protocol", window.location.protocol);
160 var container = document.getElementById("container");
[email protected]7f801d82011-07-08 23:30:11161 container.addEventListener("message", handleTestingMessage, true);
[email protected]2deab8c2011-11-15 23:30:04162 container.appendChild(obj);
[email protected]1758e882010-11-01 16:16:50163 }
164}
165</script>
166</head><body>
167<div>
168 <div id="container"></div>
169 <div id="console" /><span class="load_msg">loading...</span></div>
170</div>
171</body></html>