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 24 matching lines...) Expand all Loading... |
35 virtual NSMenu* BookmarkMenu() { | 35 virtual NSMenu* BookmarkMenu() { |
36 return menu_; | 36 return menu_; |
37 } | 37 } |
38 }; | 38 }; |
39 | 39 |
40 // TODO(jrg): see refactor comment in bookmark_bar_state_controller_unittest.mm | 40 // TODO(jrg): see refactor comment in bookmark_bar_state_controller_unittest.mm |
41 class BookmarkMenuBridgeTest : public PlatformTest { | 41 class BookmarkMenuBridgeTest : public PlatformTest { |
42 public: | 42 public: |
43 | 43 |
44 void SetUp() { | 44 void SetUp() { |
45 NSMenu *menu = [[NSMenu alloc] initWithTitle:@"test"]; | 45 NSMenu* menu = [[NSMenu alloc] initWithTitle:@"test"]; |
46 bridge_.reset(new TestBookmarkMenuBridge(browser_test_helper_.profile(), | 46 bridge_.reset(new TestBookmarkMenuBridge(browser_test_helper_.profile(), |
47 menu)); | 47 menu)); |
48 EXPECT_TRUE(bridge_.get()); | 48 EXPECT_TRUE(bridge_.get()); |
49 } | 49 } |
50 | 50 |
51 // We are a friend of BookmarkMenuBridge (and have access to | 51 // We are a friend of BookmarkMenuBridge (and have access to |
52 // protected methods), but none of the classes generated by TEST_F() | 52 // protected methods), but none of the classes generated by TEST_F() |
53 // are. This (and AddNodeToMenu()) are simple wrappers to let | 53 // are. This (and AddNodeToMenu()) are simple wrappers to let |
54 // derived test classes have access to protected methods. | 54 // derived test classes have access to protected methods. |
55 void ClearBookmarkMenu(BookmarkMenuBridge* bridge, NSMenu* menu) { | 55 void ClearBookmarkMenu(BookmarkMenuBridge* bridge, NSMenu* menu) { |
56 bridge->ClearBookmarkMenu(menu); | 56 bridge->ClearBookmarkMenu(menu); |
57 } | 57 } |
58 | 58 |
59 void InvalidateMenu() { bridge_->InvalidateMenu(); } | 59 void InvalidateMenu() { bridge_->InvalidateMenu(); } |
60 bool menu_is_valid() { return bridge_->menuIsValid_; } | 60 bool menu_is_valid() { return bridge_->menu_is_valid_; } |
61 | 61 |
62 void AddNodeToMenu(BookmarkMenuBridge* bridge, | 62 void AddNodeToMenu(BookmarkMenuBridge* bridge, |
63 const BookmarkNode* root, | 63 const BookmarkNode* root, |
64 NSMenu* menu) { | 64 NSMenu* menu) { |
65 bridge->AddNodeToMenu(root, menu, true); | 65 bridge->AddNodeToMenu(root, menu, true); |
66 } | 66 } |
67 | 67 |
68 void AddItemToMenu(BookmarkMenuBridge* bridge, | 68 void AddItemToMenu(BookmarkMenuBridge* bridge, |
69 int command_id, | 69 int command_id, |
70 int message_id, | 70 int message_id, |
71 const BookmarkNode* node, | 71 const BookmarkNode* node, |
72 NSMenu* menu, | 72 NSMenu* menu, |
73 bool enable) { | 73 bool enable) { |
74 bridge->AddItemToMenu(command_id, message_id, node, menu, enable); | 74 bridge->AddItemToMenu(command_id, message_id, node, menu, enable); |
75 } | 75 } |
76 | 76 |
77 NSMenuItem* MenuItemForNode(BookmarkMenuBridge* bridge, | 77 NSMenuItem* MenuItemForNode(BookmarkMenuBridge* bridge, |
78 const BookmarkNode* node) { | 78 const BookmarkNode* node) { |
79 return bridge->MenuItemForNode(node); | 79 return bridge->MenuItemForNode(node); |
80 } | 80 } |
81 | 81 |
82 NSMenuItem* AddTestMenuItem(NSMenu *menu, NSString *title, SEL selector) { | 82 NSMenuItem* AddTestMenuItem(NSMenu *menu, NSString *title, SEL selector) { |
83 NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:title action:NULL | 83 NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:title action:NULL |
84 keyEquivalent:@""] autorelease]; | 84 keyEquivalent:@""] autorelease]; |
85 if (selector) | 85 if (selector) |
86 [item setAction:selector]; | 86 [item setAction:selector]; |
87 [menu addItem:item]; | 87 [menu addItem:item]; |
88 return item; | 88 return item; |
89 } | 89 } |
90 BrowserTestHelper browser_test_helper_; | 90 BrowserTestHelper browser_test_helper_; |
91 scoped_ptr<TestBookmarkMenuBridge> bridge_; | 91 scoped_ptr<TestBookmarkMenuBridge> bridge_; |
92 }; | 92 }; |
93 | 93 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 EXPECT_TRUE([item image]); | 392 EXPECT_TRUE([item image]); |
393 | 393 |
394 model->SetTitle(node, ASCIIToUTF16("New Title")); | 394 model->SetTitle(node, ASCIIToUTF16("New Title")); |
395 | 395 |
396 item = [menu itemWithTitle:@"Test Item"]; | 396 item = [menu itemWithTitle:@"Test Item"]; |
397 EXPECT_FALSE(item); | 397 EXPECT_FALSE(item); |
398 item = [menu itemWithTitle:@"New Title"]; | 398 item = [menu itemWithTitle:@"New Title"]; |
399 EXPECT_TRUE(item); | 399 EXPECT_TRUE(item); |
400 } | 400 } |
401 | 401 |
OLD | NEW |