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/memory/scoped_nsobject.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/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 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" | 9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" |
9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu.h" | 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu.h" |
10 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 11 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 12 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
12 #include "grit/ui_resources.h" | 13 #include "grit/ui_resources.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
15 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
17 #include "ui/gfx/mac/nsimage_cache.h" | 18 #include "ui/gfx/mac/nsimage_cache.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 89 |
89 // Make sure the default from the base class is overridden. | 90 // Make sure the default from the base class is overridden. |
90 TEST_F(BookmarkButtonCellTest, MouseEnterStuff) { | 91 TEST_F(BookmarkButtonCellTest, MouseEnterStuff) { |
91 scoped_nsobject<BookmarkButtonCell> cell( | 92 scoped_nsobject<BookmarkButtonCell> cell( |
92 [[BookmarkButtonCell alloc] initTextCell:@"Testing"]); | 93 [[BookmarkButtonCell alloc] initTextCell:@"Testing"]); |
93 // Setting the menu should have no affect since we either share or | 94 // Setting the menu should have no affect since we either share or |
94 // dynamically compose the menu given a node. | 95 // dynamically compose the menu given a node. |
95 [cell setMenu:[[[BookmarkMenu alloc] initWithTitle:@"foo"] autorelease]]; | 96 [cell setMenu:[[[BookmarkMenu alloc] initWithTitle:@"foo"] autorelease]]; |
96 EXPECT_FALSE([cell menu]); | 97 EXPECT_FALSE([cell menu]); |
97 | 98 |
98 BookmarkModel* model = profile()->GetBookmarkModel(); | 99 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
99 const BookmarkNode* node = model->bookmark_bar_node(); | 100 const BookmarkNode* node = model->bookmark_bar_node(); |
100 [cell setEmpty:NO]; | 101 [cell setEmpty:NO]; |
101 [cell setBookmarkNode:node]; | 102 [cell setBookmarkNode:node]; |
102 EXPECT_TRUE([cell showsBorderOnlyWhileMouseInside]); | 103 EXPECT_TRUE([cell showsBorderOnlyWhileMouseInside]); |
103 EXPECT_TRUE([cell menu]); | 104 EXPECT_TRUE([cell menu]); |
104 | 105 |
105 [cell setEmpty:YES]; | 106 [cell setEmpty:YES]; |
106 EXPECT_FALSE([cell.get() showsBorderOnlyWhileMouseInside]); | 107 EXPECT_FALSE([cell.get() showsBorderOnlyWhileMouseInside]); |
107 EXPECT_FALSE([cell menu]); | 108 EXPECT_FALSE([cell menu]); |
108 } | 109 } |
109 | 110 |
110 TEST_F(BookmarkButtonCellTest, BookmarkNode) { | 111 TEST_F(BookmarkButtonCellTest, BookmarkNode) { |
111 BookmarkModel& model(*(profile()->GetBookmarkModel())); | 112 BookmarkModel& model(*(BookmarkModelFactory::GetForProfile(profile()))); |
112 scoped_nsobject<BookmarkButtonCell> cell( | 113 scoped_nsobject<BookmarkButtonCell> cell( |
113 [[BookmarkButtonCell alloc] initTextCell:@"Testing"]); | 114 [[BookmarkButtonCell alloc] initTextCell:@"Testing"]); |
114 | 115 |
115 const BookmarkNode* node = model.bookmark_bar_node(); | 116 const BookmarkNode* node = model.bookmark_bar_node(); |
116 [cell setBookmarkNode:node]; | 117 [cell setBookmarkNode:node]; |
117 EXPECT_EQ(node, [cell bookmarkNode]); | 118 EXPECT_EQ(node, [cell bookmarkNode]); |
118 | 119 |
119 node = model.other_node(); | 120 node = model.other_node(); |
120 [cell setBookmarkNode:node]; | 121 [cell setBookmarkNode:node]; |
121 EXPECT_EQ(node, [cell bookmarkNode]); | 122 EXPECT_EQ(node, [cell bookmarkNode]); |
(...skipping 28 matching lines...) Expand all Loading... |
150 | 151 |
151 // Confirms a cell created in a nib is initialized properly | 152 // Confirms a cell created in a nib is initialized properly |
152 TEST_F(BookmarkButtonCellTest, Awake) { | 153 TEST_F(BookmarkButtonCellTest, Awake) { |
153 scoped_nsobject<BookmarkButtonCell> cell([[BookmarkButtonCell alloc] init]); | 154 scoped_nsobject<BookmarkButtonCell> cell([[BookmarkButtonCell alloc] init]); |
154 [cell awakeFromNib]; | 155 [cell awakeFromNib]; |
155 EXPECT_EQ(NSLeftTextAlignment, [cell alignment]); | 156 EXPECT_EQ(NSLeftTextAlignment, [cell alignment]); |
156 } | 157 } |
157 | 158 |
158 // Subfolder arrow details. | 159 // Subfolder arrow details. |
159 TEST_F(BookmarkButtonCellTest, FolderArrow) { | 160 TEST_F(BookmarkButtonCellTest, FolderArrow) { |
160 BookmarkModel* model = profile()->GetBookmarkModel(); | 161 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
161 const BookmarkNode* bar = model->bookmark_bar_node(); | 162 const BookmarkNode* bar = model->bookmark_bar_node(); |
162 const BookmarkNode* node = model->AddURL(bar, bar->child_count(), | 163 const BookmarkNode* node = model->AddURL(bar, bar->child_count(), |
163 ASCIIToUTF16("title"), | 164 ASCIIToUTF16("title"), |
164 GURL("http://www.google.com")); | 165 GURL("http://www.google.com")); |
165 scoped_nsobject<BookmarkButtonCell> cell( | 166 scoped_nsobject<BookmarkButtonCell> cell( |
166 [[BookmarkButtonCell alloc] initForNode:node | 167 [[BookmarkButtonCell alloc] initForNode:node |
167 contextMenu:nil | 168 contextMenu:nil |
168 cellText:@"small" | 169 cellText:@"small" |
169 cellImage:nil]); | 170 cellImage:nil]); |
170 EXPECT_TRUE(cell.get()); | 171 EXPECT_TRUE(cell.get()); |
171 | 172 |
172 NSSize size = [cell cellSize]; | 173 NSSize size = [cell cellSize]; |
173 // sanity check | 174 // sanity check |
174 EXPECT_GE(size.width, 2); | 175 EXPECT_GE(size.width, 2); |
175 EXPECT_GE(size.height, 2); | 176 EXPECT_GE(size.height, 2); |
176 | 177 |
177 // Once we turn on arrow drawing make sure there is now room for it. | 178 // Once we turn on arrow drawing make sure there is now room for it. |
178 [cell setDrawFolderArrow:YES]; | 179 [cell setDrawFolderArrow:YES]; |
179 NSSize arrowSize = [cell cellSize]; | 180 NSSize arrowSize = [cell cellSize]; |
180 EXPECT_GT(arrowSize.width, size.width); | 181 EXPECT_GT(arrowSize.width, size.width); |
181 } | 182 } |
182 | 183 |
183 TEST_F(BookmarkButtonCellTest, VerticalTextOffset) { | 184 TEST_F(BookmarkButtonCellTest, VerticalTextOffset) { |
184 BookmarkModel* model = profile()->GetBookmarkModel(); | 185 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
185 const BookmarkNode* bar = model->bookmark_bar_node(); | 186 const BookmarkNode* bar = model->bookmark_bar_node(); |
186 const BookmarkNode* node = model->AddURL(bar, bar->child_count(), | 187 const BookmarkNode* node = model->AddURL(bar, bar->child_count(), |
187 ASCIIToUTF16("title"), | 188 ASCIIToUTF16("title"), |
188 GURL("http://www.google.com")); | 189 GURL("http://www.google.com")); |
189 | 190 |
190 scoped_nsobject<GradientButtonCell> gradient_cell( | 191 scoped_nsobject<GradientButtonCell> gradient_cell( |
191 [[GradientButtonCell alloc] initTextCell:@"Testing"]); | 192 [[GradientButtonCell alloc] initTextCell:@"Testing"]); |
192 scoped_nsobject<BookmarkButtonCell> bookmark_cell( | 193 scoped_nsobject<BookmarkButtonCell> bookmark_cell( |
193 [[BookmarkButtonCell alloc] initForNode:node | 194 [[BookmarkButtonCell alloc] initForNode:node |
194 contextMenu:nil | 195 contextMenu:nil |
195 cellText:@"small" | 196 cellText:@"small" |
196 cellImage:nil]); | 197 cellImage:nil]); |
197 | 198 |
198 ASSERT_TRUE(gradient_cell.get()); | 199 ASSERT_TRUE(gradient_cell.get()); |
199 ASSERT_TRUE(bookmark_cell.get()); | 200 ASSERT_TRUE(bookmark_cell.get()); |
200 | 201 |
201 EXPECT_EQ(1, [gradient_cell verticalTextOffset]); | 202 EXPECT_EQ(1, [gradient_cell verticalTextOffset]); |
202 EXPECT_EQ(0, [bookmark_cell verticalTextOffset]); | 203 EXPECT_EQ(0, [bookmark_cell verticalTextOffset]); |
203 | 204 |
204 EXPECT_NE([bookmark_cell verticalTextOffset], | 205 EXPECT_NE([bookmark_cell verticalTextOffset], |
205 [gradient_cell verticalTextOffset]); | 206 [gradient_cell verticalTextOffset]); |
206 } | 207 } |
207 | 208 |
208 } // namespace | 209 } // namespace |
OLD | NEW |