| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/debug/debugger.h" | 7 #include "base/debug/debugger.h" |
| 8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 12 #import "chrome/browser/ui/cocoa/framed_browser_window.h" | 12 #import "chrome/browser/ui/cocoa/framed_browser_window.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #import "testing/gtest_mac.h" | 14 #import "testing/gtest_mac.h" |
| 15 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
| 16 #import "third_party/ocmock/OCMock/OCMock.h" | 16 #import "third_party/ocmock/OCMock/OCMock.h" |
| 17 | 17 |
| 18 namespace { |
| 19 NSString* const kAppleTextDirectionDefaultsKey = @"AppleTextDirection"; |
| 20 NSString* const kForceRTLWritingDirectionDefaultsKey = |
| 21 @"NSForceRightToLeftWritingDirection"; |
| 22 } // namespace |
| 23 |
| 18 class FramedBrowserWindowTest : public CocoaTest { | 24 class FramedBrowserWindowTest : public CocoaTest { |
| 19 public: | 25 public: |
| 20 void SetUp() override { | 26 void SetUp() override { |
| 21 CocoaTest::SetUp(); | 27 CocoaTest::SetUp(); |
| 22 // Create a window. | 28 // Create a window. |
| 23 window_ = [[FramedBrowserWindow alloc] | 29 window_ = [[FramedBrowserWindow alloc] |
| 24 initWithContentRect:NSMakeRect(0, 0, 800, 600) | 30 initWithContentRect:NSMakeRect(0, 0, 800, 600) |
| 25 hasTabStrip:YES]; | 31 hasTabStrip:YES]; |
| 26 if (base::debug::BeingDebugged()) { | 32 if (base::debug::BeingDebugged()) { |
| 27 [window_ orderFront:nil]; | 33 [window_ orderFront:nil]; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 kFramedWindowButtonsWithoutTabStripOffsetFromTop); | 140 kFramedWindowButtonsWithoutTabStripOffsetFromTop); |
| 135 EXPECT_EQ(NSMinX(closeBoxFrame), | 141 EXPECT_EQ(NSMinX(closeBoxFrame), |
| 136 kFramedWindowButtonsWithoutTabStripOffsetFromLeft); | 142 kFramedWindowButtonsWithoutTabStripOffsetFromLeft); |
| 137 | 143 |
| 138 NSView* miniaturizeControl = | 144 NSView* miniaturizeControl = |
| 139 [window_ standardWindowButton:NSWindowMiniaturizeButton]; | 145 [window_ standardWindowButton:NSWindowMiniaturizeButton]; |
| 140 EXPECT_TRUE(miniaturizeControl); | 146 EXPECT_TRUE(miniaturizeControl); |
| 141 NSRect miniaturizeFrame = | 147 NSRect miniaturizeFrame = |
| 142 [miniaturizeControl convertRect:[miniaturizeControl bounds] | 148 [miniaturizeControl convertRect:[miniaturizeControl bounds] |
| 143 toView:nil]; | 149 toView:nil]; |
| 150 EXPECT_LT(NSMaxX(closeBoxFrame), NSMinX(miniaturizeFrame)); |
| 144 EXPECT_EQ(NSMaxY(miniaturizeFrame), | 151 EXPECT_EQ(NSMaxY(miniaturizeFrame), |
| 145 NSMaxY(windowBounds) - | 152 NSMaxY(windowBounds) - |
| 146 kFramedWindowButtonsWithoutTabStripOffsetFromTop); | 153 kFramedWindowButtonsWithoutTabStripOffsetFromTop); |
| 154 EXPECT_EQ(NSMinX(miniaturizeFrame), |
| 155 NSMaxX(closeBoxFrame) + [window_ windowButtonsInterButtonSpacing]); |
| 156 [window_ setWindowController:nil]; |
| 157 |
| 158 // Then with a tabstrip. |
| 159 [window_ close]; |
| 160 window_ = [[FramedBrowserWindow alloc] |
| 161 initWithContentRect:NSMakeRect(0, 0, 800, 600) |
| 162 hasTabStrip:YES]; |
| 163 // Update window layout according to existing layout constraints. |
| 164 [window_ layoutIfNeeded]; |
| 165 controller = [OCMockObject mockForClass:[BrowserWindowController class]]; |
| 166 [[[controller stub] andReturnValue:OCMOCK_VALUE(yes)] |
| 167 isKindOfClass:[BrowserWindowController class]]; |
| 168 [[[controller expect] andReturnValue:OCMOCK_VALUE(yes)] hasTabStrip]; |
| 169 [[[controller expect] andReturnValue:OCMOCK_VALUE(no)] hasTitleBar]; |
| 170 [[[controller expect] andReturnValue:OCMOCK_VALUE(yes)] isTabbedWindow]; |
| 171 [window_ setWindowController:controller]; |
| 172 |
| 173 closeBoxControl = [window_ standardWindowButton:NSWindowCloseButton]; |
| 174 EXPECT_TRUE(closeBoxControl); |
| 175 closeBoxFrame = [closeBoxControl convertRect:[closeBoxControl bounds] |
| 176 toView:nil]; |
| 177 windowBounds = [window_ frame]; |
| 178 windowBounds = [[window_ contentView] convertRect:windowBounds fromView:nil]; |
| 179 windowBounds.origin = NSZeroPoint; |
| 180 EXPECT_EQ(NSMaxY(closeBoxFrame), |
| 181 NSMaxY(windowBounds) - |
| 182 kFramedWindowButtonsWithTabStripOffsetFromTop); |
| 183 EXPECT_EQ(NSMinX(closeBoxFrame), |
| 184 kFramedWindowButtonsWithTabStripOffsetFromLeft); |
| 185 |
| 186 miniaturizeControl = [window_ standardWindowButton:NSWindowMiniaturizeButton]; |
| 187 EXPECT_TRUE(miniaturizeControl); |
| 188 miniaturizeFrame = [miniaturizeControl convertRect:[miniaturizeControl bounds] |
| 189 toView:nil]; |
| 190 EXPECT_EQ(NSMaxY(miniaturizeFrame), |
| 191 NSMaxY(windowBounds) - |
| 192 kFramedWindowButtonsWithTabStripOffsetFromTop); |
| 193 EXPECT_EQ(NSMinX(miniaturizeFrame), |
| 194 NSMaxX(closeBoxFrame) + [window_ windowButtonsInterButtonSpacing]); |
| 195 [window_ setWindowController:nil]; |
| 196 } |
| 197 |
| 198 class FramedBrowserWindowRTLTest : public FramedBrowserWindowTest { |
| 199 void SetUp() override { |
| 200 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
| 201 originalAppleTextDirection_ = |
| 202 [defaults boolForKey:kAppleTextDirectionDefaultsKey]; |
| 203 originalRTLWritingDirection_ = |
| 204 [defaults boolForKey:kForceRTLWritingDirectionDefaultsKey]; |
| 205 [defaults setBool:YES forKey:kAppleTextDirectionDefaultsKey]; |
| 206 [defaults setBool:YES forKey:kForceRTLWritingDirectionDefaultsKey]; |
| 207 FramedBrowserWindowTest::SetUp(); |
| 208 } |
| 209 |
| 210 void TearDown() override { |
| 211 FramedBrowserWindowTest::TearDown(); |
| 212 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
| 213 [defaults setBool:originalAppleTextDirection_ |
| 214 forKey:kAppleTextDirectionDefaultsKey]; |
| 215 [defaults setBool:originalRTLWritingDirection_ |
| 216 forKey:kForceRTLWritingDirectionDefaultsKey]; |
| 217 } |
| 218 |
| 219 private: |
| 220 BOOL originalAppleTextDirection_; |
| 221 BOOL originalRTLWritingDirection_; |
| 222 }; |
| 223 |
| 224 // Test to make sure that our window widgets are in the right place. |
| 225 // Currently, this is the same exact test as above, since RTL button |
| 226 // layout is behind the ExperimentalMacRTL flag. However, this ensures |
| 227 // that our calculations are correct for Sierra RTL, which lays out |
| 228 // the window buttons in reverse by default. See crbug/662079. |
| 229 TEST_F(FramedBrowserWindowRTLTest, WindowWidgetLocation) { |
| 230 BOOL yes = YES; |
| 231 BOOL no = NO; |
| 232 |
| 233 // First without a tabstrip. |
| 234 [window_ close]; |
| 235 window_ = [[FramedBrowserWindow alloc] |
| 236 initWithContentRect:NSMakeRect(0, 0, 800, 600) |
| 237 hasTabStrip:NO]; |
| 238 // Update window layout according to existing layout constraints. |
| 239 [window_ layoutIfNeeded]; |
| 240 id controller = [OCMockObject mockForClass:[BrowserWindowController class]]; |
| 241 [[[controller stub] andReturnValue:OCMOCK_VALUE(yes)] |
| 242 isKindOfClass:[BrowserWindowController class]]; |
| 243 [[[controller expect] andReturnValue:OCMOCK_VALUE(no)] hasTabStrip]; |
| 244 [[[controller expect] andReturnValue:OCMOCK_VALUE(yes)] hasTitleBar]; |
| 245 [[[controller expect] andReturnValue:OCMOCK_VALUE(no)] isTabbedWindow]; |
| 246 [window_ setWindowController:controller]; |
| 247 |
| 248 NSView* closeBoxControl = [window_ standardWindowButton:NSWindowCloseButton]; |
| 249 EXPECT_TRUE(closeBoxControl); |
| 250 NSRect closeBoxFrame = |
| 251 [closeBoxControl convertRect:[closeBoxControl bounds] toView:nil]; |
| 252 NSRect windowBounds = [window_ frame]; |
| 253 windowBounds = [[window_ contentView] convertRect:windowBounds fromView:nil]; |
| 254 windowBounds.origin = NSZeroPoint; |
| 255 EXPECT_EQ( |
| 256 NSMaxY(closeBoxFrame), |
| 257 NSMaxY(windowBounds) - kFramedWindowButtonsWithoutTabStripOffsetFromTop); |
| 258 EXPECT_EQ(NSMinX(closeBoxFrame), |
| 259 kFramedWindowButtonsWithoutTabStripOffsetFromLeft); |
| 260 |
| 261 NSView* miniaturizeControl = |
| 262 [window_ standardWindowButton:NSWindowMiniaturizeButton]; |
| 263 EXPECT_TRUE(miniaturizeControl); |
| 264 NSRect miniaturizeFrame = |
| 265 [miniaturizeControl convertRect:[miniaturizeControl bounds] toView:nil]; |
| 266 EXPECT_LT(NSMaxX(closeBoxFrame), NSMinX(miniaturizeFrame)); |
| 267 EXPECT_EQ(NSMaxY(miniaturizeFrame), |
| 268 NSMaxY(windowBounds) - |
| 269 kFramedWindowButtonsWithoutTabStripOffsetFromTop); |
| 147 EXPECT_EQ(NSMinX(miniaturizeFrame), | 270 EXPECT_EQ(NSMinX(miniaturizeFrame), |
| 148 NSMaxX(closeBoxFrame) + [window_ windowButtonsInterButtonSpacing]); | 271 NSMaxX(closeBoxFrame) + [window_ windowButtonsInterButtonSpacing]); |
| 149 [window_ setWindowController:nil]; | 272 [window_ setWindowController:nil]; |
| 150 | 273 |
| 151 // Then with a tabstrip. | 274 // Then with a tabstrip. |
| 152 [window_ close]; | 275 [window_ close]; |
| 153 window_ = [[FramedBrowserWindow alloc] | 276 window_ = [[FramedBrowserWindow alloc] |
| 154 initWithContentRect:NSMakeRect(0, 0, 800, 600) | 277 initWithContentRect:NSMakeRect(0, 0, 800, 600) |
| 155 hasTabStrip:YES]; | 278 hasTabStrip:YES]; |
| 156 // Update window layout according to existing layout constraints. | 279 // Update window layout according to existing layout constraints. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 180 EXPECT_TRUE(miniaturizeControl); | 303 EXPECT_TRUE(miniaturizeControl); |
| 181 miniaturizeFrame = [miniaturizeControl convertRect:[miniaturizeControl bounds] | 304 miniaturizeFrame = [miniaturizeControl convertRect:[miniaturizeControl bounds] |
| 182 toView:nil]; | 305 toView:nil]; |
| 183 EXPECT_EQ(NSMaxY(miniaturizeFrame), | 306 EXPECT_EQ(NSMaxY(miniaturizeFrame), |
| 184 NSMaxY(windowBounds) - | 307 NSMaxY(windowBounds) - |
| 185 kFramedWindowButtonsWithTabStripOffsetFromTop); | 308 kFramedWindowButtonsWithTabStripOffsetFromTop); |
| 186 EXPECT_EQ(NSMinX(miniaturizeFrame), | 309 EXPECT_EQ(NSMinX(miniaturizeFrame), |
| 187 NSMaxX(closeBoxFrame) + [window_ windowButtonsInterButtonSpacing]); | 310 NSMaxX(closeBoxFrame) + [window_ windowButtonsInterButtonSpacing]); |
| 188 [window_ setWindowController:nil]; | 311 [window_ setWindowController:nil]; |
| 189 } | 312 } |
| OLD | NEW |