OLD | NEW |
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/memory/scoped_nsobject.h" | 5 #include "base/mac/scoped_nsobject.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "chrome/browser/bookmarks/bookmark_model.h" | 7 #include "chrome/browser/bookmarks/bookmark_model.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_button.h" | 9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" |
10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" | 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" |
11 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 11 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
14 #import "ui/base/test/cocoa_test_event_utils.h" | 14 #import "ui/base/test/cocoa_test_event_utils.h" |
15 | 15 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 } | 58 } |
59 @end | 59 @end |
60 | 60 |
61 namespace { | 61 namespace { |
62 | 62 |
63 class BookmarkButtonTest : public CocoaProfileTest { | 63 class BookmarkButtonTest : public CocoaProfileTest { |
64 }; | 64 }; |
65 | 65 |
66 // Make sure nothing leaks | 66 // Make sure nothing leaks |
67 TEST_F(BookmarkButtonTest, Create) { | 67 TEST_F(BookmarkButtonTest, Create) { |
68 scoped_nsobject<BookmarkButton> button; | 68 base::scoped_nsobject<BookmarkButton> button; |
69 button.reset([[BookmarkButton alloc] initWithFrame:NSMakeRect(0,0,500,500)]); | 69 button.reset([[BookmarkButton alloc] initWithFrame:NSMakeRect(0,0,500,500)]); |
70 } | 70 } |
71 | 71 |
72 // Test folder and empty node queries. | 72 // Test folder and empty node queries. |
73 TEST_F(BookmarkButtonTest, FolderAndEmptyOrNot) { | 73 TEST_F(BookmarkButtonTest, FolderAndEmptyOrNot) { |
74 scoped_nsobject<BookmarkButton> button; | 74 base::scoped_nsobject<BookmarkButton> button; |
75 scoped_nsobject<BookmarkButtonCell> cell; | 75 base::scoped_nsobject<BookmarkButtonCell> cell; |
76 | 76 |
77 button.reset([[BookmarkButton alloc] initWithFrame:NSMakeRect(0,0,500,500)]); | 77 button.reset([[BookmarkButton alloc] initWithFrame:NSMakeRect(0,0,500,500)]); |
78 cell.reset([[BookmarkButtonCell alloc] initTextCell:@"hi mom"]); | 78 cell.reset([[BookmarkButtonCell alloc] initTextCell:@"hi mom"]); |
79 [button setCell:cell]; | 79 [button setCell:cell]; |
80 | 80 |
81 EXPECT_TRUE([button isEmpty]); | 81 EXPECT_TRUE([button isEmpty]); |
82 EXPECT_FALSE([button isFolder]); | 82 EXPECT_FALSE([button isFolder]); |
83 EXPECT_FALSE([button bookmarkNode]); | 83 EXPECT_FALSE([button bookmarkNode]); |
84 | 84 |
85 NSEvent* downEvent = | 85 NSEvent* downEvent = |
(...skipping 14 matching lines...) Expand all Loading... |
100 EXPECT_FALSE([button isEmpty]); | 100 EXPECT_FALSE([button isEmpty]); |
101 EXPECT_FALSE([button isFolder]); | 101 EXPECT_FALSE([button isFolder]); |
102 EXPECT_EQ([button bookmarkNode], node); | 102 EXPECT_EQ([button bookmarkNode], node); |
103 } | 103 } |
104 | 104 |
105 TEST_F(BookmarkButtonTest, MouseEnterExitRedirect) { | 105 TEST_F(BookmarkButtonTest, MouseEnterExitRedirect) { |
106 NSEvent* moveEvent = | 106 NSEvent* moveEvent = |
107 cocoa_test_event_utils::MouseEventAtPoint(NSMakePoint(10,10), | 107 cocoa_test_event_utils::MouseEventAtPoint(NSMakePoint(10,10), |
108 NSMouseMoved, | 108 NSMouseMoved, |
109 0); | 109 0); |
110 scoped_nsobject<BookmarkButton> button; | 110 base::scoped_nsobject<BookmarkButton> button; |
111 scoped_nsobject<BookmarkButtonCell> cell; | 111 base::scoped_nsobject<BookmarkButtonCell> cell; |
112 scoped_nsobject<FakeButtonDelegate> | 112 base::scoped_nsobject<FakeButtonDelegate> delegate( |
113 delegate([[FakeButtonDelegate alloc] init]); | 113 [[FakeButtonDelegate alloc] init]); |
114 button.reset([[BookmarkButton alloc] initWithFrame:NSMakeRect(0,0,500,500)]); | 114 button.reset([[BookmarkButton alloc] initWithFrame:NSMakeRect(0,0,500,500)]); |
115 cell.reset([[BookmarkButtonCell alloc] initTextCell:@"hi mom"]); | 115 cell.reset([[BookmarkButtonCell alloc] initTextCell:@"hi mom"]); |
116 [button setCell:cell]; | 116 [button setCell:cell]; |
117 [button setDelegate:delegate]; | 117 [button setDelegate:delegate]; |
118 | 118 |
119 EXPECT_EQ(0, delegate.get()->entered_); | 119 EXPECT_EQ(0, delegate.get()->entered_); |
120 EXPECT_EQ(0, delegate.get()->exited_); | 120 EXPECT_EQ(0, delegate.get()->exited_); |
121 | 121 |
122 [button mouseEntered:moveEvent]; | 122 [button mouseEntered:moveEvent]; |
123 EXPECT_EQ(1, delegate.get()->entered_); | 123 EXPECT_EQ(1, delegate.get()->entered_); |
124 EXPECT_EQ(0, delegate.get()->exited_); | 124 EXPECT_EQ(0, delegate.get()->exited_); |
125 | 125 |
126 [button mouseExited:moveEvent]; | 126 [button mouseExited:moveEvent]; |
127 [button mouseExited:moveEvent]; | 127 [button mouseExited:moveEvent]; |
128 EXPECT_EQ(1, delegate.get()->entered_); | 128 EXPECT_EQ(1, delegate.get()->entered_); |
129 EXPECT_EQ(2, delegate.get()->exited_); | 129 EXPECT_EQ(2, delegate.get()->exited_); |
130 } | 130 } |
131 | 131 |
132 TEST_F(BookmarkButtonTest, DragToTrash) { | 132 TEST_F(BookmarkButtonTest, DragToTrash) { |
133 scoped_nsobject<BookmarkButton> button; | 133 base::scoped_nsobject<BookmarkButton> button; |
134 scoped_nsobject<BookmarkButtonCell> cell; | 134 base::scoped_nsobject<BookmarkButtonCell> cell; |
135 scoped_nsobject<FakeButtonDelegate> | 135 base::scoped_nsobject<FakeButtonDelegate> delegate( |
136 delegate([[FakeButtonDelegate alloc] init]); | 136 [[FakeButtonDelegate alloc] init]); |
137 button.reset([[BookmarkButton alloc] initWithFrame:NSMakeRect(0,0,500,500)]); | 137 button.reset([[BookmarkButton alloc] initWithFrame:NSMakeRect(0,0,500,500)]); |
138 cell.reset([[BookmarkButtonCell alloc] initTextCell:@"hi mom"]); | 138 cell.reset([[BookmarkButtonCell alloc] initTextCell:@"hi mom"]); |
139 [button setCell:cell]; | 139 [button setCell:cell]; |
140 [button setDelegate:delegate]; | 140 [button setDelegate:delegate]; |
141 | 141 |
142 // Add a deletable bookmark to the button. | 142 // Add a deletable bookmark to the button. |
143 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 143 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
144 const BookmarkNode* barNode = model->bookmark_bar_node(); | 144 const BookmarkNode* barNode = model->bookmark_bar_node(); |
145 const BookmarkNode* node = model->AddURL(barNode, 0, ASCIIToUTF16("hi mom"), | 145 const BookmarkNode* node = model->AddURL(barNode, 0, ASCIIToUTF16("hi mom"), |
146 GURL("http://www.google.com")); | 146 GURL("http://www.google.com")); |
(...skipping 20 matching lines...) Expand all Loading... |
167 EXPECT_EQ(0, delegate.get()->didDragToTrashCount_); | 167 EXPECT_EQ(0, delegate.get()->didDragToTrashCount_); |
168 [button draggedImage:nil endedAt:NSZeroPoint operation:NSDragOperationCopy]; | 168 [button draggedImage:nil endedAt:NSZeroPoint operation:NSDragOperationCopy]; |
169 EXPECT_EQ(0, delegate.get()->didDragToTrashCount_); | 169 EXPECT_EQ(0, delegate.get()->didDragToTrashCount_); |
170 [button draggedImage:nil endedAt:NSZeroPoint operation:NSDragOperationMove]; | 170 [button draggedImage:nil endedAt:NSZeroPoint operation:NSDragOperationMove]; |
171 EXPECT_EQ(0, delegate.get()->didDragToTrashCount_); | 171 EXPECT_EQ(0, delegate.get()->didDragToTrashCount_); |
172 [button draggedImage:nil endedAt:NSZeroPoint operation:NSDragOperationDelete]; | 172 [button draggedImage:nil endedAt:NSZeroPoint operation:NSDragOperationDelete]; |
173 EXPECT_EQ(1, delegate.get()->didDragToTrashCount_); | 173 EXPECT_EQ(1, delegate.get()->didDragToTrashCount_); |
174 } | 174 } |
175 | 175 |
176 } | 176 } |
OLD | NEW |