summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-30 17:59:24 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-30 17:59:24 +0000
commit4240438bc0860628bc93b59c291c9a4b6f69d2ff (patch)
tree6fa475044ba9b83cdb1e4290da649cb04ddaa9c7 /chrome/browser
parent75e287db9508753ada184ee4252b679912f6f085 (diff)
downloadchromium_src-4240438bc0860628bc93b59c291c9a4b6f69d2ff.zip
chromium_src-4240438bc0860628bc93b59c291c9a4b6f69d2ff.tar.gz
chromium_src-4240438bc0860628bc93b59c291c9a4b6f69d2ff.tar.bz2
Add a very basic preferences window controller with unit test. Fix the prefs nib to know the FileOwner is a NSWindowController and hook them together.
Review URL: http://codereview.chromium.org/102015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14958 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/app_controller_mac.mm10
-rw-r--r--chrome/browser/cocoa/preferences_window_controller.h21
-rw-r--r--chrome/browser/cocoa/preferences_window_controller.mm49
-rw-r--r--chrome/browser/cocoa/preferences_window_controller_unittest.mm36
4 files changed, 114 insertions, 2 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index 2992289..082d0f5 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -13,6 +13,7 @@
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_shutdown.h"
#import "chrome/browser/cocoa/bookmark_menu_bridge.h"
+#import "chrome/browser/cocoa/preferences_window_controller.h"
#include "chrome/browser/command_updater.h"
#include "chrome/browser/profile_manager.h"
#include "chrome/common/temp_scaffolding_stubs.h"
@@ -184,7 +185,7 @@ void OpenURLs(const std::vector<GURL>& urls) {
launch.OpenURLsInBrowser(BrowserList::GetLastActive(), false, urls);
}
-}
+} // namespace
- (void)getUrl:(NSAppleEventDescriptor*)event
withReply:(NSAppleEventDescriptor*)reply {
@@ -234,7 +235,12 @@ void OpenURLs(const std::vector<GURL>& urls) {
// Show the preferences window, or bring it to the front if it's already
// visible.
- (IBAction)showPreferences:(id)sender {
-// TODO(pinkerton): more goes here...
+ if (!prefsController_.get()) {
+ PrefService* prefs = [self defaultProfile]->GetPrefs();
+ prefsController_.reset([[PreferencesWindowController alloc]
+ initWithPrefs:prefs]);
+ }
+ [prefsController_ showPreferences:sender];
}
@end
diff --git a/chrome/browser/cocoa/preferences_window_controller.h b/chrome/browser/cocoa/preferences_window_controller.h
new file mode 100644
index 0000000..f1bf625
--- /dev/null
+++ b/chrome/browser/cocoa/preferences_window_controller.h
@@ -0,0 +1,21 @@
+// Copyright (c) 2009 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.
+
+#import <Cocoa/Cocoa.h>
+
+class PrefService;
+
+// A window controller that handles the preferences window.
+@interface PreferencesWindowController : NSWindowController {
+ @private
+ PrefService* prefs_; // weak ref
+}
+
+// Designated initializer. |prefs| should not be NULL.
+- (id)initWithPrefs:(PrefService*)prefs;
+
+// Show the preferences window.
+- (IBAction)showPreferences:(id)sender;
+
+@end
diff --git a/chrome/browser/cocoa/preferences_window_controller.mm b/chrome/browser/cocoa/preferences_window_controller.mm
new file mode 100644
index 0000000..941d6b3
--- /dev/null
+++ b/chrome/browser/cocoa/preferences_window_controller.mm
@@ -0,0 +1,49 @@
+// Copyright (c) 2009 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.
+
+#import "chrome/browser/cocoa/preferences_window_controller.h"
+
+#include "base/mac_util.h"
+#include "chrome/common/pref_service.h"
+
+PreferencesWindowController* gPrefWindowSingleton = nil;
+
+@implementation PreferencesWindowController
+
+- (id)initWithPrefs:(PrefService*)prefs {
+ DCHECK(prefs);
+ // Use initWithWindowNibPath:: instead of initWithWindowNibName: so we
+ // can override it in a unit test.
+ NSString *nibpath = [mac_util::MainAppBundle()
+ pathForResource:@"Preferences"
+ ofType:@"nib"];
+ if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
+ prefs_ = prefs;
+ }
+ return self;
+}
+
+- (void)awakeFromNib {
+
+}
+
+// Synchronizes the window's UI elements with the values in |prefs_|.
+- (void)syncWithPrefs {
+ // TODO(pinkerton): do it...
+}
+
+// Show the preferences window.
+- (IBAction)showPreferences:(id)sender {
+ [self syncWithPrefs];
+ [self showWindow:sender];
+}
+
+// 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.
+}
+
+@end
diff --git a/chrome/browser/cocoa/preferences_window_controller_unittest.mm b/chrome/browser/cocoa/preferences_window_controller_unittest.mm
new file mode 100644
index 0000000..85018b0
--- /dev/null
+++ b/chrome/browser/cocoa/preferences_window_controller_unittest.mm
@@ -0,0 +1,36 @@
+// Copyright (c) 2009 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.
+
+#import <Cocoa/Cocoa.h>
+
+#import "base/scoped_nsobject.h"
+#import "chrome/browser/cocoa/preferences_window_controller.h"
+#include "chrome/browser/cocoa/browser_test_helper.h"
+#include "chrome/browser/cocoa/cocoa_test_helper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+namespace {
+
+class PrefsControllerTest : public PlatformTest {
+ public:
+ PrefsControllerTest() {
+ PrefService* prefs = browser_helper_.profile()->GetPrefs();
+ pref_controller_.reset([[PreferencesWindowController alloc]
+ initWithPrefs:prefs]);
+ EXPECT_TRUE(pref_controller_.get());
+ }
+
+ BrowserTestHelper browser_helper_;
+ CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
+ scoped_nsobject<PreferencesWindowController> pref_controller_;
+};
+
+// Test showing the preferences window and making sure it's visible
+TEST_F(PrefsControllerTest, Show) {
+ [pref_controller_ showPreferences:nil];
+ EXPECT_TRUE([[pref_controller_ window] isVisible]);
+}
+
+} // namespace