Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1635)

Side by Side Diff: chrome/browser/cocoa/nswindow_local_state_unittest.mm

Issue 207027: [Mac] Polish the search engine manager (Closed)
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import <Cocoa/Cocoa.h>
6
7 #include "base/scoped_nsobject.h"
8 #include "chrome/browser/cocoa/browser_test_helper.h"
9 #import "chrome/browser/cocoa/cocoa_test_helper.h"
10 #import "chrome/browser/cocoa/nswindow_local_state.h"
11 #include "chrome/common/pref_service.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/platform_test.h"
14
15 class NSWindowLocalStateTest : public PlatformTest {
16 virtual void SetUp() {
17 path_ = L"NSWindowLocalStateTest";
18 window_.reset(
19 [[NSWindow alloc] initWithContentRect:NSMakeRect(100, 100, 20, 20)
20 styleMask:NSTitledWindowMask
21 backing:NSBackingStoreBuffered
22 defer:NO]);
23 browser_helper_.profile()->GetPrefs()->RegisterDictionaryPref(path_);
24 }
25
26 public:
27 CocoaTestHelper cocoa_helper_;
28 BrowserTestHelper browser_helper_;
29 scoped_nsobject<NSWindow> window_;
30 const wchar_t* path_;
31 };
32
33 TEST_F(NSWindowLocalStateTest, TestSaveWindowPlacement) {
34 PrefService* prefs = browser_helper_.profile()->GetPrefs();
35 ASSERT_TRUE(prefs != NULL);
36
37 // Check to make sure there is no existing pref for window placement.
38 ASSERT_TRUE(prefs->GetDictionary(path_) == NULL);
39
40 // Ask the window to save its position, then check that a preference
41 // exists. We're technically passing in a pointer to the user prefs
42 // and not the local state prefs, but a PrefService* is a
43 // PrefService*, and this is a unittest.
44 [window_ saveWindowPositionToPrefs:prefs withPath:path_];
45 EXPECT_TRUE(prefs->GetDictionary(path_) != NULL);
46 int x, y;
47 DictionaryValue* windowPrefs = prefs->GetMutableDictionary(path_);
48 windowPrefs->GetInteger(L"x", &x);
49 windowPrefs->GetInteger(L"y", &y);
50 EXPECT_EQ(x, [window_ frame].origin.x);
51 EXPECT_EQ(y, [window_ frame].origin.y);
52 }
53
54 TEST_F(NSWindowLocalStateTest, TestRestoreWindowPlacement) {
55 PrefService* prefs = browser_helper_.profile()->GetPrefs();
56 DictionaryValue* windowPrefs = prefs->GetMutableDictionary(path_);
57
58 const int value = 42;
59 windowPrefs->SetInteger(L"x", value);
60 windowPrefs->SetInteger(L"y", value);
61 [window_ restoreWindowPositionFromPrefs:prefs withPath:path_];
62 EXPECT_LT(value, [window_ frame].origin.x);
63 EXPECT_GT(value, [window_ frame].origin.y);
64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698