From 71c0eb9125f569d127fe0c5dedc0066628e4bb8c Mon Sep 17 00:00:00 2001 From: "asvitkine@chromium.org" Date: Tue, 3 Jan 2012 17:57:30 +0000 Subject: 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 --- chrome/app/nibs/MainMenu.xib | 18 +++++------ chrome/app/nibs/main_menu_unittest.mm | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 chrome/app/nibs/main_menu_unittest.mm (limited to 'chrome/app/nibs') 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 @@ commandDispatch: - - - 528 - - - - commandDispatch: - 529 @@ -1862,6 +1854,14 @@ 697 + + + performClose: + + + + 698 + @@ -3213,7 +3213,7 @@ - 697 + 698 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 + +#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 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]; +} -- cgit v1.1