Permalink
Browse files

Merge pull request #74 from typekit/bs-add-bb-support

Add support for BlackBerry
  • Loading branch information...
2 parents 71c48ae + 5cb6d1f commit 5c383cd262972e8567e7d91edbb366e2a0929b31 Sean McBride committed Dec 12, 2012
Showing with 79 additions and 6 deletions.
  1. +51 −4 src-test/core/useragenttest.js
  2. +28 −2 src/core/useragentparser.js
@@ -196,21 +196,36 @@ UserAgentTest.prototype.testBrowserIsIPhone = function() {
assertTrue(userAgent.isSupportingWebFont());
};
-
UserAgentTest.prototype.testBrowserIsAndroid = function() {
+ var userAgentParser = new webfont.UserAgentParser(
+ "Mozilla/5.0 (Linux; U; Android 2.2.1; en-ca; LG-P505R Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
+ this.defaultDocument_);
+ var userAgent = userAgentParser.parse();
+
+ assertEquals("BuiltinBrowser", userAgent.getName());
+ assertEquals("Unknown", userAgent.getVersion());
+ assertEquals("Android", userAgent.getPlatform());
+ assertEquals("2.2.1", userAgent.getPlatformVersion());
+ assertEquals("AppleWebKit", userAgent.getEngine());
+ assertEquals("533.1", userAgent.getEngineVersion());
+ assertEquals(undefined, userAgent.getDocumentMode());
+ assertTrue(userAgent.isSupportingWebFont());
+};
+
+UserAgentTest.prototype.testBrowserIsOldUnsupportedAndroid = function() {
var userAgentParser = new webfont.UserAgentParser(
"Mozilla/5.0 (Linux; U; Android 2.1-update1; en-us; Nexus One Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17",
this.defaultDocument_);
var userAgent = userAgentParser.parse();
- assertEquals("Safari", userAgent.getName());
- assertEquals("4.0", userAgent.getVersion());
+ assertEquals("BuiltinBrowser", userAgent.getName());
+ assertEquals("Unknown", userAgent.getVersion());
assertEquals("Android", userAgent.getPlatform());
assertEquals("2.1-update1", userAgent.getPlatformVersion());
assertEquals("AppleWebKit", userAgent.getEngine());
assertEquals("530.17", userAgent.getEngineVersion());
assertEquals(undefined, userAgent.getDocumentMode());
- assertTrue(userAgent.isSupportingWebFont());
+ assertFalse(userAgent.isSupportingWebFont());
};
UserAgentTest.prototype.testBrowserIsAndroidChromeMobile = function() {
@@ -670,3 +685,35 @@ UserAgentTest.prototype.testBrowserGeckoHighSubVerShouldNotSupportWebFont = func
assertEquals(undefined, userAgent.getDocumentMode());
assertFalse(userAgent.isSupportingWebFont());
};
+
+UserAgentTest.prototype.testBrowserBBSupportWebfont = function() {
+ var userAgentParser = new webfont.UserAgentParser(
+ "Mozilla/5.0 (BB10; Touch) AppleWebKit/537.3+ (KHTML, like Gecko) Version/10.0.9.388 Mobile Safari/537.3+",
+ this.defaultDocument_);
+ var userAgent = userAgentParser.parse();
+
+ assertEquals("BuiltinBrowser", userAgent.getName());
+ assertEquals("Unknown", userAgent.getVersion());
+ assertEquals("BlackBerry", userAgent.getPlatform());
+ assertEquals("10.0.9.388", userAgent.getPlatformVersion());
+ assertEquals("AppleWebKit", userAgent.getEngine());
+ assertEquals("537.3+", userAgent.getEngineVersion());
+ assertEquals(undefined, userAgent.getDocumentMode());
+ assertTrue(userAgent.isSupportingWebFont());
+};
+
+UserAgentTest.prototype.testBrowserBBNotSupportWebfont = function() {
+ var userAgentParser = new webfont.UserAgentParser(
+ "Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+",
+ this.defaultDocument_);
+ var userAgent = userAgentParser.parse();
+
+ assertEquals("BuiltinBrowser", userAgent.getName());
+ assertEquals("Unknown", userAgent.getVersion());
+ assertEquals("BlackBerry", userAgent.getPlatform());
+ assertEquals("7.1.0.346", userAgent.getPlatformVersion());
+ assertEquals("AppleWebKit", userAgent.getEngine());
+ assertEquals("534.11+", userAgent.getEngineVersion());
+ assertEquals(undefined, userAgent.getDocumentMode());
+ assertFalse(userAgent.isSupportingWebFont());
+};
@@ -13,6 +13,16 @@ webfont.UserAgentParser = function(userAgent, doc) {
*/
webfont.UserAgentParser.UNKNOWN = "Unknown";
+/**
+ * A constant for identifying a generic browser on a mobile platform that
+ * doesn't really have a name, but just came with the platform. Usually these
+ * are WebKit based, and examples are the default browser app on Android and
+ * the default browser app on BlackBerry 10.
+ * @const
+ * @type {string}
+ */
+webfont.UserAgentParser.BUILTIN_BROWSER = "BuiltinBrowser";
+
/**
* @const
* @type {webfont.UserAgent}
@@ -50,9 +60,12 @@ webfont.UserAgentParser.prototype.parse = function() {
*/
webfont.UserAgentParser.prototype.getPlatform_ = function() {
var mobileOs = this.getMatchingGroup_(this.userAgent_,
- /(iPod|iPad|iPhone|Android|Windows Phone)/, 1);
+ /(iPod|iPad|iPhone|Android|Windows Phone|BB\d{2}|BlackBerry)/, 1);
if (mobileOs != "") {
+ if (/BB\d{2}/.test(mobileOs)) {
+ mobileOs = "BlackBerry";
+ }
return mobileOs;
}
var os = this.getMatchingGroup_(this.userAgent_,
@@ -91,6 +104,11 @@ webfont.UserAgentParser.prototype.getPlatformVersion_ = function() {
if (linuxVersion) {
return linuxVersion;
}
+ var blackBerryVersion = this.getMatchingGroup_(this.userAgent_,
+ /(BB\d{2}|BlackBerry).*?Version\/([^\s]*)/, 2);
+ if (blackBerryVersion) {
+ return blackBerryVersion;
+ }
return webfont.UserAgentParser.UNKNOWN;
};
@@ -224,14 +242,18 @@ webfont.UserAgentParser.prototype.parseWebKitUserAgentString_ = function() {
if (this.userAgent_.indexOf("Chrome") != -1 || this.userAgent_.indexOf("CrMo") != -1 || this.userAgent_.indexOf("CriOS") != -1) {
name = "Chrome";
+ } else if (platform == "BlackBerry" || platform == "Android") {
+ name = webfont.UserAgentParser.BUILTIN_BROWSER;
} else if (this.userAgent_.indexOf("Safari") != -1) {
name = "Safari";
} else if (this.userAgent_.indexOf("AdobeAIR") != -1) {
name = "AdobeAIR";
}
var version = webfont.UserAgentParser.UNKNOWN;
- if (this.userAgent_.indexOf("Version/") != -1) {
+ if (name == webfont.UserAgentParser.BUILTIN_BROWSER) {
+ version = webfont.UserAgentParser.UNKNOWN;
+ } else if (this.userAgent_.indexOf("Version/") != -1) {
version = this.getMatchingGroup_(this.userAgent_,
/Version\/([\d\.\w]+)/, 1);
} else if (name == "Chrome") {
@@ -246,6 +268,10 @@ webfont.UserAgentParser.prototype.parseWebKitUserAgentString_ = function() {
var minor = this.getMatchingGroup_(version, /\d+\.(\d+)/, 1);
supportWebFont = this.getMajorVersion_(version) > 2 ||
this.getMajorVersion_(version) == 2 && parseInt(minor, 10) >= 5;
+ } else if (platform == "BlackBerry") {
+ supportWebFont = parseInt(platformVersion, 10) >= 10;
+ } else if (platform == "Android") {
+ supportWebFont = parseFloat(platformVersion) > 2.1;
} else {
var minor = this.getMatchingGroup_(webKitVersion, /\d+\.(\d+)/, 1);
supportWebFont = this.getMajorVersion_(webKitVersion) >= 526 ||

0 comments on commit 5c383cd

Please sign in to comment.