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/mac/scoped_nsobject.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 11 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
13 #include "components/user_prefs/pref_registry_syncable.h" | 13 #include "components/user_prefs/pref_registry_syncable.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 class WindowSizeAutosaverTest : public CocoaProfileTest { | 19 class WindowSizeAutosaverTest : public CocoaProfileTest { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 defer:NO]; | 62 defer:NO]; |
63 | 63 |
64 // Ask the window to save its position, then check that a preference | 64 // Ask the window to save its position, then check that a preference |
65 // exists. We're technically passing in a pointer to the user prefs | 65 // exists. We're technically passing in a pointer to the user prefs |
66 // and not the local state prefs, but a PrefService* is a | 66 // and not the local state prefs, but a PrefService* is a |
67 // PrefService*, and this is a unittest. | 67 // PrefService*, and this is a unittest. |
68 | 68 |
69 { | 69 { |
70 NSRect frame = [window_ frame]; | 70 NSRect frame = [window_ frame]; |
71 // Empty state, shouldn't restore: | 71 // Empty state, shouldn't restore: |
72 scoped_nsobject<WindowSizeAutosaver> sizeSaver([[WindowSizeAutosaver alloc] | 72 base::scoped_nsobject<WindowSizeAutosaver> sizeSaver( |
73 initWithWindow:window_ | 73 [[WindowSizeAutosaver alloc] initWithWindow:window_ |
74 prefService:pref | 74 prefService:pref |
75 path:path_]); | 75 path:path_]); |
76 EXPECT_EQ(NSMinX(frame), NSMinX([window_ frame])); | 76 EXPECT_EQ(NSMinX(frame), NSMinX([window_ frame])); |
77 EXPECT_EQ(NSMinY(frame), NSMinY([window_ frame])); | 77 EXPECT_EQ(NSMinY(frame), NSMinY([window_ frame])); |
78 EXPECT_EQ(NSWidth(frame), NSWidth([window_ frame])); | 78 EXPECT_EQ(NSWidth(frame), NSWidth([window_ frame])); |
79 EXPECT_EQ(NSHeight(frame), NSHeight([window_ frame])); | 79 EXPECT_EQ(NSHeight(frame), NSHeight([window_ frame])); |
80 | 80 |
81 // Move and resize window, should store position but not size. | 81 // Move and resize window, should store position but not size. |
82 [window_ setFrame:NSMakeRect(300, 310, 250, 252) display:NO]; | 82 [window_ setFrame:NSMakeRect(300, 310, 250, 252) display:NO]; |
83 } | 83 } |
84 | 84 |
85 // Another window movement -- shouldn't be recorded. | 85 // Another window movement -- shouldn't be recorded. |
86 [window_ setFrame:NSMakeRect(400, 420, 160, 162) display:NO]; | 86 [window_ setFrame:NSMakeRect(400, 420, 160, 162) display:NO]; |
87 | 87 |
88 { | 88 { |
89 // Should restore last stored position, but not size. | 89 // Should restore last stored position, but not size. |
90 scoped_nsobject<WindowSizeAutosaver> sizeSaver([[WindowSizeAutosaver alloc] | 90 base::scoped_nsobject<WindowSizeAutosaver> sizeSaver( |
91 initWithWindow:window_ | 91 [[WindowSizeAutosaver alloc] initWithWindow:window_ |
92 prefService:pref | 92 prefService:pref |
93 path:path_]); | 93 path:path_]); |
94 EXPECT_EQ(300, NSMinX([window_ frame])); | 94 EXPECT_EQ(300, NSMinX([window_ frame])); |
95 EXPECT_EQ(310, NSMinY([window_ frame])); | 95 EXPECT_EQ(310, NSMinY([window_ frame])); |
96 EXPECT_EQ(160, NSWidth([window_ frame])); | 96 EXPECT_EQ(160, NSWidth([window_ frame])); |
97 EXPECT_EQ(162, NSHeight([window_ frame])); | 97 EXPECT_EQ(162, NSHeight([window_ frame])); |
98 } | 98 } |
99 | 99 |
100 // ...and it should be in the profile, too. | 100 // ...and it should be in the profile, too. |
101 EXPECT_TRUE(pref->GetDictionary(path_) != NULL); | 101 EXPECT_TRUE(pref->GetDictionary(path_) != NULL); |
102 int x, y; | 102 int x, y; |
103 const DictionaryValue* windowPref = pref->GetDictionary(path_); | 103 const DictionaryValue* windowPref = pref->GetDictionary(path_); |
(...skipping 17 matching lines...) Expand all Loading... |
121 EXPECT_TRUE(placement->empty()); | 121 EXPECT_TRUE(placement->empty()); |
122 | 122 |
123 // Ask the window to save its position, then check that a preference | 123 // Ask the window to save its position, then check that a preference |
124 // exists. We're technically passing in a pointer to the user prefs | 124 // exists. We're technically passing in a pointer to the user prefs |
125 // and not the local state prefs, but a PrefService* is a | 125 // and not the local state prefs, but a PrefService* is a |
126 // PrefService*, and this is a unittest. | 126 // PrefService*, and this is a unittest. |
127 | 127 |
128 { | 128 { |
129 NSRect frame = [window_ frame]; | 129 NSRect frame = [window_ frame]; |
130 // Empty state, shouldn't restore: | 130 // Empty state, shouldn't restore: |
131 scoped_nsobject<WindowSizeAutosaver> sizeSaver([[WindowSizeAutosaver alloc] | 131 base::scoped_nsobject<WindowSizeAutosaver> sizeSaver( |
132 initWithWindow:window_ | 132 [[WindowSizeAutosaver alloc] initWithWindow:window_ |
133 prefService:pref | 133 prefService:pref |
134 path:path_]); | 134 path:path_]); |
135 EXPECT_EQ(NSMinX(frame), NSMinX([window_ frame])); | 135 EXPECT_EQ(NSMinX(frame), NSMinX([window_ frame])); |
136 EXPECT_EQ(NSMinY(frame), NSMinY([window_ frame])); | 136 EXPECT_EQ(NSMinY(frame), NSMinY([window_ frame])); |
137 EXPECT_EQ(NSWidth(frame), NSWidth([window_ frame])); | 137 EXPECT_EQ(NSWidth(frame), NSWidth([window_ frame])); |
138 EXPECT_EQ(NSHeight(frame), NSHeight([window_ frame])); | 138 EXPECT_EQ(NSHeight(frame), NSHeight([window_ frame])); |
139 | 139 |
140 // Move and resize window, should store | 140 // Move and resize window, should store |
141 [window_ setFrame:NSMakeRect(300, 310, 250, 252) display:NO]; | 141 [window_ setFrame:NSMakeRect(300, 310, 250, 252) display:NO]; |
142 } | 142 } |
143 | 143 |
144 // Another window movement -- shouldn't be recorded. | 144 // Another window movement -- shouldn't be recorded. |
145 [window_ setFrame:NSMakeRect(400, 420, 160, 162) display:NO]; | 145 [window_ setFrame:NSMakeRect(400, 420, 160, 162) display:NO]; |
146 | 146 |
147 { | 147 { |
148 // Should restore last stored size | 148 // Should restore last stored size |
149 scoped_nsobject<WindowSizeAutosaver> sizeSaver([[WindowSizeAutosaver alloc] | 149 base::scoped_nsobject<WindowSizeAutosaver> sizeSaver( |
150 initWithWindow:window_ | 150 [[WindowSizeAutosaver alloc] initWithWindow:window_ |
151 prefService:pref | 151 prefService:pref |
152 path:path_]); | 152 path:path_]); |
153 EXPECT_EQ(300, NSMinX([window_ frame])); | 153 EXPECT_EQ(300, NSMinX([window_ frame])); |
154 EXPECT_EQ(310, NSMinY([window_ frame])); | 154 EXPECT_EQ(310, NSMinY([window_ frame])); |
155 EXPECT_EQ(250, NSWidth([window_ frame])); | 155 EXPECT_EQ(250, NSWidth([window_ frame])); |
156 EXPECT_EQ(252, NSHeight([window_ frame])); | 156 EXPECT_EQ(252, NSHeight([window_ frame])); |
157 } | 157 } |
158 | 158 |
159 // ...and it should be in the profile, too. | 159 // ...and it should be in the profile, too. |
160 EXPECT_TRUE(pref->GetDictionary(path_) != NULL); | 160 EXPECT_TRUE(pref->GetDictionary(path_) != NULL); |
161 int x1, y1, x2, y2; | 161 int x1, y1, x2, y2; |
162 const DictionaryValue* windowPref = pref->GetDictionary(path_); | 162 const DictionaryValue* windowPref = pref->GetDictionary(path_); |
(...skipping 17 matching lines...) Expand all Loading... |
180 DictionaryPrefUpdate update(pref, path_); | 180 DictionaryPrefUpdate update(pref, path_); |
181 DictionaryValue* windowPref = update.Get(); | 181 DictionaryValue* windowPref = update.Get(); |
182 windowPref->SetInteger("left", 50); | 182 windowPref->SetInteger("left", 50); |
183 windowPref->SetInteger("right", 50); | 183 windowPref->SetInteger("right", 50); |
184 windowPref->SetInteger("top", 60); | 184 windowPref->SetInteger("top", 60); |
185 windowPref->SetInteger("bottom", 60); | 185 windowPref->SetInteger("bottom", 60); |
186 | 186 |
187 { | 187 { |
188 // Window rect shouldn't change... | 188 // Window rect shouldn't change... |
189 NSRect frame = [window_ frame]; | 189 NSRect frame = [window_ frame]; |
190 scoped_nsobject<WindowSizeAutosaver> sizeSaver([[WindowSizeAutosaver alloc] | 190 base::scoped_nsobject<WindowSizeAutosaver> sizeSaver( |
191 initWithWindow:window_ | 191 [[WindowSizeAutosaver alloc] initWithWindow:window_ |
192 prefService:pref | 192 prefService:pref |
193 path:path_]); | 193 path:path_]); |
194 EXPECT_EQ(NSMinX(frame), NSMinX([window_ frame])); | 194 EXPECT_EQ(NSMinX(frame), NSMinX([window_ frame])); |
195 EXPECT_EQ(NSMinY(frame), NSMinY([window_ frame])); | 195 EXPECT_EQ(NSMinY(frame), NSMinY([window_ frame])); |
196 EXPECT_EQ(NSWidth(frame), NSWidth([window_ frame])); | 196 EXPECT_EQ(NSWidth(frame), NSWidth([window_ frame])); |
197 EXPECT_EQ(NSHeight(frame), NSHeight([window_ frame])); | 197 EXPECT_EQ(NSHeight(frame), NSHeight([window_ frame])); |
198 } | 198 } |
199 | 199 |
200 // ...and it should be gone from the profile, too. | 200 // ...and it should be gone from the profile, too. |
201 EXPECT_TRUE(pref->GetDictionary(path_) != NULL); | 201 EXPECT_TRUE(pref->GetDictionary(path_) != NULL); |
202 int x1, y1, x2, y2; | 202 int x1, y1, x2, y2; |
203 EXPECT_FALSE(windowPref->GetInteger("x", &x1)); | 203 EXPECT_FALSE(windowPref->GetInteger("x", &x1)); |
204 EXPECT_FALSE(windowPref->GetInteger("y", &x1)); | 204 EXPECT_FALSE(windowPref->GetInteger("y", &x1)); |
205 ASSERT_FALSE(windowPref->GetInteger("left", &x1)); | 205 ASSERT_FALSE(windowPref->GetInteger("left", &x1)); |
206 ASSERT_FALSE(windowPref->GetInteger("right", &x2)); | 206 ASSERT_FALSE(windowPref->GetInteger("right", &x2)); |
207 ASSERT_FALSE(windowPref->GetInteger("top", &y1)); | 207 ASSERT_FALSE(windowPref->GetInteger("top", &y1)); |
208 ASSERT_FALSE(windowPref->GetInteger("bottom", &y2)); | 208 ASSERT_FALSE(windowPref->GetInteger("bottom", &y2)); |
209 } | 209 } |
210 | 210 |
211 } // namespace | 211 } // namespace |
OLD | NEW |