| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <AppKit/AppKit.h> | 5 #import <AppKit/AppKit.h> |
| 6 | 6 |
| 7 #import "base/memory/scoped_nsobject.h" | 7 #import "base/memory/scoped_nsobject.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 // We are a friend of BookmarkMenuBridge (and have access to | 53 // We are a friend of BookmarkMenuBridge (and have access to |
| 54 // protected methods), but none of the classes generated by TEST_F() | 54 // protected methods), but none of the classes generated by TEST_F() |
| 55 // are. This (and AddNodeToMenu()) are simple wrappers to let | 55 // are. This (and AddNodeToMenu()) are simple wrappers to let |
| 56 // derived test classes have access to protected methods. | 56 // derived test classes have access to protected methods. |
| 57 void ClearBookmarkMenu(BookmarkMenuBridge* bridge, NSMenu* menu) { | 57 void ClearBookmarkMenu(BookmarkMenuBridge* bridge, NSMenu* menu) { |
| 58 bridge->ClearBookmarkMenu(menu); | 58 bridge->ClearBookmarkMenu(menu); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void InvalidateMenu() { bridge_->InvalidateMenu(); } | 61 void InvalidateMenu() { bridge_->InvalidateMenu(); } |
| 62 bool menu_is_valid() { return bridge_->menu_is_valid_; } | 62 bool menu_is_valid() { return bridge_->menuIsValid_; } |
| 63 void set_root_node(const BookmarkNode* node) { | |
| 64 bridge_->root_node_ = node; | |
| 65 } | |
| 66 | 63 |
| 67 void AddNodeToMenu(BookmarkMenuBridge* bridge, | 64 void AddNodeToMenu(BookmarkMenuBridge* bridge, |
| 68 const BookmarkNode* root, | 65 const BookmarkNode* root, |
| 69 NSMenu* menu) { | 66 NSMenu* menu) { |
| 70 bridge->AddNodeToMenu(root, menu, true); | 67 bridge->AddNodeToMenu(root, menu, true); |
| 71 } | 68 } |
| 72 | 69 |
| 73 void AddItemToMenu(BookmarkMenuBridge* bridge, | 70 void AddItemToMenu(BookmarkMenuBridge* bridge, |
| 74 int command_id, | 71 int command_id, |
| 75 int message_id, | 72 int message_id, |
| 76 const BookmarkNode* node, | 73 const BookmarkNode* node, |
| 77 NSMenu* menu, | 74 NSMenu* menu, |
| 78 bool enable) { | 75 bool enable) { |
| 79 bridge->AddItemToMenu(command_id, message_id, node, menu, enable); | 76 bridge->AddItemToMenu(command_id, message_id, node, menu, enable); |
| 80 } | 77 } |
| 81 | 78 |
| 82 NSMenuItem* MenuItemForNode(BookmarkMenuBridge* bridge, | 79 NSMenuItem* MenuItemForNode(BookmarkMenuBridge* bridge, |
| 83 const BookmarkNode* node) { | 80 const BookmarkNode* node) { |
| 84 return bridge->MenuItemForNode(node); | 81 return bridge->MenuItemForNode(node); |
| 85 } | 82 } |
| 86 | 83 |
| 87 NSMenuItem* AddTestMenuItem(NSMenu *menu, NSString *title, SEL selector) { | 84 NSMenuItem* AddTestMenuItem(NSMenu *menu, NSString *title, SEL selector) { |
| 88 NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:title action:NULL | 85 NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:title action:NULL |
| 89 keyEquivalent:@""] autorelease]; | 86 keyEquivalent:@""] autorelease]; |
| 90 if (selector) | 87 if (selector) |
| 91 [item setAction:selector]; | 88 [item setAction:selector]; |
| 92 [menu addItem:item]; | 89 [menu addItem:item]; |
| 93 return item; | 90 return item; |
| 94 } | 91 } |
| 95 scoped_ptr<TestBookmarkMenuBridge> bridge_; | 92 scoped_ptr<TestBookmarkMenuBridge> bridge_; |
| 96 }; | 93 }; |
| 97 | 94 |
| 98 TEST_F(BookmarkMenuBridgeTest, TestBookmarkMenuAutoSeparator) { | 95 TEST_F(BookmarkMenuBridgeTest, TestBookmarkMenuAutoSeparator) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 // e.g. http://foo becomes http://foo/) | 234 // e.g. http://foo becomes http://foo/) |
| 238 EXPECT_GE([[short_item toolTip] length], strlen(short_url) - 3); | 235 EXPECT_GE([[short_item toolTip] length], strlen(short_url) - 3); |
| 239 EXPECT_GE([[long_item toolTip] length], strlen(long_url) - 3); | 236 EXPECT_GE([[long_item toolTip] length], strlen(long_url) - 3); |
| 240 | 237 |
| 241 // Make sure the favicon is non-nil (should be either the default site | 238 // Make sure the favicon is non-nil (should be either the default site |
| 242 // icon or a favicon, if present). | 239 // icon or a favicon, if present). |
| 243 EXPECT_TRUE([short_item image]); | 240 EXPECT_TRUE([short_item image]); |
| 244 EXPECT_TRUE([long_item image]); | 241 EXPECT_TRUE([long_item image]); |
| 245 } | 242 } |
| 246 | 243 |
| 247 // Test that AddNodeToMenu() properly generates a menu for an off the side | |
| 248 // button | |
| 249 TEST_F(BookmarkMenuBridgeTest, TestOffTheSideButtonMenu) { | |
| 250 string16 empty; | |
| 251 NSMenu* menu = bridge_->menu_; | |
| 252 | |
| 253 BookmarkModel* model = bridge_->GetBookmarkModel(); | |
| 254 const BookmarkNode* root = model->bookmark_bar_node(); | |
| 255 ASSERT_TRUE(model && root); | |
| 256 | |
| 257 set_root_node(root); | |
| 258 | |
| 259 // 3 nodes; First node is not in the off the side button. Second node is in | |
| 260 // the off the side button. Third node is a folder in the off the side button | |
| 261 // and it should have one submenu. | |
| 262 model->AddURL(root, 0, ASCIIToUTF16("not in button"), GURL("http://foo")); | |
| 263 model->AddURL(root, 1, ASCIIToUTF16("in button"), GURL("http://bar")); | |
| 264 const BookmarkNode* node = model->AddFolder(root, 2, | |
| 265 ASCIIToUTF16("folder in button")); | |
| 266 // Add submenu to the folder node. | |
| 267 model->AddURL(node, 0, empty, GURL("http://sub")); | |
| 268 | |
| 269 bridge_->set_off_the_side_node_start_index(1); | |
| 270 bridge_->UpdateSubMenu(menu); | |
| 271 ASSERT_EQ(2, [menu numberOfItems]); | |
| 272 | |
| 273 // Verify that the 1st node is not in the menu. | |
| 274 NSMenuItem* item = [menu itemWithTitle:@"not in button"]; | |
| 275 EXPECT_FALSE(item); | |
| 276 | |
| 277 // Verify the 2nd node is there with the right action. | |
| 278 item = [menu itemWithTitle:@"in button"]; | |
| 279 EXPECT_TRUE(item); | |
| 280 EXPECT_EQ(@selector(openBookmarkMenuItem:), [item action]); | |
| 281 EXPECT_FALSE([item hasSubmenu]); | |
| 282 | |
| 283 item = [menu itemWithTitle:@"folder in button"]; | |
| 284 EXPECT_TRUE(item); | |
| 285 EXPECT_TRUE([item hasSubmenu]); | |
| 286 } | |
| 287 | |
| 288 // Test that AddItemToMenu() properly added versions of | 244 // Test that AddItemToMenu() properly added versions of |
| 289 // 'Open All Bookmarks' as menu items. | 245 // 'Open All Bookmarks' as menu items. |
| 290 TEST_F(BookmarkMenuBridgeTest, TestAddItemToMenu) { | 246 TEST_F(BookmarkMenuBridgeTest, TestAddItemToMenu) { |
| 291 NSString* title; | 247 NSString* title; |
| 292 NSMenuItem* item; | 248 NSMenuItem* item; |
| 293 NSMenu* menu = bridge_->menu_; | 249 NSMenu* menu = bridge_->menu_; |
| 294 | 250 |
| 295 BookmarkModel* model = bridge_->GetBookmarkModel(); | 251 BookmarkModel* model = bridge_->GetBookmarkModel(); |
| 296 const BookmarkNode* root = model->bookmark_bar_node(); | 252 const BookmarkNode* root = model->bookmark_bar_node(); |
| 297 EXPECT_TRUE(model && root); | 253 EXPECT_TRUE(model && root); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 EXPECT_TRUE([item image]); | 393 EXPECT_TRUE([item image]); |
| 438 | 394 |
| 439 model->SetTitle(node, ASCIIToUTF16("New Title")); | 395 model->SetTitle(node, ASCIIToUTF16("New Title")); |
| 440 | 396 |
| 441 item = [menu itemWithTitle:@"Test Item"]; | 397 item = [menu itemWithTitle:@"Test Item"]; |
| 442 EXPECT_FALSE(item); | 398 EXPECT_FALSE(item); |
| 443 item = [menu itemWithTitle:@"New Title"]; | 399 item = [menu itemWithTitle:@"New Title"]; |
| 444 EXPECT_TRUE(item); | 400 EXPECT_TRUE(item); |
| 445 } | 401 } |
| 446 | 402 |
| OLD | NEW |