diff options
author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-23 21:27:37 +0000 |
---|---|---|
committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-23 21:27:37 +0000 |
commit | 8a7d72732a65afd4078f3e7535db264f06308697 (patch) | |
tree | d555ed545cb5db5512ea3b295dd83870aa884c17 | |
parent | 23d04b9739bab34064dbddf42dc23ef9323185c3 (diff) | |
download | chromium_src-8a7d72732a65afd4078f3e7535db264f06308697.zip chromium_src-8a7d72732a65afd4078f3e7535db264f06308697.tar.gz chromium_src-8a7d72732a65afd4078f3e7535db264f06308697.tar.bz2 |
Refactor and clean up code now that chrome::testing::NSRunLoopRunAllPending() exists.
BUG=87839,30394
TEST=unit_tests
Review URL: http://codereview.chromium.org/7712008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97922 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 11 insertions, 38 deletions
diff --git a/chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm b/chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm index 865a4c3..460345d 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm @@ -13,6 +13,7 @@ #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h" #include "chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.h" +#include "chrome/browser/ui/cocoa/run_loop_testing.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -197,8 +198,7 @@ TEST_F(LinkInfoBarControllerTest, ShowAndClickLink) { // Spin the runloop because the invocation for closing the infobar is done on // a 0-timer delayed selector. - [[NSRunLoop currentRunLoop] runUntilDate: - [NSDate dateWithTimeIntervalSinceNow:0.1]]; + chrome::testing::NSRunLoopRunAllPending(); ASSERT_TRUE(delegate_closed()); EXPECT_TRUE(closed_delegate_link_clicked_); diff --git a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h index b39e0eb..d44d83b 100644 --- a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h +++ b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h @@ -61,14 +61,4 @@ class ZoomLevelObserver; //////////////////////////////////////////////////////////////////////////////// -@interface WrenchMenuController (UnitTesting) -// |-dispatchWrenchMenuCommand:| calls this after it has determined the tag of -// the sender. The default implementation executes the command on the outermost -// run loop using |-performSelector...withDelay:|. This is not desirable in -// unit tests because it's hard to test around run loops in a deterministic -// manner. To avoid those headaches, tests should provide an alternative -// implementation. -- (void)dispatchCommandInternal:(NSInteger)tag; -@end - #endif // CHROME_BROWSER_UI_COCOA_WRENCH_MENU_WRENCH_MENU_CONTROLLER_H_ diff --git a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm index 68f0754..54b134d6 100644 --- a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm +++ b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm @@ -167,17 +167,14 @@ class ZoomLevelObserver : public NotificationObserver { // The custom views within the Wrench menu are abnormal and keep the menu // open after a target-action. Close the menu manually. [menu_ cancelTracking]; - [self dispatchCommandInternal:tag]; - } -} -- (void)dispatchCommandInternal:(NSInteger)tag { - // Executing certain commands from the nested run loop of the menu can lead - // to wonky behavior (e.g. http://crbug.com/49716). To avoid this, schedule - // the dispatch on the outermost run loop. - [self performSelector:@selector(performCommandDispatch:) - withObject:[NSNumber numberWithInt:tag] - afterDelay:0.0]; + // Executing certain commands from the nested run loop of the menu can lead + // to wonky behavior (e.g. http://crbug.com/49716). To avoid this, schedule + // the dispatch on the outermost run loop. + [self performSelector:@selector(performCommandDispatch:) + withObject:[NSNumber numberWithInt:tag] + afterDelay:0.0]; + } } // Used to perform the actual dispatch on the outermost runloop. diff --git a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm index 3451179..146b874 100644 --- a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm @@ -7,6 +7,7 @@ #include "chrome/browser/ui/cocoa/browser_test_helper.h" #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" +#include "chrome/browser/ui/cocoa/run_loop_testing.h" #import "chrome/browser/ui/cocoa/view_resizer_pong.h" #import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h" #include "chrome/browser/ui/toolbar/wrench_menu_model.h" @@ -14,14 +15,6 @@ #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" -// Override to avoid dealing with run loops in the testing environment. -@implementation WrenchMenuController (UnitTesting) -- (void)dispatchCommandInternal:(NSInteger)tag { - [self wrenchMenuModel]->ExecuteCommand(tag); -} -@end - - namespace { class MockWrenchMenuModel : public WrenchMenuModel { @@ -79,6 +72,7 @@ TEST_F(WrenchMenuControllerTest, DispatchSimple) { [controller() setModel:&fake_model_]; [controller() dispatchWrenchMenuCommand:button.get()]; + chrome::testing::NSRunLoopRunAllPending(); } } // namespace diff --git a/tools/valgrind/gtest_exclude/unit_tests.gtest_mac.txt b/tools/valgrind/gtest_exclude/unit_tests.gtest_mac.txt index 19ff43b..dddce9b 100644 --- a/tools/valgrind/gtest_exclude/unit_tests.gtest_mac.txt +++ b/tools/valgrind/gtest_exclude/unit_tests.gtest_mac.txt @@ -13,11 +13,6 @@ ProcessInfoSnapshotMacTest.EffectiveVsRealUserIDTest # Following tests do not pass memcheck test. # See http://crbug.com/30393. NSMenuItemAdditionsTest.TestMOnDifferentLayouts -# See http://crbug.com/30394. -PrefsControllerTest.GetPrefsViewForPage -PrefsControllerTest.GetToolbarItemForPage -PrefsControllerTest.ShowAndClose -PrefsControllerTest.SwitchToPage # Hangs # See http://crbug.com/75733 @@ -34,9 +29,6 @@ MacSandboxTest.FileAccess BalloonControllerTest.ShowAndCloseTest BalloonControllerTest.SizesTest -# http://crbug.com/87839 -LinkInfoBarControllerTest.ShowAndClickLink - # http://crbug.com/89030 ConnectionTesterTest.DeleteWhileInProgress |