[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / panels / panel_cocoa_browsertest.mm
blob6f8cc1c2d16c24b1b7a76d762517f7a1795339a7
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());
25   signal.Wait();
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);
40   [fileSubmenu update];
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];
45   EXPECT_TRUE(item);
46   EXPECT_TRUE([item isEnabled]);
48   item = [fileSubmenu itemWithTag:IDC_NEW_WINDOW];
49   EXPECT_TRUE(item);
50   EXPECT_TRUE([item isEnabled]);
52   item = [fileSubmenu itemWithTag:IDC_NEW_INCOGNITO_WINDOW];
53   EXPECT_TRUE(item);
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];
62   EXPECT_TRUE(item);
63   EXPECT_FALSE([item isEnabled]);
65   item = [historySubmenu itemWithTag:IDC_BACK];
66   EXPECT_TRUE(item);
67   EXPECT_FALSE([item isEnabled]);
69   item = [historySubmenu itemWithTag:IDC_FORWARD];
70   EXPECT_TRUE(item);
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:)) {
77       item = i;
78       break;
79     }
80   }
81   EXPECT_TRUE(item);
82   EXPECT_TRUE([item isEnabled]);
84   panel->Close();