| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #import "base/mac/scoped_nsexception_enabler.h" | 7 #import "base/mac/scoped_nsexception_enabler.h" |
| 8 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 9 #include "base/metrics/statistics_recorder.h" | 10 #include "base/metrics/statistics_recorder.h" |
| 10 #import "chrome/browser/chrome_browser_application_mac.h" | 11 #import "chrome/browser/chrome_browser_application_mac.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 using base::Histogram; | 14 using base::Histogram; |
| 15 using base::HistogramSamples; |
| 14 using base::StatisticsRecorder; | 16 using base::StatisticsRecorder; |
| 15 | 17 |
| 16 namespace chrome_browser_application_mac { | 18 namespace chrome_browser_application_mac { |
| 17 | 19 |
| 18 // Generate an NSException with the given name. | 20 // Generate an NSException with the given name. |
| 19 NSException* ExceptionNamed(NSString* name) { | 21 NSException* ExceptionNamed(NSString* name) { |
| 20 base::mac::ScopedNSExceptionEnabler enabler; | 22 base::mac::ScopedNSExceptionEnabler enabler; |
| 21 | 23 |
| 22 return [NSException exceptionWithName:name | 24 return [NSException exceptionWithName:name |
| 23 reason:@"No reason given" | 25 reason:@"No reason given" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // Record some unknown exceptions. | 69 // Record some unknown exceptions. |
| 68 RecordExceptionWithUma(ExceptionNamed(@"CustomName")); | 70 RecordExceptionWithUma(ExceptionNamed(@"CustomName")); |
| 69 RecordExceptionWithUma(ExceptionNamed(@"Custom Name")); | 71 RecordExceptionWithUma(ExceptionNamed(@"Custom Name")); |
| 70 RecordExceptionWithUma(ExceptionNamed(@"")); | 72 RecordExceptionWithUma(ExceptionNamed(@"")); |
| 71 RecordExceptionWithUma(nil); | 73 RecordExceptionWithUma(nil); |
| 72 | 74 |
| 73 // We should have exactly the right number of exceptions. | 75 // We should have exactly the right number of exceptions. |
| 74 StatisticsRecorder::GetSnapshot("OSX.NSException", &histograms); | 76 StatisticsRecorder::GetSnapshot("OSX.NSException", &histograms); |
| 75 EXPECT_EQ(1U, histograms.size()); | 77 EXPECT_EQ(1U, histograms.size()); |
| 76 EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histograms[0]->flags()); | 78 EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histograms[0]->flags()); |
| 77 Histogram::SampleSet sample; | 79 |
| 78 histograms[0]->SnapshotSample(&sample); | 80 scoped_ptr<HistogramSamples> samples(histograms[0]->SnapshotSamples()); |
| 79 EXPECT_EQ(4, sample.counts(0)); | 81 EXPECT_EQ(4, samples->GetCount(0)); |
| 80 EXPECT_EQ(1, sample.counts(1)); | 82 EXPECT_EQ(1, samples->GetCount(1)); |
| 81 EXPECT_EQ(3, sample.counts(2)); | 83 EXPECT_EQ(3, samples->GetCount(2)); |
| 82 EXPECT_EQ(2, sample.counts(3)); | 84 EXPECT_EQ(2, samples->GetCount(3)); |
| 83 | 85 |
| 84 // The unknown exceptions should end up in the overflow bucket. | 86 // The unknown exceptions should end up in the overflow bucket. |
| 85 EXPECT_EQ(kUnknownNSException + 1, histograms[0]->bucket_count()); | 87 EXPECT_EQ(kUnknownNSException + 1, histograms[0]->bucket_count()); |
| 86 EXPECT_EQ(4, sample.counts(kUnknownNSException)); | 88 EXPECT_EQ(4, samples->GetCount(kUnknownNSException)); |
| 87 } | 89 } |
| 88 | 90 |
| 89 } // chrome_browser_application_mac | 91 } // chrome_browser_application_mac |
| OLD | NEW |