browser 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,1141 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require "spec_helper"
3
-
4
- describe Browser do
5
- before do
6
- @browser = Browser.new
7
- Browser::Bots.instance_variable_set("@detect_empty_ua", false)
8
- end
9
-
10
- it "yields self when block is given" do
11
- browser = nil
12
- Browser.new {|b| browser = b }
13
- assert_kind_of Browser, browser
14
- end
15
-
16
- it "responds to ua methods" do
17
- assert @browser.respond_to?(:ua)
18
- assert @browser.respond_to?(:ua=)
19
- end
20
-
21
- it "delegates ua methods" do
22
- @browser.user_agent = "Safari"
23
- assert_equal "Safari", @browser.ua
24
-
25
- @browser.ua = "Mozilla"
26
- assert_equal "Mozilla", @browser.user_agent
27
- end
28
-
29
- it "sets accept language while instantiating object" do
30
- @browser = Browser.new(:accept_language => "pt-br")
31
- assert_equal ["pt-br"], @browser.accept_language
32
- end
33
-
34
- it "sets user agent while instantianting object" do
35
- @browser = Browser.new(:ua => "Safari")
36
- assert_equal "Safari", @browser.ua
37
-
38
- @browser = Browser.new(:user_agent => "Chrome")
39
- assert_equal "Chrome", @browser.ua
40
- end
41
-
42
- it "detects iphone" do
43
- @browser.ua = $ua["IPHONE"]
44
-
45
- assert_equal "iPhone", @browser.name
46
- assert @browser.iphone?
47
- assert @browser.safari?
48
- assert @browser.webkit?
49
- assert @browser.mobile?
50
- assert @browser.modern?
51
- assert @browser.ios?
52
- refute @browser.tablet?
53
- refute @browser.mac?
54
- assert_equal "3.0", @browser.full_version
55
- assert_equal "3", @browser.version
56
- end
57
-
58
- it "detects safari" do
59
- @browser.ua = $ua["SAFARI"]
60
-
61
- assert_equal "Safari", @browser.name
62
- assert @browser.safari?
63
- assert @browser.webkit?
64
- assert @browser.modern?
65
- assert_equal "5.0.1", @browser.full_version
66
- assert_equal "5", @browser.version
67
- end
68
-
69
- it "detects safari in webapp mode" do
70
- @browser.ua = $ua["SAFARI_IPAD_WEBAPP_MODE"]
71
- assert @browser.safari?
72
-
73
- @browser.ua = $ua["SAFARI_IPHONE_WEBAPP_MODE"]
74
- assert @browser.safari?
75
- end
76
-
77
- it "detects ipod" do
78
- @browser.ua = $ua["IPOD"]
79
-
80
- assert_equal "iPod Touch", @browser.name
81
- assert @browser.ipod?
82
- assert @browser.safari?
83
- assert @browser.webkit?
84
- assert @browser.mobile?
85
- assert @browser.modern?
86
- assert @browser.ios?
87
- refute @browser.tablet?
88
- refute @browser.mac?
89
- assert_equal "3.0", @browser.full_version
90
- assert_equal "3", @browser.version
91
- end
92
-
93
- it "detects ipad" do
94
- @browser.ua = $ua["IPAD"]
95
-
96
- assert_equal "iPad", @browser.name
97
- assert @browser.ipad?
98
- assert @browser.safari?
99
- assert @browser.webkit?
100
- assert @browser.modern?
101
- assert @browser.ios?
102
- assert @browser.tablet?
103
- refute @browser.mobile?
104
- refute @browser.mac?
105
- assert_equal "4.0.4", @browser.full_version
106
- assert_equal "4", @browser.version
107
- end
108
-
109
- it "detects ios4" do
110
- @browser.ua = $ua["IOS4"]
111
- assert @browser.ios?
112
- assert @browser.ios4?
113
- refute @browser.mac?
114
- end
115
-
116
-
117
- it "detects ios5" do
118
- @browser.ua = $ua["IOS5"]
119
- assert @browser.ios?
120
- assert @browser.ios5?
121
- refute @browser.mac?
122
- end
123
-
124
- it "detects ios6" do
125
- @browser.ua = $ua["IOS6"]
126
- assert @browser.ios?
127
- assert @browser.ios6?
128
- refute @browser.mac?
129
- end
130
-
131
- it "detects ios7" do
132
- @browser.ua = $ua["IOS7"]
133
- assert @browser.ios?
134
- assert @browser.ios7?
135
- refute @browser.mac?
136
- end
137
-
138
- it "detects ios8" do
139
- @browser.ua = $ua["IOS8"]
140
- assert @browser.ios?
141
- assert @browser.ios8?
142
- refute @browser.mac?
143
- end
144
-
145
- it "detects ie6" do
146
- @browser.ua = $ua["IE6"]
147
-
148
- assert_equal "Internet Explorer", @browser.name
149
- assert @browser.ie?
150
- assert @browser.ie6?
151
- refute @browser.modern?
152
- assert_equal "6.0", @browser.full_version
153
- assert_equal "6", @browser.version
154
- end
155
-
156
- it "detects ie7" do
157
- @browser.ua = $ua["IE7"]
158
-
159
- assert_equal "Internet Explorer", @browser.name
160
- assert @browser.ie?
161
- assert @browser.ie7?
162
- refute @browser.modern?
163
- assert_equal "7.0", @browser.full_version
164
- assert_equal "7", @browser.version
165
- end
166
-
167
- it "detects ie8" do
168
- @browser.ua = $ua["IE8"]
169
-
170
- assert_equal "Internet Explorer", @browser.name
171
- assert @browser.ie?
172
- assert @browser.ie8?
173
- refute @browser.modern?
174
- refute @browser.compatibility_view?
175
- assert_equal "8.0", @browser.full_version
176
- assert_equal "8", @browser.version
177
- end
178
-
179
- it "detects ie8 in compatibility view" do
180
- @browser.ua = $ua["IE8_COMPAT"]
181
-
182
- assert_equal "Internet Explorer", @browser.name
183
- assert @browser.ie?
184
- assert @browser.ie8?
185
- refute @browser.modern?
186
- assert @browser.compatibility_view?
187
- assert_equal "8.0", @browser.full_version
188
- assert_equal "8", @browser.version
189
- assert_equal "7.0", @browser.msie_full_version
190
- assert_equal "7", @browser.msie_version
191
- end
192
-
193
- it "detects ie9" do
194
- @browser.ua = $ua["IE9"]
195
-
196
- assert_equal "Internet Explorer", @browser.name
197
- assert @browser.ie?
198
- assert @browser.ie9?
199
- assert @browser.modern?
200
- refute @browser.compatibility_view?
201
- assert_equal "9.0", @browser.full_version
202
- assert_equal "9", @browser.version
203
- end
204
-
205
- it "detects ie9 in compatibility view" do
206
- @browser.ua = $ua["IE9_COMPAT"]
207
-
208
- assert_equal "Internet Explorer", @browser.name
209
- assert @browser.ie?
210
- assert @browser.ie9?
211
- refute @browser.modern?
212
- assert @browser.compatibility_view?
213
- assert_equal "9.0", @browser.full_version
214
- assert_equal "9", @browser.version
215
- assert_equal "7.0", @browser.msie_full_version
216
- assert_equal "7", @browser.msie_version
217
- end
218
-
219
- it "detects ie10" do
220
- @browser.ua = $ua["IE10"]
221
-
222
- assert_equal "Internet Explorer", @browser.name
223
- assert @browser.ie?
224
- assert @browser.ie10?
225
- assert @browser.modern?
226
- refute @browser.compatibility_view?
227
- assert_equal "10.0", @browser.full_version
228
- assert_equal "10", @browser.version
229
- end
230
-
231
- it "detects ie10 in compatibility view" do
232
- @browser.ua = $ua["IE10_COMPAT"]
233
-
234
- assert_equal "Internet Explorer", @browser.name
235
- assert @browser.ie?
236
- assert @browser.ie10?
237
- refute @browser.modern?
238
- assert @browser.compatibility_view?
239
- assert_equal "10.0", @browser.full_version
240
- assert_equal "10", @browser.version
241
- assert_equal "7.0", @browser.msie_full_version
242
- assert_equal "7", @browser.msie_version
243
- end
244
-
245
- it "detects ie11" do
246
- @browser.ua = $ua["IE11"]
247
-
248
- assert_equal "Internet Explorer", @browser.name
249
- assert @browser.ie?
250
- assert @browser.ie11?
251
- assert @browser.modern?
252
- refute @browser.compatibility_view?
253
- assert_equal "11.0", @browser.full_version
254
- assert_equal "11", @browser.version
255
- end
256
-
257
- it "detects ie11 in compatibility view" do
258
- @browser.ua = $ua["IE11_COMPAT"]
259
-
260
- assert_equal "Internet Explorer", @browser.name
261
- assert @browser.ie?
262
- assert @browser.ie11?
263
- refute @browser.modern?
264
- assert @browser.compatibility_view?
265
- assert_equal "11.0", @browser.full_version
266
- assert_equal "11", @browser.version
267
- assert_equal "7.0", @browser.msie_full_version
268
- assert_equal "7", @browser.msie_version
269
- end
270
-
271
- it "detects Lumia 800" do
272
- @browser.ua = $ua["LUMIA800"]
273
-
274
- assert_equal "Internet Explorer", @browser.name
275
- assert @browser.ie?
276
- assert @browser.ie9?
277
- assert_equal "9.0", @browser.full_version
278
- assert_equal "9", @browser.version
279
- refute @browser.tablet?
280
- assert @browser.mobile?
281
- end
282
-
283
- it "detects opera" do
284
- @browser.ua = $ua["OPERA"]
285
-
286
- assert_equal "Opera", @browser.name
287
- assert @browser.opera?
288
- refute @browser.modern?
289
- assert_equal "11.64", @browser.full_version
290
- assert_equal "11", @browser.version
291
- end
292
-
293
- it "detects opera next" do
294
- @browser.ua = $ua["OPERA_NEXT"]
295
-
296
- assert_equal "Opera", @browser.name
297
- assert_equal :opera, @browser.id
298
- assert @browser.opera?
299
- assert @browser.webkit?
300
- assert @browser.modern?
301
- refute @browser.chrome?
302
- assert_equal "15.0.1147.44", @browser.full_version
303
- assert_equal "15", @browser.version
304
- end
305
-
306
- it "detects firefox" do
307
- @browser.ua = $ua["FIREFOX"]
308
-
309
- assert_equal "Firefox", @browser.name
310
- assert @browser.firefox?
311
- refute @browser.modern?
312
- assert_equal "3.8", @browser.full_version
313
- assert_equal "3", @browser.version
314
- end
315
-
316
- it "detects modern firefox" do
317
- @browser.ua = $ua["FIREFOX_MODERN"]
318
-
319
- assert_equal :firefox, @browser.id
320
- assert_equal "Firefox", @browser.name
321
- assert @browser.firefox?
322
- assert @browser.modern?
323
- assert_equal "17.0", @browser.full_version
324
- assert_equal "17", @browser.version
325
- end
326
-
327
- it "detects firefox android tablet" do
328
- @browser.ua = $ua["FIREFOX_TABLET"]
329
-
330
- assert_equal :firefox, @browser.id
331
- assert_equal "Firefox", @browser.name
332
- assert @browser.firefox?
333
- assert @browser.modern?
334
- assert @browser.tablet?
335
- assert @browser.android?
336
- assert_equal "14.0", @browser.full_version
337
- assert_equal "14", @browser.version
338
- end
339
-
340
- it "detects chrome" do
341
- @browser.ua = $ua["CHROME"]
342
-
343
- assert_equal "Chrome", @browser.name
344
- assert @browser.chrome?
345
- refute @browser.safari?
346
- assert @browser.webkit?
347
- assert @browser.modern?
348
- assert_equal "5.0.375.99", @browser.full_version
349
- assert_equal "5", @browser.version
350
- end
351
-
352
- it "detects mobile chrome" do
353
- @browser.ua = $ua["MOBILE_CHROME"]
354
-
355
- assert_equal "Chrome", @browser.name
356
- assert @browser.chrome?
357
- refute @browser.safari?
358
- assert @browser.webkit?
359
- assert @browser.modern?
360
- assert_equal "19.0.1084.60", @browser.full_version
361
- assert_equal "19", @browser.version
362
- end
363
-
364
- it "detects samsung chrome" do
365
- @browser.ua = $ua["SAMSUNG_CHROME"]
366
-
367
- assert_equal "Chrome", @browser.name
368
- assert @browser.chrome?
369
- assert @browser.android?
370
- refute @browser.safari?
371
- assert @browser.webkit?
372
- assert @browser.modern?
373
- assert_equal "28.0.1500.94", @browser.full_version
374
- assert_equal "28", @browser.version
375
- end
376
-
377
- it "detects android" do
378
- @browser.ua = $ua["ANDROID"]
379
-
380
- assert_equal "Android", @browser.name
381
- assert @browser.android?
382
- refute @browser.safari?
383
- assert @browser.webkit?
384
- assert @browser.mobile?
385
- refute @browser.tablet?
386
- assert @browser.modern?
387
- assert_equal "3.1.2", @browser.full_version
388
- assert_equal "3", @browser.version
389
- end
390
-
391
- it "detects android tablet" do
392
- @browser.ua = $ua["TABLOID"]
393
-
394
- assert_equal "Android", @browser.name
395
- assert @browser.android?
396
- refute @browser.safari?
397
- assert @browser.webkit?
398
- refute @browser.mobile?
399
- assert @browser.tablet?
400
- assert @browser.modern?
401
- assert_equal "4.0", @browser.full_version
402
- assert_equal "4", @browser.version
403
- end
404
-
405
- it "detects surface tablet" do
406
- @browser.ua = $ua["SURFACE"]
407
-
408
- assert_equal "Internet Explorer", @browser.name
409
- assert @browser.surface?
410
- assert @browser.ie?
411
- refute @browser.mobile?
412
- assert @browser.tablet?
413
- assert @browser.modern?
414
- assert_equal "10.0", @browser.full_version
415
- assert_equal "10", @browser.version
416
- end
417
-
418
- it "detects blackberry" do
419
- @browser.ua = $ua["BLACKBERRY"]
420
-
421
- assert_equal "BlackBerry", @browser.name
422
- assert @browser.blackberry?
423
- refute @browser.tablet?
424
- assert @browser.mobile?
425
- refute @browser.modern?
426
- assert_equal "4.1.0", @browser.full_version
427
- assert_equal "4", @browser.version
428
- end
429
-
430
- it "detects blackberry4" do
431
- @browser.ua = $ua["BLACKBERRY4"]
432
-
433
- assert_equal "BlackBerry", @browser.name
434
- assert @browser.blackberry4?
435
- refute @browser.tablet?
436
- assert @browser.mobile?
437
- refute @browser.modern?
438
- assert_equal "4.2.1", @browser.full_version
439
- assert_equal "4", @browser.version
440
- end
441
-
442
- it "detects blackberry5" do
443
- @browser.ua = $ua["BLACKBERRY5"]
444
-
445
- assert_equal "BlackBerry", @browser.name
446
- assert @browser.blackberry5?
447
- refute @browser.tablet?
448
- assert @browser.mobile?
449
- refute @browser.modern?
450
- assert_equal "5.0.0.93", @browser.full_version
451
- assert_equal "5", @browser.version
452
- end
453
-
454
- it "detects blackberry6" do
455
- @browser.ua = $ua["BLACKBERRY6"]
456
-
457
- assert_equal "BlackBerry", @browser.name
458
- assert @browser.blackberry6?
459
- refute @browser.tablet?
460
- assert @browser.mobile?
461
- assert @browser.modern?
462
- assert_equal "534.11", @browser.full_version
463
- assert_equal "534", @browser.version
464
- end
465
-
466
- it "detects blackberry7" do
467
- @browser.ua = $ua["BLACKBERRY7"]
468
-
469
- assert_equal "BlackBerry", @browser.name
470
- assert @browser.blackberry7?
471
- refute @browser.tablet?
472
- assert @browser.mobile?
473
- assert @browser.modern?
474
- assert_equal "534.11", @browser.full_version
475
- assert_equal "534", @browser.version
476
- end
477
-
478
- it "detects blackberry10" do
479
- @browser.ua = $ua["BLACKBERRY10"]
480
-
481
- assert_equal "Safari", @browser.name
482
- assert @browser.blackberry10?
483
- refute @browser.tablet?
484
- assert @browser.mobile?
485
- assert @browser.modern?
486
- assert_equal "10.0.9.1675", @browser.full_version
487
- assert_equal "10", @browser.version
488
- end
489
-
490
- it "detects quicktime" do
491
- @browser.ua = $ua["QUICKTIME"]
492
-
493
- assert_equal "QuickTime", @browser.name
494
- assert @browser.quicktime?
495
- assert_equal "7.6.8", @browser.full_version
496
- assert_equal "7", @browser.version
497
- end
498
-
499
- it "detects core media" do
500
- @browser.ua = $ua["COREMEDIA"]
501
-
502
- assert_equal "Apple CoreMedia", @browser.name
503
- assert @browser.core_media?
504
- assert_equal "1.0.0.10F569", @browser.full_version
505
- assert_equal "1", @browser.version
506
- end
507
-
508
- it "detects phantom.js" do
509
- @browser.ua = $ua["PHANTOM_JS"]
510
-
511
- assert_equal "PhantomJS", @browser.name
512
- assert @browser.phantom_js?
513
- refute @browser.tablet?
514
- refute @browser.mobile?
515
- assert @browser.modern?
516
- assert_equal "1.9.0", @browser.full_version
517
- assert_equal "1", @browser.version
518
- end
519
-
520
- it "detects psp" do
521
- @browser.ua = $ua["PSP"]
522
-
523
- assert_equal "PlayStation Portable", @browser.name
524
- assert @browser.psp?
525
- refute @browser.psp_vita?
526
- assert @browser.mobile?
527
- end
528
-
529
- it "detects psp vita" do
530
- @browser.ua = $ua["PSP_VITA"]
531
-
532
- assert_equal "PlayStation Portable", @browser.name
533
- assert @browser.psp?
534
- assert @browser.psp_vita?
535
- assert @browser.mobile?
536
- end
537
-
538
- it "detects other mobiles" do
539
- @browser.ua = "Symbian OS"
540
- assert @browser.mobile?
541
- refute @browser.tablet?
542
-
543
- @browser.ua = "MIDP-2.0"
544
- assert @browser.mobile?
545
- refute @browser.tablet?
546
- end
547
-
548
- it "detects windows mobile" do
549
- @browser.ua = $ua["WINDOWS_MOBILE"]
550
-
551
- assert @browser.mobile?
552
- assert @browser.windows?
553
- assert @browser.windows_mobile?
554
- refute @browser.windows_phone?
555
- refute @browser.tablet?
556
- end
557
-
558
- it "returns a zero version" do
559
- @browser.ua = "Bot"
560
- assert_equal "0.0", @browser.full_version
561
- assert_equal "0", @browser.version
562
- end
563
-
564
- it "sets meta" do
565
- @browser.ua = $ua["CHROME"]
566
- assert_kind_of Array, @browser.meta
567
- end
568
-
569
- it "returns string representation" do
570
- @browser.ua = $ua["CHROME"]
571
- meta = @browser.to_s
572
-
573
- assert meta.include?("chrome")
574
- assert meta.include?("webkit")
575
- assert meta.include?("mac")
576
- assert meta.include?("modern")
577
- end
578
-
579
- it "returns string representation for ios" do
580
- @browser.ua = $ua["IPHONE"]
581
- meta = @browser.to_s
582
-
583
- assert meta.include?("iphone")
584
- assert meta.include?("webkit")
585
- assert meta.include?("ios")
586
- assert meta.include?("safari")
587
- assert meta.include?("safari3")
588
- assert meta.include?("modern")
589
- assert meta.include?("mobile")
590
- end
591
-
592
- it "returns string representation for mobile" do
593
- @browser.ua = $ua["BLACKBERRY"]
594
- meta = @browser.to_s
595
-
596
- assert meta.include?("blackberry")
597
- assert meta.include?("blackberry4")
598
- assert meta.include?("other")
599
- assert meta.include?("mobile")
600
- end
601
-
602
- it "returns string representation for ie6" do
603
- @browser.ua = $ua["IE6"]
604
- meta = @browser.meta
605
-
606
- assert meta.include?("ie")
607
- assert meta.include?("ie6")
608
- assert meta.include?("oldie")
609
- assert meta.include?("lt-ie8")
610
- assert meta.include?("lt-ie9")
611
- assert meta.include?("windows")
612
- end
613
-
614
- it "returns string representation for ie7" do
615
- @browser.ua = $ua["IE7"]
616
- meta = @browser.meta
617
-
618
- assert meta.include?("ie")
619
- assert meta.include?("ie7")
620
- assert meta.include?("oldie")
621
- assert meta.include?("lt-ie8")
622
- assert meta.include?("lt-ie9")
623
- assert meta.include?("windows")
624
- end
625
-
626
- it "returns string representation for ie8" do
627
- @browser.ua = $ua["IE8"]
628
- meta = @browser.meta
629
-
630
- assert meta.include?("ie")
631
- assert meta.include?("ie8")
632
- assert meta.include?("lt-ie9")
633
- assert meta.include?("windows")
634
- end
635
-
636
- it "detects unknown id" do
637
- @browser.ua = "Unknown"
638
- assert_equal :other, @browser.id
639
- end
640
-
641
- it "detects unknown name" do
642
- @browser.ua = "Unknown"
643
- assert_equal "Other", @browser.name
644
- end
645
-
646
- it "detects mac platform" do
647
- @browser.ua = "Mac OS X"
648
- assert_equal :mac, @browser.platform
649
- assert @browser.mac?
650
- end
651
-
652
- it "detects windows platform" do
653
- @browser.ua = "Windows"
654
- assert_equal :windows, @browser.platform
655
- assert @browser.windows?
656
- end
657
-
658
- it "detects windows_xp" do
659
- @browser.ua = $ua["WINDOWS_XP"]
660
-
661
- assert @browser.windows?
662
- assert @browser.windows_xp?
663
- end
664
-
665
- it "detects windows_vista" do
666
- @browser.ua = $ua["WINDOWS_VISTA"]
667
-
668
- assert @browser.windows?
669
- assert @browser.windows_vista?
670
- end
671
-
672
- it "detects windows7" do
673
- @browser.ua = $ua["WINDOWS7"]
674
-
675
- assert @browser.windows?
676
- assert @browser.windows7?
677
- end
678
-
679
- it "detects windows8" do
680
- @browser.ua = $ua["WINDOWS8"]
681
-
682
- assert @browser.windows?
683
- assert @browser.windows8?
684
- refute @browser.windows8_1?
685
- end
686
-
687
- it "detects windows8.1" do
688
- @browser.ua = $ua["WINDOWS81"]
689
-
690
- assert @browser.windows?
691
- assert @browser.windows8?
692
- assert @browser.windows8_1?
693
- end
694
-
695
- it "detects linux platform" do
696
- @browser.ua = "Linux"
697
- assert_equal :linux, @browser.platform
698
- assert @browser.linux?
699
- end
700
-
701
- it "detects unknown platform" do
702
- @browser.ua = "Unknown"
703
- assert_equal :other, @browser.platform
704
- end
705
-
706
- it "returns all known languages" do
707
- @browser.accept_language = "en-us,en;q=0.8,pt-br;q=0.5,pt;q=0.3"
708
- assert_equal ["en-us", "en", "pt-br", "pt"], @browser.accept_language
709
- end
710
-
711
- it "detects xoom" do
712
- @browser.ua = $ua["XOOM"]
713
-
714
- assert @browser.android?
715
- assert @browser.tablet?
716
- refute @browser.mobile?
717
- end
718
-
719
- it "detects nexus tablet" do
720
- @browser.ua = $ua["NEXUS_TABLET"]
721
-
722
- assert @browser.android?
723
- assert @browser.tablet?
724
- refute @browser.mobile?
725
- end
726
-
727
- it "detects blackberry playbook tablet" do
728
- @browser.ua = $ua["PLAYBOOK"]
729
-
730
- refute @browser.android?
731
- assert @browser.tablet?
732
- refute @browser.mobile?
733
-
734
- assert_equal "7.2.1.0", @browser.full_version
735
- assert_equal "7", @browser.version
736
- end
737
-
738
- it "detects opera mini" do
739
- @browser.ua = $ua["OPERA_MINI"]
740
-
741
- assert @browser.opera_mini?
742
- refute @browser.tablet?
743
- assert @browser.mobile?
744
- end
745
-
746
- it "detects opera mobi" do
747
- @browser.ua = $ua["OPERA_MOBI"]
748
-
749
- assert @browser.opera?
750
- refute @browser.tablet?
751
- assert @browser.mobile?
752
- end
753
-
754
- it "detects windows phone" do
755
- @browser.ua = $ua["WINDOWS_PHONE"]
756
-
757
- assert @browser.ie?
758
- assert_equal "7", @browser.version
759
- assert @browser.mobile?
760
- assert @browser.windows_phone?
761
- refute @browser.windows_mobile?
762
- refute @browser.tablet?
763
- end
764
-
765
- it "detects windows phone 8" do
766
- @browser.ua = $ua["WINDOWS_PHONE8"]
767
-
768
- assert @browser.ie?
769
- assert_equal "10", @browser.version
770
- assert @browser.mobile?
771
- assert @browser.windows_phone?
772
- refute @browser.windows_mobile?
773
- refute @browser.tablet?
774
- end
775
-
776
- it "detects windows phone 8.1" do
777
- @browser.ua = $ua["WINDOWS_PHONE_81"]
778
-
779
- assert @browser.ie?
780
- assert_equal "Internet Explorer", @browser.name
781
- assert_equal :ie, @browser.id
782
- assert_equal "11", @browser.version
783
- assert_equal "11.0", @browser.full_version
784
- assert @browser.mobile?
785
- assert @browser.windows_phone?
786
- refute @browser.windows_mobile?
787
- refute @browser.tablet?
788
- end
789
-
790
- it "detects windows mobile" do
791
- @browser.ua = $ua["WINDOWS_PHONE8"]
792
-
793
- assert @browser.ie?
794
- assert_equal "10", @browser.version
795
- assert @browser.mobile?
796
- assert @browser.windows_phone?
797
- refute @browser.windows_mobile?
798
- refute @browser.tablet?
799
- end
800
-
801
- it "detects windows x64" do
802
- @browser.ua = $ua["IE10_X64_WINX64"]
803
- assert @browser.windows_x64?
804
- refute @browser.windows_wow64?
805
- assert @browser.windows_x64_inclusive?
806
- end
807
-
808
- it "detects windows wow64" do
809
- @browser.ua = $ua["WINDOWS_WOW64"]
810
- refute @browser.windows_x64?
811
- assert @browser.windows_wow64?
812
- assert @browser.windows_x64_inclusive?
813
- end
814
-
815
- it "detects ie11 touch desktop pc" do
816
- @browser.ua = $ua["IE11_TOUCH_SCREEN"]
817
-
818
- assert_equal "Internet Explorer", @browser.name
819
- assert @browser.ie?
820
- assert @browser.ie11?
821
- assert @browser.modern?
822
- refute @browser.compatibility_view?
823
- refute @browser.windows_rt?
824
- assert @browser.windows_touchscreen_desktop?
825
- assert @browser.windows8?
826
- assert_equal "11.0", @browser.full_version
827
- assert_equal "11", @browser.version
828
- end
829
-
830
- it "detects Microsoft Edge" do
831
- @browser.ua = $ua["MS_EDGE"]
832
-
833
- assert_equal :edge, @browser.id
834
- assert_equal "Microsoft Edge", @browser.name
835
- assert_equal "12.0", @browser.full_version
836
- assert_equal "12", @browser.version
837
- assert @browser.windows10?
838
- assert @browser.edge?
839
- assert @browser.modern?
840
- refute @browser.webkit?
841
- refute @browser.chrome?
842
- refute @browser.safari?
843
- refute @browser.mobile?
844
- end
845
-
846
- it "detects Microsoft Edge in compatibility view" do
847
- @browser.ua = $ua["MS_EDGE_COMPAT"]
848
-
849
- assert_equal :edge, @browser.id
850
- assert_equal "Microsoft Edge", @browser.name
851
- assert_equal "12.0", @browser.full_version
852
- assert_equal "12", @browser.version
853
- assert_equal "7.0", @browser.msie_full_version
854
- assert_equal "7", @browser.msie_version
855
- assert @browser.edge?
856
- assert @browser.compatibility_view?
857
- refute @browser.modern?
858
- refute @browser.webkit?
859
- refute @browser.chrome?
860
- refute @browser.safari?
861
- refute @browser.mobile?
862
- end
863
-
864
- it "detects Microsoft Edge Mobile" do
865
- @browser.ua = $ua["MS_EDGE_MOBILE"]
866
-
867
- assert_equal :edge, @browser.id
868
- assert_equal "Microsoft Edge", @browser.name
869
- assert_equal "12.0", @browser.full_version
870
- assert_equal "12", @browser.version
871
- refute @browser.windows10?
872
- assert @browser.windows_phone?
873
- assert @browser.edge?
874
- assert @browser.modern?
875
- assert @browser.mobile?
876
- refute @browser.webkit?
877
- refute @browser.chrome?
878
- refute @browser.safari?
879
- end
880
-
881
- it "detects IE without Trident" do
882
- @browser.ua = $ua["IE_WITHOUT_TRIDENT"]
883
-
884
- assert_equal :ie, @browser.id
885
- assert_equal "Internet Explorer", @browser.name
886
- assert_equal "0.0", @browser.msie_full_version
887
- assert_equal "0", @browser.msie_version
888
- assert_equal "0.0", @browser.full_version
889
- assert_equal "0", @browser.version
890
- refute @browser.windows10?
891
- refute @browser.windows_phone?
892
- refute @browser.edge?
893
- refute @browser.modern?
894
- refute @browser.mobile?
895
- refute @browser.webkit?
896
- refute @browser.chrome?
897
- refute @browser.safari?
898
- end
899
-
900
- it "detects Daumoa" do
901
- @browser.ua = $ua["DAUMOA"]
902
-
903
- assert_equal :ie, @browser.id
904
- assert_equal "Internet Explorer", @browser.name
905
- assert_equal "0.0", @browser.msie_full_version
906
- assert_equal "0", @browser.msie_version
907
- assert_equal "0.0", @browser.full_version
908
- assert_equal "0", @browser.version
909
- assert @browser.ie?
910
- refute @browser.windows10?
911
- refute @browser.windows_phone?
912
- refute @browser.edge?
913
- refute @browser.modern?
914
- refute @browser.mobile?
915
- refute @browser.webkit?
916
- refute @browser.chrome?
917
- refute @browser.safari?
918
- end
919
-
920
- it "detects kindle monochrome" do
921
- @browser.ua = $ua["KINDLE"]
922
-
923
- assert @browser.kindle?
924
- assert @browser.webkit?
925
- end
926
-
927
- it "detects kindle fire" do
928
- @browser.ua = $ua["KINDLE_FIRE"]
929
-
930
- assert @browser.kindle?
931
- assert @browser.webkit?
932
- end
933
-
934
- it "detects kindle fire hd" do
935
- @browser.ua = $ua["KINDLE_FIRE_HD"]
936
-
937
- assert @browser.silk?
938
- assert @browser.kindle?
939
- assert @browser.webkit?
940
- assert @browser.modern?
941
- refute @browser.mobile?
942
- end
943
-
944
- it "detects kindle fire hd mobile" do
945
- @browser.ua = $ua["KINDLE_FIRE_HD_MOBILE"]
946
-
947
- assert @browser.silk?
948
- assert @browser.kindle?
949
- assert @browser.webkit?
950
- assert @browser.modern?
951
- assert @browser.mobile?
952
- end
953
-
954
- it "detects nook" do
955
- @browser.ua = $ua["NOOK"]
956
-
957
- assert @browser.tablet?
958
- refute @browser.mobile?
959
- end
960
-
961
- it "detects samsung" do
962
- @browser.ua = $ua["SAMSUNG"]
963
-
964
- assert @browser.tablet?
965
- refute @browser.mobile?
966
- end
967
-
968
- it "detects nintendo wii" do
969
- @browser.ua = $ua["NINTENDO_WII"]
970
-
971
- assert @browser.console?
972
- assert @browser.nintendo?
973
- end
974
-
975
- it "detects nintendo wii u" do
976
- @browser.ua = $ua["NINTENDO_WIIU"]
977
-
978
- assert @browser.console?
979
- assert @browser.nintendo?
980
- end
981
-
982
- it "detects playstation 3" do
983
- @browser.ua = $ua["PLAYSTATION3"]
984
-
985
- assert @browser.console?
986
- assert @browser.playstation?
987
- refute @browser.playstation4?
988
- end
989
-
990
- it "detects playstation 4" do
991
- @browser.ua = $ua["PLAYSTATION4"]
992
-
993
- assert @browser.console?
994
- assert @browser.playstation?
995
- assert @browser.playstation4?
996
- end
997
-
998
- it "detects xbox 360" do
999
- @browser.ua = $ua["XBOX360"]
1000
-
1001
- assert @browser.console?
1002
- assert @browser.xbox?
1003
- refute @browser.xbox_one?
1004
- end
1005
-
1006
- it "detects xbox one" do
1007
- @browser.ua = $ua["XBOXONE"]
1008
-
1009
- assert @browser.console?
1010
- assert @browser.xbox?
1011
- assert @browser.xbox_one?
1012
- end
1013
-
1014
- it "removes duplicate items" do
1015
- @browser.ua = $ua["SAFARI"]
1016
- assert_equal ["safari"], @browser.meta.select {|item| item == "safari" }
1017
- end
1018
-
1019
- it "detects meta aliased as to_a" do
1020
- @browser.ua = $ua["SAFARI"]
1021
- assert_equal @browser.meta, @browser.to_a
1022
- end
1023
-
1024
- it "detects bots" do
1025
- %w[
1026
- APPLE_BOT
1027
- DOT_BOT
1028
- FACEBOOK_BOT
1029
- GOOGLE_BOT
1030
- LINKDEXBOT
1031
- LOAD_TIME_BOT
1032
- MAIL_RU
1033
- MEGAINDEX_RU
1034
- MSN_BOT
1035
- QUERYSEEKER
1036
- SCRAPY
1037
- YANDEX_DIRECT
1038
- YANDEX_METRIKA
1039
- ].each do |key|
1040
- @browser.ua = $ua[key]
1041
- assert @browser.bot?, "#{$ua[key]} should be a bot"
1042
- end
1043
-
1044
- @browser.ua = $ua["CHROME"]
1045
- refute @browser.bot?
1046
- end
1047
-
1048
- it "detects Google Page Speed as a bot" do
1049
- @browser.ua = $ua["GOOGLE_PAGE_SPEED_INSIGHTS"]
1050
- assert @browser.bot?
1051
- end
1052
-
1053
- it "doesn't consider empty UA as bot" do
1054
- @browser.ua = ""
1055
- refute @browser.bot?
1056
- end
1057
-
1058
- it "allows setting empty string as bots" do
1059
- Browser::Bots.detect_empty_ua!
1060
- @browser.ua = ""
1061
-
1062
- assert @browser.bot?
1063
- end
1064
-
1065
- it "doesn't detect mozilla as a bot when considering empty UA" do
1066
- Browser::Bots.detect_empty_ua!
1067
- @browser.ua = "Mozilla"
1068
-
1069
- refute @browser.bot?
1070
- end
1071
-
1072
- it "returns bot name" do
1073
- @browser.ua = $ua["GOOGLE_BOT"]
1074
- assert_equal @browser.bot_name, "Googlebot"
1075
-
1076
- @browser.ua = $ua["FACEBOOK_BOT"]
1077
- assert_equal @browser.bot_name, "facebookexternalhit"
1078
- end
1079
-
1080
- it "returns bot name (empty string ua detection enabled)" do
1081
- Browser::Bots.detect_empty_ua!
1082
- @browser.ua = ""
1083
-
1084
- assert_equal @browser.bot_name, "Generic Bot"
1085
- end
1086
-
1087
- it "returns nil for non-bots" do
1088
- @browser.ua = $ua["CHROME"]
1089
- assert_equal @browser.bot_name, nil
1090
- end
1091
-
1092
- it "detects chrome os" do
1093
- @browser.ua = $ua["CHROME_OS"]
1094
- assert @browser.chrome_os?
1095
- end
1096
-
1097
- it "detects tv" do
1098
- @browser.ua = $ua["SMART_TV"]
1099
- assert @browser.tv?
1100
- end
1101
-
1102
- it "detects as search engines" do
1103
- %w[
1104
- ASK
1105
- BAIDU
1106
- BINGBOT
1107
- DUCKDUCKGO
1108
- GOOGLE_BOT
1109
- YAHOO_SLURP
1110
- ].each do |key|
1111
- @browser.ua = $ua[key]
1112
- assert @browser.search_engine?, "#{$ua[key]} should be a search engine"
1113
- end
1114
- end
1115
-
1116
- it "detects Google Structured Data Testing Tool as a bot" do
1117
- @browser.ua = $ua["GOOGLE_STRUCTURED_DATA_TESTING_TOOL"]
1118
-
1119
- assert @browser.bot?, "Google Structured Data Testing Tool should be a bot"
1120
- end
1121
-
1122
- it "knows a supported browser" do
1123
- @browser.ua = "Chrome"
1124
- assert @browser.known?
1125
- end
1126
-
1127
- it "does not know an unsupported browser" do
1128
- @browser.ua = "Fancy new browser"
1129
- refute @browser.known?
1130
- end
1131
-
1132
- it "detects adobe air" do
1133
- @browser.ua = $ua["ADOBE_AIR"]
1134
-
1135
- assert @browser.adobe_air?
1136
- assert @browser.webkit?
1137
- assert_equal @browser.version, "13"
1138
- assert_equal @browser.full_version, "13.0"
1139
- assert_equal @browser.name, "Other"
1140
- end
1141
- end