summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/bookmark_menu_bridge_unittest.mm
diff options
context:
space:
mode:
authorjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-18 00:57:49 +0000
committerjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-18 00:57:49 +0000
commit44b2c885548d647611d908309dfdf6306eac7ed8 (patch)
treec46fd5199ac07df770ca9b01a0b73dc594b6d63d /chrome/browser/cocoa/bookmark_menu_bridge_unittest.mm
parent9eef357377e89bffd2d5ff9fad9de0c94d8cc934 (diff)
downloadchromium_src-44b2c885548d647611d908309dfdf6306eac7ed8.zip
chromium_src-44b2c885548d647611d908309dfdf6306eac7ed8.tar.gz
chromium_src-44b2c885548d647611d908309dfdf6306eac7ed8.tar.bz2
Mac bookmark work.
- The bookmark menu is populated dynamically with bookmarks, including subfolders --> submenus. E.g. star something --> shows up in menu. Menu items are disabled but always present and current. - Always Show Bookmarks" menu now live; reads from / writes to preference, and shows correct "toggle state". - Bookmark bar on each tab, present if requested. (Currently an empty box). - Random stuff; e.g. bookmark prefs init moved to a x-plat location. This CL does not contain Cole's views. Bried english description of the nib file changes: - add a new view for the bookmark bar in the tab; hook it up to the controller - Many tag sets (e.g. View-->Always Show Bookmarks Bar now 40009) - Remove dummy bookmark menu items Review URL: http://codereview.chromium.org/46078 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11936 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/bookmark_menu_bridge_unittest.mm')
-rw-r--r--chrome/browser/cocoa/bookmark_menu_bridge_unittest.mm107
1 files changed, 107 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/bookmark_menu_bridge_unittest.mm b/chrome/browser/cocoa/bookmark_menu_bridge_unittest.mm
new file mode 100644
index 0000000..d00f75f
--- /dev/null
+++ b/chrome/browser/cocoa/bookmark_menu_bridge_unittest.mm
@@ -0,0 +1,107 @@
+// Copyright (c) 2009 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 <AppKit/AppKit.h>
+#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/cocoa/bookmark_menu_bridge.h"
+#include "chrome/browser/cocoa/browser_test_helper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// TODO(jrg): see refactor comment in bookmark_bar_state_controller_unittest.mm
+class BookmarkMenuBridgeTest : public testing::Test {
+ public:
+
+ // We are a friend of BookmarkMenuBridge (and have access to
+ // protected methods), but none of the classes generated by TEST_F()
+ // are. This (and AddNodeToMenu()) are simple wrappers to let
+ // derived test classes have access to protected methods.
+ void ClearBookmarkMenu(BookmarkMenuBridge* bridge, NSMenu* menu) {
+ bridge->ClearBookmarkMenu(menu);
+ }
+
+ void AddNodeToMenu(BookmarkMenuBridge* bridge, BookmarkNode* root,
+ NSMenu* menu) {
+ bridge->AddNodeToMenu(root, menu);
+ }
+
+ NSMenuItem* AddItemToMenu(NSMenu *menu, NSString *title, NSInteger tag) {
+ NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:title action:NULL
+ keyEquivalent:@""] autorelease];
+ [item setTag:tag];
+ [menu addItem:item];
+ return item;
+ }
+
+ BrowserTestHelper browser_test_helper_;
+};
+
+
+// Test that ClearBookmarkMenu() removes all bookmark menus.
+TEST_F(BookmarkMenuBridgeTest, TestClearBookmarkMenu) {
+ Browser* browser = browser_test_helper_.GetBrowser();
+ BookmarkMenuBridge* bridge = new BookmarkMenuBridge(browser);
+ EXPECT_TRUE(bridge);
+
+ NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"foo"] autorelease];
+
+ AddItemToMenu(menu, @"hi mom", IDC_BOOKMARK_MENUITEM_BASE);
+ AddItemToMenu(menu, @"not", 0);
+ NSMenuItem* item = AddItemToMenu(menu, @"hi mom", 0);
+ [item setSubmenu:[[[NSMenu alloc] initWithTitle:@"bar"] autorelease]];
+ AddItemToMenu(menu, @"not", 0);
+
+ ClearBookmarkMenu(bridge, menu);
+
+ // Make sure all IDC_BOOKMARK items are removed, and all items with
+ // submenus removed.
+ EXPECT_EQ(2, [menu numberOfItems]);
+ for (NSMenuItem *item in [menu itemArray]) {
+ EXPECT_TRUE([[item title] isEqual:@"not"]);
+ }
+}
+
+// Test that AddNodeToMenu() properly adds bookmark nodes as menus,
+// including the recursive case.
+TEST_F(BookmarkMenuBridgeTest, TestAddNodeToMenu) {
+ Browser* browser = browser_test_helper_.GetBrowser();
+ Profile* profile = browser_test_helper_.GetProfile();
+
+ BookmarkMenuBridge *bridge = new BookmarkMenuBridge(browser);
+ EXPECT_TRUE(bridge);
+
+ NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"foo"] autorelease];
+
+ BookmarkModel* model = new BookmarkModel(profile);
+ BookmarkNode* root = new BookmarkNode(model, GURL());
+ EXPECT_TRUE(model && root);
+
+ // 3 nodes; middle one has a child
+ BookmarkNode* node = NULL;
+ for (int x = 0; x < 3; x++) {
+ node = new BookmarkNode(model, (x==1 ? GURL() : GURL("http://foo")));
+ root->Add(x, node);
+ }
+ node = new BookmarkNode(model, GURL("http://sub"));
+ root->GetChild(1)->Add(0, node);
+
+ // Add to the NSMenu, then confirm it looks good
+ AddNodeToMenu(bridge, root, menu);
+
+ EXPECT_EQ(3, [menu numberOfItems]);
+ for (int x=0; x < 3; x++) {
+ NSMenuItem* item = [menu itemAtIndex:x];
+ NSInteger tag = [item tag];
+ EXPECT_TRUE((tag >= IDC_BOOKMARK_MENUITEM_BASE) &&
+ (tag < IDC_BOOKMARK_MENUITEM_MAX));
+ }
+ EXPECT_EQ(NO, [[menu itemAtIndex:0] hasSubmenu]);
+ EXPECT_EQ(NO, [[menu itemAtIndex:2] hasSubmenu]);
+ NSMenuItem* middle = [menu itemAtIndex:1];
+ EXPECT_NE(NO, [middle hasSubmenu]);
+ EXPECT_EQ(1, [[middle submenu] numberOfItems]);
+
+ delete root; // deletes all its kids
+ delete model;
+}