| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/scoped_nsobject.h" | 7 #include "base/scoped_nsobject.h" |
| 8 #include "chrome/app/chrome_dll_resource.h" | 8 #include "chrome/app/chrome_dll_resource.h" |
| 9 #import "chrome/browser/cocoa/chrome_browser_window.h" | 9 #import "chrome/browser/cocoa/chrome_browser_window.h" |
| 10 #import "chrome/browser/cocoa/browser_window_controller.h" | 10 #import "chrome/browser/cocoa/browser_window_controller.h" |
| 11 #import "chrome/browser/cocoa/browser_frame_view.h" |
| 11 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 12 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
| 14 #import "third_party/ocmock/OCMock/OCMock.h" | 15 #import "third_party/ocmock/OCMock/OCMock.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 NSEvent* KeyEvent(const NSUInteger flags, const NSUInteger keyCode) { | 19 NSEvent* KeyEvent(const NSUInteger flags, const NSUInteger keyCode) { |
| 19 return [NSEvent keyEventWithType:NSKeyDown | 20 return [NSEvent keyEventWithType:NSKeyDown |
| 20 location:NSZeroPoint | 21 location:NSZeroPoint |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // Baseline test that the window creates, displays, closes, and | 67 // Baseline test that the window creates, displays, closes, and |
| 67 // releases. | 68 // releases. |
| 68 TEST_F(ChromeBrowserWindowTest, ShowAndClose) { | 69 TEST_F(ChromeBrowserWindowTest, ShowAndClose) { |
| 69 [window_ display]; | 70 [window_ display]; |
| 70 } | 71 } |
| 71 | 72 |
| 72 // Verify that the window intercepts a particular key event and | 73 // Verify that the window intercepts a particular key event and |
| 73 // forwards it to [delegate executeCommand:]. Assume that other | 74 // forwards it to [delegate executeCommand:]. Assume that other |
| 74 // CommandForKeyboardShortcut() will work the same for the rest. | 75 // CommandForKeyboardShortcut() will work the same for the rest. |
| 75 TEST_F(ChromeBrowserWindowTest, PerformKeyEquivalentForwardToExecuteCommand) { | 76 TEST_F(ChromeBrowserWindowTest, PerformKeyEquivalentForwardToExecuteCommand) { |
| 76 NSEvent *event = KeyEvent(NSCommandKeyMask, kVK_ANSI_1); | 77 NSEvent* event = KeyEvent(NSCommandKeyMask, kVK_ANSI_1); |
| 77 | 78 |
| 78 id delegate = [OCMockObject mockForClass:[BrowserWindowController class]]; | 79 id delegate = [OCMockObject mockForClass:[BrowserWindowController class]]; |
| 79 // -stub to satisfy the DCHECK. | 80 // -stub to satisfy the DCHECK. |
| 80 BOOL yes = YES; | 81 BOOL yes = YES; |
| 81 [[[delegate stub] andReturnValue:OCMOCK_VALUE(yes)] | 82 [[[delegate stub] andReturnValue:OCMOCK_VALUE(yes)] |
| 82 isKindOfClass:[BrowserWindowController class]]; | 83 isKindOfClass:[BrowserWindowController class]]; |
| 83 [[delegate expect] executeCommand:IDC_SELECT_TAB_0]; | 84 [[delegate expect] executeCommand:IDC_SELECT_TAB_0]; |
| 84 | 85 |
| 85 [window_ setDelegate:delegate]; | 86 [window_ setDelegate:delegate]; |
| 86 [window_ performKeyEquivalent:event]; | 87 [window_ performKeyEquivalent:event]; |
| 87 | 88 |
| 88 // Don't wish to mock all the way down... | 89 // Don't wish to mock all the way down... |
| 89 [window_ setDelegate:nil]; | 90 [window_ setDelegate:nil]; |
| 90 [delegate verify]; | 91 [delegate verify]; |
| 91 } | 92 } |
| 92 | 93 |
| 93 // Verify that an unhandled shortcut does not get forwarded via | 94 // Verify that an unhandled shortcut does not get forwarded via |
| 94 // -executeCommand:. | 95 // -executeCommand:. |
| 95 // TODO(shess) Think of a way to test that it is sent to the | 96 // TODO(shess) Think of a way to test that it is sent to the |
| 96 // superclass. | 97 // superclass. |
| 97 TEST_F(ChromeBrowserWindowTest, PerformKeyEquivalentNoForward) { | 98 TEST_F(ChromeBrowserWindowTest, PerformKeyEquivalentNoForward) { |
| 98 NSEvent *event = KeyEvent(0, 0); | 99 NSEvent* event = KeyEvent(0, 0); |
| 99 | 100 |
| 100 id delegate = [OCMockObject mockForClass:[BrowserWindowController class]]; | 101 id delegate = [OCMockObject mockForClass:[BrowserWindowController class]]; |
| 101 // -stub to satisfy the DCHECK. | 102 // -stub to satisfy the DCHECK. |
| 102 BOOL yes = YES; | 103 BOOL yes = YES; |
| 103 [[[delegate stub] andReturnValue:OCMOCK_VALUE(yes)] | 104 [[[delegate stub] andReturnValue:OCMOCK_VALUE(yes)] |
| 104 isKindOfClass:[BrowserWindowController class]]; | 105 isKindOfClass:[BrowserWindowController class]]; |
| 105 | 106 |
| 106 [window_ setDelegate:delegate]; | 107 [window_ setDelegate:delegate]; |
| 107 [window_ performKeyEquivalent:event]; | 108 [window_ performKeyEquivalent:event]; |
| 108 | 109 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 135 [window_ setTitle:@"This is a title"]; | 136 [window_ setTitle:@"This is a title"]; |
| 136 [window_ display]; | 137 [window_ display]; |
| 137 NSData* hiddenTitleData = WindowContentsAsTIFF(); | 138 NSData* hiddenTitleData = WindowContentsAsTIFF(); |
| 138 | 139 |
| 139 // With our magic setting, the window with a title should look the | 140 // With our magic setting, the window with a title should look the |
| 140 // same as the window with an empty title. | 141 // same as the window with an empty title. |
| 141 EXPECT_TRUE([window_ _isTitleHidden]); | 142 EXPECT_TRUE([window_ _isTitleHidden]); |
| 142 EXPECT_TRUE([emptyTitleData isEqualToData:hiddenTitleData]); | 143 EXPECT_TRUE([emptyTitleData isEqualToData:hiddenTitleData]); |
| 143 } | 144 } |
| 144 | 145 |
| 146 // Test to make sure that our window widgets are in the right place. |
| 147 TEST_F(ChromeBrowserWindowTest, WindowWidgetLocation) { |
| 148 NSCell* closeBoxCell = [window_ accessibilityAttributeValue: |
| 149 NSAccessibilityCloseButtonAttribute]; |
| 150 NSView* closeBoxControl = [closeBoxCell controlView]; |
| 151 EXPECT_TRUE(closeBoxControl); |
| 152 NSRect closeBoxFrame = [closeBoxControl frame]; |
| 153 NSRect windowBounds = [window_ frame]; |
| 154 windowBounds.origin = NSZeroPoint; |
| 155 EXPECT_EQ(NSMaxY(closeBoxFrame), |
| 156 NSMaxY(windowBounds) - kChromeWindowButtonsOffsetFromTop); |
| 157 EXPECT_EQ(NSMinX(closeBoxFrame), kChromeWindowButtonsOffsetFromLeft); |
| 158 |
| 159 NSCell* miniaturizeCell = [window_ accessibilityAttributeValue: |
| 160 NSAccessibilityMinimizeButtonAttribute]; |
| 161 NSView* miniaturizeControl = [miniaturizeCell controlView]; |
| 162 EXPECT_TRUE(miniaturizeControl); |
| 163 NSRect miniaturizeFrame = [miniaturizeControl frame]; |
| 164 EXPECT_EQ(NSMaxY(miniaturizeFrame), |
| 165 NSMaxY(windowBounds) - kChromeWindowButtonsOffsetFromTop); |
| 166 EXPECT_EQ(NSMinX(miniaturizeFrame), |
| 167 NSMaxX(closeBoxFrame) + kChromeWindowButtonsInterButtonSpacing); |
| 168 } |
| 169 |
| 170 // Test that we actually have a tracking area in place. |
| 171 TEST_F(ChromeBrowserWindowTest, WindowWidgetTrackingArea) { |
| 172 NSCell* closeBoxCell = [window_ accessibilityAttributeValue: |
| 173 NSAccessibilityCloseButtonAttribute]; |
| 174 NSView* closeBoxControl = [closeBoxCell controlView]; |
| 175 NSView* frameView = [[window_ contentView] superview]; |
| 176 NSArray* trackingAreas = [frameView trackingAreas]; |
| 177 NSPoint point = [closeBoxControl frame].origin; |
| 178 point.x += 1; |
| 179 point.y += 1; |
| 180 BOOL foundArea = NO; |
| 181 for (NSTrackingArea* area in trackingAreas) { |
| 182 NSRect rect = [area rect]; |
| 183 foundArea = NSPointInRect(point, rect); |
| 184 if (foundArea) { |
| 185 EXPECT_TRUE([[area owner] isEqual:window_]); |
| 186 break; |
| 187 } |
| 188 } |
| 189 EXPECT_TRUE(foundArea); |
| 190 } |
| 191 |
| 145 } // namespace | 192 } // namespace |
| OLD | NEW |