OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #import "base/scoped_nsobject.h" | 7 #import "base/scoped_nsobject.h" |
8 #import "chrome/browser/cocoa/preferences_window_controller.h" | 8 #import "chrome/browser/cocoa/preferences_window_controller.h" |
9 #include "chrome/browser/cocoa/browser_test_helper.h" | 9 #include "chrome/browser/cocoa/browser_test_helper.h" |
10 #include "chrome/browser/cocoa/cocoa_test_helper.h" | 10 #include "chrome/browser/cocoa/cocoa_test_helper.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
13 | 13 |
| 14 // Helper Objective-C object that sets a BOOL when we get a particular |
| 15 // callback from the prefs window. |
| 16 @interface PrefsClosedObserver : NSObject { |
| 17 @public |
| 18 BOOL gotNotification_; |
| 19 } |
| 20 - (void)prefsWindowClosed:(NSNotification*)notify; |
| 21 @end |
| 22 |
| 23 @implementation PrefsClosedObserver |
| 24 - (void)prefsWindowClosed:(NSNotification*)notify { |
| 25 gotNotification_ = YES; |
| 26 } |
| 27 @end |
| 28 |
14 namespace { | 29 namespace { |
15 | 30 |
16 class PrefsControllerTest : public PlatformTest { | 31 class PrefsControllerTest : public PlatformTest { |
17 public: | 32 public: |
18 PrefsControllerTest() { | 33 PrefsControllerTest() { |
19 PrefService* prefs = browser_helper_.profile()->GetPrefs(); | 34 PrefService* prefs = browser_helper_.profile()->GetPrefs(); |
20 pref_controller_.reset([[PreferencesWindowController alloc] | 35 pref_controller_.reset([[PreferencesWindowController alloc] |
21 initWithPrefs:prefs]); | 36 initWithPrefs:prefs]); |
22 EXPECT_TRUE(pref_controller_.get()); | 37 EXPECT_TRUE(pref_controller_.get()); |
23 } | 38 } |
24 | 39 |
25 BrowserTestHelper browser_helper_; | 40 BrowserTestHelper browser_helper_; |
26 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... | 41 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... |
27 scoped_nsobject<PreferencesWindowController> pref_controller_; | 42 scoped_nsobject<PreferencesWindowController> pref_controller_; |
28 }; | 43 }; |
29 | 44 |
30 // Test showing the preferences window and making sure it's visible | 45 // Test showing the preferences window and making sure it's visible, then |
31 TEST_F(PrefsControllerTest, Show) { | 46 // making sure we get the notification when it's closed. |
| 47 TEST_F(PrefsControllerTest, ShowAndClose) { |
32 [pref_controller_ showPreferences:nil]; | 48 [pref_controller_ showPreferences:nil]; |
33 EXPECT_TRUE([[pref_controller_ window] isVisible]); | 49 EXPECT_TRUE([[pref_controller_ window] isVisible]); |
| 50 |
| 51 scoped_nsobject<PrefsClosedObserver> observer( |
| 52 [[PrefsClosedObserver alloc] init]); |
| 53 [[NSNotificationCenter defaultCenter] |
| 54 addObserver:observer.get() |
| 55 selector:@selector(prefsWindowClosed:) |
| 56 name:kUserDoneEditingPrefsNotification |
| 57 object:pref_controller_.get()]; |
| 58 [[pref_controller_ window] performClose:observer]; |
| 59 EXPECT_TRUE(observer.get()->gotNotification_); |
| 60 [[NSNotificationCenter defaultCenter] removeObserver:observer.get()]; |
34 } | 61 } |
35 | 62 |
36 } // namespace | 63 } // namespace |
OLD | NEW |