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