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

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

Issue 12891006: bookmarks: Remove Profile getter accessor from BookmarkModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cocoa alignments Created 7 years, 8 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/ui/cocoa/bookmarks/bookmark_bar_folder_controller.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) 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/memory/scoped_nsobject.h" 6 #include "base/memory/scoped_nsobject.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h" 8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
10 #import "chrome/browser/ui/cocoa/animation_utils.h" 10 #import "chrome/browser/ui/cocoa/animation_utils.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 return kLotsOfNodesCount; 202 return kLotsOfNodesCount;
203 } 203 }
204 204
205 // Return a simple BookmarkBarFolderController. 205 // Return a simple BookmarkBarFolderController.
206 BookmarkBarFolderControllerPong* SimpleBookmarkBarFolderController() { 206 BookmarkBarFolderControllerPong* SimpleBookmarkBarFolderController() {
207 BookmarkButton* parentButton = [[bar_ buttons] objectAtIndex:0]; 207 BookmarkButton* parentButton = [[bar_ buttons] objectAtIndex:0];
208 BookmarkBarFolderControllerPong* c = 208 BookmarkBarFolderControllerPong* c =
209 [[BookmarkBarFolderControllerPong alloc] 209 [[BookmarkBarFolderControllerPong alloc]
210 initWithParentButton:parentButton 210 initWithParentButton:parentButton
211 parentController:nil 211 parentController:nil
212 barController:bar_]; 212 barController:bar_
213 profile:profile()];
213 [c window]; // Force nib load. 214 [c window]; // Force nib load.
214 return c; 215 return c;
215 } 216 }
216 }; 217 };
217 218
218 TEST_F(BookmarkBarFolderControllerTest, InitCreateAndDelete) { 219 TEST_F(BookmarkBarFolderControllerTest, InitCreateAndDelete) {
219 scoped_nsobject<BookmarkBarFolderController> bbfc; 220 scoped_nsobject<BookmarkBarFolderController> bbfc;
220 bbfc.reset(SimpleBookmarkBarFolderController()); 221 bbfc.reset(SimpleBookmarkBarFolderController());
221 222
222 // Make sure none of the buttons overlap, that all are inside 223 // Make sure none of the buttons overlap, that all are inside
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 261
261 TEST_F(BookmarkBarFolderControllerTest, BasicPosition) { 262 TEST_F(BookmarkBarFolderControllerTest, BasicPosition) {
262 BookmarkButton* parentButton = [[bar_ buttons] objectAtIndex:0]; 263 BookmarkButton* parentButton = [[bar_ buttons] objectAtIndex:0];
263 EXPECT_TRUE(parentButton); 264 EXPECT_TRUE(parentButton);
264 265
265 // If parent is a BookmarkBarController, grow down. 266 // If parent is a BookmarkBarController, grow down.
266 scoped_nsobject<BookmarkBarFolderController> bbfc; 267 scoped_nsobject<BookmarkBarFolderController> bbfc;
267 bbfc.reset([[BookmarkBarFolderController alloc] 268 bbfc.reset([[BookmarkBarFolderController alloc]
268 initWithParentButton:parentButton 269 initWithParentButton:parentButton
269 parentController:nil 270 parentController:nil
270 barController:bar_]); 271 barController:bar_
272 profile:profile()]);
271 [bbfc window]; 273 [bbfc window];
272 NSPoint pt = [bbfc windowTopLeftForWidth:0 height:100]; // screen coords 274 NSPoint pt = [bbfc windowTopLeftForWidth:0 height:100]; // screen coords
273 NSPoint buttonOriginInWindow = 275 NSPoint buttonOriginInWindow =
274 [parentButton convertRect:[parentButton bounds] 276 [parentButton convertRect:[parentButton bounds]
275 toView:nil].origin; 277 toView:nil].origin;
276 NSPoint buttonOriginInScreen = 278 NSPoint buttonOriginInScreen =
277 [[parentButton window] convertBaseToScreen:buttonOriginInWindow]; 279 [[parentButton window] convertBaseToScreen:buttonOriginInWindow];
278 // Within margin 280 // Within margin
279 EXPECT_LE(abs(pt.x - buttonOriginInScreen.x), 281 EXPECT_LE(abs(pt.x - buttonOriginInScreen.x),
280 bookmarks::kBookmarkMenuOverlap + 1); 282 bookmarks::kBookmarkMenuOverlap + 1);
281 EXPECT_LE(abs(pt.y - buttonOriginInScreen.y), 283 EXPECT_LE(abs(pt.y - buttonOriginInScreen.y),
282 bookmarks::kBookmarkMenuOverlap + 1); 284 bookmarks::kBookmarkMenuOverlap + 1);
283 285
284 // Make sure we see the window shift left if it spills off the screen 286 // Make sure we see the window shift left if it spills off the screen
285 pt = [bbfc windowTopLeftForWidth:0 height:100]; 287 pt = [bbfc windowTopLeftForWidth:0 height:100];
286 NSPoint shifted = [bbfc windowTopLeftForWidth:9999999 height:100]; 288 NSPoint shifted = [bbfc windowTopLeftForWidth:9999999 height:100];
287 EXPECT_LT(shifted.x, pt.x); 289 EXPECT_LT(shifted.x, pt.x);
288 290
289 // If parent is a BookmarkBarFolderController, grow right. 291 // If parent is a BookmarkBarFolderController, grow right.
290 scoped_nsobject<BookmarkBarFolderController> bbfc2; 292 scoped_nsobject<BookmarkBarFolderController> bbfc2;
291 bbfc2.reset([[BookmarkBarFolderController alloc] 293 bbfc2.reset([[BookmarkBarFolderController alloc]
292 initWithParentButton:[[bbfc buttons] objectAtIndex:0] 294 initWithParentButton:[[bbfc buttons] objectAtIndex:0]
293 parentController:bbfc.get() 295 parentController:bbfc.get()
294 barController:bar_]); 296 barController:bar_
297 profile:profile()]);
295 [bbfc2 window]; 298 [bbfc2 window];
296 pt = [bbfc2 windowTopLeftForWidth:0 height:100]; 299 pt = [bbfc2 windowTopLeftForWidth:0 height:100];
297 // We're now overlapping the window a bit. 300 // We're now overlapping the window a bit.
298 EXPECT_EQ(pt.x, NSMaxX([[bbfc.get() window] frame]) - 301 EXPECT_EQ(pt.x, NSMaxX([[bbfc.get() window] frame]) -
299 bookmarks::kBookmarkMenuOverlap); 302 bookmarks::kBookmarkMenuOverlap);
300 } 303 }
301 304
302 // Confirm we grow right until end of screen, then start growing left 305 // Confirm we grow right until end of screen, then start growing left
303 // until end of screen again, then right. 306 // until end of screen again, then right.
304 TEST_F(BookmarkBarFolderControllerTest, PositionRightLeftRight) { 307 TEST_F(BookmarkBarFolderControllerTest, PositionRightLeftRight) {
(...skipping 15 matching lines...) Expand all
320 EXPECT_TRUE(parentButton); 323 EXPECT_TRUE(parentButton);
321 324
322 // Open them all. 325 // Open them all.
323 scoped_nsobject<NSMutableArray> folder_controller_array; 326 scoped_nsobject<NSMutableArray> folder_controller_array;
324 folder_controller_array.reset([[NSMutableArray array] retain]); 327 folder_controller_array.reset([[NSMutableArray array] retain]);
325 for (i=0; i<count; i++) { 328 for (i=0; i<count; i++) {
326 BookmarkBarFolderControllerNoLevel* bbfcl = 329 BookmarkBarFolderControllerNoLevel* bbfcl =
327 [[BookmarkBarFolderControllerNoLevel alloc] 330 [[BookmarkBarFolderControllerNoLevel alloc]
328 initWithParentButton:parentButton 331 initWithParentButton:parentButton
329 parentController:parentController 332 parentController:parentController
330 barController:bar_]; 333 barController:bar_
334 profile:profile()];
331 [folder_controller_array addObject:bbfcl]; 335 [folder_controller_array addObject:bbfcl];
332 [bbfcl autorelease]; 336 [bbfcl autorelease];
333 [bbfcl window]; 337 [bbfcl window];
334 parentController = bbfcl; 338 parentController = bbfcl;
335 parentButton = [[bbfcl buttons] objectAtIndex:0]; 339 parentButton = [[bbfcl buttons] objectAtIndex:0];
336 } 340 }
337 341
338 // Make vector of all x positions. 342 // Make vector of all x positions.
339 std::vector<CGFloat> leftPositions; 343 std::vector<CGFloat> leftPositions;
340 for (i=0; i<count; i++) { 344 for (i=0; i<count; i++) {
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 @interface BookmarkBarFolderControllerDragData : BookmarkBarFolderController { 1313 @interface BookmarkBarFolderControllerDragData : BookmarkBarFolderController {
1310 const BookmarkNode* dragDataNode_; // Weak 1314 const BookmarkNode* dragDataNode_; // Weak
1311 } 1315 }
1312 - (void)setDragDataNode:(const BookmarkNode*)node; 1316 - (void)setDragDataNode:(const BookmarkNode*)node;
1313 @end 1317 @end
1314 1318
1315 @implementation BookmarkBarFolderControllerDragData 1319 @implementation BookmarkBarFolderControllerDragData
1316 1320
1317 - (id)initWithParentButton:(BookmarkButton*)button 1321 - (id)initWithParentButton:(BookmarkButton*)button
1318 parentController:(BookmarkBarFolderController*)parentController 1322 parentController:(BookmarkBarFolderController*)parentController
1319 barController:(BookmarkBarController*)barController { 1323 barController:(BookmarkBarController*)barController
1324 profile:(Profile*)profile {
1320 if ((self = [super initWithParentButton:button 1325 if ((self = [super initWithParentButton:button
1321 parentController:parentController 1326 parentController:parentController
1322 barController:barController])) { 1327 barController:barController
1328 profile:profile])) {
1323 dragDataNode_ = NULL; 1329 dragDataNode_ = NULL;
1324 } 1330 }
1325 return self; 1331 return self;
1326 } 1332 }
1327 1333
1328 - (void)setDragDataNode:(const BookmarkNode*)node { 1334 - (void)setDragDataNode:(const BookmarkNode*)node {
1329 dragDataNode_ = node; 1335 dragDataNode_ = node;
1330 } 1336 }
1331 1337
1332 - (std::vector<const BookmarkNode*>)retrieveBookmarkNodeData { 1338 - (std::vector<const BookmarkNode*>)retrieveBookmarkNodeData {
(...skipping 22 matching lines...) Expand all
1355 EXPECT_EQ(model_string, actual); 1361 EXPECT_EQ(model_string, actual);
1356 actual = model_test_utils::ModelStringFromNode(other); 1362 actual = model_test_utils::ModelStringFromNode(other);
1357 EXPECT_EQ(other_string, actual); 1363 EXPECT_EQ(other_string, actual);
1358 1364
1359 // Pop open a folder. 1365 // Pop open a folder.
1360 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"2f"]; 1366 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"2f"];
1361 scoped_nsobject<BookmarkBarFolderControllerDragData> folderController; 1367 scoped_nsobject<BookmarkBarFolderControllerDragData> folderController;
1362 folderController.reset([[BookmarkBarFolderControllerDragData alloc] 1368 folderController.reset([[BookmarkBarFolderControllerDragData alloc]
1363 initWithParentButton:button 1369 initWithParentButton:button
1364 parentController:nil 1370 parentController:nil
1365 barController:bar_]); 1371 barController:bar_
1372 profile:profile()]);
1366 BookmarkButton* targetButton = 1373 BookmarkButton* targetButton =
1367 [folderController buttonWithTitleEqualTo:@"2f1b"]; 1374 [folderController buttonWithTitleEqualTo:@"2f1b"];
1368 ASSERT_TRUE(targetButton); 1375 ASSERT_TRUE(targetButton);
1369 1376
1370 // Gen up some dragging data. 1377 // Gen up some dragging data.
1371 const BookmarkNode* newNode = other->GetChild(2); 1378 const BookmarkNode* newNode = other->GetChild(2);
1372 [folderController setDragDataNode:newNode]; 1379 [folderController setDragDataNode:newNode];
1373 scoped_nsobject<FakedDragInfo> dragInfo([[FakedDragInfo alloc] init]); 1380 scoped_nsobject<FakedDragInfo> dragInfo([[FakedDragInfo alloc] init]);
1374 [dragInfo setDropLocation:[targetButton top]]; 1381 [dragInfo setDropLocation:[targetButton top]];
1375 [folderController dragBookmarkData:(id<NSDraggingInfo>)dragInfo.get()]; 1382 [folderController dragBookmarkData:(id<NSDraggingInfo>)dragInfo.get()];
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 1420
1414 const BookmarkNode* folderNode = root->GetChild(1); 1421 const BookmarkNode* folderNode = root->GetChild(1);
1415 int oldFolderChildCount = folderNode->child_count(); 1422 int oldFolderChildCount = folderNode->child_count();
1416 1423
1417 // Pop open a folder. 1424 // Pop open a folder.
1418 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"2f"]; 1425 BookmarkButton* button = [bar_ buttonWithTitleEqualTo:@"2f"];
1419 scoped_nsobject<BookmarkBarFolderControllerDragData> folderController; 1426 scoped_nsobject<BookmarkBarFolderControllerDragData> folderController;
1420 folderController.reset([[BookmarkBarFolderControllerDragData alloc] 1427 folderController.reset([[BookmarkBarFolderControllerDragData alloc]
1421 initWithParentButton:button 1428 initWithParentButton:button
1422 parentController:nil 1429 parentController:nil
1423 barController:bar_]); 1430 barController:bar_
1431 profile:profile()]);
1424 1432
1425 // Drag a button to the trash. 1433 // Drag a button to the trash.
1426 BookmarkButton* buttonToDelete = 1434 BookmarkButton* buttonToDelete =
1427 [folderController buttonWithTitleEqualTo:@"2f1b"]; 1435 [folderController buttonWithTitleEqualTo:@"2f1b"];
1428 ASSERT_TRUE(buttonToDelete); 1436 ASSERT_TRUE(buttonToDelete);
1429 EXPECT_TRUE([folderController canDragBookmarkButtonToTrash:buttonToDelete]); 1437 EXPECT_TRUE([folderController canDragBookmarkButtonToTrash:buttonToDelete]);
1430 [folderController didDragBookmarkToTrash:buttonToDelete]; 1438 [folderController didDragBookmarkToTrash:buttonToDelete];
1431 1439
1432 // There should be one less button in the folder. 1440 // There should be one less button in the folder.
1433 int newFolderChildCount = folderNode->child_count(); 1441 int newFolderChildCount = folderNode->child_count();
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1576 DeleteBookmark([folder parentButton], profile()); 1584 DeleteBookmark([folder parentButton], profile());
1577 EXPECT_FALSE([folder folderController]); 1585 EXPECT_FALSE([folder folderController]);
1578 } 1586 }
1579 1587
1580 // TODO(jrg): draggingEntered: and draggingExited: trigger timers so 1588 // TODO(jrg): draggingEntered: and draggingExited: trigger timers so
1581 // they are hard to test. Factor out "fire timers" into routines 1589 // they are hard to test. Factor out "fire timers" into routines
1582 // which can be overridden to fire immediately to make behavior 1590 // which can be overridden to fire immediately to make behavior
1583 // confirmable. 1591 // confirmable.
1584 // There is a similar problem with mouseEnteredButton: and 1592 // There is a similar problem with mouseEnteredButton: and
1585 // mouseExitedButton:. 1593 // mouseExitedButton:.
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698