diff options
-rw-r--r-- | chrome/app/nibs/en.lproj/Preferences.xib | 10 | ||||
-rw-r--r-- | chrome/browser/app_controller_mac.mm | 14 | ||||
-rw-r--r-- | chrome/browser/cocoa/preferences_window_controller.h | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/preferences_window_controller.mm | 8 | ||||
-rw-r--r-- | chrome/browser/cocoa/preferences_window_controller_unittest.mm | 31 |
5 files changed, 60 insertions, 6 deletions
diff --git a/chrome/app/nibs/en.lproj/Preferences.xib b/chrome/app/nibs/en.lproj/Preferences.xib index 753db5e..fe2e515 100644 --- a/chrome/app/nibs/en.lproj/Preferences.xib +++ b/chrome/app/nibs/en.lproj/Preferences.xib @@ -2317,6 +2317,14 @@ ZGVkIGZpbGVzIGRvbid0IG9wZW4gYXV0b21hdGljYWxseS4</string> </object> <int key="connectionID">252</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">delegate</string> + <reference key="source" ref="871378074"/> + <reference key="destination" ref="1001"/> + </object> + <int key="connectionID">253</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -3789,7 +3797,7 @@ ZGVkIGZpbGVzIGRvbid0IG9wZW4gYXV0b21hdGljYWxseS4</string> </object> </object> <nil key="sourceID"/> - <int key="maxID">252</int> + <int key="maxID">253</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm index 082d0f5..a75c0e5 100644 --- a/chrome/browser/app_controller_mac.mm +++ b/chrome/browser/app_controller_mac.mm @@ -232,6 +232,13 @@ void OpenURLs(const std::vector<GURL>& urls) { OpenURLs(gurlVector); } +// Called when the preferences window is closed. We use this to release the +// window controller. +- (void)prefsWindowClosed:(NSNotification*)notify { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + prefsController_.reset(NULL); +} + // Show the preferences window, or bring it to the front if it's already // visible. - (IBAction)showPreferences:(id)sender { @@ -239,6 +246,13 @@ void OpenURLs(const std::vector<GURL>& urls) { PrefService* prefs = [self defaultProfile]->GetPrefs(); prefsController_.reset([[PreferencesWindowController alloc] initWithPrefs:prefs]); + // Watch for a notification of when it goes away so that we can destroy + // the controller. + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(prefsWindowClosed:) + name:kUserDoneEditingPrefsNotification + object:prefsController_.get()]; } [prefsController_ showPreferences:sender]; } diff --git a/chrome/browser/cocoa/preferences_window_controller.h b/chrome/browser/cocoa/preferences_window_controller.h index f1bf625..1b1fd28 100644 --- a/chrome/browser/cocoa/preferences_window_controller.h +++ b/chrome/browser/cocoa/preferences_window_controller.h @@ -19,3 +19,6 @@ class PrefService; - (IBAction)showPreferences:(id)sender; @end + +// NSNotification sent when the prefs window is closed. +extern NSString* const kUserDoneEditingPrefsNotification; diff --git a/chrome/browser/cocoa/preferences_window_controller.mm b/chrome/browser/cocoa/preferences_window_controller.mm index 941d6b3..632e9cc 100644 --- a/chrome/browser/cocoa/preferences_window_controller.mm +++ b/chrome/browser/cocoa/preferences_window_controller.mm @@ -7,7 +7,8 @@ #include "base/mac_util.h" #include "chrome/common/pref_service.h" -PreferencesWindowController* gPrefWindowSingleton = nil; +NSString* const kUserDoneEditingPrefsNotification = + @"kUserDoneEditingPrefsNotification"; @implementation PreferencesWindowController @@ -42,8 +43,9 @@ PreferencesWindowController* gPrefWindowSingleton = nil; // Called when the window is being closed. Send out a notification that the // user is done editing preferences. - (void)windowWillClose:(NSNotification *)notification { - // TODO(pinkerton): send notification. Write unit test that makes sure - // we receive it. + [[NSNotificationCenter defaultCenter] + postNotificationName:kUserDoneEditingPrefsNotification + object:self]; } @end diff --git a/chrome/browser/cocoa/preferences_window_controller_unittest.mm b/chrome/browser/cocoa/preferences_window_controller_unittest.mm index 85018b0..a53b9cb 100644 --- a/chrome/browser/cocoa/preferences_window_controller_unittest.mm +++ b/chrome/browser/cocoa/preferences_window_controller_unittest.mm @@ -11,6 +11,21 @@ #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" +// Helper Objective-C object that sets a BOOL when we get a particular +// callback from the prefs window. +@interface PrefsClosedObserver : NSObject { + @public + BOOL gotNotification_; +} +- (void)prefsWindowClosed:(NSNotification*)notify; +@end + +@implementation PrefsClosedObserver +- (void)prefsWindowClosed:(NSNotification*)notify { + gotNotification_ = YES; +} +@end + namespace { class PrefsControllerTest : public PlatformTest { @@ -27,10 +42,22 @@ class PrefsControllerTest : public PlatformTest { scoped_nsobject<PreferencesWindowController> pref_controller_; }; -// Test showing the preferences window and making sure it's visible -TEST_F(PrefsControllerTest, Show) { +// Test showing the preferences window and making sure it's visible, then +// making sure we get the notification when it's closed. +TEST_F(PrefsControllerTest, ShowAndClose) { [pref_controller_ showPreferences:nil]; EXPECT_TRUE([[pref_controller_ window] isVisible]); + + scoped_nsobject<PrefsClosedObserver> observer( + [[PrefsClosedObserver alloc] init]); + [[NSNotificationCenter defaultCenter] + addObserver:observer.get() + selector:@selector(prefsWindowClosed:) + name:kUserDoneEditingPrefsNotification + object:pref_controller_.get()]; + [[pref_controller_ window] performClose:observer]; + EXPECT_TRUE(observer.get()->gotNotification_); + [[NSNotificationCenter defaultCenter] removeObserver:observer.get()]; } } // namespace |