1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Cocoa/Cocoa.h>
#include "base/basictypes.h"
#include "base/scoped_nsobject.h"
#import "chrome/browser/cocoa/bookmark_bar_constants.h" // namespace bookmarks
#import "chrome/browser/cocoa/bookmark_bar_controller.h"
#import "chrome/browser/cocoa/bookmark_bar_folder_button_cell.h"
#import "chrome/browser/cocoa/bookmark_bar_folder_controller.h"
#import "chrome/browser/cocoa/bookmark_bar_unittest_helper.h"
#include "chrome/browser/cocoa/browser_test_helper.h"
#import "chrome/browser/cocoa/cocoa_test_helper.h"
#import "chrome/browser/cocoa/view_resizer_pong.h"
#include "chrome/test/model_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
// Add a redirect to make testing easier.
@interface BookmarkBarFolderController(MakeTestingEasier)
- (IBAction)openBookmarkFolderFromButton:(id)sender;
@end
@implementation BookmarkBarFolderController(MakeTestingEasier)
- (IBAction)openBookmarkFolderFromButton:(id)sender {
[[self folderTarget] openBookmarkFolderFromButton:sender];
}
@end
// Don't use a high window level when running unit tests -- it'll
// interfere with anything else you are working on.
@interface BookmarkBarFolderControllerLow : BookmarkBarFolderController {
BOOL realTopLeft_; // Use the real windowTopLeft call?
}
@property BOOL realTopLeft;
@end
@implementation BookmarkBarFolderControllerLow
@synthesize realTopLeft = realTopLeft_;
- (void)configureWindowLevel {
// Intentionally empty.
}
- (NSPoint)windowTopLeft {
return realTopLeft_ ? [super windowTopLeft] : NSMakePoint(200,200);
}
@end
@interface BookmarkBarFolderControllerPong : BookmarkBarFolderControllerLow {
BOOL childFolderWillShow_;
BOOL childFolderWillClose_;
}
@property(readonly) BOOL childFolderWillShow;
@property(readonly) BOOL childFolderWillClose;
@end
@implementation BookmarkBarFolderControllerPong
@synthesize childFolderWillShow = childFolderWillShow_;
@synthesize childFolderWillClose = childFolderWillClose_;
- (void)childFolderWillShow:(id<BookmarkButtonControllerProtocol>)child {
childFolderWillShow_ = YES;
}
- (void)childFolderWillClose:(id<BookmarkButtonControllerProtocol>)child {
childFolderWillClose_ = YES;
}
// We don't have a real BookmarkBarController as our parent root so
// we fake this one out.
- (void)closeAllBookmarkFolders {
[self closeBookmarkFolder:self];
}
@end
namespace {
const int kLotsOfNodesCount = 150;
};
class BookmarkBarFolderControllerTest : public CocoaTest {
public:
BrowserTestHelper helper_;
scoped_nsobject<BookmarkBarController> parentBarController_;
const BookmarkNode* folderA_; // owned by model
const BookmarkNode* longTitleNode_; // owned by model
BookmarkBarFolderControllerTest() {
BookmarkModel* model = helper_.profile()->GetBookmarkModel();
const BookmarkNode* parent = model->GetBookmarkBarNode();
const BookmarkNode* folderA = model->AddGroup(parent,
parent->GetChildCount(),
L"group");
folderA_ = folderA;
model->AddGroup(parent, parent->GetChildCount(),
L"sibbling group");
const BookmarkNode* folderB = model->AddGroup(folderA,
folderA->GetChildCount(),
L"subgroup 1");
model->AddGroup(folderA,
folderA->GetChildCount(),
L"subgroup 2");
model->AddURL(folderA, folderA->GetChildCount(), L"title a",
GURL("http://www.google.com/a"));
longTitleNode_ = model->AddURL(
folderA, folderA->GetChildCount(),
L"title super duper long long whoa momma title you betcha",
GURL("http://www.google.com/b"));
model->AddURL(folderB, folderB->GetChildCount(), L"t",
GURL("http://www.google.com/c"));
parentBarController_.reset(
[[BookmarkBarController alloc]
initWithBrowser:helper_.browser()
initialWidth:300
delegate:nil
resizeDelegate:nil]);
[parentBarController_ loaded:model];
[[test_window() contentView] addSubview:[parentBarController_ view]];
}
// Remove the bookmark with the long title.
void RemoveLongTitleNode() {
BookmarkModel* model = helper_.profile()->GetBookmarkModel();
model->Remove(longTitleNode_->GetParent(),
longTitleNode_->GetParent()->IndexOfChild(longTitleNode_));
}
// Add LOTS of nodes to our model if needed (e.g. scrolling).
// Returns the number of nodes added.
int AddLotsOfNodes() {
BookmarkModel* model = helper_.profile()->GetBookmarkModel();
for (int i = 0; i < kLotsOfNodesCount; i++) {
model->AddURL(folderA_, folderA_->GetChildCount(), L"repeated title",
GURL("http://www.google.com/repeated/url"));
}
return kLotsOfNodesCount;
}
// Return a simple BookmarkBarFolderController.
BookmarkBarFolderController* SimpleBookmarkBarFolderController() {
BookmarkButton* parentButton = [[parentBarController_ buttons]
objectAtIndex:0];
BookmarkBarFolderController* c =
[[BookmarkBarFolderControllerPong alloc]
initWithParentButton:parentButton
parentController:nil
barController:parentBarController_];
[c window]; // Force nib load.
return c;
}
};
TEST_F(BookmarkBarFolderControllerTest, InitCreateAndDelete) {
scoped_nsobject<BookmarkBarFolderController> bbfc;
bbfc.reset(SimpleBookmarkBarFolderController());
// Make sure none of the buttons overlap, that all are inside
// the content frame, and their cells are of the proper class.
NSArray* buttons = [bbfc buttons];
EXPECT_TRUE([buttons count]);
for (unsigned int i = 0; i < ([buttons count]-1); i++) {
EXPECT_FALSE(NSContainsRect([[buttons objectAtIndex:i] frame],
[[buttons objectAtIndex:i+1] frame]));
}
Class cellClass = [BookmarkBarFolderButtonCell class];
for (BookmarkButton* button in buttons) {
NSRect r = [[bbfc mainView] convertRect:[button frame] fromView:button];
EXPECT_TRUE(NSContainsRect([[bbfc mainView] frame], r));
EXPECT_TRUE([[button cell] isKindOfClass:cellClass]);
}
// Confirm folder buttons have no tooltip. The important thing
// really is that we insure folders and non-folders are treated
// differently; not sure of any other generic way to do this.
for (BookmarkButton* button in buttons) {
if ([button isFolder])
EXPECT_FALSE([button toolTip]);
else
EXPECT_TRUE([button toolTip]);
}
}
// Make sure closing of the window releases the controller.
// (e.g. valgrind shouldn't complain if we do this).
TEST_F(BookmarkBarFolderControllerTest, ReleaseOnClose) {
scoped_nsobject<BookmarkBarFolderController> bbfc;
bbfc.reset(SimpleBookmarkBarFolderController());
EXPECT_TRUE(bbfc.get());
[bbfc retain]; // stop the scoped_nsobject from doing anything
[[bbfc window] close]; // trigger an autorelease of bbfc.get()
}
TEST_F(BookmarkBarFolderControllerTest, Position) {
BookmarkButton* parentButton = [[parentBarController_ buttons]
objectAtIndex:0];
EXPECT_TRUE(parentButton);
// If parent is a BookmarkBarController, grow down.
scoped_nsobject<BookmarkBarFolderControllerLow> bbfc;
bbfc.reset([[BookmarkBarFolderControllerLow alloc]
initWithParentButton:parentButton
parentController:nil
barController:parentBarController_]);
[bbfc window];
[bbfc setRealTopLeft:YES];
NSPoint pt = [bbfc windowTopLeft]; // screen coords
NSPoint buttonOriginInScreen =
[[parentButton window]
convertBaseToScreen:[parentButton
convertRectToBase:[parentButton frame]].origin];
// Within margin
EXPECT_LE(abs(pt.x - buttonOriginInScreen.x), 2);
EXPECT_LE(abs(pt.y - buttonOriginInScreen.y), 2);
// If parent is a BookmarkBarFolderController, grow right.
scoped_nsobject<BookmarkBarFolderControllerLow> bbfc2;
bbfc2.reset([[BookmarkBarFolderControllerLow alloc]
initWithParentButton:[[bbfc buttons] objectAtIndex:0]
parentController:bbfc.get()
barController:parentBarController_]);
[bbfc2 window];
[bbfc2 setRealTopLeft:YES];
pt = [bbfc2 windowTopLeft];
// We're now overlapping the window a bit.
EXPECT_EQ(pt.x, NSMaxX([[bbfc.get() window] frame]) - 1);
}
TEST_F(BookmarkBarFolderControllerTest, DropDestination) {
scoped_nsobject<BookmarkBarFolderController> bbfc;
bbfc.reset(SimpleBookmarkBarFolderController());
EXPECT_TRUE(bbfc.get());
// Confirm "off the top" and "off the bottom" match no buttons.
NSPoint p = NSMakePoint(NSMidX([[bbfc mainView] frame]), 10000);
EXPECT_FALSE([bbfc buttonForDroppingOnAtPoint:p]);
EXPECT_TRUE([bbfc shouldShowIndicatorShownForPoint:p]);
p = NSMakePoint(NSMidX([[bbfc mainView] frame]), -1);
EXPECT_FALSE([bbfc buttonForDroppingOnAtPoint:p]);
EXPECT_TRUE([bbfc shouldShowIndicatorShownForPoint:p]);
// Confirm "right in the center" (give or take a pixel) is a match,
// and confirm "just barely in the button" is not. Anything more
// specific seems likely to be tweaked. We don't loop over all
// buttons because the scroll view makes them not visible.
for (BookmarkButton* button in [bbfc buttons]) {
CGFloat x = NSMidX([button frame]);
CGFloat y = NSMidY([button frame]);
// Somewhere near the center: a match (but only if a folder!)
if ([button isFolder]) {
EXPECT_EQ(button,
[bbfc buttonForDroppingOnAtPoint:NSMakePoint(x-1, y+1)]);
EXPECT_EQ(button,
[bbfc buttonForDroppingOnAtPoint:NSMakePoint(x+1, y-1)]);
EXPECT_FALSE([bbfc shouldShowIndicatorShownForPoint:NSMakePoint(x, y)]);;
} else {
// If not a folder we don't drop into it.
EXPECT_FALSE([bbfc buttonForDroppingOnAtPoint:NSMakePoint(x-1, y+1)]);
EXPECT_FALSE([bbfc buttonForDroppingOnAtPoint:NSMakePoint(x+1, y-1)]);
EXPECT_TRUE([bbfc shouldShowIndicatorShownForPoint:NSMakePoint(x, y)]);;
}
}
}
TEST_F(BookmarkBarFolderControllerTest, OpenFolder) {
scoped_nsobject<BookmarkBarFolderController> bbfc;
bbfc.reset(SimpleBookmarkBarFolderController());
EXPECT_TRUE(bbfc.get());
EXPECT_FALSE([bbfc folderController]);
BookmarkButton* button = [[bbfc buttons] objectAtIndex:0];
[bbfc openBookmarkFolderFromButton:button];
id controller = [bbfc folderController];
EXPECT_TRUE(controller);
EXPECT_EQ([controller parentButton], button);
// Click the same one --> it gets closed.
[bbfc openBookmarkFolderFromButton:[[bbfc buttons] objectAtIndex:0]];
EXPECT_FALSE([bbfc folderController]);
// Open a new one --> change.
[bbfc openBookmarkFolderFromButton:[[bbfc buttons] objectAtIndex:1]];
EXPECT_NE(controller, [bbfc folderController]);
EXPECT_NE([[bbfc folderController] parentButton], button);
// Close it --> all gone!
[bbfc closeBookmarkFolder:nil];
EXPECT_FALSE([bbfc folderController]);
}
TEST_F(BookmarkBarFolderControllerTest, ChildFolderCallbacks) {
scoped_nsobject<BookmarkBarFolderControllerPong> bbfc;
bbfc.reset(SimpleBookmarkBarFolderController());
EXPECT_TRUE(bbfc.get());
EXPECT_FALSE([bbfc childFolderWillShow]);
[bbfc openBookmarkFolderFromButton:[[bbfc buttons] objectAtIndex:0]];
EXPECT_TRUE([bbfc childFolderWillShow]);
EXPECT_FALSE([bbfc childFolderWillClose]);
[bbfc closeBookmarkFolder:nil];
EXPECT_TRUE([bbfc childFolderWillClose]);
}
// Make sure bookmark folders have variable widths.
TEST_F(BookmarkBarFolderControllerTest, ChildFolderWidth) {
scoped_nsobject<BookmarkBarFolderController> bbfc;
bbfc.reset(SimpleBookmarkBarFolderController());
EXPECT_TRUE(bbfc.get());
[bbfc showWindow:bbfc.get()];
CGFloat wideWidth = NSWidth([[bbfc window] frame]);
RemoveLongTitleNode();
bbfc.reset(SimpleBookmarkBarFolderController());
EXPECT_TRUE(bbfc.get());
CGFloat thinWidth = NSWidth([[bbfc window] frame]);
// Make sure window size changed as expected.
EXPECT_GT(wideWidth, thinWidth);
}
// Simple scrolling tests.
TEST_F(BookmarkBarFolderControllerTest, SimpleScroll) {
scoped_nsobject<BookmarkBarFolderController> bbfc;
int nodecount = AddLotsOfNodes();
bbfc.reset(SimpleBookmarkBarFolderController());
EXPECT_TRUE(bbfc.get());
[bbfc showWindow:bbfc.get()];
// Make sure the window fits on the screen.
EXPECT_LT(NSHeight([[bbfc window] frame]),
NSHeight([[NSScreen mainScreen] frame]));
// Verify the logic used by the scroll arrow code.
EXPECT_TRUE([bbfc canScrollUp]);
EXPECT_FALSE([bbfc canScrollDown]);
// Scroll it up. Make sure the window has gotten bigger each time.
// Also, for each scroll, make sure our hit test finds a new button
// (to confirm the content area changed).
NSView* savedHit = nil;
for (int i=0; i<3; i++) {
CGFloat height = NSHeight([[bbfc window] frame]);
[bbfc performOneScroll:60];
EXPECT_GT(NSHeight([[bbfc window] frame]), height);
NSView* hit = [[[bbfc window] contentView] hitTest:NSMakePoint(22, 22)];
EXPECT_NE(hit, savedHit);
savedHit = hit;
}
// Keep scrolling up; make sure we never get bigger than the screen.
// Also confirm we never scroll the window off the screen.
bool bothAtOnce = false;
NSRect screenFrame = [[NSScreen mainScreen] frame];
for (int i = 0; i < nodecount; i++) {
[bbfc performOneScroll:60];
EXPECT_TRUE(NSContainsRect(screenFrame,
[[bbfc window] frame]));
// Make sure, sometime during our scroll, we have the ability to
// scroll in either direction.
if ([bbfc canScrollUp] &&
[bbfc canScrollDown])
bothAtOnce = true;
}
EXPECT_TRUE(bothAtOnce);
// Once we've scrolled to the end, our only option should be to scroll back.
EXPECT_FALSE([bbfc canScrollUp]);
EXPECT_TRUE([bbfc canScrollDown]);
// Now scroll down and make sure the window size does not change.
// Also confirm we never scroll the window off the screen the other
// way.
for (int i=0; i<nodecount+50; i++) {
CGFloat height = NSHeight([[bbfc window] frame]);
[bbfc performOneScroll:-60];
EXPECT_EQ(height, NSHeight([[bbfc window] frame]));
EXPECT_TRUE(NSContainsRect(screenFrame,
[[bbfc window] frame]));
}
}
class BookmarkBarFolderControllerDragDropTest : public CocoaTest {
public:
BrowserTestHelper helper_;
scoped_nsobject<NSView> parent_view_;
scoped_nsobject<ViewResizerPong> resizeDelegate_;
scoped_nsobject<BookmarkBarController> bar_;
BookmarkBarFolderControllerDragDropTest() {
resizeDelegate_.reset([[ViewResizerPong alloc] init]);
NSRect parent_frame = NSMakeRect(0, 0, 800, 50);
parent_view_.reset([[NSView alloc] initWithFrame:parent_frame]);
[parent_view_ setHidden:YES];
bar_.reset([[BookmarkBarController alloc]
initWithBrowser:helper_.browser()
initialWidth:NSWidth(parent_frame)
delegate:nil
resizeDelegate:resizeDelegate_.get()]);
InstallAndToggleBar(bar_.get());
}
void InstallAndToggleBar(BookmarkBarController* bar) {
// Force loading of the nib.
[bar view];
// Awkwardness to look like we've been installed.
[parent_view_ addSubview:[bar view]];
NSRect frame = [[[bar view] superview] frame];
frame.origin.y = 100;
[[[bar view] superview] setFrame:frame];
// Make sure it's on in a window so viewDidMoveToWindow is called
[[test_window() contentView] addSubview:parent_view_];
// Make sure it's open so certain things aren't no-ops.
[bar updateAndShowNormalBar:YES
showDetachedBar:NO
withAnimation:NO];
}
};
#if CGFLOAT_IS_DOUBLE
#define CGFLOAT_EPSILON DBL_EPSILON
#else
#define CGFLOAT_EPSILON FLT_EPSILON
#endif
#define CGFLOAT_EQ(expected, actual) \
(actual >= (expected - CGFLOAT_EPSILON) && \
actual <= (expected + CGFLOAT_EPSILON))
#define EXPECT_CGFLOAT_EQ(expected, actual) \
EXPECT_TRUE(CGFLOAT_EQ(actual, expected)
#define EXPECT_NSRECT_EQ(expected, actual) \
EXPECT_TRUE(CGFLOAT_EQ(expected.origin.x, actual.origin.x) && \
CGFLOAT_EQ(expected.origin.y, actual.origin.y) && \
CGFLOAT_EQ(expected.size.width, actual.size.width) && \
CGFLOAT_EQ(expected.size.height, actual.size.height)) << \
"Rects do not match: " << \
[NSStringFromRect(expected) UTF8String] << \
" != " << [NSStringFromRect(actual) UTF8String];
TEST_F(BookmarkBarFolderControllerDragDropTest, DragMoveBarBookmarkToFolder) {
BookmarkModel& model(*helper_.profile()->GetBookmarkModel());
const BookmarkNode* root = model.GetBookmarkBarNode();
const std::wstring model_string(L"1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b "
"2f2f3b ] 2f3b ] 3b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f:[ 4f2f1b "
"4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b ");
model_test_utils::AddNodesFromModelString(model, root, model_string);
// Validate initial model.
std::wstring actualModelString = model_test_utils::ModelStringFromNode(root);
EXPECT_EQ(model_string, actualModelString);
// Pop up a folder menu and drag in a button from the bar.
BookmarkButton* toFolder = [bar_ buttonWithTitleEqualTo:@"2f"];
NSRect oldToFolderFrame = [toFolder frame];
[[toFolder target] performSelector:@selector(openBookmarkFolderFromButton:)
withObject:toFolder];
BookmarkBarFolderController* folderController = [bar_ folderController];
EXPECT_TRUE(folderController);
NSWindow* toWindow = [folderController window];
EXPECT_TRUE(toWindow);
NSRect oldToWindowFrame = [toWindow frame];
// Drag a bar button onto a bookmark (i.e. not a folder) in a folder
// so it should end up below the target bookmark.
BookmarkButton* draggedButton = [bar_ buttonWithTitleEqualTo:@"1b"];
ASSERT_TRUE(draggedButton);
CGFloat horizontalShift =
NSWidth([draggedButton frame]) + bookmarks::kBookmarkHorizontalPadding;
BookmarkButton* targetButton = [folderController buttonWithTitleEqualTo:@"2f1b"];
ASSERT_TRUE(targetButton);
[folderController dragButton:draggedButton
to:[targetButton center]
copy:NO];
// The button should have landed just after "2f1b".
const std::wstring expected_string(L"2f:[ 2f1b 1b 2f2f:[ 2f2f1b "
"2f2f2b 2f2f3b ] 2f3b ] 3b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f:[ "
"4f2f1b 4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b ");
EXPECT_EQ(expected_string, model_test_utils::ModelStringFromNode(root));
// Verify the window still appears by looking for its controller.
EXPECT_TRUE([bar_ folderController]);
// Gather the new frames.
NSRect newToFolderFrame = [toFolder frame];
NSRect newToWindowFrame = [toWindow frame];
// The toFolder should have shifted left horizontally but not vertically.
NSRect expectedToFolderFrame =
NSOffsetRect(oldToFolderFrame, -horizontalShift, 0);
EXPECT_NSRECT_EQ(expectedToFolderFrame, newToFolderFrame);
// The toWindow should have shifted left horizontally, down vertically,
// and grown vertically.
NSRect expectedToWindowFrame = oldToWindowFrame;
expectedToWindowFrame.origin.x -= horizontalShift;
expectedToWindowFrame.origin.y -= bookmarks::kBookmarkBarHeight;
expectedToWindowFrame.size.height += bookmarks::kBookmarkBarHeight;
EXPECT_NSRECT_EQ(expectedToWindowFrame, newToWindowFrame);
// Move the button back to the bar at the beginning.
draggedButton = [folderController buttonWithTitleEqualTo:@"1b"];
ASSERT_TRUE(draggedButton);
targetButton = [bar_ buttonWithTitleEqualTo:@"2f"];
ASSERT_TRUE(targetButton);
[bar_ dragButton:draggedButton
to:[targetButton left]
copy:NO];
EXPECT_EQ(model_string, model_test_utils::ModelStringFromNode(root));
// Don't check the folder window since it's not supposed to be showing.
}
TEST_F(BookmarkBarFolderControllerDragDropTest, DragCopyBarBookmarkToFolder) {
BookmarkModel& model(*helper_.profile()->GetBookmarkModel());
const BookmarkNode* root = model.GetBookmarkBarNode();
const std::wstring model_string(L"1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b "
"2f2f3b ] 2f3b ] 3b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f:[ 4f2f1b "
"4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b ");
model_test_utils::AddNodesFromModelString(model, root, model_string);
// Validate initial model.
std::wstring actualModelString = model_test_utils::ModelStringFromNode(root);
EXPECT_EQ(model_string, actualModelString);
// Pop up a folder menu and copy in a button from the bar.
BookmarkButton* toFolder = [bar_ buttonWithTitleEqualTo:@"2f"];
ASSERT_TRUE(toFolder);
NSRect oldToFolderFrame = [toFolder frame];
[[toFolder target] performSelector:@selector(openBookmarkFolderFromButton:)
withObject:toFolder];
BookmarkBarFolderController* folderController = [bar_ folderController];
EXPECT_TRUE(folderController);
NSWindow* toWindow = [folderController window];
EXPECT_TRUE(toWindow);
NSRect oldToWindowFrame = [toWindow frame];
// Drag a bar button onto a bookmark (i.e. not a folder) in a folder
// so it should end up below the target bookmark.
BookmarkButton* draggedButton = [bar_ buttonWithTitleEqualTo:@"1b"];
ASSERT_TRUE(draggedButton);
BookmarkButton* targetButton = [folderController buttonWithTitleEqualTo:@"2f1b"];
ASSERT_TRUE(targetButton);
[folderController dragButton:draggedButton
to:[targetButton center]
copy:YES];
// The button should have landed just after "2f1b".
const std::wstring expected_1(L"1b 2f:[ 2f1b 1b 2f2f:[ 2f2f1b "
"2f2f2b 2f2f3b ] 2f3b ] 3b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f:[ "
"4f2f1b 4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b ");
EXPECT_EQ(expected_1, model_test_utils::ModelStringFromNode(root));
// Gather the new frames.
NSRect newToFolderFrame = [toFolder frame];
NSRect newToWindowFrame = [toWindow frame];
// The toFolder should have shifted.
EXPECT_NSRECT_EQ(oldToFolderFrame, newToFolderFrame);
// The toWindow should have shifted down vertically and grown vertically.
NSRect expectedToWindowFrame = oldToWindowFrame;
expectedToWindowFrame.origin.y -= bookmarks::kBookmarkBarHeight;
expectedToWindowFrame.size.height += bookmarks::kBookmarkBarHeight;
EXPECT_NSRECT_EQ(expectedToWindowFrame, newToWindowFrame);
// Copy the button back to the bar after "3b".
draggedButton = [folderController buttonWithTitleEqualTo:@"1b"];
ASSERT_TRUE(draggedButton);
targetButton = [bar_ buttonWithTitleEqualTo:@"4f"];
ASSERT_TRUE(targetButton);
[bar_ dragButton:draggedButton
to:[targetButton left]
copy:YES];
const std::wstring expected_2(L"1b 2f:[ 2f1b 1b 2f2f:[ 2f2f1b "
"2f2f2b 2f2f3b ] 2f3b ] 3b 1b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f:[ "
"4f2f1b 4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b ");
EXPECT_EQ(expected_2, model_test_utils::ModelStringFromNode(root));
}
TEST_F(BookmarkBarFolderControllerDragDropTest,
DragMoveBarBookmarkToSubfolder) {
BookmarkModel& model(*helper_.profile()->GetBookmarkModel());
const BookmarkNode* root = model.GetBookmarkBarNode();
const std::wstring model_string(L"1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b "
"2f2f3b ] 2f3b ] 3b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f:[ 4f2f1b "
"4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b ");
model_test_utils::AddNodesFromModelString(model, root, model_string);
// Validate initial model.
std::wstring actualModelString = model_test_utils::ModelStringFromNode(root);
EXPECT_EQ(model_string, actualModelString);
// Pop up a folder menu and a subfolder menu.
BookmarkButton* toFolder = [bar_ buttonWithTitleEqualTo:@"4f"];
ASSERT_TRUE(toFolder);
[[toFolder target] performSelector:@selector(openBookmarkFolderFromButton:)
withObject:toFolder];
BookmarkBarFolderController* folderController = [bar_ folderController];
EXPECT_TRUE(folderController);
NSWindow* toWindow = [folderController window];
EXPECT_TRUE(toWindow);
NSRect oldToWindowFrame = [toWindow frame];
BookmarkButton* toSubfolder = [folderController buttonWithTitleEqualTo:@"4f2f"];
ASSERT_TRUE(toSubfolder);
NSRect oldToSubfolderFrame = [toSubfolder frame];
[[toSubfolder target] performSelector:@selector(openBookmarkFolderFromButton:)
withObject:toSubfolder];
BookmarkBarFolderController* subfolderController =
[folderController folderController];
EXPECT_TRUE(subfolderController);
NSWindow* toSubwindow = [subfolderController window];
EXPECT_TRUE(toSubwindow);
NSRect oldToSubwindowFrame = [toSubwindow frame];
// Drag a bar button onto a bookmark (i.e. not a folder) in a folder
// so it should end up below the target bookmark.
BookmarkButton* draggedButton = [bar_ buttonWithTitleEqualTo:@"5b"];
ASSERT_TRUE(draggedButton);
BookmarkButton* targetButton =
[subfolderController buttonWithTitleEqualTo:@"4f2f3b"];
ASSERT_TRUE(targetButton);
[subfolderController dragButton:draggedButton
to:[targetButton center]
copy:NO];
// The button should have landed just after "2f".
const std::wstring expected_string(L"1b 2f:[ 2f1b 2f2f:[ 2f2f1b "
"2f2f2b 2f2f3b ] 2f3b ] 3b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f:[ "
"4f2f1b 4f2f2b 4f2f3b 5b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] ");
EXPECT_EQ(expected_string, model_test_utils::ModelStringFromNode(root));
// Check the window layouts. The folder window should not have changed,
// but the subfolder window should have shifted vertically and grown.
NSRect newToWindowFrame = [toWindow frame];
EXPECT_NSRECT_EQ(oldToWindowFrame, newToWindowFrame);
NSRect newToSubwindowFrame = [toSubwindow frame];
NSRect expectedToSubwindowFrame = oldToSubwindowFrame;
expectedToSubwindowFrame.origin.y -= bookmarks::kBookmarkBarHeight;
expectedToSubwindowFrame.size.height += bookmarks::kBookmarkBarHeight;
EXPECT_NSRECT_EQ(expectedToSubwindowFrame, newToSubwindowFrame);
}
TEST_F(BookmarkBarFolderControllerDragDropTest, DragMoveWithinFolder) {
BookmarkModel& model(*helper_.profile()->GetBookmarkModel());
const BookmarkNode* root = model.GetBookmarkBarNode();
const std::wstring model_string(L"1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b "
"2f2f3b ] 2f3b ] 3b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f:[ 4f2f1b "
"4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b ");
model_test_utils::AddNodesFromModelString(model, root, model_string);
// Validate initial model.
std::wstring actualModelString = model_test_utils::ModelStringFromNode(root);
EXPECT_EQ(model_string, actualModelString);
// Pop up a folder menu.
BookmarkButton* toFolder = [bar_ buttonWithTitleEqualTo:@"4f"];
ASSERT_TRUE(toFolder);
[[toFolder target] performSelector:@selector(openBookmarkFolderFromButton:)
withObject:toFolder];
BookmarkBarFolderController* folderController = [bar_ folderController];
EXPECT_TRUE(folderController);
NSWindow* toWindow = [folderController window];
EXPECT_TRUE(toWindow);
NSRect oldToWindowFrame = [toWindow frame];
// Drag a folder button to the top within the same parent.
BookmarkButton* draggedButton = [folderController buttonWithTitleEqualTo:@"4f2f"];
ASSERT_TRUE(draggedButton);
BookmarkButton* targetButton = [folderController buttonWithTitleEqualTo:@"4f1f"];
ASSERT_TRUE(targetButton);
[folderController dragButton:draggedButton
to:[targetButton top]
copy:NO];
// The button should have landed above "4f1f".
const std::wstring expected_string(L"1b 2f:[ 2f1b 2f2f:[ 2f2f1b "
"2f2f2b 2f2f3b ] 2f3b ] 3b 4f:[ 4f2f:[ 4f2f1b 4f2f2b 4f2f3b ] "
"4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b ");
EXPECT_EQ(expected_string, model_test_utils::ModelStringFromNode(root));
// The window should not have gone away.
EXPECT_TRUE([bar_ folderController]);
// The folder window should not have changed.
NSRect newToWindowFrame = [toWindow frame];
EXPECT_NSRECT_EQ(oldToWindowFrame, newToWindowFrame);
}
TEST_F(BookmarkBarFolderControllerDragDropTest, DragParentOntoChild) {
BookmarkModel& model(*helper_.profile()->GetBookmarkModel());
const BookmarkNode* root = model.GetBookmarkBarNode();
const std::wstring model_string(L"1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b "
"2f2f3b ] 2f3b ] 3b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f:[ 4f2f1b "
"4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b ");
model_test_utils::AddNodesFromModelString(model, root, model_string);
// Validate initial model.
std::wstring actualModelString = model_test_utils::ModelStringFromNode(root);
EXPECT_EQ(model_string, actualModelString);
// Pop up a folder menu.
BookmarkButton* toFolder = [bar_ buttonWithTitleEqualTo:@"4f"];
ASSERT_TRUE(toFolder);
[[toFolder target] performSelector:@selector(openBookmarkFolderFromButton:)
withObject:toFolder];
BookmarkBarFolderController* folderController = [bar_ folderController];
EXPECT_TRUE(folderController);
NSWindow* toWindow = [folderController window];
EXPECT_TRUE(toWindow);
// Drag a folder button to one of its children.
BookmarkButton* draggedButton = [bar_ buttonWithTitleEqualTo:@"4f"];
ASSERT_TRUE(draggedButton);
BookmarkButton* targetButton = [folderController buttonWithTitleEqualTo:@"4f3f"];
ASSERT_TRUE(targetButton);
[folderController dragButton:draggedButton
to:[targetButton top]
copy:NO];
// The model should not have changed.
EXPECT_EQ(model_string, model_test_utils::ModelStringFromNode(root));
}
TEST_F(BookmarkBarFolderControllerDragDropTest, DragMoveChildToParent) {
BookmarkModel& model(*helper_.profile()->GetBookmarkModel());
const BookmarkNode* root = model.GetBookmarkBarNode();
const std::wstring model_string(L"1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b "
"2f2f3b ] 2f3b ] 3b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f:[ 4f2f1b "
"4f2f2b 4f2f3b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b ");
model_test_utils::AddNodesFromModelString(model, root, model_string);
// Validate initial model.
std::wstring actualModelString = model_test_utils::ModelStringFromNode(root);
EXPECT_EQ(model_string, actualModelString);
// Pop up a folder menu and a subfolder menu.
BookmarkButton* toFolder = [bar_ buttonWithTitleEqualTo:@"4f"];
ASSERT_TRUE(toFolder);
[[toFolder target] performSelector:@selector(openBookmarkFolderFromButton:)
withObject:toFolder];
BookmarkBarFolderController* folderController = [bar_ folderController];
EXPECT_TRUE(folderController);
BookmarkButton* toSubfolder = [folderController buttonWithTitleEqualTo:@"4f2f"];
ASSERT_TRUE(toSubfolder);
[[toSubfolder target] performSelector:@selector(openBookmarkFolderFromButton:)
withObject:toSubfolder];
BookmarkBarFolderController* subfolderController =
[folderController folderController];
EXPECT_TRUE(subfolderController);
// Drag a subfolder bookmark to the parent folder.
BookmarkButton* draggedButton =
[subfolderController buttonWithTitleEqualTo:@"4f2f3b"];
ASSERT_TRUE(draggedButton);
BookmarkButton* targetButton = [folderController buttonWithTitleEqualTo:@"4f2f"];
ASSERT_TRUE(targetButton);
[folderController dragButton:draggedButton
to:[targetButton top]
copy:NO];
// The button should have landed above "4f2f".
const std::wstring expected_string(L"1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b "
"2f2f3b ] 2f3b ] 3b 4f:[ 4f1f:[ 4f1f1b 4f1f2b 4f1f3b ] 4f2f3b 4f2f:[ "
"4f2f1b 4f2f2b ] 4f3f:[ 4f3f1b 4f3f2b 4f3f3b ] ] 5b ");
EXPECT_EQ(expected_string, model_test_utils::ModelStringFromNode(root));
// The window should not have gone away.
EXPECT_TRUE([bar_ folderController]);
// The subfolder should have gone away.
EXPECT_FALSE([folderController folderController]);
}
TEST_F(BookmarkBarFolderControllerDragDropTest, DragWindowResizing) {
BookmarkModel& model(*helper_.profile()->GetBookmarkModel());
const BookmarkNode* root = model.GetBookmarkBarNode();
const std::wstring
model_string(L"a b:[ b1 b2 b3 ] reallyReallyLongBookmarkName c ");
model_test_utils::AddNodesFromModelString(model, root, model_string);
// Validate initial model.
std::wstring actualModelString = model_test_utils::ModelStringFromNode(root);
EXPECT_EQ(model_string, actualModelString);
// Pop up a folder menu.
BookmarkButton* toFolder = [bar_ buttonWithTitleEqualTo:@"b"];
ASSERT_TRUE(toFolder);
[[toFolder target] performSelector:@selector(openBookmarkFolderFromButton:)
withObject:toFolder];
BookmarkBarFolderController* folderController = [bar_ folderController];
EXPECT_TRUE(folderController);
NSWindow* toWindow = [folderController window];
EXPECT_TRUE(toWindow);
CGFloat oldWidth = NSWidth([toWindow frame]);
// Drag the bookmark with a long name to the folder.
BookmarkButton* draggedButton =
[bar_ buttonWithTitleEqualTo:@"reallyReallyLongBookmarkName"];
ASSERT_TRUE(draggedButton);
BookmarkButton* targetButton = [folderController buttonWithTitleEqualTo:@"b1"];
ASSERT_TRUE(targetButton);
[folderController dragButton:draggedButton
to:[targetButton center]
copy:NO];
// Verify the model change.
const std::wstring
expected_string(L"a b:[ b1 reallyReallyLongBookmarkName b2 b3 ] c ");
EXPECT_EQ(expected_string, model_test_utils::ModelStringFromNode(root));
// Verify the window grew. Just test a reasonable width gain.
CGFloat newWidth = NSWidth([toWindow frame]);
EXPECT_LT(oldWidth + 30.0, newWidth);
}
TEST_F(BookmarkBarFolderControllerDragDropTest, MoveRemoveAddButtons) {
BookmarkModel& model(*helper_.profile()->GetBookmarkModel());
const BookmarkNode* root = model.GetBookmarkBarNode();
const std::wstring model_string(L"1b 2f:[ 2f1b 2f2b 2f3b ] 3b 4b ");
model_test_utils::AddNodesFromModelString(model, root, model_string);
// Validate initial model.
std::wstring actualModelString = model_test_utils::ModelStringFromNode(root);
EXPECT_EQ(model_string, actualModelString);
// Pop up a folder menu.
BookmarkButton* toFolder = [bar_ buttonWithTitleEqualTo:@"2f"];
ASSERT_TRUE(toFolder);
[[toFolder target] performSelector:@selector(openBookmarkFolderFromButton:)
withObject:toFolder];
BookmarkBarFolderController* folder = [bar_ folderController];
EXPECT_TRUE(folder);
// Remember how many buttons are showing.
NSArray* buttons = [folder buttons];
NSUInteger oldDisplayedButtons = [buttons count];
// Move a button around a bit.
[folder moveButtonFromIndex:0 toIndex:2];
EXPECT_TRUE([[[buttons objectAtIndex:0] title] isEqualToString:@"2f2b"]);
EXPECT_TRUE([[[buttons objectAtIndex:1] title] isEqualToString:@"2f3b"]);
EXPECT_TRUE([[[buttons objectAtIndex:2] title] isEqualToString:@"2f1b"]);
EXPECT_EQ(oldDisplayedButtons, [buttons count]);
[folder moveButtonFromIndex:2 toIndex:0];
EXPECT_TRUE([[[buttons objectAtIndex:0] title] isEqualToString:@"2f1b"]);
EXPECT_TRUE([[[buttons objectAtIndex:1] title] isEqualToString:@"2f2b"]);
EXPECT_TRUE([[[buttons objectAtIndex:2] title] isEqualToString:@"2f3b"]);
EXPECT_EQ(oldDisplayedButtons, [buttons count]);
// Add a couple of buttons.
const BookmarkNode* node = root->GetChild(2); // Purloin an existing node.
[folder addButtonForNode:node atIndex:0];
EXPECT_TRUE([[[buttons objectAtIndex:0] title] isEqualToString:@"3b"]);
EXPECT_TRUE([[[buttons objectAtIndex:1] title] isEqualToString:@"2f1b"]);
EXPECT_TRUE([[[buttons objectAtIndex:2] title] isEqualToString:@"2f2b"]);
EXPECT_TRUE([[[buttons objectAtIndex:3] title] isEqualToString:@"2f3b"]);
EXPECT_EQ(oldDisplayedButtons + 1, [buttons count]);
node = root->GetChild(3);
[folder addButtonForNode:node atIndex:-1];
EXPECT_TRUE([[[buttons objectAtIndex:0] title] isEqualToString:@"3b"]);
EXPECT_TRUE([[[buttons objectAtIndex:1] title] isEqualToString:@"2f1b"]);
EXPECT_TRUE([[[buttons objectAtIndex:2] title] isEqualToString:@"2f2b"]);
EXPECT_TRUE([[[buttons objectAtIndex:3] title] isEqualToString:@"2f3b"]);
EXPECT_TRUE([[[buttons objectAtIndex:4] title] isEqualToString:@"4b"]);
EXPECT_EQ(oldDisplayedButtons + 2, [buttons count]);
// Remove a couple of buttons.
[folder removeButton:4 animate:NO];
[folder removeButton:1 animate:NO];
EXPECT_TRUE([[[buttons objectAtIndex:0] title] isEqualToString:@"3b"]);
EXPECT_TRUE([[[buttons objectAtIndex:1] title] isEqualToString:@"2f2b"]);
EXPECT_TRUE([[[buttons objectAtIndex:2] title] isEqualToString:@"2f3b"]);
EXPECT_EQ(oldDisplayedButtons, [buttons count]);
}
TEST_F(BookmarkBarFolderControllerDragDropTest, ControllerForNode) {
BookmarkModel& model(*helper_.profile()->GetBookmarkModel());
const BookmarkNode* root = model.GetBookmarkBarNode();
const std::wstring model_string(L"1b 2f:[ 2f1b 2f2b ] 3b ");
model_test_utils::AddNodesFromModelString(model, root, model_string);
// Validate initial model.
std::wstring actualModelString = model_test_utils::ModelStringFromNode(root);
EXPECT_EQ(model_string, actualModelString);
// Find the main bar controller.
const void* expectedController = bar_;
const void* actualController = [bar_ controllerForNode:root];
EXPECT_EQ(expectedController, actualController);
// Pop up the folder menu.
BookmarkButton* targetFolder = [bar_ buttonWithTitleEqualTo:@"2f"];
ASSERT_TRUE(targetFolder);
[[targetFolder target]
performSelector:@selector(openBookmarkFolderFromButton:)
withObject:targetFolder];
BookmarkBarFolderController* folder = [bar_ folderController];
EXPECT_TRUE(folder);
// Find the folder controller using the folder controller.
const BookmarkNode* targetNode = root->GetChild(1);
expectedController = folder;
actualController = [bar_ controllerForNode:targetNode];
EXPECT_EQ(expectedController, actualController);
// Find the folder controller from the bar.
actualController = [folder controllerForNode:targetNode];
EXPECT_EQ(expectedController, actualController);
}
@interface BookmarkBarControllerNoDelete : BookmarkBarController
- (IBAction)deleteBookmark:(id)sender;
@end
@implementation BookmarkBarControllerNoDelete
- (IBAction)deleteBookmark:(id)sender {
// NOP
}
@end
class BookmarkBarFolderControllerClosingTest : public
BookmarkBarFolderControllerDragDropTest {
public:
BookmarkBarFolderControllerClosingTest() {
bar_.reset([[BookmarkBarControllerNoDelete alloc]
initWithBrowser:helper_.browser()
initialWidth:NSWidth([parent_view_ frame])
delegate:nil
resizeDelegate:resizeDelegate_.get()]);
InstallAndToggleBar(bar_.get());
}
};
TEST_F(BookmarkBarFolderControllerClosingTest, DeleteClosesFolder) {
BookmarkModel& model(*helper_.profile()->GetBookmarkModel());
const BookmarkNode* root = model.GetBookmarkBarNode();
const std::wstring model_string(L"1b 2f:[ 2f1b 2f2f:[ 2f2f1b 2f2f2b ] "
"2f3b ] 3b ");
model_test_utils::AddNodesFromModelString(model, root, model_string);
// Validate initial model.
std::wstring actualModelString = model_test_utils::ModelStringFromNode(root);
EXPECT_EQ(model_string, actualModelString);
// Open the folder menu and submenu.
BookmarkButton* target = [bar_ buttonWithTitleEqualTo:@"2f"];
ASSERT_TRUE(target);
[[target target] performSelector:@selector(openBookmarkFolderFromButton:)
withObject:target];
BookmarkBarFolderController* folder = [bar_ folderController];
EXPECT_TRUE(folder);
BookmarkButton* subTarget = [folder buttonWithTitleEqualTo:@"2f2f"];
ASSERT_TRUE(subTarget);
[[subTarget target] performSelector:@selector(openBookmarkFolderFromButton:)
withObject:subTarget];
BookmarkBarFolderController* subFolder = [folder folderController];
EXPECT_TRUE(subFolder);
// Delete the folder node and verify the window closed down by looking
// for its controller again.
[folder deleteBookmark:folder];
EXPECT_FALSE([folder folderController]);
}
// TODO(jrg): draggingEntered: and draggingExited: trigger timers so
// they are hard to test. Factor out "fire timers" into routines
// which can be overridden to fire immediately to make behavior
// confirmable.
// There is a similar problem with mouseEnteredButton: and
// mouseExitedButton:.
|