OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // Check all the controls. | 131 // Check all the controls. |
132 // Make sure everything is non-nil, and that the fields that are | 132 // Make sure everything is non-nil, and that the fields that are |
133 // auto-translated don't start with a caret (that would indicate that they | 133 // auto-translated don't start with a caret (that would indicate that they |
134 // were not translated). | 134 // were not translated). |
135 EXPECT_TRUE([controller iconView] != nil); | 135 EXPECT_TRUE([controller iconView] != nil); |
136 EXPECT_TRUE([[controller iconView] image] != nil); | 136 EXPECT_TRUE([[controller iconView] image] != nil); |
137 | 137 |
138 EXPECT_TRUE([controller titleField] != nil); | 138 EXPECT_TRUE([controller titleField] != nil); |
139 EXPECT_NE(0u, [[[controller titleField] stringValue] length]); | 139 EXPECT_NE(0u, [[[controller titleField] stringValue] length]); |
140 | 140 |
141 EXPECT_TRUE([controller subtitleField] != nil); | 141 NSOutlineView* outlineView = [controller outlineView]; |
142 EXPECT_NE(0u, [[[controller subtitleField] stringValue] length]); | 142 EXPECT_TRUE(outlineView != nil); |
143 EXPECT_NE('^', [[[controller subtitleField] stringValue] characterAtIndex:0]); | 143 EXPECT_EQ(2, [outlineView numberOfRows]); |
144 | 144 EXPECT_NSEQ([[outlineView dataSource] outlineView:outlineView |
145 EXPECT_TRUE([controller warningsField] != nil); | 145 objectValueForTableColumn:nil |
146 EXPECT_NSEQ([[controller warningsField] stringValue], | 146 byItem:[outlineView itemAtRow:1]], |
147 base::SysUTF16ToNSString(prompt.GetPermission(0))); | 147 base::SysUTF16ToNSString(prompt.GetPermission(0))); |
148 | 148 |
149 EXPECT_TRUE([controller cancelButton] != nil); | 149 EXPECT_TRUE([controller cancelButton] != nil); |
150 EXPECT_NE(0u, [[[controller cancelButton] stringValue] length]); | 150 EXPECT_NE(0u, [[[controller cancelButton] stringValue] length]); |
151 EXPECT_NE('^', [[[controller cancelButton] stringValue] characterAtIndex:0]); | 151 EXPECT_NE('^', [[[controller cancelButton] stringValue] characterAtIndex:0]); |
152 | 152 |
153 EXPECT_TRUE([controller okButton] != nil); | 153 EXPECT_TRUE([controller okButton] != nil); |
154 EXPECT_NE(0u, [[[controller okButton] stringValue] length]); | 154 EXPECT_NE(0u, [[[controller okButton] stringValue] length]); |
155 EXPECT_NE('^', [[[controller okButton] stringValue] characterAtIndex:0]); | 155 EXPECT_NE('^', [[[controller okButton] stringValue] characterAtIndex:0]); |
156 | 156 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 prompt:two_warnings_prompt]); | 224 prompt:two_warnings_prompt]); |
225 | 225 |
226 [controller2 window]; // force nib load | 226 [controller2 window]; // force nib load |
227 | 227 |
228 // Test control positioning. We don't test exact positioning because we don't | 228 // Test control positioning. We don't test exact positioning because we don't |
229 // want this to depend on string details and localization. But we do know the | 229 // want this to depend on string details and localization. But we do know the |
230 // relative effect that adding a second warning should have on the layout. | 230 // relative effect that adding a second warning should have on the layout. |
231 ASSERT_LT([[controller1 window] frame].size.height, | 231 ASSERT_LT([[controller1 window] frame].size.height, |
232 [[controller2 window] frame].size.height); | 232 [[controller2 window] frame].size.height); |
233 | 233 |
234 ASSERT_LT([[controller1 warningsField] frame].size.height, | 234 ASSERT_LT([[controller1 outlineView] frame].size.height, |
235 [[controller2 warningsField] frame].size.height); | 235 [[controller2 outlineView] frame].size.height); |
236 | |
237 ASSERT_LT([[controller1 subtitleField] frame].origin.y, | |
238 [[controller2 subtitleField] frame].origin.y); | |
239 | 236 |
240 ASSERT_LT([[controller1 titleField] frame].origin.y, | 237 ASSERT_LT([[controller1 titleField] frame].origin.y, |
241 [[controller2 titleField] frame].origin.y); | 238 [[controller2 titleField] frame].origin.y); |
242 } | 239 } |
243 | 240 |
244 // Test that we can load the skinny prompt correctly, and that the outlets are | 241 // Test that we can load the skinny prompt correctly, and that the outlets are |
245 // are hooked up. | 242 // are hooked up. |
246 TEST_F(ExtensionInstallDialogControllerTest, BasicsSkinny) { | 243 TEST_F(ExtensionInstallDialogControllerTest, BasicsSkinny) { |
247 MockExtensionInstallPromptDelegate delegate; | 244 MockExtensionInstallPromptDelegate delegate; |
248 | 245 |
(...skipping 25 matching lines...) Expand all Loading... |
274 EXPECT_NE(0u, [[[controller titleField] stringValue] length]); | 271 EXPECT_NE(0u, [[[controller titleField] stringValue] length]); |
275 | 272 |
276 EXPECT_TRUE([controller cancelButton] != nil); | 273 EXPECT_TRUE([controller cancelButton] != nil); |
277 EXPECT_NE(0u, [[[controller cancelButton] stringValue] length]); | 274 EXPECT_NE(0u, [[[controller cancelButton] stringValue] length]); |
278 EXPECT_NE('^', [[[controller cancelButton] stringValue] characterAtIndex:0]); | 275 EXPECT_NE('^', [[[controller cancelButton] stringValue] characterAtIndex:0]); |
279 | 276 |
280 EXPECT_TRUE([controller okButton] != nil); | 277 EXPECT_TRUE([controller okButton] != nil); |
281 EXPECT_NE(0u, [[[controller okButton] stringValue] length]); | 278 EXPECT_NE(0u, [[[controller okButton] stringValue] length]); |
282 EXPECT_NE('^', [[[controller okButton] stringValue] characterAtIndex:0]); | 279 EXPECT_NE('^', [[[controller okButton] stringValue] characterAtIndex:0]); |
283 | 280 |
284 EXPECT_TRUE([controller subtitleField] == nil); | 281 EXPECT_TRUE([controller outlineView] == nil); |
285 EXPECT_TRUE([controller warningsField] == nil); | |
286 } | 282 } |
287 | 283 |
288 | 284 |
289 // Test that we can load the inline prompt correctly, and that the outlets are | 285 // Test that we can load the inline prompt correctly, and that the outlets are |
290 // are hooked up. | 286 // are hooked up. |
291 TEST_F(ExtensionInstallDialogControllerTest, BasicsInline) { | 287 TEST_F(ExtensionInstallDialogControllerTest, BasicsInline) { |
292 MockExtensionInstallPromptDelegate delegate; | 288 MockExtensionInstallPromptDelegate delegate; |
293 | 289 |
294 // No warnings should trigger skinny prompt. | 290 // No warnings should trigger skinny prompt. |
295 ExtensionInstallPrompt::Prompt inline_prompt( | 291 ExtensionInstallPrompt::Prompt inline_prompt( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 EXPECT_EQ(5u, [[[controller ratingStars] subviews] count]); | 325 EXPECT_EQ(5u, [[[controller ratingStars] subviews] count]); |
330 | 326 |
331 EXPECT_TRUE([controller ratingCountField] != nil); | 327 EXPECT_TRUE([controller ratingCountField] != nil); |
332 EXPECT_NE(0u, [[[controller ratingCountField] stringValue] length]); | 328 EXPECT_NE(0u, [[[controller ratingCountField] stringValue] length]); |
333 | 329 |
334 EXPECT_TRUE([controller userCountField] != nil); | 330 EXPECT_TRUE([controller userCountField] != nil); |
335 EXPECT_NE(0u, [[[controller userCountField] stringValue] length]); | 331 EXPECT_NE(0u, [[[controller userCountField] stringValue] length]); |
336 | 332 |
337 // Though we have no permissions warnings, these should still be hooked up, | 333 // Though we have no permissions warnings, these should still be hooked up, |
338 // just invisible. | 334 // just invisible. |
339 EXPECT_TRUE([controller subtitleField] != nil); | 335 EXPECT_TRUE([controller outlineView] != nil); |
340 EXPECT_TRUE([[controller subtitleField] isHidden]); | 336 EXPECT_TRUE([[[controller outlineView] enclosingScrollView] isHidden]); |
341 EXPECT_TRUE([controller warningsField] != nil); | |
342 EXPECT_TRUE([[controller warningsField] isHidden]); | |
343 EXPECT_TRUE([controller warningsSeparator] != nil); | 337 EXPECT_TRUE([controller warningsSeparator] != nil); |
344 EXPECT_TRUE([[controller warningsSeparator] isHidden]); | 338 EXPECT_TRUE([[controller warningsSeparator] isHidden]); |
345 } | 339 } |
| 340 |
| 341 TEST_F(ExtensionInstallDialogControllerTest, OAuthIssues) { |
| 342 MockExtensionInstallPromptDelegate delegate; |
| 343 |
| 344 ExtensionInstallPrompt::Prompt prompt( |
| 345 ExtensionInstallPrompt::INSTALL_PROMPT); |
| 346 std::vector<string16> permissions; |
| 347 permissions.push_back(UTF8ToUTF16("warning 1")); |
| 348 prompt.SetPermissions(permissions); |
| 349 IssueAdviceInfoEntry issue; |
| 350 issue.description = UTF8ToUTF16("issue description 1"); |
| 351 issue.details.push_back(UTF8ToUTF16("issue detail 1")); |
| 352 IssueAdviceInfo issues; |
| 353 issues.push_back(issue); |
| 354 prompt.SetOAuthIssueAdvice(issues); |
| 355 prompt.set_extension(extension_.get()); |
| 356 prompt.set_icon(icon_); |
| 357 |
| 358 scoped_nsobject<ExtensionInstallDialogController> |
| 359 controller([[ExtensionInstallDialogController alloc] |
| 360 initWithParentWindow:test_window() |
| 361 navigator:browser() |
| 362 delegate:&delegate |
| 363 prompt:prompt]); |
| 364 |
| 365 [controller window]; // force nib load |
| 366 NSOutlineView* outlineView = [controller outlineView]; |
| 367 EXPECT_TRUE(outlineView != nil); |
| 368 EXPECT_EQ(4, [outlineView numberOfRows]); |
| 369 EXPECT_NSEQ([[outlineView dataSource] outlineView:outlineView |
| 370 objectValueForTableColumn:nil |
| 371 byItem:[outlineView itemAtRow:3]], |
| 372 base::SysUTF16ToNSString(prompt.GetOAuthIssue(0).description)); |
| 373 } |
OLD | NEW |