OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/cocoa/options/preferences_window_controller.h" | 5 #import "chrome/browser/ui/cocoa/options/preferences_window_controller.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #import "base/scoped_nsobject.h" | 9 #import "base/scoped_nsobject.h" |
10 #include "chrome/browser/prefs/browser_prefs.h" | |
10 #include "chrome/browser/ui/cocoa/browser_test_helper.h" | 11 #include "chrome/browser/ui/cocoa/browser_test_helper.h" |
11 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 12 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
12 #import "chrome/browser/ui/cocoa/options/custom_home_pages_model.h" | 13 #import "chrome/browser/ui/cocoa/options/custom_home_pages_model.h" |
13 #include "chrome/browser/ui/options/options_window.h" | 14 #include "chrome/browser/ui/options/options_window.h" |
14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "chrome/test/testing_browser_process.h" | |
17 #include "chrome/test/testing_pref_service.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
16 #import "testing/gtest_mac.h" | 19 #import "testing/gtest_mac.h" |
17 #include "testing/platform_test.h" | 20 #include "testing/platform_test.h" |
18 | 21 |
19 // Helper Objective-C object that sets a BOOL when we get a particular | 22 // Helper Objective-C object that sets a BOOL when we get a particular |
20 // callback from the prefs window. | 23 // callback from the prefs window. |
21 @interface PrefsClosedObserver : NSObject { | 24 @interface PrefsClosedObserver : NSObject { |
22 @public | 25 @public |
23 BOOL gotNotification_; | 26 BOOL gotNotification_; |
24 } | 27 } |
25 - (void)prefsWindowClosed:(NSNotification*)notify; | 28 - (void)prefsWindowClosed:(NSNotification*)notify; |
26 @end | 29 @end |
27 | 30 |
28 @implementation PrefsClosedObserver | 31 @implementation PrefsClosedObserver |
29 - (void)prefsWindowClosed:(NSNotification*)notify { | 32 - (void)prefsWindowClosed:(NSNotification*)notify { |
30 gotNotification_ = YES; | 33 gotNotification_ = YES; |
31 } | 34 } |
32 @end | 35 @end |
33 | 36 |
34 namespace { | 37 namespace { |
35 | 38 |
36 class PrefsControllerTest : public CocoaTest { | 39 class PrefsControllerTest : public CocoaTest { |
37 public: | 40 public: |
38 virtual void SetUp() { | 41 virtual void SetUp() { |
39 CocoaTest::SetUp(); | 42 CocoaTest::SetUp(); |
40 // The metrics reporting pref is registerd on the local state object in | 43 browser::RegisterLocalState(&local_state_); |
41 // real builds, but we don't have one of those for unit tests. Register | 44 local_state_.RegisterBooleanPref(prefs::kMetricsReportingEnabled, false); |
42 // it on prefs so we'll find it when we go looking. | 45 browser_process_.get()->SetPrefService(&local_state_); |
Paweł Hajdan Jr.
2011/02/18 17:03:43
Just use g_browser_process here.
Mattias Nissler (ping if slow)
2011/02/18 17:08:04
That won't work, since the SetPrefService is a spe
| |
43 PrefService* prefs = browser_helper_.profile()->GetPrefs(); | |
44 prefs->RegisterBooleanPref(prefs::kMetricsReportingEnabled, false); | |
45 | 46 |
46 pref_controller_ = [[PreferencesWindowController alloc] | 47 pref_controller_ = [[PreferencesWindowController alloc] |
47 initWithProfile:browser_helper_.profile() | 48 initWithProfile:browser_helper_.profile() |
48 initialPage:OPTIONS_PAGE_DEFAULT]; | 49 initialPage:OPTIONS_PAGE_DEFAULT]; |
49 EXPECT_TRUE(pref_controller_); | 50 EXPECT_TRUE(pref_controller_); |
50 } | 51 } |
51 | 52 |
52 virtual void TearDown() { | 53 virtual void TearDown() { |
53 [pref_controller_ close]; | 54 [pref_controller_ close]; |
54 CocoaTest::TearDown(); | 55 CocoaTest::TearDown(); |
55 } | 56 } |
56 | 57 |
58 ScopedTestingBrowserProcess browser_process_; | |
59 TestingPrefService local_state_; | |
57 BrowserTestHelper browser_helper_; | 60 BrowserTestHelper browser_helper_; |
58 PreferencesWindowController* pref_controller_; | 61 PreferencesWindowController* pref_controller_; |
59 }; | 62 }; |
60 | 63 |
61 // Test showing the preferences window and making sure it's visible, then | 64 // Test showing the preferences window and making sure it's visible, then |
62 // making sure we get the notification when it's closed. | 65 // making sure we get the notification when it's closed. |
63 TEST_F(PrefsControllerTest, ShowAndClose) { | 66 TEST_F(PrefsControllerTest, ShowAndClose) { |
64 [pref_controller_ showPreferences:nil]; | 67 [pref_controller_ showPreferences:nil]; |
65 EXPECT_TRUE([[pref_controller_ window] isVisible]); | 68 EXPECT_TRUE([[pref_controller_ window] isVisible]); |
66 | 69 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 | 235 |
233 // TODO(akalin): Figure out how to test animation; we'll need everything | 236 // TODO(akalin): Figure out how to test animation; we'll need everything |
234 // to stick around until the animation finishes. | 237 // to stick around until the animation finishes. |
235 } | 238 } |
236 | 239 |
237 // TODO(akalin): Figure out how to test sync controls. | 240 // TODO(akalin): Figure out how to test sync controls. |
238 // TODO(akalin): Figure out how to test that sync controls are not shown | 241 // TODO(akalin): Figure out how to test that sync controls are not shown |
239 // when there isn't a sync service. | 242 // when there isn't a sync service. |
240 | 243 |
241 } // namespace | 244 } // namespace |
OLD | NEW |