1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import <Cocoa/Cocoa.h>
7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/browser_finder.h"
11 #include "chrome/browser/ui/panels/base_panel_browser_test.h"
12 #include "chrome/browser/ui/panels/panel.h"
13 #include "content/public/test/test_utils.h"
15 typedef BasePanelBrowserTest PanelCocoaBrowserTest;
17 IN_PROC_BROWSER_TEST_F(PanelCocoaBrowserTest, MenuItems) {
18 Panel* panel = CreatePanel("Panel");
20 // Close main tabbed window.
21 content::WindowedNotificationObserver signal(
22 chrome::NOTIFICATION_BROWSER_CLOSED,
23 content::Source<Browser>(browser()));
24 chrome::CloseWindow(browser());
27 // There should be no browser windows.
28 EXPECT_EQ(0u, chrome::GetTotalBrowserCount());
30 // There should be one panel.
31 EXPECT_EQ(1, PanelManager::GetInstance()->num_panels());
33 NSMenu* mainMenu = [NSApp mainMenu];
34 EXPECT_TRUE(mainMenu);
36 // Chrome(0) File(1) ....
37 // Get File submenu. It doesn't have a command id, fetch it by index.
38 NSMenu* fileSubmenu = [[[mainMenu itemArray] objectAtIndex:1] submenu];
39 EXPECT_TRUE(fileSubmenu);
42 // Verify the items normally enabled for "all windows closed" case are
43 // also enabled when there is a panel but no browser windows on the screen.
44 NSMenuItem* item = [fileSubmenu itemWithTag:IDC_NEW_TAB];
46 EXPECT_TRUE([item isEnabled]);
48 item = [fileSubmenu itemWithTag:IDC_NEW_WINDOW];
50 EXPECT_TRUE([item isEnabled]);
52 item = [fileSubmenu itemWithTag:IDC_NEW_INCOGNITO_WINDOW];
54 EXPECT_TRUE([item isEnabled]);
56 NSMenu* historySubmenu = [[mainMenu itemWithTag:IDC_HISTORY_MENU] submenu];
57 EXPECT_TRUE(historySubmenu);
58 [historySubmenu update];
60 // These should be disabled.
61 item = [historySubmenu itemWithTag:IDC_HOME];
63 EXPECT_FALSE([item isEnabled]);
65 item = [historySubmenu itemWithTag:IDC_BACK];
67 EXPECT_FALSE([item isEnabled]);
69 item = [historySubmenu itemWithTag:IDC_FORWARD];
71 EXPECT_FALSE([item isEnabled]);
73 // 'Close Window' should be enabled because the remaining Panel is a Responder
74 // which implements performClose:, the 'action' of 'Close Window'.
75 for (NSMenuItem *i in [fileSubmenu itemArray]) {
76 if ([i action] == @selector(performClose:)) {
82 EXPECT_TRUE([item isEnabled]);