Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ui/cocoa/page_info/website_settings_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/page_info/website_settings_bubble_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 @end | 23 @end |
| 24 | 24 |
| 25 @implementation WebsiteSettingsBubbleController (ExposedForTesting) | 25 @implementation WebsiteSettingsBubbleController (ExposedForTesting) |
| 26 - (NSView*)permissionsView { | 26 - (NSView*)permissionsView { |
| 27 return permissionsView_; | 27 return permissionsView_; |
| 28 } | 28 } |
| 29 - (NSButton*)resetDecisionsButton { | 29 - (NSButton*)resetDecisionsButton { |
| 30 return resetDecisionsButton_; | 30 return resetDecisionsButton_; |
| 31 } | 31 } |
| 32 - (NSButton*)connectionHelpButton { | 32 - (NSButton*)connectionHelpButton { |
| 33 | |
| 34 return connectionHelpButton_; | 33 return connectionHelpButton_; |
| 35 } | 34 } |
| 36 @end | 35 @end |
| 37 | 36 |
| 38 @interface WebsiteSettingsBubbleControllerForTesting | 37 @interface WebsiteSettingsBubbleControllerForTesting |
| 39 : WebsiteSettingsBubbleController { | 38 : WebsiteSettingsBubbleController { |
| 40 @private | 39 @private |
| 41 CGFloat defaultWindowWidth_; | 40 CGFloat defaultWindowWidth_; |
| 42 } | 41 } |
| 43 @end | 42 @end |
| 44 | 43 |
| 45 @implementation WebsiteSettingsBubbleControllerForTesting | 44 @implementation WebsiteSettingsBubbleControllerForTesting |
| 46 - (void)setDefaultWindowWidth:(CGFloat)width { | 45 - (void)setDefaultWindowWidth:(CGFloat)width { |
| 47 defaultWindowWidth_ = width; | 46 defaultWindowWidth_ = width; |
| 48 } | 47 } |
| 49 - (CGFloat)defaultWindowWidth { | 48 - (CGFloat)defaultWindowWidth { |
| 50 // If |defaultWindowWidth_| is 0, use the superclass implementation. | 49 // If |defaultWindowWidth_| is 0, use the superclass implementation. |
| 51 return defaultWindowWidth_ ? | 50 return defaultWindowWidth_ ? defaultWindowWidth_ : [super defaultWindowWidth]; |
| 52 defaultWindowWidth_ : [super defaultWindowWidth]; | |
| 53 } | 51 } |
| 54 @end | 52 @end |
| 55 | 53 |
| 56 namespace { | 54 namespace { |
| 57 | 55 |
| 58 // Indices of the menu items in the permission menu. | 56 // Indices of the menu items in the permission menu. |
| 59 enum PermissionMenuIndices { | 57 enum PermissionMenuIndices { |
| 60 kMenuIndexContentSettingAllow = 0, | 58 kMenuIndexContentSettingAllow = 0, |
| 61 kMenuIndexContentSettingBlock, | 59 kMenuIndexContentSettingBlock, |
| 62 kMenuIndexContentSettingDefault | 60 kMenuIndexContentSettingDefault |
| 63 }; | 61 }; |
| 64 | 62 |
| 65 const ContentSettingsType kTestPermissionTypes[] = { | 63 const ContentSettingsType kTestPermissionTypes[] = { |
| 66 CONTENT_SETTINGS_TYPE_IMAGES, | 64 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
|
estark
2017/03/20 20:09:58
This looks really weird... but I guess that's how
| |
| 67 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 65 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTINGS_TYPE_POPUPS, |
| 68 CONTENT_SETTINGS_TYPE_PLUGINS, | 66 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 69 CONTENT_SETTINGS_TYPE_POPUPS, | 67 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC}; |
| 70 CONTENT_SETTINGS_TYPE_GEOLOCATION, | |
| 71 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
| 72 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC | |
| 73 }; | |
| 74 | 68 |
| 75 const ContentSetting kTestSettings[] = { | 69 const ContentSetting kTestSettings[] = { |
| 76 CONTENT_SETTING_DEFAULT, | 70 CONTENT_SETTING_DEFAULT, CONTENT_SETTING_DEFAULT, CONTENT_SETTING_ALLOW, |
| 77 CONTENT_SETTING_DEFAULT, | 71 CONTENT_SETTING_BLOCK, CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK, |
| 78 CONTENT_SETTING_ALLOW, | 72 CONTENT_SETTING_BLOCK}; |
| 79 CONTENT_SETTING_BLOCK, | |
| 80 CONTENT_SETTING_ALLOW, | |
| 81 CONTENT_SETTING_BLOCK, | |
| 82 CONTENT_SETTING_BLOCK | |
| 83 }; | |
| 84 | 73 |
| 85 const ContentSetting kTestDefaultSettings[] = { | 74 const ContentSetting kTestDefaultSettings[] = {CONTENT_SETTING_BLOCK, |
| 86 CONTENT_SETTING_BLOCK, | 75 CONTENT_SETTING_ASK}; |
| 87 CONTENT_SETTING_ASK | |
| 88 }; | |
| 89 | 76 |
| 90 const content_settings::SettingSource kTestSettingSources[] = { | 77 const content_settings::SettingSource kTestSettingSources[] = { |
| 91 content_settings::SETTING_SOURCE_USER, | 78 content_settings::SETTING_SOURCE_USER, |
| 92 content_settings::SETTING_SOURCE_USER, | 79 content_settings::SETTING_SOURCE_USER, |
| 93 content_settings::SETTING_SOURCE_USER, | 80 content_settings::SETTING_SOURCE_USER, |
| 94 content_settings::SETTING_SOURCE_USER, | 81 content_settings::SETTING_SOURCE_USER, |
| 95 content_settings::SETTING_SOURCE_POLICY, | 82 content_settings::SETTING_SOURCE_POLICY, |
| 96 content_settings::SETTING_SOURCE_POLICY, | 83 content_settings::SETTING_SOURCE_POLICY, |
| 97 content_settings::SETTING_SOURCE_EXTENSION | 84 content_settings::SETTING_SOURCE_EXTENSION}; |
| 98 }; | |
| 99 | 85 |
| 100 class WebsiteSettingsBubbleControllerTest : public CocoaTest { | 86 class WebsiteSettingsBubbleControllerTest : public CocoaTest { |
| 101 public: | 87 public: |
| 102 WebsiteSettingsBubbleControllerTest() { | 88 WebsiteSettingsBubbleControllerTest() { controller_ = nil; } |
| 103 controller_ = nil; | |
| 104 } | |
| 105 | 89 |
| 106 void TearDown() override { | 90 void TearDown() override { |
| 107 [controller_ close]; | 91 [controller_ close]; |
| 108 CocoaTest::TearDown(); | 92 CocoaTest::TearDown(); |
| 109 } | 93 } |
| 110 | 94 |
| 111 protected: | 95 protected: |
| 112 WebsiteSettingsUIBridge* bridge_; // Weak, owned by controller. | 96 WebsiteSettingsUIBridge* bridge_; // Weak, owned by controller. |
| 113 | 97 |
| 114 enum MatchType { | 98 enum MatchType { TEXT_EQUAL = 0, TEXT_NOT_EQUAL }; |
| 115 TEXT_EQUAL = 0, | |
| 116 TEXT_NOT_EQUAL | |
| 117 }; | |
| 118 | 99 |
| 119 // Creates a new website settings bubble, with the given default width. | 100 // Creates a new website settings bubble, with the given default width. |
| 120 // If |default_width| is 0, the *default* default width will be used. | 101 // If |default_width| is 0, the *default* default width will be used. |
| 121 void CreateBubbleWithWidth(CGFloat default_width) { | 102 void CreateBubbleWithWidth(CGFloat default_width) { |
| 122 bridge_ = new WebsiteSettingsUIBridge(nullptr); | 103 bridge_ = new WebsiteSettingsUIBridge(nullptr); |
| 123 | 104 |
| 124 // The controller cleans up after itself when the window closes. | 105 // The controller cleans up after itself when the window closes. |
| 125 controller_ = [WebsiteSettingsBubbleControllerForTesting alloc]; | 106 controller_ = [WebsiteSettingsBubbleControllerForTesting alloc]; |
| 126 [controller_ setDefaultWindowWidth:default_width]; | 107 [controller_ setDefaultWindowWidth:default_width]; |
| 127 [controller_ initWithParentWindow:test_window() | 108 [controller_ initWithParentWindow:test_window() |
| 128 websiteSettingsUIBridge:bridge_ | 109 websiteSettingsUIBridge:bridge_ |
| 129 webContents:web_contents_factory_.CreateWebContents( | 110 webContents:web_contents_factory_.CreateWebContents( |
| 130 &profile_) | 111 &profile_) |
| 131 url:GURL("https://www.google.com")]; | 112 url:GURL("https://www.google.com")]; |
| 132 window_ = [controller_ window]; | 113 window_ = [controller_ window]; |
| 133 [controller_ showWindow:nil]; | 114 [controller_ showWindow:nil]; |
| 134 } | 115 } |
| 135 | 116 |
| 136 void CreateBubble() { | 117 void CreateBubble() { CreateBubbleWithWidth(0.0); } |
| 137 CreateBubbleWithWidth(0.0); | |
| 138 } | |
| 139 | 118 |
| 140 // Return a pointer to the first NSTextField found that either matches, or | 119 // Return a pointer to the first NSTextField found that either matches, or |
| 141 // doesn't match, the given text. | 120 // doesn't match, the given text. |
| 142 NSTextField* FindTextField(MatchType match_type, NSString* text) { | 121 NSTextField* FindTextField(MatchType match_type, NSString* text) { |
| 143 // The window's only immediate child is an invisible view that has a flipped | 122 // The window's only immediate child is an invisible view that has a flipped |
| 144 // coordinate origin. It is into this that all views get placed. | 123 // coordinate origin. It is into this that all views get placed. |
| 145 NSArray* window_subviews = [[window_ contentView] subviews]; | 124 NSArray* window_subviews = [[window_ contentView] subviews]; |
| 146 EXPECT_EQ(1U, [window_subviews count]); | 125 EXPECT_EQ(1U, [window_subviews count]); |
| 147 NSArray* bubble_subviews = [[window_subviews lastObject] subviews]; | 126 NSArray* bubble_subviews = [[window_subviews lastObject] subviews]; |
| 148 NSArray* security_section_subviews = | 127 NSArray* security_section_subviews = |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 // when we set an identity with `show_ssl_decision_revoke_button == false` | 226 // when we set an identity with `show_ssl_decision_revoke_button == false` |
| 248 // again. | 227 // again. |
| 249 } | 228 } |
| 250 | 229 |
| 251 TEST_F(WebsiteSettingsBubbleControllerTest, SetPermissionInfo) { | 230 TEST_F(WebsiteSettingsBubbleControllerTest, SetPermissionInfo) { |
| 252 CreateBubble(); | 231 CreateBubble(); |
| 253 SetTestPermissions(); | 232 SetTestPermissions(); |
| 254 | 233 |
| 255 // There should be three subviews per permission. | 234 // There should be three subviews per permission. |
| 256 NSArray* subviews = [[controller_ permissionsView] subviews]; | 235 NSArray* subviews = [[controller_ permissionsView] subviews]; |
| 257 EXPECT_EQ(arraysize(kTestPermissionTypes) * 3 , [subviews count]); | 236 EXPECT_EQ(arraysize(kTestPermissionTypes) * 3, [subviews count]); |
| 258 | 237 |
| 259 // Ensure that there is a distinct label for each permission. | 238 // Ensure that there is a distinct label for each permission. |
| 260 NSMutableSet* labels = [NSMutableSet set]; | 239 NSMutableSet* labels = [NSMutableSet set]; |
| 261 for (NSView* view in subviews) { | 240 for (NSView* view in subviews) { |
| 262 if ([view isKindOfClass:[NSTextField class]]) | 241 if ([view isKindOfClass:[NSTextField class]]) |
| 263 [labels addObject:[static_cast<NSTextField*>(view) stringValue]]; | 242 [labels addObject:[static_cast<NSTextField*>(view) stringValue]]; |
| 264 } | 243 } |
| 265 EXPECT_EQ(arraysize(kTestPermissionTypes), [labels count]); | 244 EXPECT_EQ(arraysize(kTestPermissionTypes), [labels count]); |
| 266 | 245 |
| 267 // Ensure that the button labels are distinct, and look for the correct | 246 // Ensure that the button labels are distinct, and look for the correct |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 } | 294 } |
| 316 if ([view isKindOfClass:[NSPopUpButton class]]) { | 295 if ([view isKindOfClass:[NSPopUpButton class]]) { |
| 317 NSPopUpButton* button = static_cast<NSPopUpButton*>(view); | 296 NSPopUpButton* button = static_cast<NSPopUpButton*>(view); |
| 318 EXPECT_LT(NSMaxX([button frame]), window_width); | 297 EXPECT_LT(NSMaxX([button frame]), window_width); |
| 319 } | 298 } |
| 320 } | 299 } |
| 321 } | 300 } |
| 322 } | 301 } |
| 323 | 302 |
| 324 } // namespace | 303 } // namespace |
| OLD | NEW |