Permalink
Browse files

Merge branch 'w42_MDL-35469_m23_geckover' of git://github.com/skodak/…

…moodle into MOODLE_23_STABLE
  • Loading branch information...
2 parents d402e05 + a4848f6 commit 0d79d9656685818bd6b9365d4bb3ee6ec12e4d0b @danpoltawski danpoltawski committed Nov 2, 2012
Showing with 154 additions and 11 deletions.
  1. +36 −9 lib/moodlelib.php
  2. +118 −2 lib/tests/moodlelib_test.php
View
@@ -8421,18 +8421,45 @@ function check_browser_version($brand, $version = null) {
case 'Gecko': /// Gecko based browsers
- if (empty($version) and substr_count($agent, 'Camino')) {
- // MacOS X Camino support
- $version = 20041110;
+ // Do not look for dates any more, we expect real Firefox version here.
+ if (empty($version)) {
+ $version = 1;
+ } else if ($version > 20000000) {
+ // This is just a guess, it is not supposed to be 100% accurate!
+ if (preg_match('/^201/', $version)) {
+ $version = 3.6;
+ } else if (preg_match('/^200[7-9]/', $version)) {
+ $version = 3;
+ } else if (preg_match('/^2006/', $version)) {
+ $version = 2;
+ } else {
+ $version = 1.5;
+ }
}
-
- // the proper string - Gecko/CCYYMMDD Vendor/Version
- // Faster version and work-a-round No IDN problem.
- if (preg_match("/Gecko\/([0-9]+)/i", $agent, $match)) {
- if ($match[1] > $version) {
- return true;
+ if (preg_match("/(Iceweasel|Firefox)\/([0-9\.]+)/i", $agent, $match)) {
+ // Use real Firefox version if specified in user agent string.
+ if (version_compare($match[2], $version) >= 0) {
+ return true;
+ }
+ } else if (preg_match("/Gecko\/([0-9\.]+)/i", $agent, $match)) {
+ // Gecko might contain date or Firefox revision, let's just guess the Firefox version from the date.
+ $browserver = $match[1];
+ if ($browserver > 20000000) {
+ // This is just a guess, it is not supposed to be 100% accurate!
+ if (preg_match('/^201/', $browserver)) {
+ $browserver = 3.6;
+ } else if (preg_match('/^200[7-9]/', $browserver)) {
+ $browserver = 3;
+ } else if (preg_match('/^2006/', $version)) {
+ $browserver = 2;
+ } else {
+ $browserver = 1.5;
}
}
+ if (version_compare($browserver, $version) >= 0) {
+ return true;
+ }
+ }
break;
@@ -49,8 +49,17 @@ class moodlelib_testcase extends advanced_testcase {
'1.5' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5'),
'1.5.0.1' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1'),
'2.0' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1',
- 'Ubuntu Linux AMD64' => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)'),
- '3.0.6' => array('SUSE' => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.6) Gecko/2009012700 SUSE/3.0.6-1.4 Firefox/3.0.6'),
+ 'Ubuntu Linux AMD64' => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)'),
+ '3.0.6' => array('SUSE' => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.6) Gecko/2009012700 SUSE/3.0.6-1.4 Firefox/3.0.6'),
+ '3.6' => array('Linux' => 'Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/3.6'),
+ '11.0' => array('Windows' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko Firefox/11.0'),
+ '15.0a2' => array('Windows' => 'Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2'),
+ '18.0' => array('Mac OS X' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/18.0 Firefox/18.0'),
+ ),
+ 'SeaMonkey' => array(
+ '2.0' => array('Windows' => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1b3pre) Gecko/20081208 SeaMonkey/2.0'),
+ '2.1' => array('Linux' => 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110609 Firefox/4.0.1 SeaMonkey/2.1'),
+ '2.3' => array('FreeBSD' => 'Mozilla/5.0 (X11; FreeBSD amd64; rv:6.0) Gecko/20110818 Firefox/6.0 SeaMonkey/2.3'),
),
'Safari' => array(
'312' => array('Mac OS X' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312'),
@@ -248,6 +257,113 @@ function test_check_browser_version()
$this->assertTrue(check_browser_version('Firefox'));
$this->assertTrue(check_browser_version('Firefox', '1.5'));
$this->assertFalse(check_browser_version('Firefox', '3.0'));
+ $this->assertTrue(check_browser_version('Gecko', '2'));
+ $this->assertTrue(check_browser_version('Gecko', 20030516));
+ $this->assertTrue(check_browser_version('Gecko', 20051106));
+ $this->assertTrue(check_browser_version('Gecko', 2006010100));
+
+ $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['1.0.6']['Windows XP'];
+ $this->assertTrue(check_browser_version('Firefox'));
+ $this->assertTrue(check_browser_version('Gecko', '1'));
+ $this->assertFalse(check_browser_version('Gecko', 20030516));
+ $this->assertFalse(check_browser_version('Gecko', 20051106));
+ $this->assertFalse(check_browser_version('Gecko', 2006010100));
+ $this->assertFalse(check_browser_version('Firefox', '1.5'));
+ $this->assertFalse(check_browser_version('Firefox', '3.0'));
+ $this->assertFalse(check_browser_version('Gecko', '2'));
+
+ $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['2.0']['Windows XP'];
+ $this->assertTrue(check_browser_version('Firefox'));
+ $this->assertTrue(check_browser_version('Firefox', '1.5'));
+ $this->assertTrue(check_browser_version('Gecko', '1'));
+ $this->assertTrue(check_browser_version('Gecko', '2'));
+ $this->assertTrue(check_browser_version('Gecko', 20030516));
+ $this->assertTrue(check_browser_version('Gecko', 20051106));
+ $this->assertTrue(check_browser_version('Gecko', 2006010100));
+ $this->assertFalse(check_browser_version('Firefox', '3.0'));
+
+ $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['3.6']['Linux'];
+ $this->assertTrue(check_browser_version('Firefox'));
+ $this->assertTrue(check_browser_version('Firefox', '1.5'));
+ $this->assertTrue(check_browser_version('Firefox', '3.0'));
+ $this->assertTrue(check_browser_version('Gecko', '2'));
+ $this->assertTrue(check_browser_version('Gecko', '3.6'));
+ $this->assertTrue(check_browser_version('Gecko', 20030516));
+ $this->assertTrue(check_browser_version('Gecko', 20051106));
+ $this->assertTrue(check_browser_version('Gecko', 2006010100));
+ $this->assertFalse(check_browser_version('Firefox', '4'));
+ $this->assertFalse(check_browser_version('Firefox', '10'));
+
+ $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['3.6']['Linux'];
+ $this->assertTrue(check_browser_version('Firefox'));
+ $this->assertTrue(check_browser_version('Firefox', '1.5'));
+ $this->assertTrue(check_browser_version('Firefox', '3.0'));
+ $this->assertTrue(check_browser_version('Gecko', '2'));
+ $this->assertTrue(check_browser_version('Gecko', '3.6'));
+ $this->assertTrue(check_browser_version('Gecko', 20030516));
+ $this->assertTrue(check_browser_version('Gecko', 20051106));
+ $this->assertTrue(check_browser_version('Gecko', 2006010100));
+ $this->assertFalse(check_browser_version('Firefox', '4'));
+ $this->assertFalse(check_browser_version('Firefox', '10'));
+ $this->assertFalse(check_browser_version('Firefox', '18'));
+ $this->assertFalse(check_browser_version('Gecko', '4'));
+
+ $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['15.0a2']['Windows'];
+ $this->assertTrue(check_browser_version('Firefox'));
+ $this->assertTrue(check_browser_version('Firefox', '1.5'));
+ $this->assertTrue(check_browser_version('Firefox', '3.0'));
+ $this->assertTrue(check_browser_version('Gecko', '2'));
+ $this->assertTrue(check_browser_version('Gecko', '3.6'));
+ $this->assertTrue(check_browser_version('Gecko', '15.0'));
+ $this->assertTrue(check_browser_version('Gecko', 20030516));
+ $this->assertTrue(check_browser_version('Gecko', 20051106));
+ $this->assertTrue(check_browser_version('Gecko', 2006010100));
+ $this->assertTrue(check_browser_version('Firefox', '4'));
+ $this->assertTrue(check_browser_version('Firefox', '10'));
+ $this->assertTrue(check_browser_version('Firefox', '15'));
+ $this->assertFalse(check_browser_version('Firefox', '18'));
+ $this->assertFalse(check_browser_version('Gecko', '18'));
+
+ $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['18.0']['Mac OS X'];
+ $this->assertTrue(check_browser_version('Firefox'));
+ $this->assertTrue(check_browser_version('Firefox', '1.5'));
+ $this->assertTrue(check_browser_version('Firefox', '3.0'));
+ $this->assertTrue(check_browser_version('Gecko', '2'));
+ $this->assertTrue(check_browser_version('Gecko', '3.6'));
+ $this->assertTrue(check_browser_version('Gecko', '15.0'));
+ $this->assertTrue(check_browser_version('Gecko', '18.0'));
+ $this->assertTrue(check_browser_version('Gecko', 20030516));
+ $this->assertTrue(check_browser_version('Gecko', 20051106));
+ $this->assertTrue(check_browser_version('Gecko', 2006010100));
+ $this->assertTrue(check_browser_version('Firefox', '4'));
+ $this->assertTrue(check_browser_version('Firefox', '10'));
+ $this->assertTrue(check_browser_version('Firefox', '15'));
+ $this->assertTrue(check_browser_version('Firefox', '18'));
+ $this->assertFalse(check_browser_version('Firefox', '19'));
+ $this->assertFalse(check_browser_version('Gecko', '19'));
+
+ $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['SeaMonkey']['2.0']['Windows'];
+
+ $this->assertTrue(check_browser_version('Gecko', '2'));
+ $this->assertTrue(check_browser_version('Gecko', 20030516));
+ $this->assertTrue(check_browser_version('Gecko', 20051106));
+ $this->assertTrue(check_browser_version('Gecko', 2006010100));
+ $this->assertFalse(check_browser_version('Gecko', '3.6'));
+ $this->assertFalse(check_browser_version('Gecko', '4.0'));
+ $this->assertFalse(check_browser_version('Firefox'));
+
+ $_SERVER['HTTP_USER_AGENT'] = $this->user_agents['SeaMonkey']['2.1']['Linux'];
+ $this->assertTrue(check_browser_version('Gecko', '2'));
+ $this->assertTrue(check_browser_version('Gecko', '3.6'));
+ $this->assertTrue(check_browser_version('Gecko', '4.0'));
+ $this->assertTrue(check_browser_version('Gecko', 20030516));
+ $this->assertTrue(check_browser_version('Gecko', 20051106));
+ $this->assertTrue(check_browser_version('Gecko', 2006010100));
+ $this->assertTrue(check_browser_version('Firefox'));
+ $this->assertTrue(check_browser_version('Firefox', 4.0));
+ $this->assertFalse(check_browser_version('Firefox', 5));
+ $this->assertFalse(check_browser_version('Gecko', '18.0'));
+
}
function test_get_browser_version_classes() {

0 comments on commit 0d79d96

Please sign in to comment.