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

Side by Side Diff: ppapi/tests/test_case.html

Issue 9564024: Re-land http://codereview.chromium.org/9403039/, r124106 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove unnecessary change to ppapi_uitest.cc timer_ Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/tests/test_case.cc ('k') | ppapi/tests/test_instance_deprecated.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <html><head> 1 <html><head>
2 <meta http-equiv="Pragma" content="no-cache" /> 2 <meta http-equiv="Pragma" content="no-cache" />
3 <meta http-equiv="Expires" content="-1" /> 3 <meta http-equiv="Expires" content="-1" />
4 <link rel="stylesheet" href="test_page.css"> 4 <link rel="stylesheet" href="test_page.css">
5 <script> 5 <script>
6 function AdjustHeight(frameWin) { 6 function AdjustHeight(frameWin) {
7 var div = frameWin.document.getElementsByTagName("div")[0]; 7 var div = frameWin.document.getElementsByTagName("div")[0];
8 var height = frameWin.getComputedStyle(div).height; 8 var height = frameWin.getComputedStyle(div).height;
9 frameWin.frameElement.style.height = height; 9 frameWin.frameElement.style.height = height;
10 } 10 }
11 11
12 function DidExecuteTests() { 12 function DidExecuteTests() {
13 var plugin = document.getElementById("plugin");
14 plugin.parentNode.removeChild(plugin);
15 plugin = undefined;
16 CheckPostConditions();
17
13 if (window == top) 18 if (window == top)
14 return; 19 return;
15 20
16 // Otherwise, we are in a subframe, so we can use this opportunity to resize 21 // Otherwise, we are in a subframe, so we can use this opportunity to resize
17 // ourselves. 22 // ourselves.
18 AdjustHeight(window); 23 AdjustHeight(window);
19 } 24 }
20 25
21 function AppendFrame(testcase, i) { 26 function AppendFrame(testcase, i) {
22 var p = document.createElement("P"); 27 var p = document.createElement("P");
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // If the message_data is not a string or does not match the above format, then 81 // If the message_data is not a string or does not match the above format, then
77 // undefined is returned. 82 // undefined is returned.
78 // 83 //
79 // Otherwise, returns an array containing 2 items. The 0th element is the 84 // Otherwise, returns an array containing 2 items. The 0th element is the
80 // message_type, one of: 85 // message_type, one of:
81 // - ClearContents 86 // - ClearContents
82 // - DidExecuteTests 87 // - DidExecuteTests
83 // - LogHTML 88 // - LogHTML
84 // - SetCookie 89 // - SetCookie
85 // - EvalScript 90 // - EvalScript
91 // - AddPostCondition
86 // The second item is the verbatim message_contents. 92 // The second item is the verbatim message_contents.
87 function ParseTestingMessage(message_data) { 93 function ParseTestingMessage(message_data) {
88 if (typeof(message_data)!='string') 94 if (typeof(message_data) != "string")
89 return undefined; 95 return undefined;
90 var testing_message_prefix = "TESTING_MESSAGE"; 96 var testing_message_prefix = "TESTING_MESSAGE";
91 var delim_str = ":"; 97 var delim_str = ":";
92 var delim1 = message_data.indexOf(delim_str); 98 var delim1 = message_data.indexOf(delim_str);
93 if (message_data.substring(0, delim1) !== testing_message_prefix) 99 if (message_data.substring(0, delim1) !== testing_message_prefix)
94 return undefined; 100 return undefined;
95 var delim2 = message_data.indexOf(delim_str, delim1 + 1); 101 var delim2 = message_data.indexOf(delim_str, delim1 + 1);
96 if (delim2 == -1) 102 if (delim2 == -1)
97 delim2 = message_data.length; 103 delim2 = message_data.length;
98 var message_type = message_data.substring(delim1 + 1, delim2); 104 var message_type = message_data.substring(delim1 + 1, delim2);
(...skipping 13 matching lines...) Expand all
112 window.document.cookie = key_value_string + "; path=/"; 118 window.document.cookie = key_value_string + "; path=/";
113 } 119 }
114 120
115 function EvalScript(script) { 121 function EvalScript(script) {
116 try { 122 try {
117 eval(script); 123 eval(script);
118 } catch(ex) { 124 } catch(ex) {
119 } 125 }
120 } 126 }
121 127
128 var conditions = [];
129 // Add a "PostCondition". These are bits of script that are run after the plugin
130 // is destroyed. If they evaluate to false or throw an exception, it's
131 // considered a failure.
132 function AddPostCondition(script) {
133 conditions.push(script);
134 }
135 // Update the HTML to show the failure and update cookies so that ui_tests
136 // doesn't count this as a pass.
137 function ConditionFailed(error) {
138 error_string = "Post condition check failed: " + error;
139 var i = 0;
140 // If the plugin thinks the test passed but a post-condition failed, we want
141 // to clear the PASS cookie so that ui_tests doesn't count it is a passed
142 // test.
143 if (window.document.cookie.indexOf("PASS") != -1) {
144 while (window.document.cookie.indexOf("PPAPI_PROGRESS_" + i) != -1) {
145 window.document.cookie = "PPAPI_PROGRESS_" + i + "=; max-age=0";
146 ++i;
147 }
148 window.document.cookie = "PPAPI_PROGRESS_0=" + error_string
149 }
150 LogHTML("<p>" + error_string);
151 }
152 // Iterate through the post conditions defined in |conditions| and check that
153 // they all pass.
154 function CheckPostConditions() {
155 for (var i = 0; i < conditions.length; ++i) {
156 var script = conditions[i];
157 try {
158 if (!eval(script)) {
159 ConditionFailed("\"" + script + "\"");
160 }
161 } catch (ex) {
162 ConditionFailed("\"" + script + "\"" + " failed with exception: " +
163 "\"" + ex.toString() + "\"");
164 }
165 }
166 }
167
122 function IsTestingMessage(message_data) { 168 function IsTestingMessage(message_data) {
123 return (ParseTestingMessage(message_data) != undefined); 169 return (ParseTestingMessage(message_data) != undefined);
124 } 170 }
125 171
126 function handleTestingMessage(message_event) { 172 function handleTestingMessage(message_event) {
127 var type_contents_tuple = ParseTestingMessage(message_event.data); 173 var type_contents_tuple = ParseTestingMessage(message_event.data);
128 if (type_contents_tuple) { 174 if (type_contents_tuple) {
129 var type = type_contents_tuple[0]; 175 var type = type_contents_tuple[0];
130 var contents = type_contents_tuple[1]; 176 var contents = type_contents_tuple[1];
131 if (type === "ClearConsole") 177 if (type === "ClearConsole")
132 ClearConsole(); 178 ClearConsole();
133 else if (type === "DidExecuteTests") 179 else if (type === "DidExecuteTests")
134 DidExecuteTests(); 180 DidExecuteTests();
135 else if (type === "LogHTML") 181 else if (type === "LogHTML")
136 LogHTML(contents); 182 LogHTML(contents);
137 else if (type === "SetCookie") 183 else if (type === "SetCookie")
138 SetCookie(contents); 184 SetCookie(contents);
139 else if (type === "EvalScript") 185 else if (type === "EvalScript")
140 EvalScript(contents); 186 EvalScript(contents);
187 else if (type == "AddPostCondition")
188 AddPostCondition(contents);
141 } 189 }
142 } 190 }
143 191
144 onload = function() { 192 onload = function() {
145 var testcase = ExtractSearchParameter("testcase"); 193 var testcase = ExtractSearchParameter("testcase");
146 var mode = ExtractSearchParameter("mode"); 194 var mode = ExtractSearchParameter("mode");
147 document.title = 'Test ' + testcase; 195 document.title = 'Test ' + testcase;
148 var obj; 196 var obj;
149 if (mode == "nacl") { 197 if (mode == "nacl") {
150 obj = document.createElement("EMBED"); 198 obj = document.createElement("EMBED");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 container.appendChild(obj); 232 container.appendChild(obj);
185 } 233 }
186 } 234 }
187 235
188 // EVIL Note: 236 // EVIL Note:
189 // This part of the script does some nefarious things to make sure that it 237 // This part of the script does some nefarious things to make sure that it
190 // doesn't affect the behavior of PostMessage (on which all the tests rely). In 238 // doesn't affect the behavior of PostMessage (on which all the tests rely). In
191 // particular, we replace document.createEvent, MessageEvent.initMessageEvent, 239 // particular, we replace document.createEvent, MessageEvent.initMessageEvent,
192 // and the MessageEvent constructor. Previous versions of the PostMessage 240 // and the MessageEvent constructor. Previous versions of the PostMessage
193 // implementation made use of these and would fail (http://crbug.com/82604). 241 // implementation made use of these and would fail (http://crbug.com/82604).
242 // TODO(dmichael): These should clear the PASS cookie so that ui_tests sees
243 // these as a failure (see ConditionFailed for how to do this).
244 // crbug.com/109775
194 document.createEvent = function() { 245 document.createEvent = function() {
195 LogHTML("<p>Bad document.createEvent called!"); 246 LogHTML("<p>Bad document.createEvent called!");
196 } 247 }
197 function MessageEvent() { 248 function MessageEvent() {
198 LogHTML("<p>Bad MessageEvent constructor called!"); 249 LogHTML("<p>Bad MessageEvent constructor called!");
199 } 250 }
200 MessageEvent.prototype.initMessageEvent = function() { 251 MessageEvent.prototype.initMessageEvent = function() {
201 LogHTML("<p>Bad MessageEvent.initMessageEvent called!"); 252 LogHTML("<p>Bad MessageEvent.initMessageEvent called!");
202 } 253 }
203 254
204 </script> 255 </script>
205 </head><body> 256 </head><body>
206 <div> 257 <div>
207 <div id="container"></div> 258 <div id="container"></div>
208 <div id="console" /><span class="load_msg">loading...</span></div> 259 <div id="console" /><span class="load_msg">loading...</span></div>
209 </div> 260 </div>
210 </body></html> 261 </body></html>
OLDNEW
« no previous file with comments | « ppapi/tests/test_case.cc ('k') | ppapi/tests/test_instance_deprecated.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698