useragent_parser 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/config/regexes.yaml +829 -0
- data/lib/useragent_parser/parsers/device_parser.rb +38 -0
- data/lib/useragent_parser/parsers/os_parser.rb +39 -0
- data/lib/useragent_parser/{parser.rb → parsers/user_agent_parser.rb} +3 -7
- data/lib/useragent_parser/user_agent.rb +31 -9
- data/lib/useragent_parser/version.rb +1 -1
- data/lib/useragent_parser.rb +70 -29
- data/spec/fixtures/additional_os_tests.yaml +134 -0
- data/spec/fixtures/firefox_user_agent_strings.yaml +804 -804
- data/spec/fixtures/pgts_browser_list.yaml +37489 -37489
- data/spec/fixtures/test_device.yaml +31 -0
- data/spec/fixtures/test_user_agent_parser.yaml +216 -687
- data/spec/fixtures/test_user_agent_parser_os.yaml +346 -0
- data/spec/parsers/device_parser_spec.rb +18 -0
- data/spec/parsers/os_parser_spec.rb +35 -0
- data/spec/{useragent_parser → parsers}/useragent_parser_spec.rb +16 -20
- data/spec/user_agent_spec.rb +190 -0
- data/spec/useragent_parser_spec.rb +34 -0
- metadata +44 -21
- data/config/user_agent_parser.yaml +0 -259
- data/spec/useragent_parser/user_agent_spec.rb +0 -169
@@ -0,0 +1,346 @@
|
|
1
|
+
test_cases:
|
2
|
+
|
3
|
+
- user_agent_string: 'Mozilla/5.0 (Linux x86_64) AppleWebKit/534.26+ WebKitGTK+/1.4.1 luakit/f3a2dbe'
|
4
|
+
family: 'Linux'
|
5
|
+
major:
|
6
|
+
minor:
|
7
|
+
patch:
|
8
|
+
patch_minor:
|
9
|
+
|
10
|
+
- user_agent_string: 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0) Gecko/20110408 conkeror/0.9.3'
|
11
|
+
family: 'Linux'
|
12
|
+
major:
|
13
|
+
minor:
|
14
|
+
patch:
|
15
|
+
patch_minor:
|
16
|
+
|
17
|
+
- user_agent_string: 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20110302 Conkeror/0.9.2 (Debian-0.9.2+git100804-1)'
|
18
|
+
family: 'Debian'
|
19
|
+
major: '0'
|
20
|
+
minor: '9'
|
21
|
+
patch: '2'
|
22
|
+
patch_minor:
|
23
|
+
|
24
|
+
- user_agent_string: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b3pre Thunderbird/3.1.10'
|
25
|
+
family: 'Windows XP'
|
26
|
+
major:
|
27
|
+
minor:
|
28
|
+
patch:
|
29
|
+
patch_minor:
|
30
|
+
|
31
|
+
- user_agent_string: 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 ThunderBrowse/3.3.5'
|
32
|
+
family: 'Windows 7'
|
33
|
+
major:
|
34
|
+
minor:
|
35
|
+
patch:
|
36
|
+
patch_minor:
|
37
|
+
|
38
|
+
- user_agent_string: 'Mozilla/5.0 (Windows; U; en-US) AppleWebKit/531.9 (KHTML, like Gecko) AdobeAIR/2.5.1'
|
39
|
+
family: 'Windows'
|
40
|
+
major:
|
41
|
+
minor:
|
42
|
+
patch:
|
43
|
+
patch_minor:
|
44
|
+
|
45
|
+
- user_agent_string: 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
|
46
|
+
family: 'Other'
|
47
|
+
major:
|
48
|
+
minor:
|
49
|
+
patch:
|
50
|
+
patch_minor:
|
51
|
+
|
52
|
+
- user_agent_string: 'Mozilla/5.0 YottaaMonitor;'
|
53
|
+
family: 'Other'
|
54
|
+
major:
|
55
|
+
minor:
|
56
|
+
patch:
|
57
|
+
patch_minor:
|
58
|
+
|
59
|
+
- user_agent_string: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) RockMelt/0.8.34.841 Chrome/6.0.472.63 Safari/534.3'
|
60
|
+
family: 'Windows XP'
|
61
|
+
major:
|
62
|
+
minor:
|
63
|
+
patch:
|
64
|
+
patch_minor:
|
65
|
+
|
66
|
+
- user_agent_string: 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0) Gecko/20110417 IceCat/4.0'
|
67
|
+
family: 'Linux'
|
68
|
+
major:
|
69
|
+
minor:
|
70
|
+
patch:
|
71
|
+
patch_minor:
|
72
|
+
|
73
|
+
- user_agent_string: 'Mozilla/5.0 (X11; U; Linux i686; nl-NL) AppleWebKit/534.3 (KHTML, like Gecko) WeTab-Browser Safari/534.3'
|
74
|
+
family: 'WeTab'
|
75
|
+
major:
|
76
|
+
minor:
|
77
|
+
patch:
|
78
|
+
patch_minor:
|
79
|
+
|
80
|
+
- user_agent_string: 'Mozilla/4.0 (compatible; Linux 2.6.10) NetFront/3.3 Kindle/1.0 (screen 600x800)'
|
81
|
+
family: 'Kindle'
|
82
|
+
major: '1'
|
83
|
+
minor: '0'
|
84
|
+
patch:
|
85
|
+
patch_minor:
|
86
|
+
|
87
|
+
- user_agent_string: 'Opera/9.80 (Android 3.2; Linux; Opera Tablet/ADR-1106291546; U; en) Presto/2.8.149 Version/11.10'
|
88
|
+
family: 'Android'
|
89
|
+
major: '3'
|
90
|
+
minor: '2'
|
91
|
+
patch:
|
92
|
+
patch_minor:
|
93
|
+
|
94
|
+
- user_agent_string: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) FireWeb/1.0.0.0'
|
95
|
+
family: 'Windows 7'
|
96
|
+
major:
|
97
|
+
minor:
|
98
|
+
patch:
|
99
|
+
patch_minor:
|
100
|
+
|
101
|
+
- user_agent_string: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Comodo_Dragon/4.1.1.11 Chrome/4.1.249.1042 Safari/532.5'
|
102
|
+
family: 'Windows XP'
|
103
|
+
major:
|
104
|
+
minor:
|
105
|
+
patch:
|
106
|
+
patch_minor:
|
107
|
+
|
108
|
+
- user_agent_string: 'Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5'
|
109
|
+
family: 'iOS'
|
110
|
+
major: '4'
|
111
|
+
minor: '3'
|
112
|
+
patch: '2'
|
113
|
+
patch_minor:
|
114
|
+
|
115
|
+
- user_agent_string: 'Mozilla/5.0 (Linux; U; Android 3.0.1; en-us; GT-P7510 Build/HRI83) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13'
|
116
|
+
family: 'Android'
|
117
|
+
major: '3'
|
118
|
+
minor: '0'
|
119
|
+
patch: '1'
|
120
|
+
patch_minor:
|
121
|
+
|
122
|
+
- user_agent_string: 'Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.58 Safari/534.6 TouchPad/1.0'
|
123
|
+
family: 'webOS'
|
124
|
+
major: '3'
|
125
|
+
minor: '0'
|
126
|
+
patch: '0'
|
127
|
+
patch_minor:
|
128
|
+
|
129
|
+
- user_agent_string: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; SAMSUNG; SGH-i917)'
|
130
|
+
family: 'Windows Phone OS'
|
131
|
+
major: '7'
|
132
|
+
minor: '0'
|
133
|
+
patch:
|
134
|
+
patch_minor:
|
135
|
+
|
136
|
+
|
137
|
+
- user_agent_string: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Safari/530.17 Skyfire/2.0'
|
138
|
+
family: 'Mac OS X'
|
139
|
+
major: '10'
|
140
|
+
minor: '5'
|
141
|
+
patch: '7'
|
142
|
+
patch_minor:
|
143
|
+
|
144
|
+
- user_agent_string: 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.8+ (KHTML, like Gecko) Version/0.0.1 Safari/534.8+'
|
145
|
+
family: 'BlackBerry Tablet OS'
|
146
|
+
major: '1'
|
147
|
+
minor: '0'
|
148
|
+
patch: '0'
|
149
|
+
patch_minor:
|
150
|
+
|
151
|
+
- user_agent_string: 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Ubuntu/10.10 Chromium/10.0.648.133 Chrome/10.0.648.133 Safari/534.16'
|
152
|
+
family: 'Ubuntu'
|
153
|
+
major: '10'
|
154
|
+
minor: '10'
|
155
|
+
patch:
|
156
|
+
patch_minor:
|
157
|
+
|
158
|
+
- user_agent_string: 'Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20110407 Firefox/4.0.3 PaleMoon/4.0.3'
|
159
|
+
family: 'Windows XP'
|
160
|
+
major:
|
161
|
+
minor:
|
162
|
+
patch:
|
163
|
+
patch_minor:
|
164
|
+
|
165
|
+
- user_agent_string: 'Opera/9.80 (Series 60; Opera Mini/6.24455/25.677; U; fr) Presto/2.5.25 Version/10.54'
|
166
|
+
family: 'Symbian OS'
|
167
|
+
major:
|
168
|
+
minor:
|
169
|
+
patch:
|
170
|
+
patch_minor:
|
171
|
+
|
172
|
+
- user_agent_string: 'Mozilla/5.0 (X11; Linux i686 (x86_64); rv:2.0b4) Gecko/20100818 Firefox/4.0b4'
|
173
|
+
family: 'Linux'
|
174
|
+
major:
|
175
|
+
minor:
|
176
|
+
patch:
|
177
|
+
patch_minor:
|
178
|
+
|
179
|
+
- user_agent_string: 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101027 Ubuntu/10.04 (lucid) Firefox/3.6.12'
|
180
|
+
family: 'Ubuntu'
|
181
|
+
major: '10'
|
182
|
+
minor: '04'
|
183
|
+
patch:
|
184
|
+
patch_minor:
|
185
|
+
|
186
|
+
- user_agent_string: 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.1pre) Gecko/20090717 Ubuntu/9.04 (jaunty) Shiretoko/3.5.1pre'
|
187
|
+
family: 'Ubuntu'
|
188
|
+
major: '9'
|
189
|
+
minor: '04'
|
190
|
+
patch:
|
191
|
+
patch_minor:
|
192
|
+
|
193
|
+
- user_agent_string: 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0b8pre) Gecko/20101031 Firefox-4.0/4.0b8pre'
|
194
|
+
family: 'Linux'
|
195
|
+
major:
|
196
|
+
minor:
|
197
|
+
patch:
|
198
|
+
patch_minor:
|
199
|
+
|
200
|
+
- user_agent_string: 'Mozilla/5.0 (X11; U; BSD Four; en-US) AppleWebKit/533.3 (KHTML, like Gecko) rekonq Safari/533.3'
|
201
|
+
family: 'BSD'
|
202
|
+
major:
|
203
|
+
minor:
|
204
|
+
patch:
|
205
|
+
patch_minor:
|
206
|
+
|
207
|
+
- user_agent_string: 'Mozilla/5.0 (X11; U; Linux; de-DE) AppleWebKit/527 (KHTML, like Gecko, Safari/419.3) konqueror/4.3.1'
|
208
|
+
family: 'Linux'
|
209
|
+
major:
|
210
|
+
minor:
|
211
|
+
patch:
|
212
|
+
patch_minor:
|
213
|
+
|
214
|
+
- user_agent_string: 'SomethingWeNeverKnewExisted'
|
215
|
+
family: 'Other'
|
216
|
+
major:
|
217
|
+
minor:
|
218
|
+
patch:
|
219
|
+
patch_minor:
|
220
|
+
|
221
|
+
- user_agent_string: 'Midori/0.2 (X11; Linux; U; en-us) WebKit/531.2 '
|
222
|
+
family: 'Linux'
|
223
|
+
major:
|
224
|
+
minor:
|
225
|
+
patch:
|
226
|
+
patch_minor:
|
227
|
+
|
228
|
+
- user_agent_string: 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.3a1) Gecko/20100208 MozillaDeveloperPreview/3.7a1 (.NET CLR 3.5.30729)'
|
229
|
+
family: 'Windows 7'
|
230
|
+
major:
|
231
|
+
minor:
|
232
|
+
patch:
|
233
|
+
patch_minor:
|
234
|
+
|
235
|
+
- user_agent_string: 'Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.5.24 Version/10.53'
|
236
|
+
family: 'Windows XP'
|
237
|
+
major:
|
238
|
+
minor:
|
239
|
+
patch:
|
240
|
+
patch_minor:
|
241
|
+
|
242
|
+
- user_agent_string: 'Opera/9.80 (S60; SymbOS; Opera Mobi/275; U; es-ES) Presto/2.4.13 Version/10.00'
|
243
|
+
family: 'Symbian OS'
|
244
|
+
major:
|
245
|
+
minor:
|
246
|
+
patch:
|
247
|
+
patch_minor:
|
248
|
+
|
249
|
+
- user_agent_string: 'Mozilla/5.0 (webOS/1.2; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Desktop/1.0'
|
250
|
+
family: 'webOS'
|
251
|
+
major: '1'
|
252
|
+
minor: '2'
|
253
|
+
patch:
|
254
|
+
patch_minor:
|
255
|
+
|
256
|
+
- user_agent_string: 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10'
|
257
|
+
family: 'iOS'
|
258
|
+
major: '3'
|
259
|
+
minor: '2'
|
260
|
+
patch:
|
261
|
+
patch_minor:
|
262
|
+
|
263
|
+
- user_agent_string: 'Mozilla/5.0 (SAMSUNG; SAMSUNG-GT-S8500/S8500XXJEE; U; Bada/1.0; nl-nl) AppleWebKit/533.1 (KHTML, like Gecko) Dolfin/2.0 Mobile WVGA SMM-MMS/1.2.0 OPN-B'
|
264
|
+
family: 'Bada'
|
265
|
+
major: '1'
|
266
|
+
minor: '0'
|
267
|
+
patch:
|
268
|
+
patch_minor:
|
269
|
+
|
270
|
+
- user_agent_string: 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; BOLT/2.101) AppleWebKit/530 (KHTML, like Gecko) Version/4.0 Safari/530.17'
|
271
|
+
family: 'Windows XP'
|
272
|
+
major:
|
273
|
+
minor:
|
274
|
+
patch:
|
275
|
+
patch_minor:
|
276
|
+
|
277
|
+
- user_agent_string: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/418.8 (KHTML, like Gecko) Safari/419.3'
|
278
|
+
family: 'Mac OS X'
|
279
|
+
major:
|
280
|
+
minor:
|
281
|
+
patch:
|
282
|
+
patch_minor:
|
283
|
+
|
284
|
+
- user_agent_string: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-us) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5'
|
285
|
+
family: 'Mac OS X'
|
286
|
+
major: '10'
|
287
|
+
minor: '6'
|
288
|
+
patch: '5'
|
289
|
+
patch_minor:
|
290
|
+
|
291
|
+
# BlackBerry devices
|
292
|
+
- user_agent_string: 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en-GB) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.141 Mobile Safari/534.1+'
|
293
|
+
family: 'BlackBerry OS'
|
294
|
+
major: '6'
|
295
|
+
minor: '0'
|
296
|
+
patch: '0'
|
297
|
+
patch_minor: '141'
|
298
|
+
|
299
|
+
- user_agent_string: 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en-US) AppleWebKit/534.1 (KHTML, like Gecko) Version/6.0.0.91 Mobile Safari/534.1 '
|
300
|
+
family: 'BlackBerry OS'
|
301
|
+
major: '6'
|
302
|
+
minor: '0'
|
303
|
+
patch: '0'
|
304
|
+
patch_minor: '91'
|
305
|
+
|
306
|
+
# Chrome
|
307
|
+
- user_agent_string: 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; chromeframe; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; Sleipnir 2.8.5)3.0.30729)'
|
308
|
+
js_ua: "{'js_user_agent_string': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.1 (KHTML, like Gecko) Chrome/2.0.169.1 Safari/530.1'}"
|
309
|
+
family: 'Windows XP'
|
310
|
+
major:
|
311
|
+
minor:
|
312
|
+
patch:
|
313
|
+
patch_minor:
|
314
|
+
|
315
|
+
- user_agent_string: 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; chromeframe; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729)'
|
316
|
+
js_ua: "{'js_user_agent_string': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.1 (KHTML, like Gecko) Chrome/2.0.169.1 Safari/530.1'}"
|
317
|
+
family: 'Windows Vista'
|
318
|
+
major:
|
319
|
+
minor:
|
320
|
+
patch:
|
321
|
+
patch_minor:
|
322
|
+
|
323
|
+
# Chrome Frame installed but not enabled
|
324
|
+
- user_agent_string: 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6; chromeframe; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)'
|
325
|
+
js_ua: "{'js_user_agent_string': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; chromeframe; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)'}"
|
326
|
+
family: 'Windows XP'
|
327
|
+
major:
|
328
|
+
minor:
|
329
|
+
patch:
|
330
|
+
patch_minor:
|
331
|
+
|
332
|
+
- user_agent_string: 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6; .NET CLR 2.0.50727; .NET CLR 1.1.4322)'
|
333
|
+
js_ua: "{'js_user_agent_string': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322)', 'js_user_agent_family': 'IE Platform Preview', 'js_user_agent_v1': '9', 'js_user_agent_v2': '0', 'js_user_agent_v3': '1'}"
|
334
|
+
family: 'Windows XP'
|
335
|
+
major:
|
336
|
+
minor:
|
337
|
+
patch:
|
338
|
+
patch_minor:
|
339
|
+
|
340
|
+
# version indeterminate. could also be windows phone 7.5
|
341
|
+
- user_agent_string: 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; XBLWP7; ZuneWP7)'
|
342
|
+
family: 'Windows Phone OS'
|
343
|
+
major:
|
344
|
+
minor:
|
345
|
+
patch:
|
346
|
+
patch_minor:
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe UseragentParser::DeviceParser do
|
6
|
+
YAML.load_file(File.expand_path(File.dirname(__FILE__)) + "/../fixtures/test_device.yaml")['test_cases'].each do |testcase|
|
7
|
+
it "should correctly parse the useragent header '#{testcase['user_agent_string']}'" do
|
8
|
+
if testcase['js_ua']
|
9
|
+
js_ua = eval(testcase['js_ua'].gsub("': '", "' => '"))
|
10
|
+
js_ua = [ js_ua['js_user_agent_string'], js_ua['js_user_agent_family'], js_ua['js_user_agent_v1'], js_ua['js_user_agent_v2'], js_ua['js_user_agent_v3'] ]
|
11
|
+
end
|
12
|
+
result = UseragentParser.parse_device(testcase['user_agent_string'], *js_ua)
|
13
|
+
result['family'].should == testcase['family']
|
14
|
+
result['is_mobile'].should == testcase['is_mobile']
|
15
|
+
result['is_spider'].should == testcase['is_spider']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe UseragentParser::OSParser do
|
6
|
+
YAML.load_file(File.expand_path(File.dirname(__FILE__)) + "/../fixtures/test_user_agent_parser_os.yaml")['test_cases'].each do |testcase|
|
7
|
+
it "should correctly parse the useragent header '#{testcase['user_agent_string']}'" do
|
8
|
+
if testcase['js_ua']
|
9
|
+
js_ua = eval(testcase['js_ua'].gsub("': '", "' => '"))
|
10
|
+
js_ua = [ js_ua['js_user_agent_string'], js_ua['js_user_agent_family'], js_ua['js_user_agent_v1'], js_ua['js_user_agent_v2'], js_ua['js_user_agent_v3'] ]
|
11
|
+
end
|
12
|
+
result = UseragentParser.parse_os(testcase['user_agent_string'], *js_ua)
|
13
|
+
result['family'].should == testcase['family']
|
14
|
+
result['major'].should == testcase['major']
|
15
|
+
result['minor'].should == testcase['minor']
|
16
|
+
result['patch'].should == testcase['patch']
|
17
|
+
result['patch_minor'].should == testcase['patch_minor']
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
YAML.load_file(File.expand_path(File.dirname(__FILE__)) + "/../fixtures/additional_os_tests.yaml")['test_cases'].each do |testcase|
|
22
|
+
it "should correctly parse the useragent header '#{testcase['user_agent_string']}'" do
|
23
|
+
if testcase['js_ua']
|
24
|
+
js_ua = eval(testcase['js_ua'].gsub("': '", "' => '"))
|
25
|
+
js_ua = [ js_ua['js_user_agent_string'], js_ua['js_user_agent_family'], js_ua['js_user_agent_v1'], js_ua['js_user_agent_v2'], js_ua['js_user_agent_v3'] ]
|
26
|
+
end
|
27
|
+
result = UseragentParser.parse_os(testcase['user_agent_string'], *js_ua)
|
28
|
+
result['family'].should == testcase['family']
|
29
|
+
result['major'].should == testcase['major']
|
30
|
+
result['minor'].should == testcase['minor']
|
31
|
+
result['patch'].should == testcase['patch']
|
32
|
+
result['patch_minor'].should == testcase['patch_minor']
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -2,22 +2,18 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe UseragentParser do
|
5
|
+
describe UseragentParser::UserAgentParser do
|
6
6
|
YAML.load_file(File.expand_path(File.dirname(__FILE__)) + "/../fixtures/test_user_agent_parser.yaml")['test_cases'].each do |testcase|
|
7
7
|
it "should correctly parse the useragent header '#{testcase['user_agent_string']}'" do
|
8
8
|
if testcase['js_ua']
|
9
9
|
js_ua = eval(testcase['js_ua'].gsub("': '", "' => '"))
|
10
10
|
js_ua = [ js_ua['js_user_agent_string'], js_ua['js_user_agent_family'], js_ua['js_user_agent_v1'], js_ua['js_user_agent_v2'], js_ua['js_user_agent_v3'] ]
|
11
11
|
end
|
12
|
-
result = UseragentParser.
|
13
|
-
result.
|
14
|
-
result.
|
15
|
-
result.
|
16
|
-
result.
|
17
|
-
result.os_family.should == testcase['os_family']
|
18
|
-
result.os_major_version.should == testcase['os_v1']
|
19
|
-
result.os_minor_version.should == testcase['os_v2']
|
20
|
-
result.os_patch_version.should == testcase['os_v3']
|
12
|
+
result = UseragentParser.parse_user_agent(testcase['user_agent_string'], *js_ua)
|
13
|
+
result['family'].should == testcase['family']
|
14
|
+
result['major'].should == testcase['major']
|
15
|
+
result['minor'].should == testcase['minor']
|
16
|
+
result['patch'].should == testcase['patch']
|
21
17
|
end
|
22
18
|
end
|
23
19
|
|
@@ -27,11 +23,11 @@ describe UseragentParser do
|
|
27
23
|
if testcase['js_ua']
|
28
24
|
js_ua = eval(testcase['js_ua'].gsub("': '", "' => '")).values
|
29
25
|
end
|
30
|
-
result = UseragentParser.
|
31
|
-
result.
|
32
|
-
result.
|
33
|
-
result.
|
34
|
-
result.
|
26
|
+
result = UseragentParser.parse_user_agent(testcase['user_agent_string'], *js_ua)
|
27
|
+
result['family'].should == testcase['family']
|
28
|
+
result['major'].should == testcase['major']
|
29
|
+
result['minor'].should == testcase['minor']
|
30
|
+
result['patch'].should == testcase['patch']
|
35
31
|
end
|
36
32
|
end
|
37
33
|
|
@@ -41,11 +37,11 @@ describe UseragentParser do
|
|
41
37
|
if testcase['js_ua']
|
42
38
|
js_ua = eval(testcase['js_ua'].gsub("': '", "' => '")).values
|
43
39
|
end
|
44
|
-
result = UseragentParser.
|
45
|
-
result.
|
46
|
-
result.
|
47
|
-
result.
|
48
|
-
result.
|
40
|
+
result = UseragentParser.parse_user_agent(testcase['user_agent_string'], *js_ua)
|
41
|
+
result['family'].should == testcase['family']
|
42
|
+
result['major'].should == testcase['major']
|
43
|
+
result['minor'].should == testcase['minor']
|
44
|
+
result['patch'].should == testcase['patch']
|
49
45
|
end
|
50
46
|
end
|
51
47
|
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe UseragentParser::UserAgent do
|
6
|
+
describe "for browser details" do
|
7
|
+
it "should report the browser family" do
|
8
|
+
UseragentParser::UserAgent.new({ 'user_agent' => { 'family' => 'Chrome', 'major' => '14', 'minor' => '0', 'patch' => '835' } }).browser_family.should == 'Chrome'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should report the browser major version" do
|
12
|
+
UseragentParser::UserAgent.new({ 'user_agent' => { 'family' => 'Chrome', 'major' => '14', 'minor' => '0', 'patch' => '835' } }).browser_major_version.should == '14'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should report the browser minor version" do
|
16
|
+
UseragentParser::UserAgent.new({ 'user_agent' => { 'family' => 'Chrome', 'major' => '14', 'minor' => '0', 'patch' => '835' } }).browser_minor_version.should == '0'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should report the browser patch version" do
|
20
|
+
UseragentParser::UserAgent.new({ 'user_agent' => { 'family' => 'Chrome', 'major' => '14', 'minor' => '0', 'patch' => '835' } }).browser_patch_version.should == '835'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should report the browser version" do
|
24
|
+
UseragentParser::UserAgent.new({ 'user_agent' => { 'family' => 'Chrome', 'major' => '14', 'minor' => '0', 'patch' => '835' } }).browser_version.should == '14.0.835'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should report the browser version without patch level" do
|
28
|
+
UseragentParser::UserAgent.new({ 'user_agent' => { 'family' => 'Firefox', 'major' => '5', 'minor' => '0' } }).browser_version.should == '5.0'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should report the browser version without minor version" do
|
32
|
+
UseragentParser::UserAgent.new({ 'user_agent' => { 'family' => 'Firefox', 'major' => '5' } }).browser_version.should == '5'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should report the browser family without version" do
|
36
|
+
UseragentParser::UserAgent.new({ 'user_agent' => { 'family' => 'Opera' } }).browser_version.should == ''
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "for device details" do
|
41
|
+
it "should report mobile classification" do
|
42
|
+
UseragentParser::UserAgent.new({ 'device' => { 'family' => nil, 'is_mobile' => false, 'is_spider' => false } }).is_mobile?.should be_false
|
43
|
+
UseragentParser::UserAgent.new({ 'device' => { 'family' => nil, 'is_mobile' => true, 'is_spider' => false } }).is_mobile?.should be_true
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should report spider classification" do
|
47
|
+
UseragentParser::UserAgent.new({ 'device' => { 'family' => nil, 'is_mobile' => false, 'is_spider' => false } }).is_spider?.should be_false
|
48
|
+
UseragentParser::UserAgent.new({ 'device' => { 'family' => nil, 'is_mobile' => false, 'is_spider' => true } }).is_spider?.should be_true
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should report device platform" do
|
52
|
+
UseragentParser::UserAgent.new({ 'device' => { 'family' => 'iPad', 'is_mobile' => true, 'is_spider' => false } }).device.should == "iPad"
|
53
|
+
UseragentParser::UserAgent.new({ 'device' => { 'family' => 'iPod', 'is_mobile' => true, 'is_spider' => false } }).device.should == "iPod"
|
54
|
+
UseragentParser::UserAgent.new({ 'device' => { 'family' => 'iPhone', 'is_mobile' => true, 'is_spider' => false } }).device.should == "iPhone"
|
55
|
+
UseragentParser::UserAgent.new({ 'device' => { 'family' => 'GT-P7510', 'is_mobile' => true, 'is_spider' => false } }).device.should == "GT-P7510"
|
56
|
+
UseragentParser::UserAgent.new({ 'device' => { 'family' => 'Blackberry Playbook', 'is_mobile' => true, 'is_spider' => false } }).device.should == "Blackberry Playbook"
|
57
|
+
UseragentParser::UserAgent.new({ 'device' => { 'family' => 'Spider', 'is_mobile' => false, 'is_spider' => true } }).device.should == "Spider"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "for operating system details" do
|
62
|
+
it "should report the os family" do
|
63
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows NT', 'major' => '3', 'minor' => '1' } }).os_family.should == 'Windows NT'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should report the major os version" do
|
67
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows NT', 'major' => '3', 'minor' => '1' } }).os_major_version.should == '3'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should report the minor os version" do
|
71
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows NT', 'major' => '3', 'minor' => '1' } }).os_minor_version.should == '1'
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should report the os patchlevel" do
|
75
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows NT', 'major' => '3', 'minor' => '1' } }).os_patch_version.should be_nil
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should report the os version" do
|
79
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows NT', 'major' => '3', 'minor' => '1' } }).os_version.should == '3.1'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should know the code name for Windows NT 3.1" do
|
83
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows NT', 'major' => '3', 'minor' => '1' } }).os.should == 'Microsoft Windows NT 3.1'
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should know the code name for Windows NT 3.5" do
|
87
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows NT', 'major' => '3', 'minor' => '5' } }).os.should == 'Microsoft Windows NT 3.5'
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should know the code name for Windows NT 4.0" do
|
91
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows NT', 'major' => '4', 'minor' => '0' } }).os.should == 'Microsoft Windows NT 4.0'
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should know the code name for Windows 2000" do
|
95
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows NT', 'major' => '5', 'minor' => '0' } }).os.should == 'Microsoft Windows 2000'
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should know the code name for Windows XP" do
|
99
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows NT', 'major' => '5', 'minor' => '1' } }).os.should == 'Microsoft Windows XP'
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should know the code name for Windows XP 64bit / Server 2003" do
|
103
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows NT', 'major' => '5', 'minor' => '2' } }).os.should == 'Microsoft Windows XP 64bit / Server 2003'
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should know the code name for Windows Vista / Server 2008" do
|
107
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows NT', 'major' => '6', 'minor' => '0' } }).os.should == 'Microsoft Windows Vista / Server 2008'
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should know the code name for Windows 7 / Server 2008 R2" do
|
111
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows NT', 'major' => '6', 'minor' => '1' } }).os.should == 'Microsoft Windows 7 / Server 2008 R2'
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should know the code name for Windows 8" do
|
115
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows NT', 'major' => '6', 'minor' => '2' } }).os.should == 'Microsoft Windows 8'
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should know the code name for Windows 3.1" do
|
119
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows', 'major' => '3', 'minor' => '1' } }).os.should == 'Microsoft Windows 3.1'
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should know the code name for Windows 95" do
|
123
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows', 'major' => '95' } }).os.should == 'Microsoft Windows 95'
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should know the code name for Windows 98" do
|
127
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows', 'major' => '98' } }).os.should == 'Microsoft Windows 98'
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should know the code name for Windows ME" do
|
131
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows', 'major' => 'ME' } }).os.should == 'Microsoft Windows ME'
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should know the code name for Windows 9x" do
|
135
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Windows', 'major' => '9x' } }).os.should == 'Microsoft Windows 9x'
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should know the code name for Mac OS X 10.0" do
|
139
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Mac OS X', 'major' => '10', 'minor' => '0' } }).os.should == 'Apple Mac OS X 10.0 (Cheetah)'
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should know the code name for Mac OS X 10.0" do
|
143
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Mac OS X', 'major' => '10', 'minor' => '0', 'patch' => 2 } }).os.should == 'Apple Mac OS X 10.0.2 (Cheetah)'
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should know the code name for Mac OS X 10.1" do
|
147
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Mac OS X', 'major' => '10', 'minor' => '1', 'patch' => 2 } }).os.should == 'Apple Mac OS X 10.1.2 (Puma)'
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should know the code name for Mac OS X 10.2" do
|
151
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Mac OS X', 'major' => '10', 'minor' => '2', 'patch' => 2 } }).os.should == 'Apple Mac OS X 10.2.2 (Jaguar)'
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should know the code name for Mac OS X 10.3" do
|
155
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Mac OS X', 'major' => '10', 'minor' => '3', 'patch' => 2 } }).os.should == 'Apple Mac OS X 10.3.2 (Panther)'
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should know the code name for Mac OS X 10.4" do
|
159
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Mac OS X', 'major' => '10', 'minor' => '4', 'patch' => 2 } }).os.should == 'Apple Mac OS X 10.4.2 (Tiger)'
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should know the code name for Mac OS X 10.5" do
|
163
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Mac OS X', 'major' => '10', 'minor' => '5', 'patch' => 2 } }).os.should == 'Apple Mac OS X 10.5.2 (Leopard)'
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should know the code name for Mac OS X 10.6" do
|
167
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Mac OS X', 'major' => '10', 'minor' => '6', 'patch' => 2 } }).os.should == 'Apple Mac OS X 10.6.2 (Snow Leopard)'
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should know the code name for Mac OS X 10.7" do
|
171
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Mac OS X', 'major' => '10', 'minor' => '7', 'patch' => '2' } }).os.should == 'Apple Mac OS X 10.7.2 (Lion)'
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should provide a generic os/version for other operating systems" do
|
175
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Linux', 'major' => '2', 'minor' => '6', 'patch' => '32' } }).os.should == 'Linux 2.6.32'
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should provide a generic os name without version" do
|
179
|
+
UseragentParser::UserAgent.new({ 'os' => { 'family' => 'FreeBSD' } }).os.should == 'FreeBSD'
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should combing operating system and browser version" do
|
184
|
+
ua = UseragentParser::UserAgent.new({ 'os' => { 'family' => 'Mac OS X', 'major' => '10', 'minor' => '7', 'patch' => '2' }, 'user_agent' => { 'family' => 'Chrome', 'major' => '14', 'minor' => '0', 'patch' => '835' } })
|
185
|
+
ua.browser_family.should == 'Chrome'
|
186
|
+
ua.browser_version.should == '14.0.835'
|
187
|
+
ua.os_family.should == 'Mac OS X'
|
188
|
+
ua.os_version.should == '10.7.2'
|
189
|
+
end
|
190
|
+
end
|