newrelic_rpm 2.12.3 → 2.13.0.beta3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of newrelic_rpm might be problematic. Click here for more details.

Files changed (118) hide show
  1. data/CHANGELOG +24 -2
  2. data/README.rdoc +172 -0
  3. data/bin/newrelic +13 -0
  4. data/bin/newrelic_cmd +2 -1
  5. data/install.rb +8 -45
  6. data/lib/new_relic/agent.rb +43 -30
  7. data/lib/new_relic/agent/agent.rb +699 -631
  8. data/lib/new_relic/agent/busy_calculator.rb +81 -81
  9. data/lib/new_relic/agent/error_collector.rb +9 -6
  10. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +2 -2
  11. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +10 -5
  12. data/lib/new_relic/agent/instrumentation/data_mapper.rb +13 -45
  13. data/lib/new_relic/agent/instrumentation/memcache.rb +15 -4
  14. data/lib/new_relic/agent/instrumentation/metric_frame.rb +37 -29
  15. data/lib/new_relic/agent/instrumentation/rack.rb +20 -34
  16. data/lib/new_relic/agent/method_tracer.rb +9 -9
  17. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +31 -31
  18. data/lib/new_relic/agent/stats_engine/metric_stats.rb +5 -5
  19. data/lib/new_relic/agent/stats_engine/samplers.rb +3 -0
  20. data/lib/new_relic/agent/transaction_sampler.rb +31 -15
  21. data/lib/new_relic/agent/worker_loop.rb +29 -28
  22. data/lib/new_relic/collection_helper.rb +4 -2
  23. data/lib/new_relic/command.rb +85 -0
  24. data/lib/new_relic/commands/deployments.rb +74 -114
  25. data/lib/new_relic/commands/install.rb +81 -0
  26. data/lib/new_relic/control.rb +54 -379
  27. data/lib/new_relic/control/configuration.rb +149 -0
  28. data/lib/new_relic/control/{external.rb → frameworks/external.rb} +2 -2
  29. data/lib/new_relic/control/{merb.rb → frameworks/merb.rb} +1 -1
  30. data/lib/new_relic/control/frameworks/rails.rb +126 -0
  31. data/lib/new_relic/control/{rails3.rb → frameworks/rails3.rb} +11 -10
  32. data/lib/new_relic/control/{ruby.rb → frameworks/ruby.rb} +1 -1
  33. data/lib/new_relic/control/{sinatra.rb → frameworks/sinatra.rb} +2 -2
  34. data/lib/new_relic/control/instrumentation.rb +84 -0
  35. data/lib/new_relic/control/logging_methods.rb +74 -0
  36. data/lib/new_relic/control/profiling.rb +24 -0
  37. data/lib/new_relic/control/server_methods.rb +88 -0
  38. data/lib/new_relic/local_environment.rb +3 -3
  39. data/lib/new_relic/metric_parser.rb +13 -2
  40. data/lib/new_relic/metric_parser/active_record.rb +4 -1
  41. data/lib/new_relic/metric_parser/apdex.rb +53 -0
  42. data/lib/new_relic/metric_parser/controller.rb +13 -5
  43. data/lib/new_relic/metric_parser/mem_cache.rb +1 -1
  44. data/lib/new_relic/metric_parser/other_transaction.rb +21 -0
  45. data/lib/new_relic/metric_spec.rb +3 -3
  46. data/lib/new_relic/noticed_error.rb +1 -1
  47. data/lib/new_relic/rack/developer_mode.rb +257 -0
  48. data/lib/new_relic/rack/metric_app.rb +56 -50
  49. data/lib/new_relic/rack/mongrel_rpm.ru +7 -6
  50. data/lib/new_relic/rack/newrelic.yml +4 -3
  51. data/lib/new_relic/rack_app.rb +2 -1
  52. data/lib/new_relic/recipes.rb +7 -7
  53. data/lib/new_relic/stats.rb +6 -14
  54. data/lib/new_relic/timer_lib.rb +27 -0
  55. data/lib/new_relic/transaction_analysis.rb +2 -7
  56. data/lib/new_relic/transaction_sample.rb +17 -85
  57. data/lib/new_relic/url_rule.rb +14 -0
  58. data/lib/new_relic/version.rb +3 -3
  59. data/lib/newrelic_rpm.rb +5 -9
  60. data/newrelic.yml +26 -9
  61. data/newrelic_rpm.gemspec +67 -32
  62. data/test/config/newrelic.yml +5 -0
  63. data/test/config/test_control.rb +6 -8
  64. data/test/new_relic/agent/active_record_instrumentation_test.rb +5 -6
  65. data/test/new_relic/agent/agent_controller_test.rb +18 -4
  66. data/test/new_relic/agent/agent_test_controller.rb +1 -6
  67. data/test/new_relic/agent/busy_calculator_test.rb +2 -0
  68. data/test/new_relic/agent/collection_helper_test.rb +6 -6
  69. data/test/new_relic/agent/error_collector_test.rb +13 -21
  70. data/test/new_relic/agent/metric_data_test.rb +3 -6
  71. data/test/new_relic/agent/rpm_agent_test.rb +121 -117
  72. data/test/new_relic/agent/task_instrumentation_test.rb +128 -133
  73. data/test/new_relic/agent/transaction_sample_test.rb +176 -170
  74. data/test/new_relic/agent/worker_loop_test.rb +24 -18
  75. data/test/new_relic/control_test.rb +13 -3
  76. data/test/new_relic/deployments_api_test.rb +7 -7
  77. data/test/new_relic/environment_test.rb +1 -1
  78. data/test/new_relic/metric_parser_test.rb +58 -4
  79. data/test/new_relic/rack/episodes_test.rb +317 -0
  80. data/test/new_relic/stats_test.rb +3 -2
  81. data/test/test_contexts.rb +28 -0
  82. data/test/test_helper.rb +24 -5
  83. data/ui/helpers/{newrelic_helper.rb → developer_mode_helper.rb} +63 -23
  84. data/ui/views/layouts/newrelic_default.rhtml +6 -6
  85. data/ui/views/newrelic/_explain_plans.rhtml +4 -4
  86. data/ui/views/newrelic/_sample.rhtml +18 -17
  87. data/ui/views/newrelic/_segment.rhtml +1 -0
  88. data/ui/views/newrelic/_segment_row.rhtml +8 -8
  89. data/ui/views/newrelic/_show_sample_detail.rhtml +1 -1
  90. data/ui/views/newrelic/_show_sample_sql.rhtml +2 -2
  91. data/ui/views/newrelic/_sql_row.rhtml +8 -3
  92. data/ui/views/newrelic/_stack_trace.rhtml +9 -24
  93. data/ui/views/newrelic/_table.rhtml +1 -1
  94. data/ui/views/newrelic/explain_sql.rhtml +3 -2
  95. data/ui/views/newrelic/{images → file/images}/arrow-close.png +0 -0
  96. data/ui/views/newrelic/{images → file/images}/arrow-open.png +0 -0
  97. data/ui/views/newrelic/{images → file/images}/blue_bar.gif +0 -0
  98. data/ui/views/newrelic/{images → file/images}/file_icon.png +0 -0
  99. data/ui/views/newrelic/{images → file/images}/gray_bar.gif +0 -0
  100. data/ui/views/newrelic/{images → file/images}/new-relic-rpm-desktop.gif +0 -0
  101. data/ui/views/newrelic/{images → file/images}/new_relic_rpm_desktop.gif +0 -0
  102. data/ui/views/newrelic/{images → file/images}/textmate.png +0 -0
  103. data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
  104. data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
  105. data/ui/views/newrelic/{stylesheets → file/stylesheets}/style.css +0 -0
  106. data/ui/views/newrelic/index.rhtml +7 -5
  107. data/ui/views/newrelic/sample_not_found.rhtml +1 -1
  108. data/ui/views/newrelic/show_sample.rhtml +5 -6
  109. metadata +92 -34
  110. data/README.md +0 -138
  111. data/lib/new_relic/commands/new_relic_commands.rb +0 -30
  112. data/lib/new_relic/control/rails.rb +0 -151
  113. data/test/new_relic/agent/mock_ar_connection.rb +0 -40
  114. data/test/ui/newrelic_controller_test.rb +0 -14
  115. data/test/ui/newrelic_helper_test.rb +0 -53
  116. data/ui/controllers/newrelic_controller.rb +0 -220
  117. data/ui/views/newrelic/javascript/prototype-scriptaculous.js +0 -7288
  118. data/ui/views/newrelic/javascript/transaction_sample.js +0 -107
@@ -6,7 +6,7 @@ require 'mocha'
6
6
  class NewRelic::DeploymentsTest < Test::Unit::TestCase
7
7
 
8
8
  def setup
9
- NewRelic::Commands::Deployments.class_eval do
9
+ NewRelic::Command::Deployments.class_eval do
10
10
  attr_accessor :messages, :exit_status, :errors, :revision
11
11
  def err(message); @errors = @errors ? @errors + message : message; end
12
12
  def info(message); @messages = @messages ? @messages + message : message; end
@@ -21,20 +21,20 @@ class NewRelic::DeploymentsTest < Test::Unit::TestCase
21
21
  end
22
22
  def test_help
23
23
  begin
24
- NewRelic::Commands::Deployments.new "-h"
24
+ NewRelic::Command::Deployments.new "-h"
25
25
  fail "should have thrown"
26
- rescue NewRelic::Commands::CommandFailure => c
26
+ rescue NewRelic::Command::CommandFailure => c
27
27
  assert_match /^Usage/, c.message
28
28
  end
29
29
  end
30
30
  def test_bad_command
31
- assert_raise OptionParser::InvalidOption do
32
- NewRelic::Commands::Deployments.new ["-foo", "bar"]
31
+ assert_raise NewRelic::Command::CommandFailure do
32
+ NewRelic::Command::Deployments.new ["-foo", "bar"]
33
33
  end
34
34
  end
35
35
  def test_interactive
36
36
  mock_the_connection
37
- @deployment = NewRelic::Commands::Deployments.new :appname => 'APP', :revision => 3838, :user => 'Bill', :description => "Some lengthy description"
37
+ @deployment = NewRelic::Command::Deployments.new :appname => 'APP', :revision => 3838, :user => 'Bill', :description => "Some lengthy description"
38
38
  assert_nil @deployment.exit_status
39
39
  assert_nil @deployment.errors
40
40
  assert_equal '3838', @deployment.revision
@@ -45,7 +45,7 @@ class NewRelic::DeploymentsTest < Test::Unit::TestCase
45
45
  def test_command_line_run
46
46
  mock_the_connection
47
47
  # @mock_response.expects(:body).returns("<xml>deployment</xml>")
48
- @deployment = NewRelic::Commands::Deployments.new(%w[-a APP -r 3838 --user=Bill] << "Some lengthy description")
48
+ @deployment = NewRelic::Command::Deployments.new(%w[-a APP -r 3838 --user=Bill] << "Some lengthy description")
49
49
  assert_nil @deployment.exit_status
50
50
  assert_nil @deployment.errors
51
51
  assert_equal '3838', @deployment.revision
@@ -2,7 +2,7 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
2
2
  require "test/unit"
3
3
  require "mocha"
4
4
  ##require 'new_relic/local_environment'
5
- class EnvironmentTest < ActiveSupport::TestCase
5
+ class EnvironmentTest < Test::Unit::TestCase # ActiveSupport::TestCase
6
6
 
7
7
  def teardown
8
8
  # To remove mock server instances from ObjectSpace
@@ -1,12 +1,19 @@
1
+ ENV['SKIP_RAILS'] = 'true'
1
2
  require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
2
3
 
3
4
  class MetricParserTest < Test::Unit::TestCase
4
-
5
+
5
6
  def test_memcache
6
7
  m = NewRelic::MetricParser.for_metric_named "MemCache/read"
7
8
  assert_equal "MemCache read", m.developer_name
8
9
  end
9
-
10
+
11
+ def test_memcache__all
12
+ m = NewRelic::MetricParser.for_metric_named "MemCache/all"
13
+ assert_equal "MemCache All Operations", m.developer_name
14
+ assert_equal "All Operations", m.operation
15
+ end
16
+
10
17
  def test_view__short
11
18
  i = NewRelic::MetricParser.parse("View/.rhtml Processing")
12
19
  assert_equal "ERB compilation", i.developer_name
@@ -157,7 +164,7 @@ class MetricParserTest < Test::Unit::TestCase
157
164
  assert_equal "All venus calls", m.legend_name
158
165
  assert_nil m.operation
159
166
  assert_equal 'all', m.library
160
-
167
+
161
168
  m = NewRelic::MetricParser.for_metric_named("External/venus/Net::Http/get")
162
169
  assert !m.all?
163
170
  assert !m.hosts_all?
@@ -169,4 +176,51 @@ class MetricParserTest < Test::Unit::TestCase
169
176
 
170
177
 
171
178
  end
172
- end
179
+
180
+ context "with apdex" do
181
+
182
+ context "client" do
183
+ setup do
184
+ @client_name = NewRelic::MetricParser::Apdex.client_metric(NewRelic::Control.instance.apdex_t)
185
+ @apdex_client = NewRelic::MetricParser.for_metric_named(@client_name)
186
+ end
187
+ should "produce a client metric name" do
188
+ assert_equal "Apdex/Client/#{NewRelic::Control.instance.apdex_t}", @client_name
189
+ end
190
+ should "display the apdex value in " do
191
+ assert_equal "Apdex Client (1.1)", @apdex_client.developer_name
192
+ end
193
+ should "act like a client score" do
194
+ assert ! @apdex_client.is_summary?
195
+ assert @apdex_client.is_client?
196
+ end
197
+ should "display nicely" do
198
+ assert_equal "Apdex Client (#{NewRelic::Control.instance.apdex_t})", @apdex_client.developer_name
199
+ end
200
+
201
+ end
202
+
203
+ context "summary" do
204
+ setup do
205
+ @apdex_summary = NewRelic::MetricParser.for_metric_named('Apdex')
206
+ end
207
+
208
+ should "act like a summary" do
209
+ assert @apdex_summary.is_summary?
210
+ assert ! @apdex_summary.is_client?
211
+ end
212
+ end
213
+ context "controller score" do
214
+ setup do
215
+ @controller_apdex = NewRelic::MetricParser.for_metric_named('Apdex/sessions/guest_index')
216
+ end
217
+ should "act like a controller" do
218
+ assert ! @controller_apdex.is_summary?
219
+ assert ! @controller_apdex.is_client?
220
+ end
221
+ should "display nicely" do
222
+ assert_equal "Apdex sessions/guest_index", @controller_apdex.developer_name
223
+ end
224
+ end
225
+ end
226
+ end
@@ -0,0 +1,317 @@
1
+ # Run faster standalone
2
+ # ENV['SKIP_RAILS'] = 'true'
3
+ require File.expand_path(File.join(File.dirname(__FILE__),'..', '..', 'test_helper'))
4
+ require 'rack'
5
+
6
+ class EpisodesTest < Test::Unit::TestCase
7
+
8
+ def setup
9
+ super
10
+
11
+ @app = Mocha::Mockery.instance.named_mock 'Episodes'
12
+ #@app = mock('Episodes')
13
+ @e = NewRelic::Rack::Episodes.new(@app)
14
+ NewRelic::Agent.manual_start
15
+ @agent = NewRelic::Agent.instance
16
+ @agent.transaction_sampler.send :clear_builder
17
+ @agent.transaction_sampler.reset!
18
+ @agent.stats_engine.clear_stats
19
+ end
20
+
21
+ def test_match
22
+ @e.expects(:process).times(3)
23
+ @app.expects(:call).times(2)
24
+ @e.call(mock_env('/newrelic/episodes/page_load/stuff'))
25
+ @e.call(mock_env('/newrelic/episodes/page_load'))
26
+ @e.call(mock_env('/newrelic/episodes/page_load?'))
27
+
28
+ @e.call(mock_env('/v2/newrelic/episodes/page_load?'))
29
+ @e.call(mock_env('/v2'))
30
+ end
31
+
32
+ def test_process
33
+
34
+ args = "ets=backend:2807,onload:7641,frontend:4835,pageready:7642,totaltime:7642&" +
35
+ "url=/bogosity/bogus_action&"+
36
+ "userAgent=#{Rack::Utils.escape("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2")}"
37
+ v = @e.call(mock_env("/newrelic/episodes/page_load?#{args}"))
38
+ assert_equal 3, v.size
39
+ assert_equal 204, v[0]
40
+ compare_metrics %w[
41
+ Apdex/Client/4.4
42
+ Client/totaltime
43
+ Client/frontend
44
+ Client/backend
45
+ Client/onload
46
+ Client/pageready
47
+ Client/totaltime/Mac/Firefox/3.6
48
+ Client/frontend/Mac/Firefox/3.6
49
+ Client/backend/Mac/Firefox/3.6
50
+ Client/onload/Mac/Firefox/3.6
51
+ Client/pageready/Mac/Firefox/3.6], @agent.stats_engine.metrics
52
+ totaltime = @agent.stats_engine.get_stats_no_scope('Client/totaltime')
53
+ assert_equal 1, totaltime.call_count
54
+ assert_equal 7.642, totaltime.average_call_time
55
+ totaltime = @agent.stats_engine.get_stats_no_scope('Client/totaltime/Mac/Firefox/3.6')
56
+ assert_equal 1, totaltime.call_count
57
+ assert_equal 7.642, totaltime.average_call_time
58
+ end
59
+
60
+ context "when normalizing user agent strings" do
61
+ setup do
62
+ setup
63
+ @e.class.send :public, :identify_browser_and_os
64
+ end
65
+
66
+ should "parse 'like Firefox/* Gecko/*' as Gecko" do
67
+ browser, version, os = @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:1.0rc2) Gecko/20020512 like Firefox/3.1")
68
+
69
+ assert_equal "Mozilla Gecko", browser
70
+ assert_equal 1.0, version
71
+ end
72
+
73
+ should "parse 'Chrome/' as Chrome, unknown version" do
74
+ browser, version, os = @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/ Safari/530.5")
75
+
76
+ assert_equal "Chrome", browser
77
+ assert_equal 0, version
78
+ end
79
+
80
+ should "parse x.y float versions for Firefox, Gecko and Webkit" do
81
+ browser, version, os = @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.2) Gecko/20100105 Firefox/3.6")
82
+ assert Float === version
83
+
84
+ browser, version, os = @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:1.0rc2) Gecko/20020512 Netscape/7.0b1")
85
+ assert Float === version
86
+
87
+ browser, version, os = @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_2; en-gb) AppleWebKit/526+ (KHTML, like Gecko) Version/3.1 iPhone")
88
+ assert Float === version
89
+ end
90
+
91
+ context "in-the-wild" do
92
+ should "identify AOL correctly" do
93
+ assert_equal ["IE", 5, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 5.5; AOL 6.0; Windows 98)"), "AOL 6.0 identified incorrectly"
94
+ assert_equal ["IE", 6, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 6.0; AOL 6.0; Windows NT 5.1)"), "AOL 6.0 identified incorrectly"
95
+ assert_equal ["IE", 6, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 6.0; AOL 7.0; Windows 98; SpamBlockerUtility 4.8.0)"), "AOL 7.0 identified incorrectly"
96
+ assert_equal ["IE", 7, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 7.0; AOL 7.0; Windows NT 5.1; .NET CLR 1.1.4322)"), "AOL 7.0 identified incorrectly"
97
+ assert_equal ["IE", 6, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 6.0; AOL 8.0; Windows NT 5.1)"), "AOL 8.0 identified incorrectly"
98
+ assert_equal ["IE", 7, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 7.0; AOL 8.0; Windows NT 5.1; GTB5; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"), "AOL 8.0 identified incorrectly"
99
+ assert_equal ["IE", 8, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 8.0; AOL 9.5; AOLBuild 4337.29; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618)"), "AOL 9.5 identified incorrectly"
100
+ end
101
+
102
+ should "identify Camino correctly" do
103
+ assert_equal ["Mozilla Gecko", 1.8, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.0.1) Gecko/20060214 Camino/1.0"), "Camino 1.0 identified incorrectly"
104
+ assert_equal ["Mozilla Gecko", 1.8, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.1) Gecko/20060119 Camino/1.0b2+"), "Camino 1.0b2+ identified incorrectly"
105
+ assert_equal ["Mozilla Gecko", 1.8, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en; rv:1.8.1.4) Gecko/20070509 Camino/1.5"), "Camino 1.5 identified incorrectly"
106
+ assert_equal ["Mozilla Gecko", 1.9, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en; rv:1.9.0.18) Gecko/2010021619 Camino/2.0.2 (like Firefox/3.0.18)"), "Camino 2.0.2 identified incorrectly"
107
+ assert_equal ["Mozilla Gecko", 1.9, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en; rv:1.9.0.10pre) Gecko/2009041800 Camino/2.0b3pre (like Firefox/3.0.10pre)"), "Camino 2.0b3pre identified incorrectly"
108
+ end
109
+
110
+ should "identify Chrome correctly" do
111
+ assert_equal ["Chrome", 0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/ Safari/530.5"), "Chrome identified incorrectly"
112
+ assert_equal ["Chrome", 1, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.59 Safari/525.19"), "Chrome 1.0.154.59 identified incorrectly"
113
+ assert_equal ["Chrome", 2, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/528.8 (KHTML, like Gecko) Chrome/2.0.156.0 Version/3.2.1 Safari/528.8"), "Chrome 2.0.156.0 identified incorrectly"
114
+ assert_equal ["Chrome", 2, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US) AppleWebKit/530.7 (KHTML, like Gecko) Chrome/2.0.175.0 Safari/530.7"), "Chrome 2.0.175.0 identified incorrectly"
115
+ assert_equal ["Chrome", 3, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-US) AppleWebKit/531.3 (KHTML, like Gecko) Chrome/3.0.192 Safari/531.3"), "Chrome 3.0.192 identified incorrectly"
116
+ assert_equal ["Chrome", 3, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/531.3 (KHTML, like Gecko) Chrome/3.0.193.0 Safari/531.3"), "Chrome 3.0.193.0 identified incorrectly"
117
+ assert_equal ["Chrome", 3, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/531.4 (KHTML, like Gecko) Chrome/3.0.194.0 Safari/531.4"), "Chrome 3.0.194.0 identified incorrectly"
118
+ assert_equal ["Chrome", 3, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.0 (KHTML,like Gecko) Chrome/3.0.195.27"), "Chrome 3.0.195.27 identified incorrectly"
119
+ assert_equal ["Chrome", 4, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/4.0.201.1 Safari/532.0"), "Chrome 4.0.201.1 identified incorrectly"
120
+ assert_equal ["Chrome", 4, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/4.0.202.0 Safari/532.0"), "Chrome 4.0.202.0 identified incorrectly"
121
+ assert_equal ["Chrome", 4, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/4.0.202.0 Safari/532.0"), "Chrome 4.0.202.0 identified incorrectly"
122
+ assert_equal ["Chrome", 4, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 6.0 (x86_64); de-DE) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/4.0.202.2 Safari/532.0"), "Chrome 4.0.202.2 identified incorrectly"
123
+ assert_equal ["Chrome", 5, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.307.1 Safari/532.9"), "Chrome 5.0.307.1 identified incorrectly"
124
+ assert_equal ["Chrome", 5, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_0; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.307.11 Safari/532.9"), "Chrome 5.0.307.11 identified incorrectly"
125
+ assert_equal ["Chrome", 5, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.309.0 Safari/532.9"), "Chrome 5.0.309.0 identified incorrectly"
126
+ assert_equal ["Chrome", 6, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/6.0"), "Chrome 6.0 identified incorrectly"
127
+ end
128
+
129
+ should "identify Fennec correctly" do # Mozilla mobile browser
130
+ assert_equal ["Mozilla Gecko", 1.9, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux armv6l; en-US; rv:1.9.1a1pre) Gecko/2008071707 Fennec/0.5"), "Fennec 0.5 identified incorrectly"
131
+ assert_equal ["Mozilla Gecko", 1.9, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux armv6l; en-US; rv:1.9.1a2pre) Gecko/20080820121708 Fennec/0.7"), "Fennec 0.7 identified incorrectly"
132
+ assert_equal ["Mozilla Gecko", 1.9, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux armv6l; en-US; rv:1.9.1b1pre) Gecko/20080923171103 Fennec/0.8"), "Fennec 0.8 identified incorrectly"
133
+ assert_equal ["Mozilla Gecko", 1.9, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux armv6l; en-US; rv:1.9.1b1pre) Gecko/20081005220218 Gecko/2008052201 Fennec/0.9pre"), "Fennec 0.9pre identified incorrectly"
134
+ assert_equal ["Mozilla Gecko", 1.9, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2a1pre) Gecko/20090626 Fennec/1.0b2"), "Fennec 1.0b2 identified incorrectly"
135
+ assert_equal ["Mozilla Gecko", 1.9, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux armv7l; en-US; rv:1.9.2a1pre) Gecko/20090322 Fennec/1.0b2pre"), "Fennec 1.0b2pre identified incorrectly"
136
+ assert_equal ["Mozilla Gecko", 1.8, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.8.1.17) Gecko/20080829 Mozilla/5.0 (X11; U; Linux armv7l; en-US; rv:1.9.2a1pre) Gecko/20090322 Fennec/1.0b2pre"), "Fennec 1.0b2pre identified incorrectly"
137
+ end
138
+
139
+ should "identify Firefox correctly" do
140
+ assert_equal ["Firefox", 1.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.2; de-DE; rv:1.7.6) Gecko/20050321 Firefox/1.0.2"), "Firefox 1.0.2 identified incorrectly"
141
+ assert_equal ["Firefox", 1.5, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; lt-LT; rv:1.6) Gecko/20051114 Firefox/1.5"), "Firefox 1.5 identified incorrectly"
142
+ assert_equal ["Firefox", 1.5, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows NT 5.2; U; de; rv:1.8.0) Gecko/20060728 Firefox/1.5.0"), "Firefox 1.5.0 identified incorrectly"
143
+ assert_equal ["Firefox", 1.5, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.0.9) Gecko/20070126 Ubuntu/dapper-security Firefox/1.5.0.9"), "Firefox 1.5.0.9 identified incorrectly"
144
+ assert_equal ["Firefox", 2.0, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11;U;Linux i686;en-US;rv:1.8.1) Gecko/2006101022 Firefox/2.0"), "Firefox 2.0 identified incorrectly"
145
+ assert_equal ["Firefox", 2.0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; PPC Mac OS X; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0"), "Firefox 2.0.0 identified incorrectly"
146
+ assert_equal ["Firefox", 2.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows NT 6.0; U; hu; rv:1.8.1) Gecko/20061208 Firefox/2.0.0"), "Firefox 2.0.0 identified incorrectly"
147
+ assert_equal ["Firefox", 2.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.2; en-GB; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13"), "Firefox 2.0.0.13 identified incorrectly"
148
+ assert_equal ["Firefox", 3.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.0 (.NET CLR 3.5.30729)"), "Firefox 3.0.0 identified incorrectly"
149
+ assert_equal ["Firefox", 3.0, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; tr-TR; rv:1.9.0.10) Gecko/2009042523 Ubuntu/9.04 (jaunty) Firefox/3.0.10"), "Firefox 3.0.10 identified incorrectly"
150
+ assert_equal ["Firefox", 3.5, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.1) Gecko/20090624 Firefox/3.5 (.NET CLR 3.5.30729)"), "Firefox 3.5 identified incorrectly"
151
+ assert_equal ["Firefox", 3.5, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; fr; rv:1.9.1b4) Gecko/20090423 Firefox/3.5b4"), "Firefox 3.5b4 identified incorrectly"
152
+ assert_equal ["Firefox", 3.6, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.2) Gecko/20100105 Firefox/3.6 (.NET CLR 3.5.30729)"), "Firefox 3.6 identified incorrectly"
153
+ assert_equal ["Firefox", 3.6, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2"), "Firefox 3.6.2 identified incorrectly"
154
+ end
155
+
156
+ should "identify Flock correctly" do
157
+ assert_equal ["Firefox", 2.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080910 Firefox/2.0.0.17 Flock/1.2.6"), "Flock 1.2.6 identified incorrectly"
158
+ assert_equal ["Firefox", 3.0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.3) Gecko/2008100716 Firefox/3.0.3 Flock/2.0"), "Flock 2.0 identified incorrectly"
159
+ assert_equal ["Firefox", 3.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008100719 Firefox/3.0.3 Flock/2.0"), "Flock 2.0 identified incorrectly"
160
+ assert_equal ["Safari", 0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7) Gecko/20091221 AppleWebKit/531.21.8 KHTML/4.3.2 (like Gecko) Firefox/3.5.7 Flock/2.5.6 (.NET CLR 3.5.30729)"), "Flock 2.5.6 identified incorrectly"
161
+ end
162
+
163
+ should "identify Fluid correctly" do # Safari-based single-site browser
164
+ assert_equal ["Safari", 0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_1; nl-nl) AppleWebKit/532.3+ (KHTML, like Gecko) Fluid/0.9.6 Safari/532.3+"), "Fluid 0.9.6 identified incorrectly"
165
+ end
166
+
167
+ should "identify Iceweasel correctly" do # Debian's Firefox
168
+ assert_equal ["Firefox", 1.5, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.8pre) Gecko/20061001 Firefox/1.5.0.8pre (Iceweasel)"), "Iceweasel identified incorrectly"
169
+ assert_equal ["Firefox", 3.0, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.7) Gecko/2009030814 Iceweasel Firefox/3.0.7 (Debian-3.0.7-1)"), "Iceweasel identified incorrectly"
170
+ assert_equal ["Firefox", 2.0, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0 Iceweasel/2.0.0.3 (Debian-2.0.0.13-1)"), "Iceweasel 2.0.0.3 identified incorrectly"
171
+ end
172
+
173
+ should "identify IE correctly" do
174
+ assert_equal ["IE", 3, "Windows"], @e.identify_browser_and_os("Mozilla/3.0 (compatible; MSIE 3.0; Windows NT 5.0)"), "Internet Explorer 3.0 identified incorrectly"
175
+ assert_equal ["IE", 4, "Windows"], @e.identify_browser_and_os("Mozilla/2.0 (compatible; MSIE 4.0; Windows 98)"), "Internet Explorer 4.0 identified incorrectly"
176
+ assert_equal ["IE", 4, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 4.01; Windows CE)"), "Internet Explorer 4.01 identified incorrectly"
177
+ assert_equal ["IE", 4, "Unknown"], @e.identify_browser_and_os(" Mozilla/4.0 (compatible; MSIE 4.5; Mac_PowerPC)"), "Internet Explorer 4.5 identified incorrectly"
178
+ assert_equal ["IE", 4, "Unknown"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 4.5; Mac_PowerPC)"), "Internet Explorer 4.5 identified incorrectly"
179
+ assert_equal ["IE", 5, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt; .NET CLR 1.0.3705)"), "Internet Explorer 5.00 identified incorrectly"
180
+ assert_equal ["IE", 5, "Unknown"], @e.identify_browser_and_os(" Mozilla/4.0 (compatible; MSIE 5.2; Mac_PowerPC)"), "Internet Explorer 5.2 identified incorrectly"
181
+ assert_equal ["IE", 5, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1; .NET CLR 2.0.50727)"), "Internet Explorer 5.50 identified incorrectly"
182
+ assert_equal ["IE", 6, "Windows"], @e.identify_browser_and_os("Mozilla/4.08 (compatible; MSIE 6.0; Windows NT 5.1)"), "Internet Explorer 6.0 identified incorrectly"
183
+ assert_equal ["IE", 6, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"), "Internet Explorer 6.0 identified incorrectly"
184
+ assert_equal ["IE", 6, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 6.1; Windows XP)"), "Internet Explorer 6.1 identified incorrectly"
185
+ assert_equal ["IE", 7, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (Mozilla/4.0; MSIE 7.0; Windows NT 5.1; FDM; SV1; .NET CLR 3.0.04506.30)"), "Internet Explorer 7.0 identified incorrectly"
186
+ assert_equal ["IE", 7, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; c .NET CLR 3.0.04506; .NET CLR 3.5.30707; InfoPath.1; el-GR)"), "Internet Explorer 7.0 identified incorrectly"
187
+ assert_equal ["IE", 8, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.4; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MSSDMC2.5.2219.1)"), "Internet Explorer 8.0 identified incorrectly"
188
+ assert_equal ["IE", 8, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; Media Center PC 6.0; InfoPath.2; MS-RTC LM 8)"), "Internet Explorer 8.0 identified incorrectly"
189
+ assert_equal ["IE", 8, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"), "Internet Explorer 8.0 identified incorrectly"
190
+ end
191
+
192
+ should "identify Mozilla correctly" do
193
+ assert_equal ["Mozilla Gecko", 1.4, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030908 Debian/1.4-4"), "Mozilla 1.4 identified incorrectly"
194
+ assert_equal ["Mozilla Gecko", 1.4, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624"), "Mozilla 1.4 identified incorrectly"
195
+ assert_equal ["Mozilla Gecko", 1.5, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.5) Gecko/20031007"), "Mozilla 1.5 identified incorrectly"
196
+ assert_equal ["Mozilla Gecko", 1.5, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.0; de-AT; rv:1.5) Gecko/20031007"), "Mozilla 1.5 identified incorrectly"
197
+ assert_equal ["Mozilla Gecko", 1.6, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux x86_64; fr; rv:1.6) Gecko/20040115"), "Mozilla 1.6 identified incorrectly"
198
+ assert_equal ["Mozilla Gecko", 1.6, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.6) Gecko/20040113"), "Mozilla 1.6 identified incorrectly"
199
+ assert_equal ["Mozilla Gecko", 1.6, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.0; de-AT; rv:1.6) Gecko/20040113"), "Mozilla 1.6 identified incorrectly"
200
+ assert_equal ["Mozilla Gecko", 1.6, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; fr-FR; rv:1.6) Gecko/20040113"), "Mozilla 1.6 identified incorrectly"
201
+
202
+ # no way to tell that this string isn't Firefox, so let's lump it into Firefox
203
+ assert_equal ["Firefox", 0.9, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.7) Gecko/20040803 Firefox/0.9.3"), "Mozilla 1.7 identified incorrectly"
204
+
205
+ assert_equal ["Mozilla Gecko", 1.7, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040514"), "Mozilla 1.7 identified incorrectly"
206
+ assert_equal ["Mozilla Gecko", 1.7, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040616"), "Mozilla 1.7 identified incorrectly"
207
+ assert_equal ["Mozilla Gecko", 1.8, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 KHTML/3.5.5"), "Mozilla 1.8.0.5 identified incorrectly"
208
+ assert_equal ["Mozilla Gecko", 1.8, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.11) Gecko/20071206"), "Mozilla 1.8.1.11 identified incorrectly"
209
+ assert_equal ["Mozilla Gecko", 1.8, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.13) Gecko/20080313"), "Mozilla 1.8.1.13 identified incorrectly"
210
+ assert_equal ["Mozilla Gecko", 1.9, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9.2a1pre) Gecko"), "Mozilla 1.9.2a1pre identified incorrectly"
211
+
212
+ assert_equal ["Mozilla Gecko", 0.9, "Linux"], @e.identify_browser_and_os(" Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2) Gecko/20010726 Netscape6/6.1"), "Netscape 6.1 identified incorrectly"
213
+ assert_equal ["Mozilla Gecko", 0.9, "Mac"], @e.identify_browser_and_os(" Mozilla/5.0 (Macintosh; U; PPC; de-DE; rv:0.9.2) Gecko/20010726 Netscape6/6.1"), "Netscape 6.1 identified incorrectly"
214
+ assert_equal ["Mozilla Gecko", 0.9, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; fr-FR; rv:0.9.2) Gecko/20010726 Netscape6/6.1"), "Netscape 6.1 identified incorrectly"
215
+ assert_equal ["Mozilla Gecko", 1.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.0; ja-JP; rv:1.0.2) Gecko/20021120 Netscape/7.01"), "Netscape 7.01 identified incorrectly"
216
+ assert_equal ["Mozilla Gecko", 1.0, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0rc2) Gecko/20020513 Netscape/7.0b1"), "Netscape 7.0b1 identified incorrectly"
217
+ assert_equal ["Mozilla Gecko", 1.0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:1.0rc2) Gecko/20020512 Netscape/7.0b1"), "Netscape 7.0b1 identified incorrectly"
218
+ assert_equal ["Mozilla Gecko", 1.7, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20060111 Netscape/8.1"), "Netscape 8.1 identified incorrectly"
219
+
220
+ # no way to tell that these aren't Firefox
221
+ assert_equal ["Firefox", 2.0, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.8pre) Gecko/20071015 Firefox/2.0.0.7 Navigator/9.0"), "Netscape 9.0 identified incorrectly"
222
+ assert_equal ["Firefox", 2.0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.8pre) Gecko/20071015 Firefox/2.0.0.7 Navigator/9.0"), "Netscape 9.0 identified incorrectly"
223
+ assert_equal ["Firefox", 2.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.8.1.8pre) Gecko/20071015 Firefox/2.0.0.7 Navigator/9.0"), "Netscape 9.0 identified incorrectly"
224
+ end
225
+
226
+ should "identify OmniWeb correctly" do
227
+ assert_equal ["Safari", 0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US) AppleWebKit/125.4 (KHTML, like Gecko, Safari) OmniWeb/v563.59"), "OmniWeb v563.59 identified incorrectly"
228
+ end
229
+
230
+ should "identify Opera correctly" do
231
+ assert_equal ["Opera", 0, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera"), "Opera identified incorrectly"
232
+ assert_equal ["Opera", 0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; ; Intel Mac OS X; fr; rv:1.8.1.1) Gecko/20061204 Opera"), "Opera identified incorrectly"
233
+ assert_equal ["Opera", 7, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows XP) Opera 7.0 [en]"), "Opera 7.0 identified incorrectly"
234
+ assert_equal ["Opera", 7, "Windows"], @e.identify_browser_and_os("Mozilla/4.78 (Windows NT 5.0; U) Opera 7.01 [en]"), "Opera 7.01 identified incorrectly"
235
+ assert_equal ["Opera", 7, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows NT 5.0; U) Opera 7.01 [en]"), "Opera 7.01 identified incorrectly"
236
+ assert_equal ["Opera", 7, "Windows"], @e.identify_browser_and_os("Opera/7.52 (Windows NT 5.1; U) [en]"), "Opera 7.52 identified incorrectly"
237
+ assert_equal ["Opera", 7, "Linux"], @e.identify_browser_and_os("Opera/7.53 (X11; Linux i686; U) [en_US]"), "Opera 7.53 identified incorrectly"
238
+ assert_equal ["Opera", 8, "Linux"], @e.identify_browser_and_os("Opera/8.0 (X11; Linux i686; U; cs)"), "Opera 8.00 identified incorrectly"
239
+ assert_equal ["Opera", 8, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; ru) Opera 8.0"), "Opera 8.00 identified incorrectly"
240
+ assert_equal ["Opera", 9, "Mac"], @e.identify_browser_and_os("Opera/9.01 (Macintosh; PPC Mac OS X; U; en)"), "Opera 9.01 identified incorrectly"
241
+ assert_equal ["Opera", 9, "Linux"], @e.identify_browser_and_os("Opera/9.02 (X11; Linux i686; U; pl)"), "Opera 9.02 identified incorrectly"
242
+ assert_equal ["Opera", 9, "Windows"], @e.identify_browser_and_os("Opera/9.02 (Windows NT 5.0; U; de)"), "Opera 9.02 identified incorrectly"
243
+ assert_equal ["Opera", 9, "Linux"], @e.identify_browser_and_os("Opera/9.64 (X11; Linux x86_64; U; pl) Presto/2.1.1"), "Opera 9.64 identified incorrectly"
244
+ assert_equal ["Opera", 9, "Windows"], @e.identify_browser_and_os("Opera/9.64 (Windows NT 6.0; U; pl) Presto/2.1.1"), "Opera 9.64 identified incorrectly"
245
+ assert_equal ["Opera", 10, "Linux"], @e.identify_browser_and_os("Opera/9.80 (X11; Linux x86_64; U; en) Presto/2.2.15 Version/10.00"), "Opera 10.00 identified incorrectly"
246
+ assert_equal ["Opera", 10, "Windows"], @e.identify_browser_and_os("Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.2.15 Version/10.00"), "Opera 10.00 identified incorrectly"
247
+ end
248
+
249
+ should "identify Safari correctly" do
250
+ assert_equal ["Safari", 0, "iPhone"], @e.identify_browser_and_os("Mozilla/5.0 (iPod; U; CPU iPhone OS 2_2_1 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Mobile/5H11"), "Safari identified incorrectly"
251
+ assert_equal ["Safari", 0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.2 (KHTML, like Gecko) Safari/125.7"), "Safari 1.2.2 identified incorrectly"
252
+ assert_equal ["Safari", 0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; es) AppleWebKit/417.9 (KHTML, like Gecko) Safari/417.8"), "Safari 2.0.3 identified incorrectly"
253
+ assert_equal ["Safari", 3.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; nl) AppleWebKit/522.11.3 (KHTML, like Gecko) Version/3.0 Safari/522.11.3"), "Safari 3.0 identified incorrectly"
254
+ assert_equal ["Safari", 3.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; pl-PL) AppleWebKit/523.12.9 (KHTML, like Gecko) Version/3.0 Safari/523.12.9"), "Safari 3.0 identified incorrectly"
255
+ assert_equal ["Safari", 3.0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; de-de) AppleWebKit/522.11.1 (KHTML, like Gecko) Version/3.0.3 Safari/522.12.1"), "Safari 3.0.3 identified incorrectly"
256
+ assert_equal ["Safari", 3.1, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.2; ru-RU) AppleWebKit/525.13 (KHTML, like Gecko) Version/3.1 Safari/525.13.3"), "Safari 3.1 identified incorrectly"
257
+ assert_equal ["Safari", 3.1, "iPhone"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_2; en-gb) AppleWebKit/526+ (KHTML, like Gecko) Version/3.1 iPhone"), "Safari 3.1 identified incorrectly"
258
+ assert_equal ["Safari", 3.1, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; fr-fr) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.18"), "Safari 3.1.1 identified incorrectly"
259
+ assert_equal ["Safari", 4.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 6.0; ja-JP) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16"), "Safari 4.0 identified incorrectly"
260
+ assert_equal ["Safari", 4.0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.19.2 (KHTML, like Gecko) Version/4.0.1 Safari/530.18"), "Safari 4.0.1 identified incorrectly"
261
+ assert_equal ["Safari", 4.0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7"), "Safari 4.0.5 identified incorrectly"
262
+ assert_equal ["Safari", 4.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7"), "Safari 4.0.5 identified incorrectly"
263
+ end
264
+
265
+ should "identify SeaMonkey correctly" do # Mozilla distribution of core Gecko engine
266
+ assert_equal ["Mozilla Gecko", 1.8, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.8.1.5) Gecko/20070716 SeaMonkey/1.1.3"), "SeaMonkey 1.1.3 identified incorrectly"
267
+ assert_equal ["Mozilla Gecko", 1.8, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.1.5) Gecko/20070716 SeaMonkey/1.1.3"), "SeaMonkey 1.1.3 identified incorrectly"
268
+ assert_equal ["Mozilla Gecko", 1.9, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1b3pre) Gecko/20081208 SeaMonkey/2.0"), "SeaMonkey 2.0 identified incorrectly"
269
+ assert_equal ["Mozilla Gecko", 1.9, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9pre) Gecko/20100212 SeaMonkey/2.0.4pre"), "SeaMonkey 2.0.4pre identified incorrectly"
270
+ assert_equal ["Mozilla Gecko", 1.9, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.1b3pre) Gecko/20090223 SeaMonkey/2.0a3"), "SeaMonkey 2.0a3 identified incorrectly"
271
+ end
272
+ end
273
+ end
274
+
275
+ private
276
+
277
+ def mock_env(uri_override)
278
+ path, query = uri_override.split('?')
279
+
280
+ Hash[
281
+ 'HTTP_ACCEPT' => 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
282
+ 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
283
+ 'HTTP_ACCEPT_LANGUAGE' => 'en-us',
284
+ 'HTTP_CACHE_CONTROL' => 'max-age=0',
285
+ 'HTTP_CONNECTION' => 'keep-alive',
286
+ 'HTTP_COOKIE' => '_newrelic_development_session=BAh7CzoPc2Vzc2lvbl9pZCIlMTlkMGE5MTY1YmNhNTM5MjAxODRiNjdmNWY3ZTczOTU6D2FjY291bnRfaWRpBjoMdXNlcl9pZGkGOhNhcHBsaWNhdGlvbl9pZCIGMyIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7ADoQdGltZV93aW5kb3dvOg9UaW1lV2luZG93CjoQQGJlZ2luX3RpbWVJdToJVGltZQ3OixuAAAAAGAY6H0BtYXJzaGFsX3dpdGhfdXRjX2NvZXJjaW9uRjoWQHJlcG9ydGluZ19wZXJpb2RpQToOQGVuZF90aW1lSXU7Dg3RixuAAAAAGAY7D0Y6DkBlbmRzX25vd1Q6D0ByYW5nZV9rZXk6EUxBU1RfM19IT1VSUw%3D%3D--ac863fb87fc0233caa5063398300a9b4c0c1fe71; _newrelic_local_production_session=BAh7CjoPc2Vzc2lvbl9pZCIlMjFmOGQzMmMwZmUxYjYzMjcyYjU1NzBkYmMyNzA5NTc6DHVzZXJfaWRpHjoTYXBwbGljYXRpb25faWQiCTE3NDY6D2FjY291bnRfaWRpPiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D--22ebf9e965e67d49430d8b9c2817302b37628766; auth_token=d0bf9b0468c3b994b23a0e1cdc712824ab4246d9',
287
+ 'HTTP_HOST' => 'localhost:3000',
288
+ 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-us) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7',
289
+ 'HTTP_VERSION' => 'HTTP/1.1',
290
+ 'QUERY_STRING' => query,
291
+ 'REMOTE_ADDR' => '127.0.0.1',
292
+ 'REQUEST_METHOD' => 'GET',
293
+ 'PATH_INFO' => path,
294
+ 'REQUEST_PATH' => path,
295
+ 'REQUEST_URI' => uri_override,
296
+ 'SCRIPT_NAME' => '',
297
+ 'SERVER_NAME' => 'localhost',
298
+ 'SERVER_PORT' => '3000',
299
+ 'SERVER_PROTOCOL' => 'HTTP/1.1',
300
+ 'SERVER_SOFTWARE' => 'Unicorn 0.97.0',
301
+ 'rack.input' => StringIO.new,
302
+ 'rack.errorst' => StringIO.new,
303
+ # 'rack.logger' => '#<Logger:0x1014d7cc0>',
304
+ # 'rack.session.options' => 'path/key_session_idexpire_afterdomainhttponlytrue',
305
+ 'rack.multiprocess' => 'true',
306
+ 'rack.multithread' => 'false',
307
+ 'rack.run_once' => 'false',
308
+ 'rack.session' => '',
309
+ 'rack.url_scheme' => 'http',
310
+ 'rack.version' => '11'
311
+ ]
312
+ end
313
+
314
+ def mock_routes
315
+ ActionController::Routing::Routes.nil;
316
+ end
317
+ end if defined? NewRelic::Rack::Episodes