diff options
author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-19 01:54:23 +0000 |
---|---|---|
committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-19 01:54:23 +0000 |
commit | c2788ecbcd5c443fb129f63b7b86f83e944b4950 (patch) | |
tree | 5bf36eb1814dbafe12604c05c19b703897a2c74b /chrome/browser/cocoa/nswindow_local_state_unittest.mm | |
parent | d4208dd1717889212bc7749168d1a7b8dea44ebe (diff) | |
download | chromium_src-c2788ecbcd5c443fb129f63b7b86f83e944b4950.zip chromium_src-c2788ecbcd5c443fb129f63b7b86f83e944b4950.tar.gz chromium_src-c2788ecbcd5c443fb129f63b7b86f83e944b4950.tar.bz2 |
[Mac] Polish the search engine manager
* Make the edit search engine window a sheet.
* Only allow one instance of the search engine manager to be opened at once.
* The search engine manager now remembers its position.
* Create NSWindow(LocalStateAdditions) category to assist with storing window
position in Chromium's local state.
BUG=21761,21762,21883,21996
TEST=Editing/adding a search engine happens in a sheet. Press [Manage] multiple times and only 1 window should open. Press [Manage] and the window should be at its last position.
Review URL: http://codereview.chromium.org/207027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26646 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/nswindow_local_state_unittest.mm')
-rw-r--r-- | chrome/browser/cocoa/nswindow_local_state_unittest.mm | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/nswindow_local_state_unittest.mm b/chrome/browser/cocoa/nswindow_local_state_unittest.mm new file mode 100644 index 0000000..6d4fab1 --- /dev/null +++ b/chrome/browser/cocoa/nswindow_local_state_unittest.mm @@ -0,0 +1,66 @@ +// 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> + +#include "base/scoped_nsobject.h" +#include "chrome/browser/cocoa/browser_test_helper.h" +#import "chrome/browser/cocoa/cocoa_test_helper.h" +#import "chrome/browser/cocoa/nswindow_local_state.h" +#include "chrome/common/pref_service.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/platform_test.h" + +class NSWindowLocalStateTest : public PlatformTest { + virtual void SetUp() { + path_ = L"NSWindowLocalStateTest"; + window_.reset( + [[NSWindow alloc] initWithContentRect:NSMakeRect(100, 100, 20, 20) + styleMask:NSTitledWindowMask + backing:NSBackingStoreBuffered + defer:NO]); + browser_helper_.profile()->GetPrefs()->RegisterDictionaryPref(path_); + } + + public: + CocoaTestHelper cocoa_helper_; + BrowserTestHelper browser_helper_; + scoped_nsobject<NSWindow> window_; + const wchar_t* path_; +}; + +TEST_F(NSWindowLocalStateTest, SaveWindowPlacement) { + PrefService* prefs = browser_helper_.profile()->GetPrefs(); + ASSERT_TRUE(prefs != NULL); + + // Check to make sure there is no existing pref for window placement. + ASSERT_TRUE(prefs->GetDictionary(path_) == NULL); + + // Ask the window to save its position, then check that a preference + // exists. We're technically passing in a pointer to the user prefs + // and not the local state prefs, but a PrefService* is a + // PrefService*, and this is a unittest. + [window_ saveWindowPositionToPrefs:prefs withPath:path_]; + EXPECT_TRUE(prefs->GetDictionary(path_) != NULL); + int x, y; + DictionaryValue* windowPrefs = prefs->GetMutableDictionary(path_); + windowPrefs->GetInteger(L"x", &x); + windowPrefs->GetInteger(L"y", &y); + EXPECT_EQ(x, [window_ frame].origin.x); + EXPECT_EQ(y, [window_ frame].origin.y); +} + +TEST_F(NSWindowLocalStateTest, RestoreWindowPlacement) { + PrefService* prefs = browser_helper_.profile()->GetPrefs(); + DictionaryValue* windowPrefs = prefs->GetMutableDictionary(path_); + + // Large enough so that the window is on screen without cascasding to a + // totally new location. + const int value = 420; + windowPrefs->SetInteger(L"x", value); + windowPrefs->SetInteger(L"y", value); + [window_ restoreWindowPositionFromPrefs:prefs withPath:path_]; + EXPECT_LT(value, [window_ frame].origin.x); + EXPECT_GT(value, [window_ frame].origin.y); +} |