Update testkit files in wrt
authorwanmingx.lin <wanmingx.lin@intel.com>
Wed, 9 Oct 2013 09:41:57 +0000 (17:41 +0800)
committerwanmingx.lin <wanmingx.lin@intel.com>
Wed, 9 Oct 2013 09:41:57 +0000 (17:41 +0800)
Signed-off-by: wanmingx.lin <wanmingx.lin@intel.com>
98 files changed:
tct-ext01-wrt-tests/application-privilege/index.html
tct-ext01-wrt-tests/application-privilege/testrunner.js
tct-ext01-wrt-tests/metadata-support/index.html
tct-ext01-wrt-tests/metadata-support/testrunner.js
tct-ext01-wrt-tests/setting-install-location-auto/index.html
tct-ext01-wrt-tests/setting-install-location-auto/testrunner.js
tct-rt01-wrt-tests/dom-events-audio-onerror/index.html
tct-rt01-wrt-tests/dom-events-audio-onerror/testrunner.js
tct-rt01-wrt-tests/dom-events-video-onerror/index.html
tct-rt01-wrt-tests/dom-events-video-onerror/testrunner.js
tct-rt01-wrt-tests/lifecycle-hide-running-app/index.html
tct-rt01-wrt-tests/lifecycle-hide-running-app/testrunner.js
tct-rt01-wrt-tests/lifecycle-load-event/index.html
tct-rt01-wrt-tests/lifecycle-load-event/testrunner.js
tct-rt01-wrt-tests/other-uri-XMLHttpRequest-get-false/index.html
tct-rt01-wrt-tests/other-uri-XMLHttpRequest-get-false/testrunner.js
tct-rt01-wrt-tests/other-uri-XMLHttpRequest-get/index.html
tct-rt01-wrt-tests/other-uri-XMLHttpRequest-get/testrunner.js
tct-rt01-wrt-tests/other-uri-XMLHttpRequest-head-false/index.html
tct-rt01-wrt-tests/other-uri-XMLHttpRequest-head-false/testrunner.js
tct-rt01-wrt-tests/other-uri-XMLHttpRequest-head/index.html
tct-rt01-wrt-tests/other-uri-XMLHttpRequest-head/testrunner.js
tct-rt01-wrt-tests/other-uri-XMLHttpRequest-invalid/index.html
tct-rt01-wrt-tests/other-uri-XMLHttpRequest-invalid/testrunner.js
tct-rt01-wrt-tests/other-uri-XMLHttpRequest-null/index.html
tct-rt01-wrt-tests/other-uri-XMLHttpRequest-null/testrunner.js
tct-rt01-wrt-tests/other-uri-XMLHttpRequest-post-false/index.html
tct-rt01-wrt-tests/other-uri-XMLHttpRequest-post-false/testrunner.js
tct-rt01-wrt-tests/other-uri-XMLHttpRequest-post/index.html
tct-rt01-wrt-tests/other-uri-XMLHttpRequest-post/testrunner.js
tct-sp01-wrt-tests/protection-decrypt-css/index.html
tct-sp01-wrt-tests/protection-decrypt-css/testrunner.js
tct-sp01-wrt-tests/protection-decrypt-html/index.html
tct-sp01-wrt-tests/protection-decrypt-html/testrunner.js
tct-sp01-wrt-tests/protection-decrypt-js/index.html
tct-sp01-wrt-tests/protection-decrypt-js/testrunner.js
tct-sp01-wrt-tests/storage-cookies-check/index.html
tct-sp01-wrt-tests/storage-cookies-check/testrunner.js
tct-ui01-wrt-tests/multiple-other-alarm/testkit_index.html
tct-ui01-wrt-tests/multiple-other-alarm/testrunner.js
tct-ui01-wrt-tests/multiple-other-application-launch/testkit_index.html
tct-ui01-wrt-tests/multiple-other-application-launch/testrunner.js
tct-ui01-wrt-tests/multiple-other-application-read/testkit_index.html
tct-ui01-wrt-tests/multiple-other-application-read/testrunner.js
tct-ui01-wrt-tests/multiple-other-bluetooth-admin/testkit_index.html
tct-ui01-wrt-tests/multiple-other-bluetooth-admin/testrunner.js
tct-ui01-wrt-tests/multiple-other-bluetooth-gap/testkit_index.html
tct-ui01-wrt-tests/multiple-other-bluetooth-gap/testrunner.js
tct-ui01-wrt-tests/multiple-other-bluetooth-spp/testkit_index.html
tct-ui01-wrt-tests/multiple-other-bluetooth-spp/testrunner.js
tct-ui01-wrt-tests/multiple-other-calendar-read/testkit_index.html
tct-ui01-wrt-tests/multiple-other-calendar-read/testrunner.js
tct-ui01-wrt-tests/multiple-other-calendar-write/testkit_index.html
tct-ui01-wrt-tests/multiple-other-calendar-write/testrunner.js
tct-ui01-wrt-tests/multiple-other-callhistory-read/testkit_index.html
tct-ui01-wrt-tests/multiple-other-callhistory-read/testrunner.js
tct-ui01-wrt-tests/multiple-other-callhistory-write/testkit_index.html
tct-ui01-wrt-tests/multiple-other-callhistory-write/testrunner.js
tct-ui01-wrt-tests/multiple-other-contact-read/testkit_index.html
tct-ui01-wrt-tests/multiple-other-contact-read/testrunner.js
tct-ui01-wrt-tests/multiple-other-contact-write/testkit_index.html
tct-ui01-wrt-tests/multiple-other-contact-write/testrunner.js
tct-ui01-wrt-tests/multiple-other-content-read/testkit_index.html
tct-ui01-wrt-tests/multiple-other-content-read/testrunner.js
tct-ui01-wrt-tests/multiple-other-content-write/testkit_index.html
tct-ui01-wrt-tests/multiple-other-content-write/testrunner.js
tct-ui01-wrt-tests/multiple-other-download/testkit_index.html
tct-ui01-wrt-tests/multiple-other-download/testrunner.js
tct-ui01-wrt-tests/multiple-other-filesystem-read/testkit_index.html
tct-ui01-wrt-tests/multiple-other-filesystem-read/testrunner.js
tct-ui01-wrt-tests/multiple-other-filesystem-write/testkit_index.html
tct-ui01-wrt-tests/multiple-other-filesystem-write/testrunner.js
tct-ui01-wrt-tests/multiple-other-messaging-read/testkit_index.html
tct-ui01-wrt-tests/multiple-other-messaging-read/testrunner.js
tct-ui01-wrt-tests/multiple-other-messaging-send/testkit_index.html
tct-ui01-wrt-tests/multiple-other-messaging-send/testrunner.js
tct-ui01-wrt-tests/multiple-other-messaging-write/testkit_index.html
tct-ui01-wrt-tests/multiple-other-messaging-write/testrunner.js
tct-ui01-wrt-tests/multiple-other-nfc-admin/testkit_index.html
tct-ui01-wrt-tests/multiple-other-nfc-admin/testrunner.js
tct-ui01-wrt-tests/multiple-other-nfc-common/testkit_index.html
tct-ui01-wrt-tests/multiple-other-nfc-common/testrunner.js
tct-ui01-wrt-tests/multiple-other-nfc-p2p/testkit_index.html
tct-ui01-wrt-tests/multiple-other-nfc-p2p/testrunner.js
tct-ui01-wrt-tests/multiple-other-nfc-tag/testkit_index.html
tct-ui01-wrt-tests/multiple-other-nfc-tag/testrunner.js
tct-ui01-wrt-tests/multiple-other-notification/testkit_index.html
tct-ui01-wrt-tests/multiple-other-notification/testrunner.js
tct-ui01-wrt-tests/multiple-other-power/testkit_index.html
tct-ui01-wrt-tests/multiple-other-power/testrunner.js
tct-ui01-wrt-tests/multiple-other-systeminfo/testkit_index.html
tct-ui01-wrt-tests/multiple-other-systeminfo/testrunner.js
tct-ui01-wrt-tests/multiple-other-systemsetting/testkit_index.html
tct-ui01-wrt-tests/multiple-other-systemsetting/testrunner.js
tct-ui01-wrt-tests/multiple-other-time/testkit_index.html
tct-ui01-wrt-tests/multiple-other-time/testrunner.js
tct-ui01-wrt-tests/multiple-other-tizen/testkit_index.html
tct-ui01-wrt-tests/multiple-other-tizen/testrunner.js

index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);
index e527416703b52518a38942fbcae374081ac307b5..8728bea4559fde8a4050383a379800254d8b4b35 100644 (file)
 <meta name="viewport" content="width=device-width">
 <script src="jquery-1.10.2.min.js"></script>
 <style type="text/css">
-html {
-       font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
-}
-
-table#browse {
-       border-collapse:collapse;
-       table-layout:fixed;width:80%;
-}
-
-table#browse th:first-child,table#browse td:first-child {width:40%;}
-
-table#browse th:last-child,table#browse td:last-child {width:30%;}
-
-table#browse th {
-       padding:0;
-       padding-bottom:0.5em;
-       text-align:left;
-       border-bottom:medium solid black;
-}
-table#browse td {
-       padding:1em;
-       padding-bottom:0.5em;
-       border-bottom:thin solid black;
-}
-div#navbar{
+div#navbar,#footbar{
        box-sizing: border-box;
        width: 99%;
        border: 0px;
@@ -54,79 +30,45 @@ div#navbar{
        background: teal;
        color: white;
 }
-div#footbar{
-       width: 99%;
-       border: 0px;
-       text-align: left;
-}
+
 textarea#testinfo{
        width: 99%;
-       font-size: 0.8em;
-}
-input,select{
-       font-size: 1.2em;
-       padding-top: 0.1em;
-       padding-bottom: 0.1em;
-}
-Label {
-       font-size: 1em;
-}
-#btnPrev,#btnNext{
-       width: 8%;
-}
-#btnDone,#btnRun,#btnList,#btnPass,#btnFail,#btnBlock{
-       width: 12%;
-}
-#btnPass { color: green;}
-#btnFail { color: red;}
-#btnBlock { color: orange;}
-#labBatch{
-       font-size: 0.5em;
-}
-#textTest {
-       width: 60%;
+       font-size: 14px;
 }
 
-#frmTest {
-       border: none;
+input,label,select{
+       font-size: 14px;
 }
-.singlemode { display: none;}
-.short{
-       padding-left: 0.8em;
+
+span.short{
+       padding-left: 10px;
 }
-.
-.long{
-       padding-left: 2em;
+
+span.long{
+       padding-left: 60px;
 }
 </style>
 </head>
 
 <body>
-<div id="navbar" class="batchmode">
-       <span class="short"><input type="button" id="btnList" value="List"/></span>
-       <span class="singlemode short">
-               <input type="button" id="btnPrev" value="<"/>
-               <input type="text"  id="textTest" readonly />
-               <input type="button" id="btnNext" value=">"/> 
-       </span>
-       <span class="listmode long">
-               <input type="button" id="btnDone" value="Exit"/>
-       </span>
+<div id="navbar">
+       <span class="short"><input type="button" style="width:8%" id="btnPrev" value="< Prev"/></span>
+       <select id="selTestlist" style="width:60%"> </select>
+       <input type="button" style="width:8%" id="btnNext" value="Next >"/>
+       <input type="checkbox" name="manualonly" id="chkManualonly"/><label for="chkManualonly">Manual-Only</label>
 </div>
-<div id="divSum"> </div>
-<div width="99%" class="singlemode">
-       <textarea class="batchmode" id="testinfo" rows=4 disabled>
+<div width="99%">
+       <textarea id="testinfo" rows=8 disabled>
        </textarea>
 </div>
-<div id="footbar" class="batchmode">
-       <span class="short"><input type="button"  id="btnRun" value="Run"/></span>
-       <span class="short singlemode">
-               <input  type="button" id="btnPass" value="PASS"/>
-               <input  type="button" id="btnFail" value="FAIL"/>
-               <input  type="button" id="btnBlock" value="BLOCK"/>
-       </span>
+<div id="footbar">
+       <span class="short"><input type="button" style="width:8%" id="btnDone" value="Done"/></span>
+       <span class="short"><input type="radio" name="result" id="radPass" value="PASS"/><label for="radPass">Pass</label></span>
+       <span class="short"><input type="radio" name="result" id="radFail" value="FAIL"/><label for="radFail">Fail</label></span>
+       <span class="long"><input type="button" style="width:8%" id="btnRun" value="Run"/></span>
+       <input type="checkbox" name="batch" id="chkBatch"/><label for="chkBatch">Batch</label>
 </div>
-<iframe width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
+<iframe frameborder="1" width="100%" id="frmTest" allowFullScreen="true" mozAllowFullScreen="true" webkitAllowFullscreen="true" src="">
 </iframe>
 <script src="testrunner.js"> </script>
 </body>
index 46eacf486b1745f3643e0ee5a599126351516535..6901cbf028fde51d44dafe80c116a822279365cc 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #
 */
+
 (function (window){
        function TestRunner() {
                this.start = null;
-               this.ui = null;
                this.submitResult = null;
+               this.ui = null;
                this.report = function (result, message) {};
                this.doTest = function () {};
+               this.internal = {};
        }
 
        TestRunner.prototype = (function () {
                var index = -1;
+               var autoflag = false;
                var Tests = [];
-               var Sets =  {};
-               function newSummary() {
-                       return {"TOTAL": 0,
-                               "PASS" : 0,
-                               "FAIL" : 0,
-                               "BLOCK" : 0,
-                               "NOTRUN" : 0};
-               }
-               function newTestContext() {
-                       return {start_time: null,
-                               prev_uri: "",
-                               uri: "",
-                               sub_index: 0,
-                               onload_delay: 0
-                       };
-               }
-               var sum = newSummary();
-               var testContext =  newTestContext();
+               var sum = {"TOTAL": 0,
+                         "PASS" : 0,
+                         "FAIL" : 0,
+                         "BLOCK" : 0,
+                         "NOTRUN" : 0
+               };
+               var testContext =  {
+                       start_time: null,
+                       prev_uri: "",
+                       uri: "",
+                       sub_index: 0,
+                       onload_delay: 0
+               };
                return { 
                        constructor: TestRunner,
-                       options:  {},
                        getTestContext: function (field) {
                                return testContext[field];
                        },
 
+                       cleanTests: function () {
+                               Tests = [];
+                       },
+
                        goNext: function () {
-                               if (Tests.length === 0) return false;
-                               if (index >= Tests.length) {
-                                       index = -1;
-                                       return false;
-                               }
                                index++;
-                               return true;
-                       },
-       
-                       goPrev: function () {
-                               if (Tests.length === 0) return false;
-                               if (index < 0) {
-                                       index = Tests.length;
-                                       return false;
-                               }
-                               index--;
-                               return true;
                        },
 
-                       runAll: function () {
-                               testContext = newTestContext();
-                               this.ui.updateView(VIEWFLAGS.add("batch"));
-                               this.ui.updateView(VIEWFLAGS.del("list"));
-                               this.testIndex(-1);     
-                               this.doTest();
-                       },
-       
-                       cleanTests: function () {
-                               Tests = [];
+                       getTestIndex: function () {
+                               return index;
                        },
 
-                       testIndex: function (ind) {
-                               if (typeof ind === "undefined")
-                                       return index;
+                       setTestIndex: function (ind) {
                                index = ind;
                        },
 
                        },
 
                        addTest: function (test) {
-                               if (test instanceof Array)
-                                       Tests = Tests.concat(test);
-                               else
-                                       Tests.push(test);
+                               Tests.push(test);
+                       },
+
+                       getTestLength: function () {
+                               if (Tests === null)
+                                       return 0;
+                               return Tests.length;
                        },
 
                        sumInit: function (num) {
                                if (typeof num === "undefined")
                                        num = Tests.length;
-                               sum.TOTAL = sum.NOTRUN = num;
-                               sum.PASS = sum.FAIL = sum.BLOCK = 0;
+                               sum["TOTAL"] = sum["NOTRUN"] = num;
+                               sum["PASS"] = sum["FAIL"] = sum["BLOCK"] = 0;
                        },
                        
-                       sumUpdate: function (oldRes, newRes, set) {
-                               if (oldRes !== null) {
+                       sumUpdate: function (oldRes, newRes) {
+                               if (oldRes !== null)
                                        sum[oldRes]--;
-                                       if (set !== null) Sets[set][oldRes]--;
-                               }
-                               if (newRes !== null) {
+                               if (newRes !== null)
                                        sum[newRes]++;
-                                       if (set != null) Sets[set][newRes]++;
-                               }
                        },
 
-                       checkResult: function (oTestDoc) {
+                       checkResult: function () {
                                var message = "";
+                               var oTestDoc = this.ui.getTestfrmDoc();
                                // Handle sub-index test
                                if (testContext.sub_index > 0) {
                                        var oRes = $(oTestDoc).find("table#results");
                                                return false;
                                        var ind = testContext.sub_index - 1;
                                        var $n = $(oRes).find('tbody > tr').eq(ind);
-                                       if ($n.length == 0)
-                                               return false
-                                       var result = $n.children("td:eq(0)").text();
-                                       message = $n.children("td:eq(2)").text();
-                                       this.report(result.toUpperCase(), message);
+                                       if ($n.length > 0) {
+                                               var result = $n.children("td:eq(0)").text();
+                                               message = $n.children("td:eq(2)").text();
+                                               if (result)
+                                                       this.report(result.toUpperCase(), message);
+                                       } else
+                                               this.report('FAIL', 'Not found test');
                                        return true;
                                }
 
                                return false;
                        },
 
-                       testInfo: function (ind) {
+                       testinfo: function () {
                                var info = "";
+                               for (var n in sum)
+                                       info += n + ":" + sum[n] + "  ";
                                var tc = this.getTest();
-                               if (!tc) return info;
-                               info += "Test   : (" + (index + 1) + "/" + sum.TOTAL + ") ";
-                               info += tc.test_script_entry;
-                               info += "\nPurpose: " +  tc.purpose;
+                               info += "\n\nTest\t: " + tc.test_script_entry;
+                               info += "\nPurpose\t: " +  tc.purpose;
                                if (tc.pre_condition)
                                        info += "\nPrecondition: " + tc.pre_condition;
                                if (tc.steps)
                                return info;
                        },
 
-                       getTestCaseUrl: function () {
+                       getTestCase: function (name, ind) {
+                               if (ind === null)
+                                       ind = this.getTestIndex();
+                               var tc = this.getTest(ind);
+                               return tc[name];
+                       },
+
+                       getTestCase: function () {
                                function getUriField(uri, param) {
                                        var querys = uri.split("?")
                                        if (querys.length <= 1)
                                                return "";
-                                       uri = querys[1];
                                        var start = uri.indexOf(param);
                                        if (start == -1)
                                                return "";
                                        return uri.substring(start, end);
                                }
                                var tc = this.getTest();
-                               if (!tc) return null;
                                var delay = tc.onload_delay;
                                if (delay)
                                        testContext.onload_delay = parseInt(delay) * 1000;
                                        testContext.onload_delay = 5000;
 
                                var uri = tc.test_script_entry;
-                               if (typeof this.options.testprefix !== "undefined") {
-                                       var pos = uri.indexOf('http://');
-                                       if (pos !== 0)
-                                               uri = this.options.testprefix + uri
-                               }
                                var val = getUriField(uri, "value");
-                               if (val && tc.execution_type == "auto" && VIEWFLAGS.has("batch")) { // Need sub index in TC
+                               if (val && tc.execution_type == "auto") { // Need sub index in TC
                                        testContext.sub_index = parseInt(val);
                                        testContext.uri = uri.split("?")[0];
-                                       if (testContext.uri == testContext.prev_uri)
+                                       if (testContext.uri == testContext.prev_uri) {
+                                               this.load_ready();
                                                return "";
+                                       }
                                } else {
                                        testContext.uri = uri;
                                        testContext.sub_index = 0;
                                return testContext.uri;
                        },
 
-                       loadReady: function () {
-                               if (!VIEWFLAGS.has("batch"))
+                       load_ready: function () {
+                               if (!autoflag)
                                        return;
-                               if (!this.ui.testComplete()){
+                               if (!this.checkResult()){
                                        if (testContext.onload_delay > 0){
                                                var tval = 500;
                                                var self = this;
-                                               setTimeout(function() {self.loadReady();}, tval);
+                                               setTimeout(function() {self.load_ready();}, tval);
                                                testContext.onload_delay -= tval;
                                                return
                                        }
                                this.doTest();
                        },
 
-                       getTestSum: function (include_set) {
-                               var sumdata = "<section><h3>Total:" + sum.TOTAL
-                                               + " Pass:<span style='color:green;'>" + sum.PASS
-                                               + "</span> Fail:<span style='color:red;'>" + sum.FAIL
-                                               + "</span> Block:<span style='color:orange;'>" + sum.BLOCK
-                                               + "</span> NotRun:<span style='color:black;'>" + sum.NOTRUN
-                                               + "</span></h3></section>";
-                               if (VIEWFLAGS.has("batch")) {
-                                       var tc = this.getTest();
-                                       if (tc) sumdata += "<h4><span style='background-color: wheat'>(#" + index + ") " + tc.id + "</span></h4>";
-                               }
-
-                               if (include_set) {
-                                       sumdata += "<p><table id='browse'><tr><th>TestSet</th>";
-                                       sumdata += "<th>Total</th><th>Pass</th><th>Fail</th><th>Block</th></tr>";
-                                       $.each(Sets, function (key, val){
-                                               sumdata += "<tr><td>" + key+ "</td>";
-                                               sumdata += "<td style='color:black;'>" + val.TOTAL + "</td>";
-                                               sumdata += "<td style='color:green;'>" + val.PASS + "</td>";
-                                               sumdata += "<td style='color:red;'>" + val.FAIL + "</td>";
-                                               sumdata += "<td style='color:orange;'>" + val.BLOCK + "</td></tr>";
-                                       });
-                                       sumdata += "</table>";
-                               }
-                               return sumdata;
+                       setAutomode: function (flag) {
+                               if (this.ui)
+                                       this.ui.setAutotestView(flag);
+                               autoflag = flag;
                        },
 
-                       getBrowseInfo: function () {
-                               var failList = passList = blockList = notrunList = "";
-                               function createTestList(tc, color, ind) {
-                                       var mtag = (tc.execution_type === "manual") ? "(M)" : ""; 
-                                       return "<li>" + mtag + "<a rel='" + ind + "' href='' style ='color:" + color + ";'>" + tc.id + "</a>" + "</li>";
-                               }
-                               Sets = {};
-                               $.each(Tests, function (ind ,val) {
-                                       if (this.set === null)
-                                               this.set = "default";
-                                       if (typeof Sets[this.set] === "undefined")
-                                               Sets[this.set] = newSummary(); 
-                                       Sets[this.set][this.result]++;
-                                       Sets[this.set]["TOTAL"]++;
-                                       if (this.result == "FAIL")
-                                               failList += createTestList(this, "red", ind);
-                                       if (this.result == "PASS")
-                                               passList += createTestList(this, "green", ind);
-                                       if (this.result == "BLOCK")
-                                               blockList += createTestList(this, "orange", ind);
-                                       if (this.result == "NOTRUN")
-                                               notrunList += createTestList(this, "black", ind);
-                               });
-                               var data = "<html><head><style>ul li {padding-bottom:0.8em;font-size: 1.3em;}";
-                               data += "html{font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;}</style></head><body>";
-                               if (notrunList)
-                                       data += "<section><h3>NotRuns</h3><ul>" + notrunList + "</ul></section>";
-                               if (failList)
-                                       data += "<section><h3>Fails</h3><ul>" + failList + "</ul></section>";
-                               if (blockList)
-                                       data += "<section><h3>Blocks</h3><ul>" + blockList + "</ul></section>";
-                               if (passList)
-                                       data += "<section><h3>Passes</h3><ul>" + passList + "</ul></section>";
-                               data += "</body></html>";
-                               return data;
+                       autoTest: function () {
+                               index = -1;
+                               this.setAutomode(true);
+                               this.doTest();
                        },
 
                        TestCase: function() {
                                        execution_type: "manual",
                                        result: "NOTRUN",
                                        purpose: "",
-                                       set: null,
                                        pre_condition: "",
                                        onload_delay: 0,
                                        steps: "",
        var master_runner = new TestRunner();
        master_runner.start = function (ui) {
                function filter(xml, self) {
-                       var set_ind = 0;
-                       var manuals = [];
-                       $(xml).find("set").each(function () {
-                               var setname = $(this).attr("name");
-                               if (!setname)
-                                       setname = "set" + set_ind;
-                               $(this).find("testcase").each(function () {
-                                       var v = $(this).attr('execution_type');
-                                       if (self.options.execution_type && v != self.options.execution_type
-                                                       && $.inArray(v, self.options.execution_type) < 0) {
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       v = $(this).attr('priority');
-                                       if (self.options.priority && v != self.options.priority
-                                                       && $.inArray(v, self.options.priority) < 0){
-                                               $(this).remove();
-                                               return;
-                                       }
-                                       var test = self.TestCase();
-                                       test.id = $(this).attr("id");
-                                       test.execution_type = $(this).attr("execution_type");
-                                       test.test_script_entry = $(this).find("test_script_entry").text();
-                                       test.purpose = $(this).attr("purpose");
-                                       test.pre_condition = $(this).find("pre_condition").text();
-                                       test.onload_delay = $(this).attr("onload_delay");
-                                       test.result = "NOTRUN";
-                                       test.set = setname;
-                                       test.data = this;
-                                       if (test.execution_type === "auto")
-                                               self.addTest(test);
-                                       else
-                                               manuals.push(test);
-                               });
-                               set_ind++;
+                       $(xml).find("testcase").each(function() {
+                               var v = $(this).attr('execution_type');
+                               if (parms.execution_type && v != parms.execution_type
+                                               && $.inArray(v, parms.execution_type) < 0) {
+                                       $(this).remove();
+                                       return;
+                               }
+                               v = $(this).attr('priority');
+                               if (parms.priority && v != parms.priority
+                                               && $.inArray(v, parms.priority) < 0){
+                                       $(this).remove();
+                                       return;
+                               }
+                               var test = self.TestCase();
+                               test.id = $(this).attr("id");
+                               test.execution_type = $(this).attr("execution_type");
+                               test.test_script_entry = $(this).find("test_script_entry").text();
+                               test.purpose = $(this).attr("purpose");
+                               test.pre_condition = $(this).find("pre_condition").text();
+                               test.onload_delay = $(this).attr("onload_delay");
+                               test.result = "NOTRUN";
+                               test.data = this;
+                               self.addTest(test);
                        });
-                       self.addTest(manuals);
                }
 
                function getParms() {
 
                var self = this;
                ui.bind(self);
-               self.options = getParms();
-               $.get(self.options.testsuite, null, function (xml) {
-                       self.internal.xmldoc = xml;
-                       filter(xml, self);
-                       self.sumInit();
-                       setTimeout(function () {
-                               self.ui.browse();
-                               setTimeout(function () {
-                                       if (self.options.autorun)
-                                               self.runAll();
-                               }, 2000);
-                       }, 100);
-               }, "xml");
+               var parms = getParms();
+               $.get(parms.testsuite, null, function (xml) {
+                               self.internal.xmldoc = xml;
+                               filter(xml, self);
+                               self.sumInit();
+                               self.ui.updateList();
+                               if (parms.hasOwnProperty("autorun"))
+                                       self.autoTest();
+                       }, "xml");
        };
 
        master_runner.doTest = function () {
-               var self = this, tc = null;
-               while (self.goNext()) {
-                       tc = self.getTest();
-                       if (!tc || tc.execution_type === "manual")
-                               break;
-                       self.ui.updateTestInfo(self.testInfo(), null, null);
-                       self.ui.runTest(self.getTestCaseUrl());
-                       return;
-               }
-               if (self.options.autorun) {
-                       self.submitResult();
-                       close_window();
-                       return;
-               }
-               this.ui.updateView(VIEWFLAGS.del("batch"));
-               if (!tc) {
-                       setTimeout(function () {self.ui.browse();}, 500);
+               var self = this, tc;
+               self.goNext();
+               while ((tc = self.getTest())) {
+                       if (tc.execution_type != 'auto') {
+                               self.goNext();
+                               continue;
+                       }
+                       self.ui.updateTestInfo(self.testinfo());
+                       self.ui.runTest(self.getTestCase());
                        return;
                }
-               this.ui.updateTest();   
+               self.ui.updateList();
+               this.setAutomode(false);
+               setTimeout(function () {self.submitResult();}, 2000);
        };
 
        master_runner.report = function (result, log) {
                var tc = this.getTest();
-               if (!tc) return;
                var oldresult = tc.result;
-               this.sumUpdate(oldresult, result, tc.set);
+               this.sumUpdate(oldresult, result);
                tc.result = result;
                $(tc.data).find('result_info').remove();
                $(tc.data).attr('result', result);
                                   "</start><end>" + new Date() + "</end><stdout>" +
                                   escape_html(log) + "</stdout></result_info>");
                $(tc.data).append(doc.documentElement);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.ui.updateResult(result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        master_runner.submitResult = function () {
                var xmldoc = this.internal.xmldoc;
-               var contents = (new XMLSerializer()).serializeToString(xmldoc);
-               if (window.opener) window.opener.postMessage(contents, "*");
+               var data = "<title>Test Result</title><head>";
+               data += "<link rel='stylesheet' type='text/css' href='report.css'>";
+               data += "</head><body><section id='summary'><h2>Summary</h2>";
+               var failList = $(xmldoc).find("testcase[result='FAIL']");
+               var blockList = $(xmldoc).find("testcase[result='BLOCK']");
+               var ipassList = $(xmldoc).find("testcase[result='PASS']");
+               var ifail, iblock;
+               data += "<h3>Total:" + this.getTestLength()
+                               + " Pass:<span style='color:green;'>" + ipassList.length
+                               + "</span> Fail:<span style='color:red;'>" + failList.length
+                               + "</span> Block:<span style='color:orange;'>" + blockList.length
+                               + "</span></h3></section>";
+
+               data += "<p><table id='results'><tr><th>TestSet</th>";
+               data += "<th>Pass</th><th>Fail</th><th>Block</th></tr>";
+               $(xmldoc).find("set").each(function (){
+                       ipass = $(this).find("testcase[result='PASS']").length;
+                       ifail = $(this).find("testcase[result='FAIL']").length;
+                       iblock = $(this).find("testcase[result='BLOCK']").length;
+                       data += "<tr><td>" + $(this).attr('name') + "</td>";
+                       data += "<td style='color:green;'>" + ipass + "</td>";
+                       data += "<td style='color:red;'>" + ifail + "</td>";
+                       data += "<td style='color:orange;'>" + iblock + "</td></tr>";
+               });
+               data += "</table>";
+
+               function appendList(list, title, color) {
+                       data += "<section><h2>" + title + "</h2>";
+                       $(list).each(function() {
+                               var url = $(this).find("test_script_entry").text();
+                               data += "<ul><li><a href='" + url + "' style ='color:" + color + ";'>" + url + "</a></li></ul>";
+                       });
+                       data += "</section>";
+               }
+
+               if (failList.length > 0)
+                       appendList(failList, "Fails", "red");
+
+               if (blockList.length > 0)
+                       appendList(blockList, "Blocks", "orange");
+
+               var tdoc = this.ui.getTestfrmDoc();
+               tdoc.open("text/html", "replace");
+               tdoc.writeln(data);
        };
 
        master_runner.internal = {xmldoc: null};
                if (!next_step || next_step.step != "continue")
                         return false;
                ui.bind(self);
+               self.ui.updateTestInfo("Connecting server...");
                var f = function () {
                        var p = self.internal.get_json("check_execution_progress");
-                       if (p) self.sumInit(parseInt(p.total));
+                       if (p)
+                               self.sumInit(parseInt(p.total));
                        self.doTest();
                };
-               self.ui.updateView(VIEWFLAGS.add("batch"));
-               self.ui.updateView(VIEWFLAGS.del("list"));
-               setTimeout(f, 1000);
+               self.setAutomode(true);
+               setTimeout(f, 2000);
                return true;
        };
 
        slave_runner.doTest = function () {
                var self = this;
                if (self.internal.stage > 0) {
-                       self.ui.updateView(VIEWFLAGS.del("batch"));
-                       self.goNext();
-                       self.ui.updateTest();
+                       self.setAutomode(false);
                        return;
                }
                var next_step = self.internal.get_json("ask_next_step");
                        var task = self.internal.get_json("auto_test_task");
                        if (task === null) {
                                print_error("ask_test_task", "Fail get task");
-                       } else if (task.invalid === 0) {
+                       } else if (task.invalid == 0) {
                                print_error("ask_test_task", "Invalid session");
-                       } else if (task.stop === 0) {
+                       } else if (task.stop == 0) {
                                print_error("ask_test_task", "close window");
-                       } else if (task.none !== 0) { //handle auto test
+                       } else if (task.none != 0) { //handle auto test
                                var test = self.TestCase();
                                test.id = task.case_id;
                                test.onload_delay = task.onload_delay;
                                test.test_script_entry = task.entry;
-                               test.execution_type = "auto";
                                test.purpose = task.purpose;
                                test.pre_condition = task.pre_condition;
+                               self.cleanTests();
                                self.addTest(test);
-                               self.goNext();
-                               self.ui.updateTestInfo(self.testInfo(), null, null);
-                               self.ui.runTest(self.getTestCaseUrl());
+                               self.setTestIndex(0);
+                               self.ui.runTest(self.getTestCase());
                                return;
                        } else {  //handle manual test
-                               self.ui.updateView(VIEWFLAGS.del("batch"));
+                               self.setAutomode(false);
                                self.internal.stage = 1;
                                var mtask = self.internal.get_json("manual_cases");
-                               if (mtask && mtask.none != 0) {
+                               if (mtask && mtask.none !=0) {
                                        self.cleanTests();
                                        for (var i = 0, max = mtask.length; i < max; i++) {
                                                var test = self.TestCase();
                                                test.purpose = mtask[i].purpose;
                                                test.pre_condition = mtask[i].pre_condition;
                                                test.result = "NOTRUN";
-                                               test.execution_type = "manual";
-                                               test.index = i;
                                                var steps = "";
                                                $(mtask[i].steps).each(function () {
                                                        steps += "Step-" + this.order + "\t: " + this.step_desc + "\n";
                                                test.steps = steps;
                                                self.addTest(test);
                                        }
-                                       self.ui.updateTest(-1);
+                                       self.ui.updateList();
                                        self.sumInit();
-                                       self.ui.browse();
                                } else
                                        close_window();
                                return;
                                {"case_id": tc.id, "result": result});
                        oldresult = tc.result
                        tc.result = result;
+                       this.ui.updateResult(result);
                } else {
                        this.internal.post_json("commit_result",
                                { "case_id" : tc.id,
                                  "session_id" : this.internal.session_id});
                        oldresult = "NOTRUN";
                }
-               this.sumUpdate(oldresult, result, null);
-               if (VIEWFLAGS.has("batch")) result = null;
-               this.ui.updateTestInfo(null, this.getTestSum(false), result);
+               this.sumUpdate(oldresult, result);
+               this.ui.updateTestInfo(this.testinfo());
        };
 
        slave_runner.submitResult = function () {
                $.get(SERVER + "/generate_xml");
+               close_window();
        };
 
        slave_runner.internal = {
        var i_ui = (function () {
                var testinfo = $("#testinfo").get(0);
                var frmTest = $("#frmTest").get(0);
-               var textTest  = $("#textTest").get(0);
-               var btnPass = $("#btnPass").get(0);
-               var btnFail = $("#btnFail").get(0);
-               var btnBlock = $("#btnBlock").get(0);
+               var selTestlist  = $("#selTestlist").get(0);
+               var radPass = $("#radPass").get(0);
+               var radFail = $("#radFail").get(0);
                var btnDone = $("#btnDone").get(0);
                var btnNext = $("#btnNext").get(0);
                var btnPrev = $("#btnPrev").get(0);
                var btnRun      = $("#btnRun").get(0);
-               var divSum = $("#divSum").get(0);
-               var btnList = $("#btnList").get(0);
+               var divNav      = $("#navbar").get(0);
+               var divFoot = $("#footbar").get(0);
+               var chkBatch = $("#chkBatch").get(0);
+               var chkManualonly = $("#chkManualonly").get(0);
                var runner = null;
-               var listmode = null;
                var nextTest = function () {
-                       runner.goNext();
-                       selectTest();
+                       if (selTestlist.selectedIndex >= (selTestlist.options.length - 1))
+                               selTestlist.selectedIndex = 0;
+                       else
+                               selTestlist.selectedIndex++;
+                       selectTest.call(selTestlist);
                };
 
                var prevTest = function() {
-                       runner.goPrev();
-                       selectTest();
+                       if (selTestlist.selectedIndex <= 0)
+                               selTestlist.selectedIndex = selTestlist.options.length - 1;
+                       else
+                               selTestlist.selectedIndex--;
+                       selectTest.call(selTestlist);
                };
 
                var selectResult = function() {
                };
 
                var selectTest = function () {
-                       frmTest.src = "";
-                       var tc = runner.getTest();
-                       if (!tc) {
-                               if (runner.testIndex() === -1)
-                                       textTest.value = "---Begin---";
-                               else
-                                       textTest.value = "---End---";
-                               changeColor("NOTRUN");
-                               return;
+                       var opt = this.options[this.selectedIndex];
+                       runner.setTestIndex(parseInt(opt.value));
+                       var result = runner.getTest().result;
+                       if (result == "PASS"){
+                               radPass.checked = true;
+                       } else if (result == "FAIL"){
+                               radFail.checked = true;
+                       } else {
+                               radPass.checked = false;
+                               radFail.checked = false;
                        }
-                       testinfo.value = runner.testInfo();
-                       $(divSum).html(runner.getTestSum(false));
-                       textTest.value = ((tc.execution_type === "manual") ? "(M)" : "") + tc.id;
-                       changeColor(tc.result);
+                       frmTest.src = "";
+                       testinfo.value = runner.testinfo();
                };
 
-               function changeColor(result) {
-                       if (result === "PASS")
-                               $(textTest).css("backgroundColor", "lightgreen");
-                       else if (result === "FAIL")
-                               $(textTest).css("backgroundColor", "tomato");
-                       else if (result === "BLOCK")
-                               $(textTest).css("backgroundColor", "yellow");
-                       else
-                               $(textTest).css("backgroundColor", "white");
-               }
+               var changeOptColor = function (result, opt) {
+                       if (result == "PASS")
+                               $(opt).css("backgroundColor", "greenyellow");
+                       else if ($.inArray(result, ["FAIL", "BLOCK"]) > -1)
+                               $(opt).css("backgroundColor", "orangered");
+               };
 
                return {
                        bind: function (r) {
                                var self = this;
                                r.ui = self;
                                runner = r;
-                               $(btnPass).on("click", selectResult);
-                               $(btnFail).on("click", selectResult);
-                               $(btnBlock).on("click", selectResult);
+                               $(radPass).on("click", selectResult);
+                               $(radFail).on("click", selectResult);
                                $(btnNext).on("click", nextTest);
                                $(btnPrev).on("click", prevTest);
                                $(btnRun).on("click",  function () {
-                                       if (VIEWFLAGS.has("list")) {
-                                               runner.runAll();
-                                       } else 
-                                               self.runTest(runner.getTestCaseUrl());
+                                       if (chkBatch.checked && !chkManualonly.checked)
+                                               runner.autoTest();
+                                       else {
+                                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                                               runner.setTestIndex(parseInt(opt.value));
+                                               self.runTest(runner.getTestCase());
+                                       }
                                });
-                               $(frmTest).on("load",  function () {runner.loadReady();});
+                               $(frmTest).on("load",  function () {runner.load_ready();});
                                $(btnDone).on("click", function () {
-                                       runner.submitResult();
-                                       close_window();
-                               });
-                               $(btnList).on("click", function () {
-                                       frmTest.src = "";
-                                       self.updateTest(-1);
-                                       setTimeout(function () {self.browse();}, 300);
+                                       setTimeout(function () {runner.submitResult();}, 300);
+                                       frmTest.src = "";});
+                               $(chkManualonly).on("click", function () {
+                                       chkBatch.disabled = this.checked;
+                                       chkBatch.checked = false;
+                                       self.updateList();
                                });
                                frmTest.height = $(window).height();
                        },
-               
-                       browse: function () {
-                               var tdoc = frmTest.contentWindow.document;
-                               tdoc.open("text/html", "replace");
-                               tdoc.writeln(runner.getBrowseInfo());
-                               var self = this;
-                               $(tdoc).find("section ul li>a").on("click", function (e) {
-                                       var ind = parseInt($(this).attr("rel"));
-                                       self.updateView(VIEWFLAGS.del("list")); 
-                                       self.updateTest(ind);
-                                       window.scrollTo(0, 0);
-                                       e.preventDefault();
-                               });
-                               $(divSum).html(runner.getTestSum(true));
-                               self.updateView(VIEWFLAGS.add("list")); 
-                       },
-       
-                       updateTest: function (ind) {
-                               if (typeof ind !== "undefined") runner.testIndex(ind);
-                               selectTest();
-                       },
 
-                       updateView: function (flags) {
-                               if (flags & VIEWFLAGS.flags.list) {
-                                       $(".listmode").show();
-                                       $(".singlemode").hide();
+                       setAutotestView: function (autoflag) {
+                               if (autoflag){
+                                       $(divNav).hide();
+                                       $(divFoot).hide();
                                } else {
-                                       $(".listmode").hide();
-                                       $(".singlemode").show();
+                                       $(divNav).show();
+                                       $(divFoot).show();
+                                       frmTest.src = "";
                                }
-                               if (flags & VIEWFLAGS.flags.batch)
-                                       $(".batchmode").hide();
-                               else
-                                       $(".batchmode").show();
                        },
 
-                       testComplete: function () {
-                               return runner.checkResult(frmTest.contentWindow.document);
+                       getTestfrmDoc: function () {
+                               return frmTest.contentWindow.document;
                        },
+                  
                        runTest: function (uri) {
-                               if (uri === null) return;
                                if (uri)
                                        frmTest.src = uri;
-                               else
-                                       runner.loadReady();
-                               
                        },
 
-                       updateTestInfo: function (info, sum, result) {
-                               if (info !== null)
-                                       testinfo.value = info;
-                               if (sum !== null)
-                                       $(divSum).html(sum);
-                               if (result !== null)
-                                       changeColor(result);
+                       updateList: function (){
+                               var item;
+                               selTestlist.options.length = 0;
+                               for(var i = 0, max = runner.getTestLength(); i < max; i++){
+                                       var tc = runner.getTest(i);
+                                       if (chkManualonly.checked && tc.execution_type=="auto")
+                                               continue;
+                                       if (tc.id.length > 32) {
+                                               var prefix = tc.id.substring(0, 9);
+                                               var postfix = tc.id.substring(15);
+                                               item = new Option(prefix + " ... " + postfix, i);
+                                       } else
+                                               item = new Option(tc.id, i);
+                                       selTestlist.options.add(item);
+                                       changeOptColor(tc.result, item);
+                               }
+                               $(selTestlist).on("change",  selectTest);
+                               selectTest.call(selTestlist);
+                       },
+
+                       updateResult: function (result) {
+                               var opt = selTestlist.options[selTestlist.selectedIndex];
+                               changeOptColor(result, opt);
                        },
+
+                       updateTestInfo: function (info) {
+                          testinfo.value = info;
+                       }
           };
        } ());
 
                        master_runner.start(i_ui);
        }
        var SERVER = "http://127.0.0.1:8000";
-       var VIEWFLAGS = { val: 0,
-               flags: {list: 1, batch: 2},
-               add: function (f) { this.val |= this.flags[f]; return this.val},
-               del: function (f) { this.val &= ~this.flags[f]; return this.val},
-               has: function (f) { return this.val & this.flags[f];},
-       };
        $.ajaxSetup({ async: false});
        $(window).on("ready", pre_init);
 })(window);