Chromium Code Reviews| 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 "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #import "chrome/browser/ui/cocoa/chrome_browser_window.h" | 9 #import "chrome/browser/ui/cocoa/chrome_browser_window.h" |
| 10 #import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h" | 10 #import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #import "testing/gtest_mac.h" | 12 #import "testing/gtest_mac.h" |
| 13 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
| 14 | 14 |
| 15 class ChromeBrowserWindowTest : public CocoaTest { | 15 class ChromeBrowserWindowTest : public CocoaTest { |
| 16 public: | 16 public: |
| 17 void SetUp() override { | 17 void SetUp() override { |
| 18 CocoaTest::SetUp(); | 18 CocoaTest::SetUp(); |
| 19 // Create a window. | 19 // Create a window. |
| 20 const NSUInteger mask = NSTitledWindowMask | NSClosableWindowMask | | 20 const NSUInteger mask = NSTitledWindowMask | NSClosableWindowMask | |
| 21 NSMiniaturizableWindowMask | NSResizableWindowMask; | 21 NSMiniaturizableWindowMask | NSResizableWindowMask; |
| 22 window_ = [[ChromeBrowserWindow alloc] | 22 window_ = [[ChromeBrowserWindow alloc] |
| 23 initWithContentRect:NSMakeRect(0, 0, 800, 600) | 23 initWithContentRect:NSMakeRect(0, 0, 800, 600) |
| 24 styleMask:mask | 24 styleMask:mask |
| 25 backing:NSBackingStoreBuffered | 25 backing:NSBackingStoreBuffered |
| 26 defer:NO]; | 26 defer:NO |
| 27 wantsViewsOverTitlebar:YES]; | |
|
tapted
2017/03/21 02:16:51
Is this needed? It suggests that passing `NO` will
Sidney San Martín
2017/03/22 21:40:22
Where we force Auto Layout is somewhat arbitrary.
| |
| 27 if (base::debug::BeingDebugged()) { | 28 if (base::debug::BeingDebugged()) { |
| 28 [window_ orderFront:nil]; | 29 [window_ orderFront:nil]; |
| 29 } else { | 30 } else { |
| 30 [window_ orderBack:nil]; | 31 [window_ orderBack:nil]; |
| 31 } | 32 } |
| 32 } | 33 } |
| 33 | 34 |
| 34 void TearDown() override { | 35 void TearDown() override { |
| 35 [window_ close]; | 36 [window_ close]; |
| 36 CocoaTest::TearDown(); | 37 CocoaTest::TearDown(); |
| 37 } | 38 } |
| 38 | 39 |
| 39 ChromeBrowserWindow* window_; | 40 ChromeBrowserWindow* window_; |
| 40 }; | 41 }; |
| 41 | 42 |
| 42 // Baseline test that the window creates, displays, closes, and | 43 // Baseline test that the window creates, displays, closes, and |
| 43 // releases. | 44 // releases. |
| 44 TEST_F(ChromeBrowserWindowTest, ShowAndClose) { | 45 TEST_F(ChromeBrowserWindowTest, ShowAndClose) { |
| 45 [window_ display]; | 46 [window_ display]; |
| 46 } | 47 } |
| 47 | 48 |
| 49 // Verify that browser windows use Auto Layout. Since frame-based layout and | |
|
tapted
2017/03/21 02:16:51
This is super nit-picky, but I'm not sure if this
Sidney San Martín
2017/03/22 21:40:22
Heh, great point :). Re-wording the comment like t
| |
| 50 // Auto Layout behave differently in subtle ways, we shouldn't start/stop using | |
| 51 // it accidentally. If we don't want Auto Layout, this test should be changed | |
| 52 // to expect constraints.count == 0, not disabled. | |
| 53 TEST_F(ChromeBrowserWindowTest, UsesAutoLayout) { | |
| 54 base::scoped_nsobject<NSView> view( | |
|
tapted
2017/03/21 02:16:51
Comment why the extra subview is necessary for the
Sidney San Martín
2017/03/22 21:40:22
Gone.
| |
| 55 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 10, 10)]); | |
| 56 [view setAutoresizingMask:NSViewWidthSizable]; | |
| 57 [window_.contentView addSubview:view]; | |
|
tapted
2017/03/21 02:16:51
nit: [[window contentView] addSubview: view]
Sidney San Martín
2017/03/22 21:40:22
Gone.
| |
| 58 [window_ orderFront:nil]; | |
| 59 [window_ layoutIfNeeded]; | |
| 60 EXPECT_TRUE([[[window_ contentView] constraints] count] > 0); | |
|
tapted
2017/03/21 02:16:50
nit:
EXPECT_LT(0u, [[[window_ contentView] constr
Sidney San Martín
2017/03/22 21:40:21
Oof, `EXPECT_LT(0u, count)` seems harder to unders
tapted
2017/03/22 22:40:00
looks good!
| |
| 61 } | |
| OLD | NEW |