diff options
22 files changed, 80 insertions, 128 deletions
diff --git a/base/base.gyp b/base/base.gyp index 3579c2d..c75544b 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -160,6 +160,7 @@ '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 8c483b3..52fef77 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -158,6 +158,8 @@ '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/content/common/mac/scoped_sending_event.h b/base/mac/scoped_sending_event.h index 160edeb..fcc984f 100644 --- a/content/common/mac/scoped_sending_event.h +++ b/base/mac/scoped_sending_event.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_COMMON_MAC_SCOPED_SENDING_EVENT_H_ -#define CONTENT_COMMON_MAC_SCOPED_SENDING_EVENT_H_ +#ifndef BASE_MAC_SCOPED_SENDING_EVENT_H_ +#define BASE_MAC_SCOPED_SENDING_EVENT_H_ #pragma once #include "base/basictypes.h" @@ -26,7 +26,7 @@ - (void)setHandlingSendEvent:(BOOL)handlingSendEvent; @end -namespace content { +namespace base { namespace mac { class ScopedSendingEvent { @@ -44,6 +44,6 @@ class ScopedSendingEvent { }; } // namespace mac -} // namespace content +} // namespace base -#endif // CONTENT_COMMON_MAC_SCOPED_SENDING_EVENT_H_ +#endif // BASE_MAC_SCOPED_SENDING_EVENT_H_ diff --git a/content/common/mac/scoped_sending_event.mm b/base/mac/scoped_sending_event.mm index bc4deac..c3813d8 100644 --- a/content/common/mac/scoped_sending_event.mm +++ b/base/mac/scoped_sending_event.mm @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#import "content/common/mac/scoped_sending_event.h" +#import "base/mac/scoped_sending_event.h" #include "base/logging.h" -namespace content { +namespace base { namespace mac { ScopedSendingEvent::ScopedSendingEvent() @@ -21,4 +21,4 @@ ScopedSendingEvent::~ScopedSendingEvent() { } } // namespace mac -} // namespace content +} // namespace base diff --git a/content/common/mac/scoped_sending_event_unittest.mm b/base/mac/scoped_sending_event_unittest.mm index 510a821..9ae9985 100644 --- a/content/common/mac/scoped_sending_event_unittest.mm +++ b/base/mac/scoped_sending_event_unittest.mm @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // 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" @@ -13,7 +13,7 @@ TEST(ScopedSendingEventTest, SetHandlingSendEvent) { id<CrAppProtocol> app = NSApp; EXPECT_FALSE([app isHandlingSendEvent]); { - content::mac::ScopedSendingEvent is_handling_send_event; + base::mac::ScopedSendingEvent is_handling_send_event; EXPECT_TRUE([app isHandlingSendEvent]); } EXPECT_FALSE([app isHandlingSendEvent]); @@ -24,10 +24,10 @@ TEST(ScopedSendingEventTest, NestedSetHandlingSendEvent) { id<CrAppProtocol> app = NSApp; EXPECT_FALSE([app isHandlingSendEvent]); { - content::mac::ScopedSendingEvent is_handling_send_event; + base::mac::ScopedSendingEvent is_handling_send_event; 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]); diff --git a/base/test/mock_chrome_application_mac.h b/base/test/mock_chrome_application_mac.h index e7e2c67..325c637 100644 --- a/base/test/mock_chrome_application_mac.h +++ b/base/test/mock_chrome_application_mac.h @@ -1,4 +1,4 @@ -// 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 // found in the LICENSE file. @@ -10,12 +10,18 @@ #import <AppKit/AppKit.h> +#include "base/mac/scoped_sending_event.h" #include "base/message_pump_mac.h" -// 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> +// 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_; +} @end #endif diff --git a/base/test/mock_chrome_application_mac.mm b/base/test/mock_chrome_application_mac.mm index 48db419..b0b8617 100644 --- a/base/test/mock_chrome_application_mac.mm +++ b/base/test/mock_chrome_application_mac.mm @@ -4,22 +4,38 @@ #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 NO; + return handlingSendEvent_; } + @end namespace mock_cr_app { void RegisterMockCrApp() { - 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)]); + [MockCrApp sharedApplication]; } } // namespace mock_cr_app diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 2d92a3a..609946c 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -34,7 +34,10 @@ include_rules = [ "+content/common/child_process_host.h", "+content/common/child_process_info.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", # TODO(gbilock) "+content/common/intents_messages.h", diff --git a/chrome/browser/chrome_browser_application_mac.mm b/chrome/browser/chrome_browser_application_mac.mm index c219252..282ecc3 100644 --- a/chrome/browser/chrome_browser_application_mac.mm +++ b/chrome/browser/chrome_browser_application_mac.mm @@ -369,7 +369,7 @@ void SwizzleInit() { } - (void)sendEvent:(NSEvent*)event { - content::mac::ScopedSendingEvent sendingEventScoper; + base::mac::ScopedSendingEvent sendingEventScoper; for (id<CrApplicationEventHookProtocol> handler in eventHooks_.get()) { [handler hookForEvent:event]; } diff --git a/chrome/browser/tab_contents/render_view_context_menu_mac.mm b/chrome/browser/tab_contents/render_view_context_menu_mac.mm index ae50c59..9659744 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_mac.mm +++ b/chrome/browser/tab_contents/render_view_context_menu_mac.mm @@ -5,13 +5,13 @@ #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" #include "base/compiler_specific.h" +#import "base/mac/scoped_sending_event.h" #include "base/memory/scoped_nsobject.h" #include "base/message_loop.h" #include "base/sys_string_conversions.h" #include "chrome/app/chrome_command_ids.h" #import "chrome/browser/ui/cocoa/browser_window_controller.h" #import "chrome/browser/ui/cocoa/menu_controller.h" -#import "content/common/mac/scoped_sending_event.h" #include "grit/generated_resources.h" namespace { @@ -88,7 +88,7 @@ void RenderViewContextMenuMac::PlatformInit() { // setting flags in -[CrApplication sendEvent:], but since // web-content menus are initiated by IPC message the setup has to // be done manually. - content::mac::ScopedSendingEvent sendingEventScoper; + base::mac::ScopedSendingEvent sendingEventScoper; // Show the menu. [NSMenu popUpContextMenu:[menuController_ menu] diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.mm b/chrome/browser/tab_contents/tab_contents_view_mac.mm index ff7ce92..121e082 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.mm +++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm @@ -8,6 +8,7 @@ #include <string> +#import "base/mac/scoped_sending_event.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/web_drag_bookmark_handler_mac.h" @@ -23,7 +24,6 @@ #import "content/browser/tab_contents/web_drag_dest_mac.h" #import "content/browser/tab_contents/web_drag_source_mac.h" #import "content/common/chrome_application_mac.h" -#import "content/common/mac/scoped_sending_event.h" #include "content/common/view_messages.h" #include "skia/ext/skia_utils_mac.h" #import "third_party/mozilla/NSPasteboard+Utils.h" @@ -172,7 +172,7 @@ void TabContentsViewMac::StartDragging( // processing -sendEvent:, so Close() is deferred in that case. // Drags from web content do not come via -sendEvent:, this sets the // 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 // processing events. diff --git a/content/browser/tab_contents/popup_menu_helper_mac.mm b/content/browser/tab_contents/popup_menu_helper_mac.mm index db861b6..29f502a 100644 --- a/content/browser/tab_contents/popup_menu_helper_mac.mm +++ b/content/browser/tab_contents/popup_menu_helper_mac.mm @@ -6,11 +6,11 @@ #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/message_loop.h" #include "content/browser/renderer_host/render_view_host.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_types.h" #import "ui/base/cocoa/base_view.h" @@ -54,7 +54,7 @@ void PopupMenuHelper::ShowPopupMenu( // setting flags in -[CrApplication sendEvent:], but since // web-content menus are initiated by IPC message the setup has to // 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. [menu_runner runMenuInView:cocoa_view diff --git a/content/common/chrome_application_mac.h b/content/common/chrome_application_mac.h index 9778023..35e09a7 100644 --- a/content/common/chrome_application_mac.h +++ b/content/common/chrome_application_mac.h @@ -11,7 +11,7 @@ #import <AppKit/AppKit.h> #include "base/basictypes.h" -#import "content/common/mac/scoped_sending_event.h" +#import "base/mac/scoped_sending_event.h" @interface CrApplication : NSApplication<CrAppControlProtocol> { @private diff --git a/content/common/chrome_application_mac.mm b/content/common/chrome_application_mac.mm index deec8b3..81b341c 100644 --- a/content/common/chrome_application_mac.mm +++ b/content/common/chrome_application_mac.mm @@ -37,7 +37,7 @@ } - (void)sendEvent:(NSEvent*)event { - content::mac::ScopedSendingEvent sendingEventScoper; + base::mac::ScopedSendingEvent sendingEventScoper; [super sendEvent:event]; } diff --git a/content/content_common.gypi b/content/content_common.gypi index 02b0a32..ad7cf85 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -181,8 +181,6 @@ 'common/mac/font_descriptor.mm', 'common/mac/font_loader.h', '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_stream_state.h', 'common/media/media_stream_messages.h', diff --git a/content/content_tests.gypi b/content/content_tests.gypi index 5dcd046..b9ba0be 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -74,8 +74,6 @@ 'test/browser_test_base.h', 'test/content_test_suite.cc', 'test/content_test_suite.h', - 'test/mock_chrome_application_mac.h', - 'test/mock_chrome_application_mac.mm', 'test/mock_keyboard.cc', 'test/mock_keyboard.h', 'test/mock_keyboard_driver_win.cc', @@ -228,8 +226,6 @@ 'browser/trace_subscriber_stdio_unittest.cc', 'common/mac/attributed_string_coder_unittest.mm', 'common/mac/font_descriptor_unittest.mm', - 'common/gamepad_seqlock_unittest.cc', - 'common/mac/scoped_sending_event_unittest.mm', 'common/gpu/gpu_feature_flags_unittest.cc', 'common/gpu/gpu_info_unittest.cc', 'common/hi_res_timer_manager_unittest.cc', diff --git a/content/test/content_test_suite.cc b/content/test/content_test_suite.cc index c67f10a..7a87809 100644 --- a/content/test/content_test_suite.cc +++ b/content/test/content_test_suite.cc @@ -17,7 +17,6 @@ #if defined(OS_MACOSX) #include "base/mac/scoped_nsautorelease_pool.h" -#include "content/test/mock_chrome_application_mac.h" #endif namespace { @@ -68,7 +67,6 @@ ContentTestSuite::~ContentTestSuite() { void ContentTestSuite::Initialize() { #if defined(OS_MACOSX) base::mac::ScopedNSAutoreleasePool autorelease_pool; - mock_cr_app::RegisterMockCrControlApp(); #endif base::TestSuite::Initialize(); diff --git a/content/test/mock_chrome_application_mac.h b/content/test/mock_chrome_application_mac.h deleted file mode 100644 index c068962..0000000 --- a/content/test/mock_chrome_application_mac.h +++ /dev/null @@ -1,32 +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 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_ diff --git a/content/test/mock_chrome_application_mac.mm b/content/test/mock_chrome_application_mac.mm deleted file mode 100644 index a5d4c0c..0000000 --- a/content/test/mock_chrome_application_mac.mm +++ /dev/null @@ -1,28 +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. - -#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 diff --git a/webkit/support/drt_application_mac.h b/webkit/support/drt_application_mac.h index 64e91b9..cc03508 100644 --- a/webkit/support/drt_application_mac.h +++ b/webkit/support/drt_application_mac.h @@ -1,4 +1,4 @@ -// 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 // found in the LICENSE file. @@ -6,12 +6,18 @@ #define WEBKIT_SUPPORT_DRT_APPLICATION_MAC_H #include "base/message_pump_mac.h" +#include "base/mac/scoped_sending_event.h" -@interface CrDrtApplication : NSApplication<CrAppProtocol> { +@interface CrDrtApplication : NSApplication<CrAppProtocol, + CrAppControlProtocol> { @private BOOL handlingSendEvent_; } +// CrAppProtocol - (BOOL)isHandlingSendEvent; + +// CrAppControlProtocol +- (void)setHandlingSendEvent:(BOOL)handlingSendEvent; @end #endif // WEBKIT_SUPPORT_DRT_APPLICATION_MAC_H diff --git a/webkit/support/drt_application_mac.mm b/webkit/support/drt_application_mac.mm index 06ae4a7..9fc61da 100644 --- a/webkit/support/drt_application_mac.mm +++ b/webkit/support/drt_application_mac.mm @@ -1,4 +1,4 @@ -// 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 // found in the LICENSE file. @@ -15,4 +15,9 @@ [super sendEvent:event]; handlingSendEvent_ = wasHandlingSendEvent; } + +- (void)setHandlingSendEvent:(BOOL)handlingSendEvent { + handlingSendEvent_ = handlingSendEvent; +} + @end diff --git a/webkit/tools/test_shell/test_shell_platform_delegate_mac.mm b/webkit/tools/test_shell/test_shell_platform_delegate_mac.mm index f856448..7cead5d 100644 --- a/webkit/tools/test_shell/test_shell_platform_delegate_mac.mm +++ b/webkit/tools/test_shell/test_shell_platform_delegate_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 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 // found in the LICENSE file. @@ -13,6 +13,7 @@ #include "base/command_line.h" #include "base/logging.h" #include "base/message_pump_mac.h" +#import "base/test/mock_chrome_application_mac.h" #include "third_party/WebKit/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.h" #include "webkit/tools/test_shell/test_shell.h" #include "webkit/tools/test_shell/test_shell_platform_delegate.h" @@ -20,26 +21,6 @@ static NSAutoreleasePool *gTestShellAutoreleasePool = nil; -@interface CrApplication : NSApplication<CrAppProtocol> { - @private - BOOL handlingSendEvent_; -} -- (BOOL)isHandlingSendEvent; -@end - -@implementation CrApplication -- (BOOL)isHandlingSendEvent { - return handlingSendEvent_; -} - -- (void)sendEvent:(NSEvent*)event { - BOOL wasHandlingSendEvent = handlingSendEvent_; - handlingSendEvent_ = YES; - [super sendEvent:event]; - handlingSendEvent_ = wasHandlingSendEvent; -} -@end - static void SetDefaultsToLayoutTestValues(void) { // So we can match the WebKit layout tests, we want to force a bunch of // preferences that control appearance to match. @@ -172,15 +153,15 @@ static void SwizzleNSPasteboard(void) { TestShellPlatformDelegate::TestShellPlatformDelegate( const CommandLine &command_line) : command_line_(command_line) { - // Force AppKit to init itself, but don't start the runloop yet - [CrApplication sharedApplication]; gTestShellAutoreleasePool = [[NSAutoreleasePool alloc] init]; + // Force AppKit to init itself, but don't start the runloop yet + [MockCrApp sharedApplication]; InitWebCoreSystemInterface(); [NSBundle loadNibNamed:@"MainMenu" owner:NSApp]; } TestShellPlatformDelegate::~TestShellPlatformDelegate() { - [gTestShellAutoreleasePool release]; + [gTestShellAutoreleasePool drain]; } bool TestShellPlatformDelegate::CheckLayoutTestSystemDependencies() { |