| Index: chrome/browser/ui/cocoa/framed_browser_window_unittest.mm
|
| diff --git a/chrome/browser/ui/cocoa/framed_browser_window_unittest.mm b/chrome/browser/ui/cocoa/framed_browser_window_unittest.mm
|
| index ff640dbea6c931f74509bef62ebd8a59df94414f..cf8774f67c19167d51a48cdcd901bc90d89b7661 100644
|
| --- a/chrome/browser/ui/cocoa/framed_browser_window_unittest.mm
|
| +++ b/chrome/browser/ui/cocoa/framed_browser_window_unittest.mm
|
| @@ -15,6 +15,12 @@
|
| #include "testing/platform_test.h"
|
| #import "third_party/ocmock/OCMock/OCMock.h"
|
|
|
| +namespace {
|
| +NSString* const kAppleTextDirectionDefaultsKey = @"AppleTextDirection";
|
| +NSString* const kForceRTLWritingDirectionDefaultsKey =
|
| + @"NSForceRightToLeftWritingDirection";
|
| +} // namespace
|
| +
|
| class FramedBrowserWindowTest : public CocoaTest {
|
| public:
|
| void SetUp() override {
|
| @@ -141,6 +147,123 @@ TEST_F(FramedBrowserWindowTest, WindowWidgetLocation) {
|
| NSRect miniaturizeFrame =
|
| [miniaturizeControl convertRect:[miniaturizeControl bounds]
|
| toView:nil];
|
| + EXPECT_LT(NSMaxX(closeBoxFrame), NSMinX(miniaturizeFrame));
|
| + EXPECT_EQ(NSMaxY(miniaturizeFrame),
|
| + NSMaxY(windowBounds) -
|
| + kFramedWindowButtonsWithoutTabStripOffsetFromTop);
|
| + EXPECT_EQ(NSMinX(miniaturizeFrame),
|
| + NSMaxX(closeBoxFrame) + [window_ windowButtonsInterButtonSpacing]);
|
| + [window_ setWindowController:nil];
|
| +
|
| + // Then with a tabstrip.
|
| + [window_ close];
|
| + window_ = [[FramedBrowserWindow alloc]
|
| + initWithContentRect:NSMakeRect(0, 0, 800, 600)
|
| + hasTabStrip:YES];
|
| + // Update window layout according to existing layout constraints.
|
| + [window_ layoutIfNeeded];
|
| + controller = [OCMockObject mockForClass:[BrowserWindowController class]];
|
| + [[[controller stub] andReturnValue:OCMOCK_VALUE(yes)]
|
| + isKindOfClass:[BrowserWindowController class]];
|
| + [[[controller expect] andReturnValue:OCMOCK_VALUE(yes)] hasTabStrip];
|
| + [[[controller expect] andReturnValue:OCMOCK_VALUE(no)] hasTitleBar];
|
| + [[[controller expect] andReturnValue:OCMOCK_VALUE(yes)] isTabbedWindow];
|
| + [window_ setWindowController:controller];
|
| +
|
| + closeBoxControl = [window_ standardWindowButton:NSWindowCloseButton];
|
| + EXPECT_TRUE(closeBoxControl);
|
| + closeBoxFrame = [closeBoxControl convertRect:[closeBoxControl bounds]
|
| + toView:nil];
|
| + windowBounds = [window_ frame];
|
| + windowBounds = [[window_ contentView] convertRect:windowBounds fromView:nil];
|
| + windowBounds.origin = NSZeroPoint;
|
| + EXPECT_EQ(NSMaxY(closeBoxFrame),
|
| + NSMaxY(windowBounds) -
|
| + kFramedWindowButtonsWithTabStripOffsetFromTop);
|
| + EXPECT_EQ(NSMinX(closeBoxFrame),
|
| + kFramedWindowButtonsWithTabStripOffsetFromLeft);
|
| +
|
| + miniaturizeControl = [window_ standardWindowButton:NSWindowMiniaturizeButton];
|
| + EXPECT_TRUE(miniaturizeControl);
|
| + miniaturizeFrame = [miniaturizeControl convertRect:[miniaturizeControl bounds]
|
| + toView:nil];
|
| + EXPECT_EQ(NSMaxY(miniaturizeFrame),
|
| + NSMaxY(windowBounds) -
|
| + kFramedWindowButtonsWithTabStripOffsetFromTop);
|
| + EXPECT_EQ(NSMinX(miniaturizeFrame),
|
| + NSMaxX(closeBoxFrame) + [window_ windowButtonsInterButtonSpacing]);
|
| + [window_ setWindowController:nil];
|
| +}
|
| +
|
| +class FramedBrowserWindowRTLTest : public FramedBrowserWindowTest {
|
| + void SetUp() override {
|
| + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
| + originalAppleTextDirection_ =
|
| + [defaults boolForKey:kAppleTextDirectionDefaultsKey];
|
| + originalRTLWritingDirection_ =
|
| + [defaults boolForKey:kForceRTLWritingDirectionDefaultsKey];
|
| + [defaults setBool:YES forKey:kAppleTextDirectionDefaultsKey];
|
| + [defaults setBool:YES forKey:kForceRTLWritingDirectionDefaultsKey];
|
| + FramedBrowserWindowTest::SetUp();
|
| + }
|
| +
|
| + void TearDown() override {
|
| + FramedBrowserWindowTest::TearDown();
|
| + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
| + [defaults setBool:originalAppleTextDirection_
|
| + forKey:kAppleTextDirectionDefaultsKey];
|
| + [defaults setBool:originalRTLWritingDirection_
|
| + forKey:kForceRTLWritingDirectionDefaultsKey];
|
| + }
|
| +
|
| + private:
|
| + BOOL originalAppleTextDirection_;
|
| + BOOL originalRTLWritingDirection_;
|
| +};
|
| +
|
| +// Test to make sure that our window widgets are in the right place.
|
| +// Currently, this is the same exact test as above, since RTL button
|
| +// layout is behind the ExperimentalMacRTL flag. However, this ensures
|
| +// that our calculations are correct for Sierra RTL, which lays out
|
| +// the window buttons in reverse by default. See crbug/662079.
|
| +TEST_F(FramedBrowserWindowRTLTest, WindowWidgetLocation) {
|
| + BOOL yes = YES;
|
| + BOOL no = NO;
|
| +
|
| + // First without a tabstrip.
|
| + [window_ close];
|
| + window_ = [[FramedBrowserWindow alloc]
|
| + initWithContentRect:NSMakeRect(0, 0, 800, 600)
|
| + hasTabStrip:NO];
|
| + // Update window layout according to existing layout constraints.
|
| + [window_ layoutIfNeeded];
|
| + id controller = [OCMockObject mockForClass:[BrowserWindowController class]];
|
| + [[[controller stub] andReturnValue:OCMOCK_VALUE(yes)]
|
| + isKindOfClass:[BrowserWindowController class]];
|
| + [[[controller expect] andReturnValue:OCMOCK_VALUE(no)] hasTabStrip];
|
| + [[[controller expect] andReturnValue:OCMOCK_VALUE(yes)] hasTitleBar];
|
| + [[[controller expect] andReturnValue:OCMOCK_VALUE(no)] isTabbedWindow];
|
| + [window_ setWindowController:controller];
|
| +
|
| + NSView* closeBoxControl = [window_ standardWindowButton:NSWindowCloseButton];
|
| + EXPECT_TRUE(closeBoxControl);
|
| + NSRect closeBoxFrame =
|
| + [closeBoxControl convertRect:[closeBoxControl bounds] toView:nil];
|
| + NSRect windowBounds = [window_ frame];
|
| + windowBounds = [[window_ contentView] convertRect:windowBounds fromView:nil];
|
| + windowBounds.origin = NSZeroPoint;
|
| + EXPECT_EQ(
|
| + NSMaxY(closeBoxFrame),
|
| + NSMaxY(windowBounds) - kFramedWindowButtonsWithoutTabStripOffsetFromTop);
|
| + EXPECT_EQ(NSMinX(closeBoxFrame),
|
| + kFramedWindowButtonsWithoutTabStripOffsetFromLeft);
|
| +
|
| + NSView* miniaturizeControl =
|
| + [window_ standardWindowButton:NSWindowMiniaturizeButton];
|
| + EXPECT_TRUE(miniaturizeControl);
|
| + NSRect miniaturizeFrame =
|
| + [miniaturizeControl convertRect:[miniaturizeControl bounds] toView:nil];
|
| + EXPECT_LT(NSMaxX(closeBoxFrame), NSMinX(miniaturizeFrame));
|
| EXPECT_EQ(NSMaxY(miniaturizeFrame),
|
| NSMaxY(windowBounds) -
|
| kFramedWindowButtonsWithoutTabStripOffsetFromTop);
|
|
|