blob: 4091168726329abe94ee0778988f710c2888d8bd (
plain)
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
|
// Copyright (c) 2009 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.
#include "base/scoped_nsobject.h"
#import "chrome/browser/cocoa/bookmark_bar_view.h"
#import "chrome/browser/cocoa/bookmark_button.h"
#import "chrome/browser/cocoa/cocoa_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
// Fake DraggingInfo, fake BookmarkBarController, fake pasteboard...
@interface FakeBookmarkDraggingInfo : NSObject {
scoped_nsobject<NSData> data_;
BOOL pong_;
}
@end
@implementation FakeBookmarkDraggingInfo
- (id)init {
if ((self = [super init])) {
data_.reset([[NSData dataWithBytes:&self length:sizeof(self)] retain]);
}
return self;
}
// So we can be both info and pasteboard.
- (id)draggingPasteboard {
return self;
}
// So we can look local.
- (id)draggingSource {
return self;
}
- (BOOL)containsURLData {
return NO;
}
- (NSPoint)draggingLocation {
return NSMakePoint(10, 10);
}
- (NSData*)dataForType:(NSString*)type {
if ([type isEqual:kBookmarkButtonDragType])
return data_.get();
return nil;
}
// Fake a controller for callback ponging
- (BOOL)dragButton:(BookmarkButton*)button to:(NSPoint)point {
pong_ = YES;
return YES;
}
// Confirm the pong.
- (BOOL)dragButtonToPong {
return pong_;
}
@end
namespace {
class BookmarkBarViewTest : public CocoaTest {
public:
scoped_nsobject<BookmarkBarView> view_;
};
TEST_F(BookmarkBarViewTest, CanDragWindow) {
view_.reset([[BookmarkBarView alloc] init]);
EXPECT_FALSE([view_.get() mouseDownCanMoveWindow]);
}
TEST_F(BookmarkBarViewTest, BookmarkButtonDragAndDrop) {
view_.reset([[BookmarkBarView alloc] init]);
scoped_nsobject<FakeBookmarkDraggingInfo>
info([[FakeBookmarkDraggingInfo alloc] init]);
[view_ setController:info.get()];
EXPECT_EQ([view_ draggingEntered:(id)info.get()], NSDragOperationMove);
EXPECT_TRUE([view_ performDragOperation:(id)info.get()]);
EXPECT_TRUE([info dragButtonToPong]);
}
} // namespace
|