OLD | NEW |
1 // Copyright (c) 2011 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #import "chrome/browser/ui/cocoa/window_size_autosaver.h" | 7 #import "chrome/browser/ui/cocoa/window_size_autosaver.h" |
8 | 8 |
9 #include "base/memory/scoped_nsobject.h" | 9 #include "base/memory/scoped_nsobject.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
| 11 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
11 #include "chrome/browser/ui/cocoa/browser_test_helper.h" | 12 #include "chrome/browser/ui/cocoa/browser_test_helper.h" |
12 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 13 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 class WindowSizeAutosaverTest : public CocoaTest { | 19 class WindowSizeAutosaverTest : public CocoaTest { |
19 virtual void SetUp() { | 20 virtual void SetUp() { |
20 CocoaTest::SetUp(); | 21 CocoaTest::SetUp(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 path:path_]); | 89 path:path_]); |
89 EXPECT_EQ(300, NSMinX([window_ frame])); | 90 EXPECT_EQ(300, NSMinX([window_ frame])); |
90 EXPECT_EQ(310, NSMinY([window_ frame])); | 91 EXPECT_EQ(310, NSMinY([window_ frame])); |
91 EXPECT_EQ(160, NSWidth([window_ frame])); | 92 EXPECT_EQ(160, NSWidth([window_ frame])); |
92 EXPECT_EQ(162, NSHeight([window_ frame])); | 93 EXPECT_EQ(162, NSHeight([window_ frame])); |
93 } | 94 } |
94 | 95 |
95 // ...and it should be in the profile, too. | 96 // ...and it should be in the profile, too. |
96 EXPECT_TRUE(pref->GetDictionary(path_) != NULL); | 97 EXPECT_TRUE(pref->GetDictionary(path_) != NULL); |
97 int x, y; | 98 int x, y; |
98 DictionaryValue* windowPref = pref->GetMutableDictionary(path_); | 99 const DictionaryValue* windowPref = pref->GetDictionary(path_); |
99 EXPECT_FALSE(windowPref->GetInteger("left", &x)); | 100 EXPECT_FALSE(windowPref->GetInteger("left", &x)); |
100 EXPECT_FALSE(windowPref->GetInteger("right", &x)); | 101 EXPECT_FALSE(windowPref->GetInteger("right", &x)); |
101 EXPECT_FALSE(windowPref->GetInteger("top", &x)); | 102 EXPECT_FALSE(windowPref->GetInteger("top", &x)); |
102 EXPECT_FALSE(windowPref->GetInteger("bottom", &x)); | 103 EXPECT_FALSE(windowPref->GetInteger("bottom", &x)); |
103 ASSERT_TRUE(windowPref->GetInteger("x", &x)); | 104 ASSERT_TRUE(windowPref->GetInteger("x", &x)); |
104 ASSERT_TRUE(windowPref->GetInteger("y", &y)); | 105 ASSERT_TRUE(windowPref->GetInteger("y", &y)); |
105 EXPECT_EQ(300, x); | 106 EXPECT_EQ(300, x); |
106 EXPECT_EQ(310, y); | 107 EXPECT_EQ(310, y); |
107 } | 108 } |
108 | 109 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 path:path_]); | 148 path:path_]); |
148 EXPECT_EQ(300, NSMinX([window_ frame])); | 149 EXPECT_EQ(300, NSMinX([window_ frame])); |
149 EXPECT_EQ(310, NSMinY([window_ frame])); | 150 EXPECT_EQ(310, NSMinY([window_ frame])); |
150 EXPECT_EQ(250, NSWidth([window_ frame])); | 151 EXPECT_EQ(250, NSWidth([window_ frame])); |
151 EXPECT_EQ(252, NSHeight([window_ frame])); | 152 EXPECT_EQ(252, NSHeight([window_ frame])); |
152 } | 153 } |
153 | 154 |
154 // ...and it should be in the profile, too. | 155 // ...and it should be in the profile, too. |
155 EXPECT_TRUE(pref->GetDictionary(path_) != NULL); | 156 EXPECT_TRUE(pref->GetDictionary(path_) != NULL); |
156 int x1, y1, x2, y2; | 157 int x1, y1, x2, y2; |
157 DictionaryValue* windowPref = pref->GetMutableDictionary(path_); | 158 const DictionaryValue* windowPref = pref->GetDictionary(path_); |
158 EXPECT_FALSE(windowPref->GetInteger("x", &x1)); | 159 EXPECT_FALSE(windowPref->GetInteger("x", &x1)); |
159 EXPECT_FALSE(windowPref->GetInteger("y", &x1)); | 160 EXPECT_FALSE(windowPref->GetInteger("y", &x1)); |
160 ASSERT_TRUE(windowPref->GetInteger("left", &x1)); | 161 ASSERT_TRUE(windowPref->GetInteger("left", &x1)); |
161 ASSERT_TRUE(windowPref->GetInteger("right", &x2)); | 162 ASSERT_TRUE(windowPref->GetInteger("right", &x2)); |
162 ASSERT_TRUE(windowPref->GetInteger("top", &y1)); | 163 ASSERT_TRUE(windowPref->GetInteger("top", &y1)); |
163 ASSERT_TRUE(windowPref->GetInteger("bottom", &y2)); | 164 ASSERT_TRUE(windowPref->GetInteger("bottom", &y2)); |
164 EXPECT_EQ(300, x1); | 165 EXPECT_EQ(300, x1); |
165 EXPECT_EQ(310, y1); | 166 EXPECT_EQ(310, y1); |
166 EXPECT_EQ(300 + 250, x2); | 167 EXPECT_EQ(300 + 250, x2); |
167 EXPECT_EQ(310 + 252, y2); | 168 EXPECT_EQ(310 + 252, y2); |
168 } | 169 } |
169 | 170 |
170 // http://crbug.com/39625 | 171 // http://crbug.com/39625 |
171 TEST_F(WindowSizeAutosaverTest, DoesNotRestoreButClearsEmptyRect) { | 172 TEST_F(WindowSizeAutosaverTest, DoesNotRestoreButClearsEmptyRect) { |
172 PrefService* pref = browser_helper_.profile()->GetPrefs(); | 173 PrefService* pref = browser_helper_.profile()->GetPrefs(); |
173 ASSERT_TRUE(pref != NULL); | 174 ASSERT_TRUE(pref != NULL); |
174 | 175 |
175 DictionaryValue* windowPref = pref->GetMutableDictionary(path_); | 176 DictionaryPrefUpdate update(pref, path_); |
| 177 DictionaryValue* windowPref = update.Get(); |
176 windowPref->SetInteger("left", 50); | 178 windowPref->SetInteger("left", 50); |
177 windowPref->SetInteger("right", 50); | 179 windowPref->SetInteger("right", 50); |
178 windowPref->SetInteger("top", 60); | 180 windowPref->SetInteger("top", 60); |
179 windowPref->SetInteger("bottom", 60); | 181 windowPref->SetInteger("bottom", 60); |
180 | 182 |
181 { | 183 { |
182 // Window rect shouldn't change... | 184 // Window rect shouldn't change... |
183 NSRect frame = [window_ frame]; | 185 NSRect frame = [window_ frame]; |
184 scoped_nsobject<WindowSizeAutosaver> sizeSaver([[WindowSizeAutosaver alloc] | 186 scoped_nsobject<WindowSizeAutosaver> sizeSaver([[WindowSizeAutosaver alloc] |
185 initWithWindow:window_ | 187 initWithWindow:window_ |
(...skipping 10 matching lines...) Expand all Loading... |
196 int x1, y1, x2, y2; | 198 int x1, y1, x2, y2; |
197 EXPECT_FALSE(windowPref->GetInteger("x", &x1)); | 199 EXPECT_FALSE(windowPref->GetInteger("x", &x1)); |
198 EXPECT_FALSE(windowPref->GetInteger("y", &x1)); | 200 EXPECT_FALSE(windowPref->GetInteger("y", &x1)); |
199 ASSERT_FALSE(windowPref->GetInteger("left", &x1)); | 201 ASSERT_FALSE(windowPref->GetInteger("left", &x1)); |
200 ASSERT_FALSE(windowPref->GetInteger("right", &x2)); | 202 ASSERT_FALSE(windowPref->GetInteger("right", &x2)); |
201 ASSERT_FALSE(windowPref->GetInteger("top", &y1)); | 203 ASSERT_FALSE(windowPref->GetInteger("top", &y1)); |
202 ASSERT_FALSE(windowPref->GetInteger("bottom", &y2)); | 204 ASSERT_FALSE(windowPref->GetInteger("bottom", &y2)); |
203 } | 205 } |
204 | 206 |
205 } // namespace | 207 } // namespace |
OLD | NEW |