Skip to content
Browse files

Ensure that Opera Mini is NOT detected as supporting web fonts

While Opera Mobile supports web fonts and is like a mobile version of full
desktop Opera, the Opera Mini application doesn't currently support web fonts
and also follows a different versioning system separate from the main Opera
version. Thus, we should treat Opera Mini as a separate browser for the
purposes of web font support, and make sure that we don't return false
positives for support as well.
  • Loading branch information...
1 parent 8c42153 commit e2a76b64961f63100ba5886e02074711ff104953 Sean McBride committed Jul 25, 2012
Showing with 38 additions and 0 deletions.
  1. +23 −0 src-test/core/useragenttest.js
  2. +15 −0 src/core/useragentparser.js
View
23 src-test/core/useragenttest.js
@@ -312,6 +312,9 @@ UserAgentTest.prototype.testBrowserIsOperaBeforeVersion10 = function() {
};
UserAgentTest.prototype.testBrowserIsOperaMobileAndroid = function() {
+ // For the purposes of web font support, we consider Opera Mobile to be a
+ // version of full Opera on mobile devices, since the support for web fonts
+ // follows the same version numbers as the desktop versions.
var userAgentParser = new webfont.UserAgentParser(
"Opera/9.80 (Android 4.1.1; Linux; Opera Mobi/ADR-1207201819; U; en) Presto/2.10.254 Version/12.00",
this.defaultDocument_);
@@ -327,6 +330,26 @@ UserAgentTest.prototype.testBrowserIsOperaMobileAndroid = function() {
assertTrue(userAgent.isSupportingWebFont());
};
+UserAgentTest.prototype.testBrowserIsOperaMiniAndroid = function() {
+ // For the purposes of web font support, we consider Opera Mini to be a
+ // different browser from the full Opera, since it doesn't support web fonts
+ // and follows two separate versioning systems. We use the Opera Mini version
+ // instead of the more generic Opera version.
+ var userAgentParser = new webfont.UserAgentParser(
+ "Opera/9.80 (Android; Opera Mini/7.0.29952/28.2144; U; en) Presto/2.8.119 Version/11.10",
+ this.defaultDocument_);
+ var userAgent = userAgentParser.parse();
+
+ assertEquals("OperaMini", userAgent.getName());
+ assertEquals("7.0.29952", userAgent.getVersion());
+ assertEquals("Android", userAgent.getPlatform());
+ assertEquals("Unknown", userAgent.getPlatformVersion());
+ assertEquals("Presto", userAgent.getEngine());
+ assertEquals("2.8.119", userAgent.getEngineVersion());
+ assertEquals(undefined, userAgent.getDocumentMode());
+ assertFalse(userAgent.isSupportingWebFont());
+}
+
UserAgentTest.prototype.testBrowserIsIEOnMac = function() {
var userAgentParser = new webfont.UserAgentParser(
"Mozilla/4.0 (compatible; MSIE 5.23; Mac_PowerPC)",
View
15 src/core/useragentparser.js
@@ -153,6 +153,21 @@ webfont.UserAgentParser.prototype.parseOperaUserAgentString_ = function() {
engineVersion = geckoVersion;
}
}
+
+ // Check for Opera Mini first, since it looks like normal Opera
+ if (this.userAgent_.indexOf("Opera Mini/") != -1) {
+ var version = this.getMatchingGroup_(this.userAgent_, /Opera Mini\/([\d\.]+)/, 1);
+
+ if (version == "") {
+ version = webfont.UserAgentParser.UNKNOWN;
+ }
+
+ return new webfont.UserAgent("OperaMini", version, engineName,
+ engineVersion, this.getPlatform_(), this.getPlatformVersion_(),
+ this.getDocumentMode_(this.doc_), false);
+ }
+
+ // Otherwise, find version information for normal Opera or Opera Mobile
if (this.userAgent_.indexOf("Version/") != -1) {
var version = this.getMatchingGroup_(this.userAgent_, /Version\/([\d\.]+)/, 1);

0 comments on commit e2a76b6

Please sign in to comment.
Something went wrong with that request. Please try again.