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 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 int abort_count() { return abort_count_; } | 97 int abort_count() { return abort_count_; } |
98 | 98 |
99 protected: | 99 protected: |
100 int proceed_count_; | 100 int proceed_count_; |
101 int abort_count_; | 101 int abort_count_; |
102 }; | 102 }; |
103 | 103 |
104 // Test that we can load the two kinds of prompts correctly, that the outlets | 104 // Test that we can load the two kinds of prompts correctly, that the outlets |
105 // are hooked up, and that the dialog calls cancel when cancel is pressed. | 105 // are hooked up, and that the dialog calls cancel when cancel is pressed. |
106 TEST_F(ExtensionInstallDialogControllerTest, BasicsNormalCancel) { | 106 TEST_F(ExtensionInstallDialogControllerTest, BasicsNormalCancel) { |
107 scoped_ptr<MockExtensionInstallUIDelegate> delegate( | 107 MockExtensionInstallUIDelegate delegate; |
108 new MockExtensionInstallUIDelegate); | |
109 | 108 |
110 ExtensionInstallUI::Prompt prompt(ExtensionInstallUI::INSTALL_PROMPT); | 109 ExtensionInstallUI::Prompt prompt(ExtensionInstallUI::INSTALL_PROMPT); |
111 std::vector<string16> permissions; | 110 std::vector<string16> permissions; |
112 permissions.push_back(UTF8ToUTF16("warning 1")); | 111 permissions.push_back(UTF8ToUTF16("warning 1")); |
113 prompt.SetPermissions(permissions); | 112 prompt.SetPermissions(permissions); |
114 | 113 |
115 scoped_nsobject<ExtensionInstallDialogController> | 114 scoped_nsobject<ExtensionInstallDialogController> |
116 controller([[ExtensionInstallDialogController alloc] | 115 controller([[ExtensionInstallDialogController alloc] |
117 initWithParentWindow:test_window() | 116 initWithParentWindow:test_window() |
118 profile:helper_.profile() | 117 profile:helper_.profile() |
119 extension:extension_.get() | 118 extension:extension_.get() |
120 delegate:delegate.get() | 119 delegate:&delegate |
121 icon:&icon_ | 120 icon:&icon_ |
122 prompt:prompt]); | 121 prompt:prompt]); |
123 | 122 |
124 [controller window]; // force nib load | 123 [controller window]; // force nib load |
125 | 124 |
126 // Test the right nib loaded. | 125 // Test the right nib loaded. |
127 EXPECT_NSEQ(@"ExtensionInstallPrompt", [controller windowNibName]); | 126 EXPECT_NSEQ(@"ExtensionInstallPrompt", [controller windowNibName]); |
128 | 127 |
129 // Check all the controls. | 128 // Check all the controls. |
130 // Make sure everything is non-nil, and that the fields that are | 129 // Make sure everything is non-nil, and that the fields that are |
131 // auto-translated don't start with a caret (that would indicate that they | 130 // auto-translated don't start with a caret (that would indicate that they |
132 // were not translated). | 131 // were not translated). |
133 EXPECT_TRUE([controller iconView] != nil); | 132 EXPECT_TRUE([controller iconView] != nil); |
134 EXPECT_TRUE([[controller iconView] image] != nil); | 133 EXPECT_TRUE([[controller iconView] image] != nil); |
135 | 134 |
136 EXPECT_TRUE([controller titleField] != nil); | 135 EXPECT_TRUE([controller titleField] != nil); |
137 EXPECT_NE(0u, [[[controller titleField] stringValue] length]); | 136 EXPECT_NE(0u, [[[controller titleField] stringValue] length]); |
138 | 137 |
139 EXPECT_TRUE([controller subtitleField] != nil); | 138 EXPECT_TRUE([controller subtitleField] != nil); |
140 EXPECT_NE(0u, [[[controller subtitleField] stringValue] length]); | 139 EXPECT_NE(0u, [[[controller subtitleField] stringValue] length]); |
141 EXPECT_NE('^', [[[controller subtitleField] stringValue] characterAtIndex:0]); | 140 EXPECT_NE('^', [[[controller subtitleField] stringValue] characterAtIndex:0]); |
142 | 141 |
143 EXPECT_TRUE([controller warningsField] != nil); | 142 EXPECT_TRUE([controller warningsField] != nil); |
144 EXPECT_NSEQ([[controller warningsField] stringValue], | 143 EXPECT_NSEQ([[controller warningsField] stringValue], |
145 base::SysUTF16ToNSString(prompt.GetPermission(0))); | 144 base::SysUTF16ToNSString(prompt.GetPermission(0))); |
146 | 145 |
147 EXPECT_TRUE([controller warningsBox] != nil); | |
148 | |
149 EXPECT_TRUE([controller cancelButton] != nil); | 146 EXPECT_TRUE([controller cancelButton] != nil); |
150 EXPECT_NE(0u, [[[controller cancelButton] stringValue] length]); | 147 EXPECT_NE(0u, [[[controller cancelButton] stringValue] length]); |
151 EXPECT_NE('^', [[[controller cancelButton] stringValue] characterAtIndex:0]); | 148 EXPECT_NE('^', [[[controller cancelButton] stringValue] characterAtIndex:0]); |
152 | 149 |
153 EXPECT_TRUE([controller okButton] != nil); | 150 EXPECT_TRUE([controller okButton] != nil); |
154 EXPECT_NE(0u, [[[controller okButton] stringValue] length]); | 151 EXPECT_NE(0u, [[[controller okButton] stringValue] length]); |
155 EXPECT_NE('^', [[[controller okButton] stringValue] characterAtIndex:0]); | 152 EXPECT_NE('^', [[[controller okButton] stringValue] characterAtIndex:0]); |
156 | 153 |
157 // Test that cancel calls our delegate. | 154 // Test that cancel calls our delegate. |
158 [controller cancel:nil]; | 155 [controller cancel:nil]; |
159 EXPECT_EQ(1, delegate->abort_count()); | 156 EXPECT_EQ(1, delegate.abort_count()); |
160 EXPECT_EQ(0, delegate->proceed_count()); | 157 EXPECT_EQ(0, delegate.proceed_count()); |
161 } | 158 } |
162 | 159 |
163 | 160 |
164 TEST_F(ExtensionInstallDialogControllerTest, BasicsNormalOK) { | 161 TEST_F(ExtensionInstallDialogControllerTest, BasicsNormalOK) { |
165 scoped_ptr<MockExtensionInstallUIDelegate> delegate( | 162 MockExtensionInstallUIDelegate delegate; |
166 new MockExtensionInstallUIDelegate); | |
167 | 163 |
168 ExtensionInstallUI::Prompt prompt(ExtensionInstallUI::INSTALL_PROMPT); | 164 ExtensionInstallUI::Prompt prompt(ExtensionInstallUI::INSTALL_PROMPT); |
169 std::vector<string16> permissions; | 165 std::vector<string16> permissions; |
170 permissions.push_back(UTF8ToUTF16("warning 1")); | 166 permissions.push_back(UTF8ToUTF16("warning 1")); |
171 prompt.SetPermissions(permissions); | 167 prompt.SetPermissions(permissions); |
172 | 168 |
173 scoped_nsobject<ExtensionInstallDialogController> | 169 scoped_nsobject<ExtensionInstallDialogController> |
174 controller([[ExtensionInstallDialogController alloc] | 170 controller([[ExtensionInstallDialogController alloc] |
175 initWithParentWindow:test_window() | 171 initWithParentWindow:test_window() |
176 profile:helper_.profile() | 172 profile:helper_.profile() |
177 extension:extension_.get() | 173 extension:extension_.get() |
178 delegate:delegate.get() | 174 delegate:&delegate |
179 icon:&icon_ | 175 icon:&icon_ |
180 prompt:prompt]); | 176 prompt:prompt]); |
181 | 177 |
182 [controller window]; // force nib load | 178 [controller window]; // force nib load |
183 [controller ok:nil]; | 179 [controller ok:nil]; |
184 | 180 |
185 EXPECT_EQ(0, delegate->abort_count()); | 181 EXPECT_EQ(0, delegate.abort_count()); |
186 EXPECT_EQ(1, delegate->proceed_count()); | 182 EXPECT_EQ(1, delegate.proceed_count()); |
187 } | 183 } |
188 | 184 |
189 // Test that controls get repositioned when there are two warnings vs one | 185 // Test that controls get repositioned when there are two warnings vs one |
190 // warning. | 186 // warning. |
191 TEST_F(ExtensionInstallDialogControllerTest, MultipleWarnings) { | 187 TEST_F(ExtensionInstallDialogControllerTest, MultipleWarnings) { |
192 scoped_ptr<MockExtensionInstallUIDelegate> delegate1( | 188 MockExtensionInstallUIDelegate delegate1; |
193 new MockExtensionInstallUIDelegate); | 189 MockExtensionInstallUIDelegate delegate2; |
194 scoped_ptr<MockExtensionInstallUIDelegate> delegate2( | |
195 new MockExtensionInstallUIDelegate); | |
196 | 190 |
197 ExtensionInstallUI::Prompt one_warning_prompt( | 191 ExtensionInstallUI::Prompt one_warning_prompt( |
198 ExtensionInstallUI::INSTALL_PROMPT); | 192 ExtensionInstallUI::INSTALL_PROMPT); |
199 std::vector<string16> permissions; | 193 std::vector<string16> permissions; |
200 permissions.push_back(UTF8ToUTF16("warning 1")); | 194 permissions.push_back(UTF8ToUTF16("warning 1")); |
201 one_warning_prompt.SetPermissions(permissions); | 195 one_warning_prompt.SetPermissions(permissions); |
202 | 196 |
203 ExtensionInstallUI::Prompt two_warnings_prompt( | 197 ExtensionInstallUI::Prompt two_warnings_prompt( |
204 ExtensionInstallUI::INSTALL_PROMPT); | 198 ExtensionInstallUI::INSTALL_PROMPT); |
205 permissions.push_back(UTF8ToUTF16("warning 2")); | 199 permissions.push_back(UTF8ToUTF16("warning 2")); |
206 two_warnings_prompt.SetPermissions(permissions); | 200 two_warnings_prompt.SetPermissions(permissions); |
207 | 201 |
208 scoped_nsobject<ExtensionInstallDialogController> | 202 scoped_nsobject<ExtensionInstallDialogController> |
209 controller1([[ExtensionInstallDialogController alloc] | 203 controller1([[ExtensionInstallDialogController alloc] |
210 initWithParentWindow:test_window() | 204 initWithParentWindow:test_window() |
211 profile:helper_.profile() | 205 profile:helper_.profile() |
212 extension:extension_.get() | 206 extension:extension_.get() |
213 delegate:delegate1.get() | 207 delegate:&delegate1 |
214 icon:&icon_ | 208 icon:&icon_ |
215 prompt:one_warning_prompt]); | 209 prompt:one_warning_prompt]); |
216 | 210 |
217 [controller1 window]; // force nib load | 211 [controller1 window]; // force nib load |
218 | 212 |
219 scoped_nsobject<ExtensionInstallDialogController> | 213 scoped_nsobject<ExtensionInstallDialogController> |
220 controller2([[ExtensionInstallDialogController alloc] | 214 controller2([[ExtensionInstallDialogController alloc] |
221 initWithParentWindow:test_window() | 215 initWithParentWindow:test_window() |
222 profile:helper_.profile() | 216 profile:helper_.profile() |
223 extension:extension_.get() | 217 extension:extension_.get() |
224 delegate:delegate2.get() | 218 delegate:&delegate2 |
225 icon:&icon_ | 219 icon:&icon_ |
226 prompt:two_warnings_prompt]); | 220 prompt:two_warnings_prompt]); |
227 | 221 |
228 [controller2 window]; // force nib load | 222 [controller2 window]; // force nib load |
229 | 223 |
230 // Test control positioning. We don't test exact positioning because we don't | 224 // Test control positioning. We don't test exact positioning because we don't |
231 // want this to depend on string details and localization. But we do know the | 225 // want this to depend on string details and localization. But we do know the |
232 // relative effect that adding a second warning should have on the layout. | 226 // relative effect that adding a second warning should have on the layout. |
233 ASSERT_LT([[controller1 window] frame].size.height, | 227 ASSERT_LT([[controller1 window] frame].size.height, |
234 [[controller2 window] frame].size.height); | 228 [[controller2 window] frame].size.height); |
235 | 229 |
236 ASSERT_LT([[controller1 warningsField] frame].size.height, | 230 ASSERT_LT([[controller1 warningsField] frame].size.height, |
237 [[controller2 warningsField] frame].size.height); | 231 [[controller2 warningsField] frame].size.height); |
238 | 232 |
239 ASSERT_LT([[controller1 warningsBox] frame].size.height, | |
240 [[controller2 warningsBox] frame].size.height); | |
241 | |
242 ASSERT_EQ([[controller1 warningsBox] frame].origin.y, | |
243 [[controller2 warningsBox] frame].origin.y); | |
244 | |
245 ASSERT_LT([[controller1 subtitleField] frame].origin.y, | 233 ASSERT_LT([[controller1 subtitleField] frame].origin.y, |
246 [[controller2 subtitleField] frame].origin.y); | 234 [[controller2 subtitleField] frame].origin.y); |
247 | 235 |
248 ASSERT_LT([[controller1 titleField] frame].origin.y, | 236 ASSERT_LT([[controller1 titleField] frame].origin.y, |
249 [[controller2 titleField] frame].origin.y); | 237 [[controller2 titleField] frame].origin.y); |
250 } | 238 } |
251 | 239 |
252 // Test that we can load the skinny prompt correctly, and that the outlets are | 240 // Test that we can load the skinny prompt correctly, and that the outlets are |
253 // are hooked up. | 241 // are hooked up. |
254 TEST_F(ExtensionInstallDialogControllerTest, BasicsSkinny) { | 242 TEST_F(ExtensionInstallDialogControllerTest, BasicsSkinny) { |
255 scoped_ptr<MockExtensionInstallUIDelegate> delegate( | 243 MockExtensionInstallUIDelegate delegate; |
256 new MockExtensionInstallUIDelegate); | |
257 | 244 |
258 // No warnings should trigger skinny prompt. | 245 // No warnings should trigger skinny prompt. |
259 ExtensionInstallUI::Prompt no_warnings_prompt( | 246 ExtensionInstallUI::Prompt no_warnings_prompt( |
260 ExtensionInstallUI::INSTALL_PROMPT); | 247 ExtensionInstallUI::INSTALL_PROMPT); |
261 | 248 |
262 std::vector<string16> warnings; | |
263 | |
264 scoped_nsobject<ExtensionInstallDialogController> | 249 scoped_nsobject<ExtensionInstallDialogController> |
265 controller([[ExtensionInstallDialogController alloc] | 250 controller([[ExtensionInstallDialogController alloc] |
266 initWithParentWindow:test_window() | 251 initWithParentWindow:test_window() |
267 profile:helper_.profile() | 252 profile:helper_.profile() |
268 extension:extension_.get() | 253 extension:extension_.get() |
269 delegate:delegate.get() | 254 delegate:&delegate |
270 icon:&icon_ | 255 icon:&icon_ |
271 prompt:no_warnings_prompt]); | 256 prompt:no_warnings_prompt]); |
272 | 257 |
273 [controller window]; // force nib load | 258 [controller window]; // force nib load |
274 | 259 |
275 // Test the right nib loaded. | 260 // Test the right nib loaded. |
276 EXPECT_NSEQ(@"ExtensionInstallPromptNoWarnings", [controller windowNibName]); | 261 EXPECT_NSEQ(@"ExtensionInstallPromptNoWarnings", [controller windowNibName]); |
277 | 262 |
278 // Check all the controls. | 263 // Check all the controls. |
279 // In the skinny prompt, only the icon, title and buttons are non-nill. | 264 // In the skinny prompt, only the icon, title and buttons are non-nill. |
280 // Everything else is nil. | 265 // Everything else is nil. |
281 EXPECT_TRUE([controller iconView] != nil); | 266 EXPECT_TRUE([controller iconView] != nil); |
282 EXPECT_TRUE([[controller iconView] image] != nil); | 267 EXPECT_TRUE([[controller iconView] image] != nil); |
283 | 268 |
284 EXPECT_TRUE([controller titleField] != nil); | 269 EXPECT_TRUE([controller titleField] != nil); |
285 EXPECT_NE(0u, [[[controller titleField] stringValue] length]); | 270 EXPECT_NE(0u, [[[controller titleField] stringValue] length]); |
286 | 271 |
287 EXPECT_TRUE([controller cancelButton] != nil); | 272 EXPECT_TRUE([controller cancelButton] != nil); |
288 EXPECT_NE(0u, [[[controller cancelButton] stringValue] length]); | 273 EXPECT_NE(0u, [[[controller cancelButton] stringValue] length]); |
289 EXPECT_NE('^', [[[controller cancelButton] stringValue] characterAtIndex:0]); | 274 EXPECT_NE('^', [[[controller cancelButton] stringValue] characterAtIndex:0]); |
290 | 275 |
291 EXPECT_TRUE([controller okButton] != nil); | 276 EXPECT_TRUE([controller okButton] != nil); |
292 EXPECT_NE(0u, [[[controller okButton] stringValue] length]); | 277 EXPECT_NE(0u, [[[controller okButton] stringValue] length]); |
293 EXPECT_NE('^', [[[controller okButton] stringValue] characterAtIndex:0]); | 278 EXPECT_NE('^', [[[controller okButton] stringValue] characterAtIndex:0]); |
294 | 279 |
295 EXPECT_TRUE([controller subtitleField] == nil); | 280 EXPECT_TRUE([controller subtitleField] == nil); |
296 EXPECT_TRUE([controller warningsField] == nil); | 281 EXPECT_TRUE([controller warningsField] == nil); |
297 EXPECT_TRUE([controller warningsBox] == nil); | |
298 } | 282 } |
| 283 |
| 284 |
| 285 // Test that we can load the inline prompt correctly, and that the outlets are |
| 286 // are hooked up. |
| 287 TEST_F(ExtensionInstallDialogControllerTest, BasicsInline) { |
| 288 MockExtensionInstallUIDelegate delegate; |
| 289 |
| 290 // No warnings should trigger skinny prompt. |
| 291 ExtensionInstallUI::Prompt inline_prompt( |
| 292 ExtensionInstallUI::INLINE_INSTALL_PROMPT); |
| 293 inline_prompt.SetInlineInstallWebstoreData("1,000", 3.5, 200); |
| 294 |
| 295 scoped_nsobject<ExtensionInstallDialogController> |
| 296 controller([[ExtensionInstallDialogController alloc] |
| 297 initWithParentWindow:test_window() |
| 298 profile:helper_.profile() |
| 299 extension:extension_.get() |
| 300 delegate:&delegate |
| 301 icon:&icon_ |
| 302 prompt:inline_prompt]); |
| 303 |
| 304 [controller window]; // force nib load |
| 305 |
| 306 // Test the right nib loaded. |
| 307 EXPECT_NSEQ(@"ExtensionInstallPromptInline", [controller windowNibName]); |
| 308 |
| 309 // Check all the controls. |
| 310 EXPECT_TRUE([controller iconView] != nil); |
| 311 EXPECT_TRUE([[controller iconView] image] != nil); |
| 312 |
| 313 EXPECT_TRUE([controller titleField] != nil); |
| 314 EXPECT_NE(0u, [[[controller titleField] stringValue] length]); |
| 315 |
| 316 EXPECT_TRUE([controller cancelButton] != nil); |
| 317 EXPECT_NE(0u, [[[controller cancelButton] stringValue] length]); |
| 318 EXPECT_NE('^', [[[controller cancelButton] stringValue] characterAtIndex:0]); |
| 319 |
| 320 EXPECT_TRUE([controller okButton] != nil); |
| 321 EXPECT_NE(0u, [[[controller okButton] stringValue] length]); |
| 322 EXPECT_NE('^', [[[controller okButton] stringValue] characterAtIndex:0]); |
| 323 |
| 324 EXPECT_TRUE([controller ratingStars] != nil); |
| 325 EXPECT_EQ(5u, [[[controller ratingStars] subviews] count]); |
| 326 |
| 327 EXPECT_TRUE([controller ratingCountField] != nil); |
| 328 EXPECT_NE(0u, [[[controller ratingCountField] stringValue] length]); |
| 329 |
| 330 EXPECT_TRUE([controller userCountField] != nil); |
| 331 EXPECT_NE(0u, [[[controller userCountField] stringValue] length]); |
| 332 |
| 333 // Though we have no permissions warnings, these should still be hooked up, |
| 334 // just invisible. |
| 335 EXPECT_TRUE([controller subtitleField] != nil); |
| 336 EXPECT_TRUE([[controller subtitleField] isHidden]); |
| 337 EXPECT_TRUE([controller warningsField] != nil); |
| 338 EXPECT_TRUE([[controller warningsField] isHidden]); |
| 339 EXPECT_TRUE([controller warningsSeparator] != nil); |
| 340 EXPECT_TRUE([[controller warningsSeparator] isHidden]); |
| 341 } |
OLD | NEW |