| 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/cocoa_test_helper.h" | 10 #import "chrome/browser/ui/cocoa/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 // An NSWindowDelegate that implements -commandDispatch:. | |
| 16 @interface TestDelegateWithCommandDispatch : NSObject { | |
| 17 } | |
| 18 - (void)commandDispatch:(id)sender; | |
| 19 @end | |
| 20 @implementation TestDelegateWithCommandDispatch | |
| 21 - (void)commandDispatch:(id)sender { | |
| 22 } | |
| 23 @end | |
| 24 | |
| 25 // An NSWindowDelegate that doesn't implement -commandDispatch:. | |
| 26 @interface TestDelegateWithoutCommandDispatch : NSObject { | |
| 27 } | |
| 28 @end | |
| 29 @implementation TestDelegateWithoutCommandDispatch | |
| 30 @end | |
| 31 | |
| 32 class ChromeBrowserWindowTest : public CocoaTest { | 15 class ChromeBrowserWindowTest : public CocoaTest { |
| 33 public: | 16 public: |
| 34 virtual void SetUp() { | 17 virtual void SetUp() { |
| 35 CocoaTest::SetUp(); | 18 CocoaTest::SetUp(); |
| 36 // Create a window. | 19 // Create a window. |
| 37 const NSUInteger mask = NSTitledWindowMask | NSClosableWindowMask | | 20 const NSUInteger mask = NSTitledWindowMask | NSClosableWindowMask | |
| 38 NSMiniaturizableWindowMask | NSResizableWindowMask; | 21 NSMiniaturizableWindowMask | NSResizableWindowMask; |
| 39 window_ = [[ChromeBrowserWindow alloc] | 22 window_ = [[ChromeBrowserWindow alloc] |
| 40 initWithContentRect:NSMakeRect(0, 0, 800, 600) | 23 initWithContentRect:NSMakeRect(0, 0, 800, 600) |
| 41 styleMask:mask | 24 styleMask:mask |
| (...skipping 13 matching lines...) Expand all Loading... |
| 55 | 38 |
| 56 ChromeBrowserWindow* window_; | 39 ChromeBrowserWindow* window_; |
| 57 }; | 40 }; |
| 58 | 41 |
| 59 // Baseline test that the window creates, displays, closes, and | 42 // Baseline test that the window creates, displays, closes, and |
| 60 // releases. | 43 // releases. |
| 61 TEST_F(ChromeBrowserWindowTest, ShowAndClose) { | 44 TEST_F(ChromeBrowserWindowTest, ShowAndClose) { |
| 62 [window_ display]; | 45 [window_ display]; |
| 63 } | 46 } |
| 64 | 47 |
| 65 // Tests routing of -performClose:. | |
| 66 TEST_F(ChromeBrowserWindowTest, PerformCloseTest) { | |
| 67 scoped_nsobject<NSMenuItem> zoom_item( | |
| 68 [[NSMenuItem alloc] initWithTitle:@"Zoom" | |
| 69 action:@selector(performZoom:) | |
| 70 keyEquivalent:@""]); | |
| 71 scoped_nsobject<NSMenuItem> close_item( | |
| 72 [[NSMenuItem alloc] initWithTitle:@"Close" | |
| 73 action:@selector(performClose:) | |
| 74 keyEquivalent:@""]); | |
| 75 scoped_nsobject<NSMenuItem> close_tab_item( | |
| 76 [[NSMenuItem alloc] initWithTitle:@"Close Tab" | |
| 77 action:@selector(performClose:) | |
| 78 keyEquivalent:@""]); | |
| 79 [close_tab_item setTag:IDC_CLOSE_TAB]; | |
| 80 | |
| 81 scoped_nsobject<id> delegate1( | |
| 82 [[TestDelegateWithCommandDispatch alloc] init]); | |
| 83 scoped_nsobject<id> delegate2( | |
| 84 [[TestDelegateWithoutCommandDispatch alloc] init]); | |
| 85 | |
| 86 struct { | |
| 87 id delegate; | |
| 88 id sender; | |
| 89 BOOL should_route; | |
| 90 } cases[] = { | |
| 91 { delegate1, delegate1, NO }, | |
| 92 { delegate1, window_, NO }, | |
| 93 { delegate1, zoom_item, NO }, | |
| 94 { delegate1, close_item, NO }, | |
| 95 { delegate1, close_tab_item, YES }, | |
| 96 { delegate2, close_tab_item, NO }, | |
| 97 }; | |
| 98 | |
| 99 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | |
| 100 [window_ setDelegate:cases[i].delegate]; | |
| 101 EXPECT_EQ(cases[i].should_route, | |
| 102 [window_ performCloseShouldRouteToCommandDispatch:cases[i].sender]); | |
| 103 } | |
| 104 } | |
| OLD | NEW |