1(function(){ 2 var DRT = { 3 baseURL: "./resources/dromaeo/web/index.html", 4 5 setup: function(testName) { 6 var ITERATION_COUNT = 5; 7 PerfTestRunner.prepareToMeasureValuesAsync({dromaeoIterationCount: ITERATION_COUNT, doNotMeasureMemoryUsage: true, doNotIgnoreInitialRun: true, unit: 'runs/s'}); 8 9 var iframe = document.createElement("iframe"); 10 var url = DRT.baseURL + "?" + testName + '&numTests=' + ITERATION_COUNT; 11 iframe.setAttribute("src", url); 12 document.body.insertBefore(iframe, document.body.firstChild); 13 iframe.addEventListener( 14 "load", function() { 15 DRT.targetDocument = iframe.contentDocument; 16 DRT.targetWindow = iframe.contentDocument.defaultView; 17 }); 18 19 window.addEventListener( 20 "message", 21 function(event) { 22 switch(event.data.name) { 23 case "dromaeo:ready": 24 DRT.start(); 25 break; 26 case "dromaeo:progress": 27 DRT.progress(event.data); 28 break; 29 case "dromaeo:alldone": 30 DRT.teardown(event.data); 31 break; 32 } 33 }); 34 }, 35 36 start: function() { 37 DRT.targetWindow.postMessage({ name: "dromaeo:start" } , "*"); 38 }, 39 40 progress: function(message) { 41 var score = message.status.score; 42 if (score) 43 DRT.log(score.name + ': [' + score.times.join(', ') + ']'); 44 }, 45 46 teardown: function(data) { 47 PerfTestRunner.log(''); 48 49 var tests = data.result; 50 var times = []; 51 for (var i = 0; i < tests.length; ++i) { 52 for (var j = 0; j < tests[i].times.length; ++j) { 53 var runsPerSecond = tests[i].times[j]; 54 times[j] = (times[j] || 0) + 1 / runsPerSecond; 55 } 56 } 57 58 for (var i = 0; i < times.length; ++i) 59 PerfTestRunner.measureValueAsync(1 / times[i]); 60 }, 61 62 targetDelegateOf: function(functionName) { 63 return function() { 64 DRT.targetWindow[functionName].apply(null, arguments); 65 }; 66 }, 67 68 log: function(text) { 69 PerfTestRunner.log(text); 70 } 71 }; 72 73 // These functions are referred from htmlrunner.js 74 this.startTest = DRT.targetDelegateOf("startTest"); 75 this.test = DRT.targetDelegateOf("test"); 76 this.endTest = DRT.targetDelegateOf("endTest"); 77 this.prep = DRT.targetDelegateOf("prep"); 78 79 window.DRT = DRT; 80 })(); 81