UnitTC: Pass,error count save method has been changed
[platform/framework/web/web-ui-fw.git] / tests / jqm-tchelper / tizen.testHelper.js
1 /*
2  *      Goal
3  *              - Run button/index.html -> buttonMarkup/index.html automatically in one browser
4  *              - Summarize result of each test suite
5  *                      - pass current summary data by GET variables
6  *                      - Get current summary data by parsing URL to get those GET variables
7  *
8  *      Issues
9  *              - Some testcases may change URL during test
10  *      It is a not complete versionc. Optimization, refactoring is needed
11  *
12  */
13
14 function setCookie( cookieName, cookieValue, expireDate) {
15         var today = new Date();
16                 today.setDate( today.getDate() + parseInt( expireDate ) );
17                 document.cookie = cookieName + "=" + escape( cookieValue ) + "; path=/; expires=" + today.toGMTString() + ";";
18 }
19 function getCookie(name) {
20         var cname = name + "=";
21         var dc = document.cookie;
22         if (dc.length > 0) {
23                 begin = dc.indexOf(cname);
24                         if (begin != -1) {
25                                 begin += cname.length;
26                                 end = dc.indexOf(";", begin);
27                                         if (end == -1) {
28                                                 end = dc.length;
29                                         }
30                                 return unescape(dc.substring(begin, end));
31                         }
32         }
33         return null;
34 }
35
36 ( function ( ) {
37
38         var QueryString = function () {
39                 var query_string = {},
40                         vars,
41                         pair,
42                         arr,
43                         query = window.location.search.substring(1);
44
45                 vars = query.split("&");
46
47                 for (var i = 0 ; i < vars.length ; i++) {
48                         pair = vars[i].split("=");
49                         if (typeof query_string[pair[0]] === "undefined") {
50                                 query_string[pair[0]] = pair[1];
51                         } else if (typeof query_string[pair[0]] === "string") {
52                                 arr = [ query_string[pair[0]], pair[1] ];
53                                 query_string[pair[0]] = arr;
54                         } else {
55                                 query_string[pair[0]].push(pair[1]);
56                         }
57                 }
58                 return query_string;
59         } ();
60 /*
61         except : listview, event
62 */
63         var tests = [
64                 "listview",
65                 "event",
66                 "button",
67                 "button-markup",
68                 "navigation",
69                 "zoom",
70                 "checkboxradio",
71                 "collapsible",
72                 "controlgroup",
73                 "core",
74                 "degrade-inputs",
75                 "dialog",
76                 "field-contain",
77                 "fixed-toolbar",
78                 "init",
79                 "loader",
80                 "textinput",
81                 "support",
82                 "media",
83                 "kitchensink",
84                 "navbar",
85                 "page",
86                 "page-sections",
87                 "select",
88                 "slider",
89                 "widget"
90         ],
91
92                 passCount, failCount, totalCount, runtime,
93                 currenTest,
94                 url;
95
96         function getCurrentURL ( ) {
97                 return window.location.href;
98         }
99         function getURLParameter(name) {
100     return decodeURI(
101         (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
102     );
103 }
104         url = getCurrentURL( );
105
106         ( function parseURL ( url ) {
107                 // TODO
108                 var loc,
109                         dir;
110                 passCount = ( getCookie( "TizenP") === "undefined" ) ? 0 : parseInt( getCookie( "TizenP") );
111                 failCount = ( getCookie( "TizenF") === "undefined" ) ? 0 : parseInt( getCookie( "TizenF") );
112                 totalCount = ( getCookie( "TizenT") === "undefined" ) ? 0 : parseInt( getCookie( "TizenT") );
113                 runTime = ( getCookie( "TizenR") === "undefined" ) ? 0 : parseInt( getCookie( "TizenR") );
114
115                 loc = window.location.pathname;
116                 dirs = loc.substring(0, loc.lastIndexOf('/')).split('/');
117                 currentTest = dirs[dirs.length-1];
118         } ( url ) );
119
120         QUnit.done = function ( details ) {
121                 var nextTestURL;
122
123                 function getNextTestURL( currentTest, passCount, failCount, totalCount , runTime ) {
124                         var i = 0,
125                                 nextUrl = "",
126                                 updir = "../";
127                         for( i = 0 ; i < tests.length ; i++ )
128                         {
129                                 if( tests[i] == currentTest ) {
130                                         break;
131                                 }
132                         }
133
134                         if( tests.length -1 == i )
135                         {
136                                 //Goto result Page
137                                 nextUrl ="../../../../../../tests/jqm-tchelper/result.php";
138                         }else{
139                                 if( currentTest === "navigation"  ) {
140                                         updir += "../../";
141                                 } else if ( currentTest === "listview" ) {
142                                         updir += "../";
143                                 }
144                                 setCookie( "TizenP", passCount );
145                                 setCookie( "TizenF", failCount );
146                                 setCookie( "TizenR", runTime );
147                                 setCookie( "TizenT", totalCount );
148                                 nextUrl = updir +  tests[i + 1];
149                         }
150
151                         return nextUrl;
152                 }
153                 function gotoURL( url ) {
154                         window.location.href = url;
155                         return;
156                 }
157
158                 passCount += details.passed;
159                 failCount += details.failed;
160                 totalCount +=  details.total;
161                 runTime += details.runtime;
162
163                 nextTestURL = getNextTestURL( currentTest, passCount, failCount, totalCount ,runTime );
164                 gotoURL( nextTestURL );
165
166         };
167 } () );