summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chrome_browser_application_mac_unittest.mm
diff options
context:
space:
mode:
authordmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-05 21:53:01 +0000
committerdmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-05 21:53:01 +0000
commitaaa47ee9d83f773d37aa4fd4a04097425ce62063 (patch)
tree9250680ad28ed8c31fdb967b702e2b638bd80347 /chrome/browser/chrome_browser_application_mac_unittest.mm
parent0d6bb06531d9b7d68e6d78b79b4ec29e68a059cb (diff)
downloadchromium_src-aaa47ee9d83f773d37aa4fd4a04097425ce62063.zip
chromium_src-aaa47ee9d83f773d37aa4fd4a04097425ce62063.tar.gz
chromium_src-aaa47ee9d83f773d37aa4fd4a04097425ce62063.tar.bz2
Cleans up our autorelease pool handling by making sure that an autorelease pool isn't created while the app is handling an event sent via -[NSApp sendEvent].
Branches browser/chrome_application_mac into browser/chrome_browser_application and base/chrome_application. Renderers will run as chrome_applications, and browsers will run as chrome_browser_applications. BUG=26418, 25462, 25463, 25465 TEST=1) See bug 25857. 2) Start up. Open 3+ windows. 3)Quit. See bugs for other repro cases. Review URL: http://codereview.chromium.org/345051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31135 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chrome_browser_application_mac_unittest.mm')
-rw-r--r--chrome/browser/chrome_browser_application_mac_unittest.mm81
1 files changed, 81 insertions, 0 deletions
diff --git a/chrome/browser/chrome_browser_application_mac_unittest.mm b/chrome/browser/chrome_browser_application_mac_unittest.mm
new file mode 100644
index 0000000..7fc134e
--- /dev/null
+++ b/chrome/browser/chrome_browser_application_mac_unittest.mm
@@ -0,0 +1,81 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/histogram.h"
+#import "chrome/browser/chrome_browser_application_mac.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chrome_browser_application_mac {
+
+// Generate an NSException with the given name.
+NSException* ExceptionNamed(NSString* name) {
+ return [NSException exceptionWithName:name
+ reason:@"No reason given"
+ userInfo:nil];
+}
+
+// Helper to keep binning expectations readible.
+size_t BinForExceptionNamed(NSString* name) {
+ return BinForException(ExceptionNamed(name));
+}
+
+TEST(ChromeApplicationMacTest, ExceptionBinning) {
+ // These exceptions must be in this order.
+ EXPECT_EQ(BinForExceptionNamed(NSGenericException), 0U);
+ EXPECT_EQ(BinForExceptionNamed(NSRangeException), 1U);
+ EXPECT_EQ(BinForExceptionNamed(NSInvalidArgumentException), 2U);
+ EXPECT_EQ(BinForExceptionNamed(NSMallocException), 3U);
+
+ // Random other exceptions map to |kUnknownNSException|.
+ EXPECT_EQ(BinForExceptionNamed(@"CustomName"), kUnknownNSException);
+ EXPECT_EQ(BinForExceptionNamed(@"Custom Name"), kUnknownNSException);
+ EXPECT_EQ(BinForExceptionNamed(@""), kUnknownNSException);
+ EXPECT_EQ(BinForException(nil), kUnknownNSException);
+}
+
+TEST(ChromeApplicationMacTest, RecordException) {
+ // Start up a histogram recorder.
+ StatisticsRecorder recorder;
+
+ StatisticsRecorder::Histograms histograms;
+ StatisticsRecorder::GetSnapshot("OSX.NSException", &histograms);
+ EXPECT_EQ(0U, histograms.size());
+
+ // Record some known exceptions.
+ RecordExceptionWithUma(ExceptionNamed(NSGenericException));
+ RecordExceptionWithUma(ExceptionNamed(NSGenericException));
+ RecordExceptionWithUma(ExceptionNamed(NSGenericException));
+ RecordExceptionWithUma(ExceptionNamed(NSGenericException));
+ RecordExceptionWithUma(ExceptionNamed(NSRangeException));
+ RecordExceptionWithUma(ExceptionNamed(NSInvalidArgumentException));
+ RecordExceptionWithUma(ExceptionNamed(NSInvalidArgumentException));
+ RecordExceptionWithUma(ExceptionNamed(NSInvalidArgumentException));
+ RecordExceptionWithUma(ExceptionNamed(NSMallocException));
+ RecordExceptionWithUma(ExceptionNamed(NSMallocException));
+
+ // Record some unknown exceptions.
+ RecordExceptionWithUma(ExceptionNamed(@"CustomName"));
+ RecordExceptionWithUma(ExceptionNamed(@"Custom Name"));
+ RecordExceptionWithUma(ExceptionNamed(@""));
+ RecordExceptionWithUma(nil);
+
+ // We should have exactly the right number of exceptions.
+ StatisticsRecorder::GetSnapshot("OSX.NSException", &histograms);
+ EXPECT_EQ(1U, histograms.size());
+ EXPECT_EQ(kUmaTargetedHistogramFlag, histograms[0]->flags());
+ Histogram::SampleSet sample;
+ histograms[0]->SnapshotSample(&sample);
+ EXPECT_EQ(4, sample.counts(0));
+ EXPECT_EQ(1, sample.counts(1));
+ EXPECT_EQ(3, sample.counts(2));
+ EXPECT_EQ(2, sample.counts(3));
+
+ // The unknown exceptions should end up in the overflow bucket.
+ EXPECT_EQ(kUnknownNSException + 1, histograms[0]->bucket_count());
+ EXPECT_EQ(4, sample.counts(kUnknownNSException));
+}
+
+} // chrome_browser_application_mac