Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Unified Diff: chrome/browser/ui/cocoa/tab_controller_unittest.mm

Issue 5703007: Mac: Correctly clip tab title... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/tab_controller.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/tab_controller_unittest.mm
===================================================================
--- chrome/browser/ui/cocoa/tab_controller_unittest.mm (revision 68959)
+++ chrome/browser/ui/cocoa/tab_controller_unittest.mm (working copy)
@@ -62,6 +62,14 @@
namespace {
+CGFloat LeftMargin(NSRect superFrame, NSRect subFrame) {
+ return NSMinX(subFrame) - NSMinX(superFrame);
+}
+
+CGFloat RightMargin(NSRect superFrame, NSRect subFrame) {
+ return NSMaxX(superFrame) - NSMaxX(subFrame);
+}
+
// The dragging code in TabView makes heavy use of autorelease pools so
// inherit from CocoaTest to have one created for us.
class TabControllerTest : public CocoaTest {
@@ -265,4 +273,61 @@
EXPECT_GT([menu numberOfItems], 0);
}
+// Tests that the title field is correctly positioned and sized when the
+// view is resized.
+TEST_F(TabControllerTest, TitleViewLayout) {
+ NSWindow* window = test_window();
+
+ scoped_nsobject<TabController> controller([[TabController alloc] init]);
+ [[window contentView] addSubview:[controller view]];
+ NSRect tabFrame = [[controller view] frame];
+ tabFrame.size.width = [TabController maxTabWidth];
+ [[controller view] setFrame:tabFrame];
+
+ const NSRect originalTabFrame = [[controller view] frame];
+ const NSRect originalIconFrame = [[controller iconView] frame];
+ const NSRect originalCloseFrame = [[controller closeButton] frame];
+ const NSRect originalTitleFrame = [[controller titleView] frame];
+
+ // Sanity check the start state.
+ EXPECT_FALSE([[controller iconView] isHidden]);
+ EXPECT_FALSE([[controller closeButton] isHidden]);
+ EXPECT_GT(NSWidth([[controller view] frame]),
+ NSWidth([[controller titleView] frame]));
+
+ // Resize the tab so that that the it shrinks.
+ tabFrame.size.width = [TabController minTabWidth];
+ [[controller view] setFrame:tabFrame];
+
+ // The icon view and close button should be hidden and the title view should
+ // be resize to take up their space.
+ EXPECT_TRUE([[controller iconView] isHidden]);
+ EXPECT_TRUE([[controller closeButton] isHidden]);
+ EXPECT_GT(NSWidth([[controller view] frame]),
+ NSWidth([[controller titleView] frame]));
+ EXPECT_EQ(LeftMargin(originalTabFrame, originalIconFrame),
+ LeftMargin([[controller view] frame],
+ [[controller titleView] frame]));
+ EXPECT_EQ(RightMargin(originalTabFrame, originalCloseFrame),
+ RightMargin([[controller view] frame],
+ [[controller titleView] frame]));
+
+ // Resize the tab so that that the it grows.
+ tabFrame.size.width = [TabController maxTabWidth] * 0.75;
+ [[controller view] setFrame:tabFrame];
+
+ // The icon view and close button should be visible again and the title view
+ // should be resized to make room for them.
+ EXPECT_FALSE([[controller iconView] isHidden]);
+ EXPECT_FALSE([[controller closeButton] isHidden]);
+ EXPECT_GT(NSWidth([[controller view] frame]),
+ NSWidth([[controller titleView] frame]));
+ EXPECT_EQ(LeftMargin(originalTabFrame, originalTitleFrame),
+ LeftMargin([[controller view] frame],
+ [[controller titleView] frame]));
+ EXPECT_EQ(RightMargin(originalTabFrame, originalTitleFrame),
+ RightMargin([[controller view] frame],
+ [[controller titleView] frame]));
+}
+
} // namespace
« no previous file with comments | « chrome/browser/ui/cocoa/tab_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698