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

Side by Side Diff: chrome/browser/ui/cocoa/accelerators_cocoa_browsertest.mm

Issue 2950403002: [Mac] Add system share menu
Patch Set: CL comments Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/logging.h" 7 #include "base/logging.h"
8 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
9 #import "chrome/browser/ui/cocoa/accelerators_cocoa.h" 9 #import "chrome/browser/ui/cocoa/accelerators_cocoa.h"
10 #include "chrome/grit/generated_resources.h"
10 #include "chrome/test/base/in_process_browser_test.h" 11 #include "chrome/test/base/in_process_browser_test.h"
11 #include "testing/gtest_mac.h" 12 #include "testing/gtest_mac.h"
12 #include "ui/base/accelerators/platform_accelerator_cocoa.h" 13 #include "ui/base/accelerators/platform_accelerator_cocoa.h"
14 #include "ui/base/l10n/l10n_util_mac.h"
13 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" 15 #import "ui/events/keycodes/keyboard_code_conversion_mac.h"
14 16
15 typedef InProcessBrowserTest AcceleratorsCocoaBrowserTest; 17 typedef InProcessBrowserTest AcceleratorsCocoaBrowserTest;
16 18
17 namespace { 19 namespace {
18 20
19 // Adds all NSMenuItems with an accelerator to the array. 21 // Adds all NSMenuItems with an accelerator to the array.
20 void AddAcceleratorItemsToArray(NSMenu* menu, NSMutableArray* array) { 22 void AddAcceleratorItemsToArray(NSMenu* menu, NSMutableArray* array) {
21 for (NSMenuItem* item in [menu itemArray]) { 23 for (NSMenuItem* item in [menu itemArray]) {
22 NSMenu* submenu = item.submenu; 24 NSMenu* submenu = item.submenu;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 EXPECT_TRUE(maskEqual); 107 EXPECT_TRUE(maskEqual);
106 } 108 }
107 } 109 }
108 110
109 // Check that each accelerator with a command_id has an associated NSMenuItem 111 // Check that each accelerator with a command_id has an associated NSMenuItem
110 // in the main menu. If the selector is commandDispatch:, then the tag must 112 // in the main menu. If the selector is commandDispatch:, then the tag must
111 // match the command_id. 113 // match the command_id.
112 IN_PROC_BROWSER_TEST_F(AcceleratorsCocoaBrowserTest, 114 IN_PROC_BROWSER_TEST_F(AcceleratorsCocoaBrowserTest,
113 MappingAcceleratorsInMainMenu) { 115 MappingAcceleratorsInMainMenu) {
114 AcceleratorsCocoa* keymap = AcceleratorsCocoa::GetInstance(); 116 AcceleratorsCocoa* keymap = AcceleratorsCocoa::GetInstance();
117 // The "Share" menu is dynamically populated.
118 NSMenu* mainMenu = [NSApp mainMenu];
119 NSMenu* fileMenu = [[mainMenu itemWithTag:IDC_FILE_MENU] submenu];
120 NSMenu* shareMenu =
121 [[fileMenu itemWithTitle:l10n_util::GetNSString(IDS_SHARE_MAC)] submenu];
122 [[shareMenu delegate] menuNeedsUpdate:shareMenu];
123
115 for (AcceleratorsCocoa::AcceleratorMap::iterator it = 124 for (AcceleratorsCocoa::AcceleratorMap::iterator it =
116 keymap->accelerators_.begin(); 125 keymap->accelerators_.begin();
117 it != keymap->accelerators_.end(); 126 it != keymap->accelerators_.end();
118 ++it) { 127 ++it) {
119 const ui::PlatformAcceleratorCocoa* platform_accelerator = 128 const ui::PlatformAcceleratorCocoa* platform_accelerator =
120 static_cast<const ui::PlatformAcceleratorCocoa*>( 129 static_cast<const ui::PlatformAcceleratorCocoa*>(
121 it->second.platform_accelerator()); 130 it->second.platform_accelerator());
122 131
123 // Check that there exists a corresponding NSMenuItem. 132 // Check that there exists a corresponding NSMenuItem.
124 NSMenuItem* item = 133 NSMenuItem* item =
125 MenuContainsAccelerator([NSApp mainMenu], 134 MenuContainsAccelerator([NSApp mainMenu],
126 platform_accelerator->characters(), 135 platform_accelerator->characters(),
127 platform_accelerator->modifier_mask()); 136 platform_accelerator->modifier_mask());
128 EXPECT_TRUE(item); 137 EXPECT_TRUE(item);
129 138
130 // If the menu uses a commandDispatch:, the tag must match the command id! 139 // If the menu uses a commandDispatch:, the tag must match the command id!
131 // Added an exception for IDC_TOGGLE_FULLSCREEN_TOOLBAR, which conflicts 140 // Added an exception for IDC_TOGGLE_FULLSCREEN_TOOLBAR, which conflicts
132 // with IDC_PRESENTATION_MODE. 141 // with IDC_PRESENTATION_MODE.
133 if (item.action == @selector(commandDispatch:) 142 if (item.action == @selector(commandDispatch:)
134 && item.tag != IDC_TOGGLE_FULLSCREEN_TOOLBAR) 143 && item.tag != IDC_TOGGLE_FULLSCREEN_TOOLBAR)
135 EXPECT_EQ(item.tag, it->first); 144 EXPECT_EQ(item.tag, it->first);
136 } 145 }
137 } 146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698