[Mac] Do not initialize the MockCrApplication in base::TestSuite.
This is not the right layer to do this, since it forces all test suites to have
an initialized Cocoa NSApp. Instead, only do it for test suites that require it.
BUG=71686
Review URL: https://codereview.chromium.org/656293003
Cr-Commit-Position: refs/heads/master@{#300275}
diff --git a/base/mac/scoped_sending_event_unittest.mm b/base/mac/scoped_sending_event_unittest.mm
index 9ae9985..95f6eba 100644
--- a/base/mac/scoped_sending_event_unittest.mm
+++ b/base/mac/scoped_sending_event_unittest.mm
@@ -4,12 +4,39 @@
#import "base/mac/scoped_sending_event.h"
+#import <Foundation/Foundation.h>
+
+#include "base/mac/scoped_nsobject.h"
#include "testing/gtest/include/gtest/gtest.h"
+@interface ScopedSendingEventTestCrApp : NSObject <CrAppControlProtocol> {
+ @private
+ BOOL handlingSendEvent_;
+}
+@property(nonatomic, assign, getter=isHandlingSendEvent) BOOL handlingSendEvent;
+@end
+
+@implementation ScopedSendingEventTestCrApp
+@synthesize handlingSendEvent = handlingSendEvent_;
+@end
+
namespace {
+class ScopedSendingEventTest : public testing::Test {
+ public:
+ ScopedSendingEventTest() : app_([[ScopedSendingEventTestCrApp alloc] init]) {
+ NSApp = app_.get();
+ }
+ virtual ~ScopedSendingEventTest() {
+ NSApp = nil;
+ }
+
+ private:
+ base::scoped_nsobject<ScopedSendingEventTestCrApp> app_;
+};
+
// Sets the flag within scope, resets when leaving scope.
-TEST(ScopedSendingEventTest, SetHandlingSendEvent) {
+TEST_F(ScopedSendingEventTest, SetHandlingSendEvent) {
id<CrAppProtocol> app = NSApp;
EXPECT_FALSE([app isHandlingSendEvent]);
{
@@ -20,7 +47,7 @@
}
// Nested call restores previous value rather than resetting flag.
-TEST(ScopedSendingEventTest, NestedSetHandlingSendEvent) {
+TEST_F(ScopedSendingEventTest, NestedSetHandlingSendEvent) {
id<CrAppProtocol> app = NSApp;
EXPECT_FALSE([app isHandlingSendEvent]);
{