Ticket #3627: 3627.patch

File 3627.patch, 14.2 KB (added by garry.yao, 5 years ago)
  • _source/tests/JSLitmus.js

     
     1// JSLitmus.js 
     2// 
     3// History: 
     4//   2008-10-27: Initial release 
     5//   2008-11-09: Account for iteration loop overhead 
     6//   2008-11-13: Added OS detection 
     7//   2009-02-25: Create tinyURL automatically, shift-click runs tests in reverse 
     8// 
     9// Copyright (c) 2008-2009, Robert Kieffer 
     10// All Rights Reserved 
     11// 
     12// Permission is hereby granted, free of charge, to any person obtaining a copy 
     13// of this software and associated documentation files (the 
     14// Software), to deal in the Software without restriction, including 
     15// without limitation the rights to use, copy, modify, merge, publish, 
     16// distribute, sublicense, and/or sell copies of the Software, and to permit 
     17// persons to whom the Software is furnished to do so, subject to the 
     18// following conditions: 
     19// 
     20// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, 
     21// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
     22// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 
     23// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
     24// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
     25// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 
     26// USE OR OTHER DEALINGS IN THE SOFTWARE. 
     27(function(){var b="unknown platform",a=navigator.userAgent;var i=["Windows","iPhone OS","(Intel |PPC )?Mac OS X","Linux"].join("|");var d=new RegExp("(("+i+") [^ );]*)").test(a)?RegExp.$1:null;if(!d){d=new RegExp("(("+i+")[^ );]*)").test(a)?RegExp.$1:null}var g=/(Chrome|MSIE|Safari|Opera|Firefox)/.test(a)?RegExp.$1:null;var f=new RegExp("(Version|"+g+")[ /]([^ ;]*)");var j=(g&&f.test(a))?RegExp.$2:null;var b=(d&&g&&j)?g+" "+j+" on "+d:"unknown platform";var e={escape:function(l){l=l.replace(/,/g,"\\,");l=escape(l);l=l.replace(/\+/g,"%2b");l=l.replace(/ /g,"+");return l},$:function(l){return document.getElementById(l)},F:function(){},status:function(m){var l=e.$("jsl_status");if(l){l.innerHTML=m||""}},toLabel:function(l){if(l==Infinity){return"Infinity"}else{if(l>1000000000){l=Math.round(l/100000000);return l/10+"B"}else{if(l>1000000){l=Math.round(l/100000);return l/10+"M"}else{if(l>1000){l=Math.round(l/100);return l/10+"K"}}}}return l},extend:function(n,m){for(var l in m){n[l]=m[l]}return n},join:function(q,p,n){if(q.join){return q.join(p)}var m=[];for(var l in q){m.push(l+p+q[l])}return m.join(n)},indexOf:function(l,n){if(l.indexOf){return l.indexOf(n)}for(var m=0;m<this.length;m++){if(l[m]===n){return m}}return -1}};var k=function(l,m){if(!m){throw new Error("Undefined test function")}if(!/function[^\(]*\(([^,\)]*)/.test(m.toString())){throw new Error('"'+l+'" test: Test is not a valid Function object')}this.loopArg=RegExp.$1;this.name=l;this.f=m};e.extend(k,{CALIBRATIONS:[new k("calibrating loop",function(l){while(l--){}}),new k("calibrating function",e.F)],calibrate:function(l){for(var m=0;m<k.CALIBRATIONS.length;m++){var n=k.CALIBRATIONS[m];if(n.running){return true}if(!n.count){n.isCalibration=true;n.onStop=l;n.run(20000);return true}}return false}});e.extend(k.prototype,{INIT_COUNT:10,MAX_COUNT:1000000000,MIN_TIME:0.5,onChange:e.F,onStop:e.F,reset:function(){delete this.count;delete this.time;delete this.running;delete this.error},run:function(m){m=m||this.INIT_COUNT;e.status(this.name+" x "+m);this.running=true;var l=this;setTimeout(function(){l._run(m)},200)},_run:function(p){var s=this;if(!s.isCalibration&&k.calibrate(function(){s.run(p)})){return}this.error=null;try{var l,o=this.f,m,n=p;l=new Date();if(this.loopArg){o(p)}else{while(n--){o()}}this.time=Math.max(1,new Date()-l)/1000;this.count=p;this.period=this.time/p;this.running=this.time<=this.MIN_TIME;if(this.running){var t=this.MIN_TIME/this.time;var q=Math.pow(2,Math.max(1,Math.ceil(Math.log(t)/Math.log(2))));p*=q;if(p>this.MAX_COUNT){throw new Error("Max count exceeded.  If this test uses a looping function, make sure the iteration loop is working properly.")}}}catch(r){this.reset();this.error=r}if(this.running){s.run(p)}else{e.status("");s.onStop(s)}this.onChange(this)},getHz:function(l){var n=this.period;if(l&&!this.isCalibration){var m=k.CALIBRATIONS[this.loopArg?0:1];n=n<m.period*1.2?0:n-m.period}return Math.round(1/n)},toString:function(){return this.name+" - "+this.time/this.count+" secs"}});var c="<style>     #jslitmus {font-family:sans-serif; font-size: 12px;}     #jslitmus a {text-decoration: none;}     #jslitmus a:hover {text-decoration: underline;}     #jsl_status {       margin-top: 10px;       font-size: 10px;       color: #888;     }     A IMG  {border:none}     #test_results {       margin-top: 10px;       font-size: 12px;       font-family: sans-serif;       border-collapse: collapse;       border-spacing: 0px;     }     #test_results th, #test_results td {       border: solid 1px #ccc;       vertical-align: top;       padding: 3px;     }     #test_results th {       vertical-align: bottom;       background-color: #ccc;       padding: 1px;       font-size: 10px;     }     #test_results #test_platform {       color: #444;       text-align:center;     }     #test_results .test_row {       color: #006;       cursor: pointer;     }     #test_results .test_nonlooping {       border-left-style: dotted;       border-left-width: 2px;     }     #test_results .test_looping {       border-left-style: solid;       border-left-width: 2px;     }     #test_results .test_name {white-space: nowrap;}     #test_results .test_pending {     }     #test_results .test_running {       font-style: italic;     }     #test_results .test_done {}     #test_results .test_done {       text-align: right;       font-family: monospace;     }     #test_results .test_error {color: #600;}     #test_results .test_error .error_head {font-weight:bold;}     #test_results .test_error .error_body {font-size:85%;}     #test_results .test_row:hover td {       background-color: #ffc;       text-decoration: underline;     }     #chart {       margin: 10px 0px;       width: 250px;     }     #chart img {       border: solid 1px #ccc;       margin-bottom: 5px;     }     #chart #tiny_url {       height: 40px;       width: 250px;     }     #jslitmus_credit {       font-size: 10px;       color: #888;       margin-top: 8px;     }     </style>";var h='<div id="jslitmus">       <button onclick="JSLitmus.runAll(event)">Run Tests</button>       <button id="stop_button" disabled="disabled" onclick="JSLitmus.stop()">Stop Tests</button>       <br >       <br >       <input type="checkbox" style="vertical-align: middle" id="test_normalize" checked="checked" onchange="JSLitmus.renderAll()""> Normalize results       <table id="test_results">         <colgroup>           <col />           <col width="100" />         </colgroup>         <tr><th id="test_platform" colspan="2">'+b+'</th></tr>         <tr><th>Test</th><th>Ops/sec</th></tr>         <tr id="test_row_template" class="test_row" style="display:none">           <td class="test_name"></td>           <td class="test_result">Ready</td>         </tr>       </table>       <div id="jsl_status"></div>       <div id="chart" style="display:none">       <a id="chart_link" target="_blank"><img id="chart_image"></a>       TinyURL (for chart):       <iframe id="tiny_url" frameBorder="0" scrolling="no" src=""></iframe>       </div>       <a id="jslitmus_credit" title="JSLitmus home page" href="http://code.google.com/p/jslitmus" target="_blank">Powered by JSLitmus</a>     </div>';window.JSLitmus={_tests:[],_queue:[],params:{},_init:function(){var l=(location+"").match(/([^?#]*)(#.*)?$/);if(l){var p=l[1].split("&");for(var n=0;n<p.length;n++){var q=p[n].split("=");if(q.length>1){var m=q.shift();var o=q.length>1?q.join("="):q[0];this.params[m]=o}}}document.write(c);if(window.addEventListener){window.addEventListener("load",this._setup,false)}else{if(document.addEventListener){document.addEventListener("load",this._setup,false)}else{if(window.attachEvent){window.attachEvent("onload",this._setup)}}}return this},_setup:function(){var m=e.$("jslitmus_container");if(!m){document.body.appendChild(m=document.createElement("div"))}m.innerHTML=h;for(var l=0;l<JSLitmus._tests.length;l++){JSLitmus.renderTest(JSLitmus._tests[l])}},renderAll:function(){for(var l=0;l<JSLitmus._tests.length;l++){JSLitmus.renderTest(JSLitmus._tests[l])}JSLitmus.renderChart()},renderChart:function(){var l=JSLitmus.chartUrl();e.$("chart_link").href=l;e.$("chart_image").src=l;e.$("chart").style.display="";e.$("tiny_url").src="http://tinyurl.com/api-create.php?url="+escape(l)},renderTest:function(p){if(!p._row){var m=e.$("test_row_template");if(!m){return}p._row=m.cloneNode(true);p._row.style.display="";p._row.id="";p._row.onclick=function(){JSLitmus._queueTest(p)};p._row.title="Run "+p.name+" test";m.parentNode.appendChild(p._row);p._row.cells[0].innerHTML=p.name}var l=p._row.cells[1];var n=[p.loopArg?"test_looping":"test_nonlooping"];if(p.error){n.push("test_error");l.innerHTML='<div class="error_head">'+p.error+'</div><ul class="error_body"><li>'+e.join(p.error,": ","</li><li>")+"</li></ul>"}else{if(p.running){n.push("test_running");l.innerHTML="running"}else{if(e.indexOf(JSLitmus._queue,p)>=0){n.push("test_pending");l.innerHTML="pending"}else{if(p.count){n.push("test_done");var o=p.getHz(e.$("test_normalize").checked);l.innerHTML=o!=Infinity?o:"&infin;"}else{l.innerHTML="ready"}}}}l.className=n.join(" ")},test:function(l,m){var n=new k(l,m);JSLitmus._tests.push(n);n.onChange=JSLitmus.renderTest;n.onStop=function(o){if(JSLitmus.onTestFinish){JSLitmus.onTestFinish(o)}JSLitmus.currentTest=null;JSLitmus._nextTest()};this.renderTest(n)},runAll:function(o){o=o||window.event;var m=o&&o.shiftKey,l=JSLitmus._tests.length;for(var n=0;n<l;n++){JSLitmus._queueTest(JSLitmus._tests[!m?n:(l-n-1)])}},stop:function(){while(JSLitmus._queue.length){var l=JSLitmus._queue.shift();JSLitmus.renderTest(l)}},_nextTest:function(){if(!JSLitmus.currentTest){var l=JSLitmus._queue.shift();if(l){e.$("stop_button").disabled=false;JSLitmus.currentTest=l;l.run();JSLitmus.renderTest(l);if(JSLitmus.onTestStart){JSLitmus.onTestStart(l)}}else{e.$("stop_button").disabled=true;JSLitmus.renderChart()}}},_queueTest:function(l){if(e.indexOf(JSLitmus._queue,l)>=0){return}JSLitmus._queue.push(l);JSLitmus.renderTest(l);JSLitmus._nextTest()},chartUrl:function(){var p=JSLitmus._tests.length,y=[],F=[];var B,q=0,s=-10000000000;var r=e.$("test_normalize").checked;for(var t=0;t<JSLitmus._tests.length;t++){var A=JSLitmus._tests[t];if(A.count){var x=A.getHz(r);var o=x!=Infinity?x:0;F.push(o);y.push("t"+e.escape(A.name+"("+e.toLabel(x)+")")+",000000,0,"+y.length+",10");s=Math.max(o,s)}}if(y.length<=0){return null}var G=document.getElementsByTagName("title");G=(G&&G.length)?G[0].innerHTML:null;var l=[];if(G){l.push(G)}l.push("Ops/sec ("+b+")");var C=[e.toLabel(q),e.toLabel(s)];var m=250,z=15;var E=5;var u=y.length*(z+E)+30+l.length*20;var D={chtt:escape(l.join("|")),chts:"000000,10",cht:"bhg",chd:"t:"+F.join(","),chds:q+","+s,chxt:"x",chxl:"0:|"+C.join("|"),chsp:"0,1",chm:y.join("|"),chbh:[z,0,E].join(","),chs:m+"x"+u};return"http://chart.apis.google.com/chart?"+e.join(D,"=","&")}};JSLitmus._init()})(); 
  • _source/tests/test.js

     
    1515        '_tests/yuitest.js"></script>' ); 
    1616%REMOVE_LINE%   */ 
    1717 
     18// Inject the JSLitmus Performance Test files into the page. 
     19// URLs copied from http://code.google.com/p/jslitmus/ 
    1820document.write( 
    1921        '<script type="text/javascript" src="' + 
    2022        CKEDITOR.basePath + 
     23        '_source/' +                                            // %REMOVE_LINE% 
     24        'tests/JSLitmus.js"></script>' );       /* %REMOVE_LINE% 
     25        '_tests/JSLitmus.js"></script>' ); 
     26%REMOVE_LINE%   */ 
     27 
     28 
     29document.write( 
     30        '<script type="text/javascript" src="' + 
     31        CKEDITOR.basePath + 
    2132        '_source/' + 
    2233        'core/test.js"></script>' ); 
    2334 
  • _source/tests/test.css

     
    7979{ 
    8080        background-color: #f1f100; 
    8181} 
     82 
     83#jslitmus { 
     84        position: absolute; 
     85        right: 10px; 
     86        top: 10px; 
     87        margin: 10px 10px 0px 0px; 
     88         
     89} 
  • _source/core/test.js

     
    3030         */ 
    3131        assert : YAHOO.util.Assert, 
    3232 
     33        runner : YAHOO.tool.TestRunner, 
     34 
    3335        /** 
     36         * Run the specific profile function right after the 
     37         * corresponding unit test has passed. 
     38         * @type {Boolean} 
     39         */ 
     40        autoProfile : false, 
     41 
     42        /** 
    3443         * Adds a test case to the test runner. 
    3544         * @param {Object} testCase The test case object. See other tests for 
    3645         *              examples. 
     
    5059         */ 
    5160        addTestCase : function( testCase ) 
    5261        { 
    53                 YAHOO.tool.TestRunner.add( new YAHOO.tool.TestCase( testCase ) ); 
     62                this.runner.add( new YAHOO.tool.TestCase( testCase ) ); 
     63 
     64                // Ignore performance testing if it declared to be a pure unit TC. 
     65                if ( !testCase.unitTestOnly ) 
     66                { 
     67                        this.addPerformanceTestCase( testCase ); 
     68                } 
    5469        }, 
    5570 
    5671        /** 
     72         * Adds a performance test case to the performance test runner. 
     73         * @param {Object} testCase Either a YUITest TC OR JSLitmus performance TC. 
     74         */ 
     75        addPerformanceTestCase : function( testCase ) 
     76        { 
     77                function rename( testCase ) 
     78                { 
     79                        return testCase.replace(/^test/, 'profile' ); 
     80                } 
     81 
     82                if ( this.autoProfile ) 
     83                        this.runner.subscribe( this.runner.TEST_PASS_EVENT, function( evt ){ 
     84                                // JSLitmus doesn't provide API for queue a specific test, trigger it 
     85                                // at UI level. 
     86                                var row = YAHOO.util.Selector.query( 'tr[title="' + 'Run '+ rename( evt.testName ) + ' test' + '"]' )[ 0 ]; 
     87                                row && row.onclick(); 
     88                        } ); 
     89 
     90                var profileFunction; 
     91                for( var test in testCase ) 
     92                { 
     93                        if ( typeof ( profileFunction = testCase[ test ] ) == 'function' ) 
     94                        { 
     95                                JSLitmus.test( rename( test ), profileFunction ); 
     96                        } 
     97                } 
     98        }, 
     99 
     100        /** 
    57101         * Gets the inner HTML of an element, for testing purposes. 
    58102         */ 
    59103        getInnerHtml : function( elementOrId ) 
© 2003 – 2012 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy