r101845 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101844‎ | r101845 | r101846 >
Date:18:33, 3 November 2011
Author:brion
Status:resolved (Comments)
Tags:
Comment:
Add to jquery.client's qunit tests by actually testing the test() function against the sample user-agents.

Also changed from hardcoded constant of how many user-agents to test to counting them so it won't get out of sync.

Added Firefox 10 and IE 10 sample user-agent strings in to make sure they test correctly.
They *do* test correctly *if and only if* you use raw numbers for a major-version test (eg > 7). If you tried > "7.0" you would find it fails on the version 10 browsers.
Modified paths:
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.client.test.js (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.client.test.js
@@ -5,8 +5,7 @@
66 ok( jQuery.client, 'jQuery.client defined' );
77 });
88
9 -test( 'profile userAgent support', function() {
10 - expect(8);
 9+var uacount = 0, uas = (function() {
1110
1211 // Object keyed by userAgent. Value is an array (human-readable name, client-profile object, navigator.platform value)
1312 // Info based on results from http://toolserver.org/~krinkle/testswarm/job/174/
@@ -24,11 +23,32 @@
2524 "version": "7.0",
2625 "versionBase": "7",
2726 "versionNumber": 7
 27+ },
 28+ wikiEditor: {
 29+ ltr: true,
 30+ rtl: false
2831 }
2932 },
3033 // Internet Explorer 8
3134 // Internet Explorer 9
3235 // Internet Explorer 10
 36+ 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)': {
 37+ title: 'Internet Explorer 10',
 38+ platform: 'Win32',
 39+ profile: {
 40+ "name": "msie",
 41+ "layout": "trident",
 42+ "layoutVersion": "unknown", // should be able to report 6?
 43+ "platform": "win",
 44+ "version": "10.0",
 45+ "versionBase": "10",
 46+ "versionNumber": 10
 47+ },
 48+ wikiEditor: {
 49+ ltr: true,
 50+ rtl: true
 51+ }
 52+ },
3353 // Firefox 2
3454 // Firefox 3.5
3555 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': {
@@ -42,6 +62,10 @@
4363 "version": "3.5.19",
4464 "versionBase": "3",
4565 "versionNumber": 3.5
 66+ },
 67+ wikiEditor: {
 68+ ltr: true,
 69+ rtl: true
4670 }
4771 },
4872 // Firefox 3.6
@@ -56,6 +80,10 @@
5781 "version": "3.6.17",
5882 "versionBase": "3",
5983 "versionNumber": 3.6
 84+ },
 85+ wikiEditor: {
 86+ ltr: true,
 87+ rtl: true
6088 }
6189 },
6290 // Firefox 4
@@ -70,8 +98,30 @@
7199 "version": "4.0.1",
72100 "versionBase": "4",
73101 "versionNumber": 4
 102+ },
 103+ wikiEditor: {
 104+ ltr: true,
 105+ rtl: true
74106 }
75107 },
 108+ // Firefox 10 nightly build
 109+ 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0a1) Gecko/20111103 Firefox/10.0a1': {
 110+ title: 'Firefox 10 nightly',
 111+ platform: 'Linux',
 112+ profile: {
 113+ "name": "firefox",
 114+ "layout": "gecko",
 115+ "layoutVersion": 20111103,
 116+ "platform": "linux",
 117+ "version": "10.0a1",
 118+ "versionBase": "10",
 119+ "versionNumber": 10
 120+ },
 121+ wikiEditor: {
 122+ ltr: true,
 123+ rtl: true
 124+ }
 125+ },
76126 // Firefox 5
77127 // Safari 3
78128 // Safari 4
@@ -86,6 +136,10 @@
87137 "version": "4.0.5",
88138 "versionBase": "4",
89139 "versionNumber": 4
 140+ },
 141+ wikiEditor: {
 142+ ltr: true,
 143+ rtl: true
90144 }
91145 },
92146 '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': {
@@ -99,6 +153,10 @@
100154 "version": "4.0.5",
101155 "versionBase": "4",
102156 "versionNumber": 4
 157+ },
 158+ wikiEditor: {
 159+ ltr: true,
 160+ rtl: true
103161 }
104162 },
105163 // Safari 5
@@ -122,6 +180,10 @@
123181 "version": "12.0.742.112",
124182 "versionBase": "12",
125183 "versionNumber": 12
 184+ },
 185+ wikiEditor: {
 186+ ltr: true,
 187+ rtl: true
126188 }
127189 },
128190 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': {
@@ -135,10 +197,20 @@
136198 "version": "12.0.742.68",
137199 "versionBase": "12",
138200 "versionNumber": 12
 201+ },
 202+ wikiEditor: {
 203+ ltr: true,
 204+ rtl: true
139205 }
140206 }
141207 };
 208+ $.each( uas, function() { uacount++ });
 209+ return uas;
 210+})();
142211
 212+test( 'profile userAgent support', function() {
 213+ expect(uacount);
 214+
143215 // Generate a client profile object and compare recursively
144216 var uaTest = function( rawUserAgent, data ) {
145217 var ret = $.client.profile( {
@@ -168,34 +240,35 @@
169241 equal( typeof p.versionNumber, 'number', 'p.versionNumber is a number' );
170242 });
171243
 244+// Example from WikiEditor
 245+var testMap = {
 246+ 'ltr': {
 247+ 'msie': [['>=', 7.0]],
 248+ 'firefox': [['>=', 2]],
 249+ 'opera': [['>=', 9.6]],
 250+ 'safari': [['>=', 3]],
 251+ 'chrome': [['>=', 3]],
 252+ 'netscape': [['>=', 9]],
 253+ 'blackberry': false,
 254+ 'ipod': false,
 255+ 'iphone': false
 256+ },
 257+ 'rtl': {
 258+ 'msie': [['>=', 8]],
 259+ 'firefox': [['>=', 2]],
 260+ 'opera': [['>=', 9.6]],
 261+ 'safari': [['>=', 3]],
 262+ 'chrome': [['>=', 3]],
 263+ 'netscape': [['>=', 9]],
 264+ 'blackberry': false,
 265+ 'ipod': false,
 266+ 'iphone': false
 267+ }
 268+};
 269+
172270 test( 'test', function() {
173271 expect(1);
174272
175 - // Example from WikiEditor
176 - var testMap = {
177 - 'ltr': {
178 - 'msie': [['>=', 7]],
179 - 'firefox': [['>=', 2]],
180 - 'opera': [['>=', 9.6]],
181 - 'safari': [['>=', 3]],
182 - 'chrome': [['>=', 3]],
183 - 'netscape': [['>=', 9]],
184 - 'blackberry': false,
185 - 'ipod': false,
186 - 'iphone': false
187 - },
188 - 'rtl': {
189 - 'msie': [['>=', 8]],
190 - 'firefox': [['>=', 2]],
191 - 'opera': [['>=', 9.6]],
192 - 'safari': [['>=', 3]],
193 - 'chrome': [['>=', 3]],
194 - 'netscape': [['>=', 9]],
195 - 'blackberry': false,
196 - 'ipod': false,
197 - 'iphone': false
198 - }
199 - };
200273 // .test() uses eval, make sure no exceptions are thrown
201274 // then do a basic return value type check
202275 var testMatch = $.client.test( testMap );
@@ -203,3 +276,23 @@
204277 equal( typeof testMatch, 'boolean', 'test returns a boolean value' );
205278
206279 });
 280+
 281+test( 'User-agent matches against WikiEditor\'s compatibility map', function() {
 282+ expect( uacount * 2 );
 283+
 284+ // Loop through and run tests
 285+ $.each( uas, function( agent, data ) {
 286+ $.each( ['ltr', 'rtl'], function( i, dir ) {
 287+ $('body').addClass(dir);
 288+ var profile = $.client.profile( {
 289+ userAgent: agent,
 290+ platform: data.platform
 291+ } );
 292+ var testMatch = $.client.test( testMap, profile );
 293+ $('body').removeClass(dir);
 294+
 295+ equal( testMatch, data.wikiEditor[dir], 'testing comparison based on ' + dir + ', ' + agent );
 296+ });
 297+ });
 298+});
 299+

Follow-up revisions

RevisionCommit summaryAuthorDate
r105861comments from r101845 on jquery.client.Testhashar10:23, 12 December 2011
r110214Fix jquery.client.test breakage...krinkle16:56, 28 January 2012

Comments

#Comment by Krinkle (talk | contribs)   16:50, 28 January 2012
+	// Loop through and run tests
+	$.each( uas, function( agent, data ) {
+		$.each( ['ltr', 'rtl'], function( i, dir ) {
+			$('body').addClass(dir);
+			var profile = $.client.profile( {
+				userAgent: agent,
+				platform: data.platform
+			} );
+			var testMatch = $.client.test( testMap, profile );
+			$('body').removeClass(dir);
+
+			equal( testMatch, data.wikiEditor[dir], 'testing comparison based on ' + dir + ', ' + agent );
+		});
+	});

The above leaves the page with both "rtl" and "ltr" classes removed, it should restore the original value after the test.

Also the test run fails in RTL mode because it assumes that the page doesn't have class "rtl" already. It should remove either and add one for the test.

#Comment by Krinkle (talk | contribs)   16:56, 28 January 2012

Resolved in r110214.

Status & tagging log