Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(882)

Issue 5576002: Fix BrowserKeyEventsTest.ReservedAccelerators on Mac 10.6 (Closed)

Created:
10 years ago by James Su
Modified:
9 years, 7 months ago
Reviewers:
Nico, Ilya Sherman
CC:
chromium-reviews, ben+cc_chromium.org, Paweł Hajdan Jr., pam+watch_chromium.org
Visibility:
Public.

Description

Fix BrowserKeyEventsTest.ReservedAccelerators on Mac 10.6 There are two reasons that cause this problem: 1. See issue http://crbug.com/65375 2. By some reason, when BrowserWindowCocoa::PreHandleKeyboardEvent() is called for Cmd-W, it fails to get its corresponding command id, because the corresponding menu item is not enabled at that time. This CL does following changes: 1. Change testing flow to work around issue 65375. 2. Fix the second problem by always retrieving the corresponding command id regardless of the menu item's state. The reason of the second issue: When Cmd-T gets handled in NSApp, BrowserWindowController's -validateUserInterfaceItem: method will be called for all menu items to determine their enable states and the states will be cached in each menu item. At this time, because there is only one tab, the "Close Tab" menu item will be disabled. Then when sending Cmd-W to the browser, it'll firstly be handled in BrowserWindowCocoa::PreHandleKeyboardEvent() method, which will look up the command id associated to Cmd-W, but at this time, BrowserWindowController's -validateUserInterfaceItem: method does not get called yet, so the corresponding menu item is still not enabled. Then BrowserWindowCocoa::PreHandleKeyboardEvent() will not handle Cmd-W because it cannot find its command id. After removing the check in cr_firesForKeyEvent method, BrowserWindowCocoa::PreHandleKeyboardEvent() method will always get the correct command id of a key equivalent regardless of its enable state, then if it's a reserved key equivalent, it will always be sent to NSApp for handling, which will call BrowserWindowController's -validateUserInterfaceItem: to update the enable states of all menu items. Then if the corresponding menu item is really disabled, NSApp will do nothing and return false, then the key event will be dispatched to web page as normal. BUG=50447 BrowserKeyEventsTest.ReservedAccelerators failed on Mac10.6 Tests (dbg)(1) bot. TEST=The test should not flaky. Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=68369

Patch Set 1 #

Patch Set 2 : Fix the second problem. #

Patch Set 3 : Fix unittest and remove FLAKY tag. #

Total comments: 2

Patch Set 4 : Update comment. #

Total comments: 4

Patch Set 5 : Add cr_firesForKeyEventIfEnabled. #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+43 lines, -20 lines) Patch
M chrome/browser/browser_keyevents_browsertest.cc View 1 2 3 8 chunks +33 lines, -18 lines 0 comments Download
M chrome/browser/ui/cocoa/browser_window_cocoa.mm View 1 2 3 4 1 chunk +1 line, -1 line 0 comments Download
M chrome/browser/ui/cocoa/nsmenuitem_additions.h View 1 2 3 4 1 chunk +5 lines, -0 lines 0 comments Download
M chrome/browser/ui/cocoa/nsmenuitem_additions.mm View 1 2 3 4 1 chunk +4 lines, -1 line 1 comment Download

Messages

Total messages: 6 (0 generated)
James Su
I'm trying to write a test for issue 65375, but seems that it's hard to ...
10 years ago (2010-12-04 01:55:57 UTC) #1
Ilya Sherman
There is a lot of code that is reproduced in the Windows and Mac portions ...
10 years ago (2010-12-04 02:31:00 UTC) #2
James Su
For now, I'd rather to keep code of different platforms separated, which is clearer. As ...
10 years ago (2010-12-04 03:21:11 UTC) #3
Nico
LG Thanks for tracking this down, and for the great answer to Ilya's question – ...
10 years ago (2010-12-04 20:25:14 UTC) #4
James Su
CL updated. http://codereview.chromium.org/5576002/diff/7003/chrome/browser/ui/cocoa/nsmenuitem_additions.h File chrome/browser/ui/cocoa/nsmenuitem_additions.h (right): http://codereview.chromium.org/5576002/diff/7003/chrome/browser/ui/cocoa/nsmenuitem_additions.h#newcode20 chrome/browser/ui/cocoa/nsmenuitem_additions.h:20: - (BOOL)cr_firesForKeyEvent:(NSEvent*)event; On 2010/12/04 20:25:15, Nico wrote: ...
10 years ago (2010-12-06 18:37:28 UTC) #5
Ilya Sherman
10 years ago (2010-12-06 18:45:27 UTC) #6
LGTM

http://codereview.chromium.org/5576002/diff/12002/chrome/browser/ui/cocoa/nsm...
File chrome/browser/ui/cocoa/nsmenuitem_additions.mm (right):

http://codereview.chromium.org/5576002/diff/12002/chrome/browser/ui/cocoa/nsm...
chrome/browser/ui/cocoa/nsmenuitem_additions.mm:13: -
(BOOL)cr_firesForKeyEvent:(NSEvent*)event {
nit: It seems weird to me to leave this function around without any clients. 
Nico thinks it might be useful for clients outside of Chromium though.  *shrug*

Powered by Google App Engine
This is Rietveld 408576698