diff options
author | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-03 17:57:30 +0000 |
---|---|---|
committer | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-03 17:57:30 +0000 |
commit | 71c0eb9125f569d127fe0c5dedc0066628e4bb8c (patch) | |
tree | 0b47f9a6f51f8070897a2f8d956925c8f5f53e4e /chrome/app/nibs | |
parent | a18130a5bfdeba5556c2bee55817064da72a343b (diff) | |
download | chromium_src-71c0eb9125f569d127fe0c5dedc0066628e4bb8c.zip chromium_src-71c0eb9125f569d127fe0c5dedc0066628e4bb8c.tar.gz chromium_src-71c0eb9125f569d127fe0c5dedc0066628e4bb8c.tar.bz2 |
Fix Lion dictionary popup staying after tab-close via cmd-W.
This was caused by the close menu item not sending a -[performClose:],
which was what the popup was looking for.
Adds some unit tests and refactors some code to make it more testable.
BUG=104931
TEST=Open a tab and double 3-finger tap on a word to bring up the
dictionary popup. Hit cmd-W. The popup should close but they tab
should stay open. Hit cmd-W again. The tab should close.
Try cmd-shift-W with > 1 tab open. The window should close.
Review URL: http://codereview.chromium.org/9026016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116144 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/app/nibs')
-rw-r--r-- | chrome/app/nibs/MainMenu.xib | 18 | ||||
-rw-r--r-- | chrome/app/nibs/main_menu_unittest.mm | 60 |
2 files changed, 69 insertions, 9 deletions
diff --git a/chrome/app/nibs/MainMenu.xib b/chrome/app/nibs/MainMenu.xib index 09fd8d3..247cd96 100644 --- a/chrome/app/nibs/MainMenu.xib +++ b/chrome/app/nibs/MainMenu.xib @@ -1450,14 +1450,6 @@ <object class="IBActionConnection" key="connection"> <string key="label">commandDispatch:</string> <reference key="source" ref="1014"/> - <reference key="destination" ref="1059729334"/> - </object> - <int key="connectionID">528</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">commandDispatch:</string> - <reference key="source" ref="1014"/> <reference key="destination" ref="1051826322"/> </object> <int key="connectionID">529</int> @@ -1862,6 +1854,14 @@ </object> <int key="connectionID">697</int> </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">performClose:</string> + <reference key="source" ref="1014"/> + <reference key="destination" ref="1059729334"/> + </object> + <int key="connectionID">698</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -3213,7 +3213,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">697</int> + <int key="maxID">698</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> diff --git a/chrome/app/nibs/main_menu_unittest.mm b/chrome/app/nibs/main_menu_unittest.mm new file mode 100644 index 0000000..ec72d88 --- /dev/null +++ b/chrome/app/nibs/main_menu_unittest.mm @@ -0,0 +1,60 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import <Cocoa/Cocoa.h> + +#include "base/mac/foundation_util.h" +#include "base/memory/scoped_nsobject.h" +#include "chrome/app/chrome_command_ids.h" +#include "testing/platform_test.h" + +class MainMenuTest : public PlatformTest { + public: + // Recursively find the menu item with the given |tag| in |menu|. + NSMenuItem* FindMenuItemWithTag(NSMenu* menu, NSInteger tag) { + NSMenuItem* found = [menu itemWithTag:tag]; + if (found) + return found; + NSMenuItem* item; + for (item in [menu itemArray]) { + if ([item hasSubmenu]) { + found = FindMenuItemWithTag([item submenu], tag); + if (found) + return found; + } + } + return nil; + } +}; + + +TEST_F(MainMenuTest, CloseTabPerformClose) { + scoped_nsobject<NSNib> nib( + [[NSNib alloc] initWithNibNamed:@"MainMenu" + bundle:base::mac::MainAppBundle()]); + EXPECT_TRUE(nib); + + NSArray* objects = nil; + EXPECT_TRUE([nib instantiateNibWithOwner:nil + topLevelObjects:&objects]); + + // Check that "Close Tab" is mapped to -performClose:. This is needed to + // ensure the Lion dictionary pop up gets closed on Cmd-W, if it's open. + // See http://crbug.com/104931 for details. + BOOL found = NO; + for (NSUInteger i = 0; i < [objects count]; ++i) { + if ([[objects objectAtIndex:i] isKindOfClass:[NSMenu class]]) { + NSMenu* menu = [objects objectAtIndex:i]; + NSMenuItem* closeTabItem = FindMenuItemWithTag(menu, IDC_CLOSE_TAB); + if (closeTabItem) { + EXPECT_EQ(@selector(performClose:), [closeTabItem action]); + found = YES; + break; + } + } + } + EXPECT_TRUE(found); + [objects makeObjectsPerformSelector:@selector(release)]; + [NSApp setMainMenu:nil]; +} |