comparison chrome/pageloader.js @ 200:31249cbe4f19

Bug 629691 - pageloader.xpi does not support e10s for Tp chrome testing. r=jmaher
author Joel Maher <jmaher@mozilla.com>
date Sun, 30 Jan 2011 10:21:05 -0500
parents 59d4f04497dd
children bffb8b1b0948
comparison
equal deleted inserted replaced
199:eab9ffc922b1 200:31249cbe4f19
60 var cycle; 60 var cycle;
61 var report; 61 var report;
62 var renderReport; 62 var renderReport;
63 var noisy = false; 63 var noisy = false;
64 var timeout = -1; 64 var timeout = -1;
65 var delay = 250;
65 var timeoutEvent = -1; 66 var timeoutEvent = -1;
66 var running = false; 67 var running = false;
67 var forceCC = true; 68 var forceCC = true;
68 69
69 var content; 70 var content;
96 if (args.width) winWidth = parseInt(args.width); 97 if (args.width) winWidth = parseInt(args.width);
97 if (args.height) winHeight = parseInt(args.height); 98 if (args.height) winHeight = parseInt(args.height);
98 if (args.filter) pageFilterRegexp = new RegExp(args.filter); 99 if (args.filter) pageFilterRegexp = new RegExp(args.filter);
99 if (args.noisy) noisy = true; 100 if (args.noisy) noisy = true;
100 if (args.timeout) timeout = parseInt(args.timeout); 101 if (args.timeout) timeout = parseInt(args.timeout);
102 if (args.delay) delay = parseInt(args.delay);
101 forceCC = !args.noForceCC; 103 forceCC = !args.noForceCC;
102 doRenderTest = args.doRender; 104 doRenderTest = args.doRender;
103 105
104 if (forceCC && 106 if (forceCC &&
105 !window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) 107 !window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
166 browserWindow.resizeTo(winWidth, winHeight); 168 browserWindow.resizeTo(winWidth, winHeight);
167 browserWindow.moveTo(0, 0); 169 browserWindow.moveTo(0, 0);
168 browserWindow.focus(); 170 browserWindow.focus();
169 171
170 content = browserWindow.getBrowser(); 172 content = browserWindow.getBrowser();
173
174 // Load the frame script for e10s / IPC message support
175 if (content.getAttribute("remote") == "true") {
176 let contentScript = "data:,addEventListener('load', function(e) { " +
177 " if (e.originalTarget.defaultView == content) { " +
178 " sendAsyncMessage('PageLoader:Load', {}); " +
179 " content.wrappedJSObject.tpRecordTime = function(t) { sendAsyncMessage('PageLoader:RecordTime', { time: t }); } " +
180 " }" +
181 "}, true);"
182 content.messageManager.loadFrameScript(contentScript, false);
183 }
184
171 setTimeout(plLoadPage, 100); 185 setTimeout(plLoadPage, 100);
172 }, 500); 186 }, 500);
173 }; 187 };
174 188
175 browserWindow.addEventListener('load', browserLoadFunc, true); 189 browserWindow.addEventListener('load', browserLoadFunc, true);
176 } else { 190 } else {
177 window.resizeTo(winWidth, winHeight); 191 window.resizeTo(winWidth, winHeight);
178 192
179 content = document.getElementById('contentPageloader'); 193 content = document.getElementById('contentPageloader');
180 194
181 setTimeout(plLoadPage, 250); 195 setTimeout(plLoadPage, delay);
182 } 196 }
183 } catch(e) { 197 } catch(e) {
184 dumpLine(e); 198 dumpLine(e);
185 plStop(true); 199 plStop(true);
186 } 200 }
190 return pages[pageIndex].flags; 204 return pages[pageIndex].flags;
191 } 205 }
192 206
193 // load the current page, start timing 207 // load the current page, start timing
194 var removeLastAddedListener = null; 208 var removeLastAddedListener = null;
209 var removeLastAddedMsgListener = null;
195 function plLoadPage() { 210 function plLoadPage() {
196 var pageName = pages[pageIndex].url.spec; 211 var pageName = pages[pageIndex].url.spec;
197 212
198 if (removeLastAddedListener) 213 if (removeLastAddedListener)
199 removeLastAddedListener(); 214 removeLastAddedListener();
215
216 if (removeLastAddedMsgListener)
217 removeLastAddedMsgListener();
200 218
201 if (plPageFlags() & TEST_DOES_OWN_TIMING) { 219 if (plPageFlags() & TEST_DOES_OWN_TIMING) {
202 // if the page does its own timing, use a capturing handler 220 // if the page does its own timing, use a capturing handler
203 // to make sure that we can set up the function for content to call 221 // to make sure that we can set up the function for content to call
204 content.addEventListener('load', plLoadHandlerCapturing, true); 222 content.addEventListener('load', plLoadHandlerCapturing, true);
215 removeLastAddedListener = function() { 233 removeLastAddedListener = function() {
216 content.removeEventListener('load', plLoadHandler, true); 234 content.removeEventListener('load', plLoadHandler, true);
217 }; 235 };
218 } 236 }
219 237
238 // If the test browser is remote (e10s / IPC) we need to use messages to watch for page load
239 if (content.getAttribute("remote") == "true") {
240 content.messageManager.addMessageListener('PageLoader:Load', plLoadHandlerMessage);
241 content.messageManager.addMessageListener('PageLoader:RecordTime', plRecordTimeMessage);
242 removeLastAddedMsgListener = function() {
243 content.messageManager.removeMessageListener('PageLoader:Load', plLoadHandlerMessage);
244 content.messageManager.removeMessageListener('PageLoader:RecordTime', plRecordTimeMessage);
245 };
246 }
247
220 if (timeout > 0) { 248 if (timeout > 0) {
221 timeoutEvent = setTimeout('loadFail()', timeout); 249 timeoutEvent = setTimeout('loadFail()', timeout);
222 } 250 }
223 start_time = Date.now(); 251 start_time = Date.now();
224 content.loadURI(pageName); 252 content.loadURI(pageName);
241 .garbageCollect(); 269 .garbageCollect();
242 var tccend = new Date(); 270 var tccend = new Date();
243 report.recordCCTime(tccend - tccstart); 271 report.recordCCTime(tccend - tccstart);
244 } 272 }
245 273
246 setTimeout(plLoadPage, 250); 274 setTimeout(plLoadPage, delay);
247 } else { 275 } else {
248 plStop(false); 276 plStop(false);
249 } 277 }
250 } 278 }
251 279
279 } 307 }
280 308
281 // set up the function for content to call 309 // set up the function for content to call
282 content.contentWindow.wrappedJSObject.tpRecordTime = function (time) { 310 content.contentWindow.wrappedJSObject.tpRecordTime = function (time) {
283 plRecordTime(time); 311 plRecordTime(time);
284 setTimeout(plNextPage, 250); 312 setTimeout(plNextPage, delay);
285 }; 313 };
286 } 314 }
287 315
288 // the onload handler 316 // the onload handler
289 function plLoadHandler(evt) { 317 function plLoadHandler(evt) {
322 runRenderTest(); 350 runRenderTest();
323 351
324 plNextPage(); 352 plNextPage();
325 } 353 }
326 354
355 // the onload handler used for remote (e10s) browser
356 function plLoadHandlerMessage(message) {
357 if (timeout > 0) {
358 clearTimeout(timeoutEvent);
359 }
360
361 // does this page want to do its own timing?
362 // if so, let's bail
363 if (plPageFlags() & TEST_DOES_OWN_TIMING)
364 return;
365
366 var end_time = Date.now();
367 var time = (end_time - start_time);
368
369 plRecordTime(time);
370
371 if (doRenderTest)
372 runRenderTest();
373
374 plNextPage();
375 }
376
377 // the record time handler used for remote (e10s) browser
378 function plRecordTimeMessage(message) {
379 plRecordTime(message.json.time);
380 setTimeout(plNextPage, delay);
381 }
382
327 function runRenderTest() { 383 function runRenderTest() {
328 const redrawsPerSample = 500; 384 const redrawsPerSample = 500;
329 385
330 if (!Ci.nsIDOMWindowUtils) 386 if (!Ci.nsIDOMWindowUtils)
331 return; 387 return;
350 try { 406 try {
351 if (force == false) { 407 if (force == false) {
352 pageIndex = 0; 408 pageIndex = 0;
353 if (cycle < NUM_CYCLES-1) { 409 if (cycle < NUM_CYCLES-1) {
354 cycle++; 410 cycle++;
355 setTimeout(plLoadPage, 250); 411 setTimeout(plLoadPage, delay);
356 return; 412 return;
357 } 413 }
358 414
359 var formats = reportFormat.split(","); 415 var formats = reportFormat.split(",");
360 416
370 } 426 }
371 } catch (e) { 427 } catch (e) {
372 dumpLine(e); 428 dumpLine(e);
373 } 429 }
374 430
375 if (content) 431 if (content) {
376 content.removeEventListener('load', plLoadHandler, true); 432 content.removeEventListener('load', plLoadHandler, true);
433 if (content.getAttribute("remote") == "true")
434 content.messageManager.removeMessageListener('PageLoader:Load', plLoadHandlerMessage);
435 }
377 436
378 if (MozillaFileLogger) 437 if (MozillaFileLogger)
379 MozillaFileLogger.close(); 438 MozillaFileLogger.close();
380 439
381 goQuitApplication(); 440 goQuitApplication();