mock_chrome_application_mac.mm 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (c) 2011 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. #include "base/test/mock_chrome_application_mac.h"
  5. #include "base/auto_reset.h"
  6. #include "base/check.h"
  7. @implementation MockCrApp
  8. + (NSApplication*)sharedApplication {
  9. NSApplication* app = [super sharedApplication];
  10. DCHECK([app conformsToProtocol:@protocol(CrAppControlProtocol)])
  11. << "Existing NSApp (class " << [[app className] UTF8String]
  12. << ") does not conform to required protocol.";
  13. DCHECK(base::MessagePumpMac::UsingCrApp())
  14. << "MessagePumpMac::Create() was called before "
  15. << "+[MockCrApp sharedApplication]";
  16. return app;
  17. }
  18. - (void)sendEvent:(NSEvent*)event {
  19. base::AutoReset<BOOL> scoper(&_handlingSendEvent, YES);
  20. [super sendEvent:event];
  21. }
  22. - (void)setHandlingSendEvent:(BOOL)handlingSendEvent {
  23. _handlingSendEvent = handlingSendEvent;
  24. }
  25. - (BOOL)isHandlingSendEvent {
  26. return _handlingSendEvent;
  27. }
  28. @end
  29. namespace mock_cr_app {
  30. void RegisterMockCrApp() {
  31. [MockCrApp sharedApplication];
  32. // If there was an invocation to NSApp prior to this method, then the NSApp
  33. // will not be a MockCrApp, but will instead be an NSApplication.
  34. // This is undesirable and we must enforce that this doesn't happen.
  35. CHECK([NSApp isKindOfClass:[MockCrApp class]]);
  36. }
  37. } // namespace mock_cr_app