Commit d87aa8ef authored by shess@chromium.org's avatar shess@chromium.org

[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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112249 0039d316-1c4b-4281-b951-d872f2087c98
parent 74c3b375
...@@ -160,6 +160,7 @@ ...@@ -160,6 +160,7 @@
'mac/foundation_util_unittest.mm', 'mac/foundation_util_unittest.mm',
'mac/mac_util_unittest.mm', 'mac/mac_util_unittest.mm',
'mac/objc_property_releaser_unittest.mm', 'mac/objc_property_releaser_unittest.mm',
'mac/scoped_sending_event_unittest.mm',
'md5_unittest.cc', 'md5_unittest.cc',
'memory/linked_ptr_unittest.cc', 'memory/linked_ptr_unittest.cc',
'memory/mru_cache_unittest.cc', 'memory/mru_cache_unittest.cc',
......
...@@ -159,6 +159,8 @@ ...@@ -159,6 +159,8 @@
'mac/scoped_nsautorelease_pool.mm', 'mac/scoped_nsautorelease_pool.mm',
'mac/scoped_nsexception_enabler.h', 'mac/scoped_nsexception_enabler.h',
'mac/scoped_nsexception_enabler.mm', 'mac/scoped_nsexception_enabler.mm',
'mac/scoped_sending_event.h',
'mac/scoped_sending_event.mm',
'mach_ipc_mac.h', 'mach_ipc_mac.h',
'mach_ipc_mac.mm', 'mach_ipc_mac.mm',
'memory/linked_ptr.h', 'memory/linked_ptr.h',
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_COMMON_MAC_SCOPED_SENDING_EVENT_H_ #ifndef BASE_MAC_SCOPED_SENDING_EVENT_H_
#define CONTENT_COMMON_MAC_SCOPED_SENDING_EVENT_H_ #define BASE_MAC_SCOPED_SENDING_EVENT_H_
#pragma once #pragma once
#include "base/basictypes.h" #include "base/basictypes.h"
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent; - (void)setHandlingSendEvent:(BOOL)handlingSendEvent;
@end @end
namespace content { namespace base {
namespace mac { namespace mac {
class ScopedSendingEvent { class ScopedSendingEvent {
...@@ -44,6 +44,6 @@ class ScopedSendingEvent { ...@@ -44,6 +44,6 @@ class ScopedSendingEvent {
}; };
} // namespace mac } // namespace mac
} // namespace content } // namespace base
#endif // CONTENT_COMMON_MAC_SCOPED_SENDING_EVENT_H_ #endif // BASE_MAC_SCOPED_SENDING_EVENT_H_
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import "content/common/mac/scoped_sending_event.h" #import "base/mac/scoped_sending_event.h"
#include "base/logging.h" #include "base/logging.h"
namespace content { namespace base {
namespace mac { namespace mac {
ScopedSendingEvent::ScopedSendingEvent() ScopedSendingEvent::ScopedSendingEvent()
...@@ -21,4 +21,4 @@ ScopedSendingEvent::~ScopedSendingEvent() { ...@@ -21,4 +21,4 @@ ScopedSendingEvent::~ScopedSendingEvent() {
} }
} // namespace mac } // namespace mac
} // namespace content } // namespace base
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import "content/common/mac/scoped_sending_event.h" #import "base/mac/scoped_sending_event.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -13,7 +13,7 @@ TEST(ScopedSendingEventTest, SetHandlingSendEvent) { ...@@ -13,7 +13,7 @@ TEST(ScopedSendingEventTest, SetHandlingSendEvent) {
id<CrAppProtocol> app = NSApp; id<CrAppProtocol> app = NSApp;
EXPECT_FALSE([app isHandlingSendEvent]); EXPECT_FALSE([app isHandlingSendEvent]);
{ {
content::mac::ScopedSendingEvent is_handling_send_event; base::mac::ScopedSendingEvent is_handling_send_event;
EXPECT_TRUE([app isHandlingSendEvent]); EXPECT_TRUE([app isHandlingSendEvent]);
} }
EXPECT_FALSE([app isHandlingSendEvent]); EXPECT_FALSE([app isHandlingSendEvent]);
...@@ -24,10 +24,10 @@ TEST(ScopedSendingEventTest, NestedSetHandlingSendEvent) { ...@@ -24,10 +24,10 @@ TEST(ScopedSendingEventTest, NestedSetHandlingSendEvent) {
id<CrAppProtocol> app = NSApp; id<CrAppProtocol> app = NSApp;
EXPECT_FALSE([app isHandlingSendEvent]); EXPECT_FALSE([app isHandlingSendEvent]);
{ {
content::mac::ScopedSendingEvent is_handling_send_event; base::mac::ScopedSendingEvent is_handling_send_event;
EXPECT_TRUE([app isHandlingSendEvent]); EXPECT_TRUE([app isHandlingSendEvent]);
{ {
content::mac::ScopedSendingEvent nested_is_handling_send_event; base::mac::ScopedSendingEvent nested_is_handling_send_event;
EXPECT_TRUE([app isHandlingSendEvent]); EXPECT_TRUE([app isHandlingSendEvent]);
} }
EXPECT_TRUE([app isHandlingSendEvent]); EXPECT_TRUE([app isHandlingSendEvent]);
......
// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -10,12 +10,18 @@ ...@@ -10,12 +10,18 @@
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
#include "base/mac/scoped_sending_event.h"
#include "base/message_pump_mac.h" #include "base/message_pump_mac.h"
// A mock implementation of CrAppProtocol that claims that -sendEvent: is never // A basic implementation of CrAppProtocol and
// on the stack. This can be used in tests that need an NSApplication and use a // CrAppControlProtocol. This can be used in tests that need an
// runloop, but don't run nested message loops. // NSApplication and use a runloop, or which need a ScopedSendingEvent
@interface MockCrApp : NSApplication<CrAppProtocol> // when handling a nested event loop.
@interface MockCrApp : NSApplication<CrAppProtocol,
CrAppControlProtocol> {
@private
BOOL handlingSendEvent_;
}
@end @end
#endif #endif
......
...@@ -4,22 +4,38 @@ ...@@ -4,22 +4,38 @@
#include "base/test/mock_chrome_application_mac.h" #include "base/test/mock_chrome_application_mac.h"
#include "base/auto_reset.h"
#include "base/logging.h" #include "base/logging.h"
@implementation MockCrApp @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 { - (BOOL)isHandlingSendEvent {
return NO; return handlingSendEvent_;
} }
@end @end
namespace mock_cr_app { namespace mock_cr_app {
void RegisterMockCrApp() { void RegisterMockCrApp() {
NSApplication* app = [MockCrApp sharedApplication]; [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 } // namespace mock_cr_app
...@@ -35,7 +35,10 @@ include_rules = [ ...@@ -35,7 +35,10 @@ include_rules = [
"+content/common/child_process_host.h", "+content/common/child_process_host.h",
"+content/common/child_process_info.h", "+content/common/child_process_info.h",
"+content/common/chrome_application_mac.h", "+content/common/chrome_application_mac.h",
"+content/common/mac/scoped_sending_event.h", "+content/common/geolocation_messages.h",
"+content/common/geoposition.h",
"+content/common/pepper_plugin_registry.h",
"+content/common/test_url_constants.h",
"+content/common/view_messages.h", "+content/common/view_messages.h",
# TODO(pfeldman) # TODO(pfeldman)
"+content/common/devtools_messages.h", "+content/common/devtools_messages.h",
......
...@@ -369,7 +369,7 @@ void SwizzleInit() { ...@@ -369,7 +369,7 @@ void SwizzleInit() {
} }
- (void)sendEvent:(NSEvent*)event { - (void)sendEvent:(NSEvent*)event {
content::mac::ScopedSendingEvent sendingEventScoper; base::mac::ScopedSendingEvent sendingEventScoper;
for (id<CrApplicationEventHookProtocol> handler in eventHooks_.get()) { for (id<CrApplicationEventHookProtocol> handler in eventHooks_.get()) {
[handler hookForEvent:event]; [handler hookForEvent:event];
} }
......
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
#include "chrome/browser/tab_contents/render_view_context_menu_mac.h" #include "chrome/browser/tab_contents/render_view_context_menu_mac.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#import "base/mac/scoped_sending_event.h"
#include "base/memory/scoped_nsobject.h" #include "base/memory/scoped_nsobject.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/sys_string_conversions.h" #include "base/sys_string_conversions.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h" #import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/menu_controller.h" #import "chrome/browser/ui/cocoa/menu_controller.h"
#import "content/common/mac/scoped_sending_event.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
namespace { namespace {
...@@ -88,7 +88,7 @@ void RenderViewContextMenuMac::PlatformInit() { ...@@ -88,7 +88,7 @@ void RenderViewContextMenuMac::PlatformInit() {
// setting flags in -[CrApplication sendEvent:], but since // setting flags in -[CrApplication sendEvent:], but since
// web-content menus are initiated by IPC message the setup has to // web-content menus are initiated by IPC message the setup has to
// be done manually. // be done manually.
content::mac::ScopedSendingEvent sendingEventScoper; base::mac::ScopedSendingEvent sendingEventScoper;
// Show the menu. // Show the menu.
[NSMenu popUpContextMenu:[menuController_ menu] [NSMenu popUpContextMenu:[menuController_ menu]
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <string> #include <string>
#import "base/mac/scoped_sending_event.h"
#import "chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.h" #import "chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.h"
#include "chrome/browser/tab_contents/render_view_context_menu_mac.h" #include "chrome/browser/tab_contents/render_view_context_menu_mac.h"
#include "chrome/browser/tab_contents/web_drag_bookmark_handler_mac.h" #include "chrome/browser/tab_contents/web_drag_bookmark_handler_mac.h"
...@@ -23,7 +24,6 @@ ...@@ -23,7 +24,6 @@
#import "content/browser/tab_contents/web_drag_dest_mac.h" #import "content/browser/tab_contents/web_drag_dest_mac.h"
#import "content/browser/tab_contents/web_drag_source_mac.h" #import "content/browser/tab_contents/web_drag_source_mac.h"
#import "content/common/chrome_application_mac.h" #import "content/common/chrome_application_mac.h"
#import "content/common/mac/scoped_sending_event.h"
#include "content/common/view_messages.h" #include "content/common/view_messages.h"
#include "skia/ext/skia_utils_mac.h" #include "skia/ext/skia_utils_mac.h"
#import "third_party/mozilla/NSPasteboard+Utils.h" #import "third_party/mozilla/NSPasteboard+Utils.h"
...@@ -172,7 +172,7 @@ void TabContentsViewMac::StartDragging( ...@@ -172,7 +172,7 @@ void TabContentsViewMac::StartDragging(
// processing -sendEvent:, so Close() is deferred in that case. // processing -sendEvent:, so Close() is deferred in that case.
// Drags from web content do not come via -sendEvent:, this sets the // Drags from web content do not come via -sendEvent:, this sets the
// same flag -sendEvent: would. // same flag -sendEvent: would.
content::mac::ScopedSendingEvent sending_event_scoper; base::mac::ScopedSendingEvent sending_event_scoper;
// The drag invokes a nested event loop, arrange to continue // The drag invokes a nested event loop, arrange to continue
// processing events. // processing events.
......
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
#include "content/browser/tab_contents/popup_menu_helper_mac.h" #include "content/browser/tab_contents/popup_menu_helper_mac.h"
#import "base/mac/scoped_sending_event.h"
#include "base/memory/scoped_nsobject.h" #include "base/memory/scoped_nsobject.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "content/browser/renderer_host/render_view_host.h" #include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/renderer_host/render_widget_host_view_mac.h" #include "content/browser/renderer_host/render_widget_host_view_mac.h"
#import "content/common/mac/scoped_sending_event.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
#import "ui/base/cocoa/base_view.h" #import "ui/base/cocoa/base_view.h"
...@@ -54,7 +54,7 @@ void PopupMenuHelper::ShowPopupMenu( ...@@ -54,7 +54,7 @@ void PopupMenuHelper::ShowPopupMenu(
// setting flags in -[CrApplication sendEvent:], but since // setting flags in -[CrApplication sendEvent:], but since
// web-content menus are initiated by IPC message the setup has to // web-content menus are initiated by IPC message the setup has to
// be done manually. // be done manually.
content::mac::ScopedSendingEvent sending_event_scoper; base::mac::ScopedSendingEvent sending_event_scoper;
// Now run a SYNCHRONOUS NESTED EVENT LOOP until the pop-up is finished. // Now run a SYNCHRONOUS NESTED EVENT LOOP until the pop-up is finished.
[menu_runner runMenuInView:cocoa_view [menu_runner runMenuInView:cocoa_view
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
#include "base/basictypes.h" #include "base/basictypes.h"
#import "content/common/mac/scoped_sending_event.h" #import "base/mac/scoped_sending_event.h"
@interface CrApplication : NSApplication<CrAppControlProtocol> { @interface CrApplication : NSApplication<CrAppControlProtocol> {
@private @private
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
} }
- (void)sendEvent:(NSEvent*)event { - (void)sendEvent:(NSEvent*)event {
content::mac::ScopedSendingEvent sendingEventScoper; base::mac::ScopedSendingEvent sendingEventScoper;
[super sendEvent:event]; [super sendEvent:event];
} }
......
...@@ -176,8 +176,6 @@ ...@@ -176,8 +176,6 @@
'common/mac/font_descriptor.mm', 'common/mac/font_descriptor.mm',
'common/mac/font_loader.h', 'common/mac/font_loader.h',
'common/mac/font_loader.mm', 'common/mac/font_loader.mm',
'common/mac/scoped_sending_event.h',
'common/mac/scoped_sending_event.mm',
'common/media/audio_messages.h', 'common/media/audio_messages.h',
'common/media/audio_stream_state.h', 'common/media/audio_stream_state.h',
'common/media/media_stream_messages.h', 'common/media/media_stream_messages.h',
......
...@@ -74,8 +74,6 @@ ...@@ -74,8 +74,6 @@
'test/browser_test_base.h', 'test/browser_test_base.h',
'test/content_test_suite.cc', 'test/content_test_suite.cc',
'test/content_test_suite.h', 'test/content_test_suite.h',
'test/mock_chrome_application_mac.h',
'test/mock_chrome_application_mac.mm',
'test/mock_keyboard.cc', 'test/mock_keyboard.cc',
'test/mock_keyboard.h', 'test/mock_keyboard.h',
'test/mock_keyboard_driver_win.cc', 'test/mock_keyboard_driver_win.cc',
...@@ -227,7 +225,6 @@ ...@@ -227,7 +225,6 @@
'browser/trace_subscriber_stdio_unittest.cc', 'browser/trace_subscriber_stdio_unittest.cc',
'common/mac/attributed_string_coder_unittest.mm', 'common/mac/attributed_string_coder_unittest.mm',
'common/mac/font_descriptor_unittest.mm', 'common/mac/font_descriptor_unittest.mm',
'common/mac/scoped_sending_event_unittest.mm',
'common/gpu/gpu_feature_flags_unittest.cc', 'common/gpu/gpu_feature_flags_unittest.cc',
'common/gpu/gpu_info_unittest.cc', 'common/gpu/gpu_info_unittest.cc',
'common/hi_res_timer_manager_unittest.cc', 'common/hi_res_timer_manager_unittest.cc',
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
#include "base/mac/scoped_nsautorelease_pool.h" #include "base/mac/scoped_nsautorelease_pool.h"
#include "content/test/mock_chrome_application_mac.h"
#endif #endif
namespace { namespace {
...@@ -68,7 +67,6 @@ ContentTestSuite::~ContentTestSuite() { ...@@ -68,7 +67,6 @@ ContentTestSuite::~ContentTestSuite() {
void ContentTestSuite::Initialize() { void ContentTestSuite::Initialize() {
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
base::mac::ScopedNSAutoreleasePool autorelease_pool; base::mac::ScopedNSAutoreleasePool autorelease_pool;
mock_cr_app::RegisterMockCrControlApp();
#endif #endif
base::TestSuite::Initialize(); base::TestSuite::Initialize();
......
// 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 CONTENT_TEST_MOCK_CHROME_APPLICATION_MAC_H_
#define CONTENT_TEST_MOCK_CHROME_APPLICATION_MAC_H_
#pragma once
#if defined(__OBJC__)
#import <AppKit/AppKit.h>
#include "content/common/mac/scoped_sending_event.h"
// Mock implementation supporting CrAppControlProtocol. Can be used
// in tests using ScopedSendingEvent to deal with nested message
// loops. Also implements CrAppProtocol so can be used as a
// replacement for MockCrApp (in base/).
@interface MockCrControlApp : NSApplication<CrAppControlProtocol> {
@private
BOOL isHandlingSendEvent_;
}
@end
#endif // __OBJC__
// To be used to instantiate MockCrControlApp from C++ code.
namespace mock_cr_app {
void RegisterMockCrControlApp();
} // namespace mock_cr_app
#endif // CONTENT_TEST_MOCK_CHROME_APPLICATION_MAC_H_
// 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.
#include "content/test/mock_chrome_application_mac.h"
#include "testing/gtest/include/gtest/gtest.h"
@implementation MockCrControlApp
- (BOOL)isHandlingSendEvent {
return isHandlingSendEvent_;
}
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent {
isHandlingSendEvent_ = handlingSendEvent;
}
@end
namespace mock_cr_app {
void RegisterMockCrControlApp() {
NSApplication* app = [MockCrControlApp sharedApplication];
ASSERT_TRUE([app conformsToProtocol:@protocol(CrAppControlProtocol)]);
}
} // namespace mock_cr_app
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment