From 7e2851b8093030aa9fe97ee83d2b994273b29b36 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 3 Nov 2011 18:33:11 +0000 Subject: [PATCH] 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. --- .../resources/jquery/jquery.client.test.js | 147 ++++++++++++++---- 1 file changed, 120 insertions(+), 27 deletions(-) diff --git a/tests/qunit/suites/resources/jquery/jquery.client.test.js b/tests/qunit/suites/resources/jquery/jquery.client.test.js index fb0e0ec232..c0e869232c 100644 --- a/tests/qunit/suites/resources/jquery/jquery.client.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.client.test.js @@ -5,8 +5,7 @@ test( '-- Initial check', function() { ok( jQuery.client, 'jQuery.client defined' ); }); -test( 'profile userAgent support', function() { - expect(8); +var uacount = 0, uas = (function() { // Object keyed by userAgent. Value is an array (human-readable name, client-profile object, navigator.platform value) // Info based on results from http://toolserver.org/~krinkle/testswarm/job/174/ @@ -24,11 +23,32 @@ test( 'profile userAgent support', function() { "version": "7.0", "versionBase": "7", "versionNumber": 7 + }, + wikiEditor: { + ltr: true, + rtl: false } }, // Internet Explorer 8 // Internet Explorer 9 // Internet Explorer 10 + 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)': { + title: 'Internet Explorer 10', + platform: 'Win32', + profile: { + "name": "msie", + "layout": "trident", + "layoutVersion": "unknown", // should be able to report 6? + "platform": "win", + "version": "10.0", + "versionBase": "10", + "versionNumber": 10 + }, + wikiEditor: { + ltr: true, + rtl: true + } + }, // Firefox 2 // Firefox 3.5 '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 @@ test( 'profile userAgent support', function() { "version": "3.5.19", "versionBase": "3", "versionNumber": 3.5 + }, + wikiEditor: { + ltr: true, + rtl: true } }, // Firefox 3.6 @@ -56,6 +80,10 @@ test( 'profile userAgent support', function() { "version": "3.6.17", "versionBase": "3", "versionNumber": 3.6 + }, + wikiEditor: { + ltr: true, + rtl: true } }, // Firefox 4 @@ -70,6 +98,28 @@ test( 'profile userAgent support', function() { "version": "4.0.1", "versionBase": "4", "versionNumber": 4 + }, + wikiEditor: { + ltr: true, + rtl: true + } + }, + // Firefox 10 nightly build + 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0a1) Gecko/20111103 Firefox/10.0a1': { + title: 'Firefox 10 nightly', + platform: 'Linux', + profile: { + "name": "firefox", + "layout": "gecko", + "layoutVersion": 20111103, + "platform": "linux", + "version": "10.0a1", + "versionBase": "10", + "versionNumber": 10 + }, + wikiEditor: { + ltr: true, + rtl: true } }, // Firefox 5 @@ -86,6 +136,10 @@ test( 'profile userAgent support', function() { "version": "4.0.5", "versionBase": "4", "versionNumber": 4 + }, + wikiEditor: { + ltr: true, + rtl: true } }, '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 @@ test( 'profile userAgent support', function() { "version": "4.0.5", "versionBase": "4", "versionNumber": 4 + }, + wikiEditor: { + ltr: true, + rtl: true } }, // Safari 5 @@ -122,6 +180,10 @@ test( 'profile userAgent support', function() { "version": "12.0.742.112", "versionBase": "12", "versionNumber": 12 + }, + wikiEditor: { + ltr: true, + rtl: true } }, 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': { @@ -135,9 +197,19 @@ test( 'profile userAgent support', function() { "version": "12.0.742.68", "versionBase": "12", "versionNumber": 12 + }, + wikiEditor: { + ltr: true, + rtl: true } } }; + $.each( uas, function() { uacount++ }); + return uas; +})(); + +test( 'profile userAgent support', function() { + expect(uacount); // Generate a client profile object and compare recursively var uaTest = function( rawUserAgent, data ) { @@ -168,34 +240,35 @@ test( 'profile return validation for current user agent', function() { equal( typeof p.versionNumber, 'number', 'p.versionNumber is a number' ); }); +// Example from WikiEditor +var testMap = { + 'ltr': { + 'msie': [['>=', 7.0]], + 'firefox': [['>=', 2]], + 'opera': [['>=', 9.6]], + 'safari': [['>=', 3]], + 'chrome': [['>=', 3]], + 'netscape': [['>=', 9]], + 'blackberry': false, + 'ipod': false, + 'iphone': false + }, + 'rtl': { + 'msie': [['>=', 8]], + 'firefox': [['>=', 2]], + 'opera': [['>=', 9.6]], + 'safari': [['>=', 3]], + 'chrome': [['>=', 3]], + 'netscape': [['>=', 9]], + 'blackberry': false, + 'ipod': false, + 'iphone': false + } +}; + test( 'test', function() { expect(1); - // Example from WikiEditor - var testMap = { - 'ltr': { - 'msie': [['>=', 7]], - 'firefox': [['>=', 2]], - 'opera': [['>=', 9.6]], - 'safari': [['>=', 3]], - 'chrome': [['>=', 3]], - 'netscape': [['>=', 9]], - 'blackberry': false, - 'ipod': false, - 'iphone': false - }, - 'rtl': { - 'msie': [['>=', 8]], - 'firefox': [['>=', 2]], - 'opera': [['>=', 9.6]], - 'safari': [['>=', 3]], - 'chrome': [['>=', 3]], - 'netscape': [['>=', 9]], - 'blackberry': false, - 'ipod': false, - 'iphone': false - } - }; // .test() uses eval, make sure no exceptions are thrown // then do a basic return value type check var testMatch = $.client.test( testMap ); @@ -203,3 +276,23 @@ test( 'test', function() { equal( typeof testMatch, 'boolean', 'test returns a boolean value' ); }); + +test( 'User-agent matches against WikiEditor\'s compatibility map', function() { + expect( uacount * 2 ); + + // 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 ); + }); + }); +}); + -- 2.20.1