Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Side by Side Diff: chrome/browser/chrome_application_mac_unittest.mm

Issue 345051: Cleans up our autorelease handling so that we don't create a layered ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import <Cocoa/Cocoa.h>
6
7 #include "base/histogram.h"
8 #import "chrome/browser/chrome_application_mac.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace CrApplicationNSException {
12
13 // Generate an NSException with the given name.
14 NSException* ExceptionNamed(NSString* name) {
15 return [NSException exceptionWithName:name
16 reason:@"No reason given"
17 userInfo:nil];
18 }
19
20 // Helper to keep binning expectations readible.
21 size_t BinForExceptionNamed(NSString* name) {
22 return BinForException(ExceptionNamed(name));
23 }
24
25 TEST(ChromeApplicationMacTest, ExceptionBinning) {
26 // These exceptions must be in this order.
27 EXPECT_EQ(BinForExceptionNamed(NSGenericException), 0U);
28 EXPECT_EQ(BinForExceptionNamed(NSRangeException), 1U);
29 EXPECT_EQ(BinForExceptionNamed(NSInvalidArgumentException), 2U);
30 EXPECT_EQ(BinForExceptionNamed(NSMallocException), 3U);
31
32 // Random other exceptions map to |kUnknownNSException|.
33 EXPECT_EQ(BinForExceptionNamed(@"CustomName"), kUnknownNSException);
34 EXPECT_EQ(BinForExceptionNamed(@"Custom Name"), kUnknownNSException);
35 EXPECT_EQ(BinForExceptionNamed(@""), kUnknownNSException);
36 EXPECT_EQ(BinForException(nil), kUnknownNSException);
37 }
38
39 TEST(ChromeApplicationMacTest, RecordException) {
40 // Start up a histogram recorder.
41 StatisticsRecorder recorder;
42
43 StatisticsRecorder::Histograms histograms;
44 StatisticsRecorder::GetSnapshot("OSX.NSException", &histograms);
45 EXPECT_EQ(0U, histograms.size());
46
47 // Record some known exceptions.
48 RecordExceptionWithUma(ExceptionNamed(NSGenericException));
49 RecordExceptionWithUma(ExceptionNamed(NSGenericException));
50 RecordExceptionWithUma(ExceptionNamed(NSGenericException));
51 RecordExceptionWithUma(ExceptionNamed(NSGenericException));
52 RecordExceptionWithUma(ExceptionNamed(NSRangeException));
53 RecordExceptionWithUma(ExceptionNamed(NSInvalidArgumentException));
54 RecordExceptionWithUma(ExceptionNamed(NSInvalidArgumentException));
55 RecordExceptionWithUma(ExceptionNamed(NSInvalidArgumentException));
56 RecordExceptionWithUma(ExceptionNamed(NSMallocException));
57 RecordExceptionWithUma(ExceptionNamed(NSMallocException));
58
59 // Record some unknown exceptions.
60 RecordExceptionWithUma(ExceptionNamed(@"CustomName"));
61 RecordExceptionWithUma(ExceptionNamed(@"Custom Name"));
62 RecordExceptionWithUma(ExceptionNamed(@""));
63 RecordExceptionWithUma(nil);
64
65 // We should have exactly the right number of exceptions.
66 StatisticsRecorder::GetSnapshot("OSX.NSException", &histograms);
67 EXPECT_EQ(1U, histograms.size());
68 EXPECT_EQ(kUmaTargetedHistogramFlag, histograms[0]->flags());
69 Histogram::SampleSet sample;
70 histograms[0]->SnapshotSample(&sample);
71 EXPECT_EQ(4, sample.counts(0));
72 EXPECT_EQ(1, sample.counts(1));
73 EXPECT_EQ(3, sample.counts(2));
74 EXPECT_EQ(2, sample.counts(3));
75
76 // The unknown exceptions should end up in the overflow bucket.
77 EXPECT_EQ(kUnknownNSException + 1, histograms[0]->bucket_count());
78 EXPECT_EQ(4, sample.counts(kUnknownNSException));
79 }
80
81 } // CrApplicationNSException
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698