browser_detector 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,6 +20,33 @@ module BrowserDetector
20
20
  @g_browser_detector.browser_version
21
21
  end
22
22
 
23
+ # Returns the major version of the browser that is making this request. For example '7'. When using
24
+ # the browser detector in the contoller you may put a :g_browser_detector variabe in the session if
25
+ # you wish to keep the BrowserDetector from being instantiated more than once per request.
26
+ #
27
+ def g_browser_version_major
28
+ setup_detector
29
+ @g_browser_detector.browser_version_major
30
+ end
31
+
32
+ # Returns the major version of the browser that is making this request. For example '7'. When using
33
+ # the browser detector in the contoller you may put a :g_browser_detector variabe in the session if
34
+ # you wish to keep the BrowserDetector from being instantiated more than once per request.
35
+ #
36
+ def g_browser_version_minor
37
+ setup_detector
38
+ @g_browser_detector.browser_version_minor
39
+ end
40
+
41
+ # Returns the major version of the browser that is making this request. For example '7'. When using
42
+ # the browser detector in the contoller you may put a :g_browser_detector variabe in the session if
43
+ # you wish to keep the BrowserDetector from being instantiated more than once per request.
44
+ #
45
+ def g_browser_version_build
46
+ setup_detector
47
+ @g_browser_detector.browser_version_build
48
+ end
49
+
23
50
  # Returns the full browser name. For example, 'Internet Explorer 7.0'.
24
51
  #
25
52
  def g_browser_full_name
@@ -0,0 +1,158 @@
1
+ shared_examples_for "any browser detection" do
2
+ it "should agree that the browser name is '#{vars[:browser_name]}'" do
3
+ detector.browser_name.should == vars[:browser_name]
4
+ end
5
+
6
+ it "should agree that the browser version is '#{vars[:browser_version]}'" do
7
+ detector.browser_version.should == vars[:browser_version]
8
+ end
9
+
10
+ it "should agree that the browser major version is '#{vars[:browser_version_major]}'" do
11
+ detector.browser_version_major.should == vars[:browser_version_major]
12
+ end
13
+
14
+ it "should agree that the browser minor version is '#{vars[:browser_version_minor]}'" do
15
+ detector.browser_version_minor.should == vars[:browser_version_minor]
16
+ end
17
+
18
+ it "should agree that the browser build version is '#{vars[:browser_version_build]}'" do
19
+ detector.browser_version_build.should == vars[:browser_version_build]
20
+ end
21
+
22
+ it "should agree that the browser revision version is '#{vars[:browser_version_revision]}'" do
23
+ detector.browser_version_revision.should == vars[:browser_version_revision]
24
+ end
25
+
26
+ it "should have a browser id of '#{vars[:browser_id]}'" do
27
+ detector.browser_id.should == vars[:browser_id]
28
+ end
29
+
30
+ it "should have a browser full name of '#{vars[:browser_full_name]}'" do
31
+ detector.browser_full_name.should == vars[:browser_full_name]
32
+ end
33
+
34
+ it "should #{vars[:can_use_png] ? '' : 'not '}be able to use a png" do
35
+ detector.can_use_png?.should == vars[:can_use_png]
36
+ end
37
+
38
+ it "should agree that the browser is '#{vars[:browser_name]}" do
39
+ detector.browser_is?( :name => vars[:browser_name] ).should be_true
40
+ end
41
+
42
+ it "should agree that the browser is :version => '#{vars[:browser_version]}'" do
43
+ detector.browser_is?( :version => vars[:browser_version] ).should be_true
44
+ end
45
+
46
+ it "should agree that the browser is :name => '#{vars[:browser_name]}' and :version => '#{vars[:browser_version]}'" do
47
+ detector.browser_is?( :name => vars[:browser_name],
48
+ :version => vars[:browser_version] ).should be_true
49
+ end
50
+
51
+ it "should agree that the browser is :name => '#{vars[:browser_name]}'.to_sym and :version => '#{vars[:browser_version]}'" do
52
+ detector.browser_is?( :name => vars[:browser_name].to_sym,
53
+ :version => vars[:browser_version] ).should be_true
54
+ end
55
+
56
+ it "should agree that the browser is :major_version => '#{vars[:browser_version_major]}'" do
57
+ detector.browser_is?( :major_version => vars[:browser_version_major] ).should be_true
58
+ end
59
+
60
+ it "should agree that the browser is :minor_version => '#{vars[:browser_version_minor]}'" do
61
+ detector.browser_is?( :minor_version => vars[:browser_version_minor] ).should be_true
62
+ end
63
+
64
+ it "should agree that the browser is :build_version => '#{vars[:browser_version_build]}'" do
65
+ detector.browser_is?( :build_version => vars[:browser_version_build] ).should be_true
66
+ end
67
+
68
+ it "should agree that the browser is :revision_version => '#{vars[:browser_version_revision]}'" do
69
+ detector.browser_is?( :revision_version => vars[:browser_version_revision] ).should be_true
70
+ end
71
+
72
+ it "should agree that the browser is :major_version => '#{vars[:browser_version_major]}', :minor_version => '#{vars[:browser_version_minor]}'" do
73
+ detector.browser_is?( :major_version => vars[:browser_version_major],
74
+ :minor_version => vars[:browser_version_minor] ).should be_true
75
+ end
76
+
77
+ it "should agree that the browser is :major_version => '#{vars[:browser_version_major]}', :minor_version => '#{vars[:browser_version_minor]}', :build_version => '#{vars[:browser_version_build]}'" do
78
+ detector.browser_is?( :major_version => vars[:browser_version_major],
79
+ :minor_version => vars[:browser_version_minor],
80
+ :build_version => vars[:browser_version_build] ).should be_true
81
+ end
82
+
83
+ it "should agree that the browser is :major_version => '#{vars[:browser_version_major]}', :minor_version => '#{vars[:browser_version_minor]}', :build_version => '#{vars[:browser_version_build]}', :revision_version => '#{vars[:browser_version_revision]}'" do
84
+ detector.browser_is?( :major_version => vars[:browser_version_major],
85
+ :minor_version => vars[:browser_version_minor],
86
+ :build_version => vars[:browser_version_build],
87
+ :revision_version => vars[:browser_version_revision] ).should be_true
88
+ end
89
+
90
+ it "should agree that the browser is :name => '#{vars[:browser_name]}', :major_version => '#{vars[:browser_version_major]}'" do
91
+ detector.browser_is?( :name => vars[:browser_name],
92
+ :major_version => vars[:browser_version_major] ).should be_true
93
+ end
94
+
95
+ it "should agree that the browser is :name => '#{vars[:browser_name]}', :minor_version => '#{vars[:browser_version_minor]}'" do
96
+ detector.browser_is?( :name => vars[:browser_name],
97
+ :minor_version => vars[:browser_version_minor] ).should be_true
98
+ end
99
+
100
+ it "should agree that the browser is :name => '#{vars[:browser_name]}', :build_version => '#{vars[:browser_version_build]}'" do
101
+ detector.browser_is?( :name => vars[:browser_name],
102
+ :build_version => vars[:browser_version_build] ).should be_true
103
+ end
104
+
105
+ it "should agree that the browser is :name => '#{vars[:browser_name]}', :revision_version => '#{vars[:browser_version_revision]}'" do
106
+ detector.browser_is?( :name => vars[:browser_name],
107
+ :revision_version => vars[:browser_version_revision] ).should be_true
108
+ end
109
+
110
+ it "should agree that the browser is :name => '#{vars[:browser_name]}', :major_version => '#{vars[:browser_version_major]}'.to_i" do
111
+ detector.browser_is?( :name => vars[:browser_name],
112
+ :major_version => vars[:browser_version_major].to_i ).should be_true
113
+ end
114
+
115
+ it "should agree that the browser is :name => '#{vars[:browser_name]}', :minor_version => '#{vars[:browser_version_minor]}'.to_i" do
116
+ detector.browser_is?( :name => vars[:browser_name],
117
+ :minor_version => vars[:browser_version_minor].to_i ).should be_true
118
+ end
119
+
120
+ it "should agree that the browser is :name => '#{vars[:browser_name]}', :build_version => '#{vars[:browser_version_build]}'.to_i" do
121
+ detector.browser_is?( :name => vars[:browser_name],
122
+ :build_version => vars[:browser_version_build].to_i ).should be_true
123
+ end
124
+
125
+ it "should agree that the browser is :name => '#{vars[:browser_name]}', :revision_version => '#{vars[:browser_version_revision]}'.to_i" do
126
+ detector.browser_is?( :name => vars[:browser_name],
127
+ :revision_version => vars[:browser_version_revision].to_i ).should be_true
128
+ end
129
+
130
+ it "should agree that the browser is :name => '#{vars[:browser_name]}', :major_version => '#{vars[:browser_version_major]}', :minor_version => '#{vars[:browser_version_minor]}'" do
131
+ detector.browser_is?( :name => vars[:browser_name],
132
+ :major_version => vars[:browser_version_major],
133
+ :minor_version => vars[:browser_version_minor] ).should be_true
134
+ end
135
+
136
+ it "should agree that the browser is :name => '#{vars[:browser_name]}', :major_version => '#{vars[:browser_version_major]}', :minor_version => '#{vars[:browser_version_minor]}', :build_version => '#{vars[:browser_version_build]}'" do
137
+ detector.browser_is?( :name => vars[:browser_name],
138
+ :major_version => vars[:browser_version_major],
139
+ :minor_version => vars[:browser_version_minor],
140
+ :build_version => vars[:browser_version_build] ).should be_true
141
+ end
142
+
143
+ it "should agree that the browser is :name => '#{vars[:browser_name]}', :major_version => '#{vars[:browser_version_major]}', :minor_version => '#{vars[:browser_version_minor]}', :build_version => '#{vars[:browser_version_build]}', :revision_version => '#{vars[:browser_version_revision]}'" do
144
+ detector.browser_is?( :name => vars[:browser_name],
145
+ :major_version => vars[:browser_version_major],
146
+ :minor_version => vars[:browser_version_minor],
147
+ :build_version => vars[:browser_version_build],
148
+ :revision_version => vars[:browser_version_revision]).should be_true
149
+ end
150
+
151
+ it "should agree that it is #{vars[:is_webkit] ? '' : 'not '}a webkit browser" do
152
+ detector.webkit?.should == vars[:is_webkit]
153
+ end
154
+
155
+ it "should agree that it is #{vars[:is_iphone] ? '' : 'not '}the iphone" do
156
+ detector.iphone?.should == vars[:is_iphone]
157
+ end
158
+ end
@@ -0,0 +1,475 @@
1
+ require 'spec_helper'
2
+ require File.join( File.dirname(__FILE__), 'detector_shared_specs' )
3
+
4
+ describe BrowserDetector::Detector do
5
+ before :each do
6
+ @klass = BrowserDetector::Detector
7
+ end
8
+
9
+ def self.user_agents
10
+ {
11
+ :ie55 => 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1)',
12
+ :ie60 => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
13
+ :ie70 => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
14
+ :ie80 => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
15
+ :firefox2 => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.17) Gecko/20080829 Firefox/2.0.0.17',
16
+ :firefox3 => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.0.11) Gecko/2009060214 Firefox/3.0.11',
17
+ :firefox35 => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3',
18
+ :firefox35win => 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)',
19
+ :opera10 => 'Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/10.00',
20
+ :safari40 => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16',
21
+ :safari501 => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us) AppleWebKit/533.17.8 (KHTML, like Gecko) Version/5.0.1 Safari/533.17.8',
22
+ :chrome3 => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.27 Safari/532.0',
23
+ :chrome4 => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_1; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Chrome/4.0.221.8 Safari/532.2',
24
+ :safari_mobile4 => 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7C144 Safari/528.16',
25
+ :safari_mobile3 => 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A535b Safari/419.3'
26
+ }
27
+ end
28
+
29
+ def user_agents
30
+ self.class.user_agents
31
+ end
32
+
33
+ it "should have the correct value for IE_REGEX" do
34
+ @klass::IE_REGEX.should == /.*; MSIE ([\d|.]*);.*/i
35
+ end
36
+
37
+ it "should have the correct value for OPERA_REGEX" do
38
+ @klass::OPERA_REGEX.should == /Opera.*Version\/([\d|.]*)/i
39
+ end
40
+
41
+ it "should have the crrect value for CHROME_REGEX" do
42
+ @klass::CHROME_REGEX.should == /.* Chrome\/([\d|.]*).*/i
43
+ end
44
+
45
+ it "should have the crrect value for SAFARI_REGEX" do
46
+ @klass::SAFARI_REGEX.should == /.*Gecko\) Version\/([\d|.]*) Safari\/[\d|.]*/i
47
+ end
48
+
49
+ it "should have the crrect value for VERSION_REGEX" do
50
+ @klass::VERSION_REGEX.should == /(\d*)\.(\d*)\.*(\d*)\.*(\d*)/
51
+ end
52
+
53
+ it "should have the crrect value for FIREFOX_REGEX" do
54
+ @klass::FIREFOX_REGEX.should == /.* Firefox\/([\d|.]*).*/i
55
+ end
56
+
57
+ it "should have the crrect value for SAFARI_MOBILE_REGEX" do
58
+ @klass::SAFARI_MOBILE_REGEX.should == /.*Gecko\) Version\/([\d|.]*) Mobile\/.* Safari\/[\d|.]*/i
59
+ end
60
+
61
+ it "should have the correct patterns collection" do
62
+ @klass.patterns.should == {
63
+ @klass::CHROME_REGEX => 'chrome',
64
+ @klass::IE_REGEX => 'ie',
65
+ @klass::FIREFOX_REGEX => 'firefox',
66
+ @klass::OPERA_REGEX => 'opera',
67
+ @klass::SAFARI_REGEX => 'safari',
68
+ @klass::SAFARI_MOBILE_REGEX => 'safari_mobile'
69
+ }
70
+ end
71
+
72
+ it "should not depend on the order the user agent is tested against the REGEXs"
73
+
74
+ it "should know the correct known browser ids" do
75
+ @klass.all_browsers.sort.should == %w(chrome firefox ie55 ie60 ie70 ie80 konqueror netscape opera safari).sort
76
+ end
77
+
78
+ it "should know the correct known mobile browser ids" do
79
+ @klass.all_mobile_browsers.sort.should == %w(ie_ce4).sort
80
+ end
81
+
82
+ context "when given a nil user agent" do
83
+ before :each do
84
+ @detector = @klass.new( nil )
85
+ @detector.ua.should be_nil
86
+ end
87
+
88
+ it "should agree that the browser name is 'unknown'" do
89
+ @detector.browser_name.should == 'unknown'
90
+ end
91
+ end
92
+
93
+ context "when given Firefox 2.0 user agent" do
94
+ def detector
95
+ BrowserDetector::Detector.new( self.user_agents[:firefox2] )
96
+ end
97
+
98
+ def self.vars
99
+ {
100
+ :browser_name => 'firefox',
101
+ :browser_version => '2.0.0.17',
102
+ :browser_version_major => '2',
103
+ :browser_version_minor => '0',
104
+ :browser_version_build => '0',
105
+ :browser_version_revision => '17',
106
+ :browser_id => 'firefox20017',
107
+ :browser_full_name => 'Firefox 2.0.0.17',
108
+ :can_use_png => true,
109
+ :is_webkit => false,
110
+ :is_iphone => false
111
+ }
112
+ end
113
+ def vars; self.class.vars; end
114
+
115
+ it_should_behave_like "any browser detection"
116
+ end
117
+
118
+ context "when given Firefox 3.0 user agent" do
119
+ def detector
120
+ BrowserDetector::Detector.new( self.user_agents[:firefox3] )
121
+ end
122
+
123
+ def self.vars
124
+ {
125
+ :browser_name => 'firefox',
126
+ :browser_version => '3.0.11',
127
+ :browser_version_major => '3',
128
+ :browser_version_minor => '0',
129
+ :browser_version_build => '11',
130
+ :browser_version_revision => '0',
131
+ :browser_id => 'firefox3011',
132
+ :browser_full_name => 'Firefox 3.0.11',
133
+ :can_use_png => true,
134
+ :is_webkit => false,
135
+ :is_iphone => false
136
+ }
137
+ end
138
+ def vars; self.class.vars; end
139
+
140
+ it_should_behave_like "any browser detection"
141
+ end
142
+
143
+ context "when given Firefox 3.5 user agent" do
144
+ def detector
145
+ BrowserDetector::Detector.new( self.user_agents[:firefox35] )
146
+ end
147
+
148
+ def self.vars
149
+ {
150
+ :browser_name => 'firefox',
151
+ :browser_version => '3.5.3',
152
+ :browser_version_major => '3',
153
+ :browser_version_minor => '5',
154
+ :browser_version_build => '3',
155
+ :browser_version_revision => '0',
156
+ :browser_id => 'firefox353',
157
+ :browser_full_name => 'Firefox 3.5.3',
158
+ :can_use_png => true,
159
+ :is_webkit => false,
160
+ :is_iphone => false
161
+ }
162
+ end
163
+ def vars; self.class.vars; end
164
+
165
+ it_should_behave_like "any browser detection"
166
+ end
167
+
168
+ context "when given Firefox 3.5 Windows user agent" do
169
+ def detector
170
+ BrowserDetector::Detector.new( self.user_agents[:firefox35win] )
171
+ end
172
+
173
+ def self.vars
174
+ {
175
+ :browser_name => 'firefox',
176
+ :browser_version => '3.5.3',
177
+ :browser_version_major => '3',
178
+ :browser_version_minor => '5',
179
+ :browser_version_build => '3',
180
+ :browser_version_revision => '0',
181
+ :browser_id => 'firefox353',
182
+ :browser_full_name => 'Firefox 3.5.3',
183
+ :can_use_png => true,
184
+ :is_webkit => false,
185
+ :is_iphone => false
186
+ }
187
+ end
188
+ def vars; self.class.vars; end
189
+
190
+ it_should_behave_like "any browser detection"
191
+ end
192
+
193
+ context "when given Opera 10.0 user agent" do
194
+ def detector
195
+ BrowserDetector::Detector.new( self.user_agents[:opera10] )
196
+ end
197
+
198
+ def self.vars
199
+ {
200
+ :browser_name => 'opera',
201
+ :browser_version => '10.00',
202
+ :browser_version_major => '10',
203
+ :browser_version_minor => '0',
204
+ :browser_version_build => '0',
205
+ :browser_version_revision => '0',
206
+ :browser_id => 'opera1000',
207
+ :browser_full_name => 'Opera 10.00',
208
+ :can_use_png => true,
209
+ :is_webkit => false,
210
+ :is_iphone => false
211
+ }
212
+ end
213
+ def vars; self.class.vars; end
214
+
215
+ it_should_behave_like "any browser detection"
216
+ end
217
+
218
+ context "when given IE 5.5 user agent" do
219
+ def detector
220
+ BrowserDetector::Detector.new( self.user_agents[:ie55] )
221
+ end
222
+
223
+ def self.vars
224
+ {
225
+ :browser_name => 'ie',
226
+ :browser_version => '5.5',
227
+ :browser_version_major => '5',
228
+ :browser_version_minor => '5',
229
+ :browser_version_build => '0',
230
+ :browser_version_revision => '0',
231
+ :browser_id => 'ie55',
232
+ :browser_full_name => 'Internet Explorer 5.5',
233
+ :can_use_png => false,
234
+ :is_webkit => false,
235
+ :is_iphone => false
236
+ }
237
+ end
238
+ def vars; self.class.vars; end
239
+
240
+ it_should_behave_like "any browser detection"
241
+ end
242
+
243
+ context "when given IE 6.0 user agent" do
244
+ def detector
245
+ BrowserDetector::Detector.new( self.user_agents[:ie60] )
246
+ end
247
+
248
+ def self.vars
249
+ {
250
+ :browser_name => 'ie',
251
+ :browser_version => '6.0',
252
+ :browser_version_major => '6',
253
+ :browser_version_minor => '0',
254
+ :browser_version_build => '0',
255
+ :browser_version_revision => '0',
256
+ :browser_id => 'ie60',
257
+ :browser_full_name => 'Internet Explorer 6.0',
258
+ :can_use_png => false,
259
+ :is_webkit => false,
260
+ :is_iphone => false
261
+ }
262
+ end
263
+ def vars; self.class.vars; end
264
+
265
+ it_should_behave_like "any browser detection"
266
+ end
267
+
268
+ context "when given IE 7.0 user agent" do
269
+ def detector
270
+ BrowserDetector::Detector.new( self.user_agents[:ie70] )
271
+ end
272
+
273
+ def self.vars
274
+ {
275
+ :browser_name => 'ie',
276
+ :browser_version => '7.0',
277
+ :browser_version_major => '7',
278
+ :browser_version_minor => '0',
279
+ :browser_version_build => '0',
280
+ :browser_version_revision => '0',
281
+ :browser_id => 'ie70',
282
+ :browser_full_name => 'Internet Explorer 7.0',
283
+ :can_use_png => true,
284
+ :is_webkit => false,
285
+ :is_iphone => false
286
+ }
287
+ end
288
+ def vars; self.class.vars; end
289
+
290
+ it_should_behave_like "any browser detection"
291
+ end
292
+
293
+ context "when given IE 8.0 user agent" do
294
+ def detector
295
+ BrowserDetector::Detector.new( self.user_agents[:ie80] )
296
+ end
297
+
298
+ def self.vars
299
+ {
300
+ :browser_name => 'ie',
301
+ :browser_version => '8.0',
302
+ :browser_version_major => '8',
303
+ :browser_version_minor => '0',
304
+ :browser_version_build => '0',
305
+ :browser_version_revision => '0',
306
+ :browser_id => 'ie80',
307
+ :browser_full_name => 'Internet Explorer 8.0',
308
+ :can_use_png => true,
309
+ :is_webkit => false,
310
+ :is_iphone => false
311
+ }
312
+ end
313
+ def vars; self.class.vars; end
314
+
315
+ it_should_behave_like "any browser detection"
316
+ end
317
+
318
+ context "when given Safari 4.0 user agent" do
319
+ def detector
320
+ BrowserDetector::Detector.new( self.user_agents[:safari40] )
321
+ end
322
+
323
+ def self.vars
324
+ {
325
+ :browser_name => 'safari',
326
+ :browser_version => '4.0',
327
+ :browser_version_major => '4',
328
+ :browser_version_minor => '0',
329
+ :browser_version_build => '0',
330
+ :browser_version_revision => '0',
331
+ :browser_id => 'safari40',
332
+ :browser_full_name => 'Safari 4.0',
333
+ :can_use_png => true,
334
+ :is_webkit => true,
335
+ :is_iphone => false
336
+ }
337
+ end
338
+ def vars; self.class.vars; end
339
+
340
+ it_should_behave_like "any browser detection"
341
+ end
342
+
343
+ context "when given Safari 5.0.1 user agent" do
344
+ def detector
345
+ BrowserDetector::Detector.new( self.user_agents[:safari501] )
346
+ end
347
+
348
+ def self.vars
349
+ {
350
+ :browser_name => 'safari',
351
+ :browser_version => '5.0.1',
352
+ :browser_version_major => '5',
353
+ :browser_version_minor => '0',
354
+ :browser_version_build => '1',
355
+ :browser_version_revision => '0',
356
+ :browser_id => 'safari501',
357
+ :browser_full_name => 'Safari 5.0.1',
358
+ :can_use_png => true,
359
+ :is_webkit => true,
360
+ :is_iphone => false
361
+ }
362
+ end
363
+ def vars; self.class.vars; end
364
+
365
+ it_should_behave_like "any browser detection"
366
+ end
367
+
368
+ context "when given Chrome 3.0.195.27 user agent" do
369
+ def detector
370
+ BrowserDetector::Detector.new( self.user_agents[:chrome3] )
371
+ end
372
+
373
+ def self.vars
374
+ {
375
+ :browser_name => 'chrome',
376
+ :browser_version => '3.0.195.27',
377
+ :browser_version_major => '3',
378
+ :browser_version_minor => '0',
379
+ :browser_version_build => '195',
380
+ :browser_version_revision => '27',
381
+ :browser_id => 'chrome3019527',
382
+ :browser_full_name => 'Chrome 3.0.195.27',
383
+ :can_use_png => true,
384
+ :is_webkit => true,
385
+ :is_iphone => false
386
+ }
387
+ end
388
+ def vars; self.class.vars; end
389
+
390
+ it_should_behave_like "any browser detection"
391
+ end
392
+
393
+ context "when given Chrome 4.0.221.8 user agent" do
394
+ def detector
395
+ BrowserDetector::Detector.new( self.user_agents[:chrome4] )
396
+ end
397
+
398
+ def self.vars
399
+ {
400
+ :browser_name => 'chrome',
401
+ :browser_version => '4.0.221.8',
402
+ :browser_version_major => '4',
403
+ :browser_version_minor => '0',
404
+ :browser_version_build => '221',
405
+ :browser_version_revision => '8',
406
+ :browser_id => 'chrome402218',
407
+ :browser_full_name => 'Chrome 4.0.221.8',
408
+ :can_use_png => true,
409
+ :is_webkit => true,
410
+ :is_iphone => false
411
+ }
412
+ end
413
+ def vars; self.class.vars; end
414
+
415
+ it_should_behave_like "any browser detection"
416
+ end
417
+
418
+ context "when given Safari Mobile 3.0 user agent" do
419
+ def detector
420
+ BrowserDetector::Detector.new( self.user_agents[:safari_mobile3] )
421
+ end
422
+
423
+ def self.vars
424
+ {
425
+ :browser_name => 'safari_mobile',
426
+ :browser_version => '3.0',
427
+ :browser_version_major => '3',
428
+ :browser_version_minor => '0',
429
+ :browser_version_build => '0',
430
+ :browser_version_revision => '0',
431
+ :browser_id => 'safari_mobile30',
432
+ :browser_full_name => 'Safari Mobile 3.0',
433
+ :can_use_png => true,
434
+ :is_webkit => true,
435
+ :is_iphone => true
436
+ }
437
+ end
438
+ def vars; self.class.vars; end
439
+
440
+ it_should_behave_like "any browser detection"
441
+ end
442
+
443
+ context "when given Safari Mobile 4.0 user agent" do
444
+ def detector
445
+ BrowserDetector::Detector.new( self.user_agents[:safari_mobile4] )
446
+ end
447
+
448
+ def self.vars
449
+ {
450
+ :browser_name => 'safari_mobile',
451
+ :browser_version => '4.0',
452
+ :browser_version_major => '4',
453
+ :browser_version_minor => '0',
454
+ :browser_version_build => '0',
455
+ :browser_version_revision => '0',
456
+ :browser_id => 'safari_mobile40',
457
+ :browser_full_name => 'Safari Mobile 4.0',
458
+ :can_use_png => true,
459
+ :is_webkit => true,
460
+ :is_iphone => true
461
+ }
462
+ end
463
+ def vars; self.class.vars; end
464
+
465
+ it_should_behave_like "any browser detection"
466
+ end
467
+
468
+ context "having sample user agents" do
469
+ user_agents.each do |key, value|
470
+ it "should have the correct sample user agent for the '#{key}' browser" do
471
+ @klass.user_agents[key].should == value
472
+ end
473
+ end
474
+ end
475
+ end