| 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" |
| 11 #import "base/memory/scoped_nsobject.h" | 11 #import "base/memory/scoped_nsobject.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #import "chrome/browser/extensions/extension_install_ui.h" | 16 #import "chrome/browser/extensions/extension_install_prompt.h" |
| 17 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 17 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 18 #import "chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.
h" | 18 #import "chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.
h" |
| 19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #import "testing/gtest_mac.h" | 22 #import "testing/gtest_mac.h" |
| 23 #include "testing/platform_test.h" | 23 #include "testing/platform_test.h" |
| 24 #include "third_party/skia/include/core/SkBitmap.h" | 24 #include "third_party/skia/include/core/SkBitmap.h" |
| 25 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
| 26 #include "webkit/glue/image_decoder.h" | 26 #include "webkit/glue/image_decoder.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 return; | 71 return; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 FilePath test_data_dir_; | 75 FilePath test_data_dir_; |
| 76 gfx::Image icon_; | 76 gfx::Image icon_; |
| 77 scoped_refptr<Extension> extension_; | 77 scoped_refptr<Extension> extension_; |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 | 80 |
| 81 // Mock out the ExtensionInstallUI::Delegate interface so we can ensure the | 81 // Mock out the ExtensionInstallPrompt::Delegate interface so we can ensure the |
| 82 // dialog is interacting with it correctly. | 82 // dialog is interacting with it correctly. |
| 83 class MockExtensionInstallUIDelegate : public ExtensionInstallUI::Delegate { | 83 class MockExtensionInstallPromptDelegate |
| 84 : public ExtensionInstallPrompt::Delegate { |
| 84 public: | 85 public: |
| 85 MockExtensionInstallUIDelegate() | 86 MockExtensionInstallPromptDelegate() |
| 86 : proceed_count_(0), | 87 : proceed_count_(0), |
| 87 abort_count_(0) {} | 88 abort_count_(0) {} |
| 88 | 89 |
| 89 // ExtensionInstallUI::Delegate overrides. | 90 // ExtensionInstallPrompt::Delegate overrides. |
| 90 virtual void InstallUIProceed() OVERRIDE { | 91 virtual void InstallUIProceed() OVERRIDE { |
| 91 proceed_count_++; | 92 proceed_count_++; |
| 92 } | 93 } |
| 93 | 94 |
| 94 virtual void InstallUIAbort(bool user_initiated) OVERRIDE { | 95 virtual void InstallUIAbort(bool user_initiated) OVERRIDE { |
| 95 abort_count_++; | 96 abort_count_++; |
| 96 } | 97 } |
| 97 | 98 |
| 98 int proceed_count() { return proceed_count_; } | 99 int proceed_count() { return proceed_count_; } |
| 99 int abort_count() { return abort_count_; } | 100 int abort_count() { return abort_count_; } |
| 100 | 101 |
| 101 protected: | 102 protected: |
| 102 int proceed_count_; | 103 int proceed_count_; |
| 103 int abort_count_; | 104 int abort_count_; |
| 104 }; | 105 }; |
| 105 | 106 |
| 106 // Test that we can load the two kinds of prompts correctly, that the outlets | 107 // Test that we can load the two kinds of prompts correctly, that the outlets |
| 107 // are hooked up, and that the dialog calls cancel when cancel is pressed. | 108 // are hooked up, and that the dialog calls cancel when cancel is pressed. |
| 108 TEST_F(ExtensionInstallDialogControllerTest, BasicsNormalCancel) { | 109 TEST_F(ExtensionInstallDialogControllerTest, BasicsNormalCancel) { |
| 109 MockExtensionInstallUIDelegate delegate; | 110 MockExtensionInstallPromptDelegate delegate; |
| 110 | 111 |
| 111 ExtensionInstallUI::Prompt prompt(ExtensionInstallUI::INSTALL_PROMPT); | 112 ExtensionInstallPrompt::Prompt prompt(ExtensionInstallPrompt::INSTALL_PROMPT); |
| 112 std::vector<string16> permissions; | 113 std::vector<string16> permissions; |
| 113 permissions.push_back(UTF8ToUTF16("warning 1")); | 114 permissions.push_back(UTF8ToUTF16("warning 1")); |
| 114 prompt.SetPermissions(permissions); | 115 prompt.SetPermissions(permissions); |
| 115 prompt.set_extension(extension_.get()); | 116 prompt.set_extension(extension_.get()); |
| 116 prompt.set_icon(icon_); | 117 prompt.set_icon(icon_); |
| 117 | 118 |
| 118 scoped_nsobject<ExtensionInstallDialogController> | 119 scoped_nsobject<ExtensionInstallDialogController> |
| 119 controller([[ExtensionInstallDialogController alloc] | 120 controller([[ExtensionInstallDialogController alloc] |
| 120 initWithParentWindow:test_window() | 121 initWithParentWindow:test_window() |
| 121 profile:profile() | 122 profile:profile() |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 EXPECT_NE('^', [[[controller okButton] stringValue] characterAtIndex:0]); | 155 EXPECT_NE('^', [[[controller okButton] stringValue] characterAtIndex:0]); |
| 155 | 156 |
| 156 // Test that cancel calls our delegate. | 157 // Test that cancel calls our delegate. |
| 157 [controller cancel:nil]; | 158 [controller cancel:nil]; |
| 158 EXPECT_EQ(1, delegate.abort_count()); | 159 EXPECT_EQ(1, delegate.abort_count()); |
| 159 EXPECT_EQ(0, delegate.proceed_count()); | 160 EXPECT_EQ(0, delegate.proceed_count()); |
| 160 } | 161 } |
| 161 | 162 |
| 162 | 163 |
| 163 TEST_F(ExtensionInstallDialogControllerTest, BasicsNormalOK) { | 164 TEST_F(ExtensionInstallDialogControllerTest, BasicsNormalOK) { |
| 164 MockExtensionInstallUIDelegate delegate; | 165 MockExtensionInstallPromptDelegate delegate; |
| 165 | 166 |
| 166 ExtensionInstallUI::Prompt prompt(ExtensionInstallUI::INSTALL_PROMPT); | 167 ExtensionInstallPrompt::Prompt prompt( |
| 168 ExtensionInstallPrompt::INSTALL_PROMPT); |
| 167 std::vector<string16> permissions; | 169 std::vector<string16> permissions; |
| 168 permissions.push_back(UTF8ToUTF16("warning 1")); | 170 permissions.push_back(UTF8ToUTF16("warning 1")); |
| 169 prompt.SetPermissions(permissions); | 171 prompt.SetPermissions(permissions); |
| 170 prompt.set_extension(extension_.get()); | 172 prompt.set_extension(extension_.get()); |
| 171 prompt.set_icon(icon_); | 173 prompt.set_icon(icon_); |
| 172 | 174 |
| 173 scoped_nsobject<ExtensionInstallDialogController> | 175 scoped_nsobject<ExtensionInstallDialogController> |
| 174 controller([[ExtensionInstallDialogController alloc] | 176 controller([[ExtensionInstallDialogController alloc] |
| 175 initWithParentWindow:test_window() | 177 initWithParentWindow:test_window() |
| 176 profile:profile() | 178 profile:profile() |
| 177 delegate:&delegate | 179 delegate:&delegate |
| 178 prompt:prompt]); | 180 prompt:prompt]); |
| 179 | 181 |
| 180 [controller window]; // force nib load | 182 [controller window]; // force nib load |
| 181 [controller ok:nil]; | 183 [controller ok:nil]; |
| 182 | 184 |
| 183 EXPECT_EQ(0, delegate.abort_count()); | 185 EXPECT_EQ(0, delegate.abort_count()); |
| 184 EXPECT_EQ(1, delegate.proceed_count()); | 186 EXPECT_EQ(1, delegate.proceed_count()); |
| 185 } | 187 } |
| 186 | 188 |
| 187 // Test that controls get repositioned when there are two warnings vs one | 189 // Test that controls get repositioned when there are two warnings vs one |
| 188 // warning. | 190 // warning. |
| 189 TEST_F(ExtensionInstallDialogControllerTest, MultipleWarnings) { | 191 TEST_F(ExtensionInstallDialogControllerTest, MultipleWarnings) { |
| 190 MockExtensionInstallUIDelegate delegate1; | 192 MockExtensionInstallPromptDelegate delegate1; |
| 191 MockExtensionInstallUIDelegate delegate2; | 193 MockExtensionInstallPromptDelegate delegate2; |
| 192 | 194 |
| 193 ExtensionInstallUI::Prompt one_warning_prompt( | 195 ExtensionInstallPrompt::Prompt one_warning_prompt( |
| 194 ExtensionInstallUI::INSTALL_PROMPT); | 196 ExtensionInstallPrompt::INSTALL_PROMPT); |
| 195 std::vector<string16> permissions; | 197 std::vector<string16> permissions; |
| 196 permissions.push_back(UTF8ToUTF16("warning 1")); | 198 permissions.push_back(UTF8ToUTF16("warning 1")); |
| 197 one_warning_prompt.SetPermissions(permissions); | 199 one_warning_prompt.SetPermissions(permissions); |
| 198 one_warning_prompt.set_extension(extension_.get()); | 200 one_warning_prompt.set_extension(extension_.get()); |
| 199 one_warning_prompt.set_icon(icon_); | 201 one_warning_prompt.set_icon(icon_); |
| 200 | 202 |
| 201 ExtensionInstallUI::Prompt two_warnings_prompt( | 203 ExtensionInstallPrompt::Prompt two_warnings_prompt( |
| 202 ExtensionInstallUI::INSTALL_PROMPT); | 204 ExtensionInstallPrompt::INSTALL_PROMPT); |
| 203 permissions.push_back(UTF8ToUTF16("warning 2")); | 205 permissions.push_back(UTF8ToUTF16("warning 2")); |
| 204 two_warnings_prompt.SetPermissions(permissions); | 206 two_warnings_prompt.SetPermissions(permissions); |
| 205 two_warnings_prompt.set_extension(extension_.get()); | 207 two_warnings_prompt.set_extension(extension_.get()); |
| 206 two_warnings_prompt.set_icon(icon_); | 208 two_warnings_prompt.set_icon(icon_); |
| 207 | 209 |
| 208 scoped_nsobject<ExtensionInstallDialogController> | 210 scoped_nsobject<ExtensionInstallDialogController> |
| 209 controller1([[ExtensionInstallDialogController alloc] | 211 controller1([[ExtensionInstallDialogController alloc] |
| 210 initWithParentWindow:test_window() | 212 initWithParentWindow:test_window() |
| 211 profile:profile() | 213 profile:profile() |
| 212 delegate:&delegate1 | 214 delegate:&delegate1 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 235 ASSERT_LT([[controller1 subtitleField] frame].origin.y, | 237 ASSERT_LT([[controller1 subtitleField] frame].origin.y, |
| 236 [[controller2 subtitleField] frame].origin.y); | 238 [[controller2 subtitleField] frame].origin.y); |
| 237 | 239 |
| 238 ASSERT_LT([[controller1 titleField] frame].origin.y, | 240 ASSERT_LT([[controller1 titleField] frame].origin.y, |
| 239 [[controller2 titleField] frame].origin.y); | 241 [[controller2 titleField] frame].origin.y); |
| 240 } | 242 } |
| 241 | 243 |
| 242 // Test that we can load the skinny prompt correctly, and that the outlets are | 244 // Test that we can load the skinny prompt correctly, and that the outlets are |
| 243 // are hooked up. | 245 // are hooked up. |
| 244 TEST_F(ExtensionInstallDialogControllerTest, BasicsSkinny) { | 246 TEST_F(ExtensionInstallDialogControllerTest, BasicsSkinny) { |
| 245 MockExtensionInstallUIDelegate delegate; | 247 MockExtensionInstallPromptDelegate delegate; |
| 246 | 248 |
| 247 // No warnings should trigger skinny prompt. | 249 // No warnings should trigger skinny prompt. |
| 248 ExtensionInstallUI::Prompt no_warnings_prompt( | 250 ExtensionInstallPrompt::Prompt no_warnings_prompt( |
| 249 ExtensionInstallUI::INSTALL_PROMPT); | 251 ExtensionInstallPrompt::INSTALL_PROMPT); |
| 250 no_warnings_prompt.set_extension(extension_.get()); | 252 no_warnings_prompt.set_extension(extension_.get()); |
| 251 no_warnings_prompt.set_icon(icon_); | 253 no_warnings_prompt.set_icon(icon_); |
| 252 | 254 |
| 253 scoped_nsobject<ExtensionInstallDialogController> | 255 scoped_nsobject<ExtensionInstallDialogController> |
| 254 controller([[ExtensionInstallDialogController alloc] | 256 controller([[ExtensionInstallDialogController alloc] |
| 255 initWithParentWindow:test_window() | 257 initWithParentWindow:test_window() |
| 256 profile:profile() | 258 profile:profile() |
| 257 delegate:&delegate | 259 delegate:&delegate |
| 258 prompt:no_warnings_prompt]); | 260 prompt:no_warnings_prompt]); |
| 259 | 261 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 280 EXPECT_NE('^', [[[controller okButton] stringValue] characterAtIndex:0]); | 282 EXPECT_NE('^', [[[controller okButton] stringValue] characterAtIndex:0]); |
| 281 | 283 |
| 282 EXPECT_TRUE([controller subtitleField] == nil); | 284 EXPECT_TRUE([controller subtitleField] == nil); |
| 283 EXPECT_TRUE([controller warningsField] == nil); | 285 EXPECT_TRUE([controller warningsField] == nil); |
| 284 } | 286 } |
| 285 | 287 |
| 286 | 288 |
| 287 // Test that we can load the inline prompt correctly, and that the outlets are | 289 // Test that we can load the inline prompt correctly, and that the outlets are |
| 288 // are hooked up. | 290 // are hooked up. |
| 289 TEST_F(ExtensionInstallDialogControllerTest, BasicsInline) { | 291 TEST_F(ExtensionInstallDialogControllerTest, BasicsInline) { |
| 290 MockExtensionInstallUIDelegate delegate; | 292 MockExtensionInstallPromptDelegate delegate; |
| 291 | 293 |
| 292 // No warnings should trigger skinny prompt. | 294 // No warnings should trigger skinny prompt. |
| 293 ExtensionInstallUI::Prompt inline_prompt( | 295 ExtensionInstallPrompt::Prompt inline_prompt( |
| 294 ExtensionInstallUI::INLINE_INSTALL_PROMPT); | 296 ExtensionInstallPrompt::INLINE_INSTALL_PROMPT); |
| 295 inline_prompt.SetInlineInstallWebstoreData("1,000", 3.5, 200); | 297 inline_prompt.SetInlineInstallWebstoreData("1,000", 3.5, 200); |
| 296 inline_prompt.set_extension(extension_.get()); | 298 inline_prompt.set_extension(extension_.get()); |
| 297 inline_prompt.set_icon(icon_); | 299 inline_prompt.set_icon(icon_); |
| 298 | 300 |
| 299 scoped_nsobject<ExtensionInstallDialogController> | 301 scoped_nsobject<ExtensionInstallDialogController> |
| 300 controller([[ExtensionInstallDialogController alloc] | 302 controller([[ExtensionInstallDialogController alloc] |
| 301 initWithParentWindow:test_window() | 303 initWithParentWindow:test_window() |
| 302 profile:profile() | 304 profile:profile() |
| 303 delegate:&delegate | 305 delegate:&delegate |
| 304 prompt:inline_prompt]); | 306 prompt:inline_prompt]); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 334 | 336 |
| 335 // Though we have no permissions warnings, these should still be hooked up, | 337 // Though we have no permissions warnings, these should still be hooked up, |
| 336 // just invisible. | 338 // just invisible. |
| 337 EXPECT_TRUE([controller subtitleField] != nil); | 339 EXPECT_TRUE([controller subtitleField] != nil); |
| 338 EXPECT_TRUE([[controller subtitleField] isHidden]); | 340 EXPECT_TRUE([[controller subtitleField] isHidden]); |
| 339 EXPECT_TRUE([controller warningsField] != nil); | 341 EXPECT_TRUE([controller warningsField] != nil); |
| 340 EXPECT_TRUE([[controller warningsField] isHidden]); | 342 EXPECT_TRUE([[controller warningsField] isHidden]); |
| 341 EXPECT_TRUE([controller warningsSeparator] != nil); | 343 EXPECT_TRUE([controller warningsSeparator] != nil); |
| 342 EXPECT_TRUE([[controller warningsSeparator] isHidden]); | 344 EXPECT_TRUE([[controller warningsSeparator] isHidden]); |
| 343 } | 345 } |
| OLD | NEW |