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

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller_unittest.mm

Issue 1105413002: Avoid conversion of index to BookmarkNode pointer unnacessarily. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/mac/scoped_nsobject.h" 6 #include "base/mac/scoped_nsobject.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" 9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h"
10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
(...skipping 19 matching lines...) Expand all
30 30
31 namespace { 31 namespace {
32 32
33 const int kLotsOfNodesCount = 150; 33 const int kLotsOfNodesCount = 150;
34 34
35 // Deletes the bookmark corresponding to |button|. 35 // Deletes the bookmark corresponding to |button|.
36 void DeleteBookmark(BookmarkButton* button, Profile* profile) { 36 void DeleteBookmark(BookmarkButton* button, Profile* profile) {
37 const BookmarkNode* node = [button bookmarkNode]; 37 const BookmarkNode* node = [button bookmarkNode];
38 if (node) { 38 if (node) {
39 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile); 39 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile);
40 model->Remove(node->parent(), node->parent()->GetIndexOf(node)); 40 model->Remove(node);
41 } 41 }
42 } 42 }
43 43
44 } // namespace 44 } // namespace
45 45
46 // Add a redirect to make testing easier. 46 // Add a redirect to make testing easier.
47 @interface BookmarkBarFolderController(MakeTestingEasier) 47 @interface BookmarkBarFolderController(MakeTestingEasier)
48 - (void)validateMenuSpacing; 48 - (void)validateMenuSpacing;
49 @end 49 @end
50 50
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 NSView* fakeToolbarView = [[[NSView alloc] initWithFrame:frame] 185 NSView* fakeToolbarView = [[[NSView alloc] initWithFrame:frame]
186 autorelease]; 186 autorelease];
187 [[test_window() contentView] addSubview:fakeToolbarView]; 187 [[test_window() contentView] addSubview:fakeToolbarView];
188 [fakeToolbarView addSubview:[bar_ view]]; 188 [fakeToolbarView addSubview:[bar_ view]];
189 [bar_ setBookmarkBarEnabled:YES]; 189 [bar_ setBookmarkBarEnabled:YES];
190 } 190 }
191 191
192 // Remove the bookmark with the long title. 192 // Remove the bookmark with the long title.
193 void RemoveLongTitleNode() { 193 void RemoveLongTitleNode() {
194 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); 194 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
195 model->Remove(longTitleNode_->parent(), 195 model->Remove(longTitleNode_);
196 longTitleNode_->parent()->GetIndexOf(longTitleNode_));
197 } 196 }
198 197
199 // Add LOTS of nodes to our model if needed (e.g. scrolling). 198 // Add LOTS of nodes to our model if needed (e.g. scrolling).
200 // Returns the number of nodes added. 199 // Returns the number of nodes added.
201 int AddLotsOfNodes() { 200 int AddLotsOfNodes() {
202 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); 201 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
203 for (int i = 0; i < kLotsOfNodesCount; i++) { 202 for (int i = 0; i < kLotsOfNodesCount; i++) {
204 model->AddURL(folderA_, folderA_->child_count(), 203 model->AddURL(folderA_, folderA_->child_count(),
205 ASCIIToUTF16("repeated title"), 204 ASCIIToUTF16("repeated title"),
206 GURL("http://www.google.com/repeated/url")); 205 GURL("http://www.google.com/repeated/url"));
(...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 while (![folderController canScrollUp] && ++tripWire < 1000) { 1314 while (![folderController canScrollUp] && ++tripWire < 1000) {
1316 model->AddURL(folder, folder->child_count(), ASCIIToUTF16("B"), 1315 model->AddURL(folder, folder->child_count(), ASCIIToUTF16("B"),
1317 GURL("http://b.com/")); 1316 GURL("http://b.com/"));
1318 } 1317 }
1319 EXPECT_TRUE([folderController canScrollUp]); 1318 EXPECT_TRUE([folderController canScrollUp]);
1320 1319
1321 // Remove one bookmark and make sure the scroll down arrow has been removed. 1320 // Remove one bookmark and make sure the scroll down arrow has been removed.
1322 // We'll remove the really long node so we can see if the buttons get resized. 1321 // We'll remove the really long node so we can see if the buttons get resized.
1323 scrollerWidth = NSWidth([folderView frame]); 1322 scrollerWidth = NSWidth([folderView frame]);
1324 buttonWidth = NSWidth([button frame]); 1323 buttonWidth = NSWidth([button frame]);
1325 model->Remove(folder, reallyWideButtonNumber); 1324 model->Remove(folder->GetChild(reallyWideButtonNumber));
1326 EXPECT_FALSE([folderController canScrollUp]); 1325 EXPECT_FALSE([folderController canScrollUp]);
1327 EXPECT_FALSE([folderController canScrollDown]); 1326 EXPECT_FALSE([folderController canScrollDown]);
1328 1327
1329 // Check the size. It should have reduced. 1328 // Check the size. It should have reduced.
1330 EXPECT_GT(scrollerWidth, NSWidth([folderView frame])); 1329 EXPECT_GT(scrollerWidth, NSWidth([folderView frame]));
1331 EXPECT_GT(buttonWidth, NSWidth([button frame])); 1330 EXPECT_GT(buttonWidth, NSWidth([button frame]));
1332 1331
1333 // Check button spacing. 1332 // Check button spacing.
1334 [folderController validateMenuSpacing]; 1333 [folderController validateMenuSpacing];
1335 } 1334 }
(...skipping 18 matching lines...) Expand all
1354 1353
1355 // Hover over a button and verify that it is now known. 1354 // Hover over a button and verify that it is now known.
1356 button = [buttons objectAtIndex:3]; 1355 button = [buttons objectAtIndex:3];
1357 BookmarkButton* buttonThatMouseIsIn = [bbfc buttonThatMouseIsIn]; 1356 BookmarkButton* buttonThatMouseIsIn = [bbfc buttonThatMouseIsIn];
1358 EXPECT_FALSE(buttonThatMouseIsIn); 1357 EXPECT_FALSE(buttonThatMouseIsIn);
1359 [bbfc mouseEnteredButton:button event:nil]; 1358 [bbfc mouseEnteredButton:button event:nil];
1360 buttonThatMouseIsIn = [bbfc buttonThatMouseIsIn]; 1359 buttonThatMouseIsIn = [bbfc buttonThatMouseIsIn];
1361 EXPECT_EQ(button, buttonThatMouseIsIn); 1360 EXPECT_EQ(button, buttonThatMouseIsIn);
1362 1361
1363 // Delete the bookmark and verify that it is now not known. 1362 // Delete the bookmark and verify that it is now not known.
1364 model->Remove(folder, 3); 1363 model->Remove(folder->GetChild(3));
1365 buttonThatMouseIsIn = [bbfc buttonThatMouseIsIn]; 1364 buttonThatMouseIsIn = [bbfc buttonThatMouseIsIn];
1366 EXPECT_FALSE(buttonThatMouseIsIn); 1365 EXPECT_FALSE(buttonThatMouseIsIn);
1367 } 1366 }
1368 1367
1369 // Just like a BookmarkBarFolderController but intercedes when providing 1368 // Just like a BookmarkBarFolderController but intercedes when providing
1370 // pasteboard drag data. 1369 // pasteboard drag data.
1371 @interface BookmarkBarFolderControllerDragData : BookmarkBarFolderController { 1370 @interface BookmarkBarFolderControllerDragData : BookmarkBarFolderController {
1372 const BookmarkNode* dragDataNode_; // Weak 1371 const BookmarkNode* dragDataNode_; // Weak
1373 } 1372 }
1374 - (void)setDragDataNode:(const BookmarkNode*)node; 1373 - (void)setDragDataNode:(const BookmarkNode*)node;
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 DeleteBookmark([folder parentButton], profile()); 1641 DeleteBookmark([folder parentButton], profile());
1643 EXPECT_FALSE([folder folderController]); 1642 EXPECT_FALSE([folder folderController]);
1644 } 1643 }
1645 1644
1646 // TODO(jrg): draggingEntered: and draggingExited: trigger timers so 1645 // TODO(jrg): draggingEntered: and draggingExited: trigger timers so
1647 // they are hard to test. Factor out "fire timers" into routines 1646 // they are hard to test. Factor out "fire timers" into routines
1648 // which can be overridden to fire immediately to make behavior 1647 // which can be overridden to fire immediately to make behavior
1649 // confirmable. 1648 // confirmable.
1650 // There is a similar problem with mouseEnteredButton: and 1649 // There is a similar problem with mouseEnteredButton: and
1651 // mouseExitedButton:. 1650 // mouseExitedButton:.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698