UnitTest:JQM Unit TC helper has been added,TCs have been modified
[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 ( function ( ) {
13
14         var QueryString = function () {
15                 var query_string = {},
16                         vars,
17                         pair,
18                         arr,
19                         query = window.location.search.substring(1);
20
21                 vars = query.split("&");
22
23                 for (var i = 0 ; i < vars.length ; i++)
24                 {
25                         pair = vars[i].split("=");
26                         if (typeof query_string[pair[0]] === "undefined")
27                         {
28                                 query_string[pair[0]] = pair[1];
29                         }
30                         else if (typeof query_string[pair[0]] === "string")
31                         {
32                                 arr = [ query_string[pair[0]], pair[1] ];
33                                 query_string[pair[0]] = arr;
34                         } else {
35                                 query_string[pair[0]].push(pair[1]);
36                         }
37                 }
38                 return query_string;
39         } ();
40 /*
41         except : listview, event
42 */
43         var tests = [
44                 "button",
45                 "button-markup",
46                 "navigation",
47                 "zoom",
48                 "checkboxradio",
49                 "collapsible",
50                 "controlgroup",
51                 "core",
52                 "degrade-inputs",
53                 "dialog",
54                 "field-contain",
55                 "fixed-toolbar",
56                 "init",
57                 "loader",
58                 "textinput",
59                 "support",
60                 "media",
61                 "kitchensink",
62                 "navbar",
63                 "page",
64                 "page-sections",
65                 "select",
66                 "slider",
67                 "widget"
68         ],
69
70                 passCount, failCount, totalCount, runtime,
71                 currenTest,
72                 url;
73
74         function getCurrentURL ( ) {
75                 return window.location.href;
76         }
77         function getURLParameter(name) {
78     return decodeURI(
79         (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
80     );
81 }
82         url = getCurrentURL( );
83
84         ( function parseURL ( url ) {
85                 // TODO
86                 var loc,
87                         dir;
88                 passCount = ( typeof QueryString.p === "undefined" ) ? 0 : parseInt( QueryString.p );
89                 failCount = ( typeof QueryString.f === "undefined" ) ? 0 : parseInt( QueryString.f );
90                 totalCount = ( typeof QueryString.t === "undefined" ) ? 0 : parseInt( QueryString.t );
91                 runTime = ( typeof QueryString.r === "undefined" ) ? 0 : parseInt( QueryString.r );
92
93                 loc = window.location.pathname;
94                 dirs = loc.substring(0, loc.lastIndexOf('/')).split('/');
95                 currentTest = dirs[dirs.length-1];
96         } ( url ) );
97         QUnit.log = function( obj ) {
98                 var tempUrl = url;
99                 if( obj.result ) {
100                         if ( tempUrl.indexOf("?")>-1 ) {
101                                 tempUrl = tempUrl.substr(0,tempUrl.indexOf("?"));
102                         }
103                         $.post( tempUrl + "../../../../../../tests/jqm-tchelper/log.php", { currentTest : currentTest, obj : obj } , function(){});
104                 }
105         };
106         QUnit.done = function ( details ) {
107                 var nextTestURL;
108
109                 function getNextTestURL( currentTest, passCount, failCount, totalCount , runTime ) {
110                         var i = 0,
111                                 nextUrl = "",
112                                 updir = "../";
113                         for( i = 0 ; i < tests.length ; i++ )
114                         {
115                                 if( tests[i] == currentTest )
116                                 {
117                                         break;
118                                 }
119                         }
120
121                         if( tests.length -1 == i ||
122                                 currentTest === "listview" ||
123                                 currentTest === "event" )
124                         {
125                                 //Goto result Page
126                                 nextUrl ="../../../../../../tests/jqm-tchelper/result.php"  + "?" + "p=" + passCount + "&f=" + failCount + "&t=" + totalCount + "&r=" + runTime;
127                         }else{
128                                 if( currentTest === "navigation"  )
129                                 {
130                                         updir += "../../";
131                                 }
132                                 nextUrl = updir +  tests[i + 1] +"/?" + "p=" + passCount + "&f=" + failCount + "&t=" + totalCount + "&r=" + runTime;
133                         }
134
135                         return nextUrl;
136                 }
137                 function gotoURL( url ) {
138                         window.location.href = url;
139                         return;
140                 }
141
142                 passCount += details.passed;
143                 failCount += details.failed;
144                 totalCount +=  details.total;
145                 runTime += details.runtime;
146
147                 nextTestURL = getNextTestURL( currentTest, passCount, failCount, totalCount ,runTime );
148                 gotoURL( nextTestURL );
149
150         };
151 } () );