Applying whitespace conventions in core JS files.
[lhc/web/wiklou.git] / tests / qunit / suites / resources / jquery / jquery.client.test.js
1 module( 'jquery.client' );
2
3 test( '-- Initial check', function() {
4 expect(1);
5 ok( jQuery.client, 'jQuery.client defined' );
6 });
7
8 test( 'profile userAgent support', function() {
9 expect(8);
10
11 // Object keyed by userAgent. Value is an array (human-readable name, client-profile object, navigator.platform value)
12 // Info based on results from http://toolserver.org/~krinkle/testswarm/job/174/
13 var uas = {
14 // Internet Explorer 6
15 // Internet Explorer 7
16 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)': {
17 title: 'Internet Explorer 7',
18 platform: 'Win32',
19 profile: {
20 "name": "msie",
21 "layout": "trident",
22 "layoutVersion": "unknown",
23 "platform": "win",
24 "version": "7.0",
25 "versionBase": "7",
26 "versionNumber": 7
27 }
28 },
29 // Internet Explorer 8
30 // Internet Explorer 9
31 // Internet Explorer 10
32 // Firefox 2
33 // Firefox 3.5
34 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': {
35 title: 'Firefox 3.5',
36 platform: 'MacIntel',
37 profile: {
38 "name": "firefox",
39 "layout": "gecko",
40 "layoutVersion": 20110420,
41 "platform": "mac",
42 "version": "3.5.19",
43 "versionBase": "3",
44 "versionNumber": 3.5
45 }
46 },
47 // Firefox 3.6
48 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17': {
49 title: 'Firefox 3.6',
50 platform: 'Linux i686',
51 profile: {
52 "name": "firefox",
53 "layout": "gecko",
54 "layoutVersion": 20110422,
55 "platform": "linux",
56 "version": "3.6.17",
57 "versionBase": "3",
58 "versionNumber": 3.6
59 }
60 },
61 // Firefox 4
62 'Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': {
63 title: 'Firefox 4',
64 platform: 'Win32',
65 profile: {
66 "name": "firefox",
67 "layout": "gecko",
68 "layoutVersion": 20100101,
69 "platform": "win",
70 "version": "4.0.1",
71 "versionBase": "4",
72 "versionNumber": 4
73 }
74 },
75 // Firefox 5
76 // Safari 3
77 // Safari 4
78 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; nl-nl) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7': {
79 title: 'Safari 4',
80 platform: 'MacIntel',
81 profile: {
82 "name": "safari",
83 "layout": "webkit",
84 "layoutVersion": 531,
85 "platform": "mac",
86 "version": "4.0.5",
87 "versionBase": "4",
88 "versionNumber": 4
89 }
90 },
91 'Mozilla/5.0 (Windows; U; Windows NT 6.0; cs-CZ) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7': {
92 title: 'Safari 4',
93 platform: 'Win32',
94 profile: {
95 "name": "safari",
96 "layout": "webkit",
97 "layoutVersion": 533,
98 "platform": "win",
99 "version": "4.0.5",
100 "versionBase": "4",
101 "versionNumber": 4
102 }
103 },
104 // Safari 5
105 // Opera 10
106 // Chrome 5
107 // Chrome 6
108 // Chrome 7
109 // Chrome 8
110 // Chrome 9
111 // Chrome 10
112 // Chrome 11
113 // Chrome 12
114 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_5_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30': {
115 title: 'Chrome 12',
116 platform: 'MacIntel',
117 profile: {
118 "name": "chrome",
119 "layout": "webkit",
120 "layoutVersion": 534,
121 "platform": "mac",
122 "version": "12.0.742.112",
123 "versionBase": "12",
124 "versionNumber": 12
125 }
126 },
127 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': {
128 title: 'Chrome 12',
129 platform: 'Linux i686',
130 profile: {
131 "name": "chrome",
132 "layout": "webkit",
133 "layoutVersion": 534,
134 "platform": "linux",
135 "version": "12.0.742.68",
136 "versionBase": "12",
137 "versionNumber": 12
138 }
139 }
140 };
141
142 // Generate a client profile object and compare recursively
143 var uaTest = function( rawUserAgent, data ) {
144 var ret = $.client.profile( {
145 userAgent: rawUserAgent,
146 platform: data.platform
147 } );
148 deepEqual( ret, data.profile, 'Client profile support check for ' + data.title + ' (' + data.platform + '): ' + rawUserAgent );
149 };
150
151 // Loop through and run tests
152 $.each( uas, uaTest );
153 } );
154
155 test( 'profile return validation for current user agent', function() {
156 expect(7);
157 var p = $.client.profile();
158 var unknownOrType = function( val, type, summary ) {
159 return ok( typeof val === type || val === 'unknown', summary );
160 };
161
162 equal( typeof p, 'object', 'profile returns an object' );
163 unknownOrType( p.layout, 'string', 'p.layout is a string (or "unknown")' );
164 unknownOrType( p.layoutVersion, 'number', 'p.layoutVersion is a number (or "unknown")' );
165 unknownOrType( p.platform, 'string', 'p.platform is a string (or "unknown")' );
166 unknownOrType( p.version, 'string', 'p.version is a string (or "unknown")' );
167 unknownOrType( p.versionBase, 'string', 'p.versionBase is a string (or "unknown")' );
168 equal( typeof p.versionNumber, 'number', 'p.versionNumber is a number' );
169 });
170
171 test( 'test', function() {
172 expect(1);
173
174 // Example from WikiEditor
175 var testMap = {
176 'ltr': {
177 'msie': [['>=', 7]],
178 'firefox': [['>=', 2]],
179 'opera': [['>=', 9.6]],
180 'safari': [['>=', 3]],
181 'chrome': [['>=', 3]],
182 'netscape': [['>=', 9]],
183 'blackberry': false,
184 'ipod': false,
185 'iphone': false
186 },
187 'rtl': {
188 'msie': [['>=', 8]],
189 'firefox': [['>=', 2]],
190 'opera': [['>=', 9.6]],
191 'safari': [['>=', 3]],
192 'chrome': [['>=', 3]],
193 'netscape': [['>=', 9]],
194 'blackberry': false,
195 'ipod': false,
196 'iphone': false
197 }
198 };
199 // .test() uses eval, make sure no exceptions are thrown
200 // then do a basic return value type check
201 var testMatch = $.client.test( testMap );
202
203 equal( typeof testMatch, 'boolean', 'test returns a boolean value' );
204
205 });