Commit 563f19b6 authored by beaudoin@chromium.org's avatar beaudoin@chromium.org

On Mac, ensure messages displayed in the bookmark bar do not overlap with the Apps bookmark button.

BUG=230968
TEST=Lauch Chrome on Mac with instant extended. Ensure you have no bookmark. On the NTP observe that the "Apps" button does not overlap the empty bookmark bar message.

Review URL: https://codereview.chromium.org/14262013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194516 0039d316-1c4b-4281-b951-d872f2087c98
parent 9fa242b2
...@@ -382,7 +382,9 @@ willAnimateFromState:(BookmarkBar::State)oldState ...@@ -382,7 +382,9 @@ willAnimateFromState:(BookmarkBar::State)oldState
- (BookmarkBarView*)buttonView; - (BookmarkBarView*)buttonView;
- (NSMutableArray*)buttons; - (NSMutableArray*)buttons;
- (NSButton*)offTheSideButton; - (NSButton*)offTheSideButton;
- (NSButton*)appsPageShortcutButton;
- (BOOL)offTheSideButtonIsHidden; - (BOOL)offTheSideButtonIsHidden;
- (BOOL)appsPageShortcutButtonIsHidden;
- (BookmarkButton*)otherBookmarksButton; - (BookmarkButton*)otherBookmarksButton;
- (BookmarkBarFolderController*)folderController; - (BookmarkBarFolderController*)folderController;
- (id)folderTarget; - (id)folderTarget;
......
...@@ -1387,17 +1387,24 @@ void RecordAppLaunch(Profile* profile, GURL url) { ...@@ -1387,17 +1387,24 @@ void RecordAppLaunch(Profile* profile, GURL url) {
} }
// Adjust the horizontal width and the visibility of the "For quick access" // Adjust the horizontal width, x position and the visibility of the "For quick
// text field and "Import bookmarks..." button based on the current width // access" text field and "Import bookmarks..." button based on the current
// of the containing |buttonView_| (which is affected by window width). // width of the containing |buttonView_| (which is affected by window width).
- (void)adjustNoItemContainerWidthsForMaxX:(CGFloat)maxViewX { - (void)adjustNoItemContainerForMaxX:(CGFloat)maxViewX {
if (![[buttonView_ noItemContainer] isHidden]) { if (![[buttonView_ noItemContainer] isHidden]) {
// Reset initial frames for the two items, then adjust as necessary. // Reset initial frames for the two items, then adjust as necessary.
NSTextField* noItemTextfield = [buttonView_ noItemTextfield]; NSTextField* noItemTextfield = [buttonView_ noItemTextfield];
[noItemTextfield setFrame:originalNoItemsRect_]; NSRect noItemsRect = originalNoItemsRect_;
NSRect importBookmarksRect = originalImportBookmarksRect_;
if (![appsPageShortcutButton_ isHidden]) {
float width = NSWidth([appsPageShortcutButton_ frame]);
noItemsRect.origin.x += width;
importBookmarksRect.origin.x += width;
}
[noItemTextfield setFrame:noItemsRect];
[noItemTextfield setHidden:NO]; [noItemTextfield setHidden:NO];
NSButton* importBookmarksButton = [buttonView_ importBookmarksButton]; NSButton* importBookmarksButton = [buttonView_ importBookmarksButton];
[importBookmarksButton setFrame:originalImportBookmarksRect_]; [importBookmarksButton setFrame:importBookmarksRect];
[importBookmarksButton setHidden:NO]; [importBookmarksButton setHidden:NO];
// Check each to see if they need to be shrunk or hidden. // Check each to see if they need to be shrunk or hidden.
if ([self shrinkOrHideView:importBookmarksButton forMaxX:maxViewX]) if ([self shrinkOrHideView:importBookmarksButton forMaxX:maxViewX])
...@@ -1518,7 +1525,7 @@ void RecordAppLaunch(Profile* profile, GURL url) { ...@@ -1518,7 +1525,7 @@ void RecordAppLaunch(Profile* profile, GURL url) {
// While we're here, adjust the horizontal width and the visibility // While we're here, adjust the horizontal width and the visibility
// of the "For quick access" and "Import bookmarks..." text fields. // of the "For quick access" and "Import bookmarks..." text fields.
if (![buttons_ count]) if (![buttons_ count])
[self adjustNoItemContainerWidthsForMaxX:maxViewX]; [self adjustNoItemContainerForMaxX:maxViewX];
} }
#pragma mark Private Methods Exposed for Testing #pragma mark Private Methods Exposed for Testing
...@@ -1535,10 +1542,18 @@ void RecordAppLaunch(Profile* profile, GURL url) { ...@@ -1535,10 +1542,18 @@ void RecordAppLaunch(Profile* profile, GURL url) {
return offTheSideButton_; return offTheSideButton_;
} }
- (NSButton*)appsPageShortcutButton {
return appsPageShortcutButton_;
}
- (BOOL)offTheSideButtonIsHidden { - (BOOL)offTheSideButtonIsHidden {
return [offTheSideButton_ isHidden]; return [offTheSideButton_ isHidden];
} }
- (BOOL)appsPageShortcutButtonIsHidden {
return [appsPageShortcutButton_ isHidden];
}
- (BookmarkButton*)otherBookmarksButton { - (BookmarkButton*)otherBookmarksButton {
return otherBookmarksButton_.get(); return otherBookmarksButton_.get();
} }
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h"
#include "chrome/browser/ui/cocoa/cocoa_profile_test.h" #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
#import "chrome/browser/ui/cocoa/view_resizer_pong.h" #import "chrome/browser/ui/cocoa/view_resizer_pong.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/model_test_utils.h" #include "chrome/test/base/model_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#import "testing/gtest_mac.h" #import "testing/gtest_mac.h"
...@@ -339,6 +341,7 @@ class BookmarkBarControllerTest : public BookmarkBarControllerTestBase { ...@@ -339,6 +341,7 @@ class BookmarkBarControllerTest : public BookmarkBarControllerTestBase {
virtual void SetUp() { virtual void SetUp() {
BookmarkBarControllerTestBase::SetUp(); BookmarkBarControllerTestBase::SetUp();
ASSERT_TRUE(browser()); ASSERT_TRUE(browser());
AddCommandLineSwitches();
bar_.reset( bar_.reset(
[[BookmarkBarControllerNoOpen alloc] [[BookmarkBarControllerNoOpen alloc]
...@@ -350,6 +353,8 @@ class BookmarkBarControllerTest : public BookmarkBarControllerTestBase { ...@@ -350,6 +353,8 @@ class BookmarkBarControllerTest : public BookmarkBarControllerTestBase {
InstallAndToggleBar(bar_.get()); InstallAndToggleBar(bar_.get());
} }
virtual void AddCommandLineSwitches() {}
BookmarkBarControllerNoOpen* noOpenBar() { BookmarkBarControllerNoOpen* noOpenBar() {
return (BookmarkBarControllerNoOpen*)bar_.get(); return (BookmarkBarControllerNoOpen*)bar_.get();
} }
...@@ -1542,6 +1547,66 @@ TEST_F(BookmarkBarControllerTest, LastBookmarkResizeBehavior) { ...@@ -1542,6 +1547,66 @@ TEST_F(BookmarkBarControllerTest, LastBookmarkResizeBehavior) {
} }
} }
class BookmarkBarControllerWithInstantExtendedTest :
public BookmarkBarControllerTest {
public:
virtual void AddCommandLineSwitches() OVERRIDE {
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableInstantExtendedAPI);
}
};
TEST_F(BookmarkBarControllerWithInstantExtendedTest,
BookmarksWithAppsPageShortcut) {
BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
const BookmarkNode* root = model->bookmark_bar_node();
const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b ");
model_test_utils::AddNodesFromModelString(model, root, model_string);
[bar_ frameDidChange];
// Apps page shortcut button should be visible.
ASSERT_FALSE([bar_ appsPageShortcutButtonIsHidden]);
// Bookmarks should be to the right of the Apps page shortcut button.
CGFloat apps_button_right = NSMaxX([[bar_ appsPageShortcutButton] frame]);
CGFloat right = apps_button_right;
NSArray* buttons = [bar_ buttons];
for (size_t i = 0; i < [buttons count]; ++i) {
EXPECT_LE(right, NSMinX([[buttons objectAtIndex:i] frame]));
right = NSMaxX([[buttons objectAtIndex:i] frame]);
}
// Removing the Apps button should move every bookmark to the left.
profile()->GetPrefs()->SetBoolean(prefs::kShowAppsShortcutInBookmarkBar,
false);
ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]);
EXPECT_GT(apps_button_right, NSMinX([[buttons objectAtIndex:0] frame]));
for (size_t i = 1; i < [buttons count]; ++i) {
EXPECT_LE(NSMaxX([[buttons objectAtIndex:i - 1] frame]),
NSMinX([[buttons objectAtIndex:i] frame]));
}
}
TEST_F(BookmarkBarControllerWithInstantExtendedTest,
BookmarksWithoutAppsPageShortcut) {
// The no item containers should be to the right of the Apps button.
ASSERT_FALSE([bar_ appsPageShortcutButtonIsHidden]);
CGFloat apps_button_right = NSMaxX([[bar_ appsPageShortcutButton] frame]);
EXPECT_LE(apps_button_right,
NSMinX([[[bar_ buttonView] noItemTextfield] frame]));
EXPECT_LE(NSMaxX([[[bar_ buttonView] noItemTextfield] frame]),
NSMinX([[[bar_ buttonView] importBookmarksButton] frame]));
// Removing the Apps button should move the no item containers to the left.
profile()->GetPrefs()->SetBoolean(prefs::kShowAppsShortcutInBookmarkBar,
false);
ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]);
EXPECT_GT(apps_button_right,
NSMinX([[[bar_ buttonView] noItemTextfield] frame]));
EXPECT_LE(NSMaxX([[[bar_ buttonView] noItemTextfield] frame]),
NSMinX([[[bar_ buttonView] importBookmarksButton] frame]));
}
class BookmarkBarControllerOpenAllTest : public BookmarkBarControllerTest { class BookmarkBarControllerOpenAllTest : public BookmarkBarControllerTest {
public: public:
virtual void SetUp() { virtual void SetUp() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment