[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 1 | <html><head> |
[email protected] | 849b071 | 2011-04-28 19:15:08 | [diff] [blame] | 2 | <meta http-equiv="Pragma" content="no-cache" /> |
| 3 | <meta http-equiv="Expires" content="-1" /> |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 4 | <link rel="stylesheet" href="test_page.css"> |
| 5 | <script> |
| 6 | function 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 | |
| 12 | function 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 | |
| 21 | function 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] | 849b071 | 2011-04-28 19:15:08 | [diff] [blame] | 30 | 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] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 35 | frame.setAttribute("onload", "LoadNext(" + (i + 1) + ")"); |
| 36 | p.appendChild(frame); |
| 37 | |
| 38 | document.body.appendChild(p); |
| 39 | } |
| 40 | |
| 41 | function LoadNext(i) { |
| 42 | var links = document.links; |
| 43 | if (links.length > i) |
| 44 | AppendFrame(links[i].firstChild.nodeValue, i); |
| 45 | } |
| 46 | |
| 47 | function 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] | 52d2c8e0 | 2010-11-16 20:59:23 | [diff] [blame] | 57 | function 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] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 68 | |
[email protected] | 7f801d8 | 2011-07-08 23:30:11 | [diff] [blame] | 69 | // 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. |
| 82 | function 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 | |
| 98 | function ClearConsole() { |
| 99 | window.document.getElementById("console").innerHTML = ""; |
| 100 | } |
| 101 | |
| 102 | function LogHTML(html) { |
| 103 | window.document.getElementById("console").innerHTML += html; |
| 104 | } |
| 105 | |
| 106 | function SetCookie(key_value_string) { |
| 107 | window.document.cookie = key_value_string + "; path=/"; |
| 108 | } |
| 109 | |
| 110 | function IsTestingMessage(message_data) { |
| 111 | return (ParseTestingMessage(message_data) != undefined); |
| 112 | } |
| 113 | |
| 114 | function 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] | 52d2c8e0 | 2010-11-16 20:59:23 | [diff] [blame] | 130 | onload = 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] | 88bfb43 | 2011-05-23 22:43:59 | [diff] [blame] | 136 | obj = document.createElement("EMBED"); |
| 137 | obj.setAttribute("src", "test_case.nmf"); |
[email protected] | 849b071 | 2011-04-28 19:15:08 | [diff] [blame] | 138 | obj.setAttribute("type", "application/x-nacl"); |
[email protected] | 52d2c8e0 | 2010-11-16 20:59:23 | [diff] [blame] | 139 | obj.setAttribute("mode", mode); |
| 140 | } else { |
| 141 | var mimeType = "application/x-ppapi-tests"; |
| 142 | if (mimeType in navigator.mimeTypes) { |
[email protected] | ebc5c8be | 2011-05-20 22:52:59 | [diff] [blame] | 143 | obj = document.createElement("EMBED"); |
[email protected] | 88bfb43 | 2011-05-23 22:43:59 | [diff] [blame] | 144 | obj.setAttribute("src", "http://a.b.c/test"); |
[email protected] | 52d2c8e0 | 2010-11-16 20:59:23 | [diff] [blame] | 145 | obj.setAttribute("type", mimeType); |
[email protected] | 06e0a34 | 2011-09-27 04:24:30 | [diff] [blame] | 146 | obj.setAttribute("width", 80); |
| 147 | obj.setAttribute("height", 80); |
| 148 | obj.setAttribute("style", |
| 149 | "background-color:#AAAAAA;border:1px solid black;"); |
[email protected] | 52d2c8e0 | 2010-11-16 20:59:23 | [diff] [blame] | 150 | } 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] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 157 | obj.setAttribute("id", "plugin"); |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 158 | obj.setAttribute("testcase", testcase); |
[email protected] | 7f801d8 | 2011-07-08 23:30:11 | [diff] [blame] | 159 | obj.setAttribute("protocol", window.location.protocol); |
| 160 | var container = document.getElementById("container"); |
[email protected] | 7f801d8 | 2011-07-08 23:30:11 | [diff] [blame] | 161 | container.addEventListener("message", handleTestingMessage, true); |
[email protected] | c4cc74c | 2011-11-17 17:06:34 | [diff] [blame^] | 162 | // Register a bad dispatchEvent to make sure it isn't used. See 'EVIL' note |
| 163 | // below. |
| 164 | obj.dispatchEvent = function() { |
| 165 | LogHTML("<p>Bad dispatchEvent called!"); |
| 166 | } |
[email protected] | 2deab8c | 2011-11-15 23:30:04 | [diff] [blame] | 167 | container.appendChild(obj); |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 168 | } |
| 169 | } |
[email protected] | c4cc74c | 2011-11-17 17:06:34 | [diff] [blame^] | 170 | |
| 171 | // EVIL Note: |
| 172 | // This part of the script does some nefarious things to make sure that it |
| 173 | // doesn't affect the behavior of PostMessage (on which all the tests rely). In |
| 174 | // particular, we replace document.createEvent, MessageEvent.initMessageEvent, |
| 175 | // and the MessageEvent constructor. Previous versions of the PostMessage |
| 176 | // implementation made use of these and would fail (http://crbug.com/82604). |
| 177 | document.createEvent = function() { |
| 178 | LogHTML("<p>Bad document.createEvent called!"); |
| 179 | } |
| 180 | function MessageEvent() { |
| 181 | LogHTML("<p>Bad MessageEvent constructor called!"); |
| 182 | } |
| 183 | MessageEvent.prototype.initMessageEvent = function() { |
| 184 | LogHTML("<p>Bad MessageEvent.initMessageEvent called!"); |
| 185 | } |
| 186 | |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 187 | </script> |
| 188 | </head><body> |
| 189 | <div> |
| 190 | <div id="container"></div> |
| 191 | <div id="console" /><span class="load_msg">loading...</span></div> |
| 192 | </div> |
| 193 | </body></html> |