From 02d3a0eb68afd20f7f3388f9385ad332dd550dd5 Mon Sep 17 00:00:00 2001 From: wenshao Date: Tue, 13 Aug 2013 23:17:44 +0800 Subject: [PATCH] userAgent support android 4.2 & 4.3 --- .../druid/support/http/stat/WebAppStat.java | 18 +++++++ .../http/UserAgentAndroid_4_2_Test_2.java | 50 +++++++++++++++++++ .../http/UserAgentAndroid_4_3_Test_2.java | 50 +++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 src/test/java/com/alibaba/druid/bvt/support/http/UserAgentAndroid_4_2_Test_2.java create mode 100644 src/test/java/com/alibaba/druid/bvt/support/http/UserAgentAndroid_4_3_Test_2.java diff --git a/src/main/java/com/alibaba/druid/support/http/stat/WebAppStat.java b/src/main/java/com/alibaba/druid/support/http/stat/WebAppStat.java index f0d5d3b8dd..8e0fb541ab 100644 --- a/src/main/java/com/alibaba/druid/support/http/stat/WebAppStat.java +++ b/src/main/java/com/alibaba/druid/support/http/stat/WebAppStat.java @@ -90,6 +90,8 @@ public class WebAppStat { private final AtomicLong osAndroid32Count = new AtomicLong(0); private final AtomicLong osAndroid40Count = new AtomicLong(0); private final AtomicLong osAndroid41Count = new AtomicLong(0); + private final AtomicLong osAndroid42Count = new AtomicLong(0); + private final AtomicLong osAndroid43Count = new AtomicLong(0); private final AtomicLong osLinuxUbuntuCount = new AtomicLong(0); @@ -187,6 +189,8 @@ public class WebAppStat { osAndroid32Count.set(0); osAndroid40Count.set(0); osAndroid41Count.set(0); + osAndroid42Count.set(0); + osAndroid43Count.set(0); browserIE6Count.set(0); browserIE7Count.set(0); @@ -504,6 +508,8 @@ public class WebAppStat { data.put("OSAndroid32Count", this.getOSAndroid32Count()); data.put("OSAndroid40Count", this.getOSAndroid40Count()); data.put("OSAndroid41Count", this.getOSAndroid41Count()); + data.put("OSAndroid42Count", this.getOSAndroid42Count()); + data.put("OSAndroid43Count", this.getOSAndroid43Count()); data.put("OSLinuxUbuntuCount", this.getOSLinuxUbuntuCount()); data.put("BrowserIECount", this.getBrowserIECount()); @@ -936,6 +942,10 @@ public class WebAppStat { osAndroid40Count.incrementAndGet(); } else if (userAgent.startsWith("4.1", toffset)) { osAndroid41Count.incrementAndGet(); + } else if (userAgent.startsWith("4.2", toffset)) { + osAndroid42Count.incrementAndGet(); + } else if (userAgent.startsWith("4.3", toffset)) { + osAndroid43Count.incrementAndGet(); } return true; @@ -1039,6 +1049,14 @@ public class WebAppStat { public long getOSAndroid41Count() { return osAndroid41Count.get(); } + + public long getOSAndroid42Count() { + return osAndroid42Count.get(); + } + + public long getOSAndroid43Count() { + return osAndroid43Count.get(); + } public long getOSLinuxUbuntuCount() { return osLinuxUbuntuCount.get(); diff --git a/src/test/java/com/alibaba/druid/bvt/support/http/UserAgentAndroid_4_2_Test_2.java b/src/test/java/com/alibaba/druid/bvt/support/http/UserAgentAndroid_4_2_Test_2.java new file mode 100644 index 0000000000..3f9d0f1c5c --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/support/http/UserAgentAndroid_4_2_Test_2.java @@ -0,0 +1,50 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.druid.bvt.support.http; + +import org.junit.Assert; +import junit.framework.TestCase; + +import com.alibaba.druid.support.http.stat.WebAppStat; + +public class UserAgentAndroid_4_2_Test_2 extends TestCase { + + public void test_mac_firefox() throws Exception { + WebAppStat stat = new WebAppStat(""); + stat.computeUserAgent("Mozilla/5.0 (Linux; U; Android 4.2; en-us; Nexus 10 Build/JVP15I) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30"); + Assert.assertEquals(0, stat.getBrowserChromeCount()); + Assert.assertEquals(0, stat.getBrowserFirefoxCount()); + Assert.assertEquals(0, stat.getBrowserOperaCount()); + Assert.assertEquals(0, stat.getBrowserSafariCount()); + Assert.assertEquals(0, stat.getBrowserIECount()); + Assert.assertEquals(0, stat.getBrowserIE10Count()); + + Assert.assertEquals(1, stat.getDeviceAndroidCount()); + Assert.assertEquals(0, stat.getDeviceIphoneCount()); + Assert.assertEquals(0, stat.getDeviceWindowsPhoneCount()); + + Assert.assertEquals(1, stat.getOSLinuxCount()); + Assert.assertEquals(1, stat.getOSAndroidCount()); + Assert.assertEquals(1, stat.getOSAndroid42Count()); + Assert.assertEquals(0, stat.getOSLinuxUbuntuCount()); + Assert.assertEquals(0, stat.getOSMacOSXCount()); + Assert.assertEquals(0, stat.getOSWindowsCount()); + Assert.assertEquals(0, stat.getOSWindows8Count()); + Assert.assertEquals(0, stat.getOSSymbianCount()); + Assert.assertEquals(0, stat.getOSFreeBSDCount()); + Assert.assertEquals(0, stat.getOSOpenBSDCount()); + } +} diff --git a/src/test/java/com/alibaba/druid/bvt/support/http/UserAgentAndroid_4_3_Test_2.java b/src/test/java/com/alibaba/druid/bvt/support/http/UserAgentAndroid_4_3_Test_2.java new file mode 100644 index 0000000000..dd4364854c --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/support/http/UserAgentAndroid_4_3_Test_2.java @@ -0,0 +1,50 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.druid.bvt.support.http; + +import org.junit.Assert; +import junit.framework.TestCase; + +import com.alibaba.druid.support.http.stat.WebAppStat; + +public class UserAgentAndroid_4_3_Test_2 extends TestCase { + + public void test_mac_firefox() throws Exception { + WebAppStat stat = new WebAppStat(""); + stat.computeUserAgent("Mozilla/5.0 (Linux; U; Android 4.3; en-us; Nexus 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36"); + Assert.assertEquals(1, stat.getBrowserChromeCount()); + Assert.assertEquals(0, stat.getBrowserFirefoxCount()); + Assert.assertEquals(0, stat.getBrowserOperaCount()); + Assert.assertEquals(0, stat.getBrowserSafariCount()); + Assert.assertEquals(0, stat.getBrowserIECount()); + Assert.assertEquals(0, stat.getBrowserIE10Count()); + + Assert.assertEquals(1, stat.getDeviceAndroidCount()); + Assert.assertEquals(0, stat.getDeviceIphoneCount()); + Assert.assertEquals(0, stat.getDeviceWindowsPhoneCount()); + + Assert.assertEquals(1, stat.getOSLinuxCount()); + Assert.assertEquals(1, stat.getOSAndroidCount()); + Assert.assertEquals(1, stat.getOSAndroid43Count()); + Assert.assertEquals(0, stat.getOSLinuxUbuntuCount()); + Assert.assertEquals(0, stat.getOSMacOSXCount()); + Assert.assertEquals(0, stat.getOSWindowsCount()); + Assert.assertEquals(0, stat.getOSWindows8Count()); + Assert.assertEquals(0, stat.getOSSymbianCount()); + Assert.assertEquals(0, stat.getOSFreeBSDCount()); + Assert.assertEquals(0, stat.getOSOpenBSDCount()); + } +}