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

Side by Side Diff: chrome/browser/cocoa/bookmark_menu_bridge_unittest.mm

Issue 53116: Fix leaks found by valgrind (which now works on the Mac!)... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/cocoa/bookmark_menu_bridge.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include "chrome/app/chrome_dll_resource.h" 6 #include "chrome/app/chrome_dll_resource.h"
7 #include "chrome/browser/browser.h" 7 #include "chrome/browser/browser.h"
8 #include "chrome/browser/cocoa/bookmark_menu_bridge.h" 8 #include "chrome/browser/cocoa/bookmark_menu_bridge.h"
9 #include "chrome/browser/cocoa/browser_test_helper.h" 9 #include "chrome/browser/cocoa/browser_test_helper.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 23 matching lines...) Expand all
34 [menu addItem:item]; 34 [menu addItem:item];
35 return item; 35 return item;
36 } 36 }
37 37
38 BrowserTestHelper browser_test_helper_; 38 BrowserTestHelper browser_test_helper_;
39 }; 39 };
40 40
41 41
42 // Test that ClearBookmarkMenu() removes all bookmark menus. 42 // Test that ClearBookmarkMenu() removes all bookmark menus.
43 TEST_F(BookmarkMenuBridgeTest, TestClearBookmarkMenu) { 43 TEST_F(BookmarkMenuBridgeTest, TestClearBookmarkMenu) {
44 BookmarkMenuBridge* bridge = new BookmarkMenuBridge(); 44 scoped_ptr<BookmarkMenuBridge> bridge(new BookmarkMenuBridge());
45 EXPECT_TRUE(bridge); 45 EXPECT_TRUE(bridge.get());
46 46
47 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"foo"] autorelease]; 47 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"foo"] autorelease];
48 48
49 AddItemToMenu(menu, @"hi mom", nil); 49 AddItemToMenu(menu, @"hi mom", nil);
50 AddItemToMenu(menu, @"not", @selector(openBookmarkMenuItem:)); 50 AddItemToMenu(menu, @"not", @selector(openBookmarkMenuItem:));
51 NSMenuItem* item = AddItemToMenu(menu, @"hi mom", nil); 51 NSMenuItem* item = AddItemToMenu(menu, @"hi mom", nil);
52 [item setSubmenu:[[[NSMenu alloc] initWithTitle:@"bar"] autorelease]]; 52 [item setSubmenu:[[[NSMenu alloc] initWithTitle:@"bar"] autorelease]];
53 AddItemToMenu(menu, @"not", @selector(openBookmarkMenuItem:)); 53 AddItemToMenu(menu, @"not", @selector(openBookmarkMenuItem:));
54 AddItemToMenu(menu, @"zippy", @selector(length)); 54 AddItemToMenu(menu, @"zippy", @selector(length));
55 55
56 ClearBookmarkMenu(bridge, menu); 56 ClearBookmarkMenu(bridge.get(), menu);
57 57
58 // Make sure all bookmark items are removed, and all items with 58 // Make sure all bookmark items are removed, and all items with
59 // submenus removed. 59 // submenus removed.
60 EXPECT_EQ(2, [menu numberOfItems]); 60 EXPECT_EQ(2, [menu numberOfItems]);
61 for (NSMenuItem *item in [menu itemArray]) { 61 for (NSMenuItem *item in [menu itemArray]) {
62 EXPECT_FALSE([[item title] isEqual:@"not"]); 62 EXPECT_FALSE([[item title] isEqual:@"not"]);
63 } 63 }
64 } 64 }
65 65
66 // Test that AddNodeToMenu() properly adds bookmark nodes as menus, 66 // Test that AddNodeToMenu() properly adds bookmark nodes as menus,
67 // including the recursive case. 67 // including the recursive case.
68 TEST_F(BookmarkMenuBridgeTest, TestAddNodeToMenu) { 68 TEST_F(BookmarkMenuBridgeTest, TestAddNodeToMenu) {
69 Profile* profile = browser_test_helper_.GetProfile(); 69 Profile* profile = browser_test_helper_.GetProfile();
70 70
71 BookmarkMenuBridge *bridge = new BookmarkMenuBridge(); 71 scoped_ptr<BookmarkMenuBridge> bridge(new BookmarkMenuBridge());
72 EXPECT_TRUE(bridge); 72 EXPECT_TRUE(bridge.get());
73 73
74 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"foo"] autorelease]; 74 NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"foo"] autorelease];
75 75
76 BookmarkModel* model = new BookmarkModel(profile); 76 BookmarkModel* model = new BookmarkModel(profile);
77 BookmarkNode* root = new BookmarkNode(model, GURL()); 77 BookmarkNode* root = new BookmarkNode(model, GURL());
78 EXPECT_TRUE(model && root); 78 EXPECT_TRUE(model && root);
79 79
80 // 3 nodes; middle one has a child 80 // 3 nodes; middle one has a child
81 BookmarkNode* node = NULL; 81 BookmarkNode* node = NULL;
82 for (int x = 0; x < 3; x++) { 82 for (int x = 0; x < 3; x++) {
83 node = new BookmarkNode(model, (x==1 ? GURL() : GURL("http://foo"))); 83 node = new BookmarkNode(model, (x==1 ? GURL() : GURL("http://foo")));
84 root->Add(x, node); 84 root->Add(x, node);
85 } 85 }
86 node = new BookmarkNode(model, GURL("http://sub")); 86 node = new BookmarkNode(model, GURL("http://sub"));
87 root->GetChild(1)->Add(0, node); 87 root->GetChild(1)->Add(0, node);
88 88
89 // Add to the NSMenu, then confirm it looks good 89 // Add to the NSMenu, then confirm it looks good
90 AddNodeToMenu(bridge, root, menu); 90 AddNodeToMenu(bridge.get(), root, menu);
91 91
92 EXPECT_EQ(3, [menu numberOfItems]); 92 EXPECT_EQ(3, [menu numberOfItems]);
93 for (int x=0; x < 3; x++) { 93 for (int x=0; x < 3; x++) {
94 NSMenuItem* item = [menu itemAtIndex:x]; 94 NSMenuItem* item = [menu itemAtIndex:x];
95 EXPECT_EQ(@selector(openBookmarkMenuItem:), [item action]); 95 EXPECT_EQ(@selector(openBookmarkMenuItem:), [item action]);
96 } 96 }
97 EXPECT_EQ(NO, [[menu itemAtIndex:0] hasSubmenu]); 97 EXPECT_EQ(NO, [[menu itemAtIndex:0] hasSubmenu]);
98 EXPECT_EQ(NO, [[menu itemAtIndex:2] hasSubmenu]); 98 EXPECT_EQ(NO, [[menu itemAtIndex:2] hasSubmenu]);
99 NSMenuItem* middle = [menu itemAtIndex:1]; 99 NSMenuItem* middle = [menu itemAtIndex:1];
100 EXPECT_NE(NO, [middle hasSubmenu]); 100 EXPECT_NE(NO, [middle hasSubmenu]);
101 EXPECT_EQ(1, [[middle submenu] numberOfItems]); 101 EXPECT_EQ(1, [[middle submenu] numberOfItems]);
102 102
103 delete root; // deletes all its kids 103 delete root; // deletes all its kids
104 delete model; 104 delete model;
105 } 105 }
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bookmark_menu_bridge.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698