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

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

Issue 864153003: Added 'Find'/'Paste and Match Style' menu items for hosted apps on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test Created 5 years, 11 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_shim_menu_controller_mac_browsertest.mm
diff --git a/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac_browsertest.mm b/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac_browsertest.mm
index 663643051c1b03914fbba15a2f4b6f57b621f464..46a6900352543cabfff2a0305ef1861dc8d8197d 100644
--- a/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac_browsertest.mm
+++ b/chrome/browser/ui/cocoa/apps/app_shim_menu_controller_mac_browsertest.mm
@@ -9,8 +9,11 @@
#include "base/command_line.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
+#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/apps/app_browsertest_util.h"
+#include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h"
#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_iterator.h"
#include "chrome/browser/ui/browser_window.h"
@@ -29,6 +32,7 @@ class AppShimMenuControllerBrowserTest
AppShimMenuControllerBrowserTest()
: app_1_(NULL),
app_2_(NULL),
+ hosted_app_(NULL),
tapted 2015/01/30 00:52:48 nit: NULL -> nullptr. You can change those nearby
mitchellj 2015/01/30 02:53:38 Done.
initial_menu_item_count_(0) {}
void SetUpCommandLine(base::CommandLine* command_line) override {
@@ -43,6 +47,13 @@ class AppShimMenuControllerBrowserTest
ExtensionTestMessageListener listener_2("Launched", false);
app_2_ = InstallAndLaunchPlatformApp("minimal");
ASSERT_TRUE(listener_2.WaitUntilSatisfied());
+ hosted_app_ = InstallHostedApp();
+
+ // Explicitly set the launch type to open in a new window.
+ extensions::SetLaunchType(
+ extensions::ExtensionSystem::Get(profile())->extension_service(),
+ hosted_app_->id(), extensions::LAUNCH_TYPE_WINDOW);
+ LaunchHostedApp(hosted_app_);
initial_menu_item_count_ = [[[NSApp mainMenu] itemArray] count];
}
@@ -74,8 +85,27 @@ class AppShimMenuControllerBrowserTest
EXPECT_FALSE([[item_array objectAtIndex:i] isHidden]);
}
+ void CheckEditMenu(const extensions::Extension* app) const {
+ const int kEditMenuIndex = initial_menu_item_count_ + 2;
tapted 2015/01/30 00:52:49 nit: for function-local consts, we're meant to use
mitchellj 2015/01/30 02:53:39 Done.
+
+ NSMenuItem* editMenu =
tapted 2015/01/30 00:52:48 editMenu -> edit_menu, more below (camelCase only
mitchellj 2015/01/30 02:53:39 Done.
+ [[[NSApp mainMenu] itemArray] objectAtIndex:kEditMenuIndex];
+ NSMenu* editSubmenu = [editMenu submenu];
+ NSMenuItem* pasteAndMatchStyleMenuItem =
+ [editSubmenu itemWithTag:IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE];
+ NSMenuItem* findMenuItem = [editSubmenu itemWithTag:IDC_FIND_MENU];
+ if (app->is_hosted_app()) {
+ EXPECT_FALSE([pasteAndMatchStyleMenuItem isHidden]);
+ EXPECT_FALSE([findMenuItem isHidden]);
+ } else {
+ EXPECT_TRUE([pasteAndMatchStyleMenuItem isHidden]);
+ EXPECT_TRUE([findMenuItem isHidden]);
+ }
+ }
+
const extensions::Extension* app_1_;
const extensions::Extension* app_2_;
+ const extensions::Extension* hosted_app_;
NSUInteger initial_menu_item_count_;
private:
@@ -123,6 +153,43 @@ IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest,
CheckNoAppMenus();
}
+// Test to check that hosted apps have "Find" and "Paste and Match Style" menu
+// items under the "Edit" menu.
+IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest,
+ HostedAppHasAdditionalEditMenuItems) {
+ SetUpApps();
+
+ // Find the first hosted app window.
+ Browser* browser;
tapted 2015/01/30 00:52:48 = nullptr; And perhaps a better name, like hosted_
mitchellj 2015/01/30 02:53:38 Done.
+ BrowserList* browsers =
+ BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE);
+ for (Browser* b : *browsers) {
tapted 2015/01/30 00:52:48 `b` isn't really a common abbreviation. Maybe for
mitchellj 2015/01/30 02:53:38 Done.
+ const extensions::Extension* extension =
+ apps::ExtensionAppShimHandler::GetAppForBrowser(b);
+ if (extension && extension->is_hosted_app()) {
+ browser = b;
+ break;
+ }
+ }
+ EXPECT_TRUE(browser);
+
+ // Focus the hosted app.
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:NSWindowDidBecomeMainNotification
+ object:browser->window()->GetNativeWindow()];
+ CheckEditMenu(hosted_app_);
+
+ // Now focus a platform app, the Edit menu should not have the additional
+ // options.
+ extensions::AppWindow* app_1_app_window =
+ extensions::AppWindowRegistry::Get(profile())
+ ->GetAppWindowsForApp(app_1_->id()).front();
tapted 2015/01/30 00:52:48 Calling .front() is a bit spooky... and this is re
mitchellj 2015/01/30 02:53:39 Done.
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:NSWindowDidBecomeMainNotification
+ object:app_1_app_window->GetNativeWindow()];
+ CheckEditMenu(app_1_);
+}
+
IN_PROC_BROWSER_TEST_F(AppShimMenuControllerBrowserTest,
ExtensionUninstallUpdatesMenuBar) {
SetUpApps();

Powered by Google App Engine
This is Rietveld 408576698