diff options
author | hayato@chromium.org <hayato@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 06:45:50 +0000 |
---|---|---|
committer | hayato@chromium.org <hayato@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 06:45:50 +0000 |
commit | 62df0a016209f927a61b76cf85f98c68aeea141f (patch) | |
tree | 82e5496428285c4a40203bb95e24d201b97e3f35 /base | |
parent | 08bfdd6d84eba3f87af54ab14a761d0000f76da5 (diff) | |
download | chromium_src-62df0a016209f927a61b76cf85f98c68aeea141f.zip chromium_src-62df0a016209f927a61b76cf85f98c68aeea141f.tar.gz chromium_src-62df0a016209f927a61b76cf85f98c68aeea141f.tar.bz2 |
Revert 112249 - [Mac] Move ScopedSendingEvent from content/common/mac to base/mac.
Also merge content/ MockCrControlApp into base/ MockCrApp.
BUG=102224
Review URL: http://codereview.chromium.org/8724004
TBR=shess@chromium.org
Review URL: http://codereview.chromium.org/8762020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112411 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base.gyp | 1 | ||||
-rw-r--r-- | base/base.gypi | 2 | ||||
-rw-r--r-- | base/mac/scoped_sending_event.h | 49 | ||||
-rw-r--r-- | base/mac/scoped_sending_event.mm | 24 | ||||
-rw-r--r-- | base/mac/scoped_sending_event_unittest.mm | 38 | ||||
-rw-r--r-- | base/test/mock_chrome_application_mac.h | 16 | ||||
-rw-r--r-- | base/test/mock_chrome_application_mac.mm | 28 |
7 files changed, 11 insertions, 147 deletions
diff --git a/base/base.gyp b/base/base.gyp index c75544b..3579c2d 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -160,7 +160,6 @@ 'mac/foundation_util_unittest.mm', 'mac/mac_util_unittest.mm', 'mac/objc_property_releaser_unittest.mm', - 'mac/scoped_sending_event_unittest.mm', 'md5_unittest.cc', 'memory/linked_ptr_unittest.cc', 'memory/mru_cache_unittest.cc', diff --git a/base/base.gypi b/base/base.gypi index 52fef77..8c483b3 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -158,8 +158,6 @@ 'mac/scoped_nsautorelease_pool.mm', 'mac/scoped_nsexception_enabler.h', 'mac/scoped_nsexception_enabler.mm', - 'mac/scoped_sending_event.h', - 'mac/scoped_sending_event.mm', 'mach_ipc_mac.h', 'mach_ipc_mac.mm', 'memory/linked_ptr.h', diff --git a/base/mac/scoped_sending_event.h b/base/mac/scoped_sending_event.h deleted file mode 100644 index fcc984f..0000000 --- a/base/mac/scoped_sending_event.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2011 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. - -#ifndef BASE_MAC_SCOPED_SENDING_EVENT_H_ -#define BASE_MAC_SCOPED_SENDING_EVENT_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/memory/scoped_nsobject.h" -#include "base/message_pump_mac.h" - -// Nested event loops can pump IPC messages, including -// script-initiated tab closes, which could release objects that the -// nested event loop might message. CrAppProtocol defines how to ask -// the embedding NSApplication subclass if an event is currently being -// handled, in which case such closes are deferred to the top-level -// event loop. -// -// ScopedSendingEvent allows script-initiated event loops to work like -// a nested event loop, as such events do not arrive via -sendEvent:. -// CrAppControlProtocol lets ScopedSendingEvent tell the embedding -// NSApplication what to return from -handlingSendEvent. - -@protocol CrAppControlProtocol<CrAppProtocol> -- (void)setHandlingSendEvent:(BOOL)handlingSendEvent; -@end - -namespace base { -namespace mac { - -class ScopedSendingEvent { - public: - ScopedSendingEvent(); - ~ScopedSendingEvent(); - - private: - // The NSApp in control at the time the constructor was run, to be - // sure the |handling_| setting is restored appropriately. - NSObject<CrAppControlProtocol>* app_; - BOOL handling_; // Value of -[app_ handlingSendEvent] at construction. - - DISALLOW_COPY_AND_ASSIGN(ScopedSendingEvent); -}; - -} // namespace mac -} // namespace base - -#endif // BASE_MAC_SCOPED_SENDING_EVENT_H_ diff --git a/base/mac/scoped_sending_event.mm b/base/mac/scoped_sending_event.mm deleted file mode 100644 index c3813d8..0000000 --- a/base/mac/scoped_sending_event.mm +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2011 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 "base/mac/scoped_sending_event.h" - -#include "base/logging.h" - -namespace base { -namespace mac { - -ScopedSendingEvent::ScopedSendingEvent() - : app_(static_cast<NSObject<CrAppControlProtocol>*>(NSApp)) { - DCHECK([app_ conformsToProtocol:@protocol(CrAppControlProtocol)]); - handling_ = [app_ isHandlingSendEvent]; - [app_ setHandlingSendEvent:YES]; -} - -ScopedSendingEvent::~ScopedSendingEvent() { - [app_ setHandlingSendEvent:handling_]; -} - -} // namespace mac -} // namespace base diff --git a/base/mac/scoped_sending_event_unittest.mm b/base/mac/scoped_sending_event_unittest.mm deleted file mode 100644 index 9ae9985..0000000 --- a/base/mac/scoped_sending_event_unittest.mm +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2011 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 "base/mac/scoped_sending_event.h" - -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -// Sets the flag within scope, resets when leaving scope. -TEST(ScopedSendingEventTest, SetHandlingSendEvent) { - id<CrAppProtocol> app = NSApp; - EXPECT_FALSE([app isHandlingSendEvent]); - { - base::mac::ScopedSendingEvent is_handling_send_event; - EXPECT_TRUE([app isHandlingSendEvent]); - } - EXPECT_FALSE([app isHandlingSendEvent]); -} - -// Nested call restores previous value rather than resetting flag. -TEST(ScopedSendingEventTest, NestedSetHandlingSendEvent) { - id<CrAppProtocol> app = NSApp; - EXPECT_FALSE([app isHandlingSendEvent]); - { - base::mac::ScopedSendingEvent is_handling_send_event; - EXPECT_TRUE([app isHandlingSendEvent]); - { - base::mac::ScopedSendingEvent nested_is_handling_send_event; - EXPECT_TRUE([app isHandlingSendEvent]); - } - EXPECT_TRUE([app isHandlingSendEvent]); - } - EXPECT_FALSE([app isHandlingSendEvent]); -} - -} // namespace diff --git a/base/test/mock_chrome_application_mac.h b/base/test/mock_chrome_application_mac.h index 325c637..e7e2c67 100644 --- a/base/test/mock_chrome_application_mac.h +++ b/base/test/mock_chrome_application_mac.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -10,18 +10,12 @@ #import <AppKit/AppKit.h> -#include "base/mac/scoped_sending_event.h" #include "base/message_pump_mac.h" -// A basic implementation of CrAppProtocol and -// CrAppControlProtocol. This can be used in tests that need an -// NSApplication and use a runloop, or which need a ScopedSendingEvent -// when handling a nested event loop. -@interface MockCrApp : NSApplication<CrAppProtocol, - CrAppControlProtocol> { - @private - BOOL handlingSendEvent_; -} +// A mock implementation of CrAppProtocol that claims that -sendEvent: is never +// on the stack. This can be used in tests that need an NSApplication and use a +// runloop, but don't run nested message loops. +@interface MockCrApp : NSApplication<CrAppProtocol> @end #endif diff --git a/base/test/mock_chrome_application_mac.mm b/base/test/mock_chrome_application_mac.mm index b0b8617..48db419 100644 --- a/base/test/mock_chrome_application_mac.mm +++ b/base/test/mock_chrome_application_mac.mm @@ -4,38 +4,22 @@ #include "base/test/mock_chrome_application_mac.h" -#include "base/auto_reset.h" #include "base/logging.h" @implementation MockCrApp - -+ (NSApplication*)sharedApplication { - NSApplication* app = [super sharedApplication]; - DCHECK([app conformsToProtocol:@protocol(CrAppControlProtocol)]) - << "Existing NSApp (class " << [[app className] UTF8String] - << ") does not conform to required protocol."; - return app; -} - -- (void)sendEvent:(NSEvent*)event { - AutoReset<BOOL> scoper(&handlingSendEvent_, YES); - [super sendEvent:event]; -} - -- (void)setHandlingSendEvent:(BOOL)handlingSendEvent { - handlingSendEvent_ = handlingSendEvent; -} - - (BOOL)isHandlingSendEvent { - return handlingSendEvent_; + return NO; } - @end namespace mock_cr_app { void RegisterMockCrApp() { - [MockCrApp sharedApplication]; + NSApplication* app = [MockCrApp sharedApplication]; + + // Would prefer ASSERT_TRUE() to provide better test failures, but + // this class is used by remoting/ for a non-test use. + DCHECK([app conformsToProtocol:@protocol(CrAppProtocol)]); } } // namespace mock_cr_app |