1// Copyright 2011 The Chromium Authors 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "base/test/mock_chrome_application_mac.h" 6 7#include "base/auto_reset.h" 8#include "base/check.h" 9 10@implementation MockCrApp 11 12+ (NSApplication*)sharedApplication { 13 NSApplication* app = [super sharedApplication]; 14 DCHECK([app conformsToProtocol:@protocol(CrAppControlProtocol)]) 15 << "Existing NSApp (class " << [[app className] UTF8String] 16 << ") does not conform to required protocol."; 17 DCHECK(base::message_pump_apple::UsingCrApp()) 18 << "message_pump_apple::Create() was called before " 19 << "+[MockCrApp sharedApplication]"; 20 return app; 21} 22 23- (void)sendEvent:(NSEvent*)event { 24 base::AutoReset<BOOL> scoper(&_handlingSendEvent, YES); 25 [super sendEvent:event]; 26} 27 28- (void)setHandlingSendEvent:(BOOL)handlingSendEvent { 29 _handlingSendEvent = handlingSendEvent; 30} 31 32- (BOOL)isHandlingSendEvent { 33 return _handlingSendEvent; 34} 35 36@end 37 38namespace mock_cr_app { 39 40void RegisterMockCrApp() { 41 [MockCrApp sharedApplication]; 42 43 // If there was an invocation to NSApp prior to this method, then the NSApp 44 // will not be a MockCrApp, but will instead be an NSApplication. 45 // This is undesirable and we must enforce that this doesn't happen. 46 CHECK([NSApp isKindOfClass:[MockCrApp class]]); 47} 48 49} // namespace mock_cr_app 50