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

Unified Diff: chrome/browser/ui/cocoa/apps/app_menu_controller_mac_browsertest.mm

Issue 22867009: Swap main menu with app-specific menu when app window focused. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/apps/app_menu_controller_mac_browsertest.mm
diff --git a/chrome/browser/ui/cocoa/apps/app_menu_controller_mac_browsertest.mm b/chrome/browser/ui/cocoa/apps/app_menu_controller_mac_browsertest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..88c6400dc72244fecc05d18f45e3ba7077840980
--- /dev/null
+++ b/chrome/browser/ui/cocoa/apps/app_menu_controller_mac_browsertest.mm
@@ -0,0 +1,88 @@
+// Copyright (c) 2013 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 "chrome/browser/ui/cocoa/apps/app_menu_controller_mac.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "apps/shell_window_registry.h"
+#include "base/command_line.h"
+#include "base/mac/scoped_nsobject.h"
+#include "base/strings/sys_string_conversions.h"
+#include "chrome/browser/extensions/extension_test_message_listener.h"
+#include "chrome/browser/extensions/platform_app_browsertest_util.h"
+#import "chrome/common/chrome_switches.h"
+#include "chrome/common/extensions/extension.h"
+
+namespace {
+
+class AppMenuControllerBrowserTest
+ : public extensions::PlatformAppBrowserTest {
+ protected:
+ AppMenuControllerBrowserTest() {}
+};
+
+// Test that focusing an app window changes the menu bar.
+IN_PROC_BROWSER_TEST_F(AppMenuControllerBrowserTest,
+ PlatformAppFocusUpdatesMenuBar) {
+ // Start two apps and wait for them to be launched.
+ ExtensionTestMessageListener listener_1("Launched", false);
+ const extensions::Extension* app_1 =
+ InstallAndLaunchPlatformApp("minimal_id");
+ ASSERT_TRUE(listener_1.WaitUntilSatisfied());
+ ExtensionTestMessageListener listener_2("Launched", false);
+ const extensions::Extension* app_2 =
+ InstallAndLaunchPlatformApp("minimal");
+ ASSERT_TRUE(listener_2.WaitUntilSatisfied());
+
+ NSMenu* main_menu = [NSApp mainMenu];
+ NSUInteger initial_menu_item_count = [[main_menu itemArray] count];
+
+ // When an app is focused, all Chrome menu items should be hidden, and a menu
+ // item for the app should be added.
+ apps::ShellWindow* app_1_shell_window =
+ apps::ShellWindowRegistry::Get(profile())->
+ GetShellWindowsForApp(app_1->id()).front();
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:NSWindowDidBecomeMainNotification
+ object:app_1_shell_window->GetNativeWindow()];
+ NSArray* item_array = [main_menu itemArray];
+ EXPECT_EQ(initial_menu_item_count + 1, [item_array count]);
+ for (NSUInteger i = 0; i < initial_menu_item_count; ++i)
+ EXPECT_TRUE([[item_array objectAtIndex:i] isHidden]);
+ NSMenuItem* last_item = [item_array lastObject];
+ EXPECT_EQ(app_1->id(), base::SysNSStringToUTF8([last_item title]));
+ EXPECT_EQ(app_1->name(),
+ base::SysNSStringToUTF8([[last_item submenu] title]));
+ EXPECT_FALSE([last_item isHidden]);
+
+ // When another app is focused, the menu item for the app should change.
+ apps::ShellWindow* app_2_shell_window =
+ apps::ShellWindowRegistry::Get(profile())->
+ GetShellWindowsForApp(app_2->id()).front();
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:NSWindowDidBecomeMainNotification
+ object:app_2_shell_window->GetNativeWindow()];
+ item_array = [main_menu itemArray];
+ EXPECT_EQ(initial_menu_item_count + 1, [item_array count]);
+ for (NSUInteger i = 0; i < initial_menu_item_count; ++i)
+ EXPECT_TRUE([[item_array objectAtIndex:i] isHidden]);
+ last_item = [item_array lastObject];
+ EXPECT_EQ(app_2->id(), base::SysNSStringToUTF8([last_item title]));
+ EXPECT_EQ(app_2->name(),
+ base::SysNSStringToUTF8([[last_item submenu] title]));
+ EXPECT_FALSE([last_item isHidden]);
+
+ // When the app window loses focus, the menu items for the app should be
+ // removed.
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:NSWindowDidResignMainNotification
+ object:app_2_shell_window->GetNativeWindow()];
+ item_array = [main_menu itemArray];
+ EXPECT_EQ(initial_menu_item_count, [item_array count]);
+ for (NSUInteger i = 0; i < initial_menu_item_count; ++i)
+ EXPECT_FALSE([[item_array objectAtIndex:i] isHidden]);
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698