diff options
author | dubroy@chromium.org <dubroy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-27 17:22:27 +0000 |
---|---|---|
committer | dubroy@chromium.org <dubroy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-27 17:22:27 +0000 |
commit | b2b50c7c6aa33b38880dd05983173e69edad197b (patch) | |
tree | 63f64424dec448a4f724493538008111c51ebb74 | |
parent | dfa51e3c590f71af8cc6170f18490825a35b0047 (diff) | |
download | chromium_src-b2b50c7c6aa33b38880dd05983173e69edad197b.zip chromium_src-b2b50c7c6aa33b38880dd05983173e69edad197b.tar.gz chromium_src-b2b50c7c6aa33b38880dd05983173e69edad197b.tar.bz2 |
[Mac] Website settings: Enlarge window when permission strings are too long.
The website settings window was using a fixed width. This was fine for most
text since it would wrap, but the permissions can't wrap, so the window should
be made wide enough to fit the largest permission string.
BUG=159156
Review URL: https://codereview.chromium.org/11417082
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169678 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 226 insertions, 122 deletions
diff --git a/chrome/browser/ui/cocoa/website_settings_bubble_controller.h b/chrome/browser/ui/cocoa/website_settings_bubble_controller.h index ae0357a..235e2df 100644 --- a/chrome/browser/ui/cocoa/website_settings_bubble_controller.h +++ b/chrome/browser/ui/cocoa/website_settings_bubble_controller.h @@ -87,7 +87,9 @@ class WebContents; webContents:(content::WebContents*)webContents isInternalPage:(BOOL)isInternalPage; -- (void)permissionValueChanged:(id)sender; +// Return the default width of the window. It may be wider to fit the content. +// This may be overriden by a subclass for testing purposes. +- (CGFloat)defaultWindowWidth; @end diff --git a/chrome/browser/ui/cocoa/website_settings_bubble_controller.mm b/chrome/browser/ui/cocoa/website_settings_bubble_controller.mm index 240f62a..9bbfbc1 100644 --- a/chrome/browser/ui/cocoa/website_settings_bubble_controller.mm +++ b/chrome/browser/ui/cocoa/website_settings_bubble_controller.mm @@ -36,9 +36,9 @@ namespace { -// The width of the window, in view coordinates. The height will be determined -// by the content. -const CGFloat kWindowWidth = 310; +// The default width of the window, in view coordinates. It may be larger to +// fit the content. +const CGFloat kDefaultWindowWidth = 310; // Spacing in between sections. const CGFloat kVerticalSpacing = 10; @@ -83,6 +83,10 @@ const CGFloat kPermissionsHeadlineSpacing = 2; // The amount of horizontal space between a permission label and the popup. const CGFloat kPermissionPopUpXSpacing = 3; +// The amount of horizontal space between the permission popup title and the +// arrow icon. +const CGFloat kPermissionButtonTitleRightPadding = 4; + // The extra space to the left of the first tab in the tab strip. const CGFloat kTabStripXPadding = kFramePadding; @@ -199,7 +203,7 @@ NSColor* IdentityVerifiedTextColor() { // Draw the background to the right of the selected tab. backgroundRect.origin.x = NSMaxX(tabRect); - backgroundRect.size.width = kWindowWidth - NSMaxX(tabRect); + backgroundRect.size.width = NSMaxX(cellFrame) - NSMaxX(tabRect); NSDrawThreePartImage(backgroundRect, tabstripRightImage_, tabstripCenterImage_, @@ -284,6 +288,10 @@ NSColor* IdentityVerifiedTextColor() { @implementation WebsiteSettingsBubbleController +- (CGFloat)defaultWindowWidth { + return kDefaultWindowWidth; +} + - (id)initWithParentWindow:(NSWindow*)parentWindow websiteSettingsUIBridge:(WebsiteSettingsUIBridge*)bridge webContents:(content::WebContents*)webContents @@ -293,7 +301,7 @@ NSColor* IdentityVerifiedTextColor() { webContents_ = webContents; // Use an arbitrary height; it will be changed in performLayout. - NSRect contentRect = NSMakeRect(0, 0, kWindowWidth, 1); + NSRect contentRect = NSMakeRect(0, 0, [self defaultWindowWidth], 1); // Create an empty window into which content is placed. scoped_nsobject<InfoBubbleWindow> window( [[InfoBubbleWindow alloc] initWithContentRect:contentRect @@ -307,7 +315,7 @@ NSColor* IdentityVerifiedTextColor() { [[self bubble] setArrowLocation:info_bubble::kTopLeft]; // Create the container view that uses flipped coordinates. - NSRect contentFrame = NSMakeRect(0, 0, kWindowWidth, 300); + NSRect contentFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300); contentView_.reset( [[FlippedView alloc] initWithFrame:contentFrame]); @@ -365,7 +373,7 @@ NSColor* IdentityVerifiedTextColor() { // Adjust the contentView to fit everything. CGFloat maxY = std::max(NSMaxY([imageView frame]), NSMaxY(textFrame)); [contentView_ setFrame:NSMakeRect( - 0, 0, kWindowWidth, maxY + kInternalPageFramePadding)]; + 0, 0, [self defaultWindowWidth], maxY + kInternalPageFramePadding)]; [self sizeAndPositionWindow]; } @@ -398,13 +406,15 @@ NSColor* IdentityVerifiedTextColor() { scoped_nsobject<WebsiteSettingsTabSegmentedCell> cell( [[WebsiteSettingsTabSegmentedCell alloc] init]); CGFloat tabstripHeight = [cell cellSize].height; - NSRect tabstripFrame = NSMakeRect(0, 0, kWindowWidth, tabstripHeight); + NSRect tabstripFrame = NSMakeRect( + 0, 0, [self defaultWindowWidth], tabstripHeight); segmentedControl_.reset( [[NSSegmentedControl alloc] initWithFrame:tabstripFrame]); [segmentedControl_ setCell:cell]; [segmentedControl_ setSegmentCount:WebsiteSettingsUI::NUM_TAB_IDS]; [segmentedControl_ setTarget:self]; [segmentedControl_ setAction:@selector(tabSelected:)]; + [segmentedControl_ setAutoresizingMask:NSViewWidthSizable]; NSFont* smallSystemFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; @@ -443,7 +453,7 @@ NSColor* IdentityVerifiedTextColor() { [segmentedControl_ setFont:smallSystemFont]; [contentView_ addSubview:segmentedControl_]; - NSRect tabFrame = NSMakeRect(0, 0, kWindowWidth, 300); + NSRect tabFrame = NSMakeRect(0, 0, [self defaultWindowWidth], 300); tabView_.reset([[NSTabView alloc] initWithFrame:tabFrame]); [tabView_ setTabViewType:NSNoTabsNoBorder]; [tabView_ setDrawsBackground:NO]; @@ -465,12 +475,15 @@ NSColor* IdentityVerifiedTextColor() { atIndex:WebsiteSettingsUI::TAB_ID_PERMISSIONS]; scoped_nsobject<NSView> contentView([[FlippedView alloc] initWithFrame:[tabView_ contentRect]]); + [contentView setAutoresizingMask:NSViewWidthSizable]; [item setView:contentView.get()]; // Initialize the two containers that hold the controls. The initial frames // are arbitrary, and will be adjusted after the controls are laid out. cookiesView_ = [[[FlippedView alloc] initWithFrame:[tabView_ contentRect]] autorelease]; + [cookiesView_ setAutoresizingMask:NSViewWidthSizable]; + permissionsView_ = [[[FlippedView alloc] initWithFrame:[tabView_ contentRect]] autorelease]; @@ -521,6 +534,7 @@ NSColor* IdentityVerifiedTextColor() { scoped_nsobject<NSTabViewItem> item([[NSTabViewItem alloc] init]); scoped_nsobject<NSView> contentView([[FlippedView alloc] initWithFrame:[tabView_ contentRect]]); + [contentView setAutoresizingMask:NSViewWidthSizable]; // Place all the text and images at the same position. The positions will be // adjusted in performLayout. @@ -539,7 +553,9 @@ NSColor* IdentityVerifiedTextColor() { bold:NO toView:contentView.get() atPoint:textPosition]; + separatorAfterIdentity_ = [self addSeparatorToView:contentView]; + [separatorAfterIdentity_ setAutoresizingMask:NSViewWidthSizable]; connectionStatusIcon_ = [self addImageWithSize:imageSize toView:contentView @@ -552,6 +568,7 @@ NSColor* IdentityVerifiedTextColor() { atPoint:textPosition]; certificateInfoButton_ = nil; // This will be created only if necessary. separatorAfterConnection_ = [self addSeparatorToView:contentView]; + [separatorAfterConnection_ setAutoresizingMask:NSViewWidthSizable]; firstVisitIcon_ = [self addImageWithSize:imageSize toView:contentView @@ -570,6 +587,8 @@ NSColor* IdentityVerifiedTextColor() { atPoint:textPosition]; separatorAfterFirstVisit_ = [self addSeparatorToView:contentView]; + [separatorAfterFirstVisit_ setAutoresizingMask:NSViewWidthSizable]; + NSString* helpButtonText = l10n_util::GetNSString( IDS_PAGE_INFO_HELP_CENTER_LINK); helpButton_ = [self addLinkButtonWithText:helpButtonText @@ -593,9 +612,25 @@ NSColor* IdentityVerifiedTextColor() { return position + NSHeight(frame); } +- (void)setWidthOfView:(NSView*)view to:(CGFloat)width { + [view setFrameSize:NSMakeSize(width, NSHeight([view frame]))]; +} + // Layout all of the controls in the window. This should be called whenever // the content has changed. - (void)performLayout { + // Make the content at least as wide as the permissions view. + CGFloat contentWidth = std::max([self defaultWindowWidth], + NSWidth([permissionsView_ frame])); + + // Set the width of the content view now, so that all the text fields will + // be sized to fit before their heights and vertical positions are adjusted. + // The tab view will only resize the currently selected tab, so resize both + // tab content views manually. + [self setWidthOfView:contentView_ to:contentWidth]; + [self setWidthOfView:permissionsTabContentView_ to:contentWidth]; + [self setWidthOfView:connectionTabContentView_ to:contentWidth]; + // Place the identity status immediately below the identity. [self sizeTextFieldHeightToFit:identityField_]; [self sizeTextFieldHeightToFit:identityStatusField_]; @@ -603,6 +638,7 @@ NSColor* IdentityVerifiedTextColor() { yPos = [self setYPositionOfView:identityStatusField_ to:yPos]; // Lay out the Permissions tab. + yPos = [self setYPositionOfView:cookiesView_ to:kFramePadding]; // Put the link button for cookies and site data just below the cookie info. @@ -660,26 +696,18 @@ NSColor* IdentityVerifiedTextColor() { yPos = NSMaxY([identityStatusField_ frame]) + kTabStripTopSpacing; yPos = [self setYPositionOfView:segmentedControl_ to:yPos]; + CGFloat connectionTabHeight = NSMaxY([helpButton_ frame]) + kVerticalSpacing; + NSRect tabViewFrame = [tabView_ frame]; tabViewFrame.origin.y = yPos; - - // Determine the height of the tab contents. - - CGFloat connectionTabHeight = std::max( - NSMaxY([firstVisitDescriptionField_ frame]), - NSMaxY([firstVisitIcon_ frame ])); - connectionTabHeight += kVerticalSpacing; - - CGFloat permissionsTabHeight = NSMaxY([permissionsView_ frame]); - CGFloat tabContentHeight = std::max(connectionTabHeight, - permissionsTabHeight); - tabViewFrame.size.height = tabContentHeight + - NSHeight(tabViewFrame) - NSHeight([tabView_ contentRect]); + tabViewFrame.size.height = + std::max(connectionTabHeight, NSMaxY([permissionsView_ frame])); + tabViewFrame.size.width = contentWidth; [tabView_ setFrame:tabViewFrame]; // Adjust the contentView to fit everything. [contentView_ setFrame:NSMakeRect( - 0, 0, kWindowWidth, NSMaxY([tabView_ frame]))]; + 0, 0, NSWidth(tabViewFrame), NSMaxY(tabViewFrame))]; [self sizeAndPositionWindow]; } @@ -687,8 +715,7 @@ NSColor* IdentityVerifiedTextColor() { // Adjust the size of the window to match the size of the content, and position // the bubble anchor appropriately. - (void)sizeAndPositionWindow { - NSRect windowFrame = - NSMakeRect(0, 0, kWindowWidth, NSHeight([contentView_ frame])); + NSRect windowFrame = [contentView_ frame]; windowFrame.size = [[[self window] contentView] convertSize:windowFrame.size toView:nil]; // Adjust the origin by the difference in height. @@ -763,6 +790,7 @@ NSColor* IdentityVerifiedTextColor() { : [NSFont systemFontOfSize:fontSize]; [textField setFont:font]; [self sizeTextFieldHeightToFit:textField]; + [textField setAutoresizingMask:NSViewWidthSizable]; [view addSubview:textField.get()]; return textField.get(); } @@ -805,11 +833,26 @@ NSColor* IdentityVerifiedTextColor() { [button setBezelStyle:NSRegularSquareBezelStyle]; [view addSubview:button.get()]; - // Call size-to-fit to fixup for the localized string. [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()]; return button.get(); } +// Determine the size of a popup button with the given title. +- (NSSize)sizeForPopUpButton:(NSPopUpButton*)button + withTitle:(NSString*)title { + NSDictionary* textAttributes = + [NSDictionary dictionaryWithObject:[button font] + forKey:NSFontAttributeName]; + NSSize titleSize = [title sizeWithAttributes:textAttributes]; + + NSRect buttonFrame = [button frame]; + NSRect titleRect = [[button cell] titleRectForBounds:buttonFrame]; + CGFloat width = titleSize.width + NSWidth(buttonFrame) - NSWidth(titleRect); + + return NSMakeSize(width + kPermissionButtonTitleRightPadding, + NSHeight(buttonFrame)); +} + // Add a pop-up button for |permissionInfo| to the given view. - (NSPopUpButton*)addPopUpButtonForPermission: (const WebsiteSettingsUI::PermissionInfo&)permissionInfo @@ -863,21 +906,27 @@ NSColor* IdentityVerifiedTextColor() { [[button cell] setMenuItem:titleItem.get()]; [button sizeToFit]; - // Determine the size of the title, and size the control accordingly. - // Using |sizeToFit| results in way too much extra space after the text. - NSDictionary* textAttributes = - [NSDictionary dictionaryWithObject:[button font] - forKey:NSFontAttributeName]; - NSSize titleSize = [[button title] sizeWithAttributes:textAttributes]; + // Determine the largest possible size for this button. + CGFloat maxTitleWidth = 0; + for (NSInteger i = 0; i < [button numberOfItems]; ++i) { + string16 title = WebsiteSettingsUI::PermissionActionToUIString( + static_cast<ContentSetting>([[button itemAtIndex:i] tag]), + permissionInfo.default_setting, + content_settings::SETTING_SOURCE_USER); + NSSize size = [self sizeForPopUpButton:button + withTitle:base::SysUTF16ToNSString(title)]; + maxTitleWidth = std::max(maxTitleWidth, size.width); + } + // Ensure the containing view is large enough to contain the button with its + // widest possible title. + NSRect containerFrame = [view frame]; + containerFrame.size.width = std::max( + NSWidth(containerFrame), point.x + maxTitleWidth + kFramePadding); + [view setFrame:containerFrame]; - // Adjust the button frame to have a titleRect that exactly fits the title. - NSRect buttonFrame = [button frame]; - NSRect titleRect = [[button cell] titleRectForBounds:buttonFrame]; - buttonFrame.size.width = - titleSize.width + NSWidth(buttonFrame) - NSWidth(titleRect); - [button setFrame:buttonFrame]; - DCHECK_EQ(NSWidth([[button cell] titleRectForBounds:buttonFrame]), - titleSize.width); + // Size the button to just fit the title. + [button setFrameSize:[self sizeForPopUpButton:button + withTitle:[button title]]]; [view addSubview:button.get()]; return button.get(); @@ -901,7 +950,7 @@ NSColor* IdentityVerifiedTextColor() { // Adds a new row to the UI listing the permissions. Returns the amount of // vertical space that was taken up by the row. -- (CGFloat)addPermission: +- (NSPoint)addPermission: (const WebsiteSettingsUI::PermissionInfo&)permissionInfo toView:(NSView*)view atPoint:(NSPoint)point { @@ -950,7 +999,8 @@ NSColor* IdentityVerifiedTextColor() { [button setEnabled:NO]; } - return NSHeight([label frame]); + NSRect buttonFrame = [button frame]; + return NSMakePoint(NSMaxX(buttonFrame), NSMaxY(buttonFrame)); } // Align an image with a text field by vertically centering the image on @@ -993,10 +1043,6 @@ NSColor* IdentityVerifiedTextColor() { toView:view atPoint:point]; - // Shrink the label to fit the text width. - NSSize requiredSize = [[label cell] cellSizeForBounds:[label frame]]; - [label setFrameSize:requiredSize]; - // Align the icon with the text. [self alignPermissionIcon:imageView withTextField:label]; @@ -1054,7 +1100,6 @@ NSColor* IdentityVerifiedTextColor() { bold:YES toView:cookiesView_ atPoint:controlOrigin]; - [self sizeTextFieldHeightToFit:header]; controlOrigin.y += NSHeight([header frame]) + kPermissionsHeadlineSpacing; for (CookieInfoList::const_iterator it = cookieInfoList.begin(); @@ -1068,11 +1113,18 @@ NSColor* IdentityVerifiedTextColor() { } controlOrigin.y += kPermissionsTabSpacing; - [cookiesView_ setFrameSize:NSMakeSize(kWindowWidth, controlOrigin.y)]; + [cookiesView_ setFrameSize: + NSMakeSize(NSWidth([cookiesView_ frame]), controlOrigin.y)]; + [self performLayout]; } - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList { + // The contents of the permissions view can cause the whole window to get + // bigger, but currently permissions are always set before cookie info. + // Check to make sure that's still the case. + DCHECK_EQ(0U, [[cookiesView_ subviews] count]); + [permissionsView_ setSubviews:[NSArray array]]; NSPoint controlOrigin = NSMakePoint(kFramePadding, 0); @@ -1091,13 +1143,15 @@ NSColor* IdentityVerifiedTextColor() { permission != permissionInfoList.end(); ++permission) { controlOrigin.y += kPermissionsTabSpacing; - CGFloat rowHeight = [self addPermission:*permission - toView:permissionsView_ - atPoint:controlOrigin]; - controlOrigin.y += rowHeight; + NSPoint rowBottomRight = [self addPermission:*permission + toView:permissionsView_ + atPoint:controlOrigin]; + controlOrigin.y = rowBottomRight.y; } controlOrigin.y += kFramePadding; - [permissionsView_ setFrameSize:NSMakeSize(kWindowWidth, controlOrigin.y)]; + [permissionsView_ setFrameSize: + NSMakeSize(NSWidth([permissionsView_ frame]), controlOrigin.y)]; + [self performLayout]; } - (void)setFirstVisit:(const string16&)firstVisit { diff --git a/chrome/browser/ui/cocoa/website_settings_bubble_controller_unittest.mm b/chrome/browser/ui/cocoa/website_settings_bubble_controller_unittest.mm index 84b7854..3534ae1 100644 --- a/chrome/browser/ui/cocoa/website_settings_bubble_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/website_settings_bubble_controller_unittest.mm @@ -61,6 +61,24 @@ } @end +@interface WebsiteSettingsBubbleControllerForTesting + : WebsiteSettingsBubbleController { + @private + CGFloat defaultWindowWidth_; +} +@end + +@implementation WebsiteSettingsBubbleControllerForTesting +- (void)setDefaultWindowWidth:(CGFloat)width { + defaultWindowWidth_ = width; +} +- (CGFloat)defaultWindowWidth { + // If |defaultWindowWidth_| is 0, use the superclass implementation. + return defaultWindowWidth_ ? + defaultWindowWidth_ : [super defaultWindowWidth]; +} +@end + namespace { // Indices of the menu items in the permission menu. @@ -70,6 +88,50 @@ enum PermissionMenuIndices { kMenuIndexContentSettingDefault }; +const ContentSettingsType kTestPermissionTypes[] = { + // NOTE: FULLSCREEN does not support "Always block", so it must appear as + // one of the first three permissions. + CONTENT_SETTINGS_TYPE_FULLSCREEN, + CONTENT_SETTINGS_TYPE_IMAGES, + CONTENT_SETTINGS_TYPE_JAVASCRIPT, + CONTENT_SETTINGS_TYPE_PLUGINS, + CONTENT_SETTINGS_TYPE_POPUPS, + CONTENT_SETTINGS_TYPE_GEOLOCATION, + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, + CONTENT_SETTINGS_TYPE_MOUSELOCK, + CONTENT_SETTINGS_TYPE_MEDIASTREAM, +}; + +const ContentSetting kTestSettings[] = { + CONTENT_SETTING_DEFAULT, + CONTENT_SETTING_DEFAULT, + CONTENT_SETTING_DEFAULT, + CONTENT_SETTING_ALLOW, + CONTENT_SETTING_BLOCK, + CONTENT_SETTING_ALLOW, + CONTENT_SETTING_BLOCK, + CONTENT_SETTING_ALLOW, + CONTENT_SETTING_BLOCK, +}; + +const ContentSetting kTestDefaultSettings[] = { + CONTENT_SETTING_ALLOW, + CONTENT_SETTING_BLOCK, + CONTENT_SETTING_ASK +}; + +const content_settings::SettingSource kTestSettingSources[] = { + content_settings::SETTING_SOURCE_USER, + content_settings::SETTING_SOURCE_USER, + content_settings::SETTING_SOURCE_USER, + content_settings::SETTING_SOURCE_USER, + content_settings::SETTING_SOURCE_USER, + content_settings::SETTING_SOURCE_POLICY, + content_settings::SETTING_SOURCE_POLICY, + content_settings::SETTING_SOURCE_EXTENSION, + content_settings::SETTING_SOURCE_EXTENSION, +}; + class WebsiteSettingsBubbleControllerTest : public CocoaTest { public: WebsiteSettingsBubbleControllerTest() { @@ -89,20 +151,26 @@ class WebsiteSettingsBubbleControllerTest : public CocoaTest { TEXT_NOT_EQUAL }; - void CreateBubble() { + // Creates a new website settings bubble, with the given default width. + // If |default_width| is 0, the *default* default width will be used. + void CreateBubbleWithWidth(CGFloat default_width) { bridge_ = new WebsiteSettingsUIBridge(); // The controller cleans up after itself when the window closes. - controller_ = - [[WebsiteSettingsBubbleController alloc] - initWithParentWindow:test_window() - websiteSettingsUIBridge:bridge_ - webContents:nil - isInternalPage:NO]; + controller_ = [WebsiteSettingsBubbleControllerForTesting alloc]; + [controller_ setDefaultWindowWidth:default_width]; + [controller_ initWithParentWindow:test_window() + websiteSettingsUIBridge:bridge_ + webContents:nil + isInternalPage:NO]; window_ = [controller_ window]; [controller_ showWindow:nil]; } + void CreateBubble() { + CreateBubbleWithWidth(0.0); + } + // Return a pointer to the first NSTextField found that either matches, or // doesn't match, the given text. NSTextField* FindTextField(MatchType match_type, NSString* text) { @@ -137,7 +205,26 @@ class WebsiteSettingsBubbleControllerTest : public CocoaTest { return views; } - WebsiteSettingsBubbleController* controller_; // Weak, owns self. + // Sets up the dialog with some test permission settings. + void SetTestPermissions() { + // Create a list of 5 different permissions, corresponding to all the + // possible settings: + // - [allow, block, ask] by default + // - [block, allow] * [by user, by policy, by extension] + PermissionInfoList list; + WebsiteSettingsUI::PermissionInfo info; + for (size_t i = 0; i < arraysize(kTestPermissionTypes); ++i) { + info.type = kTestPermissionTypes[i]; + info.setting = kTestSettings[i]; + if (info.setting == CONTENT_SETTING_DEFAULT) + info.default_setting = kTestDefaultSettings[i]; + info.source = kTestSettingSources[i]; + list.push_back(info); + } + bridge_->SetPermissionInfo(list); + } + + WebsiteSettingsBubbleControllerForTesting* controller_; // Weak, owns self. NSWindow* window_; // Weak, owned by controller. }; @@ -238,66 +325,7 @@ TEST_F(WebsiteSettingsBubbleControllerTest, SetFirstVisit) { TEST_F(WebsiteSettingsBubbleControllerTest, SetPermissionInfo) { CreateBubble(); - - const ContentSettingsType kTestPermissionTypes[] = { - // NOTE: FULLSCREEN does not support "Always block", so it must appear as - // one of the first three permissions. - CONTENT_SETTINGS_TYPE_FULLSCREEN, - CONTENT_SETTINGS_TYPE_IMAGES, - CONTENT_SETTINGS_TYPE_JAVASCRIPT, - CONTENT_SETTINGS_TYPE_PLUGINS, - CONTENT_SETTINGS_TYPE_POPUPS, - CONTENT_SETTINGS_TYPE_GEOLOCATION, - CONTENT_SETTINGS_TYPE_NOTIFICATIONS, - CONTENT_SETTINGS_TYPE_MOUSELOCK, - CONTENT_SETTINGS_TYPE_MEDIASTREAM, - }; - - const ContentSetting kTestSettings[] = { - CONTENT_SETTING_DEFAULT, - CONTENT_SETTING_DEFAULT, - CONTENT_SETTING_DEFAULT, - CONTENT_SETTING_ALLOW, - CONTENT_SETTING_BLOCK, - CONTENT_SETTING_ALLOW, - CONTENT_SETTING_BLOCK, - CONTENT_SETTING_ALLOW, - CONTENT_SETTING_BLOCK, - }; - - const ContentSetting kTestDefaultSettings[] = { - CONTENT_SETTING_ALLOW, - CONTENT_SETTING_BLOCK, - CONTENT_SETTING_ASK - }; - - const content_settings::SettingSource kTestSettingSources[] = { - content_settings::SETTING_SOURCE_USER, - content_settings::SETTING_SOURCE_USER, - content_settings::SETTING_SOURCE_USER, - content_settings::SETTING_SOURCE_USER, - content_settings::SETTING_SOURCE_USER, - content_settings::SETTING_SOURCE_POLICY, - content_settings::SETTING_SOURCE_POLICY, - content_settings::SETTING_SOURCE_EXTENSION, - content_settings::SETTING_SOURCE_EXTENSION, - }; - - // Create a list of 5 different permissions, corresponding to all the - // possible settings: - // - [allow, block, ask] by default - // - [block, allow] * [by user, by policy, by extension] - PermissionInfoList list; - WebsiteSettingsUI::PermissionInfo info; - for (size_t i = 0; i < arraysize(kTestPermissionTypes); ++i) { - info.type = kTestPermissionTypes[i]; - info.setting = kTestSettings[i]; - if (info.setting == CONTENT_SETTING_DEFAULT) - info.default_setting = kTestDefaultSettings[i]; - info.source = kTestSettingSources[i]; - list.push_back(info); - } - bridge_->SetPermissionInfo(list); + SetTestPermissions(); // There should be three subviews per permission (an icon, a label and a // select box), plus a text label for the Permission section. @@ -349,4 +377,24 @@ TEST_F(WebsiteSettingsBubbleControllerTest, SetSelectedTab) { EXPECT_EQ(1, [tabView indexOfTabViewItem:[tabView selectedTabViewItem]]); } +TEST_F(WebsiteSettingsBubbleControllerTest, WindowWidth) { + // Try creating a window that is obviously too small. + CreateBubbleWithWidth(30.0); + SetTestPermissions(); + + CGFloat window_width = NSWidth([[controller_ window] frame]); + + // Check the window was made bigger to fit the content. + EXPECT_LT(30.0, window_width); + + // Check that the window is wider than the right edge of all the permission + // popup buttons. + for (NSView* view in [[controller_ permissionsView] subviews]) { + if ([view isKindOfClass:[NSPopUpButton class]]) { + NSPopUpButton* button = static_cast<NSPopUpButton*>(view); + EXPECT_LT(NSMaxX([button frame]), window_width); + } + } +} + } // namespace |