| 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 #import "base/memory/scoped_nsobject.h" | 7 #import "base/mac/scoped_nsobject.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #import "chrome/browser/extensions/extension_install_prompt.h" | 10 #import "chrome/browser/extensions/extension_install_prompt.h" |
| 11 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 11 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 12 #import "chrome/browser/ui/cocoa/extensions/extension_install_prompt_test_utils.
h" | 12 #import "chrome/browser/ui/cocoa/extensions/extension_install_prompt_test_utils.
h" |
| 13 #import "chrome/browser/ui/cocoa/extensions/extension_install_view_controller.h" | 13 #import "chrome/browser/ui/cocoa/extensions/extension_install_view_controller.h" |
| 14 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #import "testing/gtest_mac.h" | 16 #import "testing/gtest_mac.h" |
| 17 | 17 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 33 TEST_F(ExtensionInstallViewControllerTest, BasicsNormalCancel) { | 33 TEST_F(ExtensionInstallViewControllerTest, BasicsNormalCancel) { |
| 34 chrome::MockExtensionInstallPromptDelegate delegate; | 34 chrome::MockExtensionInstallPromptDelegate delegate; |
| 35 | 35 |
| 36 ExtensionInstallPrompt::Prompt prompt = | 36 ExtensionInstallPrompt::Prompt prompt = |
| 37 chrome::BuildExtensionInstallPrompt(extension_.get()); | 37 chrome::BuildExtensionInstallPrompt(extension_.get()); |
| 38 | 38 |
| 39 std::vector<string16> permissions; | 39 std::vector<string16> permissions; |
| 40 permissions.push_back(UTF8ToUTF16("warning 1")); | 40 permissions.push_back(UTF8ToUTF16("warning 1")); |
| 41 prompt.SetPermissions(permissions); | 41 prompt.SetPermissions(permissions); |
| 42 | 42 |
| 43 scoped_nsobject<ExtensionInstallViewController> | 43 base::scoped_nsobject<ExtensionInstallViewController> controller( |
| 44 controller([[ExtensionInstallViewController alloc] | 44 [[ExtensionInstallViewController alloc] initWithNavigator:browser() |
| 45 initWithNavigator:browser() | 45 delegate:&delegate |
| 46 delegate:&delegate | 46 prompt:prompt]); |
| 47 prompt:prompt]); | |
| 48 | 47 |
| 49 [controller view]; // Force nib load. | 48 [controller view]; // Force nib load. |
| 50 | 49 |
| 51 // Test the right nib loaded. | 50 // Test the right nib loaded. |
| 52 EXPECT_NSEQ(@"ExtensionInstallPrompt", [controller nibName]); | 51 EXPECT_NSEQ(@"ExtensionInstallPrompt", [controller nibName]); |
| 53 | 52 |
| 54 // Check all the controls. | 53 // Check all the controls. |
| 55 // Make sure everything is non-nil, and that the fields that are | 54 // Make sure everything is non-nil, and that the fields that are |
| 56 // auto-translated don't start with a caret (that would indicate that they | 55 // auto-translated don't start with a caret (that would indicate that they |
| 57 // were not translated). | 56 // were not translated). |
| (...skipping 28 matching lines...) Expand all Loading... |
| 86 | 85 |
| 87 TEST_F(ExtensionInstallViewControllerTest, BasicsNormalOK) { | 86 TEST_F(ExtensionInstallViewControllerTest, BasicsNormalOK) { |
| 88 chrome::MockExtensionInstallPromptDelegate delegate; | 87 chrome::MockExtensionInstallPromptDelegate delegate; |
| 89 | 88 |
| 90 ExtensionInstallPrompt::Prompt prompt = | 89 ExtensionInstallPrompt::Prompt prompt = |
| 91 chrome::BuildExtensionInstallPrompt(extension_.get()); | 90 chrome::BuildExtensionInstallPrompt(extension_.get()); |
| 92 std::vector<string16> permissions; | 91 std::vector<string16> permissions; |
| 93 permissions.push_back(UTF8ToUTF16("warning 1")); | 92 permissions.push_back(UTF8ToUTF16("warning 1")); |
| 94 prompt.SetPermissions(permissions); | 93 prompt.SetPermissions(permissions); |
| 95 | 94 |
| 96 scoped_nsobject<ExtensionInstallViewController> | 95 base::scoped_nsobject<ExtensionInstallViewController> controller( |
| 97 controller([[ExtensionInstallViewController alloc] | 96 [[ExtensionInstallViewController alloc] initWithNavigator:browser() |
| 98 initWithNavigator:browser() | 97 delegate:&delegate |
| 99 delegate:&delegate | 98 prompt:prompt]); |
| 100 prompt:prompt]); | |
| 101 | 99 |
| 102 [controller view]; // Force nib load. | 100 [controller view]; // Force nib load. |
| 103 [controller ok:nil]; | 101 [controller ok:nil]; |
| 104 | 102 |
| 105 EXPECT_EQ(0, delegate.abort_count()); | 103 EXPECT_EQ(0, delegate.abort_count()); |
| 106 EXPECT_EQ(1, delegate.proceed_count()); | 104 EXPECT_EQ(1, delegate.proceed_count()); |
| 107 } | 105 } |
| 108 | 106 |
| 109 // Test that controls get repositioned when there are two warnings vs one | 107 // Test that controls get repositioned when there are two warnings vs one |
| 110 // warning. | 108 // warning. |
| 111 TEST_F(ExtensionInstallViewControllerTest, MultipleWarnings) { | 109 TEST_F(ExtensionInstallViewControllerTest, MultipleWarnings) { |
| 112 chrome::MockExtensionInstallPromptDelegate delegate1; | 110 chrome::MockExtensionInstallPromptDelegate delegate1; |
| 113 chrome::MockExtensionInstallPromptDelegate delegate2; | 111 chrome::MockExtensionInstallPromptDelegate delegate2; |
| 114 | 112 |
| 115 ExtensionInstallPrompt::Prompt one_warning_prompt = | 113 ExtensionInstallPrompt::Prompt one_warning_prompt = |
| 116 chrome::BuildExtensionInstallPrompt(extension_.get()); | 114 chrome::BuildExtensionInstallPrompt(extension_.get()); |
| 117 std::vector<string16> permissions; | 115 std::vector<string16> permissions; |
| 118 permissions.push_back(UTF8ToUTF16("warning 1")); | 116 permissions.push_back(UTF8ToUTF16("warning 1")); |
| 119 one_warning_prompt.SetPermissions(permissions); | 117 one_warning_prompt.SetPermissions(permissions); |
| 120 | 118 |
| 121 ExtensionInstallPrompt::Prompt two_warnings_prompt = | 119 ExtensionInstallPrompt::Prompt two_warnings_prompt = |
| 122 chrome::BuildExtensionInstallPrompt(extension_.get()); | 120 chrome::BuildExtensionInstallPrompt(extension_.get()); |
| 123 permissions.push_back(UTF8ToUTF16("warning 2")); | 121 permissions.push_back(UTF8ToUTF16("warning 2")); |
| 124 two_warnings_prompt.SetPermissions(permissions); | 122 two_warnings_prompt.SetPermissions(permissions); |
| 125 | 123 |
| 126 scoped_nsobject<ExtensionInstallViewController> | 124 base::scoped_nsobject<ExtensionInstallViewController> controller1( |
| 127 controller1([[ExtensionInstallViewController alloc] | 125 [[ExtensionInstallViewController alloc] |
| 128 initWithNavigator:browser() | 126 initWithNavigator:browser() |
| 129 delegate:&delegate1 | 127 delegate:&delegate1 |
| 130 prompt:one_warning_prompt]); | 128 prompt:one_warning_prompt]); |
| 131 | 129 |
| 132 [controller1 view]; // Force nib load. | 130 [controller1 view]; // Force nib load. |
| 133 | 131 |
| 134 scoped_nsobject<ExtensionInstallViewController> | 132 base::scoped_nsobject<ExtensionInstallViewController> controller2( |
| 135 controller2([[ExtensionInstallViewController alloc] | 133 [[ExtensionInstallViewController alloc] |
| 136 initWithNavigator:browser() | 134 initWithNavigator:browser() |
| 137 delegate:&delegate2 | 135 delegate:&delegate2 |
| 138 prompt:two_warnings_prompt]); | 136 prompt:two_warnings_prompt]); |
| 139 | 137 |
| 140 [controller2 view]; // Force nib load. | 138 [controller2 view]; // Force nib load. |
| 141 | 139 |
| 142 // Test control positioning. We don't test exact positioning because we don't | 140 // Test control positioning. We don't test exact positioning because we don't |
| 143 // want this to depend on string details and localization. But we do know the | 141 // want this to depend on string details and localization. But we do know the |
| 144 // relative effect that adding a second warning should have on the layout. | 142 // relative effect that adding a second warning should have on the layout. |
| 145 ASSERT_LT([[controller1 view] frame].size.height, | 143 ASSERT_LT([[controller1 view] frame].size.height, |
| 146 [[controller2 view] frame].size.height); | 144 [[controller2 view] frame].size.height); |
| 147 | 145 |
| 148 ASSERT_LT([[controller1 view] frame].size.height, | 146 ASSERT_LT([[controller1 view] frame].size.height, |
| 149 [[controller2 view] frame].size.height); | 147 [[controller2 view] frame].size.height); |
| 150 } | 148 } |
| 151 | 149 |
| 152 // Test that we can load the skinny prompt correctly, and that the outlets are | 150 // Test that we can load the skinny prompt correctly, and that the outlets are |
| 153 // are hooked up. | 151 // are hooked up. |
| 154 TEST_F(ExtensionInstallViewControllerTest, BasicsSkinny) { | 152 TEST_F(ExtensionInstallViewControllerTest, BasicsSkinny) { |
| 155 chrome::MockExtensionInstallPromptDelegate delegate; | 153 chrome::MockExtensionInstallPromptDelegate delegate; |
| 156 | 154 |
| 157 // No warnings should trigger skinny prompt. | 155 // No warnings should trigger skinny prompt. |
| 158 ExtensionInstallPrompt::Prompt no_warnings_prompt = | 156 ExtensionInstallPrompt::Prompt no_warnings_prompt = |
| 159 chrome::BuildExtensionInstallPrompt(extension_.get()); | 157 chrome::BuildExtensionInstallPrompt(extension_.get()); |
| 160 | 158 |
| 161 scoped_nsobject<ExtensionInstallViewController> | 159 base::scoped_nsobject<ExtensionInstallViewController> controller( |
| 162 controller([[ExtensionInstallViewController alloc] | 160 [[ExtensionInstallViewController alloc] |
| 163 initWithNavigator:browser() | 161 initWithNavigator:browser() |
| 164 delegate:&delegate | 162 delegate:&delegate |
| 165 prompt:no_warnings_prompt]); | 163 prompt:no_warnings_prompt]); |
| 166 | 164 |
| 167 [controller view]; // Force nib load. | 165 [controller view]; // Force nib load. |
| 168 | 166 |
| 169 // Test the right nib loaded. | 167 // Test the right nib loaded. |
| 170 EXPECT_NSEQ(@"ExtensionInstallPromptNoWarnings", [controller nibName]); | 168 EXPECT_NSEQ(@"ExtensionInstallPromptNoWarnings", [controller nibName]); |
| 171 | 169 |
| 172 // Check all the controls. | 170 // Check all the controls. |
| 173 // In the skinny prompt, only the icon, title and buttons are non-nill. | 171 // In the skinny prompt, only the icon, title and buttons are non-nill. |
| 174 // Everything else is nil. | 172 // Everything else is nil. |
| 175 EXPECT_TRUE([controller iconView]); | 173 EXPECT_TRUE([controller iconView]); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 195 TEST_F(ExtensionInstallViewControllerTest, BasicsInline) { | 193 TEST_F(ExtensionInstallViewControllerTest, BasicsInline) { |
| 196 chrome::MockExtensionInstallPromptDelegate delegate; | 194 chrome::MockExtensionInstallPromptDelegate delegate; |
| 197 | 195 |
| 198 // No warnings should trigger skinny prompt. | 196 // No warnings should trigger skinny prompt. |
| 199 ExtensionInstallPrompt::Prompt inline_prompt( | 197 ExtensionInstallPrompt::Prompt inline_prompt( |
| 200 ExtensionInstallPrompt::INLINE_INSTALL_PROMPT); | 198 ExtensionInstallPrompt::INLINE_INSTALL_PROMPT); |
| 201 inline_prompt.SetInlineInstallWebstoreData("1,000", 3.5, 200); | 199 inline_prompt.SetInlineInstallWebstoreData("1,000", 3.5, 200); |
| 202 inline_prompt.set_extension(extension_.get()); | 200 inline_prompt.set_extension(extension_.get()); |
| 203 inline_prompt.set_icon(chrome::LoadInstallPromptIcon()); | 201 inline_prompt.set_icon(chrome::LoadInstallPromptIcon()); |
| 204 | 202 |
| 205 scoped_nsobject<ExtensionInstallViewController> | 203 base::scoped_nsobject<ExtensionInstallViewController> controller( |
| 206 controller([[ExtensionInstallViewController alloc] | 204 [[ExtensionInstallViewController alloc] initWithNavigator:browser() |
| 207 initWithNavigator:browser() | 205 delegate:&delegate |
| 208 delegate:&delegate | 206 prompt:inline_prompt]); |
| 209 prompt:inline_prompt]); | |
| 210 | 207 |
| 211 [controller view]; // Force nib load. | 208 [controller view]; // Force nib load. |
| 212 | 209 |
| 213 // Test the right nib loaded. | 210 // Test the right nib loaded. |
| 214 EXPECT_NSEQ(@"ExtensionInstallPromptInline", [controller nibName]); | 211 EXPECT_NSEQ(@"ExtensionInstallPromptInline", [controller nibName]); |
| 215 | 212 |
| 216 // Check all the controls. | 213 // Check all the controls. |
| 217 EXPECT_TRUE([controller iconView]); | 214 EXPECT_TRUE([controller iconView]); |
| 218 EXPECT_TRUE([[controller iconView] image]); | 215 EXPECT_TRUE([[controller iconView] image]); |
| 219 | 216 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 std::vector<string16> permissions; | 255 std::vector<string16> permissions; |
| 259 permissions.push_back(UTF8ToUTF16("warning 1")); | 256 permissions.push_back(UTF8ToUTF16("warning 1")); |
| 260 prompt.SetPermissions(permissions); | 257 prompt.SetPermissions(permissions); |
| 261 IssueAdviceInfoEntry issue; | 258 IssueAdviceInfoEntry issue; |
| 262 issue.description = UTF8ToUTF16("issue description 1"); | 259 issue.description = UTF8ToUTF16("issue description 1"); |
| 263 issue.details.push_back(UTF8ToUTF16("issue detail 1")); | 260 issue.details.push_back(UTF8ToUTF16("issue detail 1")); |
| 264 IssueAdviceInfo issues; | 261 IssueAdviceInfo issues; |
| 265 issues.push_back(issue); | 262 issues.push_back(issue); |
| 266 prompt.SetOAuthIssueAdvice(issues); | 263 prompt.SetOAuthIssueAdvice(issues); |
| 267 | 264 |
| 268 scoped_nsobject<ExtensionInstallViewController> | 265 base::scoped_nsobject<ExtensionInstallViewController> controller( |
| 269 controller([[ExtensionInstallViewController alloc] | 266 [[ExtensionInstallViewController alloc] initWithNavigator:browser() |
| 270 initWithNavigator:browser() | 267 delegate:&delegate |
| 271 delegate:&delegate | 268 prompt:prompt]); |
| 272 prompt:prompt]); | |
| 273 | 269 |
| 274 [controller view]; // Force nib load. | 270 [controller view]; // Force nib load. |
| 275 NSOutlineView* outlineView = [controller outlineView]; | 271 NSOutlineView* outlineView = [controller outlineView]; |
| 276 EXPECT_TRUE(outlineView); | 272 EXPECT_TRUE(outlineView); |
| 277 EXPECT_EQ(4, [outlineView numberOfRows]); | 273 EXPECT_EQ(4, [outlineView numberOfRows]); |
| 278 EXPECT_NSEQ([[outlineView dataSource] outlineView:outlineView | 274 EXPECT_NSEQ([[outlineView dataSource] outlineView:outlineView |
| 279 objectValueForTableColumn:nil | 275 objectValueForTableColumn:nil |
| 280 byItem:[outlineView itemAtRow:3]], | 276 byItem:[outlineView itemAtRow:3]], |
| 281 base::SysUTF16ToNSString(prompt.GetOAuthIssue(0).description)); | 277 base::SysUTF16ToNSString(prompt.GetOAuthIssue(0).description)); |
| 282 } | 278 } |
| 283 | 279 |
| 284 TEST_F(ExtensionInstallViewControllerTest, PostInstallPermissionsPrompt) { | 280 TEST_F(ExtensionInstallViewControllerTest, PostInstallPermissionsPrompt) { |
| 285 chrome::MockExtensionInstallPromptDelegate delegate; | 281 chrome::MockExtensionInstallPromptDelegate delegate; |
| 286 | 282 |
| 287 ExtensionInstallPrompt::Prompt prompt = | 283 ExtensionInstallPrompt::Prompt prompt = |
| 288 chrome::BuildExtensionPostInstallPermissionsPrompt(extension_.get()); | 284 chrome::BuildExtensionPostInstallPermissionsPrompt(extension_.get()); |
| 289 std::vector<string16> permissions; | 285 std::vector<string16> permissions; |
| 290 permissions.push_back(UTF8ToUTF16("warning 1")); | 286 permissions.push_back(UTF8ToUTF16("warning 1")); |
| 291 prompt.SetPermissions(permissions); | 287 prompt.SetPermissions(permissions); |
| 292 | 288 |
| 293 scoped_nsobject<ExtensionInstallViewController> | 289 base::scoped_nsobject<ExtensionInstallViewController> controller( |
| 294 controller([[ExtensionInstallViewController alloc] | 290 [[ExtensionInstallViewController alloc] initWithNavigator:browser() |
| 295 initWithNavigator:browser() | 291 delegate:&delegate |
| 296 delegate:&delegate | 292 prompt:prompt]); |
| 297 prompt:prompt]); | |
| 298 | 293 |
| 299 [controller view]; // Force nib load. | 294 [controller view]; // Force nib load. |
| 300 | 295 |
| 301 EXPECT_TRUE([controller cancelButton]); | 296 EXPECT_TRUE([controller cancelButton]); |
| 302 EXPECT_FALSE([controller okButton]); | 297 EXPECT_FALSE([controller okButton]); |
| 303 | 298 |
| 304 [controller cancel:nil]; | 299 [controller cancel:nil]; |
| 305 EXPECT_EQ(1, delegate.abort_count()); | 300 EXPECT_EQ(1, delegate.abort_count()); |
| 306 } | 301 } |
| OLD | NEW |